[gnome-bluetooth] Add public bluetooth_uuid_to_string()



commit 941dbe9e7c701958ea07b2d33b89f611027db0d2
Author: Bastien Nocera <hadess hadess net>
Date:   Wed Jun 10 16:52:41 2009 +0100

    Add public bluetooth_uuid_to_string()
    
    Add bluetooth_uuid_to_string(), to be used in the agent, so that
    we don't show crappy UUIDs to the end-user.
---
 lib/bluetooth-client.c |   38 +++++++++++++++++++++++---------------
 lib/bluetooth-client.h |    1 +
 2 files changed, 24 insertions(+), 15 deletions(-)

diff --git a/lib/bluetooth-client.c b/lib/bluetooth-client.c
index 59a377e..8fbd561 100644
--- a/lib/bluetooth-client.c
+++ b/lib/bluetooth-client.c
@@ -423,7 +423,7 @@ device_list_nodes (DBusGProxy *device, BluetoothClient *client, gboolean connect
 /* Short names from Table 2 at:
  * https://www.bluetooth.org/Technical/AssignedNumbers/service_discovery.htm */
 static const char *
-uuid16_to_string (guint64 uuid16)
+uuid16_to_string (guint uuid16)
 {
 	switch (uuid16) {
 	case 0x1103:
@@ -439,10 +439,31 @@ uuid16_to_string (guint64 uuid16)
 	case 0x1116:
 		return "NAP";
 	default:
+		g_debug ("Unhandled UUID 0x%X", uuid16);
 		return NULL;
 	}
 }
 
+const char *
+bluetooth_uuid_to_string (const char *uuid)
+{
+	char **parts;
+	guint uuid16;
+
+	parts = g_strsplit (uuid, "-", -1);
+	if (parts == NULL || parts[0] == NULL) {
+		g_strfreev (parts);
+		return NULL;
+	}
+
+	uuid16 = g_ascii_strtoull (parts[0], NULL, 16);
+	g_strfreev (parts);
+	if (uuid16 == 0)
+		return NULL;
+
+	return uuid16_to_string (uuid16);
+}
+
 static char **
 device_list_uuids (GValue *value)
 {
@@ -460,22 +481,9 @@ device_list_uuids (GValue *value)
 	ret = g_ptr_array_new ();
 
 	for (i = 0; uuids[i] != NULL; i++) {
-		char **parts;
-		guint uuid16;
 		const char *uuid;
 
-		parts = g_strsplit (uuids[i], "-", -1);
-		if (parts == NULL || parts[0] == NULL) {
-			g_strfreev (parts);
-			continue;
-		}
-
-		uuid16 = g_ascii_strtoull (parts[0], NULL, 16);
-		g_strfreev (parts);
-		if (uuid16 == 0)
-			continue;
-
-		uuid = uuid16_to_string (uuid16);
+		uuid = bluetooth_uuid_to_string (uuids[i]);
 		if (uuid == NULL)
 			continue;
 		g_ptr_array_add (ret, g_strdup (uuid));
diff --git a/lib/bluetooth-client.h b/lib/bluetooth-client.h
index d0198ee..6ae51a7 100644
--- a/lib/bluetooth-client.h
+++ b/lib/bluetooth-client.h
@@ -116,6 +116,7 @@ gboolean bluetooth_client_disconnect_service (BluetoothClient *client,
 
 const gchar *bluetooth_type_to_string(guint type);
 gboolean bluetooth_verify_address (const char *bdaddr);
+const char *bluetooth_uuid_to_string (const char *uuid);
 
 G_END_DECLS
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]