add stubs for invoke
This commit is contained in:
parent
dbd4c2f121
commit
8321f8c523
4 changed files with 46 additions and 5 deletions
17
cli.c
17
cli.c
|
@ -32,7 +32,8 @@ static int usage(char *prog)
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
"Usage: %s <command> [arguments...]\n"
|
"Usage: %s <command> [arguments...]\n"
|
||||||
"Commands:\n"
|
"Commands:\n"
|
||||||
" - list [<path>] List objects\n"
|
" - list [<path>] List objects\n"
|
||||||
|
" - call <path> <method> [<message>] Call an object method\n"
|
||||||
"\n", prog);
|
"\n", prog);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
@ -61,13 +62,21 @@ int main(int argc, char **argv)
|
||||||
|
|
||||||
ubus_start_request(ctx, &req, b.head, UBUS_MSG_LOOKUP, 0);
|
ubus_start_request(ctx, &req, b.head, UBUS_MSG_LOOKUP, 0);
|
||||||
req.data_cb = receive_lookup;
|
req.data_cb = receive_lookup;
|
||||||
ret = ubus_complete_request(ctx, &req);
|
} else if (!strcmp(cmd, "call")) {
|
||||||
if (ret)
|
if (argc < 4 || argc > 5)
|
||||||
fprintf(stderr, "Failed: %d\n", ret);
|
return usage(argv[0]);
|
||||||
|
|
||||||
|
blob_put_string(&b, UBUS_ATTR_OBJPATH, argv[2]);
|
||||||
|
blob_put_string(&b, UBUS_ATTR_METHOD, argv[3]);
|
||||||
|
ubus_start_request(ctx, &req, b.head, UBUS_MSG_INVOKE, 0);
|
||||||
} else {
|
} else {
|
||||||
return usage(argv[0]);
|
return usage(argv[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ret = ubus_complete_request(ctx, &req);
|
||||||
|
if (ret)
|
||||||
|
fprintf(stderr, "Failed: %s\n", ubus_strerror(ret));
|
||||||
|
|
||||||
ubus_free(ctx);
|
ubus_free(ctx);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
24
libubus.c
24
libubus.c
|
@ -314,6 +314,28 @@ skip:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ubus_invoke_path_async(struct ubus_context *ctx, const char *path, const char *method,
|
||||||
|
struct blob_attr *msg, struct ubus_request *req)
|
||||||
|
{
|
||||||
|
blob_buf_init(&b, 0);
|
||||||
|
blob_put_string(&b, UBUS_ATTR_OBJPATH, path);
|
||||||
|
blob_put_string(&b, UBUS_ATTR_METHOD, method);
|
||||||
|
blob_put(&b, UBUS_ATTR_DATA, blob_data(msg), blob_len(msg));
|
||||||
|
|
||||||
|
ubus_start_request(ctx, req, b.head, UBUS_MSG_INVOKE, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
int ubus_invoke_path(struct ubus_context *ctx, const char *path, const char *method,
|
||||||
|
struct blob_attr *msg, ubus_data_handler_t cb, void *priv)
|
||||||
|
{
|
||||||
|
struct ubus_request req;
|
||||||
|
|
||||||
|
ubus_invoke_path_async(ctx, path, method, msg, &req);
|
||||||
|
req.data_cb = cb;
|
||||||
|
req.priv = priv;
|
||||||
|
return ubus_complete_request(ctx, &req);
|
||||||
|
}
|
||||||
|
|
||||||
void ubus_invoke_async(struct ubus_context *ctx, uint32_t obj, const char *method,
|
void ubus_invoke_async(struct ubus_context *ctx, uint32_t obj, const char *method,
|
||||||
struct blob_attr *msg, struct ubus_request *req)
|
struct blob_attr *msg, struct ubus_request *req)
|
||||||
{
|
{
|
||||||
|
@ -322,7 +344,7 @@ void ubus_invoke_async(struct ubus_context *ctx, uint32_t obj, const char *metho
|
||||||
blob_put_string(&b, UBUS_ATTR_METHOD, method);
|
blob_put_string(&b, UBUS_ATTR_METHOD, method);
|
||||||
blob_put(&b, UBUS_ATTR_DATA, blob_data(msg), blob_len(msg));
|
blob_put(&b, UBUS_ATTR_DATA, blob_data(msg), blob_len(msg));
|
||||||
|
|
||||||
ubus_start_request(ctx, req, b.head, UBUS_MSG_INVOKE, obj);
|
ubus_start_request(ctx, req, b.head, UBUS_MSG_INVOKE, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
int ubus_invoke(struct ubus_context *ctx, uint32_t obj, const char *method,
|
int ubus_invoke(struct ubus_context *ctx, uint32_t obj, const char *method,
|
||||||
|
|
|
@ -130,10 +130,14 @@ void ubus_abort_request(struct ubus_context *ctx, struct ubus_request *req);
|
||||||
/* invoke a method on a specific object */
|
/* invoke a method on a specific object */
|
||||||
int ubus_invoke(struct ubus_context *ctx, uint32_t obj, const char *method,
|
int ubus_invoke(struct ubus_context *ctx, uint32_t obj, const char *method,
|
||||||
struct blob_attr *msg, ubus_data_handler_t cb, void *priv);
|
struct blob_attr *msg, ubus_data_handler_t cb, void *priv);
|
||||||
|
int ubus_invoke_path(struct ubus_context *ctx, const char *path, const char *method,
|
||||||
|
struct blob_attr *msg, ubus_data_handler_t cb, void *priv);
|
||||||
|
|
||||||
/* asynchronous version of ubus_invoke() */
|
/* asynchronous version of ubus_invoke() */
|
||||||
void ubus_invoke_async(struct ubus_context *ctx, uint32_t obj, const char *method,
|
void ubus_invoke_async(struct ubus_context *ctx, uint32_t obj, const char *method,
|
||||||
struct blob_attr *msg, struct ubus_request *req);
|
struct blob_attr *msg, struct ubus_request *req);
|
||||||
|
void ubus_invoke_path_async(struct ubus_context *ctx, const char *path, const char *method,
|
||||||
|
struct blob_attr *msg, struct ubus_request *req);
|
||||||
|
|
||||||
/* make an object visible to remote connections */
|
/* make an object visible to remote connections */
|
||||||
int ubus_publish(struct ubus_context *ctx, struct ubus_object *obj);
|
int ubus_publish(struct ubus_context *ctx, struct ubus_object *obj);
|
||||||
|
|
|
@ -161,10 +161,16 @@ static int ubusd_handle_lookup(struct ubus_client *cl, struct ubus_msg_buf *ub)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int ubusd_handle_invoke(struct ubus_client *cl, struct ubus_msg_buf *ub)
|
||||||
|
{
|
||||||
|
return UBUS_STATUS_NOT_FOUND;
|
||||||
|
}
|
||||||
|
|
||||||
static const ubus_cmd_cb handlers[__UBUS_MSG_LAST] = {
|
static const ubus_cmd_cb handlers[__UBUS_MSG_LAST] = {
|
||||||
[UBUS_MSG_PING] = ubusd_send_pong,
|
[UBUS_MSG_PING] = ubusd_send_pong,
|
||||||
[UBUS_MSG_PUBLISH] = ubusd_handle_publish,
|
[UBUS_MSG_PUBLISH] = ubusd_handle_publish,
|
||||||
[UBUS_MSG_LOOKUP] = ubusd_handle_lookup,
|
[UBUS_MSG_LOOKUP] = ubusd_handle_lookup,
|
||||||
|
[UBUS_MSG_INVOKE] = ubusd_handle_invoke,
|
||||||
};
|
};
|
||||||
|
|
||||||
void ubusd_receive_message(struct ubus_client *cl, struct ubus_msg_buf *ub)
|
void ubusd_receive_message(struct ubus_client *cl, struct ubus_msg_buf *ub)
|
||||||
|
|
Loading…
Reference in a new issue