1 #include <libubox/avl.h>
2 #include <libubox/list.h>
3 #include <libubox/blobmsg.h>
4 #include <libubox/uloop.h>
7 #include "ubus_common.h"
13 struct ubus_request_data
;
14 struct ubus_object_data
;
16 typedef void (*ubus_lookup_handler_t
)(struct ubus_context
*ctx
,
17 struct ubus_object_data
*obj
,
19 typedef int (*ubus_handler_t
)(struct ubus_context
*ctx
, struct ubus_object
*obj
,
20 struct ubus_request_data
*req
,
21 const char *method
, struct blob_attr
*msg
);
22 typedef void (*ubus_data_handler_t
)(struct ubus_request
*req
,
23 int type
, struct blob_attr
*msg
);
24 typedef void (*ubus_complete_handler_t
)(struct ubus_request
*req
, int ret
);
27 #define UBUS_SIGNATURE(_type, _name) { .type = _type, .name = _name }
29 #define UBUS_METHOD_START(_name) UBUS_SIGNATURE(UBUS_SIGNATURE_METHOD, _name)
30 #define UBUS_METHOD_END() UBUS_SIGNATURE(UBUS_SIGNATURE_END, NULL)
32 #define UBUS_FIELD(_type, _name) UBUS_SIGNATURE(BLOBMSG_TYPE_ ## _type, _name)
34 #define UBUS_ARRAY(_name) UBUS_FIELD(ARRAY, _name)
35 #define UBUS_ARRAY_END() UBUS_SIGNATURE(UBUS_SIGNATURE_END, NULL)
37 #define UBUS_TABLE_START(_name) UBUS_FIELD(TABLE, _name)
38 #define UBUS_TABLE_END() UBUS_SIGNATURE(UBUS_SIGNATURE_END, NULL)
40 #define UBUS_OBJECT_TYPE(_name, _signature) \
44 .n_signature = ARRAY_SIZE(_signature), \
45 .signature = _signature \
48 struct ubus_signature
{
49 enum blobmsg_type type
;
53 struct ubus_object_type
{
57 const struct ubus_signature
*signature
;
62 ubus_handler_t handler
;
72 struct ubus_object_type
*type
;
74 const struct ubus_method
*methods
;
79 struct list_head requests
;
80 struct avl_tree objects
;
87 void (*connection_lost
)(struct ubus_context
*ctx
);
90 struct ubus_msghdr hdr
;
91 char data
[UBUS_MAX_MSGLEN
- sizeof(struct ubus_msghdr
)];
95 struct ubus_object_data
{
99 struct blob_attr
*signature
;
102 struct ubus_request_data
{
108 struct ubus_request
{
109 struct list_head list
;
111 struct list_head pending
;
120 ubus_data_handler_t raw_data_cb
;
121 ubus_data_handler_t data_cb
;
122 ubus_complete_handler_t complete_cb
;
124 struct ubus_context
*ctx
;
128 #define BLOBMSG_END_TABLE BLOBMSG_TYPE_UNSPEC
130 struct ubus_context
*ubus_connect(const char *path
);
131 void ubus_free(struct ubus_context
*ctx
);
133 const char *ubus_strerror(int error
);
135 /* ----------- raw request handling ----------- */
137 /* wait for a request to complete and return its status */
138 int ubus_complete_request(struct ubus_context
*ctx
, struct ubus_request
*req
);
140 /* complete a request asynchronously */
141 void ubus_complete_request_async(struct ubus_context
*ctx
,
142 struct ubus_request
*req
);
144 /* abort an asynchronous request */
145 void ubus_abort_request(struct ubus_context
*ctx
, struct ubus_request
*req
);
147 /* ----------- objects ----------- */
149 int ubus_lookup(struct ubus_context
*ctx
, const char *path
,
150 ubus_lookup_handler_t cb
, void *priv
);
152 int ubus_lookup_id(struct ubus_context
*ctx
, const char *path
, uint32_t *id
);
154 /* ----------- rpc ----------- */
156 /* invoke a method on a specific object */
157 int ubus_invoke(struct ubus_context
*ctx
, uint32_t obj
, const char *method
,
158 struct blob_attr
*msg
, ubus_data_handler_t cb
, void *priv
);
160 /* asynchronous version of ubus_invoke() */
161 void ubus_invoke_async(struct ubus_context
*ctx
, uint32_t obj
, const char *method
,
162 struct blob_attr
*msg
, struct ubus_request
*req
);
164 /* make an object visible to remote connections */
165 int ubus_publish(struct ubus_context
*ctx
, struct ubus_object
*obj
);
167 /* send a reply to an incoming object method call */
168 int ubus_send_reply(struct ubus_context
*ctx
, struct ubus_request_data
*req
,
169 struct blob_attr
*msg
);