From 0611a9248c525c472fd3ff0f067cfb051c0b4962 Mon Sep 17 00:00:00 2001 From: Felix Fietkau Date: Thu, 10 Feb 2011 01:31:52 +0100 Subject: [PATCH] add notifications for registered/unregistered objects with path --- ubusd.h | 1 + ubusd_event.c | 24 ++++++++++++++++++++++++ ubusd_obj.c | 2 ++ 3 files changed, 27 insertions(+) diff --git a/ubusd.h b/ubusd.h index 30f9f7d..abe26b7 100644 --- a/ubusd.h +++ b/ubusd.h @@ -53,6 +53,7 @@ void ubusd_proto_free_client(struct ubus_client *cl); void ubusd_event_init(void); void ubusd_event_cleanup_object(struct ubus_object *obj); +void ubusd_send_obj_event(struct ubus_object *obj, bool add); #endif diff --git a/ubusd_event.c b/ubusd_event.c index 4045fdc..aae2e0d 100644 --- a/ubusd_event.c +++ b/ubusd_event.c @@ -269,6 +269,30 @@ static int ubusd_event_recv(struct ubus_client *cl, const char *method, struct b return UBUS_STATUS_INVALID_COMMAND; } +static struct ubus_msg_buf * +ubusd_create_object_event_msg(void *priv, const char *id) +{ + struct ubus_object *obj = priv; + void *s; + + blob_buf_init(&b, 0); + blob_put_int32(&b, UBUS_ATTR_OBJID, 0); + blob_put_string(&b, UBUS_ATTR_METHOD, id); + s = blob_nest_start(&b, UBUS_ATTR_DATA); + blobmsg_add_u32(&b, "id", obj->id.id); + blobmsg_add_string(&b, "path", obj->path.key); + blob_nest_end(&b, s); + + return ubus_msg_new(b.head, blob_raw_len(b.head), true); +} + +void ubusd_send_obj_event(struct ubus_object *obj, bool add) +{ + const char *id = add ? "ubus.object.add" : "ubus.object.remove"; + + ubusd_send_event(NULL, id, ubusd_create_object_event_msg, obj); +} + void ubusd_event_init(void) { ubus_init_string_tree(&patterns, true); diff --git a/ubusd_obj.c b/ubusd_obj.c index d1e53f8..2d78796 100644 --- a/ubusd_obj.c +++ b/ubusd_obj.c @@ -139,6 +139,7 @@ struct ubus_object *ubusd_create_object(struct ubus_client *cl, struct blob_attr obj->path.key = NULL; goto free; } + ubusd_send_obj_event(obj, true); } obj->client = cl; @@ -155,6 +156,7 @@ void ubusd_free_object(struct ubus_object *obj) { ubusd_event_cleanup_object(obj); if (obj->path.key) { + ubusd_send_obj_event(obj, false); avl_delete(&path, &obj->path); free(obj->path.key); } -- 2.30.2