From cd9de0baf95ec5e2eaa75cbb2b62bec85ad9a4d7 Mon Sep 17 00:00:00 2001 From: junkyu han Date: Thu, 31 May 2018 20:45:20 +0900 Subject: [PATCH] Check NTP time and wait for connection until time is set Change-Id: I4b6ff92c4e458ccbd28a72102963ac6ed55a7b7f --- daemon/CMakeLists.txt | 1 + daemon/src/tizen-things-daemon.c | 25 +++++++++++++++++++++++-- packaging/tizen-things-daemon.spec | 1 + 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/daemon/CMakeLists.txt b/daemon/CMakeLists.txt index f20bd44..e0fe4fc 100644 --- a/daemon/CMakeLists.txt +++ b/daemon/CMakeLists.txt @@ -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}) diff --git a/daemon/src/tizen-things-daemon.c b/daemon/src/tizen-things-daemon.c index e511760..08e6109 100644 --- a/daemon/src/tizen-things-daemon.c +++ b/daemon/src/tizen-things-daemon.c @@ -18,6 +18,7 @@ #include #include #include +#include #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); diff --git a/packaging/tizen-things-daemon.spec b/packaging/tizen-things-daemon.spec index cfc9709..0ddb682 100644 --- a/packaging/tizen-things-daemon.spec +++ b/packaging/tizen-things-daemon.spec @@ -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 -- 2.7.4