Diff between 42ab843da55125c9597a7bd8c71a2e75aab769f7 and 0b242d98736b5534068eb4e33614c6e8b9d4558e

Changed Files

File Additions Deletions Status
profiles/audio/source.c +31 -6 modified
profiles/audio/source.h +1 -1 modified

Full Patch

diff --git a/profiles/audio/source.c b/profiles/audio/source.c
index 38cb822..9981d79 100644
--- a/profiles/audio/source.c
+++ b/profiles/audio/source.c
@@ -593,15 +593,40 @@ gboolean source_new_stream(struct audio_device *dev, struct avdtp *session,
 	return TRUE;
 }
 
-gboolean source_disconnect(struct source *source)
+int source_disconnect(struct audio_device *dev, gboolean shutdown)
 {
-	if (!source->stream)
-		return FALSE;
+	struct source *source = dev->source;
 
-	if (avdtp_close(source->session, source->stream, FALSE) < 0)
-		return FALSE;
+	if (!source->session)
+		return -ENOTCONN;
 
-	return TRUE;
+	if (shutdown)
+		avdtp_set_device_disconnect(source->session, TRUE);
+
+	/* cancel pending connect */
+	if (source->connect) {
+		struct pending_request *pending = source->connect;
+
+		if (pending->msg)
+			error_failed(pending->msg, "Stream setup failed");
+
+		pending_request_free(source->dev, pending);
+		source->connect = NULL;
+
+		avdtp_unref(source->session);
+		source->session = NULL;
+
+		return 0;
+	}
+
+	/* disconnect already ongoing */
+	if (source->disconnect)
+		return -EBUSY;
+
+	if (!source->stream)
+		return -ENOTCONN;
+
+	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 49a8d64..3406754 100644
--- a/profiles/audio/source.h
+++ b/profiles/audio/source.h
@@ -47,4 +47,4 @@ source_state_t source_get_state(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);
-gboolean source_disconnect(struct source *source);
+int source_disconnect(struct audio_device *dev, gboolean shutdown);