timeserver: Trigger ntp on default changed notifier
authorAlok Barsode <alok.barsode@linux.intel.com>
Thu, 5 Apr 2012 10:20:15 +0000 (13:20 +0300)
committerPatrik Flykt <patrik.flykt@linux.intel.com>
Thu, 5 Apr 2012 15:55:16 +0000 (18:55 +0300)
Trigger NTP sync on default service going to READY/ONLINE state
instead of triggering NTP sync on ONLINE state only. This makes
sense for local ntp servers even if the wispr check fails.

src/service.c
src/timeserver.c

index 6f0e0fa..54d29a6 100644 (file)
@@ -4163,9 +4163,6 @@ static int service_indicate_state(struct connman_service *service)
                }
        }
 
-       if (new_state == CONNMAN_SERVICE_STATE_ONLINE)
-               __connman_timeserver_sync(service);
-
        if (new_state == CONNMAN_SERVICE_STATE_IDLE) {
                connman_bool_t reconnect;
 
@@ -4235,8 +4232,6 @@ static int service_indicate_state(struct connman_service *service)
                dns_changed(service);
                domain_changed(service);
 
-               __connman_timeserver_stop();
-
                __connman_notifier_disconnect(service->type);
 
                /*
index 08dd81b..8622431 100644 (file)
@@ -155,11 +155,20 @@ void __connman_timeserver_sync_next()
                                                NULL);
 }
 
-int __connman_timeserver_sync(struct connman_service *service)
+int __connman_timeserver_sync(struct connman_service *default_service)
 {
-       char **nameservers = NULL;
+       struct connman_service *service;
+       char **nameservers;
        int i;
 
+       if (default_service != NULL)
+               service = default_service;
+       else
+               service = __connman_service_get_default();
+
+       if (service == NULL)
+               return -EINVAL;
+
        DBG("service %p", service);
 
        i = __connman_service_get_index(service);
@@ -242,14 +251,33 @@ char **__connman_timeserver_system_get()
        return servers;
 }
 
+static void default_changed(struct connman_service *default_service)
+{
+       DBG("");
+
+       if (default_service != NULL)
+               __connman_timeserver_sync(default_service);
+       else
+               __connman_timeserver_stop();
+}
+
+static struct connman_notifier timeserver_notifier = {
+       .name                   = "timeserver",
+       .default_changed        = default_changed,
+};
+
 int __connman_timeserver_init(void)
 {
        DBG("");
 
+       connman_notifier_register(&timeserver_notifier);
+
        return 0;
 }
 
 void __connman_timeserver_cleanup(void)
 {
        DBG("");
+
+       connman_notifier_unregister(&timeserver_notifier);
 }