Add parameter to detemine client and others 91/267491/4
authorSuyeon Hwang <stom.hwang@samsung.com>
Mon, 6 Dec 2021 07:19:24 +0000 (16:19 +0900)
committerSuyeon Hwang <stom.hwang@samsung.com>
Mon, 6 Dec 2021 10:35:52 +0000 (19:35 +0900)
Client app does not need to fix configuration, but current code has allowed the client to fix
configuration file. And this behavior makes race condition of configuration. By this problem,
configuration file has invalid value, and it is possible to make side effect.

To solve this problem, this patch adds new parameter to identify client app. By this change,
framework can block the fix from client, and by this behavior, possibility of race condition
would be reduced.

Change-Id: I37d26f78c9d1aa185d4ab22b15a8cd76fb890196
Signed-off-by: Suyeon Hwang <stom.hwang@samsung.com>
client/tts.c
client/tts_setting.c
common/tts_config_mgr.c
common/tts_config_mgr.h
server/ttsd_config.c

index 8b4fdc68fcce3c6646bc9f9c8f96aec16e8d6fb8..b15216793323693416ed0a959dd5a8b472aabee7 100644 (file)
@@ -263,7 +263,7 @@ int tts_create(tts_h* tts)
                return TTS_ERROR_OPERATION_FAILED;
        }
 
-       int ret = tts_config_mgr_initialize(uid);
+       int ret = tts_config_mgr_initialize(uid, TTS_CONFIG_CLIENT_TYPE_DEFAULT);
        if (0 != ret) {
                SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to init config manager : %d", ret);
                tts_client_destroy(new_tts);
index ebf08f45bc308552346c84591e8fa22a2b6374ad..09126baacb553f7f6f47701d1b1edeee9d9d097d 100644 (file)
@@ -119,7 +119,7 @@ int tts_setting_initialize()
                return TTS_SETTING_ERROR_NONE;
        }
 
-       int ret = tts_config_mgr_initialize(getpid());
+       int ret = tts_config_mgr_initialize(getpid(), TTS_CONFIG_CLIENT_TYPE_SETTING);
        if (0 != ret) {
                SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to initialize config manager : %d", ret);
                return __setting_convert_config_error_code(ret);
index fbb8f130be427b7fac0cd4c430482b14d458c76a..c633b49eb91125f4769e9b632fe62e99404224d3 100644 (file)
@@ -50,6 +50,8 @@ static Ecore_Fd_Handler* g_config_fd_handler_noti = NULL;
 static int g_config_fd_noti;
 static int g_config_wd_noti;
 
+static tts_config_client_type_e g_client_type = TTS_CONFIG_CLIENT_TYPE_DEFAULT;
+
 /* For engine directory monitoring */
 typedef struct {
        Ecore_Fd_Handler* dir_fd_handler;
@@ -218,6 +220,11 @@ int __tts_config_mgr_check_engine_is_valid(const char* engine_id)
                return TTS_CONFIG_ERROR_INVALID_PARAMETER;
        }
 
+       if (TTS_CONFIG_CLIENT_TYPE_DEFAULT == g_client_type) {
+               SLOG(LOG_INFO, TAG_TTSCONFIG, "Client type is default. Skip saving configuration file.");
+               return TTS_CONFIG_ERROR_NONE;
+       }
+
        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;
@@ -655,11 +662,6 @@ int __tts_config_set_auto_language()
                char* before_lang = NULL;
                int before_type;
 
-               if (0 != tts_parser_set_voice(temp_lang, config_info.type)) {
-                       SLOG(LOG_ERROR, TAG_TTSCONFIG, "Fail to save default voice");
-                       return -1;
-               }
-
                before_lang = strdup(config_info.language);
                before_type = config_info.type;
 
@@ -708,11 +710,6 @@ int __tts_config_set_auto_language()
                        return -1;
                }
 
-               if (0 != tts_parser_set_voice(tmp_language, tmp_type)) {
-                       SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to save config");
-                       return -1;
-               }
-
                SECURE_SLOG(LOG_DEBUG, TAG_TTSCONFIG, "[Config] Default voice : lang(%s) type(%d)",
                        tmp_language, tmp_type);
 
@@ -750,6 +747,7 @@ int __tts_config_set_auto_language()
                SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to set configure information");
                return TTS_CONFIG_ERROR_INVALID_PARAMETER;
        }
+
        return 0;
 }
 
@@ -762,6 +760,18 @@ void __tts_config_display_language_changed_cb(keynode_t *key, void *data)
        }
        if (true == config_info.auto_voice) {
                __tts_config_set_auto_language();
+
+               if (TTS_CONFIG_CLIENT_TYPE_SERVER == g_client_type) {
+                       if (0 != tts_parser_get_config_info(&config_info)){
+                               SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to get configure information");
+                               return;
+                       }
+
+                       if (0 != tts_parser_set_voice(config_info.language, config_info.type)) {
+                               SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to save config");
+                               return;
+                       }
+               }
        }
 
        return;
@@ -990,7 +1000,7 @@ static Eina_Bool __tts_config_mgr_engine_config_inotify_event_callback(void* dat
                        if (0 != ret) {
                                SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to set voice");
                        } else {
-                               SLOG(LOG_DEBUG, TAG_TTSCONFIG, "[DEBUG] Saved default voice : lang(%s), type(%d)", config_info.language, config_info.type);
+                               SLOG(LOG_DEBUG, TAG_TTSCONFIG, "[DEBUG] Saved default voice : lang(%s), type(%d)", temp_lang, temp_type);
                        }
                        if (NULL != temp_lang) {
                                free(temp_lang);
@@ -998,6 +1008,11 @@ static Eina_Bool __tts_config_mgr_engine_config_inotify_event_callback(void* dat
                        }
                }
 
+               if (0 != tts_parser_get_config_info(&config_info)){
+                       SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to get configure information");
+                       return TTS_CONFIG_ERROR_INVALID_PARAMETER;
+               }
+
                GSList *iter = NULL;
                tts_config_client_s* temp_client = NULL;
                /* Call all callbacks of client*/
@@ -1107,7 +1122,7 @@ static int __tts_config_mgr_unregister_engine_config_updated_event()
        return 0;
 }
 
-int tts_config_mgr_initialize(int uid)
+int tts_config_mgr_initialize(int uid, tts_config_client_type_e client_type)
 {
        GSList *iter = NULL;
        int* get_uid;
@@ -1207,6 +1222,9 @@ int tts_config_mgr_initialize(int uid)
                }
        }
 
+       SLOG(LOG_INFO, TAG_TTSCONFIG, "Client type : %d", client_type);
+       g_client_type = client_type;
+
        if (0 != __tts_config_mgr_get_engine_info()) {
                SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to get engine info");
                __tts_config_release_client(uid);
@@ -1242,6 +1260,16 @@ int tts_config_mgr_initialize(int uid)
        if (true == config_info.auto_voice) {
                /* Check language with display language */
                __tts_config_set_auto_language();
+
+               if (TTS_CONFIG_CLIENT_TYPE_DEFAULT != g_client_type) {
+                       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");
+                       }
+               }
        } else {
                if (false == __tts_config_mgr_check_lang_is_valid(config_info.engine_id, config_info.language, config_info.type)) {
                        /* Default language is not valid */
@@ -1270,12 +1298,16 @@ int tts_config_mgr_initialize(int uid)
                                        return TTS_CONFIG_ERROR_OPERATION_FAILED;
                                }
 
-                               if (0 != tts_parser_set_voice(config_info.language, config_info.type)) {
-                                       SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to save config");
-                                       __tts_config_release_client(uid);
-                                       __tts_config_release_engine();
-                                       tts_parser_unload_config();
-                                       return TTS_CONFIG_ERROR_OPERATION_FAILED;
+                               if (TTS_CONFIG_CLIENT_TYPE_DEFAULT == g_client_type) {
+                                       SLOG(LOG_INFO, TAG_TTSCONFIG, "Client type is default. Skip saving configuration file.");
+                               } else {
+                                       if (0 != tts_parser_set_voice(config_info.language, config_info.type)) {
+                                               SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to save config");
+                                               __tts_config_release_client(uid);
+                                               __tts_config_release_engine();
+                                               tts_parser_unload_config();
+                                               return TTS_CONFIG_ERROR_OPERATION_FAILED;
+                                       }
                                }
                        }
                }
@@ -1720,6 +1752,11 @@ int tts_config_mgr_set_engine(const char* engine)
                SECURE_SLOG(LOG_DEBUG, TAG_TTSCONFIG, "  Language : %s", config_info.language);
                SECURE_SLOG(LOG_DEBUG, TAG_TTSCONFIG, "  Type : %d", config_info.type);
 
+               if (TTS_CONFIG_CLIENT_TYPE_DEFAULT == g_client_type) {
+                       SLOG(LOG_INFO, TAG_TTSCONFIG, "Client type is default. Skip saving configuration file.");
+                       return TTS_CONFIG_ERROR_NONE;
+               }
+
                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");
@@ -1845,10 +1882,15 @@ int tts_config_mgr_set_voice(const char* language, int type)
        }
 
        /* Check language is valid */
-       if (0 != tts_parser_set_voice(language, type)) {
-               SLOG(LOG_ERROR, TAG_TTSCONFIG, "Fail to save default voice");
-               return TTS_CONFIG_ERROR_OPERATION_FAILED;
+       if (TTS_CONFIG_CLIENT_TYPE_DEFAULT == g_client_type) {
+               SLOG(LOG_INFO, TAG_TTSCONFIG, "Client type is default. Skip saving configuration file.");
+       } else {
+               if (0 != tts_parser_set_voice(language, type)) {
+                       SLOG(LOG_ERROR, TAG_TTSCONFIG, "Fail to save default voice");
+                       return TTS_CONFIG_ERROR_OPERATION_FAILED;
+               }
        }
+
        memset(g_language, '\0', sizeof(g_language));
        config_info.language = g_language;
        strncpy(config_info.language, language, sizeof(g_language) - 1);
@@ -1899,14 +1941,28 @@ int tts_config_mgr_set_auto_voice(bool value)
 
        if (config_info.auto_voice != value) {
                /* Check language is valid */
-               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;
+               if (TTS_CONFIG_CLIENT_TYPE_DEFAULT == g_client_type) {
+                       SLOG(LOG_INFO, TAG_TTSCONFIG, "Client type is default. Skip saving configuration file.");
+               } else {
+                       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;
+                       }
                }
                config_info.auto_voice = value;
 
                if (true == config_info.auto_voice) {
                        __tts_config_set_auto_language();
+
+                       if (TTS_CONFIG_CLIENT_TYPE_DEFAULT != g_client_type) {
+                               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");
+                               }
+                       }
                }
        }
 
@@ -1949,9 +2005,13 @@ int tts_config_mgr_set_speech_rate(int value)
 
        if (TTS_CONFIG_SPEED_MIN <= value && value <= TTS_CONFIG_SPEED_MAX) {
                SLOG(LOG_DEBUG, TAG_TTSCONFIG, "[Config] Set speech rate : %d", value);
-               if (0 != tts_parser_set_speech_rate(value)) {
-                       SLOG(LOG_ERROR, TAG_TTSCONFIG, "Fail to save speech rate");
-                       return TTS_CONFIG_ERROR_OPERATION_FAILED;
+               if (TTS_CONFIG_CLIENT_TYPE_DEFAULT == g_client_type) {
+                       SLOG(LOG_INFO, TAG_TTSCONFIG, "Client type is default. Skip saving configuration file.");
+               } else {
+                       if (0 != tts_parser_set_speech_rate(value)) {
+                               SLOG(LOG_ERROR, TAG_TTSCONFIG, "Fail to save speech rate");
+                               return TTS_CONFIG_ERROR_OPERATION_FAILED;
+                       }
                }
 
                tts_config_s config_info;
@@ -2068,9 +2128,13 @@ int tts_config_mgr_set_pitch(int value)
                }
        }
 
-       if (0 != tts_parser_set_pitch(value)) {
-               SLOG(LOG_ERROR, TAG_TTSCONFIG, "Fail to save speech rate");
-               return TTS_CONFIG_ERROR_OPERATION_FAILED;
+       if (TTS_CONFIG_CLIENT_TYPE_DEFAULT == g_client_type) {
+               SLOG(LOG_INFO, TAG_TTSCONFIG, "Client type is default. Skip saving configuration file.");
+       } else {
+               if (0 != tts_parser_set_pitch(value)) {
+                       SLOG(LOG_ERROR, TAG_TTSCONFIG, "Fail to save speech rate");
+                       return TTS_CONFIG_ERROR_OPERATION_FAILED;
+               }
        }
 
        config_info.pitch = value;
@@ -2111,10 +2175,14 @@ int tts_config_mgr_set_bg_volume_ratio(double value)
        }
 
        SLOG(LOG_DEBUG, TAG_TTSCONFIG, "[Config] Set bg volume ratio : %lf", value);
-       if (0 != tts_parser_set_bg_volume_ratio(value))
-       {
-               SLOG(LOG_ERROR, TAG_TTSCONFIG, "Fail to save bg volume ratio");
-               return TTS_CONFIG_ERROR_OPERATION_FAILED;
+       if (TTS_CONFIG_CLIENT_TYPE_DEFAULT == g_client_type) {
+               SLOG(LOG_INFO, TAG_TTSCONFIG, "Client type is default. Skip saving configuration file.");
+       } else {
+               if (0 != tts_parser_set_bg_volume_ratio(value))
+               {
+                       SLOG(LOG_ERROR, TAG_TTSCONFIG, "Fail to save bg volume ratio");
+                       return TTS_CONFIG_ERROR_OPERATION_FAILED;
+               }
        }
 
        tts_config_s config_info;
index 2c6324242035f93601a83ae4fa24565714b567db..eb65b0984bb9e5cd103f949dca7a512a3ebcfd99 100644 (file)
@@ -1,5 +1,5 @@
 /*
-*  Copyright (c) 2011-2016 Samsung Electronics Co., Ltd All Rights Reserved 
+*  Copyright (c) 2011-2016 Samsung Electronics Co., Ltd All Rights Reserved
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
@@ -45,6 +45,13 @@ typedef enum {
        TTS_CONFIG_SPEED_MAX            = 15    /**< Max value */
 } tts_config_speed_e;
 
+typedef enum {
+       TTS_CONFIG_CLIENT_TYPE_DEFAULT = 0,
+       TTS_CONFIG_CLIENT_TYPE_SETTING = 1,
+       TTS_CONFIG_CLIENT_TYPE_SERVER = 2,
+       TTS_CONFIG_CLIENT_TYPE_INTERRUPT = 3
+} tts_config_client_type_e;
+
 
 typedef bool (*tts_config_supported_engine_cb)(const char* engine_id, const char* engine_name, const char* setting, void* user_data);
 
@@ -66,7 +73,7 @@ typedef void (*tts_config_bg_volume_ratio_changed_cb)(double value, void* user_d
 typedef void (*tts_config_screen_reader_changed_cb)(bool value, void* user_data);
 
 
-int tts_config_mgr_initialize(int uid);
+int tts_config_mgr_initialize(int uid, tts_config_client_type_e client_type);
 
 int tts_config_mgr_finalize(int uid);
 
index 57915712e2df8c88e0d882d4a887587a3683e206..aad6221bf3ffb70fe0a7996b9d950f9424a4a0e9 100644 (file)
@@ -1,5 +1,5 @@
 /*
-*  Copyright (c) 2011-2016 Samsung Electronics Co., Ltd All Rights Reserved 
+*  Copyright (c) 2011-2016 Samsung Electronics Co., Ltd All Rights Reserved
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
@@ -101,13 +101,14 @@ int ttsd_config_initialize(ttsd_config_changed_cb config_cb)
        g_sr_callback = NULL;
 
        int ret = -1;
-       ret = tts_config_mgr_initialize(getpid());
+       tts_config_client_type_e type = TTSD_MODE_INTERRUPT == ttsd_get_mode() ? TTS_CONFIG_CLIENT_TYPE_INTERRUPT : TTS_CONFIG_CLIENT_TYPE_SERVER;
+       ret = tts_config_mgr_initialize(getpid(), type);
        if (0 != ret) {
                SLOG(LOG_ERROR, tts_tag(), "[Config] Fail to initialize config manager");
                return -1;
        }
 
-       ret = tts_config_mgr_set_callback(getpid(), __ttsd_config_engine_changed_cb, __ttsd_config_voice_changed_cb, 
+       ret = tts_config_mgr_set_callback(getpid(), __ttsd_config_engine_changed_cb, __ttsd_config_voice_changed_cb,
                __ttsd_config_speech_rate_changed_cb, __ttsd_config_pitch_changed_cb, __ttsd_config_bg_volume_ratio_changed_cb, NULL);
        if (0 != ret) {
                SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to set config changed : %d", ret);
@@ -222,7 +223,7 @@ int ttsd_config_get_bg_volume_ratio(double* ratio)
        return 0;
 }
 
-int ttsd_config_save_error(int uid, int uttid, const char* lang, int vctype, const char* text, 
+int ttsd_config_save_error(int uid, int uttid, const char* lang, int vctype, const char* text,
                           const char* func, int line, const char* message)
 {
        SLOG(LOG_DEBUG, tts_tag(), "@@@@@ TTS ERROR LOG @@@@@");