Merge Ubus with the 2016.02.26 version.
This commit is contained in:
@@ -92,34 +92,37 @@ static void test_count(struct uloop_timeout *timeout)
|
||||
COUNT_TO_MAX = 1000000,
|
||||
PROGRESSION = 100,
|
||||
};
|
||||
|
||||
|
||||
uint32_t id;
|
||||
static uint32_t count_to = 100000;
|
||||
static int count_progression = PROGRESSION;
|
||||
char *s;
|
||||
|
||||
|
||||
if (count_to <= COUNT_TO_MIN)
|
||||
count_progression = PROGRESSION;
|
||||
else if (count_to >= COUNT_TO_MAX)
|
||||
count_progression = -PROGRESSION;
|
||||
|
||||
|
||||
count_to += count_progression;
|
||||
|
||||
|
||||
s = count_to_number(count_to);
|
||||
if (!s)
|
||||
if (!s) {
|
||||
fprintf(stderr, "Could not allocate memory to count up to '%u'\n", count_to);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
fprintf(stderr, "Sending count up to '%u'; string has length '%u'\n",
|
||||
count_to, (uint32_t)strlen(s));
|
||||
blob_buf_init(&b, 0);
|
||||
blobmsg_add_u32(&b, "to", count_to);
|
||||
blobmsg_add_string(&b, "string", s);
|
||||
|
||||
|
||||
if (ubus_lookup_id(ctx, "test", &id)) {
|
||||
free(s);
|
||||
fprintf(stderr, "Failed to look up test object\n");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
ubus_invoke(ctx, id, "count", b.head, test_count_data_cb, &count_to, 5000);
|
||||
|
||||
free(s);
|
||||
@@ -173,30 +176,30 @@ static void client_main(void)
|
||||
static struct ubus_request req;
|
||||
uint32_t id;
|
||||
int ret;
|
||||
|
||||
|
||||
ret = ubus_add_object(ctx, &test_client_object);
|
||||
if (ret) {
|
||||
fprintf(stderr, "Failed to add_object object: %s\n", ubus_strerror(ret));
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if (ubus_lookup_id(ctx, "test", &id)) {
|
||||
fprintf(stderr, "Failed to look up test object\n");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
blob_buf_init(&b, 0);
|
||||
blobmsg_add_u32(&b, "id", test_client_object.id);
|
||||
ubus_invoke(ctx, id, "watch", b.head, NULL, 0, 3000);
|
||||
test_client_notify_cb(¬ify_timer);
|
||||
|
||||
|
||||
blob_buf_init(&b, 0);
|
||||
blobmsg_add_string(&b, "msg", "blah");
|
||||
ubus_invoke_async(ctx, id, "hello", b.head, &req);
|
||||
req.fd_cb = test_client_fd_cb;
|
||||
req.complete_cb = test_client_complete_cb;
|
||||
ubus_complete_request_async(ctx, &req);
|
||||
|
||||
|
||||
uloop_timeout_set(&count_timer, 2000);
|
||||
|
||||
uloop_run();
|
||||
@@ -206,7 +209,7 @@ int main(int argc, char **argv)
|
||||
{
|
||||
const char *ubus_socket = NULL;
|
||||
int ch;
|
||||
|
||||
|
||||
while ((ch = getopt(argc, argv, "cs:")) != -1) {
|
||||
switch (ch) {
|
||||
case 's':
|
||||
|
||||
@@ -61,11 +61,11 @@ static void test_hello_reply(struct uloop_timeout *t)
|
||||
{
|
||||
struct hello_request *req = container_of(t, struct hello_request, timeout);
|
||||
int fds[2];
|
||||
|
||||
|
||||
blob_buf_init(&b, 0);
|
||||
blobmsg_add_string(&b, "message", req->data);
|
||||
ubus_send_reply(ctx, &req->req, b.head);
|
||||
|
||||
|
||||
if (pipe(fds) == -1) {
|
||||
fprintf(stderr, "Failed to create pipe\n");
|
||||
return;
|
||||
@@ -73,7 +73,7 @@ static void test_hello_reply(struct uloop_timeout *t)
|
||||
ubus_request_set_fd(ctx, &req->req, fds[0]);
|
||||
ubus_complete_deferred_request(ctx, &req->req, 0);
|
||||
req->fd = fds[1];
|
||||
|
||||
|
||||
req->timeout.cb = test_hello_fd_reply;
|
||||
test_hello_fd_reply(t);
|
||||
}
|
||||
@@ -86,18 +86,21 @@ static int test_hello(struct ubus_context *ctx, struct ubus_object *obj,
|
||||
struct blob_attr *tb[__HELLO_MAX];
|
||||
const char *format = "%s received a message: %s";
|
||||
const char *msgstr = "(unknown)";
|
||||
|
||||
|
||||
blobmsg_parse(hello_policy, ARRAY_SIZE(hello_policy), tb, blob_data(msg), blob_len(msg));
|
||||
|
||||
|
||||
if (tb[HELLO_MSG])
|
||||
msgstr = blobmsg_data(tb[HELLO_MSG]);
|
||||
|
||||
|
||||
hreq = calloc(1, sizeof(*hreq) + strlen(format) + strlen(obj->name) + strlen(msgstr) + 1);
|
||||
if (!hreq)
|
||||
return UBUS_STATUS_UNKNOWN_ERROR;
|
||||
|
||||
sprintf(hreq->data, format, obj->name, msgstr);
|
||||
ubus_defer_request(ctx, req, &hreq->req);
|
||||
hreq->timeout.cb = test_hello_reply;
|
||||
uloop_timeout_set(&hreq->timeout, 1000);
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -248,13 +251,13 @@ int main(int argc, char **argv)
|
||||
fprintf(stderr, "Failed to connect to ubus\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
ubus_add_uloop(ctx);
|
||||
|
||||
|
||||
server_main();
|
||||
|
||||
|
||||
ubus_free(ctx);
|
||||
uloop_done();
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user