session: Track reason on a session level
authorDaniel Wagner <daniel.wagner@bmw-carit.de>
Thu, 11 Aug 2011 14:56:18 +0000 (16:56 +0200)
committerDaniel Wagner <daniel.wagner@bmw-carit.de>
Thu, 11 Aug 2011 15:40:52 +0000 (17:40 +0200)
We need to track the Connect()/Disconnect() on a global session level
and not only in the info. This is needed when we were not able to
select and connect to a matching service in the first place. It might
happen that a valid service is added in time and then we want to use
it.

src/session.c

index da9162c..7d9fc8b 100644 (file)
@@ -84,6 +84,7 @@ struct session_info {
        unsigned int marker;
 
        struct service_entry *entry;
+       enum connman_session_reason reason;
 };
 
 struct connman_session {
@@ -760,6 +761,7 @@ static void test_and_disconnect(struct connman_session *session)
        entry = info->entry;
 
        info->online = FALSE;
+       info->reason = CONNMAN_SESSION_REASON_UNKNOWN;
        info->entry = NULL;
 
        if (disconnect == TRUE) {
@@ -784,6 +786,8 @@ static void select_and_connect(struct connman_session *session,
 
        DBG("session %p reason %s", session, reason2string(reason));
 
+       info->reason = reason;
+
        iter = g_sequence_get_begin_iter(session->service_list);
 
        while (g_sequence_iter_is_end(iter) == FALSE) {
@@ -902,6 +906,20 @@ static void session_changed(struct connman_session *session,
                        break;
                }
 
+               if (info->reason == CONNMAN_SESSION_REASON_CONNECT) {
+                       DBG("Retry to find a matching session");
+                       /*
+                        * The user called Connect() but there was no
+                        * matching session available at this point.
+                        * Now there might be a new one. Let's retry
+                        * to select and connect
+                        */
+                       select_and_connect(session,
+                                       CONNMAN_SESSION_REASON_CONNECT);
+
+                       break;
+               }
+
                if (info->stay_connected == TRUE) {
                        DBG("StayConnected");
                        select_and_connect(session,