[pulseaudio-discuss] [RFCv3 04/20] bluetooth: Unregister Handsfree Audio Agent with oFono

jprvita at gmail.com jprvita at gmail.com
Sun Apr 21 20:07:34 PDT 2013


From: João Paulo Rechi Vita <jprvita at openbossa.org>

---
 src/modules/bluetooth/bluetooth-util.c | 37 +++++++++++++++++++++++++++++++++-
 1 file changed, 36 insertions(+), 1 deletion(-)

diff --git a/src/modules/bluetooth/bluetooth-util.c b/src/modules/bluetooth/bluetooth-util.c
index aca170f..5920867 100644
--- a/src/modules/bluetooth/bluetooth-util.c
+++ b/src/modules/bluetooth/bluetooth-util.c
@@ -1174,6 +1174,34 @@ static void ofono_init(pa_bluetooth_discovery *y) {
     send_and_add_to_pending(y, m, hfagent_register_reply, NULL);
 }
 
+static void ofono_done(pa_bluetooth_discovery *y) {
+    pa_assert(y);
+
+    if (y->ofono_bus_id)
+        pa_xfree(y->ofono_bus_id);
+    y->ofono_bus_id = NULL;
+
+    if (y->hf_cards)
+        pa_hashmap_free(y->hf_cards, NULL); /* TODO: free hash entries */
+    y->hf_cards = NULL;
+}
+
+static void ofono_unregister(pa_bluetooth_discovery *y) {
+    DBusMessage *m;
+    const char *path = HFP_AUDIO_AGENT_PATH;
+
+    pa_assert(y);
+    pa_assert(y->ofono_bus_id);
+
+    pa_assert_se(m = dbus_message_new_method_call(y->ofono_bus_id, "/", "org.ofono.HandsfreeAudioManager", "Unregister"));
+
+    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(y->connection), m, NULL));
+
+    ofono_done(y);
+}
+
 static int transport_parse_property(pa_bluetooth_transport *t, DBusMessageIter *i) {
     const char *key;
     DBusMessageIter variant_i;
@@ -1394,8 +1422,10 @@ static DBusHandlerResult filter_cb(DBusConnection *bus, DBusMessage *m, void *us
         }
 
         if (pa_streq(name, "org.ofono")) {
-            if (old_owner && *old_owner)
+            if (old_owner && *old_owner) {
                 pa_log_debug("oFono disappeared");
+                ofono_done(y);
+            }
 
             if (new_owner && *new_owner) {
                 pa_log_debug("oFono appeared");
@@ -2315,11 +2345,16 @@ void pa_bluetooth_discovery_unref(pa_bluetooth_discovery *y) {
     }
 
     if (y->connection) {
+
+        if (y->ofono_bus_id)
+            ofono_unregister(y);
+
         dbus_connection_unregister_object_path(pa_dbus_connection_get(y->connection), HFP_AG_ENDPOINT);
         dbus_connection_unregister_object_path(pa_dbus_connection_get(y->connection), HFP_HS_ENDPOINT);
         dbus_connection_unregister_object_path(pa_dbus_connection_get(y->connection), A2DP_SOURCE_ENDPOINT);
         dbus_connection_unregister_object_path(pa_dbus_connection_get(y->connection), A2DP_SINK_ENDPOINT);
         dbus_connection_unregister_object_path(pa_dbus_connection_get(y->connection), HFP_AUDIO_AGENT_PATH);
+
         pa_dbus_remove_matches(
             pa_dbus_connection_get(y->connection),
             "type='signal',sender='org.freedesktop.DBus',interface='org.freedesktop.DBus',member='NameOwnerChanged'"
-- 
1.7.11.7



More information about the pulseaudio-discuss mailing list