Check NTP time and wait for connection until time is set 44/180644/1
authorjunkyu han <junkyu.han@samsung.com>
Thu, 31 May 2018 11:45:20 +0000 (20:45 +0900)
committerjunkyu han <junkyu.han@samsung.com>
Thu, 31 May 2018 11:45:20 +0000 (20:45 +0900)
Change-Id: I4b6ff92c4e458ccbd28a72102963ac6ed55a7b7f

daemon/CMakeLists.txt
daemon/src/tizen-things-daemon.c
packaging/tizen-things-daemon.spec

index f20bd44..e0fe4fc 100644 (file)
@@ -13,6 +13,7 @@ pkg_check_modules(DAEMON_PKGS REQUIRED
        gio-unix-2.0
        openssl
        capi-appfw-app-control
+       vconf
 )
 
 FOREACH (flag ${DAEMON_PKGS_CFLAGS})
index e511760..08e6109 100644 (file)
@@ -18,6 +18,7 @@
 #include <stdlib.h>
 #include <glib.h>
 #include <glib-unix.h>
+#include <vconf.h>
 
 #include "ttd-log.h"
 #include "ttd-cloud-conn-state.h"
@@ -42,6 +43,7 @@ typedef struct __ttd_data {
        GMainLoop *mainloop;
        GThreadPool *thread_pool;
        worker_interface_h worker_itf_h;
+       bool is_time_set;
 } ttd_data;
 
 static gboolean __daemon_job_handler(gpointer data);
@@ -132,6 +134,7 @@ static ttd_task_func __get_task_func(ttd_cmd_data *cmd)
 
        return func;
 }
+
 static gboolean __daemon_job_handler(gpointer data)
 {
        ttd_data *d_data = data;
@@ -250,6 +253,22 @@ static gboolean __do_device_register(gpointer data)
        return FALSE;
 }
 
+static void __time_changed(keynode_t *node, void *data)
+{
+       ttd_data *d_data = data;
+       long long current_time;
+       _D("System time is changed");
+
+       current_time = common_get_epoch_time();
+
+       if ((current_time * 1000000) > EPOCH_TIME_REF && !d_data->is_time_set) {
+               /* Do something need correct time after here */
+               _D("We assume that system time is correct, because current[%lld] is bigger than 2018-05-17", current_time * 1000000);
+               d_data->is_time_set = true;
+               g_idle_add(__do_device_register, d_data);
+       }
+}
+
 int main(int argc, char* argv[])
 {
        ttd_data *d_data = NULL;
@@ -267,6 +286,10 @@ int main(int argc, char* argv[])
        g_unix_signal_add(SIGINT, _handle_sigint, d_data);
        g_unix_signal_add(SIGTERM, _handle_sigterm, d_data);
 
+       if (vconf_notify_key_changed(VCONFKEY_SYSTEM_TIME_CHANGED, __time_changed, d_data) < 0) {
+               _E("Failed to set vconf key changed");
+       }
+
        ttd_queue_init();
        ttd_conn_mgr_init();
        ttd_http_init();
@@ -282,8 +305,6 @@ int main(int argc, char* argv[])
 
        _D("[delay] start-to-ready - %.3lf(ms)",
                (double)(_get_monotonic_time() - start)/1000);
-       g_idle_add(__do_device_register, d_data);
-
        g_main_loop_run(d_data->mainloop);
 
        g_main_loop_unref(d_data->mainloop);
index cfc9709..0ddb682 100644 (file)
@@ -20,6 +20,7 @@ BuildRequires:  pkgconfig(libtzplatform-config)
 BuildRequires:  pkgconfig(openssl)
 BuildRequires:  pkgconfig(capi-appfw-app-control)
 BuildRequires:  pkgconfig(capi-appfw-app-common)
+BuildRequires:  pkgconfig(vconf)
 
 %description
 Tizen Things daemon