1 /* Copyright (c) 2021 Google LLC
2 * SPDX-License-Identifier: Apache-2.0
3 */
4
5 #include <cinttypes>
6 #include <zephyr/sys/printk.h>
7
8 #include "chre_api/chre/event.h"
9 #include "chre/core/event_loop_manager.h"
10 #include "chre/platform/static_nanoapp_init.h"
11 #include "chre/util/system/napp_permissions.h"
12
13 namespace
14 {
15 constexpr const uint64_t kAppId = 1;
16 constexpr const uint32_t kAppVersion = 1;
17
18 chre::Nanoapp *nanoapp = nullptr;
19
nanoappStart(void)20 bool nanoappStart(void)
21 {
22 printk("EchoApp::nanoappStart()\n");
23 nanoapp = chre::EventLoopManagerSingleton ::get()->getEventLoop().getCurrentNanoapp();
24 nanoapp->registerForBroadcastEvent(CHRE_EVENT_MESSAGE_FROM_HOST);
25 return true;
26 }
27
nanoappHandleEvent(uint32_t sender_instance_id,uint16_t event_type,const void * event_data)28 void nanoappHandleEvent(uint32_t sender_instance_id, uint16_t event_type, const void *event_data)
29 {
30 printk("EchoApp::nanoappHandleEvent(sender_instance_id=%u, event_type=%u, event_data@%p)\n",
31 sender_instance_id, event_type, event_data);
32 }
33
nanoappEnd()34 void nanoappEnd()
35 {
36 nanoapp->unregisterForBroadcastEvent(0);
37 nanoapp = nullptr;
38 printk("EchoApp::nanoappEnd()\n");
39 }
40
41 } /* anonymous namespace */
42
43 CHRE_STATIC_NANOAPP_INIT(EchoApp, kAppId, kAppVersion, chre::NanoappPermissions::CHRE_PERMS_NONE);
44