Initial import
[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 struct ubus_msg_buf *next;
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 {
29 struct ubus_msghdr hdr;
30 struct blob_attr data;
31 } hdrbuf;
32
33 struct list_head objects;
34
35 int pending_msg_offset;
36 struct ubus_msg_buf *pending_msg;
37
38 unsigned int buf_head_ofs;
39 struct ubus_msg_buf *buf_head;
40 struct ubus_msg_buf **buf_tail;
41
42 struct ubus_msg_buf *requests[UBUSD_CLIENT_BACKLOG];
43 unsigned int req_head, req_tail;
44 };
45
46 struct ubus_path {
47 struct list_head list;
48 const char name[];
49 };
50
51 struct ubus_msg_buf *ubus_msg_new(void *data, int len, bool shared);
52 void ubus_msg_send(struct ubus_client *cl, struct ubus_msg_buf *ub);
53 struct ubus_msg_buf *ubus_msg_ref(struct ubus_msg_buf *ub);
54 void ubus_msg_free(struct ubus_msg_buf *ub);
55
56 struct ubus_client *ubusd_get_client_by_id(uint32_t id);
57
58 void ubusd_receive_message(struct ubus_client *cl, struct ubus_msg_buf *ub);
59 bool ubusd_send_hello(struct ubus_client *cl);
60
61 struct blob_attr **ubus_parse_msg(struct blob_attr *msg);
62
63
64 #endif