make the socket non-blocking, explicitly wait for data using poll()
[project/ubus.git] / ubusd_obj.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_OBJ_H
15 #define __UBUSD_OBJ_H
16
17 #include "ubusd_id.h"
18
19 extern struct avl_tree obj_types;
20 extern struct avl_tree objects;
21 extern struct avl_tree path;
22
23 struct ubus_client;
24 struct ubus_msg_buf;
25
26 struct ubus_object_type {
27         struct ubus_id id;
28         int refcount;
29         struct list_head methods;
30 };
31
32 struct ubus_method {
33         struct list_head list;
34         const char *name;
35         struct blob_attr data[];
36 };
37
38 struct ubus_object {
39         struct ubus_id id;
40         struct list_head list;
41
42         struct list_head events;
43
44         struct ubus_object_type *type;
45         struct avl_node path;
46
47         struct ubus_client *client;
48         int (*recv_msg)(struct ubus_client *client, const char *method, struct blob_attr *msg);
49
50         int event_seen;
51 };
52
53 struct ubus_object *ubusd_create_object(struct ubus_client *cl, struct blob_attr **attr);
54 struct ubus_object *ubusd_create_object_internal(struct ubus_object_type *type, uint32_t id);
55 void ubusd_free_object(struct ubus_object *obj);
56
57 static inline struct ubus_object *ubusd_find_object(uint32_t objid)
58 {
59         struct ubus_object *obj;
60         struct ubus_id *id;
61
62         id = ubus_find_id(&objects, objid);
63         if (!id)
64                 return NULL;
65
66         obj = container_of(id, struct ubus_object, id);
67         return obj;
68 }
69
70 #endif