X-Git-Url: http://git.archive.openwrt.org/?p=project%2Fubus.git;a=blobdiff_plain;f=libubus.c;h=03899d6db44e766513053e0eb65a5acee27cc6ee;hp=bcaf63dc377f4a158a1cda98b70997f69e077ff4;hb=d366a6de839087d8a17e5855c14ae55e95b13c65;hpb=43d6047c400041e4783a76017d21b763df988d92 diff --git a/libubus.c b/libubus.c index bcaf63d..03899d6 100644 --- a/libubus.c +++ b/libubus.c @@ -228,6 +228,10 @@ void __hidden ubus_process_msg(struct ubus_context *ctx, struct ubus_msghdr *hdr ubus_process_invoke(ctx, hdr); } break; + + case UBUS_MSG_UNSUBSCRIBE: + ubus_process_unsubscribe(ctx, hdr); + break; } } @@ -514,81 +518,6 @@ int ubus_register_event_handler(struct ubus_context *ctx, NULL, NULL, 0); } -enum { - WATCH_ID, - WATCH_NOTIFY, - __WATCH_MAX -}; - -static const struct blobmsg_policy watch_policy[] = { - [WATCH_ID] = { .name = "id", .type = BLOBMSG_TYPE_INT32 }, - [WATCH_NOTIFY] = { .name = "notify", .type = BLOBMSG_TYPE_STRING }, -}; - - -static int ubus_watch_cb(struct ubus_context *ctx, struct ubus_object *obj, - struct ubus_request_data *req, - const char *method, struct blob_attr *msg) -{ - struct ubus_watch_object *w; - struct blob_attr *tb[__WATCH_MAX]; - - blobmsg_parse(watch_policy, ARRAY_SIZE(watch_policy), tb, blob_data(msg), blob_len(msg)); - - if (!tb[WATCH_ID] || !tb[WATCH_NOTIFY]) - return UBUS_STATUS_INVALID_ARGUMENT; - - if (req->peer) - return UBUS_STATUS_INVALID_ARGUMENT; - - w = container_of(obj, struct ubus_watch_object, obj); - w->cb(ctx, w, blobmsg_get_u32(tb[WATCH_ID])); - return 0; -} - -static const struct ubus_method watch_method = { - .name = NULL, - .handler = ubus_watch_cb, -}; - -int ubus_register_watch_object(struct ubus_context *ctx, struct ubus_watch_object *w_obj) -{ - struct ubus_object *obj = &w_obj->obj; - - obj->methods = &watch_method; - obj->n_methods = 1; - - return ubus_add_object(ctx, obj); -} - -static int -__ubus_watch_request(struct ubus_context *ctx, struct ubus_object *obj, uint32_t id, const char *method, int type) -{ - struct ubus_request req; - - blob_buf_init(&b, 0); - blob_put_int32(&b, UBUS_ATTR_OBJID, obj->id); - blob_put_int32(&b, UBUS_ATTR_TARGET, id); - if (method) - blob_put_string(&b, UBUS_ATTR_METHOD, method); - - if (ubus_start_request(ctx, &req, b.head, type, 0) < 0) - return UBUS_STATUS_INVALID_ARGUMENT; - - return ubus_complete_request(ctx, &req, 0); - -} - -int ubus_watch_object_add(struct ubus_context *ctx, struct ubus_watch_object *obj, uint32_t id) -{ - return __ubus_watch_request(ctx, &obj->obj, id, "event", UBUS_MSG_ADD_WATCH); -} - -int ubus_watch_object_remove(struct ubus_context *ctx, struct ubus_watch_object *obj, uint32_t id) -{ - return __ubus_watch_request(ctx, &obj->obj, id, NULL, UBUS_MSG_REMOVE_WATCH); -} - int ubus_send_event(struct ubus_context *ctx, const char *id, struct blob_attr *data) {