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