fix message buffering
[project/ubus.git] / ubusd.h
1 #ifndef __UBUSD_H
2 #define __UBUSD_H
3
4 #include <libubox/list.h>
5 #include <libubox/uloop.h>
6 #include <libubox/blobmsg.h>
7 #include "ubus_common.h"
8 #include "ubusd_id.h"
9 #include "ubusd_obj.h"
10 #include "ubusmsg.h"
11
12 #define UBUS_UNIX_SOCKET "./ubus.sock"
13 #define UBUSD_CLIENT_BACKLOG 32
14 #define UBUS_OBJ_HASH_BITS 4
15
16 struct ubus_msg_buf {
17 uint32_t refcount; /* ~0: uses external data buffer */
18 struct ubus_msghdr hdr;
19 struct blob_attr *data;
20 int len;
21 };
22
23 struct ubus_client {
24 struct ubus_id id;
25 struct uloop_fd sock;
26
27 struct list_head objects;
28
29 struct ubus_msg_buf *tx_queue[UBUSD_CLIENT_BACKLOG];
30 unsigned int txq_cur, txq_tail, txq_ofs;
31
32 struct ubus_msg_buf *pending_msg;
33 int pending_msg_offset;
34 struct {
35 struct ubus_msghdr hdr;
36 struct blob_attr data;
37 } hdrbuf;
38 };
39
40 struct ubus_path {
41 struct list_head list;
42 const char name[];
43 };
44
45 struct ubus_msg_buf *ubus_msg_new(void *data, int len, bool shared);
46 void ubus_msg_send(struct ubus_client *cl, struct ubus_msg_buf *ub, bool free);
47 struct ubus_msg_buf *ubus_msg_ref(struct ubus_msg_buf *ub);
48 void ubus_msg_free(struct ubus_msg_buf *ub);
49
50 struct ubus_client *ubusd_get_client_by_id(uint32_t id);
51
52 void ubusd_receive_message(struct ubus_client *cl, struct ubus_msg_buf *ub);
53 bool ubusd_send_hello(struct ubus_client *cl);
54
55 struct blob_attr **ubus_parse_msg(struct blob_attr *msg);
56
57 void ubusd_event_init(void);
58 void ubusd_event_cleanup_object(struct ubus_object *obj);
59
60
61 #endif