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

Georg Chini georg at chini.tk
Thu Mar 2 16:04:11 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 7573b89..00a2a46 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"
@@ -365,6 +366,9 @@ static void rfcomm_io_callback(pa_mainloop_api *io, pa_io_event *e, int fd, pa_i
         ssize_t len;
         int gain, dummy;
         bool  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) {
@@ -390,8 +394,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;
         }
@@ -546,6 +553,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,
         rfcomm_io_callback, t);
+    trd->connection = b->connection;
     t->userdata =  trd;
 
     sco_listen(t);
-- 
2.10.1



More information about the pulseaudio-discuss mailing list