service: Schedule auto connect procedure to be ran on its own
authorTomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
Tue, 17 Apr 2012 07:10:07 +0000 (10:10 +0300)
committerPatrik Flykt <patrik.flykt@linux.intel.com>
Tue, 17 Apr 2012 10:37:42 +0000 (13:37 +0300)
src/service.c

index 5805bfc..b3644b0 100644 (file)
@@ -43,6 +43,8 @@ static GSequence *service_list = NULL;
 static GHashTable *service_hash = NULL;
 static GSList *counter_list = NULL;
 
+static unsigned int autoconnect_timeout = 0;
+
 struct connman_stats {
        connman_bool_t valid;
        connman_bool_t enabled;
@@ -3164,17 +3166,14 @@ static connman_bool_t auto_connect_service(GSequenceIter* iter,
        return FALSE;
 }
 
-void __connman_service_auto_connect(void)
+static gboolean run_auto_connect(gpointer data)
 {
        GSequenceIter *iter = NULL;
        GSequence *preferred_tech;
 
-       DBG("");
+       autoconnect_timeout = 0;
 
-       if (__connman_session_mode() == TRUE) {
-               DBG("Session mode enabled: auto connect disabled");
-               return;
-       }
+       DBG("");
 
        preferred_tech = preferred_tech_list_get(service_list);
        if (preferred_tech != NULL)
@@ -3188,6 +3187,23 @@ void __connman_service_auto_connect(void)
 
        if (preferred_tech != NULL)
                g_sequence_free(preferred_tech);
+
+       return FALSE;
+}
+
+void __connman_service_auto_connect(void)
+{
+       DBG("");
+
+       if (__connman_session_mode() == TRUE) {
+               DBG("Session mode enabled: auto connect disabled");
+               return;
+       }
+
+       if (autoconnect_timeout != 0)
+               return;
+
+       autoconnect_timeout = g_timeout_add_seconds(0, run_auto_connect, NULL);
 }
 
 static void remove_timeout(struct connman_service *service)
@@ -5949,6 +5965,11 @@ void __connman_service_cleanup(void)
 
        DBG("");
 
+       if (autoconnect_timeout != 0) {
+               g_source_remove(autoconnect_timeout);
+               autoconnect_timeout = 0;
+       }
+
        list = service_list;
        service_list = NULL;
        g_sequence_free(list);