hello_world.cc revision e5d8b38a4814e88b04bcad8e8e9835c375e725bd
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
29namespace chre {
30namespace {
31#endif  // CHRE_NANOAPP_INTERNAL
32
33bool nanoappStart() {
34  chreLog(CHRE_LOG_INFO, "Hello, world!");
35  return true;
36}
37
38void nanoappHandleEvent(uint32_t senderInstanceId,
39                        uint16_t eventType,
40                        const void * /*eventData*/) {
41  // All nanoapps by default get informed of other apps starting and stopping in
42  // the system. Ignore these, but log others.
43  if (eventType != CHRE_EVENT_NANOAPP_STARTED
44      && eventType != CHRE_EVENT_NANOAPP_STOPPED) {
45    chreLog(CHRE_LOG_INFO, "Received event 0x%" PRIx16 " from 0x%" PRIx32 " at "
46          "time %" PRIu64, eventType, senderInstanceId, chreGetTime());
47  }
48}
49
50void nanoappEnd() {
51  chreLog(CHRE_LOG_INFO, "Goodbye, world!");
52}
53
54#ifdef CHRE_NANOAPP_INTERNAL
55}  // anonymous namespace
56}  // namespace chre
57
58#include "chre/util/nanoapp/app_id.h"
59#include "chre/platform/static_nanoapp_init.h"
60
61CHRE_STATIC_NANOAPP_INIT(HelloWorld, chre::kHelloWorldAppId, 0);
62#endif  // CHRE_NANOAPP_INTERNAL
63