Package version up to 2.7.0
[platform/core/uifw/libtdm.git] / src / tdm_config.c
index 703ae0a..95f5119 100644 (file)
@@ -9,7 +9,7 @@
  *          Taeheon Kim <th908.kim@samsung.com>,
  *          YoungJun Cho <yj44.cho@samsung.com>,
  *          SooChan Lim <sc1.lim@samsung.com>,
- *          Boram Park <sc1.lim@samsung.com>
+ *          Boram Park <boram1288.park@samsung.com>
  *
  * Permission is hereby granted, free of charge, to any person obtaining a
  * copy of this software and associated documentation files (the
@@ -51,6 +51,7 @@
 
 static pthread_mutex_t g_dic_lock = PTHREAD_MUTEX_INITIALIZER;
 static dictionary *g_dic = NULL;
+static int init_dic = 0;
 
 static int
 _tdm_config_check_file_owner(const char *filepath)
@@ -103,10 +104,24 @@ _tdm_config_check_logs(void)
 
        pthread_mutex_unlock(&g_dic_lock);
 
-       level = tdm_config_get_int(TDM_CONFIG_KEY_DEBUG_LOG_LEVEL, 3);
+       level = tdm_config_get_int(TDM_CONFIG_KEY_DEBUG_LOG_LEVEL, -1);
+       if (level == -1) {
+               const char *str = getenv("TDM_DEBUG_LEVEL");
+               if (str)
+                       level = str[0] - '0';
+               else
+                       level = 3;
+       }
        tdm_log_set_debug_level(level);
 
-       level = tdm_config_get_int(TDM_CONFIG_KEY_DEBUG_ASSERT_LEVEL, 0);
+       level = tdm_config_get_int(TDM_CONFIG_KEY_DEBUG_ASSERT_LEVEL, -1);
+       if (level == -1) {
+               const char *str = getenv("TDM_ASSERT_LEVEL");
+               if (str)
+                       level = str[0] - '0';
+               else
+                       level = 0;
+       }
        tdm_log_set_assert_level(level);
 
        /* if TDM_CONFIG_KEY_DEBUG_LOG_PATH is setted, TDM_CONFIG_KEY_DEBUG_DLOG will be ignored. */
@@ -115,26 +130,33 @@ _tdm_config_check_logs(void)
                tdm_log_enable_dlog(0);
                tdm_log_set_path(path);
        } else {
-               int dlog = tdm_config_get_int(TDM_CONFIG_KEY_DEBUG_DLOG, 1);
+               int dlog = tdm_config_get_int(TDM_CONFIG_KEY_DEBUG_DLOG, -1);
+               if (dlog == -1) {
+                       const char *str = getenv("TDM_DLOG");
+                       if (str)
+                               dlog = (str[0] == '1') ? 1 : 0;
+                       else
+                               dlog = 1;
+               }
                tdm_log_enable_dlog(dlog);
        }
 
        pthread_mutex_lock(&g_dic_lock);
 }
 
-static unsigned int
+static void
 _tdm_config_check_init(void)
 {
-       if (g_dic)
-               return 1;
+       if (init_dic)
+               return;
+
+       init_dic = 1;
 
        g_dic = _tdm_config_load_file(TDM_DATA_PATH, TDM_CONFIG_FILENAME);
 
        _tdm_config_check_logs();
 
        TDM_INFO("tdm config init %s (%p)", (g_dic) ? "successed" : "failed", g_dic);
-
-       return (g_dic) ? 1 : 0;
 }
 
 INTERN void
@@ -149,6 +171,7 @@ tdm_config_deinit(void)
 
        iniparser_freedict(g_dic);
        g_dic = NULL;
+       init_dic = 0;
 
        TDM_INFO("tdm config deinit done");
 
@@ -190,7 +213,8 @@ tdm_config_get_int(const char *key, int default_value)
 
        pthread_mutex_lock(&g_dic_lock);
 
-       if (!_tdm_config_check_init()) {
+       _tdm_config_check_init();
+       if (!g_dic) {
                TDM_INFO("%s = %d: default", key, default_value);
                pthread_mutex_unlock(&g_dic_lock);
                return default_value;
@@ -220,7 +244,8 @@ tdm_config_get_string(const char *key, const char *default_value)
 
        pthread_mutex_lock(&g_dic_lock);
 
-       if (!_tdm_config_check_init()) {
+       _tdm_config_check_init();
+       if (!g_dic) {
                TDM_INFO("%s = %s: default", key, default_value);
                pthread_mutex_unlock(&g_dic_lock);
                return default_value;
@@ -246,7 +271,8 @@ tdm_config_set_int(const char *key, int value)
 
        pthread_mutex_lock(&g_dic_lock);
 
-       if (!_tdm_config_check_init()) {
+       _tdm_config_check_init();
+       if (!g_dic) {
                TDM_INFO("%s = %d set failed", key, value);
                pthread_mutex_unlock(&g_dic_lock);
                return TDM_ERROR_BAD_REQUEST;
@@ -272,7 +298,8 @@ tdm_config_set_string(const char *key, const char *value)
 
        pthread_mutex_lock(&g_dic_lock);
 
-       if (!_tdm_config_check_init()) {
+       _tdm_config_check_init();
+       if (!g_dic) {
                TDM_INFO("%s = %s set failed", key, value);
                pthread_mutex_unlock(&g_dic_lock);
                return TDM_ERROR_BAD_REQUEST;