summaryrefslogtreecommitdiff
path: root/client
diff options
context:
space:
mode:
authorPatrik Flykt <patrik.flykt@linux.intel.com>2013-03-27 13:54:03 +0200
committerPatrik Flykt <patrik.flykt@linux.intel.com>2013-04-04 10:26:59 +0300
commit787bd1940b33d61ceca91ee84e0db22278ef461d (patch)
tree31e0315c2b0a0a69766280142f28189eed89d75f /client
parent0bc79a37b387ed676ac88cb70667eb4d0266886e (diff)
downloadconnman-787bd1940b33d61ceca91ee84e0db22278ef461d.tar.gz
connman-787bd1940b33d61ceca91ee84e0db22278ef461d.tar.bz2
connman-787bd1940b33d61ceca91ee84e0db22278ef461d.zip
client: Use D-Bus helper function to implement services command
Fixes BMC#25953 BMC#25974
Diffstat (limited to 'client')
-rw-r--r--client/commands.c58
1 files changed, 49 insertions, 9 deletions
diff --git a/client/commands.c b/client/commands.c
index 561d55d0..309bd86f 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,