From d6fdd71c02223fdde027d44c36c14c8e17cfb5b9 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Mon, 2 Feb 2009 00:30:10 +0100 Subject: add new functions pa_bluetooth_cleanup_name() and pa_bluetooth_get_form_factor() --- src/modules/bluetooth/bluetooth-util.c | 73 ++++++++++++++++++++++++++++++---- 1 file changed, 66 insertions(+), 7 deletions(-) (limited to 'src/modules/bluetooth/bluetooth-util.c') diff --git a/src/modules/bluetooth/bluetooth-util.c b/src/modules/bluetooth/bluetooth-util.c index 019b97e8..7855c2ef 100644 --- a/src/modules/bluetooth/bluetooth-util.c +++ b/src/modules/bluetooth/bluetooth-util.c @@ -155,7 +155,7 @@ static int parse_device_property(pa_bluetooth_discovery *y, pa_bluetooth_device dbus_message_iter_recurse(i, &variant_i); - pa_log_debug("Parsing property org.bluez.Device.%s", key); +/* pa_log_debug("Parsing property org.bluez.Device.%s", key); */ switch (dbus_message_iter_get_arg_type(&variant_i)) { @@ -175,7 +175,7 @@ static int parse_device_property(pa_bluetooth_discovery *y, pa_bluetooth_device d->address = pa_xstrdup(value); } - pa_log_debug("Value %s", value); +/* pa_log_debug("Value %s", value); */ break; } @@ -192,7 +192,7 @@ static int parse_device_property(pa_bluetooth_discovery *y, pa_bluetooth_device else if (pa_streq(key, "Trusted")) d->trusted = !!value; - pa_log_debug("Value %s", pa_yes_no(value)); +/* pa_log_debug("Value %s", pa_yes_no(value)); */ break; } @@ -205,7 +205,7 @@ static int parse_device_property(pa_bluetooth_discovery *y, pa_bluetooth_device if (pa_streq(key, "Class")) d->class = (int) value; - pa_log_debug("Value %u", (unsigned) value); +/* pa_log_debug("Value %u", (unsigned) value); */ break; } @@ -265,7 +265,7 @@ static int parse_audio_property(pa_bluetooth_discovery *u, int *connected, DBusM dbus_message_iter_recurse(i, &variant_i); - pa_log_debug("Parsing property org.bluez.{AudioSink|Headset}.%s", key); +/* pa_log_debug("Parsing property org.bluez.{AudioSink|Headset}.%s", key); */ switch (dbus_message_iter_get_arg_type(&variant_i)) { @@ -277,7 +277,7 @@ static int parse_audio_property(pa_bluetooth_discovery *u, int *connected, DBusM if (pa_streq(key, "Connected")) *connected = !!value; - pa_log_debug("Value %s", pa_yes_no(value)); +/* pa_log_debug("Value %s", pa_yes_no(value)); */ break; } @@ -286,7 +286,6 @@ static int parse_audio_property(pa_bluetooth_discovery *u, int *connected, DBusM return 0; } - static void run_callback(pa_bluetooth_discovery *y, pa_bluetooth_device *d, pa_bool_t good) { pa_assert(y); pa_assert(d); @@ -803,3 +802,63 @@ void pa_bluetooth_discovery_sync(pa_bluetooth_discovery *y) { pa_dbus_sync_pending_list(&y->pending); } + +const char*pa_bluetooth_get_form_factor(uint32_t class) { + unsigned i; + const char *r; + + static const char * const table[] = { + [1] = "headset", + [2] = "hands-free", + [4] = "microphone", + [5] = "external-speakers", + [6] = "headphones", + [7] = "portable", + [8] = "car", + [10] = "hifi" + }; + + if (((class >> 8) & 31) != 4) + return NULL; + + if ((i = (class >> 2) & 63) > PA_ELEMENTSOF(table)) + r = NULL; + else + r = table[i]; + + if (!r) + pa_log_debug("Unknown Bluetooth minor device class %u", i); + + return r; +} + +char *pa_bluetooth_cleanup_name(const char *name) { + char *t, *s, *d; + pa_bool_t space = FALSE; + + pa_assert(name); + + while ((*name >= 1 && *name <= 32) || *name >= 127) + name++; + + t = pa_xstrdup(name); + + for (s = d = t; *s; s++) { + + if (*s <= 32 || *s >= 127 || *s == '_') { + space = TRUE; + continue; + } + + if (space) { + *(d++) = ' '; + space = FALSE; + } + + *(d++) = *s; + } + + *d = 0; + + return t; +} -- cgit