1 /*
2  * eventreg.h - CC31xx/CC32xx Host Driver Implementation
3  *
4  * Copyright (C) 2017 Texas Instruments Incorporated - http://www.ti.com/
5  *
6  *
7  *  Redistribution and use in source and binary forms, with or without
8  *  modification, are permitted provided that the following conditions
9  *  are met:
10  *
11  *    Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  *
14  *    Redistributions in binary form must reproduce the above copyright
15  *    notice, this list of conditions and the following disclaimer in the
16  *    documentation and/or other materials provided with the
17  *    distribution.
18  *
19  *    Neither the name of Texas Instruments Incorporated nor the names of
20  *    its contributors may be used to endorse or promote products derived
21  *    from this software without specific prior written permission.
22  *
23  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24  *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25  *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
26  *  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
27  *  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28  *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
29  *  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
30  *  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
31  *  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32  *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
33  *  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34  *
35 */
36 
37 #ifndef EVENTREG_H_
38 #define EVENTREG_H_
39 
40 #ifdef    __cplusplus
41 extern "C"
42 {
43 #endif
44 
45 /*!
46     \defgroup event_registration
47     \short Allows user to register event handlers dynamically.
48 
49 */
50 /*!
51 
52     \addtogroup event_registration
53     @{
54 
55 */
56 
57 typedef enum
58 {
59     SL_EVENT_HDL_FATAL_ERROR,
60     SL_EVENT_HDL_DEVICE_GENERAL,
61     SL_EVENT_HDL_WLAN,
62     SL_EVENT_HDL_NETAPP,
63     SL_EVENT_HDL_SOCKET,
64     SL_EVENT_HDL_HTTP_SERVER,
65     SL_EVENT_HDL_NETAPP_REQUEST,
66     SL_EVENT_HDL_MEM_FREE,
67     SL_EVENT_HDL_SOCKET_TRIGGER,
68     SL_NUM_OF_EVENT_TYPES
69 }SlEventHandler_e;
70 
71 typedef struct SlEventsListNode_s
72 {
73     void *event;
74     struct SlEventsListNode_s *next;
75 }SlEventsListNode_t;
76 
77 #ifdef SL_RUNTIME_EVENT_REGISTERATION
78 
79 /*!
80     \brief register events in runtime
81 
82     this api enables registration of the SimpleLink host driver in runtime.
83 
84     \param[in]  EventHandlerType event type - SlEventHandler_e - to register
85 
86     \param[in]  EventHandler pointer to the event handler
87 
88     \return 0 on success, error otherwise
89 
90     \sa     sl_RegisterEventHandler
91 
92     \note   registration of event with NULL, clears any registered event.
93 */
94 _i32 sl_RegisterEventHandler(SlEventHandler_e EventHandlerType , void* EventHandler);
95 
96 
97 
98 _i32 _SlIsEventRegistered(SlEventHandler_e EventHandlerType);
99 
100 /******************************************************************************
101     sl_RegisterLibsEventHandler
102 
103     \brief  this function registers event handlers from external libraries in runtime.
104 
105     the allocation and memory maintenance of the SlEventsListNode_t is on the library
106     Responsibility.
107 
108     RETURNS:        success or error code.
109 ******************************************************************************/
110 
111 _i32 sl_RegisterLibsEventHandler(SlEventHandler_e EventHandlerType , SlEventsListNode_t* EventHandlerNode);
112 
113 /******************************************************************************
114     sl_UnregisterLibsEventHandler
115 
116     DESCRIPTION:
117     this function unregisters event handlers from external libraries in runtime.
118     the SlEventsListNode_t that was used for registration, must be used to unregister that event handler.
119 
120     the allocation and memory maintenance of the SlEventsListNode_t is on the library
121     Responsibility.
122 
123     RETURNS:        success or error code.
124 ******************************************************************************/
125 _i32 sl_UnregisterLibsEventHandler(SlEventHandler_e EventHandlerType , SlEventsListNode_t* EventHandlerNode);
126 
127 /*!
128 
129  Close the Doxygen group.
130  @}
131 
132  */
133 
134 
135 void _SlDeviceFatalErrorEvtHdlr(SlDeviceFatal_t *pSlFatalErrorEvent);
136 void _SlDeviceGeneralEvtHdlr(SlDeviceEvent_t *pSlDeviceEvent);
137 void _SlWlanEvtHdlr(SlWlanEvent_t* pSlWlanEvent);
138 void _SlNetAppEvtHdlr(SlNetAppEvent_t* pSlNetAppEvent);
139 void _SlSockEvtHdlr(SlSockEvent_t* pSlSockEvent);
140 void _SlNetAppHttpServerHdlr(SlNetAppHttpServerEvent_t *pSlHttpServerEvent, SlNetAppHttpServerResponse_t *pSlHttpServerResponse);
141 void _SlNetAppRequestHdlr(SlNetAppRequest_t *pNetAppRequest, SlNetAppResponse_t *pNetAppResponse);
142 void _SlNetAppRequestMemFree (_u8 *buffer);
143 void _SlSocketTriggerEventHandler(SlSockTriggerEvent_t* pSlSockTriggerEvent);
144 
145 #endif /* SL_RUNTIME_EVENT_REGISTERATION */
146 
147 
148 #ifdef  __cplusplus
149 }
150 #endif /* __cplusplus */
151 
152 
153 #endif /* EVENTREG_H_ */
154