[RFCv3 12/20] bluetooth: Implement Handsfree Audio Agent NewConnection()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Jo?o Paulo Rechi Vita <jprvita@xxxxxxxxxxxxx>

This method is used by the Handsfree Audio Manager to pass the file
descriptor to the Handsfree Audio Agent.
---
 src/modules/bluetooth/bluetooth-util.c | 43 +++++++++++++++++++++++++++++++++-
 1 file changed, 42 insertions(+), 1 deletion(-)

diff --git a/src/modules/bluetooth/bluetooth-util.c b/src/modules/bluetooth/bluetooth-util.c
index ef11b9e..50555fb 100644
--- a/src/modules/bluetooth/bluetooth-util.c
+++ b/src/modules/bluetooth/bluetooth-util.c
@@ -2419,6 +2419,47 @@ static DBusMessage *hfagent_release(DBusConnection *c, DBusMessage *m, void *use
     return r;
 }
 
+static DBusMessage *hfagent_new_connection(DBusConnection *c, DBusMessage *m, void *userdata) {
+    DBusMessage *r;
+    const char *sender, *card;
+    int fd;
+    uint8_t codec;
+    struct handsfree_card *hf_card;
+    pa_bluetooth_discovery *y = userdata;
+
+    pa_assert(y);
+
+    sender = dbus_message_get_sender(m);
+    if (!pa_streq(y->ofono_bus_id, sender)) {
+        pa_assert_se(r = dbus_message_new_error(m, "org.ofono.Error.NotAllowed", "Operation is not allowed by this sender"));
+        return r;
+    }
+
+    if (dbus_message_get_args(m, NULL,
+                              DBUS_TYPE_OBJECT_PATH, &card,
+                              DBUS_TYPE_UNIX_FD, &fd,
+                              DBUS_TYPE_BYTE, &codec,
+                              DBUS_TYPE_INVALID) == FALSE) {
+        pa_assert_se(r = dbus_message_new_error(m, "org.ofono.Error.InvalidArguments", "Invalid arguments in method call"));
+        return r;
+    }
+
+    if ( !(hf_card = pa_hashmap_get(y->hf_cards, card)) ) {
+        pa_log_warn("New audio connection on unknown card %s (fd=%d, codec=%d)", card, fd, codec);
+        pa_assert_se(r = dbus_message_new_error(m, "org.ofono.Error.InvalidArguments", "Unknown card"));
+        return r;
+    } else
+        pa_log_debug("New audio connection on card %s (fd=%d, codec=%d)", card, fd, codec);
+
+    hf_card->fd = fd;
+    hf_card->codec = codec;
+    hf_card->device->transports[PROFILE_HFGW]->state = PA_BLUETOOTH_TRANSPORT_STATE_PLAYING;
+    pa_hook_fire(&y->hooks[PA_BLUETOOTH_HOOK_TRANSPORT_STATE_CHANGED], hf_card->device->transports[PROFILE_HFGW]);
+
+    pa_assert_se(r = dbus_message_new_method_return(m));
+    return r;
+}
+
 static DBusHandlerResult dbus_msg_handler(DBusConnection *c, DBusMessage *m, void *userdata) {
     struct pa_bluetooth_discovery *y = userdata;
     DBusMessage *r = NULL;
@@ -2461,7 +2502,7 @@ static DBusHandlerResult dbus_msg_handler(DBusConnection *c, DBusMessage *m, voi
     else if (dbus_message_is_method_call(m, "org.ofono.HandsfreeAudioAgent", "Release"))
         r = hfagent_release(c, m, userdata);
     else if (dbus_message_is_method_call(m, "org.ofono.HandsfreeAudioAgent", "NewConnection"))
-        pa_assert_se(r = dbus_message_new_method_return(m));
+        r = hfagent_new_connection(c, m, userdata);
     else
         return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
 
-- 
1.7.11.7



[Index of Archives]     [Linux Audio Users]     [AMD Graphics]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux