3 static struct ubus_context
*ctx
;
5 static const struct ubus_signature test_object_sig
[] = {
6 UBUS_METHOD_START("hello"),
8 UBUS_TABLE_START(NULL
),
9 UBUS_FIELD(INT32
, "id"),
10 UBUS_FIELD(STRING
, "msg"),
15 static struct ubus_object_type test_object_type
=
16 UBUS_OBJECT_TYPE("test", test_object_sig
);
18 static int test_hello(struct ubus_object
*obj
, struct ubus_request_data
*req
,
19 const char *method
, struct blob_attr
*msg
)
21 fprintf(stderr
, "Hello, world!\n");
25 static const struct ubus_method test_methods
[] = {
26 { .name
= "hello", .handler
= test_hello
},
29 static struct ubus_object test_object
= {
31 .type
= &test_object_type
,
32 .methods
= test_methods
,
33 .n_methods
= ARRAY_SIZE(test_methods
),
36 static struct ubus_object test_object2
= {
38 .type
= &test_object_type
,
39 .methods
= test_methods
,
40 .n_methods
= ARRAY_SIZE(test_methods
),
43 int main(int argc
, char **argv
)
47 ctx
= ubus_connect(NULL
);
49 fprintf(stderr
, "Failed to connect to ubus\n");
53 fprintf(stderr
, "Connected as ID 0x%08x\n", ctx
->local_id
);
55 fprintf(stderr
, "Publishing object\n");
56 ret
= ubus_publish(ctx
, &test_object
);
58 fprintf(stderr
, "Failed to publish object: %s\n", ubus_strerror(ret
));
60 fprintf(stderr
, "Object ID: %08x\n", test_object
.id
);
61 fprintf(stderr
, "Object Type ID: %08x\n", test_object
.type
->id
);
64 fprintf(stderr
, "Publishing object\n");
65 ret
= ubus_publish(ctx
, &test_object2
);
67 fprintf(stderr
, "Failed to publish object: %s\n", ubus_strerror(ret
));
69 fprintf(stderr
, "Object ID: %08x\n", test_object2
.id
);
70 fprintf(stderr
, "Object Type ID: %08x\n", test_object2
.type
->id
);
73 uloop_fd_add(&ctx
->sock
, ULOOP_READ
| ULOOP_EDGE_TRIGGER
);