linux-bluetooth.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/3] device: Split att_connect_cb
@ 2012-02-08 17:55 Andre Guedes
  2012-02-08 17:55 ` [PATCH 2/3] device: Fix invalid read in att_connect_cb Andre Guedes
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Andre Guedes @ 2012-02-08 17:55 UTC (permalink / raw)
  To: linux-bluetooth

In order to reduce code complexity, all code related to
device_browse_primary was moved to a new function called
browse_primary_connect_cb. This way att_connect_cb has
only code related to att_connect.
---
 src/device.c |   48 +++++++++++++++++++++++++++++++++---------------
 1 files changed, 33 insertions(+), 15 deletions(-)

diff --git a/src/device.c b/src/device.c
index c7c741c..311dca1 100644
--- a/src/device.c
+++ b/src/device.c
@@ -1818,21 +1818,12 @@ done:
 static void att_connect_cb(GIOChannel *io, GError *gerr, gpointer user_data)
 {
 	struct btd_device *device = user_data;
-	struct browse_req *req = device->browse;
 	GAttrib *attrib;
 
 	if (gerr) {
-		DBusMessage *reply;
-
 		DBG("%s", gerr->message);
 
-		if (req) {
-			reply = btd_error_failed(req->msg, gerr->message);
-			g_dbus_send_message(req->conn, reply);
-
-			device->browse = NULL;
-			browse_request_free(req, TRUE);
-		} else if (device->auto_connect)
+		if (device->auto_connect)
 			device->auto_id = g_timeout_add_seconds_full(
 						G_PRIORITY_DEFAULT_IDLE,
 						AUTO_CONNECTION_INTERVAL,
@@ -1847,10 +1838,7 @@ static void att_connect_cb(GIOChannel *io, GError *gerr, gpointer user_data)
 	if (device->attachid == 0)
 		error("Attribute server attach failure!");
 
-	if (req) {
-		req->attrib = attrib;
-		gatt_discover_primary(req->attrib, NULL, primary_cb, req);
-	} else if (device->attios) {
+	if (device->attios) {
 		device->attrib = attrib;
 		g_attrib_set_disconnect_function(device->attrib,
 						attrib_disconnected, device);
@@ -1902,6 +1890,36 @@ static gboolean att_connect(gpointer user_data)
 	return FALSE;
 }
 
+static void browse_primary_connect_cb(GIOChannel *io, GError *gerr,
+							gpointer user_data)
+{
+	struct btd_device *device = user_data;
+	struct browse_req *req = device->browse;
+	GAttrib *attrib;
+
+	if (gerr) {
+		DBusMessage *reply;
+
+		DBG("%s", gerr->message);
+
+		reply = btd_error_failed(req->msg, gerr->message);
+		g_dbus_send_message(req->conn, reply);
+
+		device->browse = NULL;
+		browse_request_free(req, TRUE);
+
+		return;
+	}
+
+	attrib = g_attrib_new(io);
+	device->attachid = attrib_channel_attach(attrib, TRUE);
+	if (device->attachid == 0)
+		error("Attribute server attach failure!");
+
+	req->attrib = attrib;
+	gatt_discover_primary(req->attrib, NULL, primary_cb, req);
+}
+
 int device_browse_primary(struct btd_device *device, DBusConnection *conn,
 				DBusMessage *msg, gboolean secure)
 {
@@ -1920,7 +1938,7 @@ int device_browse_primary(struct btd_device *device, DBusConnection *conn,
 
 	sec_level = secure ? BT_IO_SEC_HIGH : BT_IO_SEC_LOW;
 
-	req->io = bt_io_connect(BT_IO_L2CAP, att_connect_cb,
+	req->io = bt_io_connect(BT_IO_L2CAP, browse_primary_connect_cb,
 				device, NULL, NULL,
 				BT_IO_OPT_SOURCE_BDADDR, &src,
 				BT_IO_OPT_DEST_BDADDR, &device->bdaddr,
-- 
1.7.9


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

end of thread, other threads:[~2012-02-09 10:50 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-02-08 17:55 [PATCH 1/3] device: Split att_connect_cb Andre Guedes
2012-02-08 17:55 ` [PATCH 2/3] device: Fix invalid read in att_connect_cb Andre Guedes
2012-02-08 17:55 ` [PATCH 3/3] device: Reply ATT requests during bonding Andre Guedes
2012-02-09 10:50 ` [PATCH 1/3] device: Split att_connect_cb Johan Hedberg

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).