public inbox for linux-bluetooth@vger.kernel.org
 help / color / mirror / Atom feed
From: Luiz Augusto von Dentz <luiz.dentz@gmail.com>
To: linux-bluetooth@vger.kernel.org
Subject: [PATCH BlueZ v1 2/2] client/player: Add 'auto' option to transport.select
Date: Tue, 14 Oct 2025 15:48:55 -0400	[thread overview]
Message-ID: <20251014194855.384197-2-luiz.dentz@gmail.com> (raw)
In-Reply-To: <20251014194855.384197-1-luiz.dentz@gmail.com>

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

This enables transport.select auto which enables to auto select the
broadcast transport configured with the local endpoints, the selecting
process will also dealt with linking the transport so it needs a timer
that waits all transports to be configure to then start linking and
finally select.
---
 client/player.c | 98 ++++++++++++++++++++++++++++++++++++++++++-------
 1 file changed, 85 insertions(+), 13 deletions(-)

diff --git a/client/player.c b/client/player.c
index 4f8293ce7842..54fcbb7601c0 100644
--- a/client/player.c
+++ b/client/player.c
@@ -43,6 +43,7 @@
 #include "src/shared/shell.h"
 #include "src/shared/io.h"
 #include "src/shared/queue.h"
+#include "src/shared/timeout.h"
 #include "src/shared/bap-debug.h"
 #include "print.h"
 #include "player.h"
@@ -115,6 +116,8 @@ struct endpoint {
 	uint8_t iso_group;
 	uint8_t iso_stream;
 	struct queue *acquiring;
+	struct queue *selecting;
+	unsigned int selecting_id;
 	struct queue *transports;
 	DBusMessage *msg;
 	struct preset *preset;
@@ -135,6 +138,7 @@ static GList *transports = NULL;
 static struct queue *ios = NULL;
 static uint8_t bcast_code[] = BCAST_CODE;
 static bool auto_acquire = false;
+static bool auto_select = false;
 
 struct transport {
 	GDBusProxy *proxy;
@@ -1096,6 +1100,76 @@ static void confirm_response(const char *input, void *user_data)
 									NULL);
 }
 
+static bool match_proxy(const void *data, const void *user_data)
+{
+	const struct transport *transport = data;
+	const GDBusProxy *proxy = user_data;
+
+	return transport->proxy == proxy;
+}
+
+static struct transport *find_transport(GDBusProxy *proxy)
+{
+	return queue_find(ios, match_proxy, proxy);
+}
+
+static bool ep_selecting_process(void *user_data)
+{
+	struct endpoint *ep = user_data;
+	struct transport_select_args *args;
+	const struct queue_entry *entry;
+
+	if (queue_isempty(ep->selecting))
+		return true;
+
+	args = g_new0(struct transport_select_args, 1);
+
+	for (entry = queue_get_entries(ep->selecting); entry;
+					entry = entry->next) {
+		GDBusProxy *link;
+
+		link = g_dbus_proxy_lookup(transports, NULL, entry->data,
+					BLUEZ_MEDIA_TRANSPORT_INTERFACE);
+		if (!link)
+			continue;
+
+		if (find_transport(link))
+			continue;
+
+		if (!args->proxy) {
+			args->proxy = link;
+			continue;
+		}
+
+		if (!args->links)
+			args->links = queue_new();
+
+		/* Enqueue all links */
+		queue_push_tail(args->links, link);
+	}
+
+	queue_destroy(ep->selecting, NULL);
+	ep->selecting = NULL;
+
+	transport_set_links(args);
+
+	return true;
+}
+
+static void ep_set_selecting(struct endpoint *ep, const char *path)
+{
+	bt_shell_printf("Transport %s selecting\n", path);
+
+	if (!ep->selecting)
+		ep->selecting = queue_new();
+
+	queue_push_tail(ep->selecting, strdup(path));
+
+	if (!ep->selecting_id)
+		ep->selecting_id = timeout_add(1000, ep_selecting_process, ep,
+						NULL);
+}
+
 static DBusMessage *endpoint_set_configuration(DBusConnection *conn,
 					DBusMessage *msg, void *user_data)
 {
@@ -1133,6 +1207,9 @@ static DBusMessage *endpoint_set_configuration(DBusConnection *conn,
 	queue_push_tail(ep->transports, strdup(path));
 
 	if (ep->auto_accept) {
+		if (auto_select && ep->broadcast)
+			ep_set_selecting(ep, path);
+
 		bt_shell_printf("Auto Accepting...\n");
 		return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
 	}
@@ -2936,7 +3013,10 @@ static void endpoint_free(void *data)
 	if (ep->codec == 0xff)
 		free(ep->preset);
 
+	timeout_remove(ep->selecting_id);
+
 	queue_destroy(ep->acquiring, NULL);
+	queue_destroy(ep->selecting, free);
 	queue_destroy(ep->transports, free);
 
 	g_free(ep->path);
@@ -5205,19 +5285,6 @@ static void cmd_show_transport(int argc, char *argv[])
 	return bt_shell_noninteractive_quit(EXIT_SUCCESS);
 }
 
-static bool match_proxy(const void *data, const void *user_data)
-{
-	const struct transport *transport = data;
-	const GDBusProxy *proxy = user_data;
-
-	return transport->proxy == proxy;
-}
-
-static struct transport *find_transport(GDBusProxy *proxy)
-{
-	return queue_find(ios, match_proxy, proxy);
-}
-
 static void cmd_acquire_transport(int argc, char *argv[])
 {
 	GDBusProxy *proxy;
@@ -5446,6 +5513,11 @@ static void cmd_select_transport(int argc, char *argv[])
 	struct transport_select_args *args;
 	int i;
 
+	if (argc == 2 && !strcmp(argv[1], "auto")) {
+		auto_select = true;
+		return bt_shell_noninteractive_quit(EXIT_SUCCESS);
+	}
+
 	args = g_new0(struct transport_select_args, 1);
 
 	for (i = 1; i < argc; i++) {
-- 
2.51.0


  reply	other threads:[~2025-10-14 19:49 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-10-14 19:48 [PATCH BlueZ v1 1/2] client/player: Add 'auto' option to transport.acquire Luiz Augusto von Dentz
2025-10-14 19:48 ` Luiz Augusto von Dentz [this message]
2025-10-14 21:15 ` [BlueZ,v1,1/2] " bluez.test.bot
2025-10-14 22:30 ` [PATCH BlueZ v1 1/2] " patchwork-bot+bluetooth

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=20251014194855.384197-2-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