From: Patrik Flykt <[email protected]>

When a service is connected, remember whether it was the first
one in the session service list. As the session service list is
kept sorted, the most desired service is placed first. When the
service changes, check whether there are better services available
and try to connect them.
---
 src/session.c |    8 +++++---
 1 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/src/session.c b/src/session.c
index fb12d3c..417b698 100644
--- a/src/session.c
+++ b/src/session.c
@@ -69,6 +69,7 @@ struct service_entry {
        struct connman_service *service;
        const char *ifname;
        const char *bearer;
+       connman_bool_t optimal; /* service is the best one requested */
 };
 
 struct session_info {
@@ -844,6 +845,7 @@ static void select_and_connect(struct connman_session 
*session,
        if (entry != NULL) {
                info->entry = entry;
                info->entry->reason = reason;
+               info->entry->optimal = g_sequence_iter_is_begin(iter);
 
                if (explicit_connect(reason) == TRUE)
                        __connman_service_session_inc(info->entry->service);
@@ -886,14 +888,14 @@ static void session_changed(struct connman_session 
*session,
                        }
                }
 
-               if (info->online == FALSE) {
+               if (info->online == FALSE || info->entry->optimal == FALSE) {
                        select_and_connect(session,
                                        CONNMAN_SESSION_REASON_FREE_RIDE);
                }
 
                break;
        case CONNMAN_SESSION_TRIGGER_CONNECT:
-               if (info->online == TRUE) {
+               if (info->online == TRUE && info->entry->optimal == TRUE) {
                        info->entry->reason = CONNMAN_SESSION_REASON_CONNECT;
                        __connman_service_session_inc(info->entry->service);
                        break;
@@ -919,7 +921,7 @@ static void session_changed(struct connman_session *session,
 
                break;
        case CONNMAN_SESSION_TRIGGER_SERVICE:
-               if (info->online == TRUE)
+               if (info->online == TRUE && info->entry->optimal == TRUE)
                        break;
 
                if (info->stay_connected == TRUE) {
-- 
1.7.2.5

_______________________________________________
connman mailing list
[email protected]
http://lists.connman.net/listinfo/connman

Reply via email to