summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarcel Holtmann <marcel@holtmann.org>2009-07-07 00:03:12 -0700
committerMarcel Holtmann <marcel@holtmann.org>2009-07-07 00:03:12 -0700
commit428dd297c3662be73b932b403f039c7a03f173e3 (patch)
tree161849f5136216f3652f7dff73f53b006214bc8f
parent878f8bd34ff4478f5c6e857dbd5d7dbc1b8334c4 (diff)
downloadconnman-428dd297c3662be73b932b403f039c7a03f173e3.tar.gz
connman-428dd297c3662be73b932b403f039c7a03f173e3.tar.bz2
connman-428dd297c3662be73b932b403f039c7a03f173e3.zip
Trigger auto-connect when new service is added
-rw-r--r--src/service.c57
1 files changed, 57 insertions, 0 deletions
diff --git a/src/service.c b/src/service.c
index 5b2c6688..612424e9 100644
--- a/src/service.c
+++ b/src/service.c
@@ -1110,6 +1110,57 @@ static int service_register(struct connman_service *service)
return 0;
}
+static connman_bool_t is_connecting(struct connman_service *service)
+{
+ switch (service->state) {
+ case CONNMAN_SERVICE_STATE_UNKNOWN:
+ case CONNMAN_SERVICE_STATE_IDLE:
+ case CONNMAN_SERVICE_STATE_CARRIER:
+ case CONNMAN_SERVICE_STATE_FAILURE:
+ case CONNMAN_SERVICE_STATE_DISCONNECT:
+ case CONNMAN_SERVICE_STATE_READY:
+ break;
+ case CONNMAN_SERVICE_STATE_ASSOCIATION:
+ case CONNMAN_SERVICE_STATE_CONFIGURATION:
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
+static void __connman_service_auto_connect(void)
+{
+ struct connman_service *service;
+ GSequenceIter *iter;
+
+ DBG("");
+
+ iter = g_sequence_get_begin_iter(service_list);
+ if (g_sequence_iter_is_end(iter) == TRUE)
+ return;
+
+ service = g_sequence_get(iter);
+
+ while (service->state == CONNMAN_SERVICE_STATE_FAILURE) {
+ iter = g_sequence_iter_next(iter);
+ if (g_sequence_iter_is_end(iter))
+ return;
+ service = g_sequence_get(iter);
+ }
+
+ if (service->favorite == FALSE)
+ return;
+
+ if (service->state == CONNMAN_SERVICE_STATE_READY)
+ return;
+
+ if (is_connecting(service) == TRUE)
+ return;
+
+ if (service->state == CONNMAN_SERVICE_STATE_IDLE)
+ __connman_service_connect(service);
+}
+
/**
* connman_service_lookup_from_device:
* @device: device structure
@@ -1195,6 +1246,9 @@ struct connman_service *__connman_service_create_from_device(struct connman_devi
service_register(service);
+ if (service->favorite == TRUE)
+ __connman_service_auto_connect();
+
done:
g_free(name);
@@ -1383,6 +1437,9 @@ struct connman_service *__connman_service_create_from_network(struct connman_net
service_register(service);
+ if (service->favorite == TRUE)
+ __connman_service_auto_connect();
+
done:
g_free(name);