technology: return already enabled when tethering is enabled
[framework/connectivity/connman.git] / src / ntp.c
index f70dfc7..91a8832 100644 (file)
--- a/src/ntp.c
+++ b/src/ntp.c
@@ -2,7 +2,7 @@
  *
  *  Connection Manager
  *
- *  Copyright (C) 2007-2010  Intel Corporation. All rights reserved.
+ *  Copyright (C) 2007-2012  Intel Corporation. All rights reserved.
  *
  *  This program is free software; you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License version 2 as
@@ -75,6 +75,7 @@ static int transmit_fd = 0;
 
 static char *timeserver = NULL;
 static gint poll_id = 0;
+static gint timeout_id = 0;
 
 static void send_packet(int fd, const char *server)
 {
@@ -109,6 +110,18 @@ static void send_packet(int fd, const char *server)
        }
 }
 
+static gboolean next_server(gpointer user_data)
+{
+       if (timeserver != NULL) {
+               g_free(timeserver);
+               timeserver = NULL;
+       }
+
+       __connman_timeserver_sync_next();
+
+       return FALSE;
+}
+
 static gboolean next_poll(gpointer user_data)
 {
        if (timeserver == NULL || transmit_fd == 0)
@@ -168,7 +181,11 @@ static void decode_msg(void *base, size_t len, struct timeval *tv)
 
        DBG("offset=%f delay=%f", offset, delay);
 
-       /* Timeserver has responded.
+       /* Remove the timeout, as timeserver has responded */
+       if (timeout_id > 0)
+               g_source_remove(timeout_id);
+
+       /*
         * Now poll the server every transmit_delay seconds
         * for time correction.
         */
@@ -179,6 +196,8 @@ static void decode_msg(void *base, size_t len, struct timeval *tv)
 
        poll_id = g_timeout_add_seconds(transmit_delay, next_poll, NULL);
 
+       connman_info("ntp: time slew %+.6f s", offset);
+
        if (offset < STEPTIME_MIN_OFFSET && offset > -STEPTIME_MIN_OFFSET) {
                struct timeval adj;
 
@@ -329,7 +348,7 @@ send:
 
 int __connman_ntp_start(char *server)
 {
-       DBG("");
+       DBG("%s", server);
 
        if (server == NULL)
                return -EINVAL;
@@ -341,6 +360,13 @@ int __connman_ntp_start(char *server)
 
        start_ntp(timeserver);
 
+       /*
+        * Add a fallback timeout , preferably short, 5 sec here,
+        * to fallback on the next server.
+        */
+
+       timeout_id = g_timeout_add_seconds(5, next_server, NULL);
+
        return 0;
 }
 
@@ -351,6 +377,9 @@ void __connman_ntp_stop()
        if (poll_id > 0)
                g_source_remove(poll_id);
 
+       if (timeout_id > 0)
+               g_source_remove(timeout_id);
+
        if (channel_watch > 0) {
                g_source_remove(channel_watch);
                channel_watch = 0;