All of lore.kernel.org
 help / color / mirror / Atom feed
From: Alvaro Silva <alvaro.silva@openbossa.org>
To: linux-bluetooth@vger.kernel.org
Cc: Eder Ruiz Maria <eder.ruiz@openbossa.org>
Subject: [PATCH 10/13] gatttool: Use bluetoothctl strategy to handle standard input
Date: Thu, 21 Mar 2013 18:31:46 -0400	[thread overview]
Message-ID: <1363905109-30839-11-git-send-email-alvaro.silva@openbossa.org> (raw)
In-Reply-To: <1363905109-30839-1-git-send-email-alvaro.silva@openbossa.org>

From: Eder Ruiz Maria <eder.ruiz@openbossa.org>

Use GSource id returned by g_io_add_watch() instead of raw GIOChannel to
handle stdin and glib main loop.
---
 attrib/interactive.c |   26 +++++++++++++++++++-------
 1 file changed, 19 insertions(+), 7 deletions(-)

diff --git a/attrib/interactive.c b/attrib/interactive.c
index 7520324..fa3f82a 100644
--- a/attrib/interactive.c
+++ b/attrib/interactive.c
@@ -906,11 +906,26 @@ static char **commands_completion(const char *text, int start, int end)
 		return NULL;
 }
 
+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,
+				prompt_read, NULL);
+
+	g_io_channel_unref(channel);
+
+	return source;
+}
+
 int interactive(const gchar *src, const gchar *dst,
 		const gchar *dst_type, int psm)
 {
-	GIOChannel *pchan;
-	gint events;
+	guint input;
 
 	opt_sec_level = g_strdup("low");
 
@@ -923,10 +938,7 @@ int interactive(const gchar *src, const gchar *dst,
 
 	event_loop = g_main_loop_new(NULL, FALSE);
 
-	pchan = g_io_channel_unix_new(fileno(stdin));
-	g_io_channel_set_close_on_unref(pchan, TRUE);
-	events = G_IO_IN | G_IO_ERR | G_IO_HUP | G_IO_NVAL;
-	g_io_add_watch(pchan, events, prompt_read, NULL);
+	input = setup_standard_input();
 
 	rl_attempted_completion_function = commands_completion;
 	rl_erase_empty_line = 1;
@@ -936,7 +948,7 @@ int interactive(const gchar *src, const gchar *dst,
 
 	rl_callback_handler_remove();
 	cmd_disconnect(0, NULL);
-	g_io_channel_unref(pchan);
+	g_source_remove(input);
 	g_main_loop_unref(event_loop);
 	g_string_free(prompt, TRUE);
 
-- 
1.7.9.5


  parent reply	other threads:[~2013-03-21 22:31 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-03-21 22:31 [PATCH 00/13] Improvements on gatttool interactive interface Alvaro Silva
2013-03-21 22:31 ` [PATCH 01/13] gatttool: Fix memory leak after parsing input line Alvaro Silva
2013-03-21 22:31 ` [PATCH 02/13] gatttool: Remove programming error check Alvaro Silva
2013-03-22  1:06   ` Anderson Lizardo
2013-03-21 22:31 ` [PATCH 03/13] gatttool: Remote address is mandatory for non-interactive gatttool Alvaro Silva
2013-03-21 22:31 ` [PATCH 04/13] gatttool: Use GError to propage error messages to caller Alvaro Silva
2013-03-21 22:31 ` [PATCH 05/13] gatttool: Fix issues with printf() and readline prompt Alvaro Silva
2013-03-21 22:31 ` [PATCH 06/13] gatttool: Replace more usages of printf() with rl_printf() Alvaro Silva
2013-03-21 22:31 ` [PATCH 07/13] gatttool: Use bluetoothctl behavior when pressing Enter on empty prompt Alvaro Silva
2013-03-21 22:31 ` [PATCH 08/13] gatttool: Show connection state using color Alvaro Silva
2013-03-21 22:31 ` [PATCH 09/13] gatttool: Remove connecting message from prompt Alvaro Silva
2013-03-21 22:31 ` Alvaro Silva [this message]
2013-03-21 22:31 ` [PATCH 11/13] gatttool: Use bluetoothctl strategy for unix signal handling Alvaro Silva
2013-03-21 22:31 ` [PATCH 12/13] gatttool: Show info message when no primary service is found Alvaro Silva
2013-03-21 22:31 ` [PATCH 13/13] gatttool: Use error message prefixes consistently Alvaro Silva
2013-04-02 23:31 ` [PATCH BlueZ v2 00/13] Improvements on gatttool interactive interface Alvaro Silva
2013-04-02 23:31   ` [PATCH BlueZ v2 01/13] gatttool: Fix memory leak after parsing input line Alvaro Silva
2013-04-02 23:31   ` [PATCH BlueZ v2 02/13] gatttool: Remote address is mandatory for non-interactive gatttool Alvaro Silva
2013-04-02 23:31   ` [PATCH BlueZ v2 03/13] gatttool: Remove check for bluetooth address parameter on gatt_connect() Alvaro Silva
2013-04-02 23:31   ` [PATCH BlueZ v2 04/13] gatttool: Use GError to propage error messages to caller Alvaro Silva
2013-04-09 14:26     ` Johan Hedberg
2013-04-16 15:49     ` [PATCH BlueZ v3] " Eder Ruiz Maria
2013-04-17  8:24       ` Johan Hedberg
2013-04-02 23:31   ` [PATCH BlueZ v2 05/13] gatttool: Fix issues with printf() and readline prompt Alvaro Silva
2013-04-02 23:31   ` [PATCH BlueZ v2 06/13] gatttool: Replace more usages of printf() with rl_printf() Alvaro Silva
2013-04-02 23:31   ` [PATCH BlueZ v2 07/13] gatttool: Use bluetoothctl behavior when pressing Enter on empty prompt Alvaro Silva
2013-04-02 23:31   ` [PATCH BlueZ v2 08/13] gatttool: Show connection state using color Alvaro Silva
2013-04-02 23:31   ` [PATCH BlueZ v2 09/13] gatttool: Remove connecting message from prompt Alvaro Silva
2013-04-02 23:31   ` [PATCH BlueZ v2 10/13] gatttool: Use bluetoothctl strategy to handle standard input Alvaro Silva
2013-04-02 23:31   ` [PATCH BlueZ v2 11/13] gatttool: Use bluetoothctl strategy for unix signal handling Alvaro Silva
2013-04-02 23:31   ` [PATCH BlueZ v2 12/13] gatttool: Show info message when no primary service is found Alvaro Silva
2013-04-02 23:31   ` [PATCH BlueZ v2 13/13] gatttool: Use error message prefixes consistently Alvaro Silva

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1363905109-30839-11-git-send-email-alvaro.silva@openbossa.org \
    --to=alvaro.silva@openbossa.org \
    --cc=eder.ruiz@openbossa.org \
    --cc=linux-bluetooth@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.