[pulseaudio-discuss] [PATCH 2/4] bluez 5: Load the native headset backend if the oFono one is unavailable
David Henningsson
david.henningsson at canonical.com
Mon Nov 3 03:38:20 PST 2014
This implements some autodetect if both headset backends are compiled in:
First we try to contact the oFono service, if that's not working,
then we start the native backend instead.
Likewise if the oFono service is going offline/online, we load/unload
the native backend accordingly.
Signed-off-by: David Henningsson <david.henningsson at canonical.com>
---
src/modules/bluetooth/backend-ofono.c | 26 +++++++++++++++-----------
src/modules/bluetooth/bluez5-util.c | 12 ++++++++++++
src/modules/bluetooth/bluez5-util.h | 1 +
3 files changed, 28 insertions(+), 11 deletions(-)
diff --git a/src/modules/bluetooth/backend-ofono.c b/src/modules/bluetooth/backend-ofono.c
index 797d35c..1f0c80f 100644
--- a/src/modules/bluetooth/backend-ofono.c
+++ b/src/modules/bluetooth/backend-ofono.c
@@ -336,6 +336,16 @@ static void hf_audio_agent_get_cards(pa_bluetooth_backend *hf) {
hf_dbus_send_and_add_to_pending(hf, m, hf_audio_agent_get_cards_reply, NULL);
}
+static void ofono_bus_id_destroy(pa_bluetooth_backend *backend) {
+ pa_hashmap_remove_all(backend->cards);
+
+ if (backend->ofono_bus_id) {
+ pa_xfree(backend->ofono_bus_id);
+ backend->ofono_bus_id = NULL;
+ pa_bluetooth_discovery_set_ofono_running(backend->discovery, false);
+ }
+}
+
static void hf_audio_agent_register_reply(DBusPendingCall *pending, void *userdata) {
DBusMessage *r;
pa_dbus_pending *p;
@@ -360,6 +370,8 @@ finish:
PA_LLIST_REMOVE(pa_dbus_pending, backend->pending, p);
pa_dbus_pending_free(p);
+
+ pa_bluetooth_discovery_set_ofono_running(backend->discovery, backend->ofono_bus_id != NULL);
}
static void hf_audio_agent_register(pa_bluetooth_backend *hf) {
@@ -393,8 +405,7 @@ static void hf_audio_agent_unregister(pa_bluetooth_backend *backend) {
pa_assert_se(dbus_message_append_args(m, DBUS_TYPE_OBJECT_PATH, &path, DBUS_TYPE_INVALID));
pa_assert_se(dbus_connection_send(pa_dbus_connection_get(backend->connection), m, NULL));
- pa_xfree(backend->ofono_bus_id);
- backend->ofono_bus_id = NULL;
+ ofono_bus_id_destroy(backend);
}
}
@@ -429,11 +440,7 @@ static DBusHandlerResult filter_cb(DBusConnection *bus, DBusMessage *m, void *da
if (old_owner && *old_owner) {
pa_log_debug("oFono disappeared");
-
- pa_hashmap_remove_all(backend->cards);
-
- pa_xfree(backend->ofono_bus_id);
- backend->ofono_bus_id = NULL;
+ ofono_bus_id_destroy(backend);
}
if (new_owner && *new_owner) {
@@ -490,10 +497,7 @@ static DBusMessage *hf_audio_agent_release(DBusConnection *c, DBusMessage *m, vo
pa_log_debug("HF audio agent has been unregistered by oFono (%s)", backend->ofono_bus_id);
- pa_hashmap_remove_all(backend->cards);
-
- pa_xfree(backend->ofono_bus_id);
- backend->ofono_bus_id = NULL;
+ ofono_bus_id_destroy(backend);
pa_assert_se(r = dbus_message_new_method_return(m));
diff --git a/src/modules/bluetooth/bluez5-util.c b/src/modules/bluetooth/bluez5-util.c
index f7bf654..4121b76 100644
--- a/src/modules/bluetooth/bluez5-util.c
+++ b/src/modules/bluetooth/bluez5-util.c
@@ -861,6 +861,18 @@ static void parse_interfaces_and_properties(pa_bluetooth_discovery *y, DBusMessa
return;
}
+void pa_bluetooth_discovery_set_ofono_running(pa_bluetooth_discovery *y, bool is_running) {
+ pa_assert(y);
+
+ pa_log_debug("oFono is running: %s", pa_yes_no(is_running));
+ if (is_running && y->native_backend) {
+ pa_bluetooth_native_backend_free(y->native_backend);
+ y->native_backend = NULL;
+ }
+ else if (!is_running && !y->native_backend)
+ y->native_backend = pa_bluetooth_native_backend_new(y->core, y);
+}
+
static void get_managed_objects_reply(DBusPendingCall *pending, void *userdata) {
pa_dbus_pending *p;
pa_bluetooth_discovery *y;
diff --git a/src/modules/bluetooth/bluez5-util.h b/src/modules/bluetooth/bluez5-util.h
index d1abd39..21f56b2 100644
--- a/src/modules/bluetooth/bluez5-util.h
+++ b/src/modules/bluetooth/bluez5-util.h
@@ -157,4 +157,5 @@ const char *pa_bluetooth_profile_to_string(pa_bluetooth_profile_t profile);
pa_bluetooth_discovery* pa_bluetooth_discovery_get(pa_core *core);
pa_bluetooth_discovery* pa_bluetooth_discovery_ref(pa_bluetooth_discovery *y);
void pa_bluetooth_discovery_unref(pa_bluetooth_discovery *y);
+void pa_bluetooth_discovery_set_ofono_running(pa_bluetooth_discovery *y, bool is_running);
#endif
--
1.9.1
More information about the pulseaudio-discuss
mailing list