From: Felix Fietkau Date: Sun, 30 Jan 2011 22:57:14 +0000 (+0100) Subject: add stubs for invoke X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=8321f8c523c9bf5f476f9c5b06c955d0ce3a0f80;p=oweals%2Fubus.git add stubs for invoke --- diff --git a/cli.c b/cli.c index ba6f30f..bc884cd 100644 --- a/cli.c +++ b/cli.c @@ -32,7 +32,8 @@ static int usage(char *prog) fprintf(stderr, "Usage: %s [arguments...]\n" "Commands:\n" - " - list [] List objects\n" + " - list [] List objects\n" + " - call [] 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; } diff --git a/libubus.c b/libubus.c index 5fdde30..9e93aed 100644 --- a/libubus.c +++ b/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, 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, diff --git a/libubus.h b/libubus.h index bd3d736..3da5d21 100644 --- a/libubus.h +++ b/libubus.h @@ -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); diff --git a/ubusd_proto.c b/ubusd_proto.c index a202ace..8a69541 100644 --- a/ubusd_proto.c +++ b/ubusd_proto.c @@ -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)