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)
26 strbuf = blobmsg_alloc_string_buffer(&b, "message", 64 + strlen(obj->name));
27 sprintf(strbuf, "%s: Hello, world\n", obj->name);
28 blobmsg_add_string_buffer(&b);
29 ubus_send_reply(ctx, req, b.head);
33 static const struct ubus_method test_methods[] = {
34 { .name = "hello", .handler = test_hello },
37 static struct ubus_object test_object = {
39 .type = &test_object_type,
40 .methods = test_methods,
41 .n_methods = ARRAY_SIZE(test_methods),
44 static struct ubus_object test_object2 = {
46 .type = &test_object_type,
47 .methods = test_methods,
48 .n_methods = ARRAY_SIZE(test_methods),
51 int main(int argc, char **argv)
55 ctx = ubus_connect(NULL);
57 fprintf(stderr, "Failed to connect to ubus\n");
61 fprintf(stderr, "Connected as ID 0x%08x\n", ctx->local_id);
63 fprintf(stderr, "Publishing object\n");
64 ret = ubus_publish(ctx, &test_object);
66 fprintf(stderr, "Failed to publish object: %s\n", ubus_strerror(ret));
68 fprintf(stderr, "Object ID: %08x\n", test_object.id);
69 fprintf(stderr, "Object Type ID: %08x\n", test_object.type->id);
72 fprintf(stderr, "Publishing object\n");
73 ret = ubus_publish(ctx, &test_object2);
75 fprintf(stderr, "Failed to publish object: %s\n", ubus_strerror(ret));
77 fprintf(stderr, "Object ID: %08x\n", test_object2.id);
78 fprintf(stderr, "Object Type ID: %08x\n", test_object2.type->id);