X-Git-Url: http://git.archive.openwrt.org/?p=project%2Fubus.git;a=blobdiff_plain;f=libubus.h;h=4e45cb620a28befe23c27d3b8dc7eb1a1d12fb1a;hp=54e7d481b0496e719f2f567b664a2619c82a3b16;hb=91acde66b963e238aba35fb4f2030a147df84cd4;hpb=44a62711e0136a4a34f37d0b779c9c831818f9a4 diff --git a/libubus.h b/libubus.h index 54e7d48..4e45cb6 100644 --- a/libubus.h +++ b/libubus.h @@ -155,6 +155,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 +189,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 +210,8 @@ struct ubus_request { ubus_fd_handler_t fd_cb; ubus_complete_handler_t complete_cb; + int fd; + struct ubus_context *ctx; void *priv; }; @@ -240,6 +244,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) @@ -322,13 +332,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, @@ -338,6 +361,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; } @@ -345,9 +369,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);