From: Felix Fietkau Date: Sun, 6 Feb 2011 20:46:45 +0000 (+0100) Subject: add ubus_remove_object to libubus X-Git-Url: http://git.archive.openwrt.org/?p=project%2Fubus.git;a=commitdiff_plain;h=d2f1a01d9f6b49d7353dc848018c176400091741;hp=d2f9e766ffc818610262d44e0cb02b1f73d71a1f;ds=sidebyside add ubus_remove_object to libubus --- diff --git a/libubus.c b/libubus.c index d4ba427..3050509 100644 --- a/libubus.c +++ b/libubus.c @@ -646,6 +646,43 @@ int ubus_add_object(struct ubus_context *ctx, struct ubus_object *obj) return __ubus_add_object(ctx, obj); } +static void ubus_remove_object_cb(struct ubus_request *req, int type, struct blob_attr *msg) +{ + struct ubus_object *obj = req->priv; + + ubus_parse_msg(msg); + + if (!attrbuf[UBUS_ATTR_OBJID]) + return; + + obj->id = 0; + + if (attrbuf[UBUS_ATTR_OBJTYPE] && obj->type) + obj->type->id = 0; + + avl_delete(&req->ctx->objects, &obj->avl); +} + +int ubus_remove_object(struct ubus_context *ctx, struct ubus_object *obj) +{ + struct ubus_request req; + int ret; + + blob_buf_init(&b, 0); + blob_put_int32(&b, UBUS_ATTR_OBJID, obj->id); + ubus_start_request(ctx, &req, b.head, UBUS_MSG_REMOVE_OBJECT, 0); + req.raw_data_cb = ubus_remove_object_cb; + req.priv = obj; + ret = ubus_complete_request(ctx, &req); + if (ret) + return ret; + + if (obj->id) + return UBUS_STATUS_NO_DATA; + + return 0; +} + static int ubus_event_cb(struct ubus_context *ctx, struct ubus_object *obj, struct ubus_request_data *req, const char *method, struct blob_attr *msg) diff --git a/libubus.h b/libubus.h index bab919f..6ca7d9d 100644 --- a/libubus.h +++ b/libubus.h @@ -177,6 +177,9 @@ void ubus_invoke_async(struct ubus_context *ctx, uint32_t obj, const char *metho /* make an object visible to remote connections */ int ubus_add_object(struct ubus_context *ctx, struct ubus_object *obj); +/* remove the object from the ubus connection */ +int ubus_remove_object(struct ubus_context *ctx, struct ubus_object *obj); + /* send a reply to an incoming object method call */ int ubus_send_reply(struct ubus_context *ctx, struct ubus_request_data *req, struct blob_attr *msg);