summaryrefslogtreecommitdiff
path: root/src/message.h
blob: b34bed75ac0829c74c7dd6bf23473720dcbba0cd (plain)
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
#ifndef _MESSAGE_H_
#define _MESSAGE_H_

#include "message_list.h"
#include "mumble.pb-c.h"

enum cmumble_message {
#define MUMBLE_MSG(a,b) a,
	MUMBLE_MSGS
#undef MUMBLE_MSG
};

#define PREAMBLE_SIZE 6
struct mumble_msg_base {
	uint8_t preamble[PREAMBLE_SIZE];
};

struct __attribute__ ((__packed__)) mumble_message {
	struct mumble_msg_base base;
	ProtobufCMessage msg;
};

#define MUMBLE_MSG(cname, name) \
	struct __attribute__ ((__packed__)) mumble_##name { \
		struct mumble_msg_base base; \
		MumbleProto__##cname m; \
	};
MUMBLE_MSGS
#undef MUMBLE_MSG

/* Makro to hide ugly protobuf-c constat names. */
#define MUMBLE_REJECT_TYPE(type) MUMBLE_PROTO__REJECT__REJECT_TYPE__##type


struct cmumble;

void
cmumble_send_msg(struct cmumble *cm, ProtobufCMessage *msg);

int
cmumble_recv_msg(struct cmumble *cm);


#define MUMBLE_MSG(cname, name) \
	static inline void \
	cmumble_init_##name(struct mumble_##name *msg) \
	{ \
		mumble_proto__##name##__init(&msg->m); \
	} \
	\
	static inline void \
	cmumble_send_##name(struct cmumble *cm, struct mumble_##name *msg) \
	{ \
		cmumble_send_msg(cm, &msg->m.base); \
	}
MUMBLE_MSGS
#undef MUMBLE_MSG

#endif /* _MESSAGE_H_ */