SimpleLink CC3120/CC3220 Host Driver  Version 2.0.1.15
Simplifies the implementation of Internet connectivity
eventreg.c
1 /*
2  * Copyright (C) 2016 Texas Instruments Incorporated
3  *
4  * All rights reserved. Property of Texas Instruments Incorporated.
5  * Restricted rights to use, duplicate or disclose this code are
6  * granted through contract.
7  *
8  * The program may not be used without the written permission of
9  * Texas Instruments Incorporated or against the terms and conditions
10  * stipulated in the agreement under which this program has been supplied,
11  * and under no circumstances can it be used with non-TI connectivity device.
12  *
13  */
14 
15 #include <ti/drivers/net/wifi/simplelink.h>
16 #include <ti/drivers/net/wifi/eventreg.h>
17 
18 
19 
20 typedef void (*_pSlDeviceFatalErrorEvtHdlr_t)(SlDeviceFatal_t *pSlFatalErrorEvent);
21 typedef void (*_pSlDeviceGeneralEvtHdlr_t)(SlDeviceEvent_t *pSlDeviceEvent);
22 typedef void (*_pSlWlanEvtHdlr)(SlWlanEvent_t* pSlWlanEvent);
23 typedef void (*_pSlNetAppEvtHdlr)(SlNetAppEvent_t* pSlNetAppEvent);
24 typedef void (*_pSlSockEvtHdlr)(SlSockEvent_t* pSlSockEvent);
25 typedef void (*_pSlNetAppHttpServerHdlr)(SlNetAppHttpServerEvent_t *pSlHttpServerEvent, SlNetAppHttpServerResponse_t *pSlHttpServerResponse);
26 typedef void (*_pSlNetAppRequestHdlr)(SlNetAppRequest_t *pNetAppRequest, SlNetAppResponse_t *pNetAppResponse);
27 typedef void (*_pSlNetAppRequestMemFree)(_u8 *buffer);
28 typedef void (*_pSlSocketTriggerEventHandler)(SlSockTriggerEvent_t* pSlSockTriggerEvent);
29 
30 
31 typedef _i32 (*_pSlPropogationDeviceFatalErrorEvtHdlr_t)(SlDeviceFatal_t *pSlFatalErrorEvent);
32 typedef _i32 (*_pSlPropogationDeviceGeneralEvtHdlr_t)(SlDeviceEvent_t *pSlDeviceEvent);
33 typedef _i32 (*_pSlPropogationWlanEvtHdlr)(SlWlanEvent_t* pSlWlanEvent);
34 typedef _i32 (*_pSlPropogationNetAppEvtHdlr)(SlNetAppEvent_t* pSlNetAppEvent);
35 typedef _i32 (*_pSlPropogationSockEvtHdlr)(SlSockEvent_t* pSlSockEvent);
36 typedef _i32 (*_pSlPropogationNetAppHttpServerHdlr)(SlNetAppHttpServerEvent_t *pSlHttpServerEvent, SlNetAppHttpServerResponse_t *pSlHttpServerResponse);
37 typedef _i32 (*_pSlPropogationNetAppRequestHdlr)(SlNetAppRequest_t *pNetAppRequest, SlNetAppResponse_t *pNetAppResponse);
38 typedef _i32 (*_pSlPropogationNetAppRequestMemFree)(_u8 *buffer);
39 typedef _i32 (*_pSlPropogationSocketTriggerEventHandler)(SlSockTriggerEvent_t* pSlSockTriggerEvent);
40 
41 #ifdef SL_RUNTIME_EVENT_REGISTERATION
42 
43 void* g_UserEvents[SL_NUM_OF_EVENT_TYPES] = {0};
44 SlEventsListNode_t* g_LibsEvents[SL_NUM_OF_EVENT_TYPES] = {0};
45 
46 #endif
47 
48 
49 _i32 _SlIsEventRegistered(SlEventHandler_e EventHandlerType)
50 {
51 #ifdef SL_RUNTIME_EVENT_REGISTERATION
52  if( (NULL != g_LibsEvents[EventHandlerType]) || (NULL != g_UserEvents[EventHandlerType]) )
53  {
54  return 1;
55  }
56 #endif
57  if(SL_EVENT_HDL_MEM_FREE == EventHandlerType)
58  {
59 #ifdef slcb_NetAppRequestMemFree
60  return 1;
61 #endif
62  }
63  if(SL_EVENT_HDL_SOCKET_TRIGGER == EventHandlerType)
64  {
65 #ifdef slcb_SocketTriggerEventHandler
66  return 1;
67 #endif
68  }
69 
70  return 0;
71 }
72 
73 #ifdef SL_RUNTIME_EVENT_REGISTERATION
74 
75 _i32 sl_RegisterEventHandler(SlEventHandler_e EventHandlerType , void* EventHandler)
76 {
77  g_UserEvents[EventHandlerType] = EventHandler;
78  return 0;
79 }
80 
81 _i32 sl_RegisterLibsEventHandler(SlEventHandler_e EventHandlerType , SlEventsListNode_t* EventHandlerNode)
82 {
83  EventHandlerNode->next = NULL;
84 
85  if(g_LibsEvents[EventHandlerType] == NULL)
86  {
87  g_LibsEvents[EventHandlerType] = EventHandlerNode;
88  }
89  else
90  {
91  SlEventsListNode_t* currentNode = g_LibsEvents[EventHandlerType];
92  while(currentNode->next != NULL)
93  {
94  currentNode = currentNode->next;
95  }
96 
97  currentNode->next = EventHandlerNode;
98  }
99  return 0;
100 }
101 
102 _i32 sl_UnregisterLibsEventHandler(SlEventHandler_e EventHandlerType , SlEventsListNode_t* EventHandlerNode)
103 {
104  SlEventsListNode_t* currentNode = g_LibsEvents[EventHandlerType];
105  SlEventsListNode_t* lastNode = g_LibsEvents[EventHandlerType];
106  int count = 0;
107  while(currentNode != NULL)
108  {
109  if(EventHandlerNode == currentNode)
110  {
111  if(count == 0)
112  {
113  g_LibsEvents[EventHandlerType] = g_LibsEvents[EventHandlerType]->next;
114  }
115  else
116  {
117  lastNode->next = currentNode->next;
118  }
119  return 0;
120  }
121 
122  if(count != 0)
123  {
124  lastNode = lastNode->next;
125  }
126  count++;
127  currentNode = currentNode->next;
128  }
129 
130  return SL_RET_CODE_EVENT_LINK_NOT_FOUND;
131 }
132 
133 
134 /* Event handlers section */
135 void _SlDeviceFatalErrorEvtHdlr(SlDeviceFatal_t *pSlFatalErrorEvent)
136 {
137  SlEventsListNode_t* currentNode = g_LibsEvents[SL_EVENT_HDL_FATAL_ERROR];
138  while(currentNode != NULL)
139  {
140  if(EVENT_PROPAGATION_BLOCK == ((_pSlPropogationDeviceFatalErrorEvtHdlr_t)(currentNode->event))(pSlFatalErrorEvent))
141  {
142  return;
143  }
144  currentNode = currentNode->next;
145  }
146 
147  if (NULL != g_UserEvents[SL_EVENT_HDL_FATAL_ERROR])
148  {
149  ((_pSlDeviceFatalErrorEvtHdlr_t)g_UserEvents[SL_EVENT_HDL_FATAL_ERROR])(pSlFatalErrorEvent);
150  }
151 
152 #ifdef slcb_DeviceFatalErrorEvtHdlr
153  else
154  {
155  slcb_DeviceFatalErrorEvtHdlr(pSlFatalErrorEvent);
156  }
157 #endif
158 }
159 
160 
161 void _SlDeviceGeneralEvtHdlr(SlDeviceEvent_t *pSlDeviceEvent)
162 {
163  SlEventsListNode_t* currentNode = g_LibsEvents[SL_EVENT_HDL_DEVICE_GENERAL];
164  while(currentNode != NULL)
165  {
166  if(EVENT_PROPAGATION_BLOCK == ((_pSlPropogationDeviceGeneralEvtHdlr_t)(currentNode->event))(pSlDeviceEvent))
167  {
168  return;
169  }
170  currentNode = currentNode->next;
171  }
172 
173  if (NULL != g_UserEvents[SL_EVENT_HDL_DEVICE_GENERAL])
174  {
175  ((_pSlDeviceGeneralEvtHdlr_t)g_UserEvents[SL_EVENT_HDL_DEVICE_GENERAL])(pSlDeviceEvent);
176  }
177 #ifdef slcb_DeviceGeneralEvtHdlr
178  else
179  {
180  slcb_DeviceGeneralEvtHdlr(pSlDeviceEvent);
181  }
182 #endif
183 }
184 
185 
186 void _SlWlanEvtHdlr(SlWlanEvent_t* pSlWlanEvent)
187 {
188  SlEventsListNode_t* currentNode = g_LibsEvents[SL_EVENT_HDL_WLAN];
189  while(currentNode != NULL)
190  {
191  if(EVENT_PROPAGATION_BLOCK == ((_pSlPropogationWlanEvtHdlr)(currentNode->event))(pSlWlanEvent))
192  {
193  return;
194  }
195  currentNode = currentNode->next;
196  }
197 
198  if (NULL != g_UserEvents[SL_EVENT_HDL_WLAN])
199  {
200  ((_pSlWlanEvtHdlr)g_UserEvents[SL_EVENT_HDL_WLAN])(pSlWlanEvent);
201  }
202 #ifdef slcb_WlanEvtHdlr
203  else
204  {
205  slcb_WlanEvtHdlr(pSlWlanEvent);
206  }
207 #endif
208 }
209 
210 
211 void _SlNetAppEvtHdlr(SlNetAppEvent_t* pSlNetAppEvent)
212 {
213  SlEventsListNode_t* currentNode = g_LibsEvents[SL_EVENT_HDL_NETAPP];
214  while(currentNode != NULL)
215  {
216  if(EVENT_PROPAGATION_BLOCK == ((_pSlPropogationNetAppEvtHdlr)(currentNode->event))(pSlNetAppEvent))
217  {
218  return;
219  }
220  currentNode = currentNode->next;
221  }
222  if (NULL != g_UserEvents[SL_EVENT_HDL_NETAPP])
223  {
224  ((_pSlNetAppEvtHdlr)g_UserEvents[SL_EVENT_HDL_NETAPP])(pSlNetAppEvent);
225  }
226 #ifdef slcb_NetAppEvtHdlr
227  else
228  {
229  slcb_NetAppEvtHdlr(pSlNetAppEvent);
230  }
231 #endif
232 }
233 
234 
235 void _SlSockEvtHdlr(SlSockEvent_t* pSlSockEvent)
236 {
237  SlEventsListNode_t* currentNode = g_LibsEvents[SL_EVENT_HDL_SOCKET];
238  while(currentNode != NULL)
239  {
240  if(EVENT_PROPAGATION_BLOCK == ((_pSlPropogationSockEvtHdlr)(currentNode->event))(pSlSockEvent))
241  {
242  return;
243  }
244  currentNode = currentNode->next;
245  }
246  if (NULL != g_UserEvents[SL_EVENT_HDL_SOCKET])
247  {
248  ((_pSlSockEvtHdlr)g_UserEvents[SL_EVENT_HDL_SOCKET])(pSlSockEvent);
249  }
250 
251 #ifdef slcb_SockEvtHdlr
252  else
253  {
254  slcb_SockEvtHdlr(pSlSockEvent);
255  }
256 #endif
257 }
258 
259 
260 void _SlNetAppHttpServerHdlr(SlNetAppHttpServerEvent_t *pSlHttpServerEvent, SlNetAppHttpServerResponse_t *pSlHttpServerResponse)
261 {
262  SlEventsListNode_t* currentNode = g_LibsEvents[SL_EVENT_HDL_HTTP_SERVER];
263  while(currentNode != NULL)
264  {
265  if(EVENT_PROPAGATION_BLOCK == ((_pSlPropogationNetAppHttpServerHdlr)(currentNode->event))(pSlHttpServerEvent,pSlHttpServerResponse))
266  {
267  return;
268  }
269  currentNode = currentNode->next;
270  }
271  if (NULL != g_UserEvents[SL_EVENT_HDL_HTTP_SERVER])
272  {
273  ((_pSlNetAppHttpServerHdlr)g_UserEvents[SL_EVENT_HDL_HTTP_SERVER])(pSlHttpServerEvent,pSlHttpServerResponse);
274  }
275 #ifdef slcb_NetAppHttpServerHdlr
276  else
277  {
278  slcb_NetAppHttpServerHdlr(pSlHttpServerEvent,pSlHttpServerResponse);
279  }
280 #endif
281 }
282 
283 
284 
285 void _SlNetAppRequestHdlr(SlNetAppRequest_t *pNetAppRequest, SlNetAppResponse_t *pNetAppResponse)
286 {
287  SlEventsListNode_t* currentNode = g_LibsEvents[SL_EVENT_HDL_NETAPP_REQUEST];
288  while(currentNode != NULL)
289  {
290  if(EVENT_PROPAGATION_BLOCK == ((_pSlPropogationNetAppRequestHdlr)(currentNode->event))(pNetAppRequest,pNetAppResponse))
291  {
292  return;
293  }
294  currentNode = currentNode->next;
295  }
296  if (NULL != g_UserEvents[SL_EVENT_HDL_NETAPP_REQUEST])
297  {
298  ((_pSlNetAppRequestHdlr)g_UserEvents[SL_EVENT_HDL_NETAPP_REQUEST])(pNetAppRequest,pNetAppResponse);
299  }
300 #ifdef slcb_NetAppRequestHdlr
301  else
302  {
303  slcb_NetAppRequestHdlr(pNetAppRequest,pNetAppResponse);
304  }
305 #endif
306 }
307 
308 
309 
310 void _SlNetAppRequestMemFree (_u8 *buffer)
311 {
312  SlEventsListNode_t* currentNode = g_LibsEvents[SL_EVENT_HDL_MEM_FREE];
313  while(currentNode != NULL)
314  {
315  if(EVENT_PROPAGATION_BLOCK == ((_pSlPropogationNetAppRequestMemFree)(currentNode->event))(buffer))
316  {
317  return;
318  }
319  currentNode = currentNode->next;
320  }
321  if (NULL != g_UserEvents[SL_EVENT_HDL_MEM_FREE])
322  {
323  ((_pSlNetAppRequestMemFree)g_UserEvents[SL_EVENT_HDL_MEM_FREE])(buffer);
324  }
325 #ifdef slcb_NetAppRequestMemFree
326  else
327  {
329  }
330 #endif
331 }
332 
333 
334 
335 void _SlSocketTriggerEventHandler(SlSockTriggerEvent_t* pSlSockTriggerEvent)
336 {
337  SlEventsListNode_t* currentNode = g_LibsEvents[SL_EVENT_HDL_SOCKET_TRIGGER];
338  while(currentNode != NULL)
339  {
340  if(EVENT_PROPAGATION_BLOCK == ((_pSlPropogationSocketTriggerEventHandler)(currentNode->event))(pSlSockTriggerEvent))
341  {
342  return;
343  }
344  currentNode = currentNode->next;
345  }
346  if (NULL != g_UserEvents[SL_EVENT_HDL_SOCKET_TRIGGER])
347  {
348  ((_pSlSocketTriggerEventHandler)g_UserEvents[SL_EVENT_HDL_SOCKET_TRIGGER])(pSlSockTriggerEvent);
349  }
350 #ifdef slcb_SocketTriggerEventHandler
351  else
352  {
353  slcb_SocketTriggerEventHandler(pSlSockTriggerEvent);
354  }
355 #endif
356 }
357 
358 #endif
void slcb_NetAppRequestMemFree(_u8 *buffer)
A handler for freeing the memory of the NetApp response.
void slcb_NetAppRequestHdlr(SlNetAppRequest_t *pNetAppRequest, SlNetAppResponse_t *pNetAppResponse)
General netapp async event.
void slcb_SocketTriggerEventHandler(SlSockTriggerEvent_t *pSlSockTriggerEvent)
Socket trigger routine. This routine will notify the application that a netwrok activity has been com...
void slcb_DeviceFatalErrorEvtHdlr(SlDeviceFatal_t *pSlFatalErrorEvent)
Fatal Error event for inspecting fatal error.
void slcb_SockEvtHdlr(SlSockEvent_t *pSlSockEvent)
Socket Async event handler.
void slcb_WlanEvtHdlr(SlWlanEvent_t *pSlWlanEvent)
WLAN Async event handler.
void slcb_NetAppEvtHdlr(SlNetAppEvent_t *pSlNetAppEvent)
NETAPP Async event handler.
void slcb_NetAppHttpServerHdlr(SlNetAppHttpServerEvent_t *pSlHttpServerEvent, SlNetAppHttpServerResponse_t *pSlHttpServerResponse)
HTTP server async event.
_i32 sl_RegisterEventHandler(SlEventHandler_e EventHandlerType, void *EventHandler)
register events in runtime
Definition: eventreg.c:75
void slcb_DeviceGeneralEvtHdlr(SlDeviceEvent_t *pSlDeviceEvent)
General async event for inspecting general events.