X-Git-Url: http://git.archive.openwrt.org/?p=project%2Fubus.git;a=blobdiff_plain;f=libubus.h;h=19a421779c560eff922b036f957d741dbb8b7e7a;hp=e0e418b143921cb5ba7a2b0a74c778cdb0ff6a6b;hb=a69f062cbd4041229f8d29ef9647bf783df414c1;hpb=c0c06ec7ead11ca201bcbf0d1c7e986c7d3c90c0 diff --git a/libubus.h b/libubus.h index e0e418b..19a4217 100644 --- a/libubus.h +++ b/libubus.h @@ -11,6 +11,9 @@ * GNU General Public License for more details. */ +#ifndef __LIBUBUS_H +#define __LIBUBUS_H + #include #include #include @@ -26,6 +29,7 @@ struct ubus_request; struct ubus_request_data; struct ubus_object_data; struct ubus_event_handler; +struct ubus_subscriber; typedef void (*ubus_lookup_handler_t)(struct ubus_context *ctx, struct ubus_object_data *obj, @@ -33,6 +37,9 @@ typedef void (*ubus_lookup_handler_t)(struct ubus_context *ctx, typedef int (*ubus_handler_t)(struct ubus_context *ctx, struct ubus_object *obj, struct ubus_request_data *req, const char *method, struct blob_attr *msg); +typedef void (*ubus_state_handler_t)(struct ubus_context *ctx, struct ubus_object *obj); +typedef void (*ubus_remove_handler_t)(struct ubus_context *ctx, + struct ubus_subscriber *obj, uint32_t id); typedef void (*ubus_event_handler_t)(struct ubus_context *ctx, struct ubus_event_handler *ev, const char *type, struct blob_attr *msg); typedef void (*ubus_data_handler_t)(struct ubus_request *req, @@ -80,10 +87,20 @@ struct ubus_object { const char *path; struct ubus_object_type *type; + ubus_state_handler_t subscribe_cb; + bool has_subscribers; + const struct ubus_method *methods; int n_methods; }; +struct ubus_subscriber { + struct ubus_object obj; + + ubus_handler_t cb; + ubus_remove_handler_t remove_cb; +}; + struct ubus_event_handler { struct ubus_object obj; @@ -120,6 +137,8 @@ struct ubus_request_data { uint32_t object; uint32_t peer; uint32_t seq; + bool deferred; + bool notify; }; struct ubus_request { @@ -144,6 +163,7 @@ struct ubus_request { struct ubus_context *ubus_connect(const char *path); +int ubus_reconnect(struct ubus_context *ctx, const char *path); void ubus_free(struct ubus_context *ctx); const char *ubus_strerror(int error); @@ -185,6 +205,11 @@ int ubus_add_object(struct ubus_context *ctx, struct ubus_object *obj); /* remove the object from the ubus connection */ 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); +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); + /* ----------- rpc ----------- */ /* invoke a method on a specific object */ @@ -200,6 +225,17 @@ int ubus_invoke_async(struct ubus_context *ctx, uint32_t obj, const char *method int ubus_send_reply(struct ubus_context *ctx, struct ubus_request_data *req, struct blob_attr *msg); +static inline void ubus_defer_request(struct ubus_context *ctx, + struct ubus_request_data *req, + struct ubus_request_data *new_req) +{ + memcpy(new_req, req, sizeof(*req)); + req->deferred = true; +} + +void ubus_complete_deferred_request(struct ubus_context *ctx, + struct ubus_request_data *req, int ret); + /* ----------- events ----------- */ int ubus_send_event(struct ubus_context *ctx, const char *id, @@ -214,3 +250,5 @@ static inline int ubus_unregister_event_handler(struct ubus_context *ctx, { return ubus_remove_object(ctx, &ev->obj); } + +#endif