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;
}
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;
}
}
}
+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)
{
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,
/* 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);
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)