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 17 #include "chre/core/event_loop_manager.h" 18 19 #include "chre/platform/atomic.h" 20 #include "chre/platform/fatal_error.h" 21 #include "chre/platform/memory.h" 22 #include "chre/util/lock_guard.h" 23 24 namespace chre { 25 validateChreApiCall(const char * functionName)26Nanoapp *EventLoopManager::validateChreApiCall(const char *functionName) { 27 chre::Nanoapp *currentNanoapp = 28 EventLoopManagerSingleton::get()->getEventLoop().getCurrentNanoapp(); 29 CHRE_ASSERT_LOG(currentNanoapp, "%s called with no CHRE app context", 30 functionName); 31 return currentNanoapp; 32 } 33 getNextInstanceId()34uint16_t EventLoopManager::getNextInstanceId() { 35 // Get the next available instance ID and mask off the upper 16 bit. 36 uint16_t instanceId = 37 static_cast<uint16_t>(mNextInstanceId.fetch_increment() & 0x0000FFFF); 38 39 // 65536 instance IDs should be enough for normal use cases. If we need to 40 // support wraparound for stress testing load/unload, then we can set a flag 41 // when wraparound occurs and use EventLoop::findNanoappByInstanceId to ensure 42 // we avoid conflicts 43 if (instanceId == kBroadcastInstanceId || instanceId == kSystemInstanceId) { 44 FATAL_ERROR("Exhausted instance IDs!"); 45 } 46 47 return instanceId; 48 } 49 lateInit()50void EventLoopManager::lateInit() { 51 #ifdef CHRE_SENSORS_SUPPORT_ENABLED 52 mSensorRequestManager.init(); 53 #endif // CHRE_SENSORS_SUPPORT_ENABLED 54 55 #ifdef CHRE_GNSS_SUPPORT_ENABLED 56 mGnssManager.init(); 57 #endif // CHRE_GNSS_SUPPORT_ENABLED 58 59 #ifdef CHRE_WIFI_SUPPORT_ENABLED 60 mWifiRequestManager.init(); 61 #endif // CHRE_WIFI_SUPPORT_ENABLED 62 63 #ifdef CHRE_WWAN_SUPPORT_ENABLED 64 mWwanRequestManager.init(); 65 #endif // CHRE_WWAN_SUPPORT_ENABLED 66 67 #ifdef CHRE_AUDIO_SUPPORT_ENABLED 68 mAudioRequestManager.init(); 69 #endif // CHRE_AUDIO_SUPPORT_ENABLED 70 71 #ifdef CHRE_BLE_SUPPORT_ENABLED 72 mBleRequestManager.init(); 73 #endif // CHRE_BLE_SUPPORT_ENABLED 74 } 75 76 // Explicitly instantiate the EventLoopManagerSingleton to reduce codesize. 77 template class Singleton<EventLoopManager>; 78 79 } // namespace chre 80