X-Git-Url: http://git.archive.openwrt.org/?a=blobdiff_plain;f=libubus.h;h=17c49527095dc09084daf6b2e458a496e22f87b7;hb=d366a6de839087d8a17e5855c14ae55e95b13c65;hp=917d1221e3d2808a3b3ec5daaa8cbfa1e01bba37;hpb=34161692fae8a5d81bc73e8005effd1fd13aa412;p=project%2Fubus.git diff --git a/libubus.h b/libubus.h index 917d122..17c4952 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,7 +29,7 @@ struct ubus_request; struct ubus_request_data; struct ubus_object_data; struct ubus_event_handler; -struct ubus_watch_object; +struct ubus_subscriber; typedef void (*ubus_lookup_handler_t)(struct ubus_context *ctx, struct ubus_object_data *obj, @@ -34,10 +37,10 @@ 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_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_watch_handler_t)(struct ubus_context *ctx, struct ubus_watch_object *w, - uint32_t id); typedef void (*ubus_data_handler_t)(struct ubus_request *req, int type, struct blob_attr *msg); typedef void (*ubus_complete_handler_t)(struct ubus_request *req, int ret); @@ -87,10 +90,11 @@ struct ubus_object { int n_methods; }; -struct ubus_watch_object { +struct ubus_subscriber { struct ubus_object obj; - ubus_watch_handler_t cb; + ubus_handler_t cb; + ubus_remove_handler_t remove_cb; }; struct ubus_event_handler { @@ -129,6 +133,7 @@ struct ubus_request_data { uint32_t object; uint32_t peer; uint32_t seq; + bool deferred; }; struct ubus_request { @@ -195,12 +200,10 @@ 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 an object for watching other object state changes */ -int ubus_register_watch_object(struct ubus_context *ctx, struct ubus_watch_object *obj); - -int ubus_watch_object_add(struct ubus_context *ctx, struct ubus_watch_object *obj, uint32_t id); - -int ubus_watch_object_remove(struct ubus_context *ctx, struct ubus_watch_object *obj, uint32_t id); +/* 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 ----------- */ @@ -217,6 +220,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, @@ -231,3 +245,5 @@ static inline int ubus_unregister_event_handler(struct ubus_context *ctx, { return ubus_remove_object(ctx, &ev->obj); } + +#endif