[PATCH 2/7] service: Add mechanism to filter by session technology types

patrik.flykt at linux.intel.com patrik.flykt at linux.intel.com
Fri Nov 2 01:33:33 PDT 2012


From: Patrik Flykt <patrik.flykt at linux.intel.com>

Add a session technology type filter for autoconnect handling in
auto_connect_service(). Do a first autoconnect pass over the services
using the current state of session requests. If that does not result in
any services being connected, do another pass with session selection
turned off in order to attempt a normal autoconnected. As a result
refactor code and simplify it by also checking for NULL iterators.
---
 src/service.c |   43 ++++++++++++++++++++++++++++++++++---------
 1 file changed, 34 insertions(+), 9 deletions(-)

diff --git a/src/service.c b/src/service.c
index b36c083..2ba34b8 100644
--- a/src/service.c
+++ b/src/service.c
@@ -3479,10 +3479,13 @@ static GSequence* preferred_tech_list_get(GSequence *list)
 }
 
 static connman_bool_t auto_connect_service(GSequenceIter* iter,
-		connman_bool_t preferred)
+		connman_bool_t preferred, connman_bool_t sessions)
 {
 	struct connman_service *service = NULL;
 
+	if (iter == NULL)
+		return FALSE;
+
 	while (g_sequence_iter_is_end(iter) == FALSE) {
 		service = g_sequence_get(iter);
 
@@ -3501,6 +3504,13 @@ static connman_bool_t auto_connect_service(GSequenceIter* iter,
 		if (is_connected(service) == TRUE)
 			return TRUE;
 
+		if (sessions == TRUE &&
+				session_users[service->type].in_use == FALSE) {
+			DBG("sessions active for other types ignoring %p %s",
+					service, service->name);
+			goto next_service;
+		}
+
 		if (is_ignore(service) == FALSE && service->state ==
 				CONNMAN_SERVICE_STATE_IDLE)
 			break;
@@ -3523,12 +3533,11 @@ static connman_bool_t auto_connect_service(GSequenceIter* iter,
 	return FALSE;
 }
 
-static gboolean run_auto_connect(gpointer data)
+static gboolean run_auto_connect(connman_bool_t sessions)
 {
 	GSequenceIter *iter = NULL;
 	GSequence *preferred_tech;
-
-	autoconnect_timeout = 0;
+	connman_bool_t result;
 
 	DBG("");
 
@@ -3536,15 +3545,30 @@ static gboolean run_auto_connect(gpointer data)
 	if (preferred_tech != NULL)
 		iter = g_sequence_get_begin_iter(preferred_tech);
 
-	if (iter == NULL || auto_connect_service(iter, TRUE) == FALSE)
+	result = auto_connect_service(iter, TRUE, sessions);
+	if (result == FALSE) {
 		iter = g_sequence_get_begin_iter(service_list);
-
-	if (iter != NULL)
-		auto_connect_service(iter, FALSE);
+		result = auto_connect_service(iter, FALSE, sessions);
+	}
 
 	if (preferred_tech != NULL)
 		g_sequence_free(preferred_tech);
 
+	return result;
+}
+
+static gboolean auto_connect_timeout(gpointer data)
+{
+	connman_bool_t sessions = sessions_active;
+
+	DBG("");
+	if (run_auto_connect(sessions) == FALSE && sessions == TRUE) {
+		DBG("re-running auto connect without session selection");
+		run_auto_connect(FALSE);
+	}
+
+	autoconnect_timeout = 0;
+
 	return FALSE;
 }
 
@@ -3560,7 +3584,8 @@ void __connman_service_auto_connect(void)
 	if (autoconnect_timeout != 0)
 		return;
 
-	autoconnect_timeout = g_timeout_add_seconds(0, run_auto_connect, NULL);
+	autoconnect_timeout = g_timeout_add_seconds(0, auto_connect_timeout,
+			NULL);
 }
 
 static void remove_timeout(struct connman_service *service)
-- 
1.7.10.4




More information about the connman mailing list