Skip to contentSkip to conversation

Add watch for RFCOMM disconnect to HFP HF role

PATCH In review Frédéric Dalleau 2 participants 4 messages Aug 4, 2011 Bluetooth drivers

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Add watch for RFCOMM disconnect to HFP HF role

---
 audio/gateway.c |   22 ++++++++++++++++++++++
 1 files changed, 22 insertions(+), 0 deletions(-)
audio/gateway.c +22 -0
index ec0ec5d..200930f 100644
@@ -188,9 +188,29 @@ static void sco_connect_cb(GIOChannel *chan, GError *err, gpointer user_data)
 				(GIOFunc) sco_io_cb, dev);
 }
 
+static gboolean rfcomm_disconnect_cb(GIOChannel *chan, GIOCondition cond,
+			struct audio_device *dev)
+{
+	struct gateway *gw = dev->gateway;
+
+	if (cond & G_IO_NVAL)
+		return FALSE;
+
+	if (cond & (G_IO_ERR | G_IO_HUP)) {
+		g_io_channel_shutdown(gw->rfcomm, TRUE, NULL);
+		g_io_channel_unref(gw->rfcomm);
+		gw->rfcomm = NULL;
+		change_state(dev, GATEWAY_STATE_DISCONNECTED);
+		return FALSE;
+	}
+
+	return TRUE;
+}
+
 static void newconnection_reply(DBusPendingCall *call, void *data)
 {
 	struct audio_device *dev = data;
+	struct gateway *gw = dev->gateway;
 	DBusMessage *reply = dbus_pending_call_steal_reply(call);
 	DBusError derr;
 
@@ -202,6 +222,8 @@ static void newconnection_reply(DBusPendingCall *call, void *data)
 	dbus_error_init(&derr);
 	if (!dbus_set_error_from_message(&derr, reply)) {
 		DBG("Agent reply: file descriptor passed successfully");
+		g_io_add_watch(gw->rfcomm, G_IO_ERR | G_IO_HUP | G_IO_NVAL,
+					(GIOFunc) rfcomm_disconnect_cb, dev);
 		change_state(dev, GATEWAY_STATE_CONNECTED);
 		goto done;
 	}
Signature · 1 line
1.7.1
#1 lore raw

Hi Frédéric,

Quoted 11 lines · Frédéric Dalleau
---
 audio/gateway.c |   22 ++++++++++++++++++++++
 1 files changed, 22 insertions(+), 0 deletions(-)
audio/gateway.c +0 -0
index ec0ec5d..200930f 100644
@@ -188,9 +188,29 @@ static void sco_connect_cb(GIOChannel *chan, GError *err, gpointer user_data)
 				(GIOFunc) sco_io_cb, dev);
 }

audio/gateway.c static void sco_connect_cb(GIOChannel *chan, GError *err, gpointer user_data) · line 199

Quoted 10 lines
audio/gateway.c +9 -0
 
+static gboolean rfcomm_disconnect_cb(GIOChannel *chan, GIOCondition cond,
+			struct audio_device *dev)
+{
+	struct gateway *gw = dev->gateway;
+
+	if (cond & G_IO_NVAL)
+		return FALSE;
+
+	if (cond & (G_IO_ERR | G_IO_HUP)) {

Since this function is only called for NVAL, ERR and HUP, do you even need to have this check here. Maybe you could just get rid of this second if-statement.

Johan

#2 lore raw

Hi Johan,

Quoted 5 lines

Review

Quoted 1 line
(quoted diff) +1 -0
+	if (cond&  (G_IO_ERR | G_IO_HUP)) {

Since this function is only called for NVAL, ERR and HUP, do you even need to have this check here. Maybe you could just get rid of this second if-statement.

To be rigorous the test is not needed. This is more a matter of consistency, since the code is nearly a copy paste of the existing sco_io_cb.

If it is ok for you, I'll update both funcs.

Regards,
Frédéric

#3 lore raw
Quoted 11 lines · Frédéric Dalleau
Quoted 5 lines

Review

Quoted 1 line
(quoted diff) +1 -0
+	if (cond&  (G_IO_ERR | G_IO_HUP)) {

Since this function is only called for NVAL, ERR and HUP, do you even need to have this check here. Maybe you could just get rid of this second if-statement.

To be rigorous the test is not needed. This is more a matter of consistency, since the code is nearly a copy paste of the existing sco_io_cb.

If it is ok for you, I'll update both funcs.

Yes, though separate patches please.

Johan