1 /*
2  * Copyright (C) 2017 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 // If the CHRE build variant wants to supply its own static nanoapps, include
18 // chre/platform/static_nanoapp_init.h in the nanoapp to include and define
19 // CHRE_STATIC_NANOAPP_INIT with the appropriate parameters (see examples under
20 // chre/apps/). Then, define the UniquePtr created by CHRE_STATIC_NANOAPP_INIT
21 // similar to chre/apps/apps.h and add that variable to kStaticNanoappList
22 // below.
23 #ifdef CHRE_INCLUDE_DEFAULT_STATIC_NANOAPPS
24 #include "chre/apps/apps.h"
25 #endif  // CHRE_INCLUDE_DEFAULT_STATIC_NANOAPPS
26 #include "chre/core/event_loop_manager.h"
27 #include "chre/core/static_nanoapps.h"
28 #include "chre/util/macros.h"
29 
30 namespace chre {
31 
32 // The CHRE build variant can supply this macro to override the default list of
33 // static nanoapps. Most production variants will supply this macro as these
34 // nanoapps are mostly intended for testing and evaluation purposes. This list
35 // is supplied empty to ensure that the symbol is avilable for platforms with
36 // no static nanoapps.
37 #ifndef CHRE_VARIANT_SUPPLIES_STATIC_NANOAPP_LIST
38 
39 //! The default list of static nanoapps to load.
40 const StaticNanoappInitFunction kStaticNanoappList[] = {
41 #ifdef CHRE_LOAD_GNSS_WORLD
42   initializeStaticNanoappGnssWorld,
43 #endif
44 #ifdef CHRE_LOAD_SENSOR_WORLD
45   initializeStaticNanoappSensorWorld,
46 #endif
47 #ifdef CHRE_LOAD_WIFI_WORLD
48   initializeStaticNanoappWifiWorld,
49 #endif
50 #ifdef CHRE_LOAD_WWAN_WORLD
51   initializeStaticNanoappWwanWorld,
52 #endif
53 };
54 
55 //! The size of the default static nanoapp list.
56 const size_t kStaticNanoappCount = ARRAY_SIZE(kStaticNanoappList);
57 
58 #endif  // CHRE_VARIANT_SUPPLIES_STATIC_NANOAPP_LIST
59 
loadStaticNanoapps()60 void loadStaticNanoapps() {
61   // Compare with zero to allow the compiler to optimize away the loop.
62   // Tautological comparisons are not warnings when comparing a const with
63   // another const.
64   if (kStaticNanoappCount > 0) {
65     // Cast the kStaticNanoappCount to size_t to avoid tautological comparison
66     // warnings when the kStaticNanoappCount is zero.
67     for (size_t i = 0; i < reinterpret_cast<size_t>(kStaticNanoappCount); i++) {
68       UniquePtr<Nanoapp> nanoapp = kStaticNanoappList[i]();
69       EventLoopManagerSingleton::get()->getEventLoop().startNanoapp(nanoapp);
70     }
71   }
72 }
73 
74 }  // namespace chre
75