aboutsummaryrefslogtreecommitdiff
path: root/chre_api/legacy/v1_4/chre/nanoapp.h
blob: da199ee0f39dc5a1d27fbc0ac944680197b545fe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/*
 * Copyright (C) 2016 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef _CHRE_NANOAPP_H_
#define _CHRE_NANOAPP_H_

/**
 * @file
 * Methods in the Context Hub Runtime Environment which must be implemented
 * by the nanoapp.
 */

#include <stdbool.h>
#include <stdint.h>

#ifdef __cplusplus
extern "C" {
#endif

/**
 * Method invoked by the CHRE when loading the nanoapp.
 *
 * Every CHRE method is legal to call from this method.
 *
 * @return  'true' if the nanoapp successfully started.  'false' if the nanoapp
 *     failed to properly initialize itself (for example, could not obtain
 *     sufficient memory from the heap).  If this method returns 'false', the
 *     nanoapp will be unloaded by the CHRE (and nanoappEnd will
 *     _not_ be invoked in that case).
 * @see nanoappEnd
 */
bool nanoappStart(void);

/**
 * Method invoked by the CHRE when there is an event for this nanoapp.
 *
 * Every CHRE method is legal to call from this method.
 *
 * @param senderInstanceId  The Instance ID for the source of this event.
 *     Note that this may be CHRE_INSTANCE_ID, indicating that the event
 *     was generated by the CHRE.
 * @param eventType  The event type.  This might be one of the CHRE_EVENT_*
 *     types defined in this API.  But it might also be a user-defined event.
 * @param eventData  The associated data, if any, for this specific type of
 *     event.  From the nanoapp's perspective, this eventData's lifetime ends
 *     when this method returns, and thus any data the nanoapp wishes to
 *     retain must be copied.  Note that interpretation of event data is
 *     given by the event type, and for some events may not be a valid
 *     pointer.  See documentation of the specific CHRE_EVENT_* types for how to
 *     interpret this data for those.  Note that for user events, you will
 *     need to establish what this data means.
 */
void nanoappHandleEvent(uint32_t senderInstanceId, uint16_t eventType,
                        const void *eventData);

/**
 * Method invoked by the CHRE when unloading the nanoapp.
 *
 * It is not valid to attempt to send events or messages, or to invoke functions
 * which will generate events to this app, within the nanoapp implementation of
 * this function.  That means it is illegal for the nanoapp invoke any of the
 * following:
 *
 * - chreSendEvent()
 * - chreSendMessageToHost()
 * - chreSensorConfigure()
 * - chreSensorConfigureModeOnly()
 * - chreTimerSet()
 * - etc.
 *
 * @see nanoappStart
 */
void nanoappEnd(void);


#ifdef __cplusplus
}
#endif

#endif  /* _CHRE_NANOAPP_H_ */