From ec9b36affc528f2aba53c9cadd0adcddeb4fcbd2 Mon Sep 17 00:00:00 2001 From: Luiz Augusto von Dentz Date: Thu, 15 Aug 2013 16:37:53 +0300 Subject: [PATCH] tools/obexctl: Add list command Add support for list command which can be used to list available sessions --- tools/obexctl.c | 63 +++++++++++++++++++++++++++++++++------------------------ 1 file changed, 37 insertions(+), 26 deletions(-) diff --git a/tools/obexctl.c b/tools/obexctl.c index 67a5362b3..cb9eda730 100644 --- a/tools/obexctl.c +++ b/tools/obexctl.c @@ -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", " [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) -- 2.11.0