[pulseaudio-discuss] [PATCH 4/4] backend-native: send DBus signal on headset button press

Georg Chini georg at chini.tk
Tue Feb 14 13:33:03 UTC 2017


Currently pressing the headset button is ignored. This patch sends a DBUS
signal that can be caught by applications to trigger events like picking
up or ending a phone call.

---
 src/modules/bluetooth/backend-native.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/src/modules/bluetooth/backend-native.c b/src/modules/bluetooth/backend-native.c
index 66d545d..437d0bc 100644
--- a/src/modules/bluetooth/backend-native.c
+++ b/src/modules/bluetooth/backend-native.c
@@ -51,6 +51,7 @@ struct transport_data {
     int sco_fd;
     pa_io_event *sco_io;
     pa_mainloop_api *mainloop;
+    pa_dbus_connection *connection;
 };
 
 #define BLUEZ_SERVICE "org.bluez"
@@ -351,6 +352,9 @@ static void rfcomm_io_callback(pa_mainloop_api *io, pa_io_event *e, int fd, pa_i
         char buf[512];
         ssize_t len;
         int gain, dummy, do_reply = FALSE;
+        struct transport_data *trd = t->userdata;
+        DBusMessage *msg;
+        dbus_uint32_t serial = 0;
 
         len = pa_read(fd, buf, 511, NULL);
         if (len < 0) {
@@ -369,8 +373,11 @@ static void rfcomm_io_callback(pa_mainloop_api *io, pa_io_event *e, int fd, pa_i
             t->microphone_gain = gain;
             pa_hook_fire(pa_bluetooth_discovery_hook(t->device->discovery, PA_BLUETOOTH_HOOK_TRANSPORT_MICROPHONE_GAIN_CHANGED), t);
             do_reply = TRUE;
-        } else if (sscanf(buf, "AT+CKPD=%d", &dummy) == 1) {
+        } else if (sscanf(buf, "AT+CKPD=%d", &dummy) == 1 || sscanf(buf, "\r\nAT+CKPD=%d", &dummy) == 1) {
             do_reply = TRUE;
+            msg = dbus_message_new_signal(t->device->path, "org.bluez.Headset", "ButtonPress");
+            if (msg)
+               dbus_connection_send(pa_dbus_connection_get(trd->connection), msg, &serial);
         } else {
             do_reply = FALSE;
         }
@@ -519,6 +526,7 @@ static DBusMessage *profile_new_connection(DBusConnection *conn, DBusMessage *m,
     trd->mainloop = b->core->mainloop;
     trd->rfcomm_io = trd->mainloop->io_new(b->core->mainloop, fd, PA_IO_EVENT_INPUT|PA_IO_EVENT_HANGUP|PA_IO_EVENT_ERROR,
         rfcomm_io_callback, t);
+    trd->connection = b->connection;
     t->userdata =  trd;
 
     bluez5_sco_listen(t);
-- 
2.10.1



More information about the pulseaudio-discuss mailing list