libubus: replace __init with __constructor
[project/ubus.git] / ubusd.h
1 /*
2 * Copyright (C) 2011-2014 Felix Fietkau <nbd@openwrt.org>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License version 2.1
6 * as published by the Free Software Foundation
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 */
13
14 #ifndef __UBUSD_H
15 #define __UBUSD_H
16
17 #include <libubox/list.h>
18 #include <libubox/uloop.h>
19 #include <libubox/blobmsg.h>
20 #include "ubus_common.h"
21 #include "ubusd_id.h"
22 #include "ubusd_obj.h"
23 #include "ubusmsg.h"
24
25 #define UBUSD_CLIENT_BACKLOG 32
26 #define UBUS_OBJ_HASH_BITS 4
27
28 extern struct blob_buf b;
29
30 struct ubus_msg_buf {
31 uint32_t refcount; /* ~0: uses external data buffer */
32 struct ubus_msghdr hdr;
33 struct blob_attr *data;
34 int fd;
35 int len;
36 };
37
38 struct ubus_client {
39 struct ubus_id id;
40 struct uloop_fd sock;
41
42 struct list_head objects;
43
44 struct ubus_msg_buf *tx_queue[UBUSD_CLIENT_BACKLOG];
45 unsigned int txq_cur, txq_tail, txq_ofs;
46
47 struct ubus_msg_buf *pending_msg;
48 int pending_msg_offset;
49 int pending_msg_fd;
50 struct {
51 struct ubus_msghdr hdr;
52 struct blob_attr data;
53 } hdrbuf;
54 };
55
56 struct ubus_path {
57 struct list_head list;
58 const char name[];
59 };
60
61 struct ubus_msg_buf *ubus_msg_new(void *data, int len, bool shared);
62 void ubus_msg_send(struct ubus_client *cl, struct ubus_msg_buf *ub, bool free);
63 void ubus_msg_free(struct ubus_msg_buf *ub);
64
65 struct ubus_client *ubusd_proto_new_client(int fd, uloop_fd_handler cb);
66 void ubusd_proto_receive_message(struct ubus_client *cl, struct ubus_msg_buf *ub);
67 void ubusd_proto_free_client(struct ubus_client *cl);
68
69 void ubusd_event_init(void);
70 void ubusd_event_cleanup_object(struct ubus_object *obj);
71 void ubusd_send_obj_event(struct ubus_object *obj, bool add);
72
73
74 #endif