change set engine name when vconf changed and update config from engine vconfkey 81/317381/6
authordyamy-lee <dyamy.lee@samsung.com>
Tue, 31 Dec 2024 09:42:11 +0000 (18:42 +0900)
committerVBS <sooyeon.kim@samsung.com>
Thu, 9 Jan 2025 05:35:04 +0000 (14:35 +0900)
Change-Id: I819b27b52f97a8cd54f1d9b6d954d6daef0ce37d

common/tts_config_mgr.c
common/tts_config_parser.c
common/tts_config_parser.h
server/ttsd_server.c

index 460ad24d7f8c075d3e7a7e102bce1654770fd1fe..5061f7bb1b661efb7782c0872601f4be0ccfc0db 100644 (file)
@@ -707,7 +707,6 @@ static Eina_Bool tts_config_mgr_inotify_event_cb(void* data, Ecore_Fd_Handler *f
 
        if (IN_CLOSE_WRITE == event.mask) {
                /* check config changed state */
-               char* engine = NULL;
                char* setting = NULL;
                char* lang = NULL;
                bool auto_voice = config_info.auto_voice;
@@ -716,31 +715,35 @@ static Eina_Bool tts_config_mgr_inotify_event_cb(void* data, Ecore_Fd_Handler *f
                int pitch = -1;
                double bg_volume_ratio = -1;
 
-               if (0 != tts_parser_find_config_changed(&engine, &setting, &auto_voice, &lang, &voice_type, &speech_rate, &pitch, &bg_volume_ratio))
+               if (0 != tts_parser_find_config_changed(&setting, &auto_voice, &lang, &voice_type, &speech_rate, &pitch, &bg_volume_ratio))
                        return ECORE_CALLBACK_PASS_ON;
 
-               /* engine changed */
-               if (NULL != engine || NULL != setting) {
-                       if (NULL != engine) {
-                               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);
-                               free(engine);
-                       }
+               /* config of engine updating */
+               memset(g_engine_id, '\0', sizeof(g_engine_id));
+               config_info.engine_id = g_engine_id;
 
-                       if (NULL != setting) {
-                               memset(g_setting, '\0', sizeof(g_setting));
-                               config_info.setting = g_setting;
-                               strncpy(config_info.setting, setting, sizeof(g_setting) - 1);
-                               free(setting);
-                       }
+               char* engine_id = vconf_get_str(TTS_ENGINE_DB_DEFAULT);
+               if (engine_id) {
+                       SLOG(LOG_DEBUG, TAG_TTSCONFIG, "Set default engine id(%s)", engine_id);
+                       strncpy(config_info.engine_id, engine_id, sizeof(g_engine_id) - 1);
 
-                       SLOG(LOG_ERROR, TAG_TTSCONFIG, "[INFO] Engine change(%s)", config_info.engine_id);
+                       free(engine_id);
+                       engine_id = NULL;
+               }
 
-                       /* Call all callbacks of client*/
-                       invoke_engine_changed_event(config_info.engine_id, config_info.setting, config_info.language, config_info.type, config_info.auto_voice, config_info.credential);
+               /* engine setting changed */
+               if (NULL != setting) {
+                       memset(g_setting, '\0', sizeof(g_setting));
+                       config_info.setting = g_setting;
+                       strncpy(config_info.setting, setting, sizeof(g_setting) - 1);
+                       free(setting);
                }
 
+               SLOG(LOG_ERROR, TAG_TTSCONFIG, "[INFO] Engine setting change(%s)", config_info.engine_id);
+
+               /* Call all callbacks of client*/
+               invoke_engine_changed_event(config_info.engine_id, config_info.setting, config_info.language, config_info.type, config_info.auto_voice, config_info.credential);
+
                if (auto_voice != config_info.auto_voice) {
                        config_info.auto_voice = auto_voice;
                }
@@ -1780,11 +1783,15 @@ int tts_config_mgr_set_engine(const char* engine)
 
        SLOG(LOG_ERROR, TAG_TTSCONFIG, "[INFO] New engine id : %s", engine);
 
-       ret = __tts_set_buxtonkey(engine);
-       if (0 != ret) {
-               close(fd);
-               SLOG(LOG_ERROR, TAG_TTSCONFIG, "[DEBUG] set_buxtonkey Fail!!");
-               return ret;
+
+       char* engine_id = vconf_get_str(TTS_ENGINE_DB_DEFAULT);
+       if (0 != strncmp(engine, engine_id, strlen(engine_id) + 1)) {
+               SLOG(LOG_INFO, TAG_TTSCONFIG, "vconf engine id(%s) is different from input engine id(%s)", engine, engine_id);
+               ret = __tts_set_buxtonkey(engine);
+               if (0 != ret) {
+                       SLOG(LOG_DEBUG, TAG_TTSCONFIG, "[DEBUG] set_buxtonkey Fail!!");
+                       return ret;
+               }
        }
 
        tts_engine_info_s *engine_info = __get_engine_info(engine);
index aa06ee71e5fb6bfa2851d3162d8bb654c571d699..75b381337d4c1681f36ae2e4beffbfa9265678ff 100644 (file)
@@ -880,26 +880,17 @@ int tts_parser_load_config(void)
 
        while (cur != NULL) {
                if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_ENGINE_ID)) {
-                       if (is_default_open) {
-                               char* engine_id = vconf_get_str(TTS_ENGINE_DB_DEFAULT);
-                               if (engine_id) {
-                                       SLOG(LOG_DEBUG, TAG_TTSCONFIG, "Set default engine id(%s)", engine_id);
-                                       strncpy(temp->engine_id, engine_id, sizeof(engine_id) - 1);
-                                       xmlNodeSetContent(cur, (const xmlChar *)engine_id);
-
-                                       free(engine_id);
-                                       engine_id = NULL;
-
-                                       cur = cur->next;
-                                       continue;
-                               }
-                       }
+                       char* engine_id = vconf_get_str(TTS_ENGINE_DB_DEFAULT);
+                       if (engine_id) {
+                               SLOG(LOG_DEBUG, TAG_TTSCONFIG, "Set default engine id(%s)", engine_id);
+                               strncpy(temp->engine_id, engine_id, sizeof(g_engine_id) - 1);
+                               xmlNodeSetContent(cur, (const xmlChar *)engine_id);
 
-                       xmlChar *key = xmlNodeGetContent(cur);
-                       if (NULL != key) {
-                               strncpy(temp->engine_id, (char*)key, sizeof(g_engine_id) - 1);
-                               xmlFree(key);
-                               key = NULL;
+                               free(engine_id);
+                               engine_id = NULL;
+
+                               cur = cur->next;
+                               continue;
                        } else {
                                SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] engine id is NULL");
                        }
@@ -1383,10 +1374,10 @@ int tts_parser_set_bg_volume_ratio(double value)
        return 0;
 }
 
-int tts_parser_find_config_changed(char** engine, char**setting, bool* auto_voice, char** language, int* voice_type,
+int tts_parser_find_config_changed(char**setting, bool* auto_voice, char** language, int* voice_type,
                                   int* speech_rate, int* pitch, double* bg_volume_ratio)
 {
-       if (NULL == engine || NULL == setting || NULL == language || NULL == voice_type || NULL == speech_rate) {
+       if (NULL == setting || NULL == language || NULL == voice_type || NULL == speech_rate) {
                SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Input parameter is NULL");
                return -1;
        }
@@ -1452,31 +1443,7 @@ int tts_parser_find_config_changed(char** engine, char**setting, bool* auto_voic
        }
 
        while (cur_new != NULL && cur_old != NULL) {
-               if (0 == xmlStrcmp(cur_new->name, (const xmlChar*)TTS_TAG_CONFIG_ENGINE_ID)) {
-                       if (0 == xmlStrcmp(cur_old->name, (const xmlChar*)TTS_TAG_CONFIG_ENGINE_ID)) {
-                               xmlChar *key_old = xmlNodeGetContent(cur_old);
-                               if (NULL != key_old) {
-                                       xmlChar *key_new = xmlNodeGetContent(cur_new);
-                                       if (NULL != key_new) {
-                                               if (0 != xmlStrcmp(key_old, key_new)) {
-                                                       SLOG(LOG_ERROR, TAG_TTSCONFIG, "Old engine id(%s), New engine(%s)",
-                                                               (char*)key_old, (char*)key_new);
-                                                       if (NULL != *engine) {
-                                                               free(*engine);
-                                                               *engine = NULL;
-                                                       }
-                                                       *engine = strdup((char*)key_new);
-                                               }
-                                               xmlFree(key_new);
-                                               key_new = NULL;
-                                       }
-                                       xmlFree(key_old);
-                                       key_old = NULL;
-                               }
-                       } else {
-                               SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] old config and new config are different");
-                       }
-               } else if (0 == xmlStrcmp(cur_new->name, (const xmlChar*)TTS_TAG_CONFIG_ENGINE_SETTING)) {
+               if (0 == xmlStrcmp(cur_new->name, (const xmlChar*)TTS_TAG_CONFIG_ENGINE_SETTING)) {
                        if (0 == xmlStrcmp(cur_old->name, (const xmlChar*)TTS_TAG_CONFIG_ENGINE_SETTING)) {
                                xmlChar *key_old = xmlNodeGetContent(cur_old);
                                if (NULL != key_old) {
index e921d2a9f40410b27daeec525b38555a95553566..c6158d800b4bcb1593f9ffd6241e52138e2a2fc0 100644 (file)
@@ -96,7 +96,7 @@ int tts_parser_set_pitch(int value);
 
 int tts_parser_set_bg_volume_ratio(double value);
 
-int tts_parser_find_config_changed(char** engine, char**setting, bool* auto_voice, char** language, int* voice_type, 
+int tts_parser_find_config_changed(char**setting, bool* auto_voice, char** language, int* voice_type, 
                                   int* speech_rate, int* pitch, double* bg_volume_ratio);
 
 int tts_parser_copy_xml(const char* original, const char* destination);
index 5414d362560577bac0da1ae206406874aa8a7007..f0bfbadfd78e51e81055b56fb9a76ad34f0cd9a9 100644 (file)
@@ -791,6 +791,20 @@ int ttsd_initialize(ttse_request_callback_s *callback)
                SLOG(LOG_ERROR, tts_tag(), "[Server WARNING] Fail to initialize config.");
        }
 
+       char *engine_id_by_config;
+       int ret = ttsd_config_get_default_engine(&engine_id_by_config);
+       if (0 != ret) {
+               SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to get default engine, ret(%d)", ret);
+       }
+
+       char* engine_id_by_vconf = vconf_get_str(TTS_ENGINE_DB_DEFAULT);
+       if (0 != strncmp(engine_id_by_config, engine_id_by_vconf, strlen(engine_id_by_vconf) + 1)) {
+               ret = ttsd_config_set_default_engine(engine_id_by_vconf);
+               if (0 != ret) {
+                       SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to set default engine, ret(%d)", ret);
+               }
+       }
+
        if (TTSD_ERROR_NONE != ttsd_state_initialize(__state_changed_cb)) {
                SLOG(LOG_ERROR, tts_tag(), "[Server WARNING] Fail to initialize state.");
        }