1 #include <libubox/list.h>
2 #include <libubox/blobmsg.h>
3 #include <libubox/uloop.h>
6 #include "ubus_common.h"
11 struct ubus_request_data;
13 typedef void (*ubus_handler_t)(struct ubus_object *obj,
14 struct ubus_request_data *req,
15 const char *method, struct blob_attr *msg);
16 typedef void (*ubus_data_handler_t)(struct ubus_request *req,
17 int type, struct blob_attr *msg);
18 typedef void (*ubus_complete_handler_t)(struct ubus_request *req, int ret);
21 #define UBUS_SIGNATURE(_type, _name) { .type = _type, .name = _name }
23 #define UBUS_METHOD_START(_name) UBUS_SIGNATURE(UBUS_SIGNATURE_METHOD, _name)
24 #define UBUS_METHOD_END() UBUS_SIGNATURE(UBUS_SIGNATURE_END, NULL)
26 #define UBUS_FIELD(_type, _name) UBUS_SIGNATURE(BLOBMSG_TYPE_ ## _type, _name)
28 #define UBUS_ARRAY(_name) UBUS_FIELD(ARRAY, _name)
29 #define UBUS_ARRAY_END() UBUS_SIGNATURE(UBUS_SIGNATURE_END, NULL)
31 #define UBUS_TABLE_START(_name) UBUS_FIELD(TABLE, _name)
32 #define UBUS_TABLE_END() UBUS_SIGNATURE(UBUS_SIGNATURE_END, NULL)
34 #define UBUS_OBJECT_TYPE(_name, _signature) \
38 .n_signature = ARRAY_SIZE(_signature), \
39 .signature = _signature \
42 struct ubus_signature {
43 enum blobmsg_type type;
47 struct ubus_object_type {
51 const struct ubus_signature *signature;
59 struct ubus_object *parent;
61 struct ubus_object_type *type;
65 struct list_head requests;
66 struct list_head objects;
73 struct ubus_msghdr hdr;
74 char data[UBUS_MAX_MSGLEN - sizeof(struct ubus_msghdr)];
78 struct ubus_request_data {
85 struct list_head list;
87 struct list_head pending;
95 ubus_data_handler_t data_cb;
96 ubus_complete_handler_t complete_cb;
101 #define BLOBMSG_END_TABLE BLOBMSG_TYPE_UNSPEC
103 struct ubus_context *ubus_connect(const char *path);
104 void ubus_free(struct ubus_context *ctx);
106 const char *ubus_strerror(int error);
108 /* ----------- helpers for message handling ----------- */
110 struct blob_attr **ubus_parse_msg(struct blob_attr *msg);
112 /* ----------- raw request handling ----------- */
114 /* start a raw request */
115 int ubus_start_request(struct ubus_context *ctx, struct ubus_request *req,
116 struct blob_attr *msg, int cmd, uint32_t peer);
118 /* wait for a request to complete and return its status */
119 int ubus_complete_request(struct ubus_context *ctx, struct ubus_request *req);
121 /* complete a request asynchronously */
122 void ubus_complete_request_async(struct ubus_context *ctx,
123 struct ubus_request *req);
125 /* abort an asynchronous request */
126 void ubus_abort_request(struct ubus_context *ctx, struct ubus_request *req);
128 /* ----------- rpc ----------- */
130 /* invoke a method on a specific object */
131 int ubus_invoke(struct ubus_context *ctx, uint32_t obj, const char *method,
132 struct blob_attr *msg, ubus_data_handler_t cb, void *priv);
133 int ubus_invoke_path(struct ubus_context *ctx, const char *path, const char *method,
134 struct blob_attr *msg, ubus_data_handler_t cb, void *priv);
136 /* asynchronous version of ubus_invoke() */
137 void ubus_invoke_async(struct ubus_context *ctx, uint32_t obj, const char *method,
138 struct blob_attr *msg, struct ubus_request *req);
139 void ubus_invoke_path_async(struct ubus_context *ctx, const char *path, const char *method,
140 struct blob_attr *msg, struct ubus_request *req);
142 /* make an object visible to remote connections */
143 int ubus_publish(struct ubus_context *ctx, struct ubus_object *obj);