add stubs for invoke

This commit is contained in:
Felix Fietkau 2011-01-30 23:57:14 +01:00
parent dbd4c2f121
commit 8321f8c523
4 changed files with 46 additions and 5 deletions

17
cli.c
View file

@ -32,7 +32,8 @@ static int usage(char *prog)
fprintf(stderr,
"Usage: %s <command> [arguments...]\n"
"Commands:\n"
" - list [<path>] List objects\n"
" - list [<path>] List objects\n"
" - call <path> <method> [<message>] Call an object method\n"
"\n", prog);
return 1;
}
@ -61,13 +62,21 @@ int main(int argc, char **argv)
ubus_start_request(ctx, &req, b.head, UBUS_MSG_LOOKUP, 0);
req.data_cb = receive_lookup;
ret = ubus_complete_request(ctx, &req);
if (ret)
fprintf(stderr, "Failed: %d\n", ret);
} else if (!strcmp(cmd, "call")) {
if (argc < 4 || argc > 5)
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 {
return usage(argv[0]);
}
ret = ubus_complete_request(ctx, &req);
if (ret)
fprintf(stderr, "Failed: %s\n", ubus_strerror(ret));
ubus_free(ctx);
return 0;
}

View file

@ -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,
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(&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,

View file

@ -130,10 +130,14 @@ void ubus_abort_request(struct ubus_context *ctx, struct ubus_request *req);
/* invoke a method on a specific object */
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 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() */
void ubus_invoke_async(struct ubus_context *ctx, uint32_t obj, const char *method,
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 */
int ubus_publish(struct ubus_context *ctx, struct ubus_object *obj);

View file

@ -161,10 +161,16 @@ static int ubusd_handle_lookup(struct ubus_client *cl, struct ubus_msg_buf *ub)
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] = {
[UBUS_MSG_PING] = ubusd_send_pong,
[UBUS_MSG_PUBLISH] = ubusd_handle_publish,
[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)