add Lua bindings for ubus events
[project/ubus.git] / libubus.h
index a120eb6..f899ded 100644 (file)
--- a/libubus.h
+++ b/libubus.h
@@ -34,6 +34,12 @@ struct ubus_event_handler;
 struct ubus_subscriber;
 struct ubus_notify_request;
 
+static inline struct blob_attr *
+ubus_msghdr_data(struct ubus_msghdr *hdr)
+{
+       return (struct blob_attr *) (hdr + 1);
+}
+
 typedef void (*ubus_lookup_handler_t)(struct ubus_context *ctx,
                                      struct ubus_object_data *obj,
                                      void *priv);
@@ -67,6 +73,12 @@ typedef void (*ubus_notify_complete_handler_t)(struct ubus_notify_request *req,
                .n_policy = ARRAY_SIZE(_policy)         \
        }
 
+#define UBUS_METHOD_NOARG(_name, _handler)             \
+       {                                               \
+               .name = _name,                          \
+               .handler = _handler,                    \
+       }
+
 struct ubus_method {
        const char *name;
        ubus_handler_t handler;
@@ -221,6 +233,13 @@ int ubus_remove_object(struct ubus_context *ctx, struct ubus_object *obj);
 
 /* add a subscriber notifications from another object */
 int ubus_register_subscriber(struct ubus_context *ctx, struct ubus_subscriber *obj);
+
+static inline int
+ubus_unregister_subscriber(struct ubus_context *ctx, struct ubus_subscriber *obj)
+{
+       return ubus_remove_object(ctx, &obj->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);