libubus: add monitor support

Signed-off-by: Felix Fietkau <nbd@openwrt.org>
This commit is contained in:
Felix Fietkau 2015-11-19 22:32:25 +01:00
parent 47d75dd84a
commit 44a62711e0
3 changed files with 23 additions and 0 deletions

View file

@ -466,3 +466,9 @@ void __hidden ubus_process_req_msg(struct ubus_context *ctx, struct ubus_msghdr_
break;
}
}
int __ubus_monitor(struct ubus_context *ctx, const char *type)
{
blob_buf_init(&b, 0);
return ubus_invoke(ctx, UBUS_SYSTEM_OBJECT_MONITOR, type, b.head, NULL, NULL, 1000);
}

View file

@ -105,6 +105,10 @@ ubus_process_msg(struct ubus_context *ctx, struct ubus_msghdr_buf *buf, int fd)
ubus_process_obj_msg(ctx, buf);
break;
case UBUS_MSG_MONITOR:
if (ctx->monitor_cb)
ctx->monitor_cb(ctx, buf->hdr.seq, buf->data);
break;
}
}

View file

@ -158,6 +158,7 @@ struct ubus_context {
int stack_depth;
void (*connection_lost)(struct ubus_context *ctx);
void (*monitor_cb)(struct ubus_context *ctx, uint32_t seq, struct blob_attr *data);
struct ubus_msghdr_buf msgbuf;
uint32_t msgbuf_data_len;
@ -290,6 +291,18 @@ ubus_unregister_subscriber(struct ubus_context *ctx, struct ubus_subscriber *obj
int ubus_subscribe(struct ubus_context *ctx, struct ubus_subscriber *obj, uint32_t id);
int ubus_unsubscribe(struct ubus_context *ctx, struct ubus_subscriber *obj, uint32_t id);
int __ubus_monitor(struct ubus_context *ctx, const char *type);
static inline int ubus_monitor_start(struct ubus_context *ctx)
{
return __ubus_monitor(ctx, "add");
}
static inline int ubus_monitor_stop(struct ubus_context *ctx)
{
return __ubus_monitor(ctx, "remove");
}
/* ----------- acl ----------- */