[gnome-bluetooth] lib: Split off non-client related, helper, code
- From: Bastien Nocera <hadess src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-bluetooth] lib: Split off non-client related, helper, code
- Date: Wed, 29 Jun 2011 14:47:07 +0000 (UTC)
commit 75a50937bcd44a4c1df95169f6897ce857174722
Author: Bastien Nocera <hadess hadess net>
Date: Wed Jun 29 14:52:44 2011 +0100
lib: Split off non-client related, helper, code
Into bluetooth-utils.h
lib/Makefile.am | 5 +-
lib/bluetooth-client-private.h | 2 -
lib/bluetooth-client.c | 257 +----------------------------------
lib/bluetooth-client.h | 4 -
lib/bluetooth-utils.c | 301 ++++++++++++++++++++++++++++++++++++++++
lib/bluetooth-utils.h | 40 ++++++
6 files changed, 346 insertions(+), 263 deletions(-)
---
diff --git a/lib/Makefile.am b/lib/Makefile.am
index 71135e5..dc4b687 100644
--- a/lib/Makefile.am
+++ b/lib/Makefile.am
@@ -8,6 +8,7 @@ lib_LTLIBRARIES = libgnome-bluetooth.la
libcommon_la_SOURCES = \
bluetooth-client.h bluetooth-client.c \
+ bluetooth-utils.h bluetooth-utils.c \
bluetooth-client-private.h \
bluetooth-agent.h bluetooth-agent.c \
bluetooth-killswitch.h bluetooth-killswitch.c \
@@ -23,6 +24,7 @@ libcommon_la_LDFLAGS = -no-undefined $(AM_LDFLAGS)
# will be scanned for introspection annotation, but won't be installed
libgnome_bluetooth_c_sources = \
bluetooth-client.c \
+ bluetooth-utils.c \
bluetooth-agent.c \
bluetooth-killswitch.c \
marshal.c \
@@ -59,7 +61,8 @@ libgnome_bluetooth_introspect_headers = \
bluetooth-chooser-button.h \
bluetooth-chooser-combo.h \
bluetooth-filter-widget.h \
- bluetooth-enums.h
+ bluetooth-enums.h \
+ bluetooth-utils.h
gnomebluetoothdir = $(pkgincludedir)
gnomebluetooth_HEADERS = \
diff --git a/lib/bluetooth-client-private.h b/lib/bluetooth-client-private.h
index 3938cfe..7172900 100644
--- a/lib/bluetooth-client-private.h
+++ b/lib/bluetooth-client-private.h
@@ -31,8 +31,6 @@
G_BEGIN_DECLS
-guint bluetooth_class_to_type (guint32 class);
-
DBusGProxy *bluetooth_client_get_default_adapter(BluetoothClient *client);
gboolean bluetooth_client_start_discovery(BluetoothClient *client);
diff --git a/lib/bluetooth-client.c b/lib/bluetooth-client.c
index 54f32b9..585a202 100644
--- a/lib/bluetooth-client.c
+++ b/lib/bluetooth-client.c
@@ -45,6 +45,7 @@
#include "bluetooth-client.h"
#include "bluetooth-client-private.h"
#include "bluetooth-client-glue.h"
+#include "bluetooth-utils.h"
#include "gnome-bluetooth-enum-types.h"
#include "marshal.h"
@@ -113,149 +114,6 @@ enum {
G_DEFINE_TYPE(BluetoothClient, bluetooth_client, G_TYPE_OBJECT)
-/**
- * bluetooth_type_to_string:
- * @type: a #BluetoothType
- *
- * Returns the string representation of the @type passed. Do not free the return value.
- *
- * Return value: a string.
- **/
-const gchar *bluetooth_type_to_string(BluetoothType type)
-{
- switch (type) {
- case BLUETOOTH_TYPE_ANY:
- return _("All types");
- case BLUETOOTH_TYPE_PHONE:
- return _("Phone");
- case BLUETOOTH_TYPE_MODEM:
- return _("Modem");
- case BLUETOOTH_TYPE_COMPUTER:
- return _("Computer");
- case BLUETOOTH_TYPE_NETWORK:
- return _("Network");
- case BLUETOOTH_TYPE_HEADSET:
- /* translators: a hands-free headset, a combination of a single speaker with a microphone */
- return _("Headset");
- case BLUETOOTH_TYPE_HEADPHONES:
- return _("Headphones");
- case BLUETOOTH_TYPE_OTHER_AUDIO:
- return _("Audio device");
- case BLUETOOTH_TYPE_KEYBOARD:
- return _("Keyboard");
- case BLUETOOTH_TYPE_MOUSE:
- return _("Mouse");
- case BLUETOOTH_TYPE_CAMERA:
- return _("Camera");
- case BLUETOOTH_TYPE_PRINTER:
- return _("Printer");
- case BLUETOOTH_TYPE_JOYPAD:
- return _("Joypad");
- case BLUETOOTH_TYPE_TABLET:
- return _("Tablet");
- case BLUETOOTH_TYPE_VIDEO:
- return _("Video device");
- default:
- return _("Unknown");
- }
-}
-
-/**
- * bluetooth_verify_address:
- * @bdaddr: a string representing a Bluetooth address
- *
- * Returns whether the string is a valid Bluetooth address. This does not contact the device in any way.
- *
- * Return value: %TRUE if the address is valid, %FALSE if not.
- **/
-gboolean
-bluetooth_verify_address (const char *bdaddr)
-{
- guint i;
-
- g_return_val_if_fail (bdaddr != NULL, FALSE);
-
- if (strlen (bdaddr) != 17)
- return FALSE;
-
- for (i = 0; i < 17; i++) {
- if (((i + 1) % 3) == 0) {
- if (bdaddr[i] != ':')
- return FALSE;
- continue;
- }
- if (g_ascii_isxdigit (bdaddr[i]) == FALSE)
- return FALSE;
- }
-
- return TRUE;
-}
-
-guint
-bluetooth_class_to_type (guint32 class)
-{
- switch ((class & 0x1f00) >> 8) {
- case 0x01:
- return BLUETOOTH_TYPE_COMPUTER;
- case 0x02:
- switch ((class & 0xfc) >> 2) {
- case 0x01:
- case 0x02:
- case 0x03:
- case 0x05:
- return BLUETOOTH_TYPE_PHONE;
- case 0x04:
- return BLUETOOTH_TYPE_MODEM;
- }
- break;
- case 0x03:
- return BLUETOOTH_TYPE_NETWORK;
- case 0x04:
- switch ((class & 0xfc) >> 2) {
- case 0x01:
- case 0x02:
- return BLUETOOTH_TYPE_HEADSET;
- case 0x06:
- return BLUETOOTH_TYPE_HEADPHONES;
- case 0x0b: /* VCR */
- case 0x0c: /* Video Camera */
- case 0x0d: /* Camcorder */
- return BLUETOOTH_TYPE_VIDEO;
- default:
- return BLUETOOTH_TYPE_OTHER_AUDIO;
- }
- break;
- case 0x05:
- switch ((class & 0xc0) >> 6) {
- case 0x00:
- switch ((class & 0x1e) >> 2) {
- case 0x01:
- case 0x02:
- return BLUETOOTH_TYPE_JOYPAD;
- }
- break;
- case 0x01:
- return BLUETOOTH_TYPE_KEYBOARD;
- case 0x02:
- switch ((class & 0x1e) >> 2) {
- case 0x05:
- return BLUETOOTH_TYPE_TABLET;
- default:
- return BLUETOOTH_TYPE_MOUSE;
- }
- }
- break;
- case 0x06:
- if (class & 0x80)
- return BLUETOOTH_TYPE_PRINTER;
- if (class & 0x20)
- return BLUETOOTH_TYPE_CAMERA;
- break;
- }
-
- return 0;
-}
-
typedef gboolean (*IterSearchFunc) (GtkTreeStore *store,
GtkTreeIter *iter, gpointer user_data);
@@ -486,119 +344,6 @@ device_list_nodes (DBusGProxy *device, BluetoothClient *client, gboolean connect
return table;
}
-static const char *
-uuid16_custom_to_string (guint uuid16, const char *uuid)
-{
- switch (uuid16) {
- case 0x2:
- return "SyncMLClient";
- case 0x5601:
- return "Nokia SyncML Server";
- default:
- g_debug ("Unhandled custom UUID %s (0x%x)", uuid, uuid16);
- return NULL;
- }
-}
-
-/* Short names from Table 2 at:
- * https://www.bluetooth.org/Technical/AssignedNumbers/service_discovery.htm */
-static const char *
-uuid16_to_string (guint uuid16, const char *uuid)
-{
- switch (uuid16) {
- case 0x1101:
- return "SerialPort";
- case 0x1103:
- return "DialupNetworking";
- case 0x1104:
- return "IrMCSync";
- case 0x1105:
- return "OBEXObjectPush";
- case 0x1106:
- return "OBEXFileTransfer";
- case 0x1108:
- return "HSP";
- case 0x110A:
- return "AudioSource";
- case 0x110B:
- return "AudioSink";
- case 0x110c:
- return "A/V_RemoteControlTarget";
- case 0x110e:
- return "A/V_RemoteControl";
- case 0x1112:
- return "Headset_-_AG";
- case 0x1115:
- return "PANU";
- case 0x1116:
- return "NAP";
- case 0x1117:
- return "GN";
- case 0x111e:
- return "Handsfree";
- case 0x111F:
- return "HandsfreeAudioGateway";
- case 0x1124:
- return "HumanInterfaceDeviceService";
- case 0x112d:
- return "SIM_Access";
- case 0x112F:
- return "Phonebook_Access_-_PSE";
- case 0x1203:
- return "GenericAudio";
- case 0x1000: /* ServiceDiscoveryServerServiceClassID */
- case 0x1200: /* PnPInformation */
- /* Those are ignored */
- return NULL;
- case 0x1201:
- return "GenericNetworking";
- case 0x1303:
- return "VideoSource";
- case 0x8e771303:
- case 0x8e771301:
- return "SEMC HLA";
- case 0x8e771401:
- return "SEMC Watch Phone";
- default:
- g_debug ("Unhandled UUID %s (0x%x)", uuid, uuid16);
- return NULL;
- }
-}
-
-/**
- * bluetooth_uuid_to_string:
- * @uuid: a string representing a Bluetooth UUID
- *
- * Returns a string representing a human-readable (but not usable for display to users) version of the @uuid. Do not free the return value.
- *
- * Return value: a string.
- **/
-const char *
-bluetooth_uuid_to_string (const char *uuid)
-{
- char **parts;
- guint uuid16;
- gboolean is_custom = FALSE;
-
- if (g_str_has_suffix (uuid, "-0000-1000-8000-0002ee000002") != FALSE)
- is_custom = TRUE;
-
- 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;
-
- if (is_custom == FALSE)
- return uuid16_to_string (uuid16, uuid);
- return uuid16_custom_to_string (uuid16, uuid);
-}
-
static char **
device_list_uuids (GValue *value)
{
diff --git a/lib/bluetooth-client.h b/lib/bluetooth-client.h
index e3e1f75..89ec54e 100644
--- a/lib/bluetooth-client.h
+++ b/lib/bluetooth-client.h
@@ -72,10 +72,6 @@ GtkTreeModel *bluetooth_client_get_device_filter_model(BluetoothClient *client,
gboolean bluetooth_client_get_discoverable (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
#endif /* __BLUETOOTH_CLIENT_H */
diff --git a/lib/bluetooth-utils.c b/lib/bluetooth-utils.c
new file mode 100644
index 0000000..15c4fa1
--- /dev/null
+++ b/lib/bluetooth-utils.c
@@ -0,0 +1,301 @@
+/*
+ *
+ * BlueZ - Bluetooth protocol stack for Linux
+ *
+ * Copyright (C) 2009-2011 Bastien Nocera <hadess hadess net>
+ * Copyright (C) 2010 Giovanni Campagna <scampa giovanni gmail com>
+ *
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ */
+
+/**
+ * SECTION:bluetooth-utils
+ * @short_description: Bluetooth utility functions
+ * @stability: Stable
+ * @include: bluetooth-utils.h
+ *
+ * Those helper functions are used throughout the Bluetooth
+ * management utilities.
+ **/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <glib/gi18n-lib.h>
+
+#include "bluetooth-utils.h"
+#include "gnome-bluetooth-enum-types.h"
+
+/**
+ * bluetooth_type_to_string:
+ * @type: a #BluetoothType
+ *
+ * Returns the string representation of the @type passed. Do not free the return value.
+ *
+ * Return value: a string.
+ **/
+const gchar *
+bluetooth_type_to_string (BluetoothType type)
+{
+ switch (type) {
+ case BLUETOOTH_TYPE_ANY:
+ return _("All types");
+ case BLUETOOTH_TYPE_PHONE:
+ return _("Phone");
+ case BLUETOOTH_TYPE_MODEM:
+ return _("Modem");
+ case BLUETOOTH_TYPE_COMPUTER:
+ return _("Computer");
+ case BLUETOOTH_TYPE_NETWORK:
+ return _("Network");
+ case BLUETOOTH_TYPE_HEADSET:
+ /* translators: a hands-free headset, a combination of a single speaker with a microphone */
+ return _("Headset");
+ case BLUETOOTH_TYPE_HEADPHONES:
+ return _("Headphones");
+ case BLUETOOTH_TYPE_OTHER_AUDIO:
+ return _("Audio device");
+ case BLUETOOTH_TYPE_KEYBOARD:
+ return _("Keyboard");
+ case BLUETOOTH_TYPE_MOUSE:
+ return _("Mouse");
+ case BLUETOOTH_TYPE_CAMERA:
+ return _("Camera");
+ case BLUETOOTH_TYPE_PRINTER:
+ return _("Printer");
+ case BLUETOOTH_TYPE_JOYPAD:
+ return _("Joypad");
+ case BLUETOOTH_TYPE_TABLET:
+ return _("Tablet");
+ case BLUETOOTH_TYPE_VIDEO:
+ return _("Video device");
+ default:
+ return _("Unknown");
+ }
+}
+
+/**
+ * bluetooth_verify_address:
+ * @bdaddr: a string representing a Bluetooth address
+ *
+ * Returns whether the string is a valid Bluetooth address. This does not contact the device in any way.
+ *
+ * Return value: %TRUE if the address is valid, %FALSE if not.
+ **/
+gboolean
+bluetooth_verify_address (const char *bdaddr)
+{
+ guint i;
+
+ g_return_val_if_fail (bdaddr != NULL, FALSE);
+
+ if (strlen (bdaddr) != 17)
+ return FALSE;
+
+ for (i = 0; i < 17; i++) {
+ if (((i + 1) % 3) == 0) {
+ if (bdaddr[i] != ':')
+ return FALSE;
+ continue;
+ }
+ if (g_ascii_isxdigit (bdaddr[i]) == FALSE)
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+BluetoothType
+bluetooth_class_to_type (guint32 class)
+{
+ switch ((class & 0x1f00) >> 8) {
+ case 0x01:
+ return BLUETOOTH_TYPE_COMPUTER;
+ case 0x02:
+ switch ((class & 0xfc) >> 2) {
+ case 0x01:
+ case 0x02:
+ case 0x03:
+ case 0x05:
+ return BLUETOOTH_TYPE_PHONE;
+ case 0x04:
+ return BLUETOOTH_TYPE_MODEM;
+ }
+ break;
+ case 0x03:
+ return BLUETOOTH_TYPE_NETWORK;
+ case 0x04:
+ switch ((class & 0xfc) >> 2) {
+ case 0x01:
+ case 0x02:
+ return BLUETOOTH_TYPE_HEADSET;
+ case 0x06:
+ return BLUETOOTH_TYPE_HEADPHONES;
+ case 0x0b: /* VCR */
+ case 0x0c: /* Video Camera */
+ case 0x0d: /* Camcorder */
+ return BLUETOOTH_TYPE_VIDEO;
+ default:
+ return BLUETOOTH_TYPE_OTHER_AUDIO;
+ }
+ break;
+ case 0x05:
+ switch ((class & 0xc0) >> 6) {
+ case 0x00:
+ switch ((class & 0x1e) >> 2) {
+ case 0x01:
+ case 0x02:
+ return BLUETOOTH_TYPE_JOYPAD;
+ }
+ break;
+ case 0x01:
+ return BLUETOOTH_TYPE_KEYBOARD;
+ case 0x02:
+ switch ((class & 0x1e) >> 2) {
+ case 0x05:
+ return BLUETOOTH_TYPE_TABLET;
+ default:
+ return BLUETOOTH_TYPE_MOUSE;
+ }
+ }
+ break;
+ case 0x06:
+ if (class & 0x80)
+ return BLUETOOTH_TYPE_PRINTER;
+ if (class & 0x20)
+ return BLUETOOTH_TYPE_CAMERA;
+ break;
+ }
+
+ return 0;
+}
+
+static const char *
+uuid16_custom_to_string (guint uuid16, const char *uuid)
+{
+ switch (uuid16) {
+ case 0x2:
+ return "SyncMLClient";
+ case 0x5601:
+ return "Nokia SyncML Server";
+ default:
+ g_debug ("Unhandled custom UUID %s (0x%x)", uuid, uuid16);
+ return NULL;
+ }
+}
+
+/* Short names from Table 2 at:
+ * https://www.bluetooth.org/Technical/AssignedNumbers/service_discovery.htm */
+static const char *
+uuid16_to_string (guint uuid16, const char *uuid)
+{
+ switch (uuid16) {
+ case 0x1101:
+ return "SerialPort";
+ case 0x1103:
+ return "DialupNetworking";
+ case 0x1104:
+ return "IrMCSync";
+ case 0x1105:
+ return "OBEXObjectPush";
+ case 0x1106:
+ return "OBEXFileTransfer";
+ case 0x1108:
+ return "HSP";
+ case 0x110A:
+ return "AudioSource";
+ case 0x110B:
+ return "AudioSink";
+ case 0x110c:
+ return "A/V_RemoteControlTarget";
+ case 0x110e:
+ return "A/V_RemoteControl";
+ case 0x1112:
+ return "Headset_-_AG";
+ case 0x1115:
+ return "PANU";
+ case 0x1116:
+ return "NAP";
+ case 0x1117:
+ return "GN";
+ case 0x111e:
+ return "Handsfree";
+ case 0x111F:
+ return "HandsfreeAudioGateway";
+ case 0x1124:
+ return "HumanInterfaceDeviceService";
+ case 0x112d:
+ return "SIM_Access";
+ case 0x112F:
+ return "Phonebook_Access_-_PSE";
+ case 0x1203:
+ return "GenericAudio";
+ case 0x1000: /* ServiceDiscoveryServerServiceClassID */
+ case 0x1200: /* PnPInformation */
+ /* Those are ignored */
+ return NULL;
+ case 0x1201:
+ return "GenericNetworking";
+ case 0x1303:
+ return "VideoSource";
+ case 0x8e771303:
+ case 0x8e771301:
+ return "SEMC HLA";
+ case 0x8e771401:
+ return "SEMC Watch Phone";
+ default:
+ g_debug ("Unhandled UUID %s (0x%x)", uuid, uuid16);
+ return NULL;
+ }
+}
+
+/**
+ * bluetooth_uuid_to_string:
+ * @uuid: a string representing a Bluetooth UUID
+ *
+ * Returns a string representing a human-readable (but not usable for display to users) version of the @uuid. Do not free the return value.
+ *
+ * Return value: a string.
+ **/
+const char *
+bluetooth_uuid_to_string (const char *uuid)
+{
+ char **parts;
+ guint uuid16;
+ gboolean is_custom = FALSE;
+
+ if (g_str_has_suffix (uuid, "-0000-1000-8000-0002ee000002") != FALSE)
+ is_custom = TRUE;
+
+ 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;
+
+ if (is_custom == FALSE)
+ return uuid16_to_string (uuid16, uuid);
+ return uuid16_custom_to_string (uuid16, uuid);
+}
+
+
diff --git a/lib/bluetooth-utils.h b/lib/bluetooth-utils.h
new file mode 100644
index 0000000..f9e0670
--- /dev/null
+++ b/lib/bluetooth-utils.h
@@ -0,0 +1,40 @@
+/*
+ *
+ * BlueZ - Bluetooth protocol stack for Linux
+ *
+ * Copyright (C) 2009-2011 Bastien Nocera <hadess hadess net>
+ * Copyright (C) 2010 Giovanni Campagna <scampa giovanni gmail com>
+ *
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ */
+
+#ifndef __BLUETOOTH_UTILS_H
+#define __BLUETOOTH_UTILS_H
+
+#include <glib-object.h>
+#include <bluetooth-enums.h>
+
+G_BEGIN_DECLS
+
+BluetoothType bluetooth_class_to_type (guint32 class);
+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
+
+#endif /* __BLUETOOTH_UTILS_H */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]