X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=libubus.h;h=dc42ea78171a14608716911390676025ef9f80fd;hb=5f87f5480ebf004d735dbf44259d08cf8affd305;hp=1b219b7f9e4520208408957ce477ccee0af7a6db;hpb=6a86e65f7d4836bfe387d213a6dfaea1d5d162dd;p=oweals%2Fubus.git diff --git a/libubus.h b/libubus.h index 1b219b7..dc42ea7 100644 --- a/libubus.h +++ b/libubus.h @@ -56,6 +56,8 @@ 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); #define UBUS_OBJECT_TYPE(_name, _methods) \ @@ -155,6 +157,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); @@ -188,6 +191,7 @@ struct ubus_request_data { /* internal use */ bool deferred; int fd; + int req_fd; /* fd received from the initial request */ }; struct ubus_request { @@ -208,6 +212,8 @@ struct ubus_request { ubus_fd_handler_t fd_cb; ubus_complete_handler_t complete_cb; + int fd; + struct ubus_context *ctx; void *priv; }; @@ -217,6 +223,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]; @@ -328,13 +335,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, @@ -344,6 +364,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; } @@ -351,9 +372,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);