ubus: add notification for subscribers present/gone
[project/ubus.git] / ubusd_proto.c
index 59920ed7f9a8c79355244a26b0bd92a5e9d4ed50..283cb771b8cda759126aad0890bb2d8ab73f8775 100644 (file)
@@ -416,6 +416,20 @@ void ubusd_proto_free_client(struct ubus_client *cl)
        ubus_free_id(&clients, &cl->id);
 }
 
+void ubus_notify_subscription(struct ubus_object *obj)
+{
+       bool active = !list_empty(&obj->subscribers);
+       struct ubus_msg_buf *ub;
+
+       blob_buf_init(&b, 0);
+       blob_put_int32(&b, UBUS_ATTR_OBJID, obj->id.id);
+       blob_put_int8(&b, UBUS_ATTR_ACTIVE, active);
+
+       ub = ubus_msg_from_blob(false);
+       ubus_msg_init(ub, UBUS_MSG_NOTIFY, ++obj->invoke_seq, 0);
+       ubus_msg_send(obj->client, ub, true);
+}
+
 void ubus_notify_unsubscribe(struct ubus_subscription *s)
 {
        struct ubus_msg_buf *ub;