Fix config client type as a bit flat 19/268219/2
authorSuyeon Hwang <stom.hwang@samsung.com>
Fri, 17 Dec 2021 06:47:52 +0000 (15:47 +0900)
committerSuyeon Hwang <stom.hwang@samsung.com>
Fri, 17 Dec 2021 07:21:18 +0000 (16:21 +0900)
There is case that the app uses both client and setting API. In current code, this kind of usage
can cause invalid blocking to fix configuration file. Because current config client type is only
store single mode in one process.

To solve this problem, this patch changes config client type to bit flag variable. By this change,
a process can store multiple client type, and this can avoid wrong behavior.

Change-Id: I66bdb64cff148da5a0cc3cc725842265534d4842
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 b152167..bae260a 100644 (file)
@@ -273,7 +273,7 @@ int tts_create(tts_h* tts)
        ret = tts_config_mgr_set_callback(uid, __tts_config_engine_changed_cb, __tts_config_voice_changed_cb, NULL, NULL, NULL, new_tts);
        if (0 != ret) {
                SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to set config changed : %d", ret);
-               tts_config_mgr_finalize(uid);
+               tts_config_mgr_finalize(uid, TTS_CONFIG_CLIENT_TYPE_DEFAULT);
                tts_client_destroy(new_tts);
                return __tts_convert_config_error_code(ret);
        }
@@ -281,7 +281,7 @@ int tts_create(tts_h* tts)
        ret = tts_config_mgr_set_screen_reader_callback(uid, __tts_config_screen_reader_changed_cb, new_tts);
        if (0 != ret) {
                SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to set config changed : %d", ret);
-               tts_config_mgr_finalize(uid);
+               tts_config_mgr_finalize(uid, TTS_CONFIG_CLIENT_TYPE_DEFAULT);
                tts_client_destroy(new_tts);
                return __tts_convert_config_error_code(ret);
        }
@@ -290,7 +290,7 @@ int tts_create(tts_h* tts)
                // These function would be called only when first client is created.
                if (0 != tts_core_initialize()) {
                        SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to initialize core");
-                       tts_config_mgr_finalize(uid);
+                       tts_config_mgr_finalize(uid, TTS_CONFIG_CLIENT_TYPE_DEFAULT);
                        tts_client_destroy(new_tts);
                        return TTS_ERROR_OPERATION_FAILED;
                }
@@ -324,7 +324,7 @@ int tts_destroy(tts_h tts)
                return TTS_ERROR_OPERATION_FAILED;
        }
 
-       tts_config_mgr_finalize(uid);
+       tts_config_mgr_finalize(uid, TTS_CONFIG_CLIENT_TYPE_DEFAULT);
 
        // TODO: move into tts_client
        if (client->hello_timer) {
index 09126ba..18dc8fb 100644 (file)
@@ -155,7 +155,7 @@ int tts_setting_finalize()
 {
        SLOG(LOG_DEBUG, TAG_TTSC, "@@@ Finalize TTS Setting");
 
-       tts_config_mgr_finalize(getpid());
+       tts_config_mgr_finalize(getpid(), TTS_CONFIG_CLIENT_TYPE_SETTING);
 
        g_state = TTS_SETTING_STATE_NONE;
 
index c633b49..9749cca 100644 (file)
@@ -50,7 +50,7 @@ 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;
+static int g_client_type = 0x0;
 
 /* For engine directory monitoring */
 typedef struct {
@@ -99,6 +99,15 @@ static tts_engine_info_s* __get_engine_info(const char* engine_id)
        return NULL;
 }
 
+static bool __is_client_type(int type_flag)
+{
+       if (type_flag & g_client_type) {
+               return true;
+       }
+
+       return false;
+}
+
 int __tts_config_mgr_check_engine_is_valid(const char* engine_id)
 {
        if (NULL == engine_id) {
@@ -220,15 +229,15 @@ 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) {
+       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.");
-               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;
-       }
 
        return 0;
 }
@@ -761,7 +770,7 @@ 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 (__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;
@@ -1223,7 +1232,7 @@ int tts_config_mgr_initialize(int uid, tts_config_client_type_e client_type)
        }
 
        SLOG(LOG_INFO, TAG_TTSCONFIG, "Client type : %d", client_type);
-       g_client_type = 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");
@@ -1261,7 +1270,7 @@ int tts_config_mgr_initialize(int uid, tts_config_client_type_e client_type)
                /* Check language with display language */
                __tts_config_set_auto_language();
 
-               if (TTS_CONFIG_CLIENT_TYPE_DEFAULT != g_client_type) {
+               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");
                        }
@@ -1298,9 +1307,7 @@ int tts_config_mgr_initialize(int uid, tts_config_client_type_e client_type)
                                        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 (__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");
                                                __tts_config_release_client(uid);
@@ -1308,6 +1315,8 @@ int tts_config_mgr_initialize(int uid, tts_config_client_type_e client_type)
                                                tts_parser_unload_config();
                                                return TTS_CONFIG_ERROR_OPERATION_FAILED;
                                        }
+                               } else {
+                                       SLOG(LOG_INFO, TAG_TTSCONFIG, "Client type is default. Skip saving configuration file.");
                                }
                        }
                }
@@ -1350,12 +1359,15 @@ int tts_config_mgr_initialize(int uid, tts_config_client_type_e client_type)
        return 0;
 }
 
-int tts_config_mgr_finalize(int uid)
+int tts_config_mgr_finalize(int uid, tts_config_client_type_e client_type)
 {
        if (0 < __tts_config_release_client(uid)) {
                return 0;
        }
 
+       SLOG(LOG_INFO, TAG_TTSCONFIG, "Client type : %d", client_type);
+       g_client_type &= ~client_type;
+
        tts_config_mgr_unset_callback(uid);
 
        __tts_config_release_engine();
@@ -1752,15 +1764,14 @@ 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) {
+               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.");
-                       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;
                }
        } else {
                SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Engine id is not valid");
@@ -1882,13 +1893,13 @@ int tts_config_mgr_set_voice(const char* language, int type)
        }
 
        /* Check language is valid */
-       if (TTS_CONFIG_CLIENT_TYPE_DEFAULT == g_client_type) {
-               SLOG(LOG_INFO, TAG_TTSCONFIG, "Client type is default. Skip saving configuration file.");
-       } else {
+       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)) {
                        SLOG(LOG_ERROR, TAG_TTSCONFIG, "Fail to save default voice");
                        return TTS_CONFIG_ERROR_OPERATION_FAILED;
                }
+       } else {
+               SLOG(LOG_INFO, TAG_TTSCONFIG, "Client type is default. Skip saving configuration file.");
        }
 
        memset(g_language, '\0', sizeof(g_language));
@@ -1941,20 +1952,20 @@ int tts_config_mgr_set_auto_voice(bool value)
 
        if (config_info.auto_voice != value) {
                /* Check language is valid */
-               if (TTS_CONFIG_CLIENT_TYPE_DEFAULT == g_client_type) {
-                       SLOG(LOG_INFO, TAG_TTSCONFIG, "Client type is default. Skip saving configuration file.");
-               } else {
+               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.");
                }
                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 (__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");
                                }
@@ -2005,13 +2016,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 (TTS_CONFIG_CLIENT_TYPE_DEFAULT == g_client_type) {
-                       SLOG(LOG_INFO, TAG_TTSCONFIG, "Client type is default. Skip saving configuration file.");
-               } else {
+               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.");
                }
 
                tts_config_s config_info;
@@ -2128,13 +2139,13 @@ int tts_config_mgr_set_pitch(int value)
                }
        }
 
-       if (TTS_CONFIG_CLIENT_TYPE_DEFAULT == g_client_type) {
-               SLOG(LOG_INFO, TAG_TTSCONFIG, "Client type is default. Skip saving configuration file.");
-       } else {
+       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");
                        return TTS_CONFIG_ERROR_OPERATION_FAILED;
                }
+       } else {
+               SLOG(LOG_INFO, TAG_TTSCONFIG, "Client type is default. Skip saving configuration file.");
        }
 
        config_info.pitch = value;
@@ -2175,14 +2186,13 @@ int tts_config_mgr_set_bg_volume_ratio(double value)
        }
 
        SLOG(LOG_DEBUG, TAG_TTSCONFIG, "[Config] Set bg volume ratio : %lf", value);
-       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))
-               {
+       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)) {
                        SLOG(LOG_ERROR, TAG_TTSCONFIG, "Fail to save bg volume ratio");
                        return TTS_CONFIG_ERROR_OPERATION_FAILED;
                }
+       } else {
+               SLOG(LOG_INFO, TAG_TTSCONFIG, "Client type is default. Skip saving configuration file.");
        }
 
        tts_config_s config_info;
index eb65b09..782c35e 100644 (file)
@@ -46,10 +46,10 @@ typedef enum {
 } 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_DEFAULT = 0x1,
+       TTS_CONFIG_CLIENT_TYPE_SETTING = 0x2,
+       TTS_CONFIG_CLIENT_TYPE_SERVER = 0x4,
+       TTS_CONFIG_CLIENT_TYPE_INTERRUPT = 0x8
 } tts_config_client_type_e;
 
 
@@ -75,7 +75,7 @@ typedef void (*tts_config_screen_reader_changed_cb)(bool value, void* user_data)
 
 int tts_config_mgr_initialize(int uid, tts_config_client_type_e client_type);
 
-int tts_config_mgr_finalize(int uid);
+int tts_config_mgr_finalize(int uid, tts_config_client_type_e client_type);
 
 
 int tts_config_mgr_set_callback(int uid,
index aad6221..a280ae9 100644 (file)
@@ -122,7 +122,8 @@ int ttsd_config_finalize()
 {
        tts_config_mgr_unset_screen_reader_callback(getpid());
 
-       tts_config_mgr_finalize(getpid());
+       tts_config_client_type_e type = TTSD_MODE_INTERRUPT == ttsd_get_mode() ? TTS_CONFIG_CLIENT_TYPE_INTERRUPT : TTS_CONFIG_CLIENT_TYPE_SERVER;
+       tts_config_mgr_finalize(getpid(), type);
 
        return 0;
 }