Linux bluetooth development
 help / color / mirror / Atom feed
From: Luiz Augusto von Dentz <luiz.dentz@gmail.com>
To: linux-bluetooth@vger.kernel.org
Subject: [PATCH BlueZ] android/a2dp: Cleanup devices on unregister
Date: Wed, 20 Nov 2013 11:39:54 +0200	[thread overview]
Message-ID: <1384940394-24668-1-git-send-email-luiz.dentz@gmail.com> (raw)

From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

This cleanup any existing devices in bt_a2dp_unregister
---
 android/a2dp.c | 18 +++++++++++++++---
 1 file changed, 15 insertions(+), 3 deletions(-)

diff --git a/android/a2dp.c b/android/a2dp.c
index a9e7c65..55a433e 100644
--- a/android/a2dp.c
+++ b/android/a2dp.c
@@ -109,6 +109,11 @@ static void bt_a2dp_notify_state(struct a2dp_device *dev, uint8_t state)
 
 	ipc_send(notification_sk, HAL_SERVICE_ID_A2DP,
 			HAL_EV_A2DP_CONN_STATE, sizeof(ev), &ev, -1);
+
+	if (state != HAL_A2DP_STATE_DISCONNECTED)
+		return;
+
+	a2dp_device_free(dev);
 }
 
 static gboolean watch_cb(GIOChannel *chan, GIOCondition cond, gpointer data)
@@ -117,8 +122,6 @@ static gboolean watch_cb(GIOChannel *chan, GIOCondition cond, gpointer data)
 
 	bt_a2dp_notify_state(dev, HAL_A2DP_STATE_DISCONNECTED);
 
-	a2dp_device_free(dev);
-
 	return FALSE;
 }
 
@@ -130,7 +133,6 @@ static void signaling_connect_cb(GIOChannel *chan, GError *err,
 	if (err) {
 		bt_a2dp_notify_state(dev, HAL_A2DP_STATE_DISCONNECTED);
 		error("%s", err->message);
-		a2dp_device_free(dev);
 		return;
 	}
 
@@ -364,6 +366,13 @@ bool bt_a2dp_register(int sk, const bdaddr_t *addr)
 	return true;
 }
 
+static void a2dp_device_disconnected(gpointer data, gpointer user_data)
+{
+	struct a2dp_device *dev = data;
+
+	bt_a2dp_notify_state(dev, HAL_A2DP_STATE_DISCONNECTED);
+}
+
 void bt_a2dp_unregister(void)
 {
 	DBG("");
@@ -371,6 +380,9 @@ void bt_a2dp_unregister(void)
 	if (notification_sk < 0)
 		return;
 
+	g_slist_foreach(devices, a2dp_device_disconnected, NULL);
+	devices = NULL;
+
 	notification_sk = -1;
 
 	bt_adapter_remove_record(record_id);
-- 
1.8.3.1


             reply	other threads:[~2013-11-20  9:39 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-11-20  9:39 Luiz Augusto von Dentz [this message]
2013-11-21  8:16 ` [PATCH BlueZ] android/a2dp: Cleanup devices on unregister Johan Hedberg

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1384940394-24668-1-git-send-email-luiz.dentz@gmail.com \
    --to=luiz.dentz@gmail.com \
    --cc=linux-bluetooth@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox