All of lore.kernel.org
 help / color / mirror / Atom feed
From: "João Paulo Rechi Vita" <jprvita@openbossa.org>
To: linux-bluetooth@vger.kernel.org
Cc: "João Paulo Rechi Vita" <jprvita@openbossa.org>
Subject: [PATCH BlueZ v5 05/14] core: Use adapter connect list for LE connections
Date: Tue,  4 Sep 2012 16:04:33 -0300	[thread overview]
Message-ID: <1346785482-13359-6-git-send-email-jprvita@openbossa.org> (raw)
In-Reply-To: <1346785482-13359-1-git-send-email-jprvita@openbossa.org>

When a connection is needed for a LE device it is added to the adapter
connect list instead of directly connecting the ATT io channel.
---
 src/adapter.c |  2 +-
 src/device.c  | 45 +++++++++++----------------------------------
 src/device.h  |  1 +
 3 files changed, 13 insertions(+), 35 deletions(-)

diff --git a/src/adapter.c b/src/adapter.c
index c17f518..298a9cd 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -2916,7 +2916,7 @@ static gboolean connect_pending_cb(gpointer user_data)
 	if (adapter->discovering)
 		return TRUE;
 
-	/* TODO: call device connect callback */
+	device_att_connect(device);
 
 	return FALSE;
 }
diff --git a/src/device.c b/src/device.c
index c65f0b7..cc8a77a 100644
--- a/src/device.c
+++ b/src/device.c
@@ -68,8 +68,6 @@
 #define DISCONNECT_TIMER	2
 #define DISCOVERY_TIMER		2
 
-#define AUTO_CONNECTION_INTERVAL	5 /* Next connection attempt */
-
 struct btd_disconnect_data {
 	guint id;
 	disconnect_watch watch;
@@ -1831,15 +1829,6 @@ static void attio_disconnected(gpointer data, gpointer user_data)
 		attio->dcfunc(attio->user_data);
 }
 
-static void att_connect_dispatched(gpointer user_data)
-{
-	struct btd_device *device = user_data;
-
-	device->auto_id = 0;
-}
-
-static gboolean att_connect(gpointer user_data);
-
 static gboolean attrib_disconnected_cb(GIOChannel *io, GIOCondition cond,
 							gpointer user_data)
 {
@@ -1859,10 +1848,7 @@ static gboolean attrib_disconnected_cb(GIOChannel *io, GIOCondition cond,
 	if (device->auto_connect == FALSE || err != ETIMEDOUT)
 		goto done;
 
-	device->auto_id = g_timeout_add_seconds_full(G_PRIORITY_DEFAULT_IDLE,
-						AUTO_CONNECTION_INTERVAL,
-						att_connect, device,
-						att_connect_dispatched);
+	adapter_connect_list_add(device_get_adapter(device), device);
 
 done:
 	attio_cleanup(device);
@@ -1962,11 +1948,7 @@ static void att_error_cb(const GError *gerr, gpointer user_data)
 	if (device->auto_connect == FALSE)
 		return;
 
-	device->auto_id = g_timeout_add_seconds_full(G_PRIORITY_DEFAULT_IDLE,
-						AUTO_CONNECTION_INTERVAL,
-						att_connect, device,
-						att_connect_dispatched);
-
+	adapter_connect_list_add(device_get_adapter(device), device);
 	DBG("Enabling automatic connections");
 }
 
@@ -1981,7 +1963,7 @@ static void att_success_cb(gpointer user_data)
 	g_slist_foreach(device->attios, attio_connected, device->attrib);
 }
 
-static gboolean att_connect(gpointer user_data)
+gboolean device_att_connect(gpointer user_data)
 {
 	struct btd_device *device = user_data;
 	struct btd_adapter *adapter = device->adapter;
@@ -2243,6 +2225,9 @@ void device_set_temporary(struct btd_device *device, gboolean temporary)
 
 	DBG("temporary %d", temporary);
 
+	if (temporary)
+		adapter_connect_list_remove(device_get_adapter(device), device);
+
 	device->temporary = temporary;
 }
 
@@ -2258,6 +2243,7 @@ void device_set_bonded(struct btd_device *device, gboolean bonded)
 
 void device_set_auto_connect(struct btd_device *device, gboolean enable)
 {
+	struct btd_adapter *adapter = device_get_adapter(device);
 	char addr[18];
 
 	if (!device)
@@ -2271,15 +2257,10 @@ void device_set_auto_connect(struct btd_device *device, gboolean enable)
 
 	/* Disabling auto connect */
 	if (enable == FALSE) {
-		if (device->auto_id)
-			g_source_remove(device->auto_id);
+		adapter_connect_list_remove(adapter, device);
 		return;
 	}
 
-	/* Enabling auto connect */
-	if (device->auto_id != 0)
-		return;
-
 	if (device->attrib) {
 		DBG("Already connected");
 		return;
@@ -2288,9 +2269,8 @@ void device_set_auto_connect(struct btd_device *device, gboolean enable)
 	if (device->attios == NULL && device->attios_offline == NULL)
 		return;
 
-	device->auto_id = g_idle_add_full(G_PRIORITY_DEFAULT_IDLE,
-						att_connect, device,
-						att_connect_dispatched);
+	/* Enabling auto connect */
+	adapter_connect_list_add(adapter, device);
 }
 
 static gboolean start_discovery(gpointer user_data)
@@ -3191,10 +3171,7 @@ guint btd_device_add_attio_callback(struct btd_device *device,
 
 	device->attios = g_slist_append(device->attios, attio);
 
-	if (device->auto_id == 0)
-		device->auto_id = g_idle_add_full(G_PRIORITY_DEFAULT_IDLE,
-						att_connect, device,
-						att_connect_dispatched);
+	adapter_connect_list_add(device_get_adapter(device), device);
 
 	return attio->id;
 }
diff --git a/src/device.h b/src/device.h
index f1d95c6..ab70f90 100644
--- a/src/device.h
+++ b/src/device.h
@@ -158,3 +158,4 @@ int device_unblock(DBusConnection *conn, struct btd_device *device,
 void device_set_pnpid(struct btd_device *device, uint8_t vendor_id_src,
 			uint16_t vendor_id, uint16_t product_id,
 			uint16_t product_ver);
+gboolean device_att_connect(gpointer user_data);
-- 
1.7.11.4


  parent reply	other threads:[~2012-09-04 19:04 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-09-04 19:04 [PATCH BlueZ v5 00/14] LE General Connection Establishment procedure João Paulo Rechi Vita
2012-09-04 19:04 ` [PATCH BlueZ v5 01/14] core: Control connections based on adapter state João Paulo Rechi Vita
2012-09-07  9:59   ` Johan Hedberg
2012-09-11 13:34     ` Joao Paulo Rechi Vita
2012-09-04 19:04 ` [PATCH BlueZ v5 02/14] mgmt: Print error message when start_discovery fails João Paulo Rechi Vita
2012-09-04 19:04 ` [PATCH BlueZ v5 03/14] core: Add compare function for bdaddr in a struct btd_device João Paulo Rechi Vita
2012-09-04 19:04 ` [PATCH BlueZ v5 04/14] core: Add a list of LE devices to connect João Paulo Rechi Vita
2012-09-07 10:23   ` Johan Hedberg
2012-09-04 19:04 ` João Paulo Rechi Vita [this message]
2012-09-04 19:04 ` [PATCH BlueZ v5 06/14] core: Mutually exclude concurrent connections João Paulo Rechi Vita
2012-09-04 19:04 ` [PATCH BlueZ v5 07/14] mgmt: Add LE scanning callback João Paulo Rechi Vita
2012-09-04 19:04 ` [PATCH BlueZ v5 08/14] core: Replace interleaved by LE scanning João Paulo Rechi Vita
2012-09-04 19:04 ` [PATCH BlueZ v5 09/14] core: Start LE scanning when a device requests João Paulo Rechi Vita
2012-09-04 19:04 ` [PATCH BlueZ v5 10/14] core: Queue discovery if scanning is active João Paulo Rechi Vita
2012-09-04 19:04 ` [PATCH BlueZ v5 11/14] core: Disable unnecessary auto connections João Paulo Rechi Vita
2012-09-04 19:04 ` [PATCH BlueZ v5 12/14] core: Re-connect for ECONNRESET or ECONNABORTED João Paulo Rechi Vita
2012-09-04 19:04 ` [PATCH BlueZ v5 13/14] mgmt: Add address type to bonding debug message João Paulo Rechi Vita
2012-09-04 19:04 ` [PATCH BlueZ v5 14/14] core: Suspend scanning before connect on pairing João Paulo Rechi Vita
2012-09-05  5:00 ` [PATCH BlueZ v5 00/14] LE General Connection Establishment procedure Chen Ganir
2012-09-05 17:15   ` Joao Paulo Rechi Vita

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=1346785482-13359-6-git-send-email-jprvita@openbossa.org \
    --to=jprvita@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.