chre_api_re.cc 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /*
  2. * Copyright (C) 2016 The Android Open Source Project
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #include "chre_api/chre/re.h"
  17. #include "chre/core/event_loop.h"
  18. #include "chre/core/event_loop_manager.h"
  19. #include "chre/platform/assert.h"
  20. #include "chre/platform/memory.h"
  21. #include "chre/platform/system_time.h"
  22. #include "chre/util/macros.h"
  23. using chre::EventLoopManager;
  24. using chre::EventLoopManagerSingleton;
  25. DLL_EXPORT uint64_t chreGetTime() {
  26. return chre::SystemTime::getMonotonicTime().toRawNanoseconds();
  27. }
  28. DLL_EXPORT int64_t chreGetEstimatedHostTimeOffset() {
  29. return chre::SystemTime::getEstimatedHostTimeOffset();
  30. }
  31. DLL_EXPORT uint64_t chreGetAppId(void) {
  32. chre::Nanoapp *nanoapp = EventLoopManager::validateChreApiCall(__func__);
  33. return nanoapp->getAppId();
  34. }
  35. DLL_EXPORT uint32_t chreGetInstanceId(void) {
  36. chre::Nanoapp *nanoapp = EventLoopManager::validateChreApiCall(__func__);
  37. return nanoapp->getInstanceId();
  38. }
  39. DLL_EXPORT uint32_t chreTimerSet(uint64_t duration, const void *cookie,
  40. bool oneShot) {
  41. chre::Nanoapp *nanoapp = EventLoopManager::validateChreApiCall(__func__);
  42. return EventLoopManagerSingleton::get()->getEventLoop().getTimerPool()
  43. .setNanoappTimer(nanoapp, chre::Nanoseconds(duration), cookie, oneShot);
  44. }
  45. DLL_EXPORT bool chreTimerCancel(uint32_t timerId) {
  46. chre::Nanoapp *nanoapp = EventLoopManager::validateChreApiCall(__func__);
  47. return EventLoopManagerSingleton::get()->getEventLoop().getTimerPool()
  48. .cancelNanoappTimer(nanoapp, timerId);
  49. }
  50. DLL_EXPORT void *chreHeapAlloc(uint32_t bytes) {
  51. chre::Nanoapp *nanoapp = EventLoopManager::validateChreApiCall(__func__);
  52. return chre::EventLoopManagerSingleton::get()->getMemoryManager().
  53. nanoappAlloc(nanoapp, bytes);
  54. }
  55. DLL_EXPORT void chreHeapFree(void *ptr) {
  56. chre::Nanoapp *nanoapp = EventLoopManager::validateChreApiCall(__func__);
  57. chre::EventLoopManagerSingleton::get()->getMemoryManager().
  58. nanoappFree(nanoapp, ptr);
  59. }