• 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 #ifndef _CHRE_NANOAPP_H_
18 #define _CHRE_NANOAPP_H_
19 
20 /**
21  * @file
22  * Methods in the Context Hub Runtime Environment which must be implemented
23  * by the nanoapp.
24  */
25 
26 #include <stdbool.h>
27 #include <stdint.h>
28 
29 #ifdef __cplusplus
30 extern "C" {
31 #endif
32 
33 /**
34  * Method invoked by the CHRE when loading the nanoapp.
35  *
36  * Every CHRE method is legal to call from this method.
37  *
38  * @return  'true' if the nanoapp successfully started.  'false' if the nanoapp
39  *     failed to properly initialize itself (for example, could not obtain
40  *     sufficient memory from the heap).  If this method returns 'false', the
41  *     nanoapp will be unloaded by the CHRE (and nanoappEnd will
42  *     _not_ be invoked in that case).
43  * @see nanoappEnd
44  */
45 bool nanoappStart(void);
46 
47 /**
48  * Method invoked by the CHRE when there is an event for this nanoapp.
49  *
50  * Every CHRE method is legal to call from this method.
51  *
52  * @param senderInstanceId  The Instance ID for the source of this event.
53  *     Note that this may be CHRE_INSTANCE_ID, indicating that the event
54  *     was generated by the CHRE.
55  * @param eventType  The event type.  This might be one of the CHRE_EVENT_*
56  *     types defined in this API.  But it might also be a user-defined event.
57  * @param eventData  The associated data, if any, for this specific type of
58  *     event.  From the nanoapp's perspective, this eventData's lifetime ends
59  *     when this method returns, and thus any data the nanoapp wishes to
60  *     retain must be copied.  Note that interpretation of event data is
61  *     given by the event type, and for some events may not be a valid
62  *     pointer.  See documentation of the specific CHRE_EVENT_* types for how to
63  *     interpret this data for those.  Note that for user events, you will
64  *     need to establish what this data means.
65  */
66 void nanoappHandleEvent(uint32_t senderInstanceId, uint16_t eventType,
67                         const void *eventData);
68 
69 /**
70  * Method invoked by the CHRE when unloading the nanoapp.
71  *
72  * It is not valid to attempt to send events or messages, or to invoke functions
73  * which will generate events to this app, within the nanoapp implementation of
74  * this function.  That means it is illegal for the nanoapp invoke any of the
75  * following:
76  *
77  * - chreSendEvent()
78  * - chreSendMessageToHost()
79  * - chreSensorConfigure()
80  * - chreSensorConfigureModeOnly()
81  * - chreTimerSet()
82  * - etc.
83  *
84  * @see nanoappStart
85  */
86 void nanoappEnd(void);
87 
88 
89 #ifdef __cplusplus
90 }
91 #endif
92 
93 #endif  /* _CHRE_NANOAPP_H_ */
94