Unify the order of log to store value 81/289381/2
authorSuyeon Hwang <stom.hwang@samsung.com>
Thu, 23 Feb 2023 02:07:42 +0000 (11:07 +0900)
committerSuyeon Hwang <stom.hwang@samsung.com>
Tue, 7 Mar 2023 02:31:26 +0000 (11:31 +0900)
- Issue:
Each functions have different order of logic for storing value.

- Solution:
In previous code, some functions first stored file and then changed the
memory. However, some other functions did the reverse of it. So, this
patch unifies the order of logic for storing values in each functions.
Through this patch, all functions will store the file first and then
update the config struture on the memory.

Change-Id: Id8e4671bc342060c7c779578e7b3e75ea0dd640a
Signed-off-by: Suyeon Hwang <stom.hwang@samsung.com>
common/tts_config_mgr.c

index a61f13a..bbd1570 100644 (file)
@@ -87,7 +87,7 @@ int __tts_config_mgr_print_engine_info();
 static int __tts_config_mgr_register_engine_config_updated_event(const char* path);
 static int __tts_config_mgr_unregister_engine_config_updated_event();
 
-static char* __get_default_engine_app_id()
+static char* get_default_engine_app_id()
 {
        char* engine_name = vconf_get_str(TTS_ENGINE_DB_DEFAULT);
        if (NULL == engine_name) {
@@ -194,7 +194,7 @@ int __tts_config_mgr_check_engine_is_valid(const char* engine_id)
        }
 
        /* Change default engine */
-       char* default_engine = __get_default_engine_app_id();
+       char* default_engine = get_default_engine_app_id();
        tts_engine_info_s *engine_info = __get_engine_info(default_engine);
        free(default_engine);
 
@@ -266,11 +266,6 @@ int __tts_config_mgr_check_engine_is_valid(const char* engine_id)
                SLOG(LOG_DEBUG, TAG_TTSCONFIG, "Default voice is changed : lang(%s) type(%d)", voice->language, voice->type);
        }
 
-       if (0 != tts_parser_set_config_info(&config_info)){
-               SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to set configure information");
-               return TTS_CONFIG_ERROR_OPERATION_FAILED;
-       }
-
        if (__is_client_type(TTS_CONFIG_CLIENT_TYPE_SETTING | TTS_CONFIG_CLIENT_TYPE_SERVER | TTS_CONFIG_CLIENT_TYPE_INTERRUPT)) {
                if (0 != tts_parser_set_engine(config_info.engine_id, config_info.setting, config_info.language, config_info.type)) {
                        SLOG(LOG_ERROR, TAG_TTSCONFIG, " Fail to save config");
@@ -280,6 +275,10 @@ int __tts_config_mgr_check_engine_is_valid(const char* engine_id)
                SLOG(LOG_INFO, TAG_TTSCONFIG, "Client type is default. Skip saving configuration file.");
        }
 
+       if (0 != tts_parser_set_config_info(&config_info)){
+               SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to set configure information");
+               return TTS_CONFIG_ERROR_OPERATION_FAILED;
+       }
 
        return TTS_CONFIG_ERROR_NONE;
 }
@@ -710,23 +709,25 @@ void __tts_config_display_language_changed_cb(keynode_t *key, void *data)
                SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to get configure information");
                return;
        }
-       if (true == config_info.auto_voice) {
-               __tts_config_set_auto_language();
 
-               if (__is_client_type(TTS_CONFIG_CLIENT_TYPE_SERVER)) {
-                       if (0 != tts_parser_get_config_info(&config_info)){
-                               SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to get configure information");
-                               return;
-                       }
+       if (false == config_info.auto_voice) {
+               SLOG(LOG_DEBUG, TAG_TTSCONFIG, "[DEBUG] Auto voice selection is disabled. Skip updating language.");
+               return;
+       }
 
-                       if (0 != tts_parser_set_voice(config_info.language, config_info.type)) {
-                               SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to save config");
-                               return;
-                       }
+       __tts_config_set_auto_language();
+
+       if (__is_client_type(TTS_CONFIG_CLIENT_TYPE_SERVER)) {
+               if (0 != tts_parser_get_config_info(&config_info)){
+                       SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to get configure information");
+                       return;
                }
-       }
 
-       return;
+               if (0 != tts_parser_set_voice(config_info.language, config_info.type)) {
+                       SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to save config");
+                       return;
+               }
+       }
 }
 
 void __tts_config_screen_reader_changed_cb(keynode_t *key, void *data)
@@ -1229,11 +1230,6 @@ int tts_config_mgr_initialize(unsigned int uid, tts_config_client_type_e client_
                                free(tmp_language);
                                tmp_language = NULL;
 
-                               if (0 != tts_parser_set_config_info(&config_info)) {
-                                       SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to set configure information");
-                                       return TTS_CONFIG_ERROR_OPERATION_FAILED;
-                               }
-
                                if (__is_client_type(TTS_CONFIG_CLIENT_TYPE_SETTING | TTS_CONFIG_CLIENT_TYPE_SERVER | TTS_CONFIG_CLIENT_TYPE_INTERRUPT)) {
                                        if (0 != tts_parser_set_voice(config_info.language, config_info.type)) {
                                                SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to save config");
@@ -1245,6 +1241,11 @@ int tts_config_mgr_initialize(unsigned int uid, tts_config_client_type_e client_
                                } else {
                                        SLOG(LOG_INFO, TAG_TTSCONFIG, "Client type is default. Skip saving configuration file.");
                                }
+
+                               if (0 != tts_parser_set_config_info(&config_info)) {
+                                       SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to set configure information");
+                                       return TTS_CONFIG_ERROR_OPERATION_FAILED;
+                               }
                        }
                }
        }
@@ -1531,8 +1532,10 @@ int tts_config_mgr_set_engine(const char* engine)
                return ret;
        }
 
-       if (NULL == engine)
+       if (NULL == engine) {
+               SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Parameter is null.");
                return TTS_CONFIG_ERROR_INVALID_PARAMETER;
+       }
 
        tts_config_s config_info;
        if (0 != tts_parser_get_config_info(&config_info)){
@@ -1540,9 +1543,10 @@ int tts_config_mgr_set_engine(const char* engine)
                return TTS_CONFIG_ERROR_OPERATION_FAILED;
        }
 
-       /* Check current engine id with new engine id */
-       if (0 == strcmp(config_info.engine_id, engine))
+       if (0 == strcmp(config_info.engine_id, engine)) {
+               SLOG(LOG_DEBUG, TAG_TTSCONFIG, "Engine id(%s) is not changed. Skip setting", engine);
                return TTS_CONFIG_ERROR_NONE;
+       }
 
        SLOG(LOG_DEBUG, TAG_TTSCONFIG, "New engine id : %s", engine);
 
@@ -1552,69 +1556,49 @@ int tts_config_mgr_set_engine(const char* engine)
                return ret;
        }
 
-       bool is_valid_engine = false;
        tts_engine_info_s *engine_info = __get_engine_info(engine);
-       if (NULL != engine_info) {
-               memset(g_engine_id, '\0', sizeof(g_engine_id));
-               config_info.engine_id = g_engine_id;
-               strncpy(config_info.engine_id, engine, sizeof(g_engine_id) - 1);
-
-               if (NULL != engine_info->setting) {
-                       memset(g_setting, '\0', sizeof(g_setting));
-                       config_info.setting = g_setting;
-                       strncpy(config_info.setting, engine_info->setting, sizeof(g_setting) - 1);
-               }
-
-               /* Engine is valid*/
-               bool is_valid_voice = false;
-               tts_config_voice_s* voice = __get_voice_info(engine_info, config_info.language, config_info.type);
-               if (NULL != voice) {
-                       /* language is valid */
-                       is_valid_voice = true;
-                       config_info.type = voice->type;
-               }
-
-               if (false == is_valid_voice) {
-                       __set_language_into_config(&config_info, NULL);
-
-                       GSList *iter_voice = g_slist_nth(engine_info->voices, 0);
-                       if (NULL != iter_voice) {
-                               voice = iter_voice->data;
-                               if (NULL != voice) {
-                                       if (NULL != voice->language)
-                                               strncpy(config_info.language, voice->language, sizeof(g_language) - 1);
+       if (NULL == engine_info) {
+               SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Engine id(%s) is not valid", engine);
+               return TTS_CONFIG_ERROR_OPERATION_FAILED;
+       }
 
-                                       config_info.type = voice->type;
-                               }
-                       }
-               }
+       memset(g_engine_id, '\0', sizeof(g_engine_id));
+       config_info.engine_id = g_engine_id;
+       strncpy(config_info.engine_id, engine, sizeof(g_engine_id) - 1);
 
-               is_valid_engine = true;
+       if (NULL != engine_info->setting) {
+               memset(g_setting, '\0', sizeof(g_setting));
+               config_info.setting = g_setting;
+               strncpy(config_info.setting, engine_info->setting, sizeof(g_setting) - 1);
        }
 
-       if (0 != tts_parser_set_config_info(&config_info)) {
-               SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to set configure information");
-               return TTS_CONFIG_ERROR_OPERATION_FAILED;
+       tts_config_voice_s* voice = __get_voice_info(engine_info, config_info.language, config_info.type);
+       if (NULL == voice) {
+               tts_config_voice_s *new_voice = (tts_config_voice_s *)g_slist_nth_data(engine_info->voices, 0);
+               if (NULL != new_voice) {
+                       __set_language_into_config(&config_info, new_voice->language);
+                       config_info.type = new_voice->type;
+               }
        }
 
-       if (true == is_valid_engine) {
-               SLOG(LOG_DEBUG, TAG_TTSCONFIG, "[Config] Engine changed");
-               SECURE_SLOG(LOG_DEBUG, TAG_TTSCONFIG, "  Engine : %s", config_info.engine_id);
-               SECURE_SLOG(LOG_DEBUG, TAG_TTSCONFIG, "  Setting : %s", config_info.setting);
-               SECURE_SLOG(LOG_DEBUG, TAG_TTSCONFIG, "  Language : %s", config_info.language);
-               SECURE_SLOG(LOG_DEBUG, TAG_TTSCONFIG, "  Type : %d", config_info.type);
+       SLOG(LOG_DEBUG, TAG_TTSCONFIG, "[Config] Engine changed");
+       SECURE_SLOG(LOG_DEBUG, TAG_TTSCONFIG, "  Engine : %s", config_info.engine_id);
+       SECURE_SLOG(LOG_DEBUG, TAG_TTSCONFIG, "  Setting : %s", config_info.setting);
+       SECURE_SLOG(LOG_DEBUG, TAG_TTSCONFIG, "  Language : %s", config_info.language);
+       SECURE_SLOG(LOG_DEBUG, TAG_TTSCONFIG, "  Type : %d", config_info.type);
 
-               if (__is_client_type(TTS_CONFIG_CLIENT_TYPE_SETTING | TTS_CONFIG_CLIENT_TYPE_SERVER | TTS_CONFIG_CLIENT_TYPE_INTERRUPT)) {
-                       if (0 != tts_parser_set_engine(config_info.engine_id, config_info.setting,
+       if (__is_client_type(TTS_CONFIG_CLIENT_TYPE_SETTING | TTS_CONFIG_CLIENT_TYPE_SERVER | TTS_CONFIG_CLIENT_TYPE_INTERRUPT)) {
+               if (0 != tts_parser_set_engine(config_info.engine_id, config_info.setting,
                                config_info.language, config_info.type)) {
-                                       SLOG(LOG_ERROR, TAG_TTSCONFIG, " Fail to save config");
-                                       return TTS_CONFIG_ERROR_OPERATION_FAILED;
-                       }
-               } else {
-                       SLOG(LOG_INFO, TAG_TTSCONFIG, "Client type is default. Skip saving configuration file.");
+                       SLOG(LOG_ERROR, TAG_TTSCONFIG, " Fail to save config");
+                       return TTS_CONFIG_ERROR_OPERATION_FAILED;
                }
        } else {
-               SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Engine id is not valid");
+               SLOG(LOG_INFO, TAG_TTSCONFIG, "Client type is default. Skip saving configuration file.");
+       }
+
+       if (0 != tts_parser_set_config_info(&config_info)) {
+               SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to set configure information");
                return TTS_CONFIG_ERROR_OPERATION_FAILED;
        }
 
@@ -1705,6 +1689,26 @@ int tts_config_mgr_set_voice(const char* language, int type)
                return TTS_CONFIG_ERROR_OPERATION_FAILED;
        }
 
+       if (0 == strcmp(config_info.language, language) && config_info.type == type) {
+               SLOG(LOG_DEBUG, TAG_TTSCONFIG, "Voice(%s/%d) is not changed. Skip setting", language, type);
+               return TTS_CONFIG_ERROR_NONE;
+       }
+
+       char* default_engine = get_default_engine_app_id();
+       tts_engine_info_s *engine_info = __get_engine_info(default_engine);
+       if (NULL == engine_info) {
+               SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Current engine(%s) is not valid", default_engine);
+               free(default_engine);
+               return TTS_CONFIG_ERROR_OPERATION_FAILED;
+       }
+       free(default_engine);
+
+       tts_config_voice_s *voice = __get_voice_info(engine_info, language, type);
+       if (NULL != voice) {
+               SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Voice(%s/%d) is not valid in current engine", language, type);
+               return TTS_CONFIG_ERROR_OPERATION_FAILED;
+       }
+
        /* Check language is valid */
        if (__is_client_type(TTS_CONFIG_CLIENT_TYPE_SETTING | TTS_CONFIG_CLIENT_TYPE_SERVER | TTS_CONFIG_CLIENT_TYPE_INTERRUPT)) {
                if (0 != tts_parser_set_voice(language, type)) {
@@ -1760,34 +1764,36 @@ int tts_config_mgr_set_auto_voice(bool value)
                return TTS_CONFIG_ERROR_OPERATION_FAILED;
        }
 
-       if (config_info.auto_voice != value) {
-               /* Check language is valid */
-               if (__is_client_type(TTS_CONFIG_CLIENT_TYPE_SETTING | TTS_CONFIG_CLIENT_TYPE_SERVER | TTS_CONFIG_CLIENT_TYPE_INTERRUPT)) {
-                       if (0 != tts_parser_set_auto_voice(value)) {
-                               SLOG(LOG_ERROR, TAG_TTSCONFIG, "Fail to save auto voice option");
-                               return TTS_CONFIG_ERROR_OPERATION_FAILED;
-                       }
-               } else {
-                       SLOG(LOG_INFO, TAG_TTSCONFIG, "Client type is default. Skip saving configuration file.");
-               }
+       if (config_info.auto_voice == value) {
+               SLOG(LOG_DEBUG, TAG_TTSCONFIG, "Auto voice option(%s) is not changed. Skip setting", (value ? "True" : "False"));
+               return TTS_CONFIG_ERROR_NONE;
+       }
 
-               config_info.auto_voice = value;
-               if (0 != tts_parser_set_config_info(&config_info)) {
-                       SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to set configure information");
+       if (__is_client_type(TTS_CONFIG_CLIENT_TYPE_SETTING | TTS_CONFIG_CLIENT_TYPE_SERVER | TTS_CONFIG_CLIENT_TYPE_INTERRUPT)) {
+               if (0 != tts_parser_set_auto_voice(value)) {
+                       SLOG(LOG_ERROR, TAG_TTSCONFIG, "Fail to save auto voice option");
                        return TTS_CONFIG_ERROR_OPERATION_FAILED;
                }
+       } else {
+               SLOG(LOG_INFO, TAG_TTSCONFIG, "Client type is default. Skip saving configuration file.");
+       }
 
-               if (true == config_info.auto_voice) {
-                       __tts_config_set_auto_language();
+       config_info.auto_voice = value;
+       if (0 != tts_parser_set_config_info(&config_info)) {
+               SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to set configure information");
+               return TTS_CONFIG_ERROR_OPERATION_FAILED;
+       }
 
-                       if (__is_client_type(TTS_CONFIG_CLIENT_TYPE_SETTING | TTS_CONFIG_CLIENT_TYPE_SERVER | TTS_CONFIG_CLIENT_TYPE_INTERRUPT)) {
-                               if (0 != tts_parser_get_config_info(&config_info)){
-                                       SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to get configure information");
-                               }
+       if (true == config_info.auto_voice) {
+               __tts_config_set_auto_language();
 
-                               if (0 != tts_parser_set_voice(config_info.language, config_info.type)) {
-                                       SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to save config");
-                               }
+               if (__is_client_type(TTS_CONFIG_CLIENT_TYPE_SETTING | TTS_CONFIG_CLIENT_TYPE_SERVER | TTS_CONFIG_CLIENT_TYPE_INTERRUPT)) {
+                       if (0 != tts_parser_get_config_info(&config_info)){
+                               SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to get configure information");
+                       }
+
+                       if (0 != tts_parser_set_voice(config_info.language, config_info.type)) {
+                               SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to save config");
                        }
                }
        }
@@ -1824,29 +1830,36 @@ int tts_config_mgr_set_speech_rate(int value)
                return TTS_CONFIG_ERROR_INVALID_STATE;
        }
 
-       if (TTS_CONFIG_SPEED_MIN <= value && value <= TTS_CONFIG_SPEED_MAX) {
-               SLOG(LOG_DEBUG, TAG_TTSCONFIG, "[Config] Set speech rate : %d", value);
-               if (__is_client_type(TTS_CONFIG_CLIENT_TYPE_SETTING | TTS_CONFIG_CLIENT_TYPE_SERVER | TTS_CONFIG_CLIENT_TYPE_INTERRUPT)) {
-                       if (0 != tts_parser_set_speech_rate(value)) {
-                               SLOG(LOG_ERROR, TAG_TTSCONFIG, "Fail to save speech rate");
-                               return TTS_CONFIG_ERROR_OPERATION_FAILED;
-                       }
-               } else {
-                       SLOG(LOG_INFO, TAG_TTSCONFIG, "Client type is default. Skip saving configuration file.");
-               }
+       if (TTS_CONFIG_SPEED_MIN > value || TTS_CONFIG_SPEED_MAX < value) {
+               SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Speech rate is invalid : %d", value);
+               return TTS_CONFIG_ERROR_INVALID_PARAMETER;
+       }
 
-               tts_config_s config_info;
-               if (0 != tts_parser_get_config_info(&config_info)){
-                       SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to get configure information");
-                       return TTS_CONFIG_ERROR_OPERATION_FAILED;
-               }
-               config_info.speech_rate = value;
-               if (0 != tts_parser_set_config_info(&config_info)){
-                       SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to set configure information");
+       tts_config_s config_info;
+       if (0 != tts_parser_get_config_info(&config_info)){
+               SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to get configure information");
+               return TTS_CONFIG_ERROR_OPERATION_FAILED;
+       }
+
+       if (config_info.speech_rate == value) {
+               SLOG(LOG_DEBUG, TAG_TTSCONFIG, "Speech rate(%d) is not changed. Skip setting", value);
+               return TTS_CONFIG_ERROR_NONE;
+       }
+
+       SLOG(LOG_DEBUG, TAG_TTSCONFIG, "[Config] Set speech rate : %d", value);
+       if (__is_client_type(TTS_CONFIG_CLIENT_TYPE_SETTING | TTS_CONFIG_CLIENT_TYPE_SERVER | TTS_CONFIG_CLIENT_TYPE_INTERRUPT)) {
+               if (0 != tts_parser_set_speech_rate(value)) {
+                       SLOG(LOG_ERROR, TAG_TTSCONFIG, "Fail to save speech rate");
                        return TTS_CONFIG_ERROR_OPERATION_FAILED;
                }
        } else {
-               SLOG(LOG_ERROR, TAG_TTSCONFIG, "[Config ERROR] Speech rate is invalid : %d", value);
+               SLOG(LOG_INFO, TAG_TTSCONFIG, "Client type is default. Skip saving configuration file.");
+       }
+
+       config_info.speech_rate = value;
+       if (0 != tts_parser_set_config_info(&config_info)){
+               SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to set configure information");
+               return TTS_CONFIG_ERROR_OPERATION_FAILED;
        }
 
        return TTS_CONFIG_ERROR_NONE;
@@ -1914,9 +1927,14 @@ int tts_config_mgr_set_pitch(int value)
                return ret;
        }
 
+       if (config_info.pitch == value) {
+               SLOG(LOG_DEBUG, TAG_TTSCONFIG, "Pitch(%d) is not changed. Skip setting", value);
+               return TTS_CONFIG_ERROR_NONE;
+       }
+
        if (__is_client_type(TTS_CONFIG_CLIENT_TYPE_SETTING | TTS_CONFIG_CLIENT_TYPE_SERVER | TTS_CONFIG_CLIENT_TYPE_INTERRUPT)) {
                if (0 != tts_parser_set_pitch(value)) {
-                       SLOG(LOG_ERROR, TAG_TTSCONFIG, "Fail to save speech rate");
+                       SLOG(LOG_ERROR, TAG_TTSCONFIG, "Fail to save pitch");
                        return TTS_CONFIG_ERROR_OPERATION_FAILED;
                }
        } else {
@@ -1924,11 +1942,11 @@ int tts_config_mgr_set_pitch(int value)
        }
 
        config_info.pitch = value;
-
        if (0 != tts_parser_set_config_info(&config_info)){
                SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to set configure information");
                return TTS_CONFIG_ERROR_OPERATION_FAILED;
        }
+
        return TTS_CONFIG_ERROR_NONE;
 }