Linux bluetooth development
 help / color / mirror / Atom feed
* [PATCH 1/3] Fix gattrib.c coding style
@ 2011-02-24 20:34 Vinicius Costa Gomes
  2011-02-24 20:34 ` [PATCH 2/3] Add support for GATT client timeouts Vinicius Costa Gomes
  2011-02-24 20:34 ` [PATCH 3/3] gatttool: Remove extra reference to the connection IO Channel Vinicius Costa Gomes
  0 siblings, 2 replies; 4+ messages in thread
From: Vinicius Costa Gomes @ 2011-02-24 20:34 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Vinicius Costa Gomes

Just remove an extra empty line.
---
 attrib/gattrib.c |    1 -
 1 files changed, 0 insertions(+), 1 deletions(-)

diff --git a/attrib/gattrib.c b/attrib/gattrib.c
index 779a471..5b8b590 100644
--- a/attrib/gattrib.c
+++ b/attrib/gattrib.c
@@ -195,7 +195,6 @@ void g_attrib_unref(GAttrib *attrib)
 		g_io_channel_unref(attrib->io);
 	}
 
-
 	if (attrib->destroy)
 		attrib->destroy(attrib->destroy_user_data);
 
-- 
1.7.4.1


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

* [PATCH 2/3] Add support for GATT client timeouts
  2011-02-24 20:34 [PATCH 1/3] Fix gattrib.c coding style Vinicius Costa Gomes
@ 2011-02-24 20:34 ` Vinicius Costa Gomes
  2011-02-24 20:34 ` [PATCH 3/3] gatttool: Remove extra reference to the connection IO Channel Vinicius Costa Gomes
  1 sibling, 0 replies; 4+ messages in thread
From: Vinicius Costa Gomes @ 2011-02-24 20:34 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Vinicius Costa Gomes

This patch adds support to destroying the GATT connection
when a GATT server doesn't respond for more than 30 seconds.

A function to destroy the GAttrib is introduced and it is used
in the timeout case and when the last GAttrib reference is
dropped.
---
 attrib/gattrib.c |   43 ++++++++++++++++++++++++++++++++++++-------
 1 files changed, 36 insertions(+), 7 deletions(-)

diff --git a/attrib/gattrib.c b/attrib/gattrib.c
index 5b8b590..cf49ede 100644
--- a/attrib/gattrib.c
+++ b/attrib/gattrib.c
@@ -36,12 +36,15 @@
 #include "btio.h"
 #include "gattrib.h"
 
+#define GATT_TIMEOUT 30
+
 struct _GAttrib {
 	GIOChannel *io;
 	gint refs;
 	gint mtu;
 	guint read_watch;
 	guint write_watch;
+	guint timeout_watch;
 	GQueue *queue;
 	GSList *events;
 	guint next_cmd_id;
@@ -164,17 +167,11 @@ static void event_destroy(struct event *evt)
 	g_free(evt);
 }
 
-void g_attrib_unref(GAttrib *attrib)
+static void attrib_destroy(GAttrib *attrib)
 {
 	GSList *l;
 	struct command *c;
 
-	if (!attrib)
-		return;
-
-	if (g_atomic_int_dec_and_test(&attrib->refs) == FALSE)
-		return;
-
 	while ((c = g_queue_pop_head(attrib->queue)))
 		command_destroy(c);
 
@@ -187,6 +184,9 @@ void g_attrib_unref(GAttrib *attrib)
 	g_slist_free(attrib->events);
 	attrib->events = NULL;
 
+	if (attrib->timeout_watch> 0)
+		g_source_remove(attrib->timeout_watch);
+
 	if (attrib->write_watch > 0)
 		g_source_remove(attrib->write_watch);
 
@@ -201,6 +201,17 @@ void g_attrib_unref(GAttrib *attrib)
 	g_free(attrib);
 }
 
+void g_attrib_unref(GAttrib *attrib)
+{
+	if (!attrib)
+		return;
+
+	if (g_atomic_int_dec_and_test(&attrib->refs) == FALSE)
+		return;
+
+	attrib_destroy(attrib);
+}
+
 GIOChannel *g_attrib_get_channel(GAttrib *attrib)
 {
 	if (!attrib)
@@ -233,6 +244,15 @@ gboolean g_attrib_set_destroy_function(GAttrib *attrib,
 	return TRUE;
 }
 
+static gboolean disconnect_timeout(gpointer data)
+{
+	struct _GAttrib *attrib = data;
+
+	attrib_destroy(attrib);
+
+	return FALSE;
+}
+
 static gboolean can_write_data(GIOChannel *io, GIOCondition cond,
 								gpointer data)
 {
@@ -267,6 +287,10 @@ static gboolean can_write_data(GIOChannel *io, GIOCondition cond,
 
 	cmd->sent = TRUE;
 
+	if (attrib->timeout_watch == 0)
+		attrib->timeout_watch = g_timeout_add_seconds(GATT_TIMEOUT,
+						disconnect_timeout, attrib);
+
 	return FALSE;
 }
 
@@ -295,6 +319,11 @@ static gboolean received_data(GIOChannel *io, GIOCondition cond, gpointer data)
 	GIOStatus iostat;
 	gboolean qempty;
 
+	if (attrib->timeout_watch > 0) {
+		g_source_remove(attrib->timeout_watch);
+		attrib->timeout_watch = 0;
+	}
+
 	if (cond & (G_IO_HUP | G_IO_ERR | G_IO_NVAL)) {
 		attrib->read_watch = 0;
 		if (attrib->disconnect)
-- 
1.7.4.1


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

* [PATCH 3/3] gatttool: Remove extra reference to the connection IO Channel
  2011-02-24 20:34 [PATCH 1/3] Fix gattrib.c coding style Vinicius Costa Gomes
  2011-02-24 20:34 ` [PATCH 2/3] Add support for GATT client timeouts Vinicius Costa Gomes
@ 2011-02-24 20:34 ` Vinicius Costa Gomes
  2011-02-24 20:47   ` Johan Hedberg
  1 sibling, 1 reply; 4+ messages in thread
From: Vinicius Costa Gomes @ 2011-02-24 20:34 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Vinicius Costa Gomes

As we want the connection to be closed when the last GAttrib
reference is dropped, we don't need to keep this reference.
---
 attrib/gatttool.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/attrib/gatttool.c b/attrib/gatttool.c
index 7478043..547757d 100644
--- a/attrib/gatttool.c
+++ b/attrib/gatttool.c
@@ -620,6 +620,7 @@ int main(int argc, char *argv[])
 	}
 
 	attrib = g_attrib_new(chan);
+	g_io_channel_unref(chan);
 
 	event_loop = g_main_loop_new(NULL, FALSE);
 
@@ -634,7 +635,6 @@ int main(int argc, char *argv[])
 
 	g_main_loop_unref(event_loop);
 
-	g_io_channel_unref(chan);
 	g_attrib_unref(attrib);
 
 done:
-- 
1.7.4.1


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

* Re: [PATCH 3/3] gatttool: Remove extra reference to the connection IO Channel
  2011-02-24 20:34 ` [PATCH 3/3] gatttool: Remove extra reference to the connection IO Channel Vinicius Costa Gomes
@ 2011-02-24 20:47   ` Johan Hedberg
  0 siblings, 0 replies; 4+ messages in thread
From: Johan Hedberg @ 2011-02-24 20:47 UTC (permalink / raw)
  To: Vinicius Costa Gomes; +Cc: linux-bluetooth

Hi Vinicius,

On Thu, Feb 24, 2011, Vinicius Costa Gomes wrote:
> As we want the connection to be closed when the last GAttrib
> reference is dropped, we don't need to keep this reference.
> ---
>  attrib/gatttool.c |    2 +-
>  1 files changed, 1 insertions(+), 1 deletions(-)

All three patches have been pushed upstream. Thanks.

Johan

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

end of thread, other threads:[~2011-02-24 20:47 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-02-24 20:34 [PATCH 1/3] Fix gattrib.c coding style Vinicius Costa Gomes
2011-02-24 20:34 ` [PATCH 2/3] Add support for GATT client timeouts Vinicius Costa Gomes
2011-02-24 20:34 ` [PATCH 3/3] gatttool: Remove extra reference to the connection IO Channel Vinicius Costa Gomes
2011-02-24 20:47   ` Johan Hedberg

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox