All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 BlueZ] client/player: Add transport.receive command
@ 2022-04-26 18:04 Luiz Augusto von Dentz
  2022-04-26 19:39 ` [v2,BlueZ] " bluez.test.bot
  2022-04-28 22:30 ` [PATCH v2 BlueZ] " patchwork-bot+bluetooth
  0 siblings, 2 replies; 3+ messages in thread
From: Luiz Augusto von Dentz @ 2022-04-26 18:04 UTC (permalink / raw)
  To: linux-bluetooth

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

This adds transport.receive command:

Get/Set file to receive
Usage:
	 receive [filename]
---
 client/player.c | 57 +++++++++++++++++++++++++++++++++++++++++++++----
 1 file changed, 53 insertions(+), 4 deletions(-)

diff --git a/client/player.c b/client/player.c
index 315cde712..c2c10e7e2 100644
--- a/client/player.c
+++ b/client/player.c
@@ -81,10 +81,13 @@ static GList *transports = NULL;
 struct transport {
 	int sk;
 	int mtu[2];
+	char *filename;
+	int fd;
 	struct io *io;
 	uint32_t seq;
 } transport = {
 	.sk = -1,
+	.fd = -1,
 };
 
 static void endpoint_unregister(void *data)
@@ -2219,7 +2222,7 @@ static bool transport_disconnected(struct io *io, void *user_data)
 static bool transport_recv(struct io *io, void *user_data)
 {
 	uint8_t buf[1024];
-	int ret;
+	int ret, len;
 
 	ret = read(io_get_fd(io), buf, sizeof(buf));
 	if (ret < 0) {
@@ -2232,6 +2235,13 @@ static bool transport_recv(struct io *io, void *user_data)
 
 	transport.seq++;
 
+	if (transport.fd) {
+		len = write(transport.fd, buf, ret);
+		if (len < 0)
+			bt_shell_printf("Unable to write: %s (%d)",
+						strerror(errno), -errno);
+	}
+
 	return true;
 }
 
@@ -2451,13 +2461,17 @@ static void cmd_release_transport(int argc, char *argv[])
 	return bt_shell_noninteractive_quit(EXIT_SUCCESS);
 }
 
-static int open_file(const char *filename)
+static int open_file(const char *filename, int flags)
 {
 	int fd = -1;
 
 	bt_shell_printf("Opening %s ...\n", filename);
 
-	fd = open(filename, O_RDONLY);
+	if (flags & O_CREAT)
+		fd = open(filename, flags, 0755);
+	else
+		fd = open(filename, flags);
+
 	if (fd <= 0)
 		bt_shell_printf("Can't open file %s: %s\n", filename,
 						strerror(errno));
@@ -2514,7 +2528,7 @@ static void cmd_send_transport(int argc, char *argv[])
 		return bt_shell_noninteractive_quit(EXIT_FAILURE);
 	}
 
-	fd = open_file(argv[1]);
+	fd = open_file(argv[1], O_RDONLY);
 
 	bt_shell_printf("Sending ...\n");
 	err = transport_send(fd);
@@ -2527,6 +2541,38 @@ static void cmd_send_transport(int argc, char *argv[])
 	return bt_shell_noninteractive_quit(EXIT_SUCCESS);
 }
 
+static void transport_close(void)
+{
+	if (transport.fd < 0)
+		return;
+
+	close(transport.fd);
+	transport.fd = -1;
+
+	free(transport.filename);
+	transport.filename = NULL;
+}
+
+static void cmd_receive_transport(int argc, char *argv[])
+{
+	if (argc == 1) {
+		bt_shell_printf("Filename: %s\n", transport.filename);
+		return bt_shell_noninteractive_quit(EXIT_SUCCESS);
+	}
+
+	transport_close();
+
+	transport.fd = open_file(argv[1], O_RDWR | O_CREAT);
+	if (transport.fd < 0)
+		return bt_shell_noninteractive_quit(EXIT_FAILURE);
+
+	transport.filename = strdup(argv[1]);
+
+	bt_shell_printf("Filename: %s\n", transport.filename);
+
+	return bt_shell_noninteractive_quit(EXIT_SUCCESS);
+}
+
 static void volume_callback(const DBusError *error, void *user_data)
 {
 	if (dbus_error_is_set(error)) {
@@ -2589,6 +2635,8 @@ static const struct bt_shell_menu transport_menu = {
 						transport_generator },
 	{ "send",        "<filename>",	cmd_send_transport,
 						"Send contents of a file" },
+	{ "receive",     "[filename]",	cmd_receive_transport,
+						"Get/Set file to receive" },
 	{ "volume",      "<transport> [value]",	cmd_volume_transport,
 						"Get/Set transport volume",
 						transport_generator },
@@ -2617,4 +2665,5 @@ void player_add_submenu(void)
 void player_remove_submenu(void)
 {
 	g_dbus_client_unref(client);
+	transport_close();
 }
-- 
2.35.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* RE: [v2,BlueZ] client/player: Add transport.receive command
  2022-04-26 18:04 [PATCH v2 BlueZ] client/player: Add transport.receive command Luiz Augusto von Dentz
@ 2022-04-26 19:39 ` bluez.test.bot
  2022-04-28 22:30 ` [PATCH v2 BlueZ] " patchwork-bot+bluetooth
  1 sibling, 0 replies; 3+ messages in thread
From: bluez.test.bot @ 2022-04-26 19:39 UTC (permalink / raw)
  To: linux-bluetooth, luiz.dentz

[-- Attachment #1: Type: text/plain, Size: 1230 bytes --]

This is automated email and please do not reply to this email!

Dear submitter,

Thank you for submitting the patches to the linux bluetooth mailing list.
This is a CI test results with your patch series:
PW Link:https://patchwork.kernel.org/project/bluetooth/list/?series=635861

---Test result---

Test Summary:
CheckPatch                    PASS      1.50 seconds
GitLint                       FAIL      1.01 seconds
Prep - Setup ELL              PASS      42.35 seconds
Build - Prep                  PASS      0.70 seconds
Build - Configure             PASS      8.43 seconds
Build - Make                  PASS      1357.65 seconds
Make Check                    PASS      11.97 seconds
Make Check w/Valgrind         PASS      441.40 seconds
Make Distcheck                PASS      226.99 seconds
Build w/ext ELL - Configure   PASS      8.58 seconds
Build w/ext ELL - Make        PASS      1358.19 seconds
Incremental Build with patchesPASS      0.00 seconds

Details
##############################
Test: GitLint - FAIL
Desc: Run gitlint with rule in .gitlint
Output:
[v2,BlueZ] client/player: Add transport.receive command
9: B3 Line contains hard tab characters (\t): "	 receive [filename]"




---
Regards,
Linux Bluetooth


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH v2 BlueZ] client/player: Add transport.receive command
  2022-04-26 18:04 [PATCH v2 BlueZ] client/player: Add transport.receive command Luiz Augusto von Dentz
  2022-04-26 19:39 ` [v2,BlueZ] " bluez.test.bot
@ 2022-04-28 22:30 ` patchwork-bot+bluetooth
  1 sibling, 0 replies; 3+ messages in thread
From: patchwork-bot+bluetooth @ 2022-04-28 22:30 UTC (permalink / raw)
  To: Luiz Augusto von Dentz; +Cc: linux-bluetooth

Hello:

This patch was applied to bluetooth/bluez.git (master)
by Luiz Augusto von Dentz <luiz.von.dentz@intel.com>:

On Tue, 26 Apr 2022 11:04:01 -0700 you wrote:
> From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
> 
> This adds transport.receive command:
> 
> Get/Set file to receive
> Usage:
> 	 receive [filename]
> 
> [...]

Here is the summary with links:
  - [v2,BlueZ] client/player: Add transport.receive command
    https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=7a87497da4ab

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-04-28 22:30 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-26 18:04 [PATCH v2 BlueZ] client/player: Add transport.receive command Luiz Augusto von Dentz
2022-04-26 19:39 ` [v2,BlueZ] " bluez.test.bot
2022-04-28 22:30 ` [PATCH v2 BlueZ] " patchwork-bot+bluetooth

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.