OSDN Git Service

tools/obexctl: Add list command
authorLuiz Augusto von Dentz <luiz.von.dentz@intel.com>
Thu, 15 Aug 2013 13:37:53 +0000 (16:37 +0300)
committerLuiz Augusto von Dentz <luiz.von.dentz@intel.com>
Tue, 15 Oct 2013 13:50:20 +0000 (16:50 +0300)
Add support for list command which can be used to list available sessions

tools/obexctl.c

index 67a5362..cb9eda7 100644 (file)
@@ -260,6 +260,42 @@ static void cmd_disconnect(int argc, char *argv[])
                                                g_dbus_proxy_get_path(proxy));
 }
 
+static char *proxy_description(GDBusProxy *proxy, const char *title,
+                                               const char *description)
+{
+       const char *path;
+
+       path = g_dbus_proxy_get_path(proxy);
+
+       return g_strdup_printf("%s%s%s%s %s ",
+                                       description ? "[" : "",
+                                       description ? : "",
+                                       description ? "] " : "",
+                                       title, path);
+}
+
+static void print_proxy(GDBusProxy *proxy, const char *title,
+                                                       const char *description)
+{
+       char *str;
+
+       str = proxy_description(proxy, title, description);
+
+       rl_printf("%s%s\n", str, default_session == proxy ? "[default]" : "");
+
+       g_free(str);
+}
+
+static void cmd_list(int argc, char *arg[])
+{
+       GSList *l;
+
+       for (l = sessions; l; l = g_slist_next(l)) {
+               GDBusProxy *proxy = l->data;
+               print_proxy(proxy, "Session", NULL);
+       }
+}
+
 static const struct {
        const char *cmd;
        const char *arg;
@@ -268,6 +304,7 @@ static const struct {
 } cmd_table[] = {
        { "connect",      "<dev> [uuid]", cmd_connect, "Connect session" },
        { "disconnect",   "[session]", cmd_disconnect, "Disconnect session" },
+       { "list",         NULL,       cmd_list, "List available sessions" },
        { "quit",         NULL,       cmd_quit, "Quit program" },
        { "exit",         NULL,       cmd_quit },
        { "help" },
@@ -481,32 +518,6 @@ static guint setup_standard_input(void)
        return source;
 }
 
-static char *proxy_description(GDBusProxy *proxy, const char *title,
-                                               const char *description)
-{
-       const char *path;
-
-       path = g_dbus_proxy_get_path(proxy);
-
-       return g_strdup_printf("%s%s%s%s %s ",
-                                       description ? "[" : "",
-                                       description ? : "",
-                                       description ? "] " : "",
-                                       title, path);
-}
-
-static void print_proxy(GDBusProxy *proxy, const char *title,
-                                                       const char *description)
-{
-       char *str;
-
-       str = proxy_description(proxy, title, description);
-
-       rl_printf("%s%s\n", str, default_session == proxy ? "[default]" : "");
-
-       g_free(str);
-}
-
 static void client_added(GDBusProxy *proxy)
 {
        if (client == NULL)