event_loop_manager.cc 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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/core/event_loop_manager.h"
  17. #include "chre/platform/fatal_error.h"
  18. #include "chre/platform/memory.h"
  19. #include "chre/util/lock_guard.h"
  20. namespace chre {
  21. void freeEventDataCallback(uint16_t /*eventType*/, void *eventData) {
  22. memoryFree(eventData);
  23. }
  24. Nanoapp *EventLoopManager::validateChreApiCall(const char *functionName) {
  25. chre::Nanoapp *currentNanoapp = EventLoopManagerSingleton::get()
  26. ->getEventLoop().getCurrentNanoapp();
  27. CHRE_ASSERT_LOG(currentNanoapp, "%s called with no CHRE app context",
  28. functionName);
  29. return currentNanoapp;
  30. }
  31. UniquePtr<char> EventLoopManager::debugDump() {
  32. constexpr size_t kDebugStringSize = 4096;
  33. char *debugStr = static_cast<char *>(memoryAlloc(kDebugStringSize));
  34. if (debugStr == nullptr) {
  35. LOG_OOM();
  36. } else {
  37. size_t debugStrPos = 0;
  38. mMemoryManager.logStateToBuffer(debugStr, &debugStrPos, kDebugStringSize);
  39. mEventLoop.logStateToBuffer(debugStr, &debugStrPos, kDebugStringSize);
  40. mSensorRequestManager.logStateToBuffer(debugStr, &debugStrPos,
  41. kDebugStringSize);
  42. #ifdef CHRE_GNSS_SUPPORT_ENABLED
  43. mGnssManager.logStateToBuffer(debugStr, &debugStrPos, kDebugStringSize);
  44. #endif // CHRE_GNSS_SUPPORT_ENABLED
  45. #ifdef CHRE_WIFI_SUPPORT_ENABLED
  46. mWifiRequestManager.logStateToBuffer(debugStr, &debugStrPos,
  47. kDebugStringSize);
  48. #endif // CHRE_WIFI_SUPPORT_ENABLED
  49. #ifdef CHRE_WWAN_SUPPORT_ENABLED
  50. mWwanRequestManager.logStateToBuffer(debugStr, &debugStrPos,
  51. kDebugStringSize);
  52. #endif // CHRE_WWAN_SUPPORT_ENABLED
  53. #ifdef CHRE_AUDIO_SUPPORT_ENABLED
  54. mAudioRequestManager.logStateToBuffer(debugStr, &debugStrPos,
  55. kDebugStringSize);
  56. #endif // CHRE_AUDIO_SUPPORT_ENABLED
  57. LOGD("Debug dump used %zu bytes of log buffer", debugStrPos);
  58. }
  59. return UniquePtr<char>(debugStr);
  60. }
  61. uint32_t EventLoopManager::getNextInstanceId() {
  62. ++mLastInstanceId;
  63. // ~4 billion instance IDs should be enough for anyone... if we need to
  64. // support wraparound for stress testing load/unload, then we can set a flag
  65. // when wraparound occurs and use EventLoop::findNanoappByInstanceId to ensure
  66. // we avoid conflicts
  67. if (mLastInstanceId == kBroadcastInstanceId
  68. || mLastInstanceId == kSystemInstanceId) {
  69. FATAL_ERROR("Exhausted instance IDs!");
  70. }
  71. return mLastInstanceId;
  72. }
  73. void EventLoopManager::lateInit() {
  74. mSensorRequestManager.init();
  75. #ifdef CHRE_GNSS_SUPPORT_ENABLED
  76. mGnssManager.init();
  77. #endif // CHRE_GNSS_SUPPORT_ENABLED
  78. #ifdef CHRE_WIFI_SUPPORT_ENABLED
  79. mWifiRequestManager.init();
  80. #endif // CHRE_WIFI_SUPPORT_ENABLED
  81. #ifdef CHRE_WWAN_SUPPORT_ENABLED
  82. mWwanRequestManager.init();
  83. #endif // CHRE_WWAN_SUPPORT_ENABLED
  84. #ifdef CHRE_AUDIO_SUPPORT_ENABLED
  85. mAudioRequestManager.init();
  86. #endif // CHRE_AUDIO_SUPPORT_ENABLED
  87. }
  88. // Explicitly instantiate the EventLoopManagerSingleton to reduce codesize.
  89. template class Singleton<EventLoopManager>;
  90. } // namespace chre