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