* [PATCH BlueZ 1/3] shared/shell: Add non-interactive mode
@ 2018-02-20 14:47 Luiz Augusto von Dentz
2018-02-20 14:47 ` [PATCH BlueZ 2/3] tools/bluetooth-player: Only enable attach input when connected Luiz Augusto von Dentz
2018-02-20 14:47 ` [PATCH BlueZ 3/3] tools/obexctl: " Luiz Augusto von Dentz
0 siblings, 2 replies; 3+ messages in thread
From: Luiz Augusto von Dentz @ 2018-02-20 14:47 UTC (permalink / raw)
To: linux-bluetooth
From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
This detects if any command was given as parameter, execute it and
exit disabling all other outputs:
bluetoothctl list
Controller 00:1B:DC:07:31:88 Vudentz's T460s #1 [default]
Controller B8:8A:60:D8:17:D7 BlueZ-1
It is also possible to run interactive command with use of timeout
option:
bluetoothctl --timeout=10 advertise on
Agent registered
[CHG] Controller 00:1B:DC:07:31:88 SupportedInstances: 0x04
[CHG] Controller 00:1B:DC:07:31:88 ActiveInstances: 0x01
Advertising object registered
Tx Power: off
Name: off
Apperance: off
---
src/shared/shell.c | 37 +++++++++++++++++++++++++++++++++++--
1 file changed, 35 insertions(+), 2 deletions(-)
diff --git a/src/shared/shell.c b/src/shared/shell.c
index 12330ff53..8ce3935c8 100644
--- a/src/shared/shell.c
+++ b/src/shared/shell.c
@@ -62,6 +62,10 @@ struct bt_shell_env {
};
static struct {
+ int argc;
+ char **argv;
+ bool nint;
+ int nint_to;
struct io *input;
bool saved_prompt;
@@ -373,6 +377,9 @@ void bt_shell_printf(const char *fmt, ...)
char *saved_line;
int saved_point;
+ if (!data.input)
+ return;
+
save_input = !RL_ISSTATE(RL_STATE_DONE);
if (save_input) {
@@ -747,6 +754,7 @@ static void rl_init(void)
static const struct option main_options[] = {
{ "version", no_argument, 0, 'v' },
{ "help", no_argument, 0, 'h' },
+ { "timeout", required_argument, 0, 't' },
};
static void usage(int argc, char **argv, const struct bt_shell_opt *opt)
@@ -762,7 +770,8 @@ static void usage(int argc, char **argv, const struct bt_shell_opt *opt)
for (i = 0; opt && opt->options[i].name; i++)
printf("\t--%s \t%s\n", opt->options[i].name, opt->help[i]);
- printf("\t--version \tDisplay version\n"
+ printf("\t--timeout \t\tTimeout in seconds for non-interactive mode\n"
+ "\t--version \tDisplay version\n"
"\t--help \t\tDisplay help\n");
}
@@ -794,6 +803,9 @@ void bt_shell_init(int argc, char **argv, const struct bt_shell_opt *opt)
usage(argc, argv, opt);
exit(EXIT_SUCCESS);
return;
+ case 't':
+ data.nint_to = atoi(optarg);
+ break;
default:
if (c != opt->options[index - offset].val) {
usage(argc, argv, opt);
@@ -805,6 +817,10 @@ void bt_shell_init(int argc, char **argv, const struct bt_shell_opt *opt)
}
}
+ data.argc = argc - optind;
+ data.argv = argv + optind;
+ data.nint = (data.argc > 0);
+
main_loop = g_main_loop_new(NULL, FALSE);
rl_init();
@@ -876,7 +892,7 @@ bool bt_shell_add_submenu(const struct bt_shell_menu *menu)
void bt_shell_set_prompt(const char *string)
{
- if (!main_loop)
+ if (!main_loop || data.nint)
return;
rl_set_prompt(string);
@@ -891,6 +907,13 @@ static bool input_read(struct io *io, void *user_data)
return true;
}
+static gboolean shell_quit(void *data)
+{
+ g_main_loop_quit(main_loop);
+
+ return FALSE;
+}
+
bool bt_shell_attach(int fd)
{
struct io *io;
@@ -906,6 +929,16 @@ bool bt_shell_attach(int fd)
data.input = io;
+ if (data.nint) {
+ shell_exec(data.argc, data.argv);
+
+ if (!data.nint_to) {
+ bt_shell_detach();
+ g_main_loop_quit(main_loop);
+ } else
+ g_timeout_add_seconds(data.nint_to, shell_quit, NULL);
+ }
+
return true;
}
--
2.14.3
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [PATCH BlueZ 2/3] tools/bluetooth-player: Only enable attach input when connected
2018-02-20 14:47 [PATCH BlueZ 1/3] shared/shell: Add non-interactive mode Luiz Augusto von Dentz
@ 2018-02-20 14:47 ` Luiz Augusto von Dentz
2018-02-20 14:47 ` [PATCH BlueZ 3/3] tools/obexctl: " Luiz Augusto von Dentz
1 sibling, 0 replies; 3+ messages in thread
From: Luiz Augusto von Dentz @ 2018-02-20 14:47 UTC (permalink / raw)
To: linux-bluetooth
From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
---
tools/bluetooth-player.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/tools/bluetooth-player.c b/tools/bluetooth-player.c
index 709ef5633..32ae4f6bb 100644
--- a/tools/bluetooth-player.c
+++ b/tools/bluetooth-player.c
@@ -57,11 +57,13 @@ static GList *items = NULL;
static void connect_handler(DBusConnection *connection, void *user_data)
{
+ bt_shell_attach(fileno(stdin));
bt_shell_set_prompt(PROMPT_ON);
}
static void disconnect_handler(DBusConnection *connection, void *user_data)
{
+ bt_shell_detach();
bt_shell_set_prompt(PROMPT_OFF);
}
@@ -1124,7 +1126,6 @@ int main(int argc, char *argv[])
bt_shell_init(argc, argv, NULL);
bt_shell_set_menu(&main_menu);
bt_shell_set_prompt(PROMPT_OFF);
- bt_shell_attach(fileno(stdin));
dbus_conn = g_dbus_setup_bus(DBUS_BUS_SYSTEM, NULL, NULL);
--
2.14.3
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [PATCH BlueZ 3/3] tools/obexctl: Only enable attach input when connected
2018-02-20 14:47 [PATCH BlueZ 1/3] shared/shell: Add non-interactive mode Luiz Augusto von Dentz
2018-02-20 14:47 ` [PATCH BlueZ 2/3] tools/bluetooth-player: Only enable attach input when connected Luiz Augusto von Dentz
@ 2018-02-20 14:47 ` Luiz Augusto von Dentz
1 sibling, 0 replies; 3+ messages in thread
From: Luiz Augusto von Dentz @ 2018-02-20 14:47 UTC (permalink / raw)
To: linux-bluetooth
From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
---
tools/obexctl.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/tools/obexctl.c b/tools/obexctl.c
index 2ef1c044e..b6333842e 100644
--- a/tools/obexctl.c
+++ b/tools/obexctl.c
@@ -75,11 +75,13 @@ struct transfer_data {
static void connect_handler(DBusConnection *connection, void *user_data)
{
+ bt_shell_attach(fileno(stdin));
bt_shell_set_prompt(PROMPT_ON);
}
static void disconnect_handler(DBusConnection *connection, void *user_data)
{
+ bt_shell_detach();
bt_shell_set_prompt(PROMPT_OFF);
}
@@ -2111,7 +2113,6 @@ int main(int argc, char *argv[])
bt_shell_init(argc, argv, NULL);
bt_shell_set_menu(&main_menu);
bt_shell_set_prompt(PROMPT_OFF);
- bt_shell_attach(fileno(stdin));
dbus_conn = g_dbus_setup_bus(DBUS_BUS_SESSION, NULL, NULL);
--
2.14.3
^ permalink raw reply related [flat|nested] 3+ messages in thread
end of thread, other threads:[~2018-02-20 14:47 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-02-20 14:47 [PATCH BlueZ 1/3] shared/shell: Add non-interactive mode Luiz Augusto von Dentz
2018-02-20 14:47 ` [PATCH BlueZ 2/3] tools/bluetooth-player: Only enable attach input when connected Luiz Augusto von Dentz
2018-02-20 14:47 ` [PATCH BlueZ 3/3] tools/obexctl: " Luiz Augusto von Dentz
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).