Skip to contentSkip to conversation

Add watch for RFCOMM disconnect to HFP HF role

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

lore
Share & tools
lore
#0 lore raw

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

---
 audio/gateway.c |   19 +++++++++++++++++++
 1 files changed, 19 insertions(+), 0 deletions(-)
audio/gateway.c +19 -0
index 345f397..77aec59 100644
@@ -192,9 +192,26 @@ 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;
+
+	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;
+}
+
 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;
 
@@ -206,6 +223,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

PATCH 2/2 Minor style fix in audio/gateway.c

---
 audio/gateway.c |   15 ++++++---------
 1 files changed, 6 insertions(+), 9 deletions(-)
audio/gateway.c +6 -9
index 77aec59..e9485d0 100644
@@ -158,16 +158,13 @@ static gboolean sco_io_cb(GIOChannel *chan, GIOCondition cond,
 	if (cond & G_IO_NVAL)
 		return FALSE;
 
-	if (cond & (G_IO_ERR | G_IO_HUP)) {
-		DBG("sco connection is released");
-		g_io_channel_shutdown(gw->sco, TRUE, NULL);
-		g_io_channel_unref(gw->sco);
-		gw->sco = NULL;
-		change_state(dev, GATEWAY_STATE_CONNECTED);
-		return FALSE;
-	}
+	DBG("sco connection is released");
+	g_io_channel_shutdown(gw->sco, TRUE, NULL);
+	g_io_channel_unref(gw->sco);
+	gw->sco = NULL;
+	change_state(dev, GATEWAY_STATE_CONNECTED);
 
-	return TRUE;
+	return FALSE;
 }
 
 static void sco_connect_cb(GIOChannel *chan, GError *err, gpointer user_data)
Signature · 1 line
1.7.1
#2 lore raw
In reply to Frédéric Dalleau

Hi Frédéric,

Quoted 3 lines · Frédéric Dalleau
---
 audio/gateway.c |   19 +++++++++++++++++++
 1 files changed, 19 insertions(+), 0 deletions(-)

Both patches have been applied. Thanks.

Johan