Fix issues with current auto-connect logic
authorMarcel Holtmann <marcel@holtmann.org>
Fri, 17 Jul 2009 07:54:59 +0000 (09:54 +0200)
committerMarcel Holtmann <marcel@holtmann.org>
Fri, 17 Jul 2009 07:54:59 +0000 (09:54 +0200)
src/profile.c
src/service.c

index 5ce355e..f6ab24b 100644 (file)
@@ -93,8 +93,6 @@ static gboolean services_changed(gpointer user_data)
        append_services(&entry);
        g_dbus_send_message(connection, signal);
 
-       __connman_service_auto_connect();
-
        return FALSE;
 }
 
index 2cfbdb8..2753d90 100644 (file)
@@ -440,24 +440,6 @@ static connman_bool_t is_connecting(struct connman_service *service)
        return FALSE;
 }
 
-static struct connman_service *find_pending_service(void)
-{
-       struct connman_service *service;
-       GSequenceIter *iter;
-
-       iter = g_sequence_get_begin_iter(service_list);
-
-       while (g_sequence_iter_is_end(iter) == FALSE) {
-               service = g_sequence_get(iter);
-               if (service->pending != NULL)
-                       return service;
-
-               iter = g_sequence_iter_next(iter);
-       }
-
-       return NULL;
-}
-
 static connman_bool_t is_ignore(struct connman_service *service)
 {
        if (service->ignore == TRUE)
@@ -471,38 +453,38 @@ static connman_bool_t is_ignore(struct connman_service *service)
 
 void __connman_service_auto_connect(void)
 {
-       struct connman_service *service;
+       struct connman_service *service = NULL;
        GSequenceIter *iter;
 
        DBG("");
 
-       service = find_pending_service();
-       if (service != NULL)
-               return;
-
        iter = g_sequence_get_begin_iter(service_list);
-       if (g_sequence_iter_is_end(iter) == TRUE)
-               return;
 
-       service = g_sequence_get(iter);
+       while (g_sequence_iter_is_end(iter) == FALSE) {
+               service = g_sequence_get(iter);
+
+               if (service->pending != NULL)
+                       return;
 
-       while (is_ignore(service) == TRUE) {
-               iter = g_sequence_iter_next(iter);
-               if (g_sequence_iter_is_end(iter))
+               if (is_connecting(service) == TRUE)
                        return;
-               service = g_sequence_get(iter);
-       }
 
-       if (service->favorite == FALSE)
-               return;
+               if (service->favorite == FALSE)
+                       return;
 
-       if (service->state == CONNMAN_SERVICE_STATE_READY)
-               return;
+               if (service->state == CONNMAN_SERVICE_STATE_READY)
+                       return;
 
-       if (is_connecting(service) == TRUE)
-               return;
+               if (is_ignore(service) == FALSE &&
+                               service->state == CONNMAN_SERVICE_STATE_IDLE)
+                       break;
 
-       if (service->state == CONNMAN_SERVICE_STATE_IDLE)
+               service = NULL;
+
+               iter = g_sequence_iter_next(iter);
+       }
+
+       if (service != NULL)
                __connman_service_connect(service);
 }
 
@@ -1038,6 +1020,10 @@ int __connman_service_indicate_state(struct connman_service *service,
 
        __connman_profile_changed(FALSE);
 
+       if (service->favorite == TRUE &&
+                       service->state == CONNMAN_SERVICE_STATE_IDLE)
+               __connman_service_auto_connect();
+
        return 0;
 }