timeserver: Do not use element driver API
[framework/connectivity/connman.git] / plugins / ntpd.c
index 2ab3072..d437ecb 100644 (file)
 #include <string.h>
 #include <arpa/inet.h>
 
+#include <gdbus.h>
+
 #define CONNMAN_API_SUBJECT_TO_CHANGE
+#include <connman/types.h>
 #include <connman/plugin.h>
 #include <connman/task.h>
 #include <connman/timeserver.h>
-#include <connman/driver.h>
 #include <connman/log.h>
 
 /*
@@ -45,7 +47,6 @@ static GList *peers = NULL;
 static GList *pending_peers = NULL;
 
 #define NTPD_PORT 123
-#define DEFAULT_NTP_PEER "ntp.meego.com"
 
 struct ntpd_peer {
        char *server;
@@ -103,14 +104,16 @@ static connman_bool_t ntpd_running(void)
                        ret = TRUE;
                else
                        ret = FALSE;
-        }
+        } else
+               ret = FALSE;
 
        close(sock);
 
        return ret;
 }
 
-static void ntpdate_died(struct connman_task *task, void *user_data)
+static void ntpdate_died(struct connman_task *task,
+                               int exit_code, void *user_data)
 {
        struct ntpdate_task *ntpdate = user_data;
 
@@ -159,6 +162,7 @@ static int ntpdate(void)
                goto error_task;
        }
 
+       connman_task_add_argument(ntpdate->task, "-g", NULL);
        connman_task_add_argument(ntpdate->task, "-q", NULL);
 
        /* The servers are added through a temp configuration file */
@@ -174,9 +178,6 @@ static int ntpdate(void)
 
        DBG("conf path %s", ntpdate->conf_path);
 
-       if (pending_peers == NULL && peers == NULL)
-               ntpdate_add_peer(ntpdate, DEFAULT_NTP_PEER);
-
        for (list = pending_peers; list; list = list->next) {
                peer = list->data;
 
@@ -216,6 +217,10 @@ static void ntpd_sync(void)
 
        DBG("");
 
+       if (g_list_length(pending_peers) == 0 &&
+                       g_list_length(peers) == 0)
+               return;
+
        if (!ntpd_running()) {
                ntpdate();
                return;
@@ -300,7 +305,7 @@ remove:
 
 static struct connman_timeserver_driver ntpd_driver = {
        .name           = "ntpd",
-       .priority       = CONNMAN_DRIVER_PRIORITY_DEFAULT,
+       .priority       = CONNMAN_TIMESERVER_PRIORITY_DEFAULT,
        .append         = ntpd_append,
        .remove         = ntpd_remove,
        .sync           = ntpd_sync,