summaryrefslogtreecommitdiffstats
path: root/src/modules/bluetooth
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2009-02-02 00:30:10 +0100
committerLennart Poettering <lennart@poettering.net>2009-02-02 00:30:10 +0100
commitd6fdd71c02223fdde027d44c36c14c8e17cfb5b9 (patch)
tree861073e20d510709acdea040bbf9dda9db7bb632 /src/modules/bluetooth
parent16e369498cffd28a806f0ba7b173f3c669c0e820 (diff)
add new functions pa_bluetooth_cleanup_name() and pa_bluetooth_get_form_factor()
Diffstat (limited to 'src/modules/bluetooth')
-rw-r--r--src/modules/bluetooth/bluetooth-util.c73
-rw-r--r--src/modules/bluetooth/bluetooth-util.h4
2 files changed, 70 insertions, 7 deletions
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;
+}
diff --git a/src/modules/bluetooth/bluetooth-util.h b/src/modules/bluetooth/bluetooth-util.h
index ea6687a1..2c3ec649 100644
--- a/src/modules/bluetooth/bluetooth-util.h
+++ b/src/modules/bluetooth/bluetooth-util.h
@@ -74,4 +74,8 @@ pa_bluetooth_discovery* pa_bluetooth_discovery_new(DBusConnection *c, pa_bluetoo
void pa_bluetooth_discovery_free(pa_bluetooth_discovery *d);
void pa_bluetooth_discovery_sync(pa_bluetooth_discovery *d);
+const char*pa_bluetooth_get_form_factor(uint32_t class);
+
+char *pa_bluetooth_cleanup_name(const char *name);
+
#endif