-
Notifications
You must be signed in to change notification settings - Fork 7
/
i_tiny_message_bus.h
43 lines (32 loc) · 1.03 KB
/
i_tiny_message_bus.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
/*!
* @file
* @brief Synchronously sends messages from publishers to all subscribers.
*/
#ifndef i_tiny_message_bus_h
#define i_tiny_message_bus_h
#include <stdint.h>
#include "i_tiny_event.h"
typedef uint16_t tiny_message_bus_message_t;
typedef struct {
tiny_message_bus_message_t message;
const void* data;
} tiny_message_bus_on_receive_args_t;
struct i_tiny_message_bus_api_t;
typedef struct {
const struct i_tiny_message_bus_api_t* api;
} i_tiny_message_bus_t;
typedef struct i_tiny_message_bus_api_t {
/*!
* Sends a message to all subscribers on the bus.
*/
void (*send)(i_tiny_message_bus_t* self, tiny_message_bus_message_t message, const void* data);
/*!
* Returns the event that clients can use to subscribe to received messages.
*/
i_tiny_event_t* (*on_receive)(i_tiny_message_bus_t* self);
} i_tiny_message_bus_api_t;
#define tiny_message_bus_send(self, message, data) \
(self)->api->send((self), (message), (data))
#define tiny_message_bus_on_receive(self) \
(self)->api->on_receive((self))
#endif