blob: 503812b706b7bf15e5c11ce89985d771d03c8774 (
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
#ifndef TRANSPORT_H
#define TRANSPORT_H
#include <stddef.h>
#ifdef __cplusplus
extern "C"
{
#endif
enum {TRANSPORT_MAX_DATA_LEN = 32};
struct transport_event
{
struct transport_event_common
{
enum transport_event_type
{
TRANSPORT_EVENT_TYPE_CONNECT,
TRANSPORT_EVENT_TYPE_DISCONNECT,
TRANSPORT_EVENT_TYPE_DATA
} type;
} common;
union
{
struct transport_event_data
{
const void *buf;
size_t n;
} data;
} u;
};
union transport_packet;
struct transport_handle
{
struct transport_cfg
{
void *arg;
int (*write)(const void *, size_t, void *);
int (*read)(void *, size_t, void *);
void (*received)(const struct transport_event *, void *);
} cfg;
union transport_packet **packets;
size_t n_packets;
struct transport_input
{
union transport_packet *p;
struct transport_event ev;
} input;
};
int transport_connect(struct transport_handle *h);
int transport_disconnect(struct transport_handle *h);
int transport_send(struct transport_handle *h, const void *buf, size_t n);
int transport_update(struct transport_handle *h);
#ifdef __cplusplus
}
#endif
#endif /* TRANSPORT_H */
|