-
Notifications
You must be signed in to change notification settings - Fork 9
/
i_tiny_event_queue.h
48 lines (38 loc) · 1.27 KB
/
i_tiny_event_queue.h
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
/*!
* @file
* @brief Abstract event queue.
*
* Allows event callbacks and data to be queued for later processing.
*/
#ifndef i_tiny_event_queue_h
#define i_tiny_event_queue_h
#include <stdint.h>
typedef void (*tiny_event_queue_callback_t)(void);
typedef void (*tiny_event_queue_callback_with_data_t)(const void* data);
struct i_tiny_event_queue_api_t;
typedef struct {
const struct i_tiny_event_queue_api_t* api;
} i_tiny_event_queue_t;
typedef struct i_tiny_event_queue_api_t {
/*!
* Enqueues an event to be raised later by invoking the provided callback.
*/
void (*enqueue)(
i_tiny_event_queue_t* self,
tiny_event_queue_callback_t callback);
/*!
* Enqueues an event with data to be raised later by invoking the provided callback.
*
* @note data is copied and does not have to remain valid after the call
*/
void (*enqueue_with_data)(
i_tiny_event_queue_t* self,
tiny_event_queue_callback_with_data_t callback,
const void* data,
uint8_t data_size);
} i_tiny_event_queue_api_t;
#define tiny_event_queue_enqueue(self, callback) \
(self)->api->enqueue((self), (callback))
#define tiny_event_queue_enqueue_with_data(self, callback, data, data_size) \
(self)->api->enqueue_with_data((self), (callback), (data), (data_size))
#endif