blob: 571f61dfdb1034da0c4f0598d72df558b559c39a (
plain) (
blame)
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
|
#pragma once
#include <assert.h>
#include <stdarg.h>
#define EVENT_HANDLER_MAX_ARGC 10
typedef void (*argv_callback)(void **argv);
typedef struct message {
argv_callback handler;
void *argv[EVENT_HANDLER_MAX_ARGC];
} Event;
typedef void (*event_scheduler)(Event event, void *data);
#define VA_EVENT_INIT(event, h, a) \
do { \
assert(a <= EVENT_HANDLER_MAX_ARGC); \
(event)->handler = h; \
if (a) { \
va_list args; \
va_start(args, a); \
for (int i = 0; i < a; i++) { \
(event)->argv[i] = va_arg(args, void *); \
} \
va_end(args); \
} \
} while (0)
static inline Event event_create(argv_callback cb, int argc, ...)
{
assert(argc <= EVENT_HANDLER_MAX_ARGC);
Event event;
VA_EVENT_INIT(&event, cb, argc);
return event;
}
|