1 /* 2 * Copyright (C) 2022 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 #ifndef CHRE_PLATFORM_ZEPHYR_STATIC_NANOAPP_INIT_H_ 18 #define CHRE_PLATFORM_ZEPHYR_STATIC_NANOAPP_INIT_H_ 19 20 #include "chre/core/nanoapp.h" 21 #include "chre/core/static_nanoapps.h" 22 #include "chre/platform/fatal_error.h" 23 #include "chre/platform/shared/nanoapp_support_lib_dso.h" 24 #include "chre/version.h" 25 26 #define CHRE_STATIC_NANOAPP_INIT(app_name, app_id, app_version, app_perms) \ 27 namespace chre { \ 28 UniquePtr<Nanoapp> initializeStaticNanoapp##app_name() { \ 29 static struct ::chreNslNanoappInfo app_info; \ 30 UniquePtr<Nanoapp> nanoapp = MakeUnique<Nanoapp>(); \ 31 app_info.magic = CHRE_NSL_NANOAPP_INFO_MAGIC; \ 32 app_info.structMinorVersion = CHRE_NSL_NANOAPP_INFO_STRUCT_MINOR_VERSION; \ 33 app_info.targetApiVersion = CHRE_API_VERSION; \ 34 app_info.vendor = "Zephyr"; \ 35 app_info.name = #app_name; \ 36 app_info.isSystemNanoapp = true; \ 37 app_info.isTcmNanoapp = false; \ 38 app_info.appId = app_id; \ 39 app_info.appVersion = app_version; \ 40 app_info.entryPoints.start = nanoappStart; \ 41 app_info.entryPoints.handleEvent = nanoappHandleEvent; \ 42 app_info.entryPoints.end = nanoappEnd; \ 43 app_info.appVersionString = "<undefined>"; \ 44 app_info.appPermissions = app_perms; \ 45 if (nanoapp.isNull()) { \ 46 FATAL_ERROR("Failed to allocate nanoapp " #app_name); \ 47 } else { \ 48 nanoapp->loadStatic(&app_info); \ 49 } \ 50 \ 51 return nanoapp; \ 52 } \ 53 } 54 #endif // CHRE_PLATFORM_ZEPHYR_STATIC_NANOAPP_INIT_H_ 55