From 787bd1940b33d61ceca91ee84e0db22278ef461d Mon Sep 17 00:00:00 2001 From: Patrik Flykt Date: Wed, 27 Mar 2013 13:54:03 +0200 Subject: [PATCH] client: Use D-Bus helper function to implement services command Fixes BMC#25953 BMC#25974 --- client/commands.c | 58 ++++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 49 insertions(+), 9 deletions(-) diff --git a/client/commands.c b/client/commands.c index 561d55d..309bd86 100644 --- a/client/commands.c +++ b/client/commands.c @@ -201,12 +201,50 @@ static int cmd_state(char *args[], int num, struct option *options) state_print, NULL, DBUS_TYPE_INVALID); } +static void services_list(DBusMessageIter *iter, const char *error, + void *user_data) +{ + if (error == NULL) { + __connmanctl_services_list(iter); + fprintf(stdout, "\n"); + } else { + fprintf(stderr, "Error: %s\n", error); + } +} + +static void services_properties(DBusMessageIter *iter, const char *error, + void *user_data) +{ + char *path = user_data; + char *str; + DBusMessageIter dict; + + if (error == NULL) { + fprintf(stdout, "%s\n", path); + + dbus_message_iter_recurse(iter, &dict); + __connmanctl_dbus_print(&dict, " ", " = ", "\n"); + + fprintf(stdout, "\n"); + + } else { + str = strrchr(path, '/'); + if (str != NULL) + str++; + else + str = path; + + fprintf(stderr, "Error %s: %s\n", str, error); + } + + g_free(user_data); +} + static int cmd_services(char *args[], int num, struct option *options) { char *service_name = NULL; - int err = 0; + char *path; int c; - DBusMessage *message; if (num > 3) return -E2BIG; @@ -227,14 +265,16 @@ static int cmd_services(char *args[], int num, struct option *options) break; } - message = get_message(connection, "GetServices"); - if (message == NULL) - return -ENOMEM; - - err = list_properties(connection, "GetServices", service_name); - dbus_message_unref(message); + if (service_name == NULL) { + return __connmanctl_dbus_method_call(connection, "/", + "net.connman.Manager", "GetServices", + services_list, NULL, DBUS_TYPE_INVALID); + } - return err; + path = g_strdup_printf("/net/connman/service/%s", service_name); + return __connmanctl_dbus_method_call(connection, path, + "net.connman.Service", "GetProperties", + services_properties, path, DBUS_TYPE_INVALID); } static void technology_print(DBusMessageIter *iter, const char *error, -- 2.7.4