• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
42 //! The size of the default static nanoapp list.
43 const size_t kStaticNanoappCount = ARRAY_SIZE(kStaticNanoappList);
44 
45 #endif  // CHRE_VARIANT_SUPPLIES_STATIC_NANOAPP_LIST
46 
loadStaticNanoapps()47 void loadStaticNanoapps() {
48   // Compare with zero to allow the compiler to optimize away the loop.
49   // Tautological comparisons are not warnings when comparing a const with
50   // another const.
51   if (kStaticNanoappCount > 0) {
52     // Cast the kStaticNanoappCount to size_t to avoid tautological comparison
53     // warnings when the kStaticNanoappCount is zero.
54     for (size_t i = 0; i < reinterpret_cast<size_t>(kStaticNanoappCount); i++) {
55       UniquePtr<Nanoapp> nanoapp = kStaticNanoappList[i]();
56       EventLoopManagerSingleton::get()->getEventLoop().startNanoapp(nanoapp);
57     }
58   }
59 }
60 
61 }  // namespace chre
62