Add logic to check duplicate when personal voice is updated with ttse_send_personal_v... 22/315522/3
authorsungwook79.park <sungwook79.park@samsung.com>
Fri, 2 Aug 2024 04:40:16 +0000 (13:40 +0900)
committersungwook79.park <sungwook79.park@samsung.com>
Thu, 12 Sep 2024 10:58:21 +0000 (19:58 +0900)
Change-Id: I1a905c9a281c96256a6852bb47c7d5b1d2b51715
Signed-off-by: sungwook79.park <sungwook79.park@samsung.com>
common/tts_config_mgr.c
common/tts_config_mgr.h
server/ttsd_config.c

index fbe5dc0799c3dfb26dff61ba066a05715e51522e..09663a97409412c3937baa565811893f6fe4cd49 100644 (file)
@@ -2514,3 +2514,52 @@ int tts_config_mgr_get_personal_voice_list(const char* engine_id, tts_config_sup
 
        return TTS_CONFIG_ERROR_NONE;
 }
+
+
+int tts_config_mgr_check_duplicate_personal_voice(const char* engine_id, const char* unique_id, bool* matched)
+{
+       SLOG(LOG_DEBUG, TAG_TTSCONFIG, "[DEBUG] engine id = %s", engine_id);
+       if (NULL == engine_id) {
+               SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Input Parameter is null");
+               return TTS_CONFIG_ERROR_INVALID_PARAMETER;
+       }
+
+       char filepath[512] = {'\0',};
+       memset(filepath, '\0', 512);
+       snprintf(filepath, 512, "%s/%s-%s", TTS_DOWNLOAD_PERSONAL_INFO, engine_id, "personal.xml");
+
+       tts_personal_info_s* info = NULL;
+       int ret = tts_parser_get_personal_info(filepath, &info);
+       if (0 != ret) {
+               SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] There is no personal info file. It can be first time or fail.");
+               return 0;
+       }
+
+       GSList *iter_personal_voice = NULL;
+       tts_config_personal_s* personal_voice = NULL;
+       *matched = false;
+       if (g_slist_length(info->personal_voices) > 0) {
+               /* Get a first item */
+               iter_personal_voice = g_slist_nth(info->personal_voices, 0);
+
+               int j = 1;
+               while (NULL != iter_personal_voice) {
+                       /*Get handle data from list*/
+                       personal_voice = iter_personal_voice->data;
+
+                       SLOG(LOG_DEBUG, TAG_TTSCONFIG, "  [%dth] unique_id(%s)", j, personal_voice->unique_id);
+                       if (0 == strncmp(unique_id, personal_voice->unique_id, strlen(unique_id))) {
+                               *matched = true;
+                               break;
+                       }
+
+                       /*Get next item*/
+                       iter_personal_voice = g_slist_next(iter_personal_voice);
+                       j++;
+               }
+       } else {
+               return -1;
+       }
+
+       return 0;
+}
\ No newline at end of file
index ae3eeb79873fb2389a9a8065366ddedc1146b2fe..a9df5f27cb76906a2ee4f4d13668dc44bd228af4 100644 (file)
@@ -133,7 +133,7 @@ int tts_config_mgr_set_instant_reprepare_client(const unsigned int uid);
 
 int tts_config_mgr_update_personal_voice(const char* engine_id, const char* language, const char* unique_id, const char* display_name, const char* device_name);
 int tts_config_mgr_get_personal_voice_list(const char* engine_id, tts_config_supported_personal_voice_cb callback, void* user_data);
-
+int tts_config_mgr_check_duplicate_personal_voice(const char* engine_id, const char* unique_id, bool* matched);
 
 #ifdef __cplusplus
 }
index 13cbbbc76444f55df8dbd752d184171f57927bc8..7bf7ccb6cad369ee004f551fdcd78368ffc2ec8a 100644 (file)
@@ -274,12 +274,23 @@ int ttsd_config_update_personal_voice(const char* language, const char* unique_i
        SLOG(LOG_DEBUG, tts_tag(), "[Server] TTS Current Engine(%s)", current_engine);
 
        int ret = tts_config_mgr_update_personal_voice(current_engine, language, unique_id, display_name, device_name);
+
+       bool matched = false;
+       ret = tts_config_mgr_check_duplicate_personal_voice(current_engine, unique_id, &matched);
        if (0 != ret) {
-               SLOG(LOG_ERROR, tts_tag(), "[Config ERROR] Fail to update personal voice to xml");
+               SLOG(LOG_ERROR, tts_tag(), "[Config ERROR] Fail to check duplicate personal voice");
                return TTSD_ERROR_OPERATION_FAILED;
        }
 
-       return 0;
+       if (!matched) {
+               ret = tts_config_mgr_update_personal_voice(current_engine, language, unique_id, display_name, device_name);
+               if (0 != ret) {
+                       SLOG(LOG_ERROR, tts_tag(), "[Config ERROR] Fail to update personal voice to xml");
+                       return TTSD_ERROR_OPERATION_FAILED;
+               }
+       }
+
+       return ret;
 }
 
 bool __ttsd_config_personal_voices(const char* language, const char* unique_id, const char* display_name, const char* device_name, void* user_data)