3 static void receive_lookup(struct ubus_context
*ctx
, struct ubus_object_data
*obj
, void *priv
)
9 fprintf(stderr
, "'%s' @%08x\n", obj
->path
, obj
->id
);
14 blob_for_each_attr(cur
, obj
->signature
, rem
) {
15 s
= blobmsg_format_json(cur
, false);
16 fprintf(stderr
, "\t%s\n", s
);
21 static void receive_data(struct ubus_request
*req
, int type
, struct blob_attr
*msg
)
26 fprintf(stderr
, "%s\n", blobmsg_format_json(msg
, true));
30 static int usage(char *prog
)
33 "Usage: %s <command> [arguments...]\n"
35 " - list [<path>] List objects\n"
36 " - call <path> <method> [<message>] Call an object method\n"
37 " - listen [<path>...] Listen for events\n"
42 int main(int argc
, char **argv
)
44 static struct ubus_context
*ctx
;
48 ctx
= ubus_connect(NULL
);
50 fprintf(stderr
, "Failed to connect to ubus\n");
56 return usage(argv
[0]);
58 if (!strcmp(cmd
, "list")) {
59 const char *path
= NULL
;
64 ret
= ubus_lookup(ctx
, path
, receive_lookup
, NULL
);
65 } else if (!strcmp(cmd
, "call")) {
68 if (argc
< 4 || argc
> 5)
69 return usage(argv
[0]);
71 ret
= ubus_lookup_id(ctx
, argv
[2], &id
);
73 ret
= ubus_invoke(ctx
, id
, argv
[3], NULL
, receive_data
, NULL
);
74 } else if (!strcmp(cmd
, "listen")) {
75 ret
= ubus_invoke(ctx
, UBUS_SYSTEM_OBJECT_EVENT
, "listen", NULL
, receive_data
, NULL
);
77 return usage(argv
[0]);
81 fprintf(stderr
, "Failed: %s\n", ubus_strerror(ret
));