CMakeLists.txt: bump minimum cmake version
[project/ubus.git] / libubus.h
index ea532720a8fe07513392636d4c05881750f05eba..b74a82348e6c5fedb02805db626cfdce406cb060 100644 (file)
--- a/libubus.h
+++ b/libubus.h
 #ifndef __LIBUBUS_H
 #define __LIBUBUS_H
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 #include <libubox/avl.h>
 #include <libubox/list.h>
 #include <libubox/blobmsg.h>
@@ -56,7 +60,10 @@ typedef void (*ubus_fd_handler_t)(struct ubus_request *req, int fd);
 typedef void (*ubus_complete_handler_t)(struct ubus_request *req, int ret);
 typedef void (*ubus_notify_complete_handler_t)(struct ubus_notify_request *req,
                                               int idx, int ret);
+typedef void (*ubus_notify_data_handler_t)(struct ubus_notify_request *req,
+                                          int type, struct blob_attr *msg);
 typedef void (*ubus_connect_handler_t)(struct ubus_context *ctx);
+typedef bool (*ubus_new_object_handler_t)(struct ubus_context *ctx, struct ubus_subscriber *sub, const char *path);
 
 #define UBUS_OBJECT_TYPE(_name, _methods)              \
        {                                               \
@@ -133,10 +140,12 @@ struct ubus_object {
 };
 
 struct ubus_subscriber {
+       struct list_head list;
        struct ubus_object obj;
 
        ubus_handler_t cb;
        ubus_remove_handler_t remove_cb;
+       ubus_new_object_handler_t new_obj_cb;
 };
 
 struct ubus_event_handler {
@@ -155,6 +164,7 @@ struct ubus_context {
 
        uint32_t local_id;
        uint16_t request_seq;
+       bool cancel_poll;
        int stack_depth;
 
        void (*connection_lost)(struct ubus_context *ctx);
@@ -163,6 +173,9 @@ struct ubus_context {
        struct ubus_msghdr_buf msgbuf;
        uint32_t msgbuf_data_len;
        int msgbuf_reduction_counter;
+
+       struct list_head auto_subscribers;
+       struct ubus_event_handler auto_subscribe_event_handler;
 };
 
 struct ubus_object_data {
@@ -220,6 +233,7 @@ struct ubus_notify_request {
 
        ubus_notify_complete_handler_t status_cb;
        ubus_notify_complete_handler_t complete_cb;
+       ubus_notify_data_handler_t data_cb;
 
        uint32_t pending;
        uint32_t id[UBUS_MAX_NOTIFY_PEERS + 1];
@@ -294,6 +308,8 @@ int ubus_register_subscriber(struct ubus_context *ctx, struct ubus_subscriber *o
 static inline int
 ubus_unregister_subscriber(struct ubus_context *ctx, struct ubus_subscriber *obj)
 {
+       if (!list_empty(&obj->list))
+               list_del_init(&obj->list);
        return ubus_remove_object(ctx, &obj->obj);
 }
 
@@ -410,4 +426,8 @@ static inline int ubus_unregister_event_handler(struct ubus_context *ctx,
     return ubus_remove_object(ctx, &ev->obj);
 }
 
+#ifdef __cplusplus
+}
+#endif
+
 #endif