• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2023 The Pigweed Authors
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License"); you may not
4 // use this file except in compliance with the License. You may obtain a copy of
5 // the License at
6 //
7 //     https://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11 // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12 // License for the specific language governing permissions and limitations under
13 // the License.
14 
15 #pragma once
16 
17 #include "chre/core/static_nanoapps.h"
18 #include "chre/platform/fatal_error.h"
19 #include "chre/platform/shared/nanoapp_support_lib_dso.h"
20 
21 #define CHRE_STATIC_NANOAPP_INIT(appName, appId_, appVersion_, appPerms)     \
22   namespace chre {                                                           \
23                                                                              \
24   UniquePtr<Nanoapp> initializeStaticNanoapp##appName() {                    \
25     UniquePtr<Nanoapp> nanoapp = MakeUnique<Nanoapp>();                      \
26     static struct chreNslNanoappInfo appInfo;                                \
27     appInfo.magic = CHRE_NSL_NANOAPP_INFO_MAGIC;                             \
28     appInfo.structMinorVersion = CHRE_NSL_NANOAPP_INFO_STRUCT_MINOR_VERSION; \
29     appInfo.targetApiVersion = CHRE_API_VERSION;                             \
30     appInfo.vendor = "Google";                                               \
31     appInfo.name = #appName;                                                 \
32     appInfo.isSystemNanoapp = true;                                          \
33     appInfo.isTcmNanoapp = false;                                            \
34     appInfo.appId = appId_;                                                  \
35     appInfo.appVersion = appVersion_;                                        \
36     appInfo.entryPoints.start = nanoappStart;                                \
37     appInfo.entryPoints.handleEvent = nanoappHandleEvent;                    \
38     appInfo.entryPoints.end = nanoappEnd;                                    \
39     appInfo.appVersionString = "<undefined>";                                \
40     appInfo.appPermissions = appPerms;                                       \
41     if (nanoapp.isNull()) {                                                  \
42       FATAL_ERROR("Failed to allocate nanoapp " #appName);                   \
43     } else {                                                                 \
44       nanoapp->loadStatic(&appInfo);                                         \
45     }                                                                        \
46                                                                              \
47     return nanoapp;                                                          \
48   }                                                                          \
49                                                                              \
50   }  // namespace chre
51