• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2016 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.h>
18 #include <inttypes.h>
19 
20 /**
21  * @file
22  * A very basic example nanoapp that just logs activity in its entry points.
23  * Note that code wrapped in #ifdef CHRE_NANOAPP_INTERNAL is only relevant when
24  * a nanoapp is to be statically built into the CHRE system binary, which would
25  * make it a "system nanoapp" rather than a true dynamically loadable nanoapp.
26  */
27 
28 #ifdef CHRE_NANOAPP_INTERNAL
29 namespace chre {
30 namespace {
31 #endif  // CHRE_NANOAPP_INTERNAL
32 
nanoappStart()33 bool nanoappStart() {
34   chreLog(CHRE_LOG_INFO, "Hello, world from version 0x%08x", chreGetVersion());
35   return true;
36 }
37 
nanoappHandleEvent(uint32_t senderInstanceId,uint16_t eventType,const void *)38 void nanoappHandleEvent(uint32_t senderInstanceId,
39                         uint16_t eventType,
40                         const void * /*eventData*/) {
41   chreLog(CHRE_LOG_INFO, "Received event 0x%" PRIx16 " from 0x%" PRIx32 " at "
42           "time %" PRIu64, eventType, senderInstanceId, chreGetTime());
43 }
44 
nanoappEnd()45 void nanoappEnd() {
46   chreLog(CHRE_LOG_INFO, "Goodbye, world!");
47 }
48 
49 #ifdef CHRE_NANOAPP_INTERNAL
50 }  // anonymous namespace
51 }  // namespace chre
52 
53 #include "chre/util/nanoapp/app_id.h"
54 #include "chre/platform/static_nanoapp_init.h"
55 
56 CHRE_STATIC_NANOAPP_INIT(HelloWorld, chre::kHelloWorldAppId, 0);
57 #endif  // CHRE_NANOAPP_INTERNAL
58