Diff between e7d3fbceb74c00baafe44cbe1bd9de93f660b045 and c80e3120f896a820f9e8e3e58acc1a99015a2993

Changed Files

File Additions Deletions Status
profiles/audio/avctp.c +8 -1 modified
profiles/audio/avctp.h +2 -1 modified
profiles/audio/avrcp.c +1 -1 modified
profiles/audio/control.c +4 -4 modified
profiles/audio/device.c +4 -4 modified

Full Patch

diff --git a/profiles/audio/avctp.c b/profiles/audio/avctp.c
index c276c52..3516640 100644
--- a/profiles/audio/avctp.c
+++ b/profiles/audio/avctp.c
@@ -114,6 +114,7 @@ struct avc_header {
 
 struct avctp_state_callback {
 	avctp_state_cb cb;
+	struct audio_device *dev;
 	void *user_data;
 	unsigned int id;
 };
@@ -477,6 +478,10 @@ static void avctp_set_state(struct avctp *session, avctp_state_t new_state)
 
 	for (l = callbacks; l != NULL; l = l->next) {
 		struct avctp_state_callback *cb = l->data;
+
+		if (cb->dev && cb->dev != dev)
+			continue;
+
 		cb->cb(dev, old_state, new_state, cb->user_data);
 	}
 
@@ -1639,13 +1644,15 @@ int avctp_send_vendordep_req(struct avctp *session, uint8_t code,
 						func, user_data);
 }
 
-unsigned int avctp_add_state_cb(avctp_state_cb cb, void *user_data)
+unsigned int avctp_add_state_cb(struct audio_device *dev, avctp_state_cb cb,
+								void *user_data)
 {
 	struct avctp_state_callback *state_cb;
 	static unsigned int id = 0;
 
 	state_cb = g_new(struct avctp_state_callback, 1);
 	state_cb->cb = cb;
+	state_cb->dev = dev;
 	state_cb->user_data = user_data;
 	state_cb->id = ++id;
 
diff --git a/profiles/audio/avctp.h b/profiles/audio/avctp.h
index 411b093..7d05572 100644
--- a/profiles/audio/avctp.h
+++ b/profiles/audio/avctp.h
@@ -92,7 +92,8 @@ typedef size_t (*avctp_browsing_pdu_cb) (struct avctp *session,
 					uint8_t *operands, size_t operand_count,
 					void *user_data);
 
-unsigned int avctp_add_state_cb(avctp_state_cb cb, void *user_data);
+unsigned int avctp_add_state_cb(struct audio_device *dev, avctp_state_cb cb,
+							void *user_data);
 gboolean avctp_remove_state_cb(unsigned int id);
 
 int avctp_register(struct btd_adapter *adapter, gboolean master);
diff --git a/profiles/audio/avrcp.c b/profiles/audio/avrcp.c
index abb902a..6965fe2 100644
--- a/profiles/audio/avrcp.c
+++ b/profiles/audio/avrcp.c
@@ -2832,7 +2832,7 @@ int avrcp_register(struct btd_adapter *adapter, GKeyFile *config)
 	servers = g_slist_append(servers, server);
 
 	if (!avctp_id)
-		avctp_id = avctp_add_state_cb(state_changed, NULL);
+		avctp_id = avctp_add_state_cb(NULL, state_changed, NULL);
 
 	return 0;
 }
diff --git a/profiles/audio/control.c b/profiles/audio/control.c
index 18c8478..b50e890 100644
--- a/profiles/audio/control.c
+++ b/profiles/audio/control.c
@@ -59,11 +59,10 @@
 #include "glib-helper.h"
 #include "dbus-common.h"
 
-static unsigned int avctp_id = 0;
-
 struct control {
 	struct avctp *session;
 	gboolean target;
+	unsigned int avctp_id;
 };
 
 static void state_changed(struct audio_device *dev, avctp_state_t old_state,
@@ -250,6 +249,8 @@ static void path_unregister(void *data)
 	if (control->session)
 		avctp_disconnect(control->session);
 
+	avctp_remove_state_cb(control->avctp_id);
+
 	g_free(control);
 	dev->control = NULL;
 }
@@ -286,8 +287,7 @@ struct control *control_init(struct audio_device *dev, GSList *uuids)
 
 	control_update(control, uuids);
 
-	if (!avctp_id)
-		avctp_id = avctp_add_state_cb(state_changed, NULL);
+	control->avctp_id = avctp_add_state_cb(dev, state_changed, NULL);
 
 	return control;
 }
diff --git a/profiles/audio/device.c b/profiles/audio/device.c
index 8d5e10f..bd62434 100644
--- a/profiles/audio/device.c
+++ b/profiles/audio/device.c
@@ -81,10 +81,10 @@ struct dev_priv {
 	gboolean disconnecting;
 
 	unsigned int avdtp_callback_id;
+	unsigned int avctp_callback_id;
 };
 
 static unsigned int sink_callback_id = 0;
-static unsigned int avctp_callback_id = 0;
 
 static void device_free(struct audio_device *dev)
 {
@@ -100,6 +100,7 @@ static void device_free(struct audio_device *dev)
 							priv->dc_id);
 
 		avdtp_remove_state_cb(priv->avdtp_callback_id);
+		avctp_remove_state_cb(priv->avctp_callback_id);
 
 		g_free(priv);
 	}
@@ -315,9 +316,8 @@ struct audio_device *audio_device_register(struct btd_device *device)
 		sink_callback_id = sink_add_state_cb(device_sink_cb, NULL);
 
 	dev->priv->avdtp_callback_id = avdtp_add_state_cb(dev, device_avdtp_cb);
-
-	if (avctp_callback_id == 0)
-		avctp_callback_id = avctp_add_state_cb(device_avctp_cb, NULL);
+	dev->priv->avctp_callback_id = avctp_add_state_cb(dev, device_avctp_cb,
+									NULL);
 
 	return dev;
 }