X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;f=src%2Futils-jbus.c;h=ef87227426e6ef4e640d7e46f7268ccc7d9541cc;hb=a8c5306b1d0ac21bd745ae553f59c6eb189e04a4;hp=988f9cf6c7f8935b046f73dd7f36a0e8ff8b8773;hpb=32c6eecb9955e94b4d68efc09912efe88140ce83;p=src%2Fapp-framework-main.git diff --git a/src/utils-jbus.c b/src/utils-jbus.c index 988f9cf..ef87227 100644 --- a/src/utils-jbus.c +++ b/src/utils-jbus.c @@ -1,6 +1,8 @@ /* Copyright 2015 IoT.bzh + author: José Bollo + Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at @@ -274,8 +276,6 @@ int jbus_add_service(struct jbus *jbus, const char *method, void (*oncall)(struc return 0; -error3: - free(srv->method); error2: free(srv); error: @@ -291,14 +291,22 @@ int jbus_start_serving(struct jbus *jbus) return 0; case DBUS_REQUEST_NAME_REPLY_EXISTS: case DBUS_REQUEST_NAME_REPLY_IN_QUEUE: + default: errno = EADDRINUSE; return -1; } } +int jbus_read_write_dispatch(struct jbus *jbus, int toms) +{ + if (dbus_connection_read_write_dispatch(jbus->connection, toms)); + return 0; + errno = EPIPE; + return -1; +} + int jbus_callj(struct jbus *jbus, const char *method, const char *query, void (*onresp)(int status, struct json_object *response, void *data), void *data) { - int rc; DBusMessage *msg; struct jrespw *resp; @@ -374,7 +382,7 @@ int main() int s2 = jbus_add_service(jbus, "incr", incr); int s3 = jbus_start_serving(jbus); printf("started %d %d %d\n", s1, s2, s3); - while (dbus_connection_read_write_dispatch (jbus->connection, -1)) + while (!jbus_read_write_dispatch (jbus, -1)) ; } #endif @@ -393,9 +401,9 @@ int main() while(i--) { jbus_callj(jbus, "ping", "{\"toto\":[1,2,3,4,true,\"toto\"]}", onresp, "ping"); jbus_callj(jbus, "incr", "{\"doit\":\"for-me\"}", onresp, "incr"); - dbus_connection_read_write_dispatch (jbus->connection, 1); + jbus_read_write_dispatch (jbus, 1); } - while (dbus_connection_read_write_dispatch (jbus->connection, -1)) + while (!jbus_read_write_dispatch (jbus, -1)) ; } #endif