-
Notifications
You must be signed in to change notification settings - Fork 7
/
i_tiny_comm.h
50 lines (38 loc) · 1.02 KB
/
i_tiny_comm.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
49
50
/*!
* @file
* @brief Abstract packet-based communication interface.
*/
#ifndef i_tiny_comm_h
#define i_tiny_comm_h
#include <stdbool.h>
#include <stdint.h>
#include "i_tiny_event.h"
typedef struct {
const void* payload;
uint8_t length;
} tiny_comm_on_receive_args_t;
struct i_tiny_comm_api_t;
typedef struct {
const struct i_tiny_comm_api_t* api;
} i_tiny_comm_t;
typedef struct i_tiny_comm_api_t {
/*!
* Sends a message. Only valid when sending() is false.
*/
void (*send)(i_tiny_comm_t* self, const void* payload, uint8_t length);
/*!
* Indicates whether a message is currently being sent.
*/
bool (*sending)(i_tiny_comm_t* self);
/*!
* Event raised when a message is received.
*/
i_tiny_event_t* (*on_receive)(i_tiny_comm_t* self);
} i_tiny_comm_api_t;
#define tiny_comm_send(self, payload, length) \
(self)->api->send((self), (payload), (length))
#define tiny_comm_sending(self) \
(self)->api->sending((self))
#define tiny_comm_on_receive(self) \
(self)->api->on_receive((self))
#endif