client/print: Add decoding for UUID properties
authorLuiz Augusto von Dentz <luiz.von.dentz@intel.com>
Wed, 18 Sep 2024 19:03:22 +0000 (15:03 -0400)
committerWootak Jung <wootak.jung@samsung.com>
Thu, 20 Feb 2025 07:43:23 +0000 (16:43 +0900)
This adds proper decoding for UUID properties with usage of
bt_uuidstr_to_str so it can print the 'friendly' name as bellow:

bluetoothctl# transport.show /org/bluez/hci0/dev_94_DB_56_F7_F2_88/sep4/fd0
Transport /org/bluez/hci0/dev_94_DB_56_F7_F2_88/sep4/fd0
UUID: Audio Source              (0000110a-0000-1000-8000-00805f9b34fb)
...

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
client/main.c
client/print.c
client/print.h

index a041400115a2c1fc6c6bec1dcc43e0a714bd2d3a..6c128ef276ade7c7809f13e2e17fe24410842bd3 100644 (file)
@@ -220,33 +220,6 @@ done:
                                        address, name);
 }
 
-static void print_uuid(const char *label, const char *uuid)
-{
-       const char *text;
-
-       text = bt_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;
-               }
-
-               bt_shell_printf("\t%s: %s%*c(%s)\n", label, str, 26 - n, ' ',
-                                                                       uuid);
-       } else
-               bt_shell_printf("\t%s: %*c(%s)\n", label, 26, ' ', uuid);
-}
-
 static void print_uuids(GDBusProxy *proxy)
 {
        DBusMessageIter iter, value;
@@ -261,7 +234,7 @@ static void print_uuids(GDBusProxy *proxy)
 
                dbus_message_iter_get_basic(&value, &uuid);
 
-               print_uuid("UUID", uuid);
+               print_uuid("\t", "UUID", uuid);
 
                dbus_message_iter_next(&value);
        }
@@ -282,7 +255,7 @@ static void print_experimental(GDBusProxy *proxy)
 
                dbus_message_iter_get_basic(&value, &uuid);
 
-               print_uuid("ExperimentalFeatures", uuid);
+               print_uuid("\t", "ExperimentalFeatures", uuid);
 
                dbus_message_iter_next(&value);
        }
@@ -1379,7 +1352,7 @@ static void cmd_scan_filter_uuids(int argc, char *argv[])
                char **uuid;
 
                for (uuid = filter.uuids; uuid && *uuid; uuid++)
-                       print_uuid("UUID", *uuid);
+                       print_uuid("\t", "UUID", *uuid);
 
                return bt_shell_noninteractive_quit(EXIT_SUCCESS);
        }
index 108b988b1485b9e49db3300f26d6717dfa48b890..8d5c628bdb34c681a52bcb10474f2436d7fafc29 100644 (file)
@@ -115,6 +115,12 @@ void print_iter(const char *label, const char *name, DBusMessageIter *iter)
                bt_shell_printf("%s%s is invalid\n", label, name);
                break;
        case DBUS_TYPE_STRING:
+               if (!strcasecmp(name, "UUID")) {
+                       dbus_message_iter_get_basic(iter, &valstr);
+                       print_uuid(label, name, valstr);
+                       break;
+               }
+               /* fall through */
        case DBUS_TYPE_OBJECT_PATH:
                dbus_message_iter_get_basic(iter, &valstr);
                bt_shell_printf("%s%s: %s\n", label, name, valstr);
@@ -202,3 +208,30 @@ void print_property(GDBusProxy *proxy, const char *name)
 {
        print_property_with_label(proxy, name, NULL);
 }
+
+void print_uuid(const char *label, const char *name, const char *uuid)
+{
+       const char *text;
+
+       text = bt_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;
+               }
+
+               bt_shell_printf("%s%s: %s%*c(%s)\n", label, name, str, 26 - n,
+                                                               ' ', uuid);
+       } else
+               bt_shell_printf("%s%s: %*c(%s)\n", label, name, 26, ' ', uuid);
+}
index c0866d06c504502c24427222160dd58f341b9726..56bcce16a66191180cbdd45a05a6443e77819305 100644 (file)
@@ -12,3 +12,4 @@ void print_property(GDBusProxy *proxy, const char *name);
 void print_property_with_label(GDBusProxy *proxy, const char *name,
                                        const char *label);
 void print_iter(const char *label, const char *name, DBusMessageIter *iter);
+void print_uuid(const char *label, const char *name, const char *uuid);