From: Patrik Flykt <patrik.fl...@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 get result in any services being connected, do another pass with session selection turned off in order to attempt something to be autoconnected. As a result refactor code and simplify it by also checking for NULL iterators. --- src/service.c | 47 ++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 38 insertions(+), 9 deletions(-)
diff --git a/src/service.c b/src/service.c index fc342f9..9ef76fd 100644 --- a/src/service.c +++ b/src/service.c @@ -3464,10 +3464,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); @@ -3486,6 +3489,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; @@ -3508,12 +3518,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(""); @@ -3521,15 +3530,34 @@ 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 = FALSE; + + DBG(""); + + if (sessions_active == TRUE && __connman_session_mode() == TRUE) + sessions = TRUE; + + 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; } @@ -3545,7 +3573,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 _______________________________________________ connman mailing list connman@connman.net http://lists.connman.net/listinfo/connman