All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH BlueZ 01/14] build: Add bluetooth-player command line client
@ 2013-05-31 10:55 Luiz Augusto von Dentz
  2013-05-31 10:55 ` [PATCH BlueZ 02/14] client/bluetooth-player: Add initial code Luiz Augusto von Dentz
                   ` (12 more replies)
  0 siblings, 13 replies; 14+ messages in thread
From: Luiz Augusto von Dentz @ 2013-05-31 10:55 UTC (permalink / raw)
  To: linux-bluetooth

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

bluetooth-player is intended to control players connect over bluetooth.
---
 Makefile.tools            |  5 +++++
 client/bluetooth-player.c | 31 +++++++++++++++++++++++++++++++
 2 files changed, 36 insertions(+)
 create mode 100644 client/bluetooth-player.c

diff --git a/Makefile.tools b/Makefile.tools
index acd403e..d7920c2 100644
--- a/Makefile.tools
+++ b/Makefile.tools
@@ -7,6 +7,11 @@ client_bluetoothctl_SOURCES = $(gdbus_sources) client/main.c \
 					client/agent.h client/agent.c \
 					monitor/uuid.h monitor/uuid.c
 client_bluetoothctl_LDADD = @GLIB_LIBS@ @DBUS_LIBS@ -lreadline
+
+bin_PROGRAMS += client/bluetooth-player
+client_bluetooth_player_SOURCES = $(gdbus_sources) client/bluetooth-player.c \
+					client/display.c
+client_bluetooth_player_LDADD = @GLIB_LIBS@ @DBUS_LIBS@ -lreadline
 endif
 
 if MONITOR
diff --git a/client/bluetooth-player.c b/client/bluetooth-player.c
new file mode 100644
index 0000000..b38861a
--- /dev/null
+++ b/client/bluetooth-player.c
@@ -0,0 +1,31 @@
+/*
+ *
+ *  BlueZ - Bluetooth protocol stack for Linux
+ *
+ *  Copyright (C) 2012  Intel Corporation. All rights reserved.
+ *
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+int main(int argc, char *argv[])
+{
+	return 0;
+}
-- 
1.8.1.4


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

* [PATCH BlueZ 02/14] client/bluetooth-player: Add initial code
  2013-05-31 10:55 [PATCH BlueZ 01/14] build: Add bluetooth-player command line client Luiz Augusto von Dentz
@ 2013-05-31 10:55 ` Luiz Augusto von Dentz
  2013-05-31 10:55 ` [PATCH BlueZ 03/14] client/bluetooth-player: Add proxy handling for org.bluez.MediaPlayer1 Luiz Augusto von Dentz
                   ` (11 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: Luiz Augusto von Dentz @ 2013-05-31 10:55 UTC (permalink / raw)
  To: linux-bluetooth

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

This add initial code for things like input handling as well as some
basic commands.
---
 client/bluetooth-player.c | 318 ++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 318 insertions(+)

diff --git a/client/bluetooth-player.c b/client/bluetooth-player.c
index b38861a..687c649 100644
--- a/client/bluetooth-player.c
+++ b/client/bluetooth-player.c
@@ -25,7 +25,325 @@
 #include <config.h>
 #endif
 
+#include <stdio.h>
+#include <errno.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <signal.h>
+#include <sys/signalfd.h>
+
+#include <readline/readline.h>
+#include <readline/history.h>
+#include <glib.h>
+#include <gdbus.h>
+
+#include "display.h"
+
+/* String display constants */
+#define COLORED_NEW	COLOR_GREEN "NEW" COLOR_OFF
+#define COLORED_CHG	COLOR_YELLOW "CHG" COLOR_OFF
+#define COLORED_DEL	COLOR_RED "DEL" COLOR_OFF
+
+#define PROMPT_ON	COLOR_BLUE "[bluetooth]" COLOR_OFF "# "
+#define PROMPT_OFF	"[bluetooth]# "
+
+static GMainLoop *main_loop;
+static DBusConnection *dbus_conn;
+
+static void connect_handler(DBusConnection *connection, void *user_data)
+{
+	rl_set_prompt(PROMPT_ON);
+	printf("\r");
+	rl_on_new_line();
+	rl_redisplay();
+}
+
+static void disconnect_handler(DBusConnection *connection, void *user_data)
+{
+	rl_set_prompt(PROMPT_OFF);
+	printf("\r");
+	rl_on_new_line();
+	rl_redisplay();
+}
+
+static void cmd_quit(int argc, char *argv[])
+{
+	g_main_loop_quit(main_loop);
+}
+
+static const struct {
+	const char *cmd;
+	const char *arg;
+	void (*func) (int argc, char *argv[]);
+	const char *desc;
+} cmd_table[] = {
+	{ "quit",         NULL,       cmd_quit, "Quit program" },
+	{ "exit",         NULL,       cmd_quit },
+	{ "help" },
+	{}
+};
+
+static char *cmd_generator(const char *text, int state)
+{
+	static int index, len;
+	const char *cmd;
+
+	if (!state) {
+		index = 0;
+		len = strlen(text);
+	}
+
+	while ((cmd = cmd_table[index].cmd)) {
+		index++;
+
+		if (!strncmp(cmd, text, len))
+			return strdup(cmd);
+	}
+
+	return NULL;
+}
+
+static char **cmd_completion(const char *text, int start, int end)
+{
+	char **matches = NULL;
+
+	if (start == 0) {
+		rl_completion_display_matches_hook = NULL;
+		matches = rl_completion_matches(text, cmd_generator);
+	}
+
+	if (!matches)
+		rl_attempted_completion_over = 1;
+
+	return matches;
+}
+
+static void rl_handler(char *input)
+{
+	int argc;
+	char **argv = NULL;
+	int i;
+
+	if (!input) {
+		rl_insert_text("quit");
+		rl_redisplay();
+		rl_crlf();
+		g_main_loop_quit(main_loop);
+		return;
+	}
+
+	if (!strlen(input))
+		goto done;
+
+	add_history(input);
+
+	argv = g_strsplit(input, " ", -1);
+	if (argv == NULL)
+		goto done;
+
+	for (argc = 0; argv[argc];)
+		argc++;
+
+	if (argc == 0)
+		goto done;
+
+	for (i = 0; cmd_table[i].cmd; i++) {
+		if (strcmp(argv[0], cmd_table[i].cmd))
+			continue;
+
+		if (cmd_table[i].func) {
+			cmd_table[i].func(argc, argv);
+			goto done;
+		}
+	}
+
+	if (strcmp(argv[0], "help")) {
+		printf("Invalid command\n");
+		goto done;
+	}
+
+	printf("Available commands:\n");
+
+	for (i = 0; cmd_table[i].cmd; i++) {
+		if (cmd_table[i].desc)
+			printf("\t%s %s\t%s\n", cmd_table[i].cmd,
+						cmd_table[i].arg ? : "    ",
+						cmd_table[i].desc);
+	}
+
+done:
+	g_strfreev(argv);
+	free(input);
+}
+
+static gboolean option_version = FALSE;
+
+static GOptionEntry options[] = {
+	{ "version", 'v', 0, G_OPTION_ARG_NONE, &option_version,
+				"Show version information and exit" },
+	{ NULL },
+};
+
+static gboolean signal_handler(GIOChannel *channel, GIOCondition condition,
+							gpointer user_data)
+{
+	static unsigned int __terminated = 0;
+	struct signalfd_siginfo si;
+	ssize_t result;
+	int fd;
+
+	if (condition & (G_IO_NVAL | G_IO_ERR | G_IO_HUP)) {
+		g_main_loop_quit(main_loop);
+		return FALSE;
+	}
+
+	fd = g_io_channel_unix_get_fd(channel);
+
+	result = read(fd, &si, sizeof(si));
+	if (result != sizeof(si))
+		return FALSE;
+
+	switch (si.ssi_signo) {
+	case SIGINT:
+		rl_replace_line("", 0);
+		rl_crlf();
+		rl_on_new_line();
+		rl_redisplay();
+		break;
+	case SIGTERM:
+		if (__terminated == 0) {
+			rl_replace_line("", 0);
+			rl_crlf();
+			g_main_loop_quit(main_loop);
+		}
+
+		__terminated = 1;
+		break;
+	}
+
+	return TRUE;
+}
+
+static guint setup_signalfd(void)
+{
+	GIOChannel *channel;
+	guint source;
+	sigset_t mask;
+	int fd;
+
+	sigemptyset(&mask);
+	sigaddset(&mask, SIGINT);
+	sigaddset(&mask, SIGTERM);
+
+	if (sigprocmask(SIG_BLOCK, &mask, NULL) < 0) {
+		perror("Failed to set signal mask");
+		return 0;
+	}
+
+	fd = signalfd(-1, &mask, 0);
+	if (fd < 0) {
+		perror("Failed to create signal descriptor");
+		return 0;
+	}
+
+	channel = g_io_channel_unix_new(fd);
+
+	g_io_channel_set_close_on_unref(channel, TRUE);
+	g_io_channel_set_encoding(channel, NULL, NULL);
+	g_io_channel_set_buffered(channel, FALSE);
+
+	source = g_io_add_watch(channel,
+				G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_NVAL,
+				signal_handler, NULL);
+
+	g_io_channel_unref(channel);
+
+	return source;
+}
+
+static gboolean input_handler(GIOChannel *channel, GIOCondition condition,
+							gpointer user_data)
+{
+	if (condition & (G_IO_HUP | G_IO_ERR | G_IO_NVAL)) {
+		g_main_loop_quit(main_loop);
+		return FALSE;
+	}
+
+	rl_callback_read_char();
+	return TRUE;
+}
+
+static guint setup_standard_input(void)
+{
+	GIOChannel *channel;
+	guint source;
+
+	channel = g_io_channel_unix_new(fileno(stdin));
+
+	source = g_io_add_watch(channel,
+				G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_NVAL,
+				input_handler, NULL);
+
+	g_io_channel_unref(channel);
+
+	return source;
+}
+
 int main(int argc, char *argv[])
 {
+	GOptionContext *context;
+	GError *error = NULL;
+	GDBusClient *client;
+	guint signal, input;
+
+	context = g_option_context_new(NULL);
+	g_option_context_add_main_entries(context, options, NULL);
+
+	if (g_option_context_parse(context, &argc, &argv, &error) == FALSE) {
+		if (error != NULL) {
+			g_printerr("%s\n", error->message);
+			g_error_free(error);
+		} else
+			g_printerr("An unknown error occurred\n");
+		exit(1);
+	}
+
+	g_option_context_free(context);
+
+	if (option_version == TRUE) {
+		printf("%s\n", VERSION);
+		exit(0);
+	}
+
+	main_loop = g_main_loop_new(NULL, FALSE);
+	dbus_conn = g_dbus_setup_bus(DBUS_BUS_SYSTEM, NULL, NULL);
+
+	rl_attempted_completion_function = cmd_completion;
+
+	rl_erase_empty_line = 1;
+	rl_callback_handler_install(NULL, rl_handler);
+
+	rl_set_prompt(PROMPT_OFF);
+	rl_redisplay();
+
+	input = setup_standard_input();
+	signal = setup_signalfd();
+	client = g_dbus_client_new(dbus_conn, "org.bluez", "/org/bluez");
+
+	g_dbus_client_set_connect_watch(client, connect_handler, NULL);
+	g_dbus_client_set_disconnect_watch(client, disconnect_handler, NULL);
+
+	g_main_loop_run(main_loop);
+
+	g_dbus_client_unref(client);
+	g_source_remove(signal);
+	g_source_remove(input);
+
+	rl_message("");
+	rl_callback_handler_remove();
+
+	dbus_connection_unref(dbus_conn);
+	g_main_loop_unref(main_loop);
+
 	return 0;
 }
-- 
1.8.1.4


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

* [PATCH BlueZ 03/14] client/bluetooth-player: Add proxy handling for org.bluez.MediaPlayer1
  2013-05-31 10:55 [PATCH BlueZ 01/14] build: Add bluetooth-player command line client Luiz Augusto von Dentz
  2013-05-31 10:55 ` [PATCH BlueZ 02/14] client/bluetooth-player: Add initial code Luiz Augusto von Dentz
@ 2013-05-31 10:55 ` Luiz Augusto von Dentz
  2013-05-31 10:55 ` [PATCH BlueZ 04/14] client/bluetooth-player: Add support for container types to print_iter Luiz Augusto von Dentz
                   ` (10 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: Luiz Augusto von Dentz @ 2013-05-31 10:55 UTC (permalink / raw)
  To: linux-bluetooth

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

This adds proxy handling for org.bluez.MediaPlayer1 so changes to the
proxy are printed in the output.
---
 client/bluetooth-player.c | 133 ++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 133 insertions(+)

diff --git a/client/bluetooth-player.c b/client/bluetooth-player.c
index 687c649..6525cf3 100644
--- a/client/bluetooth-player.c
+++ b/client/bluetooth-player.c
@@ -47,8 +47,12 @@
 #define PROMPT_ON	COLOR_BLUE "[bluetooth]" COLOR_OFF "# "
 #define PROMPT_OFF	"[bluetooth]# "
 
+#define BLUEZ_MEDIA_PLAYER_INTERFACE "org.bluez.MediaPlayer1"
+
 static GMainLoop *main_loop;
 static DBusConnection *dbus_conn;
+static GDBusProxy *default_player;
+static GSList *players = NULL;
 
 static void connect_handler(DBusConnection *connection, void *user_data)
 {
@@ -289,6 +293,132 @@ static guint setup_standard_input(void)
 	return source;
 }
 
+static char *player_description(GDBusProxy *proxy, const char *description)
+{
+	const char *path;
+
+	path = g_dbus_proxy_get_path(proxy);
+
+	return g_strdup_printf("%s%s%sPlayer %s ",
+					description ? "[" : "",
+					description ? : "",
+					description ? "] " : "",
+					path);
+}
+
+static void print_player(GDBusProxy *proxy, const char *description)
+{
+	char *str;
+
+	str = player_description(proxy, description);
+
+	rl_printf("%s%s\n", str, default_player == proxy ? "[default]" : "");
+
+	g_free(str);
+}
+
+static void player_added(GDBusProxy *proxy)
+{
+	players = g_slist_append(players, proxy);
+
+	if (default_player == NULL)
+		default_player = proxy;
+
+	print_player(proxy, COLORED_NEW);
+}
+
+static void proxy_added(GDBusProxy *proxy, void *user_data)
+{
+	const char *interface;
+
+	interface = g_dbus_proxy_get_interface(proxy);
+
+	if (!strcmp(interface, BLUEZ_MEDIA_PLAYER_INTERFACE))
+		player_added(proxy);
+}
+
+static void player_removed(GDBusProxy *proxy)
+{
+	print_player(proxy, COLORED_DEL);
+
+	if (default_player == proxy)
+		default_player = NULL;
+
+	players = g_slist_remove(players, proxy);
+}
+
+static void proxy_removed(GDBusProxy *proxy, void *user_data)
+{
+	const char *interface;
+
+	interface = g_dbus_proxy_get_interface(proxy);
+
+	if (!strcmp(interface, BLUEZ_MEDIA_PLAYER_INTERFACE))
+		player_removed(proxy);
+}
+
+static void print_iter(const char *label, const char *name,
+						DBusMessageIter *iter)
+{
+	dbus_bool_t valbool;
+	dbus_uint32_t valu32;
+	dbus_uint16_t valu16;
+	dbus_int16_t vals16;
+	const char *valstr;
+
+	if (iter == NULL) {
+		rl_printf("%s%s is nil\n", label, name);
+		return;
+	}
+
+	switch (dbus_message_iter_get_arg_type(iter)) {
+	case DBUS_TYPE_INVALID:
+		rl_printf("%s%s is invalid\n", label, name);
+		break;
+	case DBUS_TYPE_STRING:
+	case DBUS_TYPE_OBJECT_PATH:
+		dbus_message_iter_get_basic(iter, &valstr);
+		rl_printf("%s%s: %s\n", label, name, valstr);
+		break;
+	case DBUS_TYPE_BOOLEAN:
+		dbus_message_iter_get_basic(iter, &valbool);
+		rl_printf("%s%s: %s\n", label, name,
+					valbool == TRUE ? "yes" : "no");
+		break;
+	case DBUS_TYPE_UINT32:
+		dbus_message_iter_get_basic(iter, &valu32);
+		rl_printf("%s%s: 0x%06x\n", label, name, valu32);
+		break;
+	case DBUS_TYPE_UINT16:
+		dbus_message_iter_get_basic(iter, &valu16);
+		rl_printf("%s%s: 0x%04x\n", label, name, valu16);
+		break;
+	case DBUS_TYPE_INT16:
+		dbus_message_iter_get_basic(iter, &vals16);
+		rl_printf("%s%s: %d\n", label, name, vals16);
+		break;
+	default:
+		rl_printf("%s%s has unsupported type\n", label, name);
+		break;
+	}
+}
+
+static void property_changed(GDBusProxy *proxy, const char *name,
+					DBusMessageIter *iter, void *user_data)
+{
+	const char *interface;
+
+	interface = g_dbus_proxy_get_interface(proxy);
+
+	if (!strcmp(interface, BLUEZ_MEDIA_PLAYER_INTERFACE)) {
+		char *str;
+
+		str = player_description(proxy, COLORED_CHG);
+		print_iter(str, name, iter);
+		g_free(str);
+	}
+}
+
 int main(int argc, char *argv[])
 {
 	GOptionContext *context;
@@ -333,6 +463,9 @@ int main(int argc, char *argv[])
 	g_dbus_client_set_connect_watch(client, connect_handler, NULL);
 	g_dbus_client_set_disconnect_watch(client, disconnect_handler, NULL);
 
+	g_dbus_client_set_proxy_handlers(client, proxy_added, proxy_removed,
+							property_changed, NULL);
+
 	g_main_loop_run(main_loop);
 
 	g_dbus_client_unref(client);
-- 
1.8.1.4


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

* [PATCH BlueZ 04/14] client/bluetooth-player: Add support for container types to print_iter
  2013-05-31 10:55 [PATCH BlueZ 01/14] build: Add bluetooth-player command line client Luiz Augusto von Dentz
  2013-05-31 10:55 ` [PATCH BlueZ 02/14] client/bluetooth-player: Add initial code Luiz Augusto von Dentz
  2013-05-31 10:55 ` [PATCH BlueZ 03/14] client/bluetooth-player: Add proxy handling for org.bluez.MediaPlayer1 Luiz Augusto von Dentz
@ 2013-05-31 10:55 ` Luiz Augusto von Dentz
  2013-05-31 10:55 ` [PATCH BlueZ 05/14] client/bluetooth-player: Add play command Luiz Augusto von Dentz
                   ` (9 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: Luiz Augusto von Dentz @ 2013-05-31 10:55 UTC (permalink / raw)
  To: linux-bluetooth

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

This adds support for container types to print_iter so it can now print
'Track' property properly.
---
 client/bluetooth-player.c | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git a/client/bluetooth-player.c b/client/bluetooth-player.c
index 6525cf3..e954be0 100644
--- a/client/bluetooth-player.c
+++ b/client/bluetooth-player.c
@@ -365,6 +365,7 @@ static void print_iter(const char *label, const char *name,
 	dbus_uint16_t valu16;
 	dbus_int16_t vals16;
 	const char *valstr;
+	DBusMessageIter subiter;
 
 	if (iter == NULL) {
 		rl_printf("%s%s is nil\n", label, name);
@@ -397,6 +398,24 @@ static void print_iter(const char *label, const char *name,
 		dbus_message_iter_get_basic(iter, &vals16);
 		rl_printf("%s%s: %d\n", label, name, vals16);
 		break;
+	case DBUS_TYPE_VARIANT:
+		dbus_message_iter_recurse(iter, &subiter);
+		print_iter(label, name, &subiter);
+		break;
+	case DBUS_TYPE_ARRAY:
+		dbus_message_iter_recurse(iter, &subiter);
+		while (dbus_message_iter_get_arg_type(&subiter) !=
+							DBUS_TYPE_INVALID) {
+			print_iter(label, name, &subiter);
+			dbus_message_iter_next(&subiter);
+		}
+		break;
+	case DBUS_TYPE_DICT_ENTRY:
+		dbus_message_iter_recurse(iter, &subiter);
+		dbus_message_iter_get_basic(&subiter, &valstr);
+		dbus_message_iter_next(&subiter);
+		print_iter(label, valstr, &subiter);
+		break;
 	default:
 		rl_printf("%s%s has unsupported type\n", label, name);
 		break;
-- 
1.8.1.4


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

* [PATCH BlueZ 05/14] client/bluetooth-player: Add play command
  2013-05-31 10:55 [PATCH BlueZ 01/14] build: Add bluetooth-player command line client Luiz Augusto von Dentz
                   ` (2 preceding siblings ...)
  2013-05-31 10:55 ` [PATCH BlueZ 04/14] client/bluetooth-player: Add support for container types to print_iter Luiz Augusto von Dentz
@ 2013-05-31 10:55 ` Luiz Augusto von Dentz
  2013-05-31 10:55 ` [PATCH BlueZ 06/14] client/bluetooth-player: Add pause command Luiz Augusto von Dentz
                   ` (8 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: Luiz Augusto von Dentz @ 2013-05-31 10:55 UTC (permalink / raw)
  To: linux-bluetooth

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

Add support for play command which can be used to resume the playback
---
 client/bluetooth-player.c | 41 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 41 insertions(+)

diff --git a/client/bluetooth-player.c b/client/bluetooth-player.c
index e954be0..312adb7 100644
--- a/client/bluetooth-player.c
+++ b/client/bluetooth-player.c
@@ -26,6 +26,7 @@
 #endif
 
 #include <stdio.h>
+#include <stdbool.h>
 #include <errno.h>
 #include <unistd.h>
 #include <stdlib.h>
@@ -75,12 +76,52 @@ static void cmd_quit(int argc, char *argv[])
 	g_main_loop_quit(main_loop);
 }
 
+static bool check_default_player(void)
+{
+	if (!default_player) {
+		rl_printf("No default player available\n");
+		return FALSE;
+	}
+
+	return TRUE;
+}
+
+static void play_reply(DBusMessage *message, void *user_data)
+{
+	DBusError error;
+
+	dbus_error_init(&error);
+
+	if (dbus_set_error_from_message(&error, message) == TRUE) {
+		rl_printf("Failed to play: %s\n", error.name);
+		dbus_error_free(&error);
+		return;
+	}
+
+	rl_printf("Play successful\n");
+}
+
+static void cmd_play(int argc, char *argv[])
+{
+	if (!check_default_player())
+		return;
+
+	if (g_dbus_proxy_method_call(default_player, "Play", NULL, play_reply,
+							NULL, NULL) == FALSE) {
+		rl_printf("Failed to play\n");
+		return;
+	}
+
+	rl_printf("Attempting to play\n");
+}
+
 static const struct {
 	const char *cmd;
 	const char *arg;
 	void (*func) (int argc, char *argv[]);
 	const char *desc;
 } cmd_table[] = {
+	{ "play",         NULL,       cmd_play, "Start playback" },
 	{ "quit",         NULL,       cmd_quit, "Quit program" },
 	{ "exit",         NULL,       cmd_quit },
 	{ "help" },
-- 
1.8.1.4


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

* [PATCH BlueZ 06/14] client/bluetooth-player: Add pause command
  2013-05-31 10:55 [PATCH BlueZ 01/14] build: Add bluetooth-player command line client Luiz Augusto von Dentz
                   ` (3 preceding siblings ...)
  2013-05-31 10:55 ` [PATCH BlueZ 05/14] client/bluetooth-player: Add play command Luiz Augusto von Dentz
@ 2013-05-31 10:55 ` Luiz Augusto von Dentz
  2013-05-31 10:55 ` [PATCH BlueZ 07/14] client/bluetooth-player: Add stop command Luiz Augusto von Dentz
                   ` (7 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: Luiz Augusto von Dentz @ 2013-05-31 10:55 UTC (permalink / raw)
  To: linux-bluetooth

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

Add support for pause command which can be used to resume the playback
---
 client/bluetooth-player.c | 30 ++++++++++++++++++++++++++++++
 1 file changed, 30 insertions(+)

diff --git a/client/bluetooth-player.c b/client/bluetooth-player.c
index 312adb7..62c1110 100644
--- a/client/bluetooth-player.c
+++ b/client/bluetooth-player.c
@@ -115,6 +115,35 @@ static void cmd_play(int argc, char *argv[])
 	rl_printf("Attempting to play\n");
 }
 
+static void pause_reply(DBusMessage *message, void *user_data)
+{
+	DBusError error;
+
+	dbus_error_init(&error);
+
+	if (dbus_set_error_from_message(&error, message) == TRUE) {
+		rl_printf("Failed to pause: %s\n", error.name);
+		dbus_error_free(&error);
+		return;
+	}
+
+	rl_printf("Pause successful\n");
+}
+
+static void cmd_pause(int argc, char *argv[])
+{
+	if (!check_default_player())
+		return;
+
+	if (g_dbus_proxy_method_call(default_player, "Pause", NULL,
+					pause_reply, NULL, NULL) == FALSE) {
+		rl_printf("Failed to play\n");
+		return;
+	}
+
+	rl_printf("Attempting to pause\n");
+}
+
 static const struct {
 	const char *cmd;
 	const char *arg;
@@ -122,6 +151,7 @@ static const struct {
 	const char *desc;
 } cmd_table[] = {
 	{ "play",         NULL,       cmd_play, "Start playback" },
+	{ "pause",        NULL,       cmd_pause, "Pause playback" },
 	{ "quit",         NULL,       cmd_quit, "Quit program" },
 	{ "exit",         NULL,       cmd_quit },
 	{ "help" },
-- 
1.8.1.4


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

* [PATCH BlueZ 07/14] client/bluetooth-player: Add stop command
  2013-05-31 10:55 [PATCH BlueZ 01/14] build: Add bluetooth-player command line client Luiz Augusto von Dentz
                   ` (4 preceding siblings ...)
  2013-05-31 10:55 ` [PATCH BlueZ 06/14] client/bluetooth-player: Add pause command Luiz Augusto von Dentz
@ 2013-05-31 10:55 ` Luiz Augusto von Dentz
  2013-05-31 10:55 ` [PATCH BlueZ 08/14] client/bluetooth-player: Add next command Luiz Augusto von Dentz
                   ` (6 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: Luiz Augusto von Dentz @ 2013-05-31 10:55 UTC (permalink / raw)
  To: linux-bluetooth

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

Add support for stop command which can be used to stop the playback
---
 client/bluetooth-player.c | 30 ++++++++++++++++++++++++++++++
 1 file changed, 30 insertions(+)

diff --git a/client/bluetooth-player.c b/client/bluetooth-player.c
index 62c1110..ebf6cd6 100644
--- a/client/bluetooth-player.c
+++ b/client/bluetooth-player.c
@@ -144,6 +144,35 @@ static void cmd_pause(int argc, char *argv[])
 	rl_printf("Attempting to pause\n");
 }
 
+static void stop_reply(DBusMessage *message, void *user_data)
+{
+	DBusError error;
+
+	dbus_error_init(&error);
+
+	if (dbus_set_error_from_message(&error, message) == TRUE) {
+		rl_printf("Failed to stop: %s\n", error.name);
+		dbus_error_free(&error);
+		return;
+	}
+
+	rl_printf("Stop successful\n");
+}
+
+static void cmd_stop(int argc, char *argv[])
+{
+	if (!check_default_player())
+		return;
+
+	if (g_dbus_proxy_method_call(default_player, "Stop", NULL, stop_reply,
+							NULL, NULL) == FALSE) {
+		rl_printf("Failed to stop\n");
+		return;
+	}
+
+	rl_printf("Attempting to stop\n");
+}
+
 static const struct {
 	const char *cmd;
 	const char *arg;
@@ -152,6 +181,7 @@ static const struct {
 } cmd_table[] = {
 	{ "play",         NULL,       cmd_play, "Start playback" },
 	{ "pause",        NULL,       cmd_pause, "Pause playback" },
+	{ "stop",         NULL,       cmd_stop, "Stop playback" },
 	{ "quit",         NULL,       cmd_quit, "Quit program" },
 	{ "exit",         NULL,       cmd_quit },
 	{ "help" },
-- 
1.8.1.4


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

* [PATCH BlueZ 08/14] client/bluetooth-player: Add next command
  2013-05-31 10:55 [PATCH BlueZ 01/14] build: Add bluetooth-player command line client Luiz Augusto von Dentz
                   ` (5 preceding siblings ...)
  2013-05-31 10:55 ` [PATCH BlueZ 07/14] client/bluetooth-player: Add stop command Luiz Augusto von Dentz
@ 2013-05-31 10:55 ` Luiz Augusto von Dentz
  2013-05-31 10:55 ` [PATCH BlueZ 09/14] client/bluetooth-player: Add previous command Luiz Augusto von Dentz
                   ` (5 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: Luiz Augusto von Dentz @ 2013-05-31 10:55 UTC (permalink / raw)
  To: linux-bluetooth

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

Add support for next command which can be used to jump to the next item
---
 client/bluetooth-player.c | 30 ++++++++++++++++++++++++++++++
 1 file changed, 30 insertions(+)

diff --git a/client/bluetooth-player.c b/client/bluetooth-player.c
index ebf6cd6..a6eb932 100644
--- a/client/bluetooth-player.c
+++ b/client/bluetooth-player.c
@@ -173,6 +173,35 @@ static void cmd_stop(int argc, char *argv[])
 	rl_printf("Attempting to stop\n");
 }
 
+static void next_reply(DBusMessage *message, void *user_data)
+{
+	DBusError error;
+
+	dbus_error_init(&error);
+
+	if (dbus_set_error_from_message(&error, message) == TRUE) {
+		rl_printf("Failed to jump to next: %s\n", error.name);
+		dbus_error_free(&error);
+		return;
+	}
+
+	rl_printf("Next successful\n");
+}
+
+static void cmd_next(int argc, char *argv[])
+{
+	if (!check_default_player())
+		return;
+
+	if (g_dbus_proxy_method_call(default_player, "Next", NULL, next_reply,
+							NULL, NULL) == FALSE) {
+		rl_printf("Failed to jump to next\n");
+		return;
+	}
+
+	rl_printf("Attempting to jump to next\n");
+}
+
 static const struct {
 	const char *cmd;
 	const char *arg;
@@ -182,6 +211,7 @@ static const struct {
 	{ "play",         NULL,       cmd_play, "Start playback" },
 	{ "pause",        NULL,       cmd_pause, "Pause playback" },
 	{ "stop",         NULL,       cmd_stop, "Stop playback" },
+	{ "next",         NULL,       cmd_next, "Jump to next item" },
 	{ "quit",         NULL,       cmd_quit, "Quit program" },
 	{ "exit",         NULL,       cmd_quit },
 	{ "help" },
-- 
1.8.1.4


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

* [PATCH BlueZ 09/14] client/bluetooth-player: Add previous command
  2013-05-31 10:55 [PATCH BlueZ 01/14] build: Add bluetooth-player command line client Luiz Augusto von Dentz
                   ` (6 preceding siblings ...)
  2013-05-31 10:55 ` [PATCH BlueZ 08/14] client/bluetooth-player: Add next command Luiz Augusto von Dentz
@ 2013-05-31 10:55 ` Luiz Augusto von Dentz
  2013-05-31 10:55 ` [PATCH BlueZ 10/14] client/bluetooth-player: Add fast_forward command Luiz Augusto von Dentz
                   ` (4 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: Luiz Augusto von Dentz @ 2013-05-31 10:55 UTC (permalink / raw)
  To: linux-bluetooth

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

Add support for next command which can be used to jump to the previous
item
---
 client/bluetooth-player.c | 30 ++++++++++++++++++++++++++++++
 1 file changed, 30 insertions(+)

diff --git a/client/bluetooth-player.c b/client/bluetooth-player.c
index a6eb932..92d577a 100644
--- a/client/bluetooth-player.c
+++ b/client/bluetooth-player.c
@@ -202,6 +202,35 @@ static void cmd_next(int argc, char *argv[])
 	rl_printf("Attempting to jump to next\n");
 }
 
+static void previous_reply(DBusMessage *message, void *user_data)
+{
+	DBusError error;
+
+	dbus_error_init(&error);
+
+	if (dbus_set_error_from_message(&error, message) == TRUE) {
+		rl_printf("Failed to jump to previous: %s\n", error.name);
+		dbus_error_free(&error);
+		return;
+	}
+
+	rl_printf("Previous successful\n");
+}
+
+static void cmd_previous(int argc, char *argv[])
+{
+	if (!check_default_player())
+		return;
+
+	if (g_dbus_proxy_method_call(default_player, "Previous", NULL,
+					previous_reply, NULL, NULL) == FALSE) {
+		rl_printf("Failed to jump to previous\n");
+		return;
+	}
+
+	rl_printf("Attempting to jump to previous\n");
+}
+
 static const struct {
 	const char *cmd;
 	const char *arg;
@@ -212,6 +241,7 @@ static const struct {
 	{ "pause",        NULL,       cmd_pause, "Pause playback" },
 	{ "stop",         NULL,       cmd_stop, "Stop playback" },
 	{ "next",         NULL,       cmd_next, "Jump to next item" },
+	{ "previous",     NULL,       cmd_previous, "Jump to previous item" },
 	{ "quit",         NULL,       cmd_quit, "Quit program" },
 	{ "exit",         NULL,       cmd_quit },
 	{ "help" },
-- 
1.8.1.4


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

* [PATCH BlueZ 10/14] client/bluetooth-player: Add fast_forward command
  2013-05-31 10:55 [PATCH BlueZ 01/14] build: Add bluetooth-player command line client Luiz Augusto von Dentz
                   ` (7 preceding siblings ...)
  2013-05-31 10:55 ` [PATCH BlueZ 09/14] client/bluetooth-player: Add previous command Luiz Augusto von Dentz
@ 2013-05-31 10:55 ` Luiz Augusto von Dentz
  2013-05-31 10:55 ` [PATCH BlueZ 11/14] client/bluetooth-player: Add rewind command Luiz Augusto von Dentz
                   ` (3 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: Luiz Augusto von Dentz @ 2013-05-31 10:55 UTC (permalink / raw)
  To: linux-bluetooth

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

Add support for fast_forward command which can be used to fast forward
the playback
---
 client/bluetooth-player.c | 31 +++++++++++++++++++++++++++++++
 1 file changed, 31 insertions(+)

diff --git a/client/bluetooth-player.c b/client/bluetooth-player.c
index 92d577a..dcbe301 100644
--- a/client/bluetooth-player.c
+++ b/client/bluetooth-player.c
@@ -231,6 +231,35 @@ static void cmd_previous(int argc, char *argv[])
 	rl_printf("Attempting to jump to previous\n");
 }
 
+static void fast_forward_reply(DBusMessage *message, void *user_data)
+{
+	DBusError error;
+
+	dbus_error_init(&error);
+
+	if (dbus_set_error_from_message(&error, message) == TRUE) {
+		rl_printf("Failed to fast forward: %s\n", error.name);
+		dbus_error_free(&error);
+		return;
+	}
+
+	rl_printf("FastForward successful\n");
+}
+
+static void cmd_fast_forward(int argc, char *argv[])
+{
+	if (!check_default_player())
+		return;
+
+	if (g_dbus_proxy_method_call(default_player, "FastForward", NULL,
+				fast_forward_reply, NULL, NULL) == FALSE) {
+		rl_printf("Failed to jump to previous\n");
+		return;
+	}
+
+	rl_printf("Fast forward playback\n");
+}
+
 static const struct {
 	const char *cmd;
 	const char *arg;
@@ -242,6 +271,8 @@ static const struct {
 	{ "stop",         NULL,       cmd_stop, "Stop playback" },
 	{ "next",         NULL,       cmd_next, "Jump to next item" },
 	{ "previous",     NULL,       cmd_previous, "Jump to previous item" },
+	{ "fast_forward", NULL,       cmd_fast_forward,
+						"Fast forward playback" },
 	{ "quit",         NULL,       cmd_quit, "Quit program" },
 	{ "exit",         NULL,       cmd_quit },
 	{ "help" },
-- 
1.8.1.4


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

* [PATCH BlueZ 11/14] client/bluetooth-player: Add rewind command
  2013-05-31 10:55 [PATCH BlueZ 01/14] build: Add bluetooth-player command line client Luiz Augusto von Dentz
                   ` (8 preceding siblings ...)
  2013-05-31 10:55 ` [PATCH BlueZ 10/14] client/bluetooth-player: Add fast_forward command Luiz Augusto von Dentz
@ 2013-05-31 10:55 ` Luiz Augusto von Dentz
  2013-05-31 10:55 ` [PATCH BlueZ 12/14] client/bluetooth-player: Add list command Luiz Augusto von Dentz
                   ` (2 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: Luiz Augusto von Dentz @ 2013-05-31 10:55 UTC (permalink / raw)
  To: linux-bluetooth

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

Add support for rewind command which can be used to rewind the playback
---
 client/bluetooth-player.c | 30 ++++++++++++++++++++++++++++++
 1 file changed, 30 insertions(+)

diff --git a/client/bluetooth-player.c b/client/bluetooth-player.c
index dcbe301..373c49e 100644
--- a/client/bluetooth-player.c
+++ b/client/bluetooth-player.c
@@ -260,6 +260,35 @@ static void cmd_fast_forward(int argc, char *argv[])
 	rl_printf("Fast forward playback\n");
 }
 
+static void rewind_reply(DBusMessage *message, void *user_data)
+{
+	DBusError error;
+
+	dbus_error_init(&error);
+
+	if (dbus_set_error_from_message(&error, message) == TRUE) {
+		rl_printf("Failed to rewind: %s\n", error.name);
+		dbus_error_free(&error);
+		return;
+	}
+
+	rl_printf("Rewind successful\n");
+}
+
+static void cmd_rewind(int argc, char *argv[])
+{
+	if (!check_default_player())
+		return;
+
+	if (g_dbus_proxy_method_call(default_player, "Rewind", NULL,
+					rewind_reply, NULL, NULL) == FALSE) {
+		rl_printf("Failed to rewind\n");
+		return;
+	}
+
+	rl_printf("Rewind playback\n");
+}
+
 static const struct {
 	const char *cmd;
 	const char *arg;
@@ -273,6 +302,7 @@ static const struct {
 	{ "previous",     NULL,       cmd_previous, "Jump to previous item" },
 	{ "fast_forward", NULL,       cmd_fast_forward,
 						"Fast forward playback" },
+	{ "rewind",       NULL,       cmd_rewind, "Rewind playback" },
 	{ "quit",         NULL,       cmd_quit, "Quit program" },
 	{ "exit",         NULL,       cmd_quit },
 	{ "help" },
-- 
1.8.1.4


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

* [PATCH BlueZ 12/14] client/bluetooth-player: Add list command
  2013-05-31 10:55 [PATCH BlueZ 01/14] build: Add bluetooth-player command line client Luiz Augusto von Dentz
                   ` (9 preceding siblings ...)
  2013-05-31 10:55 ` [PATCH BlueZ 11/14] client/bluetooth-player: Add rewind command Luiz Augusto von Dentz
@ 2013-05-31 10:55 ` Luiz Augusto von Dentz
  2013-05-31 10:55 ` [PATCH BlueZ 13/14] client/bluetooth-player: Add show command Luiz Augusto von Dentz
  2013-05-31 10:55 ` [PATCH BlueZ 14/14] client/bluetooth-player: Add select command Luiz Augusto von Dentz
  12 siblings, 0 replies; 14+ messages in thread
From: Luiz Augusto von Dentz @ 2013-05-31 10:55 UTC (permalink / raw)
  To: linux-bluetooth

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

Add support for list command which can be used to list available players
---
 client/bluetooth-player.c | 59 ++++++++++++++++++++++++++++-------------------
 1 file changed, 35 insertions(+), 24 deletions(-)

diff --git a/client/bluetooth-player.c b/client/bluetooth-player.c
index 373c49e..7cfaa17 100644
--- a/client/bluetooth-player.c
+++ b/client/bluetooth-player.c
@@ -289,12 +289,47 @@ static void cmd_rewind(int argc, char *argv[])
 	rl_printf("Rewind playback\n");
 }
 
+static char *player_description(GDBusProxy *proxy, const char *description)
+{
+	const char *path;
+
+	path = g_dbus_proxy_get_path(proxy);
+
+	return g_strdup_printf("%s%s%sPlayer %s ",
+					description ? "[" : "",
+					description ? : "",
+					description ? "] " : "",
+					path);
+}
+
+static void print_player(GDBusProxy *proxy, const char *description)
+{
+	char *str;
+
+	str = player_description(proxy, description);
+
+	rl_printf("%s%s\n", str, default_player == proxy ? "[default]" : "");
+
+	g_free(str);
+}
+
+static void cmd_list(int argc, char *arg[])
+{
+	GSList *l;
+
+	for (l = players; l; l = g_slist_next(l)) {
+		GDBusProxy *proxy = l->data;
+		print_player(proxy, NULL);
+	}
+}
+
 static const struct {
 	const char *cmd;
 	const char *arg;
 	void (*func) (int argc, char *argv[]);
 	const char *desc;
 } cmd_table[] = {
+	{ "list",         NULL,       cmd_list, "List available players" },
 	{ "play",         NULL,       cmd_play, "Start playback" },
 	{ "pause",        NULL,       cmd_pause, "Pause playback" },
 	{ "stop",         NULL,       cmd_stop, "Stop playback" },
@@ -515,30 +550,6 @@ static guint setup_standard_input(void)
 	return source;
 }
 
-static char *player_description(GDBusProxy *proxy, const char *description)
-{
-	const char *path;
-
-	path = g_dbus_proxy_get_path(proxy);
-
-	return g_strdup_printf("%s%s%sPlayer %s ",
-					description ? "[" : "",
-					description ? : "",
-					description ? "] " : "",
-					path);
-}
-
-static void print_player(GDBusProxy *proxy, const char *description)
-{
-	char *str;
-
-	str = player_description(proxy, description);
-
-	rl_printf("%s%s\n", str, default_player == proxy ? "[default]" : "");
-
-	g_free(str);
-}
-
 static void player_added(GDBusProxy *proxy)
 {
 	players = g_slist_append(players, proxy);
-- 
1.8.1.4


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

* [PATCH BlueZ 13/14] client/bluetooth-player: Add show command
  2013-05-31 10:55 [PATCH BlueZ 01/14] build: Add bluetooth-player command line client Luiz Augusto von Dentz
                   ` (10 preceding siblings ...)
  2013-05-31 10:55 ` [PATCH BlueZ 12/14] client/bluetooth-player: Add list command Luiz Augusto von Dentz
@ 2013-05-31 10:55 ` Luiz Augusto von Dentz
  2013-05-31 10:55 ` [PATCH BlueZ 14/14] client/bluetooth-player: Add select command Luiz Augusto von Dentz
  12 siblings, 0 replies; 14+ messages in thread
From: Luiz Augusto von Dentz @ 2013-05-31 10:55 UTC (permalink / raw)
  To: linux-bluetooth

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

Add support for show command which can be used to show player
information
---
 client/bluetooth-player.c | 181 +++++++++++++++++++++++++++++-----------------
 1 file changed, 116 insertions(+), 65 deletions(-)

diff --git a/client/bluetooth-player.c b/client/bluetooth-player.c
index 7cfaa17..3e25bba 100644
--- a/client/bluetooth-player.c
+++ b/client/bluetooth-player.c
@@ -323,6 +323,121 @@ static void cmd_list(int argc, char *arg[])
 	}
 }
 
+static GDBusProxy *find_player(const char *path)
+{
+	GSList *l;
+
+	for (l = players; l; l = g_slist_next(l)) {
+		GDBusProxy *proxy = l->data;
+
+		if (strcmp(path, g_dbus_proxy_get_path(proxy)) == 0)
+			return proxy;
+	}
+
+	return NULL;
+}
+
+static void print_iter(const char *label, const char *name,
+						DBusMessageIter *iter)
+{
+	dbus_bool_t valbool;
+	dbus_uint32_t valu32;
+	dbus_uint16_t valu16;
+	dbus_int16_t vals16;
+	const char *valstr;
+	DBusMessageIter subiter;
+
+	if (iter == NULL) {
+		rl_printf("%s%s is nil\n", label, name);
+		return;
+	}
+
+	switch (dbus_message_iter_get_arg_type(iter)) {
+	case DBUS_TYPE_INVALID:
+		rl_printf("%s%s is invalid\n", label, name);
+		break;
+	case DBUS_TYPE_STRING:
+	case DBUS_TYPE_OBJECT_PATH:
+		dbus_message_iter_get_basic(iter, &valstr);
+		rl_printf("%s%s: %s\n", label, name, valstr);
+		break;
+	case DBUS_TYPE_BOOLEAN:
+		dbus_message_iter_get_basic(iter, &valbool);
+		rl_printf("%s%s: %s\n", label, name,
+					valbool == TRUE ? "yes" : "no");
+		break;
+	case DBUS_TYPE_UINT32:
+		dbus_message_iter_get_basic(iter, &valu32);
+		rl_printf("%s%s: 0x%06x\n", label, name, valu32);
+		break;
+	case DBUS_TYPE_UINT16:
+		dbus_message_iter_get_basic(iter, &valu16);
+		rl_printf("%s%s: 0x%04x\n", label, name, valu16);
+		break;
+	case DBUS_TYPE_INT16:
+		dbus_message_iter_get_basic(iter, &vals16);
+		rl_printf("%s%s: %d\n", label, name, vals16);
+		break;
+	case DBUS_TYPE_VARIANT:
+		dbus_message_iter_recurse(iter, &subiter);
+		print_iter(label, name, &subiter);
+		break;
+	case DBUS_TYPE_ARRAY:
+		dbus_message_iter_recurse(iter, &subiter);
+		while (dbus_message_iter_get_arg_type(&subiter) !=
+							DBUS_TYPE_INVALID) {
+			print_iter(label, name, &subiter);
+			dbus_message_iter_next(&subiter);
+		}
+		break;
+	case DBUS_TYPE_DICT_ENTRY:
+		dbus_message_iter_recurse(iter, &subiter);
+		dbus_message_iter_get_basic(&subiter, &valstr);
+		dbus_message_iter_next(&subiter);
+		print_iter(label, valstr, &subiter);
+		break;
+	default:
+		rl_printf("%s%s has unsupported type\n", label, name);
+		break;
+	}
+}
+
+static void print_property(GDBusProxy *proxy, const char *name)
+{
+	DBusMessageIter iter;
+
+	if (g_dbus_proxy_get_property(proxy, name, &iter) == FALSE)
+		return;
+
+	print_iter("\t", name, &iter);
+}
+
+static void cmd_show(int argc, char *argv[])
+{
+	GDBusProxy *proxy;
+
+	if (argc < 2) {
+		if (check_default_player() == FALSE)
+			return;
+
+		proxy = default_player;
+	} else {
+		proxy = find_player(argv[1]);
+		if (!proxy) {
+			rl_printf("Player %s not available\n", argv[1]);
+			return;
+		}
+	}
+
+	print_property(proxy, "Name");
+	print_property(proxy, "Equalizer");
+	print_property(proxy, "Shuffle");
+	print_property(proxy, "Scan");
+	print_property(proxy, "Status");
+	print_property(proxy, "Position");
+	print_property(proxy, "Track");
+}
+
 static const struct {
 	const char *cmd;
 	const char *arg;
@@ -330,6 +445,7 @@ static const struct {
 	const char *desc;
 } cmd_table[] = {
 	{ "list",         NULL,       cmd_list, "List available players" },
+	{ "show",         "[player]", cmd_show, "Player information" },
 	{ "play",         NULL,       cmd_play, "Start playback" },
 	{ "pause",        NULL,       cmd_pause, "Pause playback" },
 	{ "stop",         NULL,       cmd_stop, "Stop playback" },
@@ -590,71 +706,6 @@ static void proxy_removed(GDBusProxy *proxy, void *user_data)
 		player_removed(proxy);
 }
 
-static void print_iter(const char *label, const char *name,
-						DBusMessageIter *iter)
-{
-	dbus_bool_t valbool;
-	dbus_uint32_t valu32;
-	dbus_uint16_t valu16;
-	dbus_int16_t vals16;
-	const char *valstr;
-	DBusMessageIter subiter;
-
-	if (iter == NULL) {
-		rl_printf("%s%s is nil\n", label, name);
-		return;
-	}
-
-	switch (dbus_message_iter_get_arg_type(iter)) {
-	case DBUS_TYPE_INVALID:
-		rl_printf("%s%s is invalid\n", label, name);
-		break;
-	case DBUS_TYPE_STRING:
-	case DBUS_TYPE_OBJECT_PATH:
-		dbus_message_iter_get_basic(iter, &valstr);
-		rl_printf("%s%s: %s\n", label, name, valstr);
-		break;
-	case DBUS_TYPE_BOOLEAN:
-		dbus_message_iter_get_basic(iter, &valbool);
-		rl_printf("%s%s: %s\n", label, name,
-					valbool == TRUE ? "yes" : "no");
-		break;
-	case DBUS_TYPE_UINT32:
-		dbus_message_iter_get_basic(iter, &valu32);
-		rl_printf("%s%s: 0x%06x\n", label, name, valu32);
-		break;
-	case DBUS_TYPE_UINT16:
-		dbus_message_iter_get_basic(iter, &valu16);
-		rl_printf("%s%s: 0x%04x\n", label, name, valu16);
-		break;
-	case DBUS_TYPE_INT16:
-		dbus_message_iter_get_basic(iter, &vals16);
-		rl_printf("%s%s: %d\n", label, name, vals16);
-		break;
-	case DBUS_TYPE_VARIANT:
-		dbus_message_iter_recurse(iter, &subiter);
-		print_iter(label, name, &subiter);
-		break;
-	case DBUS_TYPE_ARRAY:
-		dbus_message_iter_recurse(iter, &subiter);
-		while (dbus_message_iter_get_arg_type(&subiter) !=
-							DBUS_TYPE_INVALID) {
-			print_iter(label, name, &subiter);
-			dbus_message_iter_next(&subiter);
-		}
-		break;
-	case DBUS_TYPE_DICT_ENTRY:
-		dbus_message_iter_recurse(iter, &subiter);
-		dbus_message_iter_get_basic(&subiter, &valstr);
-		dbus_message_iter_next(&subiter);
-		print_iter(label, valstr, &subiter);
-		break;
-	default:
-		rl_printf("%s%s has unsupported type\n", label, name);
-		break;
-	}
-}
-
 static void property_changed(GDBusProxy *proxy, const char *name,
 					DBusMessageIter *iter, void *user_data)
 {
-- 
1.8.1.4


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

* [PATCH BlueZ 14/14] client/bluetooth-player: Add select command
  2013-05-31 10:55 [PATCH BlueZ 01/14] build: Add bluetooth-player command line client Luiz Augusto von Dentz
                   ` (11 preceding siblings ...)
  2013-05-31 10:55 ` [PATCH BlueZ 13/14] client/bluetooth-player: Add show command Luiz Augusto von Dentz
@ 2013-05-31 10:55 ` Luiz Augusto von Dentz
  12 siblings, 0 replies; 14+ messages in thread
From: Luiz Augusto von Dentz @ 2013-05-31 10:55 UTC (permalink / raw)
  To: linux-bluetooth

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

Add support for select command which can be used to set the default
player
---
 client/bluetooth-player.c | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)

diff --git a/client/bluetooth-player.c b/client/bluetooth-player.c
index 3e25bba..3daf586 100644
--- a/client/bluetooth-player.c
+++ b/client/bluetooth-player.c
@@ -438,6 +438,28 @@ static void cmd_show(int argc, char *argv[])
 	print_property(proxy, "Track");
 }
 
+static void cmd_select(int argc, char *argv[])
+{
+	GDBusProxy *proxy;
+
+	if (argc < 2) {
+		rl_printf("Missing player address argument\n");
+		return;
+	}
+
+	proxy = find_player(argv[1]);
+	if (proxy == NULL) {
+		rl_printf("Player %s not available\n", argv[1]);
+		return;
+	}
+
+	if (default_player == proxy)
+		return;
+
+	default_player = proxy,
+	print_player(proxy, NULL);
+}
+
 static const struct {
 	const char *cmd;
 	const char *arg;
@@ -446,6 +468,7 @@ static const struct {
 } cmd_table[] = {
 	{ "list",         NULL,       cmd_list, "List available players" },
 	{ "show",         "[player]", cmd_show, "Player information" },
+	{ "select",       "<player>", cmd_select, "Select default player" },
 	{ "play",         NULL,       cmd_play, "Start playback" },
 	{ "pause",        NULL,       cmd_pause, "Pause playback" },
 	{ "stop",         NULL,       cmd_stop, "Stop playback" },
-- 
1.8.1.4


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

end of thread, other threads:[~2013-05-31 10:55 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-05-31 10:55 [PATCH BlueZ 01/14] build: Add bluetooth-player command line client Luiz Augusto von Dentz
2013-05-31 10:55 ` [PATCH BlueZ 02/14] client/bluetooth-player: Add initial code Luiz Augusto von Dentz
2013-05-31 10:55 ` [PATCH BlueZ 03/14] client/bluetooth-player: Add proxy handling for org.bluez.MediaPlayer1 Luiz Augusto von Dentz
2013-05-31 10:55 ` [PATCH BlueZ 04/14] client/bluetooth-player: Add support for container types to print_iter Luiz Augusto von Dentz
2013-05-31 10:55 ` [PATCH BlueZ 05/14] client/bluetooth-player: Add play command Luiz Augusto von Dentz
2013-05-31 10:55 ` [PATCH BlueZ 06/14] client/bluetooth-player: Add pause command Luiz Augusto von Dentz
2013-05-31 10:55 ` [PATCH BlueZ 07/14] client/bluetooth-player: Add stop command Luiz Augusto von Dentz
2013-05-31 10:55 ` [PATCH BlueZ 08/14] client/bluetooth-player: Add next command Luiz Augusto von Dentz
2013-05-31 10:55 ` [PATCH BlueZ 09/14] client/bluetooth-player: Add previous command Luiz Augusto von Dentz
2013-05-31 10:55 ` [PATCH BlueZ 10/14] client/bluetooth-player: Add fast_forward command Luiz Augusto von Dentz
2013-05-31 10:55 ` [PATCH BlueZ 11/14] client/bluetooth-player: Add rewind command Luiz Augusto von Dentz
2013-05-31 10:55 ` [PATCH BlueZ 12/14] client/bluetooth-player: Add list command Luiz Augusto von Dentz
2013-05-31 10:55 ` [PATCH BlueZ 13/14] client/bluetooth-player: Add show command Luiz Augusto von Dentz
2013-05-31 10:55 ` [PATCH BlueZ 14/14] client/bluetooth-player: Add select command Luiz Augusto von Dentz

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.