linux-bluetooth.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Anderson Lizardo <anderson.lizardo@openbossa.org>
To: linux-bluetooth@vger.kernel.org
Cc: Claudio Takahasi <claudio.takahasi@openbossa.org>
Subject: [PATCH v2 BlueZ 1/8] attrib: Centralize ATTIO connection management
Date: Tue, 27 Mar 2012 16:43:42 -0400	[thread overview]
Message-ID: <1332881029-1732-2-git-send-email-anderson.lizardo@openbossa.org> (raw)
In-Reply-To: <1332881029-1732-1-git-send-email-anderson.lizardo@openbossa.org>

From: Claudio Takahasi <claudio.takahasi@openbossa.org>

On Generic Attribute, register only one ATTIO connection callback to
centralize the connection management.

Also make sure the connection reference is properly dropped only if
there is no pending operation.
---
 attrib/client.c |   40 ++++++++++++++++++++++++----------------
 1 files changed, 24 insertions(+), 16 deletions(-)

diff --git a/attrib/client.c b/attrib/client.c
index c0e00c1..143c06b 100644
--- a/attrib/client.c
+++ b/attrib/client.c
@@ -62,7 +62,6 @@ struct format {
 
 struct query {
 	DBusMessage *msg;
-	guint attioid;
 	GSList *list;
 };
 
@@ -141,6 +140,22 @@ static void gatt_service_free(struct gatt_service *gatt)
 	g_free(gatt);
 }
 
+static void remove_attio(struct gatt_service *gatt)
+{
+	if (gatt->offline_chars || gatt->watchers || gatt->query)
+		return;
+
+	if (gatt->attioid) {
+		btd_device_remove_attio_callback(gatt->dev, gatt->attioid);
+		gatt->attioid = 0;
+	}
+
+	if (gatt->attrib) {
+		g_attrib_unref(gatt->attrib);
+		gatt->attrib = NULL;
+	}
+}
+
 static void gatt_get_address(struct gatt_service *gatt,
 				bdaddr_t *sba, bdaddr_t *dba)
 {
@@ -298,11 +313,7 @@ static void offline_char_written(gpointer user_data)
 
 	gatt->offline_chars = g_slist_remove(gatt->offline_chars, chr);
 
-	if (gatt->offline_chars || gatt->watchers)
-		return;
-
-	btd_device_remove_attio_callback(gatt->dev, gatt->attioid);
-	gatt->attioid = 0;
+	remove_attio(gatt);
 }
 
 static void offline_char_write(gpointer data, gpointer user_data)
@@ -394,10 +405,7 @@ static DBusMessage *unregister_watcher(DBusConnection *conn,
 	gatt->watchers = g_slist_remove(gatt->watchers, watcher);
 	watcher_free(watcher);
 
-	if (gatt->watchers == NULL && gatt->attioid) {
-		btd_device_remove_attio_callback(gatt->dev, gatt->attioid);
-		gatt->attioid = 0;
-	}
+	remove_attio(gatt);
 
 	return dbus_message_new_method_return(msg);
 }
@@ -632,10 +640,10 @@ static void query_list_remove(struct gatt_service *gatt, struct query_data *data
 	if (query->list != NULL)
 		return;
 
-	btd_device_remove_attio_callback(gatt->dev, query->attioid);
 	g_free(query);
-
 	gatt->query = NULL;
+
+	remove_attio(gatt);
 }
 
 static void update_char_desc(guint8 status, const guint8 *pdu, guint16 len,
@@ -928,7 +936,8 @@ static DBusMessage *discover_char(DBusConnection *conn, DBusMessage *msg,
 	qchr->gatt = gatt;
 
 	query->msg = dbus_message_ref(msg);
-	query->attioid = btd_device_add_attio_callback(gatt->dev,
+
+	gatt->attioid = btd_device_add_attio_callback(gatt->dev,
 							send_discover,
 							cancel_discover,
 							qchr);
@@ -1046,9 +1055,6 @@ static void primary_unregister(struct gatt_service *gatt)
 {
 	GSList *l;
 
-	if (gatt->attioid)
-		btd_device_remove_attio_callback(gatt->dev, gatt->attioid);
-
 	for (l = gatt->chars; l; l = l->next) {
 		struct characteristic *chr = l->data;
 		g_dbus_unregister_interface(gatt->conn, chr->path,
@@ -1056,6 +1062,8 @@ static void primary_unregister(struct gatt_service *gatt)
 	}
 
 	g_dbus_unregister_interface(gatt->conn, gatt->path, CHAR_INTERFACE);
+
+	remove_attio(gatt);
 }
 
 static int path_cmp(gconstpointer data, gconstpointer user_data)
-- 
1.7.5.4


  reply	other threads:[~2012-03-27 20:43 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-03-21 17:00 [PATCH BlueZ 0/8] Generic GATT client fixes Anderson Lizardo
2012-03-21 17:00 ` [PATCH BlueZ 1/8] attrib: Centralize ATTIO connection management Anderson Lizardo
2012-03-21 17:00 ` [PATCH BlueZ 2/8] attrib: Discover Characteristics if already connected Anderson Lizardo
2012-03-21 17:00 ` [PATCH BlueZ 3/8] attrib: Move Characteristic Discovery reply to a new function Anderson Lizardo
2012-03-21 17:00 ` [PATCH BlueZ 4/8] attrib: Register only new characteristics found Anderson Lizardo
2012-03-21 17:00 ` [PATCH BlueZ 5/8] attrib: Fix missing Discovery reply when disconnected Anderson Lizardo
2012-03-21 17:00 ` [PATCH BlueZ 6/8] attrib: Fix missing D-Bus message unref on DiscoverCharacteristics Anderson Lizardo
2012-03-21 17:00 ` [PATCH BlueZ 7/8] attrib: Attempt to remove attio callback on watcher exit Anderson Lizardo
2012-03-21 17:00 ` [PATCH BlueZ 8/8] gattrib: Protect GAttrib when there is a pending write Anderson Lizardo
2012-03-27 20:43 ` [PATCH v2 BlueZ 0/8] Generic GATT client fixes Anderson Lizardo
2012-03-27 20:43   ` Anderson Lizardo [this message]
2012-03-27 20:43   ` [PATCH v2 BlueZ 2/8] attrib: Discover Characteristics if already connected Anderson Lizardo
2012-03-27 20:43   ` [PATCH v2 BlueZ 3/8] attrib: Move Characteristic Discovery reply to a new function Anderson Lizardo
2012-03-27 20:43   ` [PATCH v2 BlueZ 4/8] attrib: Register only new characteristics found Anderson Lizardo
2012-03-27 20:43   ` [PATCH v2 BlueZ 5/8] attrib: Fix missing Discovery reply when disconnected Anderson Lizardo
2012-03-30 10:23     ` Johan Hedberg
2012-03-27 20:43   ` [PATCH v2 BlueZ 6/8] attrib: Fix missing D-Bus message unref on DiscoverCharacteristics Anderson Lizardo
2012-03-27 20:43   ` [PATCH v2 BlueZ 7/8] attrib: Attempt to remove attio callback on watcher exit Anderson Lizardo
2012-03-27 20:43   ` [PATCH v2 BlueZ 8/8] gattrib: Protect GAttrib when there is a pending write Anderson Lizardo
2012-03-30 10:25     ` Johan Hedberg
2012-04-02 13:56       ` Anderson Lizardo
2012-04-02 13:56 ` [PATCH v3 BlueZ 0/2] Generic GATT client fixes Anderson Lizardo
2012-04-02 13:56   ` [PATCH v3 BlueZ 1/2] attrib: Fix missing Discovery reply when disconnected Anderson Lizardo
2012-04-02 13:56   ` [PATCH v3 BlueZ 2/2] gattrib: Protect GAttrib when there is a pending write Anderson Lizardo
2012-04-03 11:19   ` [PATCH v3 BlueZ 0/2] Generic GATT client fixes Johan Hedberg

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=1332881029-1732-2-git-send-email-anderson.lizardo@openbossa.org \
    --to=anderson.lizardo@openbossa.org \
    --cc=claudio.takahasi@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 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).