-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathevent.c
More file actions
48 lines (41 loc) · 974 Bytes
/
event.c
File metadata and controls
48 lines (41 loc) · 974 Bytes
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
#include "event.h"
#include "xeno.h"
#define MAX_EVENT_LISTENERS 16
static event_t event;
static event_data_t event_funcs[MAX_EVENT_LISTENERS];
static uint32_t event_func_counter;
void
b_event_clear() {
x_mem_set(&event, 0, sizeof(event_t));
event_func_counter = 0;
}
int
b_event_register(event_kind_t kind,
event_func_t event_func) {
if (event_func_counter < MAX_EVENT_LISTENERS)
{
event_funcs[event_func_counter++] = (event_data_t){ kind, event_func };
return 1;
}
return 0;
}
event_t*
b_event_handle_get() {
return &event;
}
void
b_event_dispatch(event_kind_t kind) {
b_event_dispatch_ext(kind, &event);
}
void
b_event_dispatch_ext(event_kind_t kind, event_t* e) {
e->kind = kind;
int i;
for(i = 0; i < event_func_counter; i++)
{
if (event_funcs[i].kind == kind)
{
event_funcs[i].func(e);
}
}
}