1 From: =?utf-8?q?Jo=C3=A3o_Paulo_Rechi_Vita?= <jprvita@openbossa.org>
2 Date: Wed, 10 Jul 2013 12:18:07 -0300
3 Subject: bluetooth: Monitor D-Bus signals
5 Change-Id: Ibfd4ab9acaf49df0fdfaff55609c560ab31f4df4
7 src/modules/bluetooth/hfaudioagent-ofono.c | 48 ++++++++++++++++++++++++++++++
8 1 file changed, 48 insertions(+)
10 diff --git a/src/modules/bluetooth/hfaudioagent-ofono.c b/src/modules/bluetooth/hfaudioagent-ofono.c
11 index af78d4d..0e3ffc4 100644
12 --- a/src/modules/bluetooth/hfaudioagent-ofono.c
13 +++ b/src/modules/bluetooth/hfaudioagent-ofono.c
16 #define OFONO_SERVICE "org.ofono"
17 #define HF_AUDIO_AGENT_INTERFACE OFONO_SERVICE ".HandsfreeAudioAgent"
18 +#define HF_AUDIO_MANAGER_INTERFACE OFONO_SERVICE ".HandsfreeAudioManager"
20 #define HF_AUDIO_AGENT_PATH "/HandsfreeAudioAgent"
23 struct hf_audio_agent_data {
25 pa_dbus_connection *connection;
28 + pa_hashmap *hf_audio_cards;
31 +static DBusHandlerResult filter_cb(DBusConnection *bus, DBusMessage *m, void *data) {
35 + return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
38 static DBusMessage *hf_audio_agent_release(DBusConnection *c, DBusMessage *m, void *data) {
39 DBusMessage *r = dbus_message_new_error(m, "org.ofono.Error.NotImplemented", "Operation is not implemented");
41 @@ -115,6 +126,7 @@ hf_audio_agent_data *hf_audio_agent_init(pa_core *c) {
43 hfdata = pa_xnew0(hf_audio_agent_data, 1);
45 + hfdata->hf_audio_cards = pa_hashmap_new(pa_idxset_string_hash_func, pa_idxset_string_compare_func);
47 dbus_error_init(&err);
49 @@ -124,6 +136,25 @@ hf_audio_agent_data *hf_audio_agent_init(pa_core *c) {
53 + /* dynamic detection of handsfree audio cards */
54 + if (!dbus_connection_add_filter(pa_dbus_connection_get(hfdata->connection), filter_cb, hfdata, NULL)) {
55 + pa_log_error("Failed to add filter function");
56 + hf_audio_agent_done(hfdata);
59 + hfdata->filter_added = true;
61 + if (pa_dbus_add_matches(pa_dbus_connection_get(hfdata->connection), &err,
62 + "type='signal',sender='org.freedesktop.DBus',interface='org.freedesktop.DBus',member='NameOwnerChanged',"
63 + "arg0='" OFONO_SERVICE "'",
64 + "type='signal',sender='" OFONO_SERVICE "',interface='" HF_AUDIO_MANAGER_INTERFACE "',member='CardAdded'",
65 + "type='signal',sender='" OFONO_SERVICE "',interface='" HF_AUDIO_MANAGER_INTERFACE "',member='CardRemoved'",
67 + pa_log("Failed to add oFono D-Bus matches: %s", err.message);
68 + hf_audio_agent_done(hfdata);
72 pa_assert_se(dbus_connection_register_object_path(pa_dbus_connection_get(hfdata->connection), HF_AUDIO_AGENT_PATH,
73 &vtable_hf_audio_agent, hfdata));
75 @@ -135,7 +166,24 @@ void hf_audio_agent_done(hf_audio_agent_data *data) {
79 + if (hfdata->hf_audio_cards) {
80 + pa_hashmap_free(hfdata->hf_audio_cards, NULL);
81 + hfdata->hf_audio_cards = NULL;
84 if (hfdata->connection) {
86 + pa_dbus_remove_matches(
87 + pa_dbus_connection_get(hfdata->connection),
88 + "type='signal',sender='org.freedesktop.DBus',interface='org.freedesktop.DBus',member='NameOwnerChanged',"
89 + "arg0='" OFONO_SERVICE "'",
90 + "type='signal',sender='" OFONO_SERVICE "',interface='" HF_AUDIO_MANAGER_INTERFACE "',member='CardAdded'",
91 + "type='signal',sender='" OFONO_SERVICE "',interface='" HF_AUDIO_MANAGER_INTERFACE "',member='CardRemoved'",
94 + if (hfdata->filter_added)
95 + dbus_connection_remove_filter(pa_dbus_connection_get(hfdata->connection), filter_cb, hfdata);
97 dbus_connection_unregister_object_path(pa_dbus_connection_get(hfdata->connection), HF_AUDIO_AGENT_PATH);
99 pa_dbus_connection_unref(hfdata->connection);