-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcmd_handlers_invoker.c
More file actions
47 lines (41 loc) · 1.07 KB
/
cmd_handlers_invoker.c
File metadata and controls
47 lines (41 loc) · 1.07 KB
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
/**
* @file cmd_handlers_invoker.c
* @copyright 2022 Silicon Laboratories Inc.
*/
#include "cmd_handlers.h"
#include <assert.h>
/**
* This is the first of the registered handlers
*/
extern const cmd_handler_map_t __start_zw_cmd_handlers;
#define cmd_handlers_start __start_zw_cmd_handlers
/**
* This marks the end of the handlers. The element
* after the last element. This means that this element
* is not valid.
*/
extern const cmd_handler_map_t __stop_zw_cmd_handlers;
#define cmd_handlers_stop __stop_zw_cmd_handlers
bool invoke_cmd_handler(const comm_interface_frame_ptr frame)
{
cmd_handler_map_t const * iter = &cmd_handlers_start;
for ( ; iter < &cmd_handlers_stop; ++iter)
{
if (iter->cmd == frame->cmd) {
iter->pHandler(frame);
return true;
}
}
return false;
}
void cmd_foreach(cmd_foreach_callback_t callback, cmd_context_t context)
{
assert(callback != NULL);
cmd_handler_map_t const * iter = &cmd_handlers_start;
for ( ; iter < &cmd_handlers_stop; ++iter)
{
if (true == callback(iter, context)) {
break;
}
}
}