move more protocol related stuff to ubusd_proto.c
[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 UBUSD_CLIENT_BACKLOG 32
13 #define UBUS_OBJ_HASH_BITS 4
14
15 extern struct blob_buf b;
16
17 struct ubus_msg_buf {
18 uint32_t refcount; /* ~0: uses external data buffer */
19 struct ubus_msghdr hdr;
20 struct blob_attr *data;
21 int len;
22 };
23
24 struct ubus_client {
25 struct ubus_id id;
26 struct uloop_fd sock;
27
28 struct list_head objects;
29
30 struct ubus_msg_buf *tx_queue[UBUSD_CLIENT_BACKLOG];
31 unsigned int txq_cur, txq_tail, txq_ofs;
32
33 struct ubus_msg_buf *pending_msg;
34 int pending_msg_offset;
35 struct {
36 struct ubus_msghdr hdr;
37 struct blob_attr data;
38 } hdrbuf;
39 };
40
41 struct ubus_path {
42 struct list_head list;
43 const char name[];
44 };
45
46 struct ubus_msg_buf *ubus_msg_new(void *data, int len, bool shared);
47 void ubus_msg_send(struct ubus_client *cl, struct ubus_msg_buf *ub, bool free);
48 void ubus_msg_free(struct ubus_msg_buf *ub);
49
50 struct ubus_client *ubusd_proto_new_client(int fd, uloop_fd_handler cb);
51 void ubusd_proto_receive_message(struct ubus_client *cl, struct ubus_msg_buf *ub);
52 void ubusd_proto_free_client(struct ubus_client *cl);
53
54 void ubusd_event_init(void);
55 void ubusd_event_cleanup_object(struct ubus_object *obj);
56
57
58 #endif