+enum {
+ WATCH_ID,
+ __WATCH_MAX
+};
+
+static const struct blobmsg_policy watch_policy[__WATCH_MAX] = {
+ [WATCH_ID] = { .name = "id", .type = BLOBMSG_TYPE_INT32 },
+};
+
+static void test_handle_event(struct ubus_context *ctx, struct ubus_watch_object *w,
+ uint32_t id)
+{
+ fprintf(stderr, "Object %08x went away\n", id);
+}
+
+static int test_watch(struct ubus_context *ctx, struct ubus_object *obj,
+ struct ubus_request_data *req, const char *method,
+ struct blob_attr *msg)
+{
+ struct blob_attr *tb[__WATCH_MAX];
+ int ret;
+
+ blobmsg_parse(watch_policy, __WATCH_MAX, tb, blob_data(msg), blob_len(msg));
+ if (!tb[WATCH_ID])
+ return UBUS_STATUS_INVALID_ARGUMENT;
+
+ test_event.cb = test_handle_event;
+ ret = ubus_watch_object_add(ctx, &test_event, blobmsg_get_u32(tb[WATCH_ID]));
+ fprintf(stderr, "Watching object %08x: %s\n", blobmsg_get_u32(tb[WATCH_ID]), ubus_strerror(ret));
+ return ret;
+}
+