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