From: Felix Fietkau Date: Thu, 19 Nov 2015 21:32:25 +0000 (+0100) Subject: libubus: add monitor support X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=44a62711e0136a4a34f37d0b779c9c831818f9a4;p=oweals%2Fubus.git libubus: add monitor support Signed-off-by: Felix Fietkau --- diff --git a/libubus-req.c b/libubus-req.c index 2197f2a..bf19f36 100644 --- a/libubus-req.c +++ b/libubus-req.c @@ -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); +} diff --git a/libubus.c b/libubus.c index e1e68d0..bfbaeb6 100644 --- a/libubus.c +++ b/libubus.c @@ -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; } } diff --git a/libubus.h b/libubus.h index 5c5f8de..54e7d48 100644 --- a/libubus.h +++ b/libubus.h @@ -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 ----------- */