• 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 #include "chre/platform/slpi/preloaded_nanoapps.h"
18 
19 #include "chre/core/event_loop_manager.h"
20 #include "chre/platform/fatal_error.h"
21 #include "chre/util/macros.h"
22 
23 namespace chre {
24 
25 // The CHRE build variant can supply this macro to override the detault list of
26 // preloaded nanoapps. This list is supplied empty to ensure that the symbol is
27 // available for platforms with no preloaded nanoapps.
28 #ifndef CHRE_VARIANT_SUPPLIES_PRELOADED_NANOAPP_LIST
29 
30 //! The default list of preloaded nanoapps to load.
31 PreloadedNanoappDescriptor kPreloadedNanoappList[] = {};
32 
33 //! The size of the default preloaded nanoapp list.
34 const size_t kPreloadedNanoappCount = ARRAY_SIZE(kPreloadedNanoappList);
35 
36 #endif  // CHRE_VARIANT_SUPPLIES_PRELOADED_NANOAPP_LIST
37 
loadPreloadedNanoapps()38 void loadPreloadedNanoapps() {
39   // Compare with zero to allow the compiler to optimize away the loop.
40   // Tautological comparisons are not warnings when comparing a const with
41   // another const.
42   if (kPreloadedNanoappCount > 0) {
43     // Cast the kPreloadedNanoappCount to size_t to avoid tautological comparison
44     // warnings when the kStaticNanoappCount is zero.
45     EventLoop& eventLoop = EventLoopManagerSingleton::get()->getEventLoop();
46     size_t nanoappCount = reinterpret_cast<size_t>(kPreloadedNanoappCount);
47     for (size_t i = 0; i < nanoappCount; i++) {
48       auto& app = kPreloadedNanoappList[i];
49       if (app.nanoapp.isNull()) {
50         FATAL_ERROR("Couldn't allocate memory for preloaded nanoapp");
51       } else {
52         app.nanoapp->loadFromFile(app.appId, app.filename);
53         eventLoop.startNanoapp(app.nanoapp);
54       }
55     }
56   }
57 }
58 
59 }  // namespace chre
60