Home | History | Annotate | Download | only in target_platform
      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 #ifndef CHRE_PLATFORM_SLPI_STATIC_NANOAPP_INIT_H_
     18 #define CHRE_PLATFORM_SLPI_STATIC_NANOAPP_INIT_H_
     19 
     20 #include "chre/core/static_nanoapps.h"
     21 #include "chre/platform/fatal_error.h"
     22 #include "chre/platform/shared/nanoapp_support_lib_dso.h"
     23 #include "chre/platform/slpi/uimg_util.h"
     24 
     25 /**
     26  * Initializes a static nanoapp that is based on the SLPI implementation of
     27  * PlatformNanoappBase.
     28  *
     29  * @param appName the name of the nanoapp. This will be prefixed by gNanoapp
     30  * when creating the global instance of the nanoapp.
     31  * @param appId the app's unique 64-bit ID
     32  * @param appVersion the application-defined 32-bit version number
     33  */
     34 #define CHRE_STATIC_NANOAPP_INIT(appName, appId_, appVersion_) \
     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 =                                 \
     42     CHRE_NSL_NANOAPP_INFO_STRUCT_MINOR_VERSION;                \
     43   appInfo.targetApiVersion = CHRE_API_VERSION;                 \
     44   appInfo.vendor = "Google"; /* TODO: make this configurable */\
     45   appInfo.name = #appName;                                     \
     46   appInfo.isSystemNanoapp = true;                              \
     47   appInfo.isTcmNanoapp = isSlpiUimgSupported();                \
     48   appInfo.appId = appId_;                                      \
     49   appInfo.appVersion = appVersion_;                            \
     50   appInfo.entryPoints.start = nanoappStart;                    \
     51   appInfo.entryPoints.handleEvent = nanoappHandleEvent;        \
     52   appInfo.entryPoints.end = nanoappEnd;                        \
     53   if (nanoapp.isNull()) {                                      \
     54     FATAL_ERROR("Failed to allocate nanoapp " #appName);       \
     55   } else {                                                     \
     56     nanoapp->loadStatic(&appInfo);                             \
     57   }                                                            \
     58                                                                \
     59   return nanoapp;                                              \
     60 }                                                              \
     61                                                                \
     62 }  // namespace chre
     63 
     64 #endif  // CHRE_PLATFORM_SLPI_STATIC_NANOAPP_INIT_H_
     65