session: Fix selection of services
authorDaniel Wagner <daniel.wagner@bmw-carit.de>
Mon, 22 Aug 2011 12:24:18 +0000 (14:24 +0200)
committerDaniel Wagner <daniel.wagner@bmw-carit.de>
Tue, 23 Aug 2011 15:22:29 +0000 (17:22 +0200)
In case we didn't select a service (entry) reset the one
in the info (deselection). And then we have also take
a refence if the reason was CONNECT.

src/session.c

index f0b6a20..19771b2 100644 (file)
@@ -823,18 +823,23 @@ static void select_and_connect(struct connman_session *session,
        if (info->entry != NULL && info->entry != entry)
                test_and_disconnect(session);
 
-       if (entry != NULL) {
-               info->entry = entry;
-               info->entry->reason = reason;
+       if (entry == NULL) {
+               info->entry = NULL;
+               return;
+       }
 
-               if (explicit_connect(reason) == TRUE)
-                       __connman_service_session_inc(info->entry->service);
+       info->entry = entry;
+       info->entry->reason = reason;
 
-               if (do_connect == TRUE)
-                       __connman_service_connect(info->entry->service);
-               else
-                       info->online = is_online(entry->state);
+       if (do_connect == TRUE) {
+               __connman_service_session_inc(info->entry->service);
+               __connman_service_connect(info->entry->service);
+       } else if (reason == CONNMAN_SESSION_REASON_CONNECT) {
+               /* session is already online take ref */
+               __connman_service_session_inc(info->entry->service);
        }
+
+       info->online = is_online(entry->state);
 }
 
 static void session_changed(struct connman_session *session,