From 833773d0914f98a56511a4bc4438ba6ab16f3ac2 Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Sat, 22 Dec 2012 19:11:46 -0800 Subject: [PATCH] client: Print UUIDs as human readable strings as well --- Makefile.tools | 3 +- client/main.c | 75 ++++++++++++++++++++++++++++++-------------------- 2 files changed, 47 insertions(+), 31 deletions(-) diff --git a/Makefile.tools b/Makefile.tools index 6be310eca..f53760d26 100644 --- a/Makefile.tools +++ b/Makefile.tools @@ -4,7 +4,8 @@ bin_PROGRAMS += client/bluetoothctl client_bluetoothctl_SOURCES = $(gdbus_sources) client/main.c \ client/display.h client/display.c \ - client/agent.h client/agent.c + client/agent.h client/agent.c \ + monitor/uuid.h monitor/uuid.c client_bluetoothctl_LDADD = @GLIB_LIBS@ @DBUS_LIBS@ -lreadline endif diff --git a/client/main.c b/client/main.c index ea839426d..b716d95f9 100644 --- a/client/main.c +++ b/client/main.c @@ -37,6 +37,7 @@ #include #include +#include "monitor/uuid.h" #include "agent.h" #include "display.h" @@ -181,6 +182,46 @@ static void print_property(GDBusProxy *proxy, const char *name) print_iter("\t", name, &iter); } +static void print_uuids(GDBusProxy *proxy) +{ + DBusMessageIter iter, value; + + if (g_dbus_proxy_get_property(proxy, "UUIDs", &iter) == FALSE) + return; + + dbus_message_iter_recurse(&iter, &value); + + while (dbus_message_iter_get_arg_type(&value) == DBUS_TYPE_STRING) { + const char *uuid, *text; + + dbus_message_iter_get_basic(&value, &uuid); + + text = uuidstr_to_str(uuid); + if (text) { + char str[26]; + unsigned int n; + + str[sizeof(str) - 1] = '\0'; + + n = snprintf(str, sizeof(str), "%s", text); + if (n > sizeof(str) - 1) { + str[sizeof(str) - 2] = '.'; + str[sizeof(str) - 3] = '.'; + if (str[sizeof(str) - 4] == ' ') + str[sizeof(str) - 4] = '.'; + + n = sizeof(str) - 1; + } + + rl_printf("\tUUID: %s%*c(%s)\n", + str, 26 - n, ' ', uuid); + } else + rl_printf("\tUUID: %*c(%s)\n", 26, ' ', uuid); + + dbus_message_iter_next(&value); + } +} + static gboolean device_is_child(GDBusProxy *device, GDBusProxy *master) { DBusMessageIter iter; @@ -376,7 +417,7 @@ static void cmd_list(const char *arg) static void cmd_show(const char *arg) { GDBusProxy *proxy; - DBusMessageIter iter, value; + DBusMessageIter iter; const char *address; if (!arg || !strlen(arg)) { @@ -403,20 +444,7 @@ static void cmd_show(const char *arg) print_property(proxy, "Powered"); print_property(proxy, "Discoverable"); print_property(proxy, "Pairable"); - - if (g_dbus_proxy_get_property(proxy, "UUIDs", &iter) == FALSE) - goto done; - - dbus_message_iter_recurse(&iter, &value); - - while (dbus_message_iter_get_arg_type(&value) == DBUS_TYPE_STRING) { - const char *str; - dbus_message_iter_get_basic(&value, &str); - rl_printf("\tUUID: %s\n", str); - dbus_message_iter_next(&value); - } - -done: + print_uuids(proxy); print_property(proxy, "Discovering"); } @@ -628,7 +656,7 @@ static void cmd_scan(const char *arg) static void cmd_info(const char *arg) { GDBusProxy *proxy; - DBusMessageIter iter, value; + DBusMessageIter iter; const char *address; if (!arg || !strlen(arg)) { @@ -657,20 +685,7 @@ static void cmd_info(const char *arg) print_property(proxy, "Blocked"); print_property(proxy, "Connected"); print_property(proxy, "LegacyPairing"); - - if (g_dbus_proxy_get_property(proxy, "UUIDs", &iter) == FALSE) - goto done; - - dbus_message_iter_recurse(&iter, &value); - - while (dbus_message_iter_get_arg_type(&value) == DBUS_TYPE_STRING) { - const char *str; - dbus_message_iter_get_basic(&value, &str); - rl_printf("\tUUID: %s\n", str); - dbus_message_iter_next(&value); - } - -done: + print_uuids(proxy); print_property(proxy, "VendorSource"); print_property(proxy, "Vendor"); print_property(proxy, "Product"); -- 2.47.3