0a93d5c34fc98a848fbe477f00568ad2b39a06eb
[scm/bb/meta-tizen.git] / recipes-multimedia / pulseaudio / pulseaudio_5.0 / 0013-bluetooth-Monitor-D-Bus-signals.patch
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
4
5 Change-Id: Ibfd4ab9acaf49df0fdfaff55609c560ab31f4df4
6 ---
7  src/modules/bluetooth/hfaudioagent-ofono.c | 48 ++++++++++++++++++++++++++++++
8  1 file changed, 48 insertions(+)
9
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
14 @@ -30,6 +30,7 @@
15  
16  #define OFONO_SERVICE "org.ofono"
17  #define HF_AUDIO_AGENT_INTERFACE OFONO_SERVICE ".HandsfreeAudioAgent"
18 +#define HF_AUDIO_MANAGER_INTERFACE OFONO_SERVICE ".HandsfreeAudioManager"
19  
20  #define HF_AUDIO_AGENT_PATH "/HandsfreeAudioAgent"
21  
22 @@ -55,8 +56,18 @@
23  struct hf_audio_agent_data {
24      pa_core *core;
25      pa_dbus_connection *connection;
26 +
27 +    bool filter_added;
28 +    pa_hashmap *hf_audio_cards;
29  };
30  
31 +static DBusHandlerResult filter_cb(DBusConnection *bus, DBusMessage *m, void *data) {
32 +    pa_assert(bus);
33 +    pa_assert(m);
34 +
35 +    return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
36 +}
37 +
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");
40      return r;
41 @@ -115,6 +126,7 @@ hf_audio_agent_data *hf_audio_agent_init(pa_core *c) {
42  
43      hfdata = pa_xnew0(hf_audio_agent_data, 1);
44      hfdata->core = c;
45 +    hfdata->hf_audio_cards = pa_hashmap_new(pa_idxset_string_hash_func, pa_idxset_string_compare_func);
46  
47      dbus_error_init(&err);
48  
49 @@ -124,6 +136,25 @@ hf_audio_agent_data *hf_audio_agent_init(pa_core *c) {
50          return NULL;
51      }
52  
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);
57 +        return NULL;
58 +    }
59 +    hfdata->filter_added = true;
60 +
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'",
66 +            NULL) < 0) {
67 +        pa_log("Failed to add oFono D-Bus matches: %s", err.message);
68 +        hf_audio_agent_done(hfdata);
69 +        return NULL;
70 +    }
71 +
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));
74  
75 @@ -135,7 +166,24 @@ void hf_audio_agent_done(hf_audio_agent_data *data) {
76  
77      pa_assert(hfdata);
78  
79 +    if (hfdata->hf_audio_cards) {
80 +        pa_hashmap_free(hfdata->hf_audio_cards, NULL);
81 +        hfdata->hf_audio_cards = NULL;
82 +    }
83 +
84      if (hfdata->connection) {
85 +
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'",
92 +            NULL);
93 +
94 +        if (hfdata->filter_added)
95 +            dbus_connection_remove_filter(pa_dbus_connection_get(hfdata->connection), filter_cb, hfdata);
96 +
97          dbus_connection_unregister_object_path(pa_dbus_connection_get(hfdata->connection), HF_AUDIO_AGENT_PATH);
98  
99          pa_dbus_connection_unref(hfdata->connection);