read tts-config.xml when set api called 87/316687/10
authordyamy-lee <dyamy.lee@samsung.com>
Tue, 17 Dec 2024 02:11:36 +0000 (11:11 +0900)
committerVBS <sooyeon.kim@samsung.com>
Thu, 26 Dec 2024 05:37:43 +0000 (14:37 +0900)
Change-Id: Id8cd446548beca252834b9b12cdcf531476c01bf

common/tts_config_mgr.c
common/tts_config_parser.c
common/tts_config_parser.h

index c2b79f178e368c24dea97b2af6f339f45338ab90..460ad24d7f8c075d3e7a7e102bce1654770fd1fe 100644 (file)
@@ -751,7 +751,7 @@ static Eina_Bool tts_config_mgr_inotify_event_cb(void* data, Ecore_Fd_Handler *f
                        int before_type = config_info.type;
 
                        set_voice_into_config(&config_info, lang, voice_type);
-                       SLOG(LOG_ERROR, TAG_TTSCONFIG, "[INFO] Voice change(%s, %d)", config_info.language, config_info.type);
+                       SLOG(LOG_ERROR, TAG_TTSCONFIG, "[INFO] Voice change(%s, %d) from (%s, %d)", config_info.language, config_info.type, before_lang, before_type);
 
                        /* Call all callbacks of client*/
                        if (NULL != before_lang) {
@@ -851,14 +851,23 @@ int __tts_config_mgr_unregister_config_event()
 
 static int set_voice_by_automation(int allowed_type_flag)
 {
+       SLOG(LOG_ERROR, TAG_TTSCONFIG, "[INFO] set_voice_by_automation");
+       int fd = tts_parser_open_with_flock();
+       if (fd < 0) {
+               SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to open with flock");
+               return TTS_CONFIG_ERROR_OPERATION_FAILED;
+       }
+
        tts_config_s config_info;
        if (0 != tts_parser_get_config_info(&config_info)){
+               close(fd);
                SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to get configure information");
                return TTS_CONFIG_ERROR_OPERATION_FAILED;
        }
 
        char* display_language = vconf_get_str(TTS_LANGSET_KEY);
        if (NULL == display_language) {
+               close(fd);
                SLOG(LOG_ERROR, TAG_TTSCONFIG, "[Config ERROR] Fail to get display language");
                return TTS_CONFIG_ERROR_OPERATION_FAILED;
        }
@@ -876,11 +885,13 @@ static int set_voice_by_automation(int allowed_type_flag)
                char* tmp_language = NULL;
                int tmp_type = TTS_CONFIG_VOICE_TYPE_NONE;
                if (0 != __tts_config_mgr_select_lang(config_info.engine_id, &tmp_language, &tmp_type)) {
+                       close(fd);
                        SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to select language");
                        return TTS_CONFIG_ERROR_OPERATION_FAILED;
                }
 
                if (NULL == tmp_language) {
+                       close(fd);
                        SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] language is NULL");
                        return TTS_CONFIG_ERROR_OPERATION_FAILED;
                }
@@ -895,16 +906,20 @@ static int set_voice_by_automation(int allowed_type_flag)
        SLOG(LOG_ERROR, TAG_TTSCONFIG, "[Config INFO] Select default voice : lang(%s) type(%d)", selected_language, selected_type);
        if (__is_client_type(allowed_type_flag)) {
                if (0 != tts_parser_set_voice(selected_language, selected_type)) {
+                       close(fd);
                        SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to save config");
                        return TTS_CONFIG_ERROR_OPERATION_FAILED;
                }
 
+               tts_parser_save_with_flock(fd);
                invoke_voice_changed_event(config_info.language, config_info.type, selected_language, selected_type, config_info.auto_voice);
                SLOG(LOG_ERROR, TAG_TTSCONFIG, "[INFO] voice changed event was invoked. language(%s), type(%d), selected language(%s), selected type(%d), auto_voice(%d)", config_info.language, config_info.type, selected_language, selected_type, (int)config_info.auto_voice);
        } else {
                SLOG(LOG_INFO, TAG_TTSCONFIG, "Client is not allowed to save configuration. Skip saving configuration file.");
        }
 
+       close(fd);
+
        set_voice_into_config(&config_info, selected_language, selected_type);
 
        if (0 != tts_parser_set_config_info(&config_info)){
@@ -1290,6 +1305,7 @@ static int __add_new_config_client(unsigned int uid)
 
 int tts_config_mgr_initialize(unsigned int uid, tts_config_client_type_e client_type)
 {
+       SLOG(LOG_ERROR, TAG_TTSCONFIG, "[INFO] tts_config_mgr_initialize");
        /* Register uid */
        if (0 < g_slist_length(g_config_client_list)) {
                /* Check uid */
@@ -1376,15 +1392,18 @@ int tts_config_mgr_initialize(unsigned int uid, tts_config_client_type_e client_
 
        __tts_config_mgr_print_engine_info();
 
-       if (0 != tts_parser_load_config()) {
+       int fd = tts_parser_open_with_flock();
+       if (fd < 0) {
                SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to parse configure information");
                release_config_client(uid);
                __tts_config_release_engine();
                return TTS_CONFIG_ERROR_OPERATION_FAILED;
        }
+
        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");
+               close(fd);
                release_config_client(uid);
                __tts_config_release_engine();
                return TTS_CONFIG_ERROR_OPERATION_FAILED;
@@ -1393,6 +1412,7 @@ int tts_config_mgr_initialize(unsigned int uid, tts_config_client_type_e client_
        /* Check whether engine id is valid */
        if (0 != __tts_config_mgr_check_engine_is_valid(config_info.engine_id)) {
                SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to get default engine");
+               close(fd);
                release_config_client(uid);
                __tts_config_release_engine();
                tts_parser_unload_config();
@@ -1401,6 +1421,8 @@ int tts_config_mgr_initialize(unsigned int uid, tts_config_client_type_e client_
 
        if (true == config_info.auto_voice) {
                /* Check language with display language */
+               close(fd);
+               SLOG(LOG_ERROR, TAG_TTSCONFIG, "[INFO] call set_voice_by_automation");
                set_voice_by_automation(TTS_CONFIG_CLIENT_TYPE_SETTING | TTS_CONFIG_CLIENT_TYPE_SERVER | TTS_CONFIG_CLIENT_TYPE_INTERRUPT);
        } else {
                if (false == __tts_config_mgr_check_lang_is_valid(config_info.engine_id, config_info.language, config_info.type)) {
@@ -1409,6 +1431,7 @@ int tts_config_mgr_initialize(unsigned int uid, tts_config_client_type_e client_
                        int tmp_type = -1;
                        if (0 != __tts_config_mgr_select_lang(config_info.engine_id, &tmp_language, &tmp_type)) {
                                SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to select language");
+                               close(fd);
                                release_config_client(uid);
                                __tts_config_release_engine();
                                tts_parser_unload_config();
@@ -1424,34 +1447,39 @@ int tts_config_mgr_initialize(unsigned int uid, tts_config_client_type_e client_
                                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");
+                                               close(fd);
                                                release_config_client(uid);
                                                __tts_config_release_engine();
                                                tts_parser_unload_config();
                                                return TTS_CONFIG_ERROR_OPERATION_FAILED;
                                        }
+                                       tts_parser_save_with_flock(fd);
                                } 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");
+                                       close(fd);
                                        return TTS_CONFIG_ERROR_OPERATION_FAILED;
                                }
                        }
                }
+               close(fd);
        }
 
+
        /* print daemon config */
-       SLOG(LOG_DEBUG, TAG_TTSCONFIG, "@@@ TTS config @@@");
-       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, " auto voice : %s", config_info.auto_voice ? "on" : "off");
-       SECURE_SLOG(LOG_DEBUG, TAG_TTSCONFIG, " language : %s", config_info.language);
-       SECURE_SLOG(LOG_DEBUG, TAG_TTSCONFIG, " voice type : %d", config_info.type);
-       SECURE_SLOG(LOG_DEBUG, TAG_TTSCONFIG, " speech rate : %d", config_info.speech_rate);
-       SECURE_SLOG(LOG_DEBUG, TAG_TTSCONFIG, " pitch : %d", config_info.pitch);
-       SECURE_SLOG(LOG_DEBUG, TAG_TTSCONFIG, " bg volume ratio : %lf", config_info.bg_volume_ratio);
-       SLOG(LOG_DEBUG, TAG_TTSCONFIG, "@@@@@");
+       SLOG(LOG_ERROR, TAG_TTSCONFIG, "@@@ TTS config @@@");
+       SECURE_SLOG(LOG_ERROR, TAG_TTSCONFIG, " engine : %s", config_info.engine_id);
+       SECURE_SLOG(LOG_ERROR, TAG_TTSCONFIG, " setting : %s", config_info.setting);
+       SECURE_SLOG(LOG_ERROR, TAG_TTSCONFIG, " auto voice : %s", config_info.auto_voice ? "on" : "off");
+       SECURE_SLOG(LOG_ERROR, TAG_TTSCONFIG, " language : %s", config_info.language);
+       SECURE_SLOG(LOG_ERROR, TAG_TTSCONFIG, " voice type : %d", config_info.type);
+       SECURE_SLOG(LOG_ERROR, TAG_TTSCONFIG, " speech rate : %d", config_info.speech_rate);
+       SECURE_SLOG(LOG_ERROR, TAG_TTSCONFIG, " pitch : %d", config_info.pitch);
+       SECURE_SLOG(LOG_ERROR, TAG_TTSCONFIG, " bg volume ratio : %lf", config_info.bg_volume_ratio);
+       SLOG(LOG_ERROR, TAG_TTSCONFIG, "@@@@@");
 
        if (0 != __tts_config_mgr_register_config_event()) {
                SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to register config event");
@@ -1730,27 +1758,38 @@ int tts_config_mgr_set_engine(const char* engine)
                return TTS_CONFIG_ERROR_INVALID_PARAMETER;
        }
 
+       SLOG(LOG_ERROR, TAG_TTSCONFIG, "[INFO] tts_config_mgr_set_engine");
+       int fd = tts_parser_open_with_flock();
+       if (fd < 0) {
+               SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to open with flock");
+               return TTS_CONFIG_ERROR_OPERATION_FAILED;
+       }
+
        tts_config_s config_info;
        if (0 != tts_parser_get_config_info(&config_info)){
+               close(fd);
                SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to get configure information");
                return TTS_CONFIG_ERROR_OPERATION_FAILED;
        }
 
        if (0 == strcmp(config_info.engine_id, engine)) {
-               SLOG(LOG_DEBUG, TAG_TTSCONFIG, "Engine id(%s) is not changed. Skip setting", engine);
+               close(fd);
+               SLOG(LOG_INFO, 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);
+       SLOG(LOG_ERROR, TAG_TTSCONFIG, "[INFO] New engine id : %s", engine);
 
        ret = __tts_set_buxtonkey(engine);
        if (0 != ret) {
-               SLOG(LOG_DEBUG, TAG_TTSCONFIG, "[DEBUG] set_buxtonkey Fail!!");
+               close(fd);
+               SLOG(LOG_ERROR, TAG_TTSCONFIG, "[DEBUG] set_buxtonkey Fail!!");
                return ret;
        }
 
        tts_engine_info_s *engine_info = __get_engine_info(engine);
        if (NULL == engine_info) {
+               close(fd);
                SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Engine id(%s) is not valid", engine);
                return TTS_CONFIG_ERROR_OPERATION_FAILED;
        }
@@ -1773,24 +1812,28 @@ int tts_config_mgr_set_engine(const char* 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_INFO, TAG_TTSCONFIG, "[Config] Engine changed");
+       SECURE_SLOG(LOG_INFO, TAG_TTSCONFIG, "  Engine : %s", config_info.engine_id);
+       SECURE_SLOG(LOG_INFO, TAG_TTSCONFIG, "  Setting : %s", config_info.setting);
+       SECURE_SLOG(LOG_INFO, TAG_TTSCONFIG, "  Language : %s", config_info.language);
+       SECURE_SLOG(LOG_INFO, 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,
                                config_info.language, config_info.type)) {
+                       close(fd);
                        SLOG(LOG_ERROR, TAG_TTSCONFIG, " Fail to save config");
                        return TTS_CONFIG_ERROR_OPERATION_FAILED;
                }
 
+               tts_parser_save_with_flock(fd);
                invoke_engine_changed_event(config_info.engine_id, config_info.setting, config_info.language, config_info.type, config_info.auto_voice, config_info.credential);
        } else {
                SLOG(LOG_INFO, TAG_TTSCONFIG, "Client type is default. Skip saving configuration file.");
        }
 
+       close(fd);
+
        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;
@@ -1877,20 +1920,30 @@ int tts_config_mgr_set_voice(const char* language, int type)
                return TTS_CONFIG_ERROR_INVALID_PARAMETER;
        }
 
+       SLOG(LOG_ERROR, TAG_TTSCONFIG, "[INFO] tts_config_mgr_set_voice");
+       int fd = tts_parser_open_with_flock();
+       if (fd < 0) {
+               SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to open with flock");
+               return TTS_CONFIG_ERROR_OPERATION_FAILED;
+       }
+
        tts_config_s config_info;
        if (0 != tts_parser_get_config_info(&config_info)){
+               close(fd);
                SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to get configure information");
                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);
+               close(fd);
+               SLOG(LOG_INFO, 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) {
+               close(fd);
                SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Current engine(%s) is not valid", default_engine);
                free(default_engine);
                return TTS_CONFIG_ERROR_OPERATION_FAILED;
@@ -1899,23 +1952,28 @@ int tts_config_mgr_set_voice(const char* language, int type)
 
        tts_config_voice_s *voice = __get_voice_info(engine_info, language, type);
        if (NULL == voice) {
+               close(fd);
                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 */
-       SECURE_SLOG(LOG_ERROR, TAG_TTSCONFIG, "[Config INFO] Select default voice : lang(%s) type(%d)", language, type);
+       SECURE_SLOG(LOG_ERROR, TAG_TTSCONFIG, "[Config INFO] Select default voice : lang(%s) type(%d), prev(%s, %d)", language, type, config_info.language, 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_voice(language, type)) {
+                       close(fd);
                        SLOG(LOG_ERROR, TAG_TTSCONFIG, "Fail to save default voice");
                        return TTS_CONFIG_ERROR_OPERATION_FAILED;
                }
 
+               tts_parser_save_with_flock(fd);
                invoke_voice_changed_event(config_info.language, config_info.type, language, type, config_info.auto_voice);
        } else {
                SLOG(LOG_INFO, TAG_TTSCONFIG, "Client type is default. Skip saving configuration file.");
        }
 
+       close(fd);
+
        set_voice_into_config(&config_info, language, type);
 
        if (0 != tts_parser_set_config_info(&config_info)){
@@ -1954,26 +2012,41 @@ int tts_config_mgr_set_auto_voice(bool value)
                return TTS_CONFIG_ERROR_INVALID_STATE;
        }
 
+       SLOG(LOG_ERROR, TAG_TTSCONFIG, "[INFO] tts_config_mgr_set_auto_voice");
+       int fd = tts_parser_open_with_flock();
+       if (fd < 0) {
+               SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to open with flock");
+               return TTS_CONFIG_ERROR_OPERATION_FAILED;
+       }
+
        tts_config_s config_info;
        if (0 != tts_parser_get_config_info(&config_info)){
+               close(fd);
                SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to get configure information");
                return TTS_CONFIG_ERROR_OPERATION_FAILED;
        }
 
        if (config_info.auto_voice == value) {
-               SLOG(LOG_DEBUG, TAG_TTSCONFIG, "Auto voice option(%s) is not changed. Skip setting", (value ? "True" : "False"));
+               close(fd);
+               SLOG(LOG_INFO, TAG_TTSCONFIG, "Auto voice option(%s) is not changed. Skip setting", (value ? "True" : "False"));
                return TTS_CONFIG_ERROR_NONE;
        }
 
+       SECURE_SLOG(LOG_ERROR, TAG_TTSCONFIG, "[Config INFO] set auto voice : %d, prev(%d)", value, config_info.auto_voice);
        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)) {
+                       close(fd);
                        SLOG(LOG_ERROR, TAG_TTSCONFIG, "Fail to save auto voice option");
                        return TTS_CONFIG_ERROR_OPERATION_FAILED;
                }
+
+               tts_parser_save_with_flock(fd);
        } else {
                SLOG(LOG_INFO, TAG_TTSCONFIG, "Client type is default. Skip saving configuration file.");
        }
 
+       close(fd);
+
        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");
@@ -1981,6 +2054,7 @@ int tts_config_mgr_set_auto_voice(bool value)
        }
 
        if (true == config_info.auto_voice) {
+               SLOG(LOG_ERROR, TAG_TTSCONFIG, "[INFO] call set_voice_by_automation");
                set_voice_by_automation(TTS_CONFIG_CLIENT_TYPE_SETTING | TTS_CONFIG_CLIENT_TYPE_SERVER | TTS_CONFIG_CLIENT_TYPE_INTERRUPT);
        }
 
@@ -2021,29 +2095,42 @@ int tts_config_mgr_set_speech_rate(int value)
                return TTS_CONFIG_ERROR_INVALID_PARAMETER;
        }
 
+       SLOG(LOG_ERROR, TAG_TTSCONFIG, "[INFO] tts_config_mgr_set_speech_rate");
+       int fd = tts_parser_open_with_flock();
+       if (fd < 0) {
+               SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to open with flock");
+               return TTS_CONFIG_ERROR_OPERATION_FAILED;
+       }
+
        tts_config_s config_info;
        if (0 != tts_parser_get_config_info(&config_info)){
+               close(fd);
                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);
+               close(fd);
+               SLOG(LOG_INFO, 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);
+       SLOG(LOG_ERROR, TAG_TTSCONFIG, "[Config] Set speech rate : %d, prev(%d)", value, config_info.speech_rate);
        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)) {
+                       close(fd);
                        SLOG(LOG_ERROR, TAG_TTSCONFIG, "Fail to save speech rate");
                        return TTS_CONFIG_ERROR_OPERATION_FAILED;
                }
 
+               tts_parser_save_with_flock(fd);
                invoke_speech_rate_changed_event(value);
        } else {
                SLOG(LOG_INFO, TAG_TTSCONFIG, "Client type is default. Skip saving configuration file.");
        }
 
+       close(fd);
+
        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");
@@ -2104,33 +2191,48 @@ int tts_config_mgr_set_pitch(int value)
                return ret;
        }
 
+       SLOG(LOG_ERROR, TAG_TTSCONFIG, "[INFO] tts_config_mgr_set_pitch");
+       int fd = tts_parser_open_with_flock();
+       if (fd < 0) {
+               SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to open with flock");
+               return TTS_CONFIG_ERROR_OPERATION_FAILED;
+       }
+
        tts_config_s config_info;
        if (0 != tts_parser_get_config_info(&config_info)){
+               close(fd);
                SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to get configure information");
                return TTS_CONFIG_ERROR_OPERATION_FAILED;
        }
 
        ret = __check_engine_support_pitch(config_info.engine_id);
        if (TTS_CONFIG_ERROR_NONE != ret) {
+               close(fd);
                return ret;
        }
 
        if (config_info.pitch == value) {
-               SLOG(LOG_DEBUG, TAG_TTSCONFIG, "Pitch(%d) is not changed. Skip setting", value);
+               close(fd);
+               SLOG(LOG_INFO, TAG_TTSCONFIG, "Pitch(%d) is not changed. Skip setting", value);
                return TTS_CONFIG_ERROR_NONE;
        }
 
+       SLOG(LOG_ERROR, TAG_TTSCONFIG, "[Config] Set pitch : %d, prev(%d)", value, config_info.pitch);
        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)) {
+                       close(fd);
                        SLOG(LOG_ERROR, TAG_TTSCONFIG, "Fail to save pitch");
                        return TTS_CONFIG_ERROR_OPERATION_FAILED;
                }
 
+               tts_parser_save_with_flock(fd);
                invoke_pitch_changed_event(value);
        } else {
                SLOG(LOG_INFO, TAG_TTSCONFIG, "Client type is default. Skip saving configuration file.");
        }
 
+       close(fd);
+
        config_info.pitch = value;
        if (0 != tts_parser_set_config_info(&config_info)){
                SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to set configure information");
@@ -2168,26 +2270,42 @@ int tts_config_mgr_set_bg_volume_ratio(double value)
                return TTS_CONFIG_ERROR_INVALID_STATE;
        }
 
-       SLOG(LOG_DEBUG, TAG_TTSCONFIG, "[Config] Set bg volume ratio : %lf", value);
+       SLOG(LOG_ERROR, TAG_TTSCONFIG, "[INFO] tts_config_mgr_set_bg_volume_ratio");
+       int fd = tts_parser_open_with_flock();
+       if (fd < 0) {
+               SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to open with flock");
+               return TTS_CONFIG_ERROR_OPERATION_FAILED;
+       }
+
+       tts_config_s config_info;
+       if (0 != tts_parser_get_config_info(&config_info)){
+               close(fd);
+               SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to get configure information");
+               return TTS_CONFIG_ERROR_OPERATION_FAILED;
+       }
+
+       SLOG(LOG_ERROR, TAG_TTSCONFIG, "[Config] Set bg volume ratio : %lf, prev(%lf)", value, config_info.bg_volume_ratio);
        if (__is_client_type(TTS_CONFIG_CLIENT_TYPE_SETTING | TTS_CONFIG_CLIENT_TYPE_SERVER | TTS_CONFIG_CLIENT_TYPE_INTERRUPT)) {
                if (0 != tts_parser_set_bg_volume_ratio(value)) {
+                       close(fd);
                        SLOG(LOG_ERROR, TAG_TTSCONFIG, "Fail to save bg volume ratio");
                        return TTS_CONFIG_ERROR_OPERATION_FAILED;
                }
 
+               tts_parser_save_with_flock(fd);
                invoke_bg_volume_ratio_changed_event(value);
        } else {
                SLOG(LOG_INFO, TAG_TTSCONFIG, "Client type is default. Skip saving configuration file.");
        }
 
-       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;
+       close(fd);
+
+       if (config_info.bg_volume_ratio == value) {
+               SLOG(LOG_INFO, TAG_TTSCONFIG, "Background volume(%lf) is not changed. Skip setting", value);
+               return TTS_CONFIG_ERROR_NONE;
        }
 
        config_info.bg_volume_ratio = 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;
index 2bbfcb99af2f6924acee03f6819b878117395cf4..937f865dc54a551492248d94665139b2088ea772 100644 (file)
@@ -18,6 +18,7 @@
 #include <vconf.h>
 #include <errno.h>
 #include <tizen_error.h>
+#include <sys/file.h>
 
 #include "tts_config_parser.h"
 #include "tts_defs.h"
@@ -790,6 +791,8 @@ int tts_parser_print_engine_info(tts_engine_info_s* engine_info)
 
 int tts_parser_load_config(void)
 {
+       SLOG(LOG_DEBUG, TAG_TTSCONFIG, "@@@ tts_parser_load_config");
+
        xmlDocPtr doc = NULL;
        xmlNodePtr cur = NULL;
        bool is_default_open = false;
@@ -993,6 +996,12 @@ int tts_parser_load_config(void)
        pthread_mutex_unlock(&g_config_info_mutex);
        g_config_doc = doc;
 
+       xmlChar* xml_buff;
+       int buffersize;
+       xmlDocDumpFormatMemory(g_config_doc, &xml_buff, &buffersize, 1);
+       SLOG(LOG_DEBUG, TAG_TTSCONFIG, "[INFO] xml_buff(%s)", xml_buff);
+       xmlFree(xml_buff);
+
        if (true == is_default_open) {
                int retry_count = 0;
                int ret = -1;
@@ -1188,6 +1197,11 @@ static void __save_configuration(xmlDocPtr config_doc)
                }
                SLOG(LOG_ERROR, TAG_TTSCONFIG, "[DEBUG] Success to save %s", TTS_CONFIG);
        }
+
+       /* Set mode */
+       if (0 > chmod(TTS_CONFIG, 0664)) {
+               SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to change file mode : %d", ret);
+       }
 }
 
 static char* __convert_voice_type_into_char(tts_config_voice_type_e voice_type)
@@ -1204,6 +1218,67 @@ static char* __convert_voice_type_into_char(tts_config_voice_type_e voice_type)
        }
 }
 
+int tts_parser_open_with_flock(void)
+{
+       SLOG(LOG_ERROR, TAG_TTSCONFIG, "[INFO] open with flock");
+       int fd = -1;
+       fd = open(TTS_CONFIG, O_WRONLY | O_CREAT, 0666);
+       if (fd == -1) {
+               SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to open file %s (errno: %d)", TTS_CONFIG, errno);
+               close(fd);
+               return -1;
+       }
+
+       int retry_count = 0;
+       while (flock(fd, LOCK_EX | LOCK_NB) == -1) {
+               SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to lock file %s (fd: %d, errno: %d). retry(%d)", TTS_CONFIG, fd, errno, retry_count);
+               retry_count++;
+               usleep(100000);
+               if (20 == retry_count) {
+                       SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to lock file error : %s", TTS_CONFIG);
+                       close(fd);
+                       return -1;
+               }
+       }
+
+       SLOG(LOG_ERROR, TAG_TTSCONFIG, "[INFO] open with flock fd(%d)", fd);
+
+       tts_parser_unload_config();
+       if (0 != tts_parser_load_config()) {
+               SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to parse configure information");
+               close(fd);
+               return -1;
+       }
+
+       SLOG(LOG_ERROR, TAG_TTSCONFIG, "[INFO] reset g_config_info from tts-config.xml by reloading");
+
+       return fd;
+}
+
+int tts_parser_save_with_flock(int fd)
+{
+       SLOG(LOG_ERROR, TAG_TTSCONFIG, "[INFO] save with flock fd(%d)", fd);
+
+       static FILE* pFile;
+       pFile = fdopen(fd, "w");
+       if (NULL == pFile) {
+               SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to open file %s (by %d)", TTS_CONFIG, errno);
+               return -1;
+       }
+
+       xmlChar* xml_buff;
+       int buffersize;
+       xmlDocDumpFormatMemory(g_config_doc, &xml_buff, &buffersize, 1);
+       SLOG(LOG_ERROR, TAG_TTSCONFIG, "[INFO] xml_buff(%s)", xml_buff);
+       fprintf(pFile, "%s", (char*)xml_buff);
+       fclose(pFile);
+       SLOG(LOG_ERROR, TAG_TTSCONFIG, "[DEBUG] Success to save %s", TTS_CONFIG);
+
+       xmlFree(xml_buff);
+
+       return 0;
+}
+
 int tts_parser_set_engine(const char* engine_id, const char* setting, const char* language, int type)
 {
        if (NULL == engine_id) {
@@ -1227,8 +1302,6 @@ int tts_parser_set_engine(const char* engine_id, const char* setting, const char
                return -1;
        }
 
-       __save_configuration(g_config_doc);
-
        return 0;
 }
 
@@ -1249,8 +1322,6 @@ int tts_parser_set_voice(const char* language, int type)
                return -1;
        }
 
-       __save_configuration(g_config_doc);
-
        return 0;
 }
 
@@ -1264,8 +1335,6 @@ int tts_parser_set_auto_voice(bool value)
                return -1;
        }
 
-       __save_configuration(g_config_doc);
-
        return 0;
 }
 
@@ -1281,8 +1350,6 @@ int tts_parser_set_speech_rate(int value)
                return -1;
        }
 
-       __save_configuration(g_config_doc);
-
        return 0;
 }
 
@@ -1298,8 +1365,6 @@ int tts_parser_set_pitch(int value)
                return -1;
        }
 
-       __save_configuration(g_config_doc);
-
        return 0;
 }
 
@@ -1315,8 +1380,6 @@ int tts_parser_set_bg_volume_ratio(double value)
                return -1;
        }
 
-       __save_configuration(g_config_doc);
-
        return 0;
 }
 
@@ -1350,8 +1413,20 @@ int tts_parser_find_config_changed(char** engine, char**setting, bool* auto_voic
                }
        }
 
+
+       xmlChar* xml_buff;
+       int buffersize;
+
        cur_new = xmlDocGetRootElement(doc);
+       xmlDocDumpFormatMemory(doc, &xml_buff, &buffersize, 1);
+       SLOG(LOG_DEBUG, TAG_TTSCONFIG, "[INFO] new xml_buff(%s)", xml_buff);
+       xmlFree(xml_buff);
+
        cur_old = xmlDocGetRootElement(g_config_doc);
+       xmlDocDumpFormatMemory(g_config_doc, &xml_buff, &buffersize, 1);
+       SLOG(LOG_DEBUG, TAG_TTSCONFIG, "[INFO] old xml_buff(%s)", xml_buff);
+       xmlFree(xml_buff);
+
        if (cur_new == NULL || cur_old == NULL) {
                SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Empty document(%p)", doc);
                xmlFreeDoc(doc);
index a74a0d2bf7b4a736bc2d14b919c263c732757ff2..e921d2a9f40410b27daeec525b38555a95553566 100644 (file)
@@ -109,6 +109,10 @@ int tts_parser_get_personal_info(const char* path, tts_personal_info_s** persona
 
 int tts_parser_free_personal_info(tts_personal_info_s* personal_info);
 
+int tts_parser_open_with_flock(void);
+
+int tts_parser_save_with_flock(int fd);
+
 #ifdef __cplusplus
 }
 #endif