implement event pattern matching
[project/ubus.git] / ubusd_obj.h
1 #ifndef __UBUSD_OBJ_H
2 #define __UBUSD_OBJ_H
3
4 #include "ubusd_id.h"
5
6 extern struct avl_tree obj_types;
7 extern struct avl_tree objects;
8 extern struct avl_tree path;
9
10 struct ubus_client;
11 struct ubus_msg_buf;
12
13 struct ubus_object_type {
14 struct ubus_id id;
15 int refcount;
16 struct list_head methods;
17 };
18
19 struct ubus_method {
20 struct list_head list;
21 const char *name;
22 struct blob_attr data[];
23 };
24
25 struct ubus_object {
26 struct ubus_id id;
27 struct list_head list;
28
29 struct list_head events;
30
31 struct ubus_object_type *type;
32 struct avl_node path;
33
34 struct ubus_client *client;
35 int (*recv_msg)(struct ubus_client *client, const char *method, struct blob_attr *msg);
36
37 int event_seen;
38 };
39
40 struct ubus_object *ubusd_create_object(struct ubus_client *cl, struct blob_attr **attr);
41 struct ubus_object *ubusd_create_object_internal(struct ubus_object_type *type, uint32_t id);
42 void ubusd_free_object(struct ubus_object *obj);
43
44 static inline struct ubus_object *ubusd_find_object(uint32_t objid)
45 {
46 struct ubus_object *obj;
47 struct ubus_id *id;
48
49 id = ubus_find_id(&objects, objid);
50 if (!id)
51 return NULL;
52
53 obj = container_of(id, struct ubus_object, id);
54 return obj;
55 }
56
57 #endif