diff mbox series

[BlueZ,2/5] client: Allow transport.send command to work with multiple transports

Message ID 20230301013842.718438-2-luiz.dentz@gmail.com (mailing list archive)
State New, archived
Headers show
Series [BlueZ,1/5] device: Don't attempt to connect LE if ATT is already connected | expand

Checks

Context Check Description
tedd_an/pre-ci_am success Success
tedd_an/CheckPatch success CheckPatch PASS
tedd_an/GitLint fail WARNING: I3 - ignore-body-lines: gitlint will be switching from using Python regex 'match' (match beginning) to 'search' (match anywhere) semantics. Please review your ignore-body-lines.regex option accordingly. To remove this warning, set general.regex-style-search=True. More details: https://jorisroovers.github.io/gitlint/configuration/#regex-style-search 1: T1 Title exceeds max length (81>80): "[BlueZ,2/5] client: Allow transport.send command to work with multiple transports"
tedd_an/IncrementalBuild success Incremental Build PASS

Commit Message

Luiz Augusto von Dentz March 1, 2023, 1:38 a.m. UTC
From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

This enables transport.send to work with multiple transports instead of
sending one by one which can create synchronization problems.
---
 client/player.c | 71 +++++++++++++++++++++++++++----------------------
 1 file changed, 39 insertions(+), 32 deletions(-)
diff mbox series

Patch

diff --git a/client/player.c b/client/player.c
index 65cac3b50376..767304b567b6 100644
--- a/client/player.c
+++ b/client/player.c
@@ -3566,48 +3566,54 @@  static void cmd_send_transport(int argc, char *argv[])
 {
 	GDBusProxy *proxy;
 	struct transport *transport;
-	int fd, err;
+	int fd = -1, err;
 	struct bt_iso_qos qos;
 	socklen_t len;
+	int i;
 
-	proxy = g_dbus_proxy_lookup(transports, NULL, argv[1],
+	for (i = 1; i < argc; i++) {
+		proxy = g_dbus_proxy_lookup(transports, NULL, argv[i],
 					BLUEZ_MEDIA_TRANSPORT_INTERFACE);
-	if (!proxy) {
-		bt_shell_printf("Transport %s not found\n", argv[1]);
-		return bt_shell_noninteractive_quit(EXIT_FAILURE);
-	}
+		if (!proxy) {
+			bt_shell_printf("Transport %s not found\n", argv[i]);
+			return bt_shell_noninteractive_quit(EXIT_FAILURE);
+		}
 
-	transport = find_transport(proxy);
-	if (!transport) {
-		bt_shell_printf("Transport %s not acquired\n", argv[1]);
-		return bt_shell_noninteractive_quit(EXIT_FAILURE);
-	}
+		transport = find_transport(proxy);
+		if (!transport) {
+			bt_shell_printf("Transport %s not acquired\n", argv[i]);
+			return bt_shell_noninteractive_quit(EXIT_FAILURE);
+		}
 
-	if (transport->sk < 0) {
-		bt_shell_printf("No Transport Socked found\n");
-		return bt_shell_noninteractive_quit(EXIT_FAILURE);
-	}
+		if (transport->sk < 0) {
+			bt_shell_printf("No Transport Socked found\n");
+			return bt_shell_noninteractive_quit(EXIT_FAILURE);
+		}
 
-	fd = open_file(argv[2], O_RDONLY);
-	if (fd < 0)
-		return bt_shell_noninteractive_quit(EXIT_FAILURE);
+		if (i + 1 < argc) {
+			fd = open_file(argv[++i], O_RDONLY);
+			if (fd < 0)
+				return bt_shell_noninteractive_quit(
+								EXIT_FAILURE);
+		}
 
-	bt_shell_printf("Sending ...\n");
+		bt_shell_printf("Sending ...\n");
 
-	/* Read QoS if available */
-	memset(&qos, 0, sizeof(qos));
-	len = sizeof(qos);
-	if (getsockopt(transport->sk, SOL_BLUETOOTH, BT_ISO_QOS, &qos,
+		/* Read QoS if available */
+		memset(&qos, 0, sizeof(qos));
+		len = sizeof(qos);
+		if (getsockopt(transport->sk, SOL_BLUETOOTH, BT_ISO_QOS, &qos,
 							&len) < 0)
-		err = transport_send(transport, fd, NULL);
-	else
-		err = transport_send(transport, fd, &qos);
+			err = transport_send(transport, fd, NULL);
+		else
+			err = transport_send(transport, fd, &qos);
 
-	if (err < 0) {
-		bt_shell_printf("Unable to send: %s (%d)", strerror(-err),
-								-err);
-		close(fd);
-		return bt_shell_noninteractive_quit(EXIT_FAILURE);
+		if (err < 0) {
+			bt_shell_printf("Unable to send: %s (%d)",
+						strerror(-err), -err);
+			close(fd);
+			return bt_shell_noninteractive_quit(EXIT_FAILURE);
+		}
 	}
 
 	return bt_shell_noninteractive_quit(EXIT_SUCCESS);
@@ -3710,7 +3716,8 @@  static const struct bt_shell_menu transport_menu = {
 	{ "release",     "<transport> [transport1...]", cmd_release_transport,
 						"Release Transport",
 						transport_generator },
-	{ "send",        "<transport> <filename>", cmd_send_transport,
+	{ "send",        "<transport> <filename> [transport1...]",
+						cmd_send_transport,
 						"Send contents of a file",
 						transport_generator },
 	{ "receive",     "<transport> [filename]", cmd_receive_transport,