From: Jeonghoon Park Date: Thu, 14 Jun 2018 06:16:11 +0000 (+0900) Subject: apply config module X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=f33611b0edde5ba79c9fbf483ffb0cd2927262e8;p=apps%2Fnative%2Ftizen-things-daemon.git apply config module Change-Id: Icde3286598e4cb72565c60b107d012b262c7455d --- diff --git a/daemon/include/ttd-config.h b/daemon/include/ttd-config.h index ed5abab..71f9c28 100644 --- a/daemon/include/ttd-config.h +++ b/daemon/include/ttd-config.h @@ -19,7 +19,6 @@ #include -#define CONFIG_PATH_MAX 1024 #define TTD_SETTING_INFO "setting" #define TTD_SETTING_DISCONNECTED_LIMIT_TIME "network_disconnected_limit" diff --git a/daemon/src/tizen-things-daemon.c b/daemon/src/tizen-things-daemon.c index 880c1c2..6e6dc54 100644 --- a/daemon/src/tizen-things-daemon.c +++ b/daemon/src/tizen-things-daemon.c @@ -181,6 +181,7 @@ int main(int argc, char* argv[]) d_data = calloc(1, sizeof(ttd_data)); ttd_log_init(TTD_LOG_TYPE_ALL); + ttd_config_init(); d_data->mainloop = g_main_loop_new(NULL, FALSE); @@ -190,8 +191,9 @@ int main(int argc, char* argv[]) vconf_notify_key_changed(VCONFKEY_SYSTEM_TIME_CHANGED, __system_time_changed, d_data); - ttd_conn_mgr_init(); ttd_http_init(); + ttd_conn_mgr_init(); + ttd_cloud_conn_state_set(TTD_CLOUD_CONN_STATE_DISCONNECTED); ttd_worker_interface_init(&(d_data->worker_itf_h)); @@ -215,7 +217,7 @@ int main(int argc, char* argv[]) ttd_conn_mgr_fini(); ttd_http_fini(); - + ttd_config_fini(); ttd_log_fini(); return 0; diff --git a/daemon/src/ttd-config.c b/daemon/src/ttd-config.c index 699c7cf..0ba9dc3 100644 --- a/daemon/src/ttd-config.c +++ b/daemon/src/ttd-config.c @@ -26,22 +26,20 @@ #define CONF_FILE_NAME "ttd.conf" #define CONF_PATH tzplatform_mkpath3(TZ_SYS_ETC, "ttd", "ttd.conf") -GKeyFile *gkf = NULL; -int is_initialized = 0; +static GKeyFile *gkf = NULL; int ttd_config_init(void) { - gkf = g_key_file_new(); - retv_if(!gkf, -1); + GKeyFile *tmp_gkf = NULL; + tmp_gkf = g_key_file_new(); + retv_if(!tmp_gkf, -1); - if (!g_key_file_load_from_file(gkf, CONF_PATH, G_KEY_FILE_NONE, NULL)) { + if (!g_key_file_load_from_file(tmp_gkf, CONF_PATH, G_KEY_FILE_NONE, NULL)) { _E("Failed to load conf file"); - ttd_config_fini(); + g_key_file_free(tmp_gkf); return -1; } - - is_initialized = 1; - + gkf = tmp_gkf; return 0; } @@ -49,6 +47,8 @@ void ttd_config_fini(void) { if (gkf) g_key_file_free(gkf); + + gkf = NULL; } int ttd_config_read_integer(const char *group, const char *key, int *value) @@ -58,8 +58,9 @@ int ttd_config_read_integer(const char *group, const char *key, int *value) retv_if(!group, -1); retv_if(!key, -1); + retv_if(!value, -1); - if (!is_initialized) { + if (!gkf) { if (ttd_config_init() < 0) { _E("Failed to initialize configure"); return -1; @@ -85,8 +86,9 @@ int ttd_config_read_boolean(const char *group, const char *key, bool *value) retv_if(!group, -1); retv_if(!key, -1); + retv_if(!value, -1); - if (!is_initialized) { + if (!gkf) { if (ttd_config_init() < 0) { _E("Failed to initialize configure"); return -1; @@ -112,8 +114,9 @@ int ttd_config_read_string(const char *group, const char *key, char **value) retv_if(!group, -1); retv_if(!key, -1); + retv_if(!value, -1); - if (!is_initialized) { + if (!gkf) { if (ttd_config_init() < 0) { _E("Failed to initialize configure"); return -1; @@ -136,9 +139,8 @@ int ttd_config_write_integer(const char *group, const char *key, int value) { retv_if(!group, -1); retv_if(!key, -1); - retv_if(!value, -1); - if (!is_initialized) { + if (!gkf) { if (ttd_config_init() < 0) { _E("Failed to initialize configure"); return -1; @@ -154,9 +156,8 @@ int ttd_config_write_boolean(const char *group, const char *key, bool value) { retv_if(!group, -1); retv_if(!key, -1); - retv_if(!value, -1); - if (!is_initialized) { + if (!gkf) { if (ttd_config_init() < 0) { _E("Failed to initialize configure"); return -1; @@ -174,7 +175,7 @@ int ttd_config_write_string(const char *group, const char *key, const char *valu retv_if(!key, -1); retv_if(!value, -1); - if (!is_initialized) { + if (!gkf) { if (ttd_config_init() < 0) { _E("Failed to initialize configure"); return -1; @@ -193,7 +194,7 @@ int ttd_config_remove_group(const char *group) retv_if(!group, -1); - if (!is_initialized) { + if (!gkf) { if (ttd_config_init() < 0) { _E("Failed to initialize configure"); return -1; @@ -215,9 +216,10 @@ int ttd_config_remove_key(const char *group, const char *key) gboolean ret = FALSE; GError *error = NULL; + retv_if(!group, -1); retv_if(!key, -1); - if (!is_initialized) { + if (!gkf) { if (ttd_config_init() < 0) { _E("Failed to initialize configure"); return -1;