X-Git-Url: http://git.openwrt.org/?a=blobdiff_plain;f=libubus.h;h=b74a82348e6c5fedb02805db626cfdce406cb060;hb=HEAD;hp=5c5f8de3cf012b6879fcad37af63880ab1c25922;hpb=8309c75828acbcee73b11d9ce90d76b7ef14b891;p=project%2Fubus.git diff --git a/libubus.h b/libubus.h index 5c5f8de..b74a823 100644 --- a/libubus.h +++ b/libubus.h @@ -14,6 +14,10 @@ #ifndef __LIBUBUS_H #define __LIBUBUS_H +#ifdef __cplusplus +extern "C" { +#endif + #include #include #include @@ -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,13 +164,18 @@ struct ubus_context { uint32_t local_id; uint16_t request_seq; + bool cancel_poll; int stack_depth; void (*connection_lost)(struct ubus_context *ctx); + void (*monitor_cb)(struct ubus_context *ctx, uint32_t seq, struct blob_attr *data); 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 { @@ -187,6 +201,7 @@ struct ubus_request_data { /* internal use */ bool deferred; int fd; + int req_fd; /* fd received from the initial request */ }; struct ubus_request { @@ -207,6 +222,8 @@ struct ubus_request { ubus_fd_handler_t fd_cb; ubus_complete_handler_t complete_cb; + int fd; + struct ubus_context *ctx; void *priv; }; @@ -216,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]; @@ -239,6 +257,12 @@ void ubus_free(struct ubus_context *ctx); /* call this only for struct ubus_context pointers initialised by ubus_connect_ctx() */ void ubus_shutdown(struct ubus_context *ctx); +static inline void ubus_auto_shutdown(struct ubus_auto_conn *conn) +{ + uloop_timeout_cancel(&conn->timer); + ubus_shutdown(&conn->ctx); +} + const char *ubus_strerror(int error); static inline void ubus_add_uloop(struct ubus_context *ctx) @@ -284,12 +308,26 @@ 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); } 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); +int __ubus_monitor(struct ubus_context *ctx, const char *type); + +static inline int ubus_monitor_start(struct ubus_context *ctx) +{ + return __ubus_monitor(ctx, "add"); +} + +static inline int ubus_monitor_stop(struct ubus_context *ctx) +{ + return __ubus_monitor(ctx, "remove"); +} + /* ----------- acl ----------- */ @@ -309,13 +347,26 @@ int ubus_register_acl(struct ubus_context *ctx); /* ----------- rpc ----------- */ /* invoke a method on a specific object */ -int ubus_invoke(struct ubus_context *ctx, uint32_t obj, const char *method, +int ubus_invoke_fd(struct ubus_context *ctx, uint32_t obj, const char *method, struct blob_attr *msg, ubus_data_handler_t cb, void *priv, - int timeout); + int timeout, int fd); +static inline int +ubus_invoke(struct ubus_context *ctx, uint32_t obj, const char *method, + struct blob_attr *msg, ubus_data_handler_t cb, void *priv, + int timeout) +{ + return ubus_invoke_fd(ctx, obj, method, msg, cb, priv, timeout, -1); +} /* asynchronous version of ubus_invoke() */ -int ubus_invoke_async(struct ubus_context *ctx, uint32_t obj, const char *method, - struct blob_attr *msg, struct ubus_request *req); +int ubus_invoke_async_fd(struct ubus_context *ctx, uint32_t obj, const char *method, + struct blob_attr *msg, struct ubus_request *req, int fd); +static inline int +ubus_invoke_async(struct ubus_context *ctx, uint32_t obj, const char *method, + struct blob_attr *msg, struct ubus_request *req) +{ + return ubus_invoke_async_fd(ctx, obj, method, msg, req, -1); +} /* send a reply to an incoming object method call */ int ubus_send_reply(struct ubus_context *ctx, struct ubus_request_data *req, @@ -325,6 +376,7 @@ static inline void ubus_defer_request(struct ubus_context *ctx, struct ubus_request_data *req, struct ubus_request_data *new_req) { + (void) ctx; memcpy(new_req, req, sizeof(*req)); req->deferred = true; } @@ -332,9 +384,18 @@ static inline void ubus_defer_request(struct ubus_context *ctx, static inline void ubus_request_set_fd(struct ubus_context *ctx, struct ubus_request_data *req, int fd) { + (void) ctx; req->fd = fd; } +static inline int ubus_request_get_caller_fd(struct ubus_request_data *req) +{ + int fd = req->req_fd; + req->req_fd = -1; + + return fd; +} + void ubus_complete_deferred_request(struct ubus_context *ctx, struct ubus_request_data *req, int ret); @@ -365,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