Diff between a2efd20b5bd0d7dd210073a72275a373000aae8d and 3b3c95f804085a0750c763bd994a6ed48cb88e7e

Changed Files

File Additions Deletions Status
profiles/audio/manager.c +22 -2 modified
profiles/audio/manager.h +5 -0 modified
profiles/audio/source.c +42 -87 modified
profiles/audio/source.h +2 -3 modified

Full Patch

diff --git a/profiles/audio/manager.c b/profiles/audio/manager.c
index 3a6ea85..7025868 100644
--- a/profiles/audio/manager.c
+++ b/profiles/audio/manager.c
@@ -202,7 +202,7 @@ static int a2dp_source_connect(struct btd_device *dev,
 		return -1;
 	}
 
-	return source_connect(audio_dev, connect_cb, profile);
+	return source_connect(audio_dev);
 }
 
 static int a2dp_source_disconnect(struct btd_device *dev,
@@ -219,7 +219,7 @@ static int a2dp_source_disconnect(struct btd_device *dev,
 		return -1;
 	}
 
-	return source_disconnect(audio_dev, FALSE, disconnect_cb, profile);
+	return source_disconnect(audio_dev, FALSE);
 }
 
 static int a2dp_sink_connect(struct btd_device *dev,
@@ -492,6 +492,26 @@ static struct btd_adapter_driver media_driver = {
 	.remove	= media_server_remove,
 };
 
+void audio_sink_connected(struct btd_device *dev, int err)
+{
+	device_profile_connected(dev, &a2dp_sink_profile, err);
+}
+
+void audio_sink_disconnected(struct btd_device *dev, int err)
+{
+	device_profile_connected(dev, &a2dp_sink_profile, err);
+}
+
+void audio_source_connected(struct btd_device *dev, int err)
+{
+	device_profile_connected(dev, &a2dp_source_profile, err);
+}
+
+void audio_source_disconnected(struct btd_device *dev, int err)
+{
+	device_profile_connected(dev, &a2dp_source_profile, err);
+}
+
 int audio_manager_init(GKeyFile *conf)
 {
 	char **list;
diff --git a/profiles/audio/manager.h b/profiles/audio/manager.h
index 5691063..75c1308 100644
--- a/profiles/audio/manager.h
+++ b/profiles/audio/manager.h
@@ -29,6 +29,11 @@ struct enabled_interfaces {
 	gboolean media_player;
 };
 
+void audio_sink_connected(struct btd_device *dev, int err);
+void audio_sink_disconnected(struct btd_device *dev, int err);
+void audio_source_connected(struct btd_device *dev, int err);
+void audio_source_disconnected(struct btd_device *dev, int err);
+
 int audio_manager_init(GKeyFile *config);
 void audio_manager_exit(void);
 
diff --git a/profiles/audio/source.c b/profiles/audio/source.c
index 85aeb4f..ef6cf7a 100644
--- a/profiles/audio/source.c
+++ b/profiles/audio/source.c
@@ -45,6 +45,7 @@
 #include "media.h"
 #include "a2dp.h"
 #include "error.h"
+#include "manager.h"
 #include "source.h"
 #include "dbus-common.h"
 #include "../src/adapter.h"
@@ -52,12 +53,6 @@
 
 #define STREAM_SETUP_RETRY_TIMER 2
 
-struct pending_request {
-	audio_device_cb cb;
-	void *cb_data;
-	unsigned int id;
-};
-
 struct source {
 	struct audio_device *dev;
 	struct avdtp *session;
@@ -67,8 +62,8 @@ struct source {
 	avdtp_session_state_t session_state;
 	avdtp_state_t stream_state;
 	source_state_t state;
-	struct pending_request *connect;
-	struct pending_request *disconnect;
+	unsigned int connect_id;
+	unsigned int disconnect_id;
 };
 
 struct source_state_callback {
@@ -138,19 +133,6 @@ static void avdtp_state_callback(struct audio_device *dev,
 	source->session_state = new_state;
 }
 
-static void pending_request_free(struct audio_device *dev,
-					struct pending_request *pending,
-					int err)
-{
-	if (pending->cb)
-		pending->cb(dev, err, pending->cb_data);
-
-	if (pending->id)
-		a2dp_cancel(dev, pending->id);
-
-	g_free(pending);
-}
-
 static void stream_state_changed(struct avdtp_stream *stream,
 					avdtp_state_t old_state,
 					avdtp_state_t new_state,
@@ -165,13 +147,11 @@ static void stream_state_changed(struct avdtp_stream *stream,
 
 	switch (new_state) {
 	case AVDTP_STATE_IDLE:
-		if (source->disconnect) {
-			struct pending_request *p;
-
-			p = source->disconnect;
-			source->disconnect = NULL;
+		audio_source_disconnected(dev->btd_dev, 0);
 
-			pending_request_free(dev, p, 0);
+		if (source->disconnect_id > 0) {
+			a2dp_cancel(dev, source->disconnect_id);
+			source->disconnect_id = 0;
 		}
 
 		if (source->session) {
@@ -200,7 +180,6 @@ static void stream_state_changed(struct avdtp_stream *stream,
 static gboolean stream_setup_retry(gpointer user_data)
 {
 	struct source *source = user_data;
-	struct pending_request *pending = source->connect;
 	int err;
 
 	source->retry_id = 0;
@@ -213,8 +192,12 @@ static gboolean stream_setup_retry(gpointer user_data)
 		err = -EIO;
 	}
 
-	source->connect = NULL;
-	pending_request_free(source->dev, pending, err);
+	audio_source_connected(source->dev->btd_dev, err);
+
+	if (source->connect_id > 0) {
+		a2dp_cancel(source->dev, source->connect_id);
+		source->connect_id = 0;
+	}
 
 	return FALSE;
 }
@@ -224,18 +207,12 @@ static void stream_setup_complete(struct avdtp *session, struct a2dp_sep *sep,
 					struct avdtp_error *err, void *user_data)
 {
 	struct source *source = user_data;
-	struct pending_request *pending;
-
-	pending = source->connect;
 
-	pending->id = 0;
+	source->connect_id = 0;
 
 	if (stream) {
 		DBG("Stream successfully created");
-
-		source->connect = NULL;
-		pending_request_free(source->dev, pending, 0);
-
+		audio_source_connected(source->dev->btd_dev, 0);
 		return;
 	}
 
@@ -248,9 +225,8 @@ static void stream_setup_complete(struct avdtp *session, struct a2dp_sep *sep,
 							stream_setup_retry,
 							source);
 	} else {
-		source->connect = NULL;
-		pending_request_free(source->dev, pending, -EIO);
 		DBG("Stream setup failed : %s", avdtp_strerror(err));
+		audio_source_connected(source->dev->btd_dev, -EIO);
 	}
 }
 
@@ -258,12 +234,9 @@ static void select_complete(struct avdtp *session, struct a2dp_sep *sep,
 			GSList *caps, void *user_data)
 {
 	struct source *source = user_data;
-	struct pending_request *pending;
 	int id;
 
-	pending = source->connect;
-
-	pending->id = 0;
+	source->connect_id = 0;
 
 	if (caps == NULL)
 		goto failed;
@@ -272,12 +245,12 @@ static void select_complete(struct avdtp *session, struct a2dp_sep *sep,
 	if (id == 0)
 		goto failed;
 
-	pending->id = id;
+	source->connect_id = id;
 	return;
 
 failed:
-	pending_request_free(source->dev, pending, -EIO);
-	source->connect = NULL;
+	audio_source_connected(source->dev->btd_dev, -EIO);
+
 	avdtp_unref(source->session);
 	source->session = NULL;
 }
@@ -286,11 +259,8 @@ static void discovery_complete(struct avdtp *session, GSList *seps, struct avdtp
 				void *user_data)
 {
 	struct source *source = user_data;
-	struct pending_request *pending;
 	int id;
 
-	pending = source->connect;
-
 	if (err) {
 		avdtp_unref(source->session);
 		source->session = NULL;
@@ -313,19 +283,18 @@ static void discovery_complete(struct avdtp *session, GSList *seps, struct avdtp
 	if (id == 0)
 		goto failed;
 
-	pending->id = id;
+	source->connect_id = id;
 	return;
 
 failed:
-	pending_request_free(source->dev, pending, -EIO);
-	source->connect = NULL;
+	audio_source_connected(source->dev->btd_dev, -EIO);
 	avdtp_unref(source->session);
 	source->session = NULL;
 }
 
 gboolean source_setup_stream(struct source *source, struct avdtp *session)
 {
-	if (source->connect || source->disconnect)
+	if (source->connect_id > 0 || source->disconnect_id > 0)
 		return FALSE;
 
 	if (session && !source->session)
@@ -337,15 +306,12 @@ gboolean source_setup_stream(struct source *source, struct avdtp *session)
 	if (avdtp_discover(source->session, discovery_complete, source) < 0)
 		return FALSE;
 
-	source->connect = g_new0(struct pending_request, 1);
-
 	return TRUE;
 }
 
-int source_connect(struct audio_device *dev, audio_device_cb cb, void *data)
+int source_connect(struct audio_device *dev)
 {
 	struct source *source = dev->source;
-	struct pending_request *pending;
 
 	if (!source->session)
 		source->session = avdtp_get(dev);
@@ -355,7 +321,7 @@ int source_connect(struct audio_device *dev, audio_device_cb cb, void *data)
 		return -EIO;
 	}
 
-	if (source->connect || source->disconnect)
+	if (source->connect_id > 0 || source->disconnect_id > 0)
 		return -EBUSY;
 
 	if (source->stream_state >= AVDTP_STATE_OPEN)
@@ -366,10 +332,6 @@ int source_connect(struct audio_device *dev, audio_device_cb cb, void *data)
 		return -EIO;
 	}
 
-	pending = source->connect;
-	pending->cb = cb;
-	pending->cb_data = data;
-
 	DBG("stream creation in progress");
 
 	return 0;
@@ -386,11 +348,17 @@ static void source_free(struct audio_device *dev)
 	if (source->session)
 		avdtp_unref(source->session);
 
-	if (source->connect)
-		pending_request_free(dev, source->connect, -ECANCELED);
+	if (source->connect_id > 0) {
+		audio_source_connected(dev->btd_dev, -ECANCELED);
+		a2dp_cancel(dev, source->disconnect_id);
+		source->disconnect_id = 0;
+	}
 
-	if (source->disconnect)
-		pending_request_free(dev, source->disconnect, -ECANCELED);
+	if (source->disconnect_id > 0) {
+		audio_source_disconnected(dev->btd_dev, -ECANCELED);
+		a2dp_cancel(dev, source->disconnect_id);
+		source->disconnect_id = 0;
+	}
 
 	if (source->retry_id)
 		g_source_remove(source->retry_id);
@@ -459,12 +427,9 @@ gboolean source_new_stream(struct audio_device *dev, struct avdtp *session,
 	return TRUE;
 }
 
-int source_disconnect(struct audio_device *dev, gboolean shutdown,
-						audio_device_cb cb, void *data)
+int source_disconnect(struct audio_device *dev, gboolean shutdown)
 {
 	struct source *source = dev->source;
-	struct pending_request *pending;
-	int err;
 
 	if (!source->session)
 		return -ENOTCONN;
@@ -473,11 +438,10 @@ int source_disconnect(struct audio_device *dev, gboolean shutdown,
 		avdtp_set_device_disconnect(source->session, TRUE);
 
 	/* cancel pending connect */
-	if (source->connect) {
-		struct pending_request *pending = source->connect;
-
-		pending_request_free(source->dev, pending, -ECANCELED);
-		source->connect = NULL;
+	if (source->connect_id > 0) {
+		a2dp_cancel(dev, source->connect_id);
+		source->connect_id = 0;
+		audio_source_connected(dev->btd_dev, -ECANCELED);
 
 		avdtp_unref(source->session);
 		source->session = NULL;
@@ -486,22 +450,13 @@ int source_disconnect(struct audio_device *dev, gboolean shutdown,
 	}
 
 	/* disconnect already ongoing */
-	if (source->disconnect)
+	if (source->disconnect_id > 0)
 		return -EBUSY;
 
 	if (!source->stream)
 		return -ENOTCONN;
 
-	err = avdtp_close(source->session, source->stream, FALSE);
-	if (err < 0)
-		return err;
-
-	pending = g_new0(struct pending_request, 1);
-	pending->cb = cb;
-	pending->cb_data = data;
-	source->disconnect = pending;
-
-	return 0;
+	return avdtp_close(source->session, source->stream, FALSE);
 }
 
 unsigned int source_add_state_cb(source_state_cb cb, void *user_data)
diff --git a/profiles/audio/source.h b/profiles/audio/source.h
index 2d382b5..a11bcff 100644
--- a/profiles/audio/source.h
+++ b/profiles/audio/source.h
@@ -44,9 +44,8 @@ struct source *source_init(struct audio_device *dev);
 void source_unregister(struct audio_device *dev);
 gboolean source_is_active(struct audio_device *dev);
 source_state_t source_get_state(struct audio_device *dev);
-int source_connect(struct audio_device *dev, audio_device_cb cb, void *data);
+int source_connect(struct audio_device *dev);
 gboolean source_new_stream(struct audio_device *dev, struct avdtp *session,
 				struct avdtp_stream *stream);
 gboolean source_setup_stream(struct source *source, struct avdtp *session);
-int source_disconnect(struct audio_device *dev, gboolean shutdown,
-						audio_device_cb cb, void *data);
+int source_disconnect(struct audio_device *dev, gboolean shutdown);