add copyright/license information
[project/ubus.git] / ubusd.h
1 /*
2 * Copyright (C) 2011 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 len;
35 };
36
37 struct ubus_client {
38 struct ubus_id id;
39 struct uloop_fd sock;
40
41 struct list_head objects;
42
43 struct ubus_msg_buf *tx_queue[UBUSD_CLIENT_BACKLOG];
44 unsigned int txq_cur, txq_tail, txq_ofs;
45
46 struct ubus_msg_buf *pending_msg;
47 int pending_msg_offset;
48 struct {
49 struct ubus_msghdr hdr;
50 struct blob_attr data;
51 } hdrbuf;
52 };
53
54 struct ubus_path {
55 struct list_head list;
56 const char name[];
57 };
58
59 struct ubus_msg_buf *ubus_msg_new(void *data, int len, bool shared);
60 void ubus_msg_send(struct ubus_client *cl, struct ubus_msg_buf *ub, bool free);
61 void ubus_msg_free(struct ubus_msg_buf *ub);
62
63 struct ubus_client *ubusd_proto_new_client(int fd, uloop_fd_handler cb);
64 void ubusd_proto_receive_message(struct ubus_client *cl, struct ubus_msg_buf *ub);
65 void ubusd_proto_free_client(struct ubus_client *cl);
66
67 void ubusd_event_init(void);
68 void ubusd_event_cleanup_object(struct ubus_object *obj);
69 void ubusd_send_obj_event(struct ubus_object *obj, bool add);
70
71
72 #endif