All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH BlueZ 0/1] Usage of bt_shell with ell
@ 2018-04-02  2:34 Inga Stotland
  2018-04-02  2:34 ` [PATCH BlueZ 1/1] shared/shell: Add commands to allow shell usage with external mainloop Inga Stotland
  2018-04-02  7:12 ` [PATCH BlueZ 0/1] Usage of bt_shell with ell Luiz Augusto von Dentz
  0 siblings, 2 replies; 4+ messages in thread
From: Inga Stotland @ 2018-04-02  2:34 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Inga Stotland

For test code that relies on underlying ell-based implementation, I would
like to use the menues and navigation features provided by bt_shell
without starting glib's mainloop.
The attached patch allows to do just that. Perhaps, this is not most elegant
solution, but it seems to be less invasive.

Inga Stotland (1):
  shared/shell: Add commands to allow shell usage with external mainloop

 src/shared/shell.c | 42 ++++++++++++++++++++++++++++++++++++++++--
 src/shared/shell.h |  3 +++
 2 files changed, 43 insertions(+), 2 deletions(-)

-- 
2.14.3


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

* [PATCH BlueZ 1/1] shared/shell: Add commands to allow shell usage with external mainloop
  2018-04-02  2:34 [PATCH BlueZ 0/1] Usage of bt_shell with ell Inga Stotland
@ 2018-04-02  2:34 ` Inga Stotland
  2018-04-02  7:12 ` [PATCH BlueZ 0/1] Usage of bt_shell with ell Luiz Augusto von Dentz
  1 sibling, 0 replies; 4+ messages in thread
From: Inga Stotland @ 2018-04-02  2:34 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Inga Stotland

This adds commands that allow to use bt_shell features when running a non glib
mainloop (e.g., ell based). This allows to bypass starting mainloop from
within the shell and register own io and on-exit operations.
---
 src/shared/shell.c | 42 ++++++++++++++++++++++++++++++++++++++++--
 src/shared/shell.h |  3 +++
 2 files changed, 43 insertions(+), 2 deletions(-)

diff --git a/src/shared/shell.c b/src/shared/shell.c
index be2a8dfe0..f552e553d 100644
--- a/src/shared/shell.c
+++ b/src/shared/shell.c
@@ -67,7 +67,8 @@ static struct {
 	char **argv;
 	bool mode;
 	int timeout;
-	struct io *input;
+	void *input;
+	bt_shell_menu_cb_t quit_cb;
 
 	bool saved_prompt;
 	bt_shell_prompt_input_func saved_func;
@@ -92,7 +93,10 @@ static void cmd_version(int argc, char *argv[])
 
 static void cmd_quit(int argc, char *argv[])
 {
-	mainloop_quit();
+	if (data.quit_cb)
+		data.quit_cb(argc, argv);
+	else
+		mainloop_quit();
 }
 
 static void cmd_help(int argc, char *argv[])
@@ -1134,6 +1138,7 @@ bool bt_shell_attach(int fd)
 	return true;
 }
 
+
 bool bt_shell_detach(void)
 {
 	if (!data.input)
@@ -1193,3 +1198,36 @@ void *bt_shell_get_env(const char *name)
 
 	return env->value;
 }
+
+bool bt_shell_attach_input_io(void *io)
+{
+	if (data.input)
+		return false;
+
+	data.input = io;
+
+	if (data.mode) {
+		if (shell_exec(data.argc, data.argv) < 0) {
+			bt_shell_noninteractive_quit(EXIT_FAILURE);
+			return true;
+		}
+
+		if (data.timeout)
+			timeout_add(data.timeout * 1000, shell_quit, NULL,
+								NULL);
+	}
+
+	return true;
+}
+
+bool bt_shell_detach_input_io(void)
+{
+	data.input = NULL;
+	return true;
+}
+
+void bt_shell_set_quit_cb(bt_shell_menu_cb_t cb)
+{
+	if (!data.quit_cb)
+		data.quit_cb = cb;
+}
diff --git a/src/shared/shell.h b/src/shared/shell.h
index 8b7cb7f30..84a74a15d 100644
--- a/src/shared/shell.h
+++ b/src/shared/shell.h
@@ -95,3 +95,6 @@ void bt_shell_set_env(const char *name, void *value);
 void *bt_shell_get_env(const char *name);
 
 void bt_shell_cleanup(void);
+bool bt_shell_attach_input_io(void *io);
+bool bt_shell_detach_input_io(void);
+void bt_shell_set_quit_cb(bt_shell_menu_cb_t cb);
-- 
2.14.3


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

* Re: [PATCH BlueZ 0/1] Usage of bt_shell with ell
  2018-04-02  2:34 [PATCH BlueZ 0/1] Usage of bt_shell with ell Inga Stotland
  2018-04-02  2:34 ` [PATCH BlueZ 1/1] shared/shell: Add commands to allow shell usage with external mainloop Inga Stotland
@ 2018-04-02  7:12 ` Luiz Augusto von Dentz
  2018-04-03  5:17   ` Stotland, Inga
  1 sibling, 1 reply; 4+ messages in thread
From: Luiz Augusto von Dentz @ 2018-04-02  7:12 UTC (permalink / raw)
  To: Inga Stotland; +Cc: linux-bluetooth

Hi Inga,

On Mon, Apr 2, 2018 at 5:34 AM, Inga Stotland <inga.stotland@intel.com> wrote:
> For test code that relies on underlying ell-based implementation, I would
> like to use the menues and navigation features provided by bt_shell
> without starting glib's mainloop.
> The attached patch allows to do just that. Perhaps, this is not most elegant
> solution, but it seems to be less invasive.


It should be possible to create ell backend for mainloop/io, etc, that
the shell uses, in fact btmgmt already do use a different mainloop
than glib.

> Inga Stotland (1):
>   shared/shell: Add commands to allow shell usage with external mainloop
>
>  src/shared/shell.c | 42 ++++++++++++++++++++++++++++++++++++++++--
>  src/shared/shell.h |  3 +++
>  2 files changed, 43 insertions(+), 2 deletions(-)
>
> --
> 2.14.3
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-bluetooth" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html



-- 
Luiz Augusto von Dentz

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

* Re: [PATCH BlueZ 0/1] Usage of bt_shell with ell
  2018-04-02  7:12 ` [PATCH BlueZ 0/1] Usage of bt_shell with ell Luiz Augusto von Dentz
@ 2018-04-03  5:17   ` Stotland, Inga
  0 siblings, 0 replies; 4+ messages in thread
From: Stotland, Inga @ 2018-04-03  5:17 UTC (permalink / raw)
  To: luiz.dentz; +Cc: linux-bluetooth

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

Hi Luiz,

On Mon, 2018-04-02 at 10:12 +0300, Luiz Augusto von Dentz wrote:
> Hi Inga,
> 
> On Mon, Apr 2, 2018 at 5:34 AM, Inga Stotland <inga.stotland@intel.co
> m> wrote:
> > For test code that relies on underlying ell-based implementation, I
> > would
> > like to use the menues and navigation features provided by bt_shell
> > without starting glib's mainloop.
> > The attached patch allows to do just that. Perhaps, this is not
> > most elegant
> > solution, but it seems to be less invasive.
> 
> 
> It should be possible to create ell backend for mainloop/io, etc,
> that
> the shell uses, in fact btmgmt already do use a different mainloop
> than glib.
> 

Right, it's not a glib mainloop. Anyway, after some digging around,
figured it out how to interface ell-based io with bt_shell. 

> > Inga Stotland (1):
> >   shared/shell: Add commands to allow shell usage with external
> > mainloop
> > 
> >  src/shared/shell.c | 42 ++++++++++++++++++++++++++++++++++++++++--
> >  src/shared/shell.h |  3 +++
> >  2 files changed, 43 insertions(+), 2 deletions(-)
> > 
> > --
> > 2.14.3
> > 
> > --
> > To unsubscribe from this list: send the line "unsubscribe linux-
> > bluetooth" in
> > the body of a message to majordomo@vger.kernel.org
> > More majordomo info at  http://vger.kernel.org/majordomo-info.html
> 
> 
> 
Inga

[-- Attachment #2: smime.p7s --]
[-- Type: application/x-pkcs7-signature, Size: 3266 bytes --]

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

end of thread, other threads:[~2018-04-03  5:17 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-04-02  2:34 [PATCH BlueZ 0/1] Usage of bt_shell with ell Inga Stotland
2018-04-02  2:34 ` [PATCH BlueZ 1/1] shared/shell: Add commands to allow shell usage with external mainloop Inga Stotland
2018-04-02  7:12 ` [PATCH BlueZ 0/1] Usage of bt_shell with ell Luiz Augusto von Dentz
2018-04-03  5:17   ` Stotland, Inga

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.