3 static struct ubus_context *ctx;
6 static const struct ubus_signature test_object_sig[] = {
7 UBUS_METHOD_START("hello"),
9 UBUS_TABLE_START(NULL),
10 UBUS_FIELD(INT32, "id"),
11 UBUS_FIELD(STRING, "msg"),
16 static struct ubus_object_type test_object_type =
17 UBUS_OBJECT_TYPE("test", test_object_sig);
19 static int test_hello(struct ubus_context *ctx, struct ubus_object *obj,
20 struct ubus_request_data *req, const char *method,
21 struct blob_attr *msg)
24 blobmsg_add_string(&b, "message", "Hello, world!\n");
25 ubus_send_reply(ctx, req, b.head);
29 static const struct ubus_method test_methods[] = {
30 { .name = "hello", .handler = test_hello },
33 static struct ubus_object test_object = {
35 .type = &test_object_type,
36 .methods = test_methods,
37 .n_methods = ARRAY_SIZE(test_methods),
40 static struct ubus_object test_object2 = {
42 .type = &test_object_type,
43 .methods = test_methods,
44 .n_methods = ARRAY_SIZE(test_methods),
47 int main(int argc, char **argv)
51 ctx = ubus_connect(NULL);
53 fprintf(stderr, "Failed to connect to ubus\n");
57 fprintf(stderr, "Connected as ID 0x%08x\n", ctx->local_id);
59 fprintf(stderr, "Publishing object\n");
60 ret = ubus_publish(ctx, &test_object);
62 fprintf(stderr, "Failed to publish object: %s\n", ubus_strerror(ret));
64 fprintf(stderr, "Object ID: %08x\n", test_object.id);
65 fprintf(stderr, "Object Type ID: %08x\n", test_object.type->id);
68 fprintf(stderr, "Publishing object\n");
69 ret = ubus_publish(ctx, &test_object2);
71 fprintf(stderr, "Failed to publish object: %s\n", ubus_strerror(ret));
73 fprintf(stderr, "Object ID: %08x\n", test_object2.id);
74 fprintf(stderr, "Object Type ID: %08x\n", test_object2.type->id);