1 /* 2 * Copyright (C) 2019 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_FREERTOS_STATIC_NANOAPP_INIT_H_ 18 #define CHRE_PLATFORM_FREERTOS_STATIC_NANOAPP_INIT_H_ 19 20 #include "chre/core/nanoapp.h" 21 #include "chre/platform/fatal_error.h" 22 #include "chre/util/unique_ptr.h" 23 24 /** 25 * Initializes a static nanoapp that is based on the FreeRTOS implementation of 26 * PlatformNanoappBase. 27 * 28 * @param appName the name of the nanoapp. This will be prefixed by gNanoapp 29 * when creating the global instance of the nanoapp. 30 * @param appId the app's unique 64-bit ID 31 * @param appVersion the application-defined 32-bit version number 32 * @param appPerms the declared CHRE_PERMS_ permissions for the nanoapp. 33 */ 34 #define CHRE_STATIC_NANOAPP_INIT(appName, appId_, appVersion_, appPerms) \ 35 namespace chre { \ 36 \ 37 UniquePtr<Nanoapp> initializeStaticNanoapp##appName() { \ 38 UniquePtr<Nanoapp> nanoapp = MakeUnique<Nanoapp>(); \ 39 static struct chreNslNanoappInfo appInfo; \ 40 appInfo.magic = CHRE_NSL_NANOAPP_INFO_MAGIC; \ 41 appInfo.structMinorVersion = CHRE_NSL_NANOAPP_INFO_STRUCT_MINOR_VERSION; \ 42 appInfo.targetApiVersion = CHRE_API_VERSION; \ 43 appInfo.vendor = "Google"; /* TODO: make this configurable */ \ 44 appInfo.name = #appName; \ 45 appInfo.isSystemNanoapp = true; \ 46 appInfo.isTcmNanoapp = false; \ 47 appInfo.appId = appId_; \ 48 appInfo.appVersion = appVersion_; \ 49 appInfo.entryPoints.start = nanoappStart; \ 50 appInfo.entryPoints.handleEvent = nanoappHandleEvent; \ 51 appInfo.entryPoints.end = nanoappEnd; \ 52 appInfo.appVersionString = "<undefined>"; \ 53 appInfo.appPermissions = appPerms; \ 54 if (nanoapp.isNull()) { \ 55 FATAL_ERROR("Failed to allocate nanoapp " #appName); \ 56 } else { \ 57 nanoapp->loadStatic(&appInfo); \ 58 } \ 59 \ 60 return nanoapp; \ 61 } \ 62 } /* namespace chre */ 63 64 #endif // CHRE_PLATFORM_FREERTOS_NANOAPP_INIT_H_ 65