1 From: =?utf-8?q?Jo=C3=A3o_Paulo_Rechi_Vita?= <jprvita@openbossa.org>
2 Date: Thu, 11 Jul 2013 11:43:48 -0300
3 Subject: bluetooth: Track oFono service
5 Change-Id: I6752f21b848757dbea20c92c68b581141cefbc67
7 src/modules/bluetooth/hfaudioagent-ofono.c | 61 ++++++++++++++++++++++++++++--
8 1 file changed, 58 insertions(+), 3 deletions(-)
10 diff --git a/src/modules/bluetooth/hfaudioagent-ofono.c b/src/modules/bluetooth/hfaudioagent-ofono.c
11 index 3684bed..97e0fa8 100644
12 --- a/src/modules/bluetooth/hfaudioagent-ofono.c
13 +++ b/src/modules/bluetooth/hfaudioagent-ofono.c
14 @@ -364,6 +364,7 @@ static void hf_audio_agent_unregister(hf_audio_agent_data *hfdata) {
16 static DBusHandlerResult filter_cb(DBusConnection *bus, DBusMessage *m, void *data) {
19 hf_audio_agent_data *hfdata = data;
22 @@ -374,6 +375,46 @@ static DBusHandlerResult filter_cb(DBusConnection *bus, DBusMessage *m, void *da
23 if (!pa_safe_streq(hfdata->ofono_bus_id, sender) && !pa_streq("org.freedesktop.DBus", sender))
24 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
26 + dbus_error_init(&err);
28 + if (dbus_message_is_signal(m, "org.freedesktop.DBus", "NameOwnerChanged")) {
29 + const char *name, *old_owner, *new_owner;
31 + if (!dbus_message_get_args(m, &err,
32 + DBUS_TYPE_STRING, &name,
33 + DBUS_TYPE_STRING, &old_owner,
34 + DBUS_TYPE_STRING, &new_owner,
35 + DBUS_TYPE_INVALID)) {
36 + pa_log_error("Failed to parse org.freedesktop.DBus.NameOwnerChanged: %s", err.message);
40 + if (pa_streq(name, OFONO_SERVICE)) {
42 + if (old_owner && *old_owner) {
43 + pa_log_debug("oFono disappeared");
45 + if (hfdata->hf_audio_cards) {
46 + pa_hashmap_free(hfdata->hf_audio_cards);
47 + hfdata->hf_audio_cards = NULL;
50 + if(hfdata->ofono_bus_id) {
51 + pa_xfree(hfdata->ofono_bus_id);
52 + hfdata->ofono_bus_id = NULL;
56 + if (new_owner && *new_owner) {
57 + pa_log_debug("oFono appeared");
58 + hf_audio_agent_register(hfdata);
65 + dbus_error_free(&err);
66 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
69 @@ -390,7 +431,20 @@ static DBusMessage *hf_audio_agent_release(DBusConnection *c, DBusMessage *m, vo
73 - r = dbus_message_new_error(m, "org.ofono.Error.NotImplemented", "Operation is not implemented");
74 + pa_log_debug("HF audio agent has been unregistered by oFono (%s)", hfdata->ofono_bus_id);
76 + if (hfdata->hf_audio_cards) {
77 + pa_hashmap_free(hfdata->hf_audio_cards);
78 + hfdata->hf_audio_cards = NULL;
81 + if(hfdata->ofono_bus_id) {
82 + pa_xfree(hfdata->ofono_bus_id);
83 + hfdata->ofono_bus_id = NULL;
86 + pa_assert_se(r = dbus_message_new_method_return(m));
91 @@ -459,7 +513,8 @@ hf_audio_agent_data *hf_audio_agent_init(pa_core *c) {
93 hfdata = pa_xnew0(hf_audio_agent_data, 1);
95 - hfdata->hf_audio_cards = pa_hashmap_new(pa_idxset_string_hash_func, pa_idxset_string_compare_func);
96 + hfdata->hf_audio_cards = pa_hashmap_new_full(pa_idxset_string_hash_func, pa_idxset_string_compare_func,
97 + NULL, hf_audio_card_free);
98 hfdata->discovery = pa_shared_get(c, "bluetooth-discovery");
100 dbus_error_init(&err);
101 @@ -505,7 +560,7 @@ void hf_audio_agent_done(hf_audio_agent_data *data) {
102 pa_dbus_free_pending_list(&hfdata->pending);
104 if (hfdata->hf_audio_cards) {
105 - pa_hashmap_free(hfdata->hf_audio_cards, hf_audio_card_free);
106 + pa_hashmap_free(hfdata->hf_audio_cards);
107 hfdata->hf_audio_cards = NULL;