Diff between 6b5b5139231246e2ea2b2de1120eabe7de1b7bb8 and 3bdc16d9e59cd3e740ed9f7b422e17ada30cd207

Changed Files

File Additions Deletions Status
src/shared/bap.c +64 -44 modified

Full Patch

diff --git a/src/shared/bap.c b/src/shared/bap.c
index 04ef4f4..391838a 100644
--- a/src/shared/bap.c
+++ b/src/shared/bap.c
@@ -2837,6 +2837,50 @@ static void read_sink_pac(struct bt_bap *bap, bool success, uint8_t att_ecode,
 	bap_parse_pacs(bap, BT_BAP_SINK, bap->rdb->sinks, value, length);
 }
 
+static void bap_pending_destroy(void *data)
+{
+	struct bt_bap_pending *pending = data;
+	struct bt_bap *bap = pending->bap;
+
+	if (queue_remove_if(bap->pending, NULL, pending))
+		free(pending);
+
+	bap_notify_ready(bap);
+}
+
+static void bap_pending_complete(bool success, uint8_t att_ecode,
+				const uint8_t *value, uint16_t length,
+				void *user_data)
+{
+	struct bt_bap_pending *pending = user_data;
+
+	if (pending->func)
+		pending->func(pending->bap, success, att_ecode, value, length,
+						pending->user_data);
+}
+
+static void bap_read_value(struct bt_bap *bap, uint16_t value_handle,
+				bap_func_t func, void *user_data)
+{
+	struct bt_bap_pending *pending;
+
+	pending = new0(struct bt_bap_pending, 1);
+	pending->bap = bap;
+	pending->func = func;
+	pending->user_data = user_data;
+
+	pending->id = bt_gatt_client_read_value(bap->client, value_handle,
+						bap_pending_complete, pending,
+						bap_pending_destroy);
+	if (!pending->id) {
+		DBG(bap, "Unable to send Read request");
+		free(pending);
+		return;
+	}
+
+	queue_push_tail(bap->pending, pending);
+}
+
 static void read_source_pac_loc(struct bt_bap *bap, bool success,
 				uint8_t att_ecode, const uint8_t *value,
 				uint16_t length, void *user_data)
@@ -2851,6 +2895,16 @@ static void read_source_pac_loc(struct bt_bap *bap, bool success,
 
 	gatt_db_attribute_write(pacs->source_loc, 0, value, length, 0, NULL,
 							NULL, NULL);
+
+	/* Resume reading sinks if supported but for some reason is empty */
+	if (pacs->source && queue_isempty(bap->rdb->sources)) {
+		uint16_t value_handle;
+
+		if (gatt_db_attribute_get_char_data(pacs->source,
+						NULL, &value_handle,
+						NULL, NULL, NULL))
+			bap_read_value(bap, value_handle, read_source_pac, bap);
+	}
 }
 
 static void read_sink_pac_loc(struct bt_bap *bap, bool success,
@@ -2867,6 +2921,16 @@ static void read_sink_pac_loc(struct bt_bap *bap, bool success,
 
 	gatt_db_attribute_write(pacs->sink_loc, 0, value, length, 0, NULL,
 							NULL, NULL);
+
+	/* Resume reading sinks if supported but for some reason is empty */
+	if (pacs->sink && queue_isempty(bap->rdb->sinks)) {
+		uint16_t value_handle;
+
+		if (gatt_db_attribute_get_char_data(pacs->sink,
+						NULL, &value_handle,
+						NULL, NULL, NULL))
+			bap_read_value(bap, value_handle, read_sink_pac, bap);
+	}
 }
 
 static void read_pac_context(struct bt_bap *bap, bool success,
@@ -2900,50 +2964,6 @@ static void read_pac_supported_context(struct bt_bap *bap, bool success,
 							NULL, NULL, NULL);
 }
 
-static void bap_pending_destroy(void *data)
-{
-	struct bt_bap_pending *pending = data;
-	struct bt_bap *bap = pending->bap;
-
-	if (queue_remove_if(bap->pending, NULL, pending))
-		free(pending);
-
-	bap_notify_ready(bap);
-}
-
-static void bap_pending_complete(bool success, uint8_t att_ecode,
-				const uint8_t *value, uint16_t length,
-				void *user_data)
-{
-	struct bt_bap_pending *pending = user_data;
-
-	if (pending->func)
-		pending->func(pending->bap, success, att_ecode, value, length,
-						pending->user_data);
-}
-
-static void bap_read_value(struct bt_bap *bap, uint16_t value_handle,
-				bap_func_t func, void *user_data)
-{
-	struct bt_bap_pending *pending;
-
-	pending = new0(struct bt_bap_pending, 1);
-	pending->bap = bap;
-	pending->func = func;
-	pending->user_data = user_data;
-
-	pending->id = bt_gatt_client_read_value(bap->client, value_handle,
-						bap_pending_complete, pending,
-						bap_pending_destroy);
-	if (!pending->id) {
-		DBG(bap, "Unable to send Read request");
-		free(pending);
-		return;
-	}
-
-	queue_push_tail(bap->pending, pending);
-}
-
 static void foreach_pacs_char(struct gatt_db_attribute *attr, void *user_data)
 {
 	struct bt_bap *bap = user_data;