X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=common%2Ftts_config_parser.c;h=1cbdec8442d041626c0ef0a0de03065b26c53289;hb=60289108d257c1e6620f97663eff41cc3e789a86;hp=82f84287fedc04c37d052f7c4ad026d9d271fd54;hpb=8f0df02ba2d9093c37b912b7242b9971fc78023c;p=platform%2Fcore%2Fuifw%2Ftts.git diff --git a/common/tts_config_parser.c b/common/tts_config_parser.c old mode 100755 new mode 100644 index 82f8428..1cbdec8 --- a/common/tts_config_parser.c +++ b/common/tts_config_parser.c @@ -29,6 +29,7 @@ #define TTS_TAG_ENGINE_VOICE "voice" #define TTS_TAG_ENGINE_VOICE_TYPE "type" #define TTS_TAG_ENGINE_PITCH_SUPPORT "pitch-support" +#define TTS_TAG_ENGINE_TEXT_SIZE "text-size" #define TTS_TAG_CONFIG_BASE_TAG "tts-config" #define TTS_TAG_CONFIG_ENGINE_ID "engine" @@ -42,39 +43,48 @@ #define TTS_TAG_VOICE_TYPE_MALE "male" #define TTS_TAG_VOICE_TYPE_CHILD "child" - -extern char* tts_tag(); +#define TTS_MAX_TEXT_SIZE 2000 static xmlDocPtr g_config_doc = NULL; +char g_engine_id[128] = {0,}; +char g_setting[128] = {0,}; +char g_language[128] = {0,}; int tts_parser_get_engine_info(const char* path, tts_engine_info_s** engine_info) { if (NULL == path || NULL == engine_info) { - SLOG(LOG_ERROR, tts_tag(), "[ERROR] Input parameter is NULL"); + SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Input parameter is NULL"); return -1; } + bool isTextsize = false; xmlDocPtr doc = NULL; xmlNodePtr cur = NULL; xmlChar *key = NULL; xmlChar *attr = NULL; - doc = xmlParseFile(path); - if (doc == NULL) { - SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to parse xml file"); + if (0 == access(path, F_OK)) { + SLOG(LOG_DEBUG, TAG_TTSCONFIG, "[DEBUG] Success to access to %s", path); + doc = xmlParseFile(path); + if (doc == NULL) { + SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to parse xml file"); + return -1; + } + } else { + SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to access to %s", path); return -1; } cur = xmlDocGetRootElement(doc); if (cur == NULL) { - SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document"); + SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Empty document. doc path(%s, %p)", path, doc); xmlFreeDoc(doc); doc = NULL; return -1; } if (xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_ENGINE_BASE_TAG)) { - SLOG(LOG_ERROR, tts_tag(), "[ERROR] The wrong type, root node is NOT 'tts-engine'"); + SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] The wrong type, root node is NOT 'tts-engine'. doc path(%s, %p)", path, doc); xmlFreeDoc(doc); doc = NULL; return -1; @@ -82,7 +92,7 @@ int tts_parser_get_engine_info(const char* path, tts_engine_info_s** engine_info cur = cur->xmlChildrenNode; if (cur == NULL) { - SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document"); + SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Empty document. doc path(%s, %p)", path, doc); xmlFreeDoc(doc); doc = NULL; return -1; @@ -92,7 +102,7 @@ int tts_parser_get_engine_info(const char* path, tts_engine_info_s** engine_info tts_engine_info_s* temp; temp = (tts_engine_info_s*)calloc(1, sizeof(tts_engine_info_s)); if (NULL == temp) { - SLOG(LOG_ERROR, tts_tag(), "[ERROR] Out of memory"); + SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Out of memory. doc path(%s, %p)", path, doc); xmlFreeDoc(doc); doc = NULL; return -1; @@ -103,6 +113,7 @@ int tts_parser_get_engine_info(const char* path, tts_engine_info_s** engine_info temp->voices = NULL; temp->setting = NULL; temp->pitch_support = false; + temp->text_size = 0; while (cur != NULL) { if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_ENGINE_NAME)) { @@ -116,7 +127,7 @@ int tts_parser_get_engine_info(const char* path, tts_engine_info_s** engine_info xmlFree(key); key = NULL; } else { - SLOG(LOG_ERROR, tts_tag(), "[ERROR] <%s> has no content", TTS_TAG_ENGINE_NAME); + SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] <%s> has no content", TTS_TAG_ENGINE_NAME); } } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_ENGINE_ID)) { key = xmlNodeGetContent(cur); @@ -129,7 +140,7 @@ int tts_parser_get_engine_info(const char* path, tts_engine_info_s** engine_info xmlFree(key); key = NULL; } else { - SLOG(LOG_ERROR, tts_tag(), "[ERROR] <%s> has no content", TTS_TAG_ENGINE_ID); + SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] <%s> has no content", TTS_TAG_ENGINE_ID); } } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_ENGINE_SETTING)) { key = xmlNodeGetContent(cur); @@ -142,7 +153,7 @@ int tts_parser_get_engine_info(const char* path, tts_engine_info_s** engine_info xmlFree(key); key = NULL; } else { - SLOG(LOG_ERROR, tts_tag(), "[ERROR] <%s> has no content", TTS_TAG_ENGINE_SETTING); + SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] <%s> has no content", TTS_TAG_ENGINE_SETTING); } } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_ENGINE_VOICE_SET)) { xmlNodePtr voice_node = NULL; @@ -152,7 +163,7 @@ int tts_parser_get_engine_info(const char* path, tts_engine_info_s** engine_info if (0 == xmlStrcmp(voice_node->name, (const xmlChar *)TTS_TAG_ENGINE_VOICE)) { tts_config_voice_s* temp_voice = (tts_config_voice_s*)calloc(1, sizeof(tts_config_voice_s)); if (NULL == temp_voice) { - SLOG(LOG_ERROR, tts_tag(), "[ERROR] Out of memory"); + SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Out of memory"); break; } @@ -170,7 +181,7 @@ int tts_parser_get_engine_info(const char* path, tts_engine_info_s** engine_info xmlFree(attr); attr = NULL; } else { - SLOG(LOG_ERROR, tts_tag(), "[ERROR] <%s> has no content", TTS_TAG_ENGINE_VOICE_TYPE); + SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] <%s> has no content", TTS_TAG_ENGINE_VOICE_TYPE); free(temp_voice); temp_voice = NULL; continue; @@ -187,7 +198,7 @@ int tts_parser_get_engine_info(const char* path, tts_engine_info_s** engine_info key = NULL; temp->voices = g_slist_append(temp->voices, temp_voice); } else { - SLOG(LOG_ERROR, tts_tag(), "[ERROR] <%s> has no content", TTS_TAG_ENGINE_VOICE); + SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] <%s> has no content", TTS_TAG_ENGINE_VOICE); if (NULL != temp_voice) { free(temp_voice); temp_voice = NULL; @@ -205,18 +216,35 @@ int tts_parser_get_engine_info(const char* path, tts_engine_info_s** engine_info xmlFree(key); key = NULL; } else { - SLOG(LOG_ERROR, tts_tag(), "[ERROR] <%s> has no content", TTS_TAG_ENGINE_PITCH_SUPPORT); + SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] <%s> has no content", TTS_TAG_ENGINE_PITCH_SUPPORT); + } + } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_ENGINE_TEXT_SIZE)) { + isTextsize = true; + key = xmlNodeGetContent(cur); + if (NULL != key) { + temp->text_size = atoi((char*)key); + xmlFree(key); + } else { + SLOG(LOG_INFO, TAG_TTSCONFIG, "[INFO] text size is unlimited."); + temp->text_size = 0; } } cur = cur->next; } - xmlFreeDoc(doc); - doc = NULL; + if (false == isTextsize) { + temp->text_size = TTS_MAX_TEXT_SIZE; + } + + if (NULL != doc) { + SLOG(LOG_ERROR, TAG_TTSCONFIG, "[DEBUG] doc path(%s, %p)", path, doc); + xmlFreeDoc(doc); + doc = NULL; + } - if (NULL == temp->name || NULL == temp->uuid) { + if (NULL == temp->uuid) { /* Invalid engine */ - SECURE_SLOG(LOG_ERROR, tts_tag(), "[ERROR] Invalid engine : %s", path); + SECURE_SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Invalid engine : %s", path); tts_parser_free_engine_info(temp); return -1; } @@ -229,7 +257,7 @@ int tts_parser_get_engine_info(const char* path, tts_engine_info_s** engine_info int tts_parser_free_engine_info(tts_engine_info_s* engine_info) { if (NULL == engine_info) { - SLOG(LOG_ERROR, tts_tag(), "[ERROR] Input parameter is NULL"); + SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Input parameter is NULL"); return -1; } @@ -274,17 +302,17 @@ int tts_parser_free_engine_info(tts_engine_info_s* engine_info) int tts_parser_print_engine_info(tts_engine_info_s* engine_info) { if (NULL == engine_info) { - SLOG(LOG_ERROR, tts_tag(), "[ERROR] Input parameter is NULL"); + SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Input parameter is NULL"); return -1; } - SLOG(LOG_DEBUG, tts_tag(), "== get engine info =="); - SLOG(LOG_DEBUG, tts_tag(), " name : %s", engine_info->name); - SLOG(LOG_DEBUG, tts_tag(), " id : %s", engine_info->uuid); + SLOG(LOG_DEBUG, TAG_TTSCONFIG, "== get engine info =="); + SLOG(LOG_DEBUG, TAG_TTSCONFIG, " name : %s", engine_info->name); + SLOG(LOG_DEBUG, TAG_TTSCONFIG, " id : %s", engine_info->uuid); if (NULL != engine_info->setting) - SLOG(LOG_DEBUG, tts_tag(), " setting : %s", engine_info->setting); + SLOG(LOG_DEBUG, TAG_TTSCONFIG, " setting : %s", engine_info->setting); - SLOG(LOG_DEBUG, tts_tag(), " voices"); + SLOG(LOG_DEBUG, TAG_TTSCONFIG, " voices"); GSList *iter = NULL; tts_config_voice_s *temp_voice; @@ -297,7 +325,7 @@ int tts_parser_print_engine_info(tts_engine_info_s* engine_info) /*Get handle data from list*/ temp_voice = iter->data; - SLOG(LOG_DEBUG, tts_tag(), " [%dth] type(%d) lang(%s)", + SLOG(LOG_DEBUG, TAG_TTSCONFIG, " [%dth] type(%d) lang(%s)", i, temp_voice->type, temp_voice->language); /*Get next item*/ @@ -305,10 +333,10 @@ int tts_parser_print_engine_info(tts_engine_info_s* engine_info) i++; } } else { - SLOG(LOG_ERROR, tts_tag(), " Voice is NONE"); + SLOG(LOG_ERROR, TAG_TTSCONFIG, " Voice is NONE"); } - SLOG(LOG_DEBUG, tts_tag(), "====================="); + SLOG(LOG_DEBUG, TAG_TTSCONFIG, "@@@"); return 0; } @@ -316,7 +344,7 @@ int tts_parser_print_engine_info(tts_engine_info_s* engine_info) int tts_parser_load_config(tts_config_s** config_info) { if (NULL == config_info) { - SLOG(LOG_ERROR, tts_tag(), "[ERROR] Input parameter is NULL"); + SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Input parameter is NULL"); return -1; } @@ -331,7 +359,7 @@ int tts_parser_load_config(tts_config_s** config_info) if (0 != access(TTS_CONFIG, F_OK)) { doc = xmlParseFile(TTS_DEFAULT_CONFIG); if (doc == NULL) { - SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to parse file error : %s", TTS_DEFAULT_CONFIG); + SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to parse file error : %s", TTS_DEFAULT_CONFIG); xmlCleanupParser(); return -1; } @@ -348,16 +376,22 @@ int tts_parser_load_config(tts_config_s** config_info) usleep(10000); if (TTS_RETRY_COUNT == retry_count) { - SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to parse file error : %s", TTS_CONFIG); - xmlCleanupParser(); - return -1; + SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to parse file error : %s", TTS_CONFIG); + doc = xmlParseFile(TTS_DEFAULT_CONFIG); + if (NULL == doc) { + SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to parse file error : %s", TTS_DEFAULT_CONFIG); + xmlCleanupParser(); + return -1; + } + is_default_open = true; + break; } } } cur = xmlDocGetRootElement(doc); if (cur == NULL) { - SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document"); + SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Empty document(%p)", doc); xmlFreeDoc(doc); doc = NULL; xmlCleanupParser(); @@ -365,7 +399,7 @@ int tts_parser_load_config(tts_config_s** config_info) } if (xmlStrcmp(cur->name, (const xmlChar *) TTS_TAG_CONFIG_BASE_TAG)) { - SLOG(LOG_ERROR, tts_tag(), "[ERROR] The wrong type, root node is NOT %s", TTS_TAG_CONFIG_BASE_TAG); + SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] The wrong type, root node is NOT %s. doc(%p)", TTS_TAG_CONFIG_BASE_TAG, doc); xmlFreeDoc(doc); doc = NULL; xmlCleanupParser(); @@ -374,7 +408,7 @@ int tts_parser_load_config(tts_config_s** config_info) cur = cur->xmlChildrenNode; if (cur == NULL) { - SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document"); + SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Empty document(%p)", doc); xmlFreeDoc(doc); doc = NULL; xmlCleanupParser(); @@ -385,43 +419,39 @@ int tts_parser_load_config(tts_config_s** config_info) tts_config_s* temp; temp = (tts_config_s*)calloc(1, sizeof(tts_config_s)); if (NULL == temp) { - SLOG(LOG_ERROR, tts_tag(), "[ERROR] Out of memory"); + SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Out of memory(%p)", doc); xmlFreeDoc(doc); doc = NULL; xmlCleanupParser(); return -1; } - temp->engine_id = NULL; - temp->setting = NULL; - temp->language = NULL; + memset(g_engine_id, '\0', sizeof(g_engine_id)); + memset(g_setting, '\0', sizeof(g_setting)); + memset(g_language, '\0', sizeof(g_language)); + + temp->engine_id = g_engine_id; + temp->setting = g_setting; + temp->language = g_language; while (cur != NULL) { if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_ENGINE_ID)) { key = xmlNodeGetContent(cur); if (NULL != key) { - if (NULL != temp->engine_id) { - free(temp->engine_id); - temp->engine_id = NULL; - } - temp->engine_id = strdup((char*)key); + strncpy(temp->engine_id, (char*)key, sizeof(g_engine_id) - 1); xmlFree(key); key = NULL; } else { - SLOG(LOG_ERROR, tts_tag(), "[ERROR] engine id is NULL"); + SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] engine id is NULL"); } } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_ENGINE_SETTING)) { key = xmlNodeGetContent(cur); if (NULL != key) { - if (NULL != temp->setting) { - free(temp->setting); - temp->setting = NULL; - } - temp->setting = strdup((char*)key); + strncpy(temp->setting, (char*)key, sizeof(g_setting) - 1); xmlFree(key); key = NULL; } else { - SLOG(LOG_ERROR, tts_tag(), "[ERROR] setting path is NULL"); + SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] setting path is NULL"); } } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_AUTO_VOICE)) { key = xmlNodeGetContent(cur); @@ -431,14 +461,14 @@ int tts_parser_load_config(tts_config_s** config_info) } else if (0 == xmlStrcmp(key, (const xmlChar *)"off")) { temp->auto_voice = false; } else { - SLOG(LOG_ERROR, tts_tag(), "Auto voice is wrong"); + SLOG(LOG_ERROR, TAG_TTSCONFIG, "Auto voice is wrong"); temp->auto_voice = true; } xmlFree(key); key = NULL; } else { - SLOG(LOG_ERROR, tts_tag(), "[ERROR] voice type is NULL"); + SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] voice type is NULL"); } } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_VOICE_TYPE)) { key = xmlNodeGetContent(cur); @@ -450,27 +480,23 @@ int tts_parser_load_config(tts_config_s** config_info) } else if (0 == xmlStrcmp(key, (const xmlChar *)TTS_TAG_VOICE_TYPE_CHILD)) { temp->type = (int)TTS_CONFIG_VOICE_TYPE_CHILD; } else { - SLOG(LOG_WARN, tts_tag(), "Voice type is user defined"); + SLOG(LOG_WARN, TAG_TTSCONFIG, "Voice type is user defined"); temp->type = (int)TTS_CONFIG_VOICE_TYPE_USER_DEFINED; } xmlFree(key); key = NULL; } else { - SLOG(LOG_ERROR, tts_tag(), "[ERROR] voice type is NULL"); + SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] voice type is NULL"); } } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_LANGUAGE)) { key = xmlNodeGetContent(cur); if (NULL != key) { - if (NULL != temp->language) { - free(temp->language); - temp->language = NULL; - } - temp->language = strdup((char*)key); + strncpy(temp->language, (char*)key, sizeof(g_language) - 1); xmlFree(key); key = NULL; } else { - SLOG(LOG_ERROR, tts_tag(), "[ERROR] engine uuid is NULL"); + SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] engine uuid is NULL"); } } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_SPEECH_RATE)) { @@ -479,7 +505,7 @@ int tts_parser_load_config(tts_config_s** config_info) temp->speech_rate = atoi((char*)key); xmlFree(key); } else { - SLOG(LOG_ERROR, tts_tag(), "[ERROR] speech rate is NULL"); + SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] speech rate is NULL"); } } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_PITCH)) { key = xmlNodeGetContent(cur); @@ -488,7 +514,7 @@ int tts_parser_load_config(tts_config_s** config_info) xmlFree(key); key = NULL; } else { - SLOG(LOG_ERROR, tts_tag(), "[ERROR] Pitch is NULL"); + SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Pitch is NULL"); } } else { @@ -501,21 +527,31 @@ int tts_parser_load_config(tts_config_s** config_info) g_config_doc = doc; if (true == is_default_open) { - int ret = xmlSaveFile(TTS_CONFIG, g_config_doc); - if (0 > ret) { - SLOG(LOG_ERROR, tts_tag(), "[ERROR] Save result : %d", ret); - } + int retry_count = 0; + int ret = -1; + do { + ret = xmlSaveFile(TTS_CONFIG, g_config_doc); + if (0 < ret) + break; + retry_count++; + usleep(10000); + + if (TTS_RETRY_COUNT == retry_count) { + SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Save result : %d", ret); + return -1; + } + } while (0 != ret); /* Set mode */ - if (0 > chmod(TTS_CONFIG, 0666)) { - SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to change file mode : %d", ret); + if (0 > chmod(TTS_CONFIG, 0600)) { + SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to change file mode : %d", ret); } /* Set owner */ if (0 > chown(TTS_CONFIG, 5000, 5000)) { - SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to change file owner : %d", ret); + SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to change file owner : %d", ret); } - SLOG(LOG_DEBUG, tts_tag(), "Default config is changed : pid(%d)", getpid()); + SLOG(LOG_DEBUG, TAG_TTSCONFIG, "Default config is changed : pid(%d)", getpid()); } return 0; @@ -524,22 +560,12 @@ int tts_parser_load_config(tts_config_s** config_info) int tts_parser_unload_config(tts_config_s* config_info) { if (NULL != g_config_doc) { + SLOG(LOG_ERROR, TAG_TTSCONFIG, "[DEBUG] Free g_config_doc(%p)", g_config_doc); xmlFreeDoc(g_config_doc); g_config_doc = NULL; } if (NULL != config_info) { - if (NULL != config_info->engine_id) { - free(config_info->engine_id); - config_info->engine_id = NULL; - } - if (NULL != config_info->setting) { - free(config_info->setting); - config_info->setting = NULL; - } - if (NULL != config_info->language) { - free(config_info->language); - config_info->language = NULL; - } + SLOG(LOG_ERROR, TAG_TTSCONFIG, "[DEBUG] Free config_info(%p)", config_info); free(config_info); config_info = NULL; } @@ -553,30 +579,53 @@ int tts_parser_unload_config(tts_config_s* config_info) int tts_parser_copy_xml(const char* original, const char* destination) { if (NULL == original || NULL == destination) { - SLOG(LOG_ERROR, tts_tag(), "[ERROR] Input parameter is NULL"); + SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Input parameter is NULL"); return -1; } xmlDocPtr doc = NULL; - doc = xmlParseFile(original); - if (doc == NULL) { - SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to parse file error : %s", original); + if (0 == access(original, F_OK)) { + SLOG(LOG_DEBUG, TAG_TTSCONFIG, "[DEBUG] Success to access to %s", original); + doc = xmlParseFile(original); + if (doc == NULL) { + SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to parse file error : %s", original); + return -1; + } + } else { + SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to access to %s", original); return -1; } int ret = xmlSaveFile(destination, doc); if (0 > ret) { - SLOG(LOG_ERROR, tts_tag(), "[ERROR] Save result : %d", ret); + SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Save result : %d", ret); + } else { + static FILE* pFile; + pFile = fopen(destination, "r"); + int fd = -1; + if (NULL == pFile) { + SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to open file %s", destination); + } else { + fd = fileno(pFile); + fsync(fd); + fclose(pFile); + SLOG(LOG_INFO, TAG_TTSCONFIG, "[DEBUG] Success to fsync %s", destination); + } + SLOG(LOG_ERROR, TAG_TTSCONFIG, "[DEBUG] Success to save %s", destination); } /* Set mode */ - if (0 > chmod(destination, 0666)) { - SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to change file mode : %d", ret); + if (0 > chmod(destination, 0600)) { + SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to change file mode : %d", ret); + } + + if (NULL != doc) { + SLOG(LOG_ERROR, TAG_TTSCONFIG, "[DEBUG] doc(%p)", doc); + xmlFreeDoc(doc); + doc = NULL; } - xmlFreeDoc(doc); - doc = NULL; - SLOG(LOG_DEBUG, tts_tag(), "[SUCCESS] Copying xml"); + SLOG(LOG_DEBUG, TAG_TTSCONFIG, "[SUCCESS] Copying xml"); return 0; } @@ -584,25 +633,25 @@ int tts_parser_copy_xml(const char* original, const char* destination) int tts_parser_set_engine(const char* engine_id, const char* setting, const char* language, int type) { if (NULL == engine_id) { - SLOG(LOG_ERROR, tts_tag(), "[ERROR] Input parameter is NULL"); + SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Input parameter is NULL"); return -1; } xmlNodePtr cur = NULL; cur = xmlDocGetRootElement(g_config_doc); if (cur == NULL) { - SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document"); + SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Empty document"); return -1; } if (xmlStrcmp(cur->name, (const xmlChar *) TTS_TAG_CONFIG_BASE_TAG)) { - SLOG(LOG_ERROR, tts_tag(), "[ERROR] The wrong type, root node is NOT %s", TTS_TAG_CONFIG_BASE_TAG); + SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] The wrong type, root node is NOT %s", TTS_TAG_CONFIG_BASE_TAG); return -1; } cur = cur->xmlChildrenNode; if (cur == NULL) { - SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document"); + SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Empty document"); return -1; } @@ -631,9 +680,26 @@ int tts_parser_set_engine(const char* engine_id, const char* setting, const char cur = cur->next; } - int ret = xmlSaveFile(TTS_CONFIG, g_config_doc); - if (0 > ret) { - SLOG(LOG_ERROR, tts_tag(), "[ERROR] Save result : %d", ret); + if (0 == access(TTS_CONFIG, F_OK)) { + int ret = xmlSaveFile(TTS_CONFIG, g_config_doc); + if (0 > ret) { + SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Save result : %d", ret); + } else { + static FILE* pFile; + pFile = fopen(TTS_CONFIG, "r"); + int fd = -1; + if (NULL == pFile) { + SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to open file %s", TTS_CONFIG); + } else { + fd = fileno(pFile); + fsync(fd); + fclose(pFile); + SLOG(LOG_INFO, TAG_TTSCONFIG, "[DEBUG] Success to fsync %s", TTS_CONFIG); + } + SLOG(LOG_ERROR, TAG_TTSCONFIG, "[DEBUG] Success to save %s", TTS_CONFIG); + } + } else { + SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to access to %s", TTS_CONFIG); } return 0; @@ -642,32 +708,32 @@ int tts_parser_set_engine(const char* engine_id, const char* setting, const char int tts_parser_set_voice(const char* language, int type) { if (NULL == language) { - SLOG(LOG_ERROR, tts_tag(), "[ERROR] Input parameter is NULL"); + SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Input parameter is NULL"); return -1; } xmlNodePtr cur = NULL; cur = xmlDocGetRootElement(g_config_doc); if (cur == NULL) { - SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document"); + SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Empty document"); return -1; } if (xmlStrcmp(cur->name, (const xmlChar *) TTS_TAG_CONFIG_BASE_TAG)) { - SLOG(LOG_ERROR, tts_tag(), "[ERROR] The wrong type, root node is NOT %s", TTS_TAG_CONFIG_BASE_TAG); + SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] The wrong type, root node is NOT %s", TTS_TAG_CONFIG_BASE_TAG); return -1; } cur = cur->xmlChildrenNode; if (cur == NULL) { - SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document"); + SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Empty document"); return -1; } while (cur != NULL) { if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_LANGUAGE)) { xmlNodeSetContent(cur, (const xmlChar *)language); - } + } if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_VOICE_TYPE)) { switch (type) { @@ -675,7 +741,7 @@ int tts_parser_set_voice(const char* language, int type) case TTS_CONFIG_VOICE_TYPE_FEMALE: xmlNodeSetContent(cur, (const xmlChar*)TTS_TAG_VOICE_TYPE_FEMALE); break; case TTS_CONFIG_VOICE_TYPE_CHILD: xmlNodeSetContent(cur, (const xmlChar*)TTS_TAG_VOICE_TYPE_CHILD); break; default: - SLOG(LOG_ERROR, tts_tag(), "[ERROR] Invalid type : %d", type); + SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Invalid type : %d", type); xmlNodeSetContent(cur, (const xmlChar*)TTS_TAG_VOICE_TYPE_FEMALE); break; } @@ -684,11 +750,27 @@ int tts_parser_set_voice(const char* language, int type) cur = cur->next; } - int ret = xmlSaveFile(TTS_CONFIG, g_config_doc); - if (0 > ret) { - SLOG(LOG_ERROR, tts_tag(), "[ERROR] Save result : %d", ret); + if (0 == access(TTS_CONFIG, F_OK)) { + int ret = xmlSaveFile(TTS_CONFIG, g_config_doc); + if (0 > ret) { + SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Save result : %d", ret); + } else { + static FILE* pFile; + pFile = fopen(TTS_CONFIG, "r"); + int fd = -1; + if (NULL == pFile) { + SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to open file %s", TTS_CONFIG); + } else { + fd = fileno(pFile); + fsync(fd); + fclose(pFile); + SLOG(LOG_INFO, TAG_TTSCONFIG, "[DEBUG] Success to fsync %s", TTS_CONFIG); + } + SLOG(LOG_ERROR, TAG_TTSCONFIG, "[DEBUG] Success to save %s", TTS_CONFIG); + } + } else { + SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to access to %s", TTS_CONFIG); } - return 0; } @@ -697,18 +779,18 @@ int tts_parser_set_auto_voice(bool value) xmlNodePtr cur = NULL; cur = xmlDocGetRootElement(g_config_doc); if (cur == NULL) { - SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document"); + SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Empty document"); return -1; } if (xmlStrcmp(cur->name, (const xmlChar *) TTS_TAG_CONFIG_BASE_TAG)) { - SLOG(LOG_ERROR, tts_tag(), "[ERROR] The wrong type, root node is NOT %s", TTS_TAG_CONFIG_BASE_TAG); + SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] The wrong type, root node is NOT %s", TTS_TAG_CONFIG_BASE_TAG); return -1; } cur = cur->xmlChildrenNode; if (cur == NULL) { - SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document"); + SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Empty document"); return -1; } @@ -719,7 +801,7 @@ int tts_parser_set_auto_voice(bool value) } else if (false == value) { xmlNodeSetContent(cur, (const xmlChar *)"off"); } else { - SLOG(LOG_ERROR, tts_tag(), "[ERROR] The wrong value of auto voice"); + SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] The wrong value of auto voice"); return -1; } break; @@ -727,9 +809,26 @@ int tts_parser_set_auto_voice(bool value) cur = cur->next; } - int ret = xmlSaveFile(TTS_CONFIG, g_config_doc); - if (0 > ret) { - SLOG(LOG_ERROR, tts_tag(), "[ERROR] Save result : %d", ret); + if (0 == access(TTS_CONFIG, F_OK)) { + int ret = xmlSaveFile(TTS_CONFIG, g_config_doc); + if (0 > ret) { + SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Save result : %d", ret); + } else { + static FILE* pFile; + pFile = fopen(TTS_CONFIG, "r"); + int fd = -1; + if (NULL == pFile) { + SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to open file %s", TTS_CONFIG); + } else { + fd = fileno(pFile); + fsync(fd); + fclose(pFile); + SLOG(LOG_INFO, TAG_TTSCONFIG, "[DEBUG] Success to fsync %s", TTS_CONFIG); + } + SLOG(LOG_ERROR, TAG_TTSCONFIG, "[DEBUG] Success to save %s", TTS_CONFIG); + } + } else { + SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to access to %s", TTS_CONFIG); } return 0; @@ -740,18 +839,18 @@ int tts_parser_set_speech_rate(int value) xmlNodePtr cur = NULL; cur = xmlDocGetRootElement(g_config_doc); if (cur == NULL) { - SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document"); + SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Empty document"); return -1; } if (xmlStrcmp(cur->name, (const xmlChar *) TTS_TAG_CONFIG_BASE_TAG)) { - SLOG(LOG_ERROR, tts_tag(), "[ERROR] The wrong type, root node is NOT %s", TTS_TAG_CONFIG_BASE_TAG); + SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] The wrong type, root node is NOT %s", TTS_TAG_CONFIG_BASE_TAG); return -1; } cur = cur->xmlChildrenNode; if (cur == NULL) { - SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document"); + SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Empty document"); return -1; } @@ -763,16 +862,33 @@ int tts_parser_set_speech_rate(int value) xmlNodeSetContent(cur, (const xmlChar *)temp); - SLOG(LOG_DEBUG, tts_tag(), "Set speech rate : %s", temp); + SLOG(LOG_DEBUG, TAG_TTSCONFIG, "Set speech rate : %s", temp); break; } cur = cur->next; } - int ret = xmlSaveFile(TTS_CONFIG, g_config_doc); - if (0 > ret) { - SLOG(LOG_ERROR, tts_tag(), "[ERROR] Save result : %d", ret); + if (0 == access(TTS_CONFIG, F_OK)) { + int ret = xmlSaveFile(TTS_CONFIG, g_config_doc); + if (0 > ret) { + SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Save result : %d", ret); + } else { + static FILE* pFile; + pFile = fopen(TTS_CONFIG, "r"); + int fd = -1; + if (NULL == pFile) { + SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to open file %s", TTS_CONFIG); + } else { + fd = fileno(pFile); + fsync(fd); + fclose(pFile); + SLOG(LOG_INFO, TAG_TTSCONFIG, "[DEBUG] Success to fsync %s", TTS_CONFIG); + } + SLOG(LOG_ERROR, TAG_TTSCONFIG, "[DEBUG] Success to save %s", TTS_CONFIG); + } + } else { + SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to access to %s", TTS_CONFIG); } return 0; @@ -783,18 +899,18 @@ int tts_parser_set_pitch(int value) xmlNodePtr cur = NULL; cur = xmlDocGetRootElement(g_config_doc); if (cur == NULL) { - SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document"); + SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Empty document"); return -1; } if (xmlStrcmp(cur->name, (const xmlChar *) TTS_TAG_CONFIG_BASE_TAG)) { - SLOG(LOG_ERROR, tts_tag(), "[ERROR] The wrong type, root node is NOT %s", TTS_TAG_CONFIG_BASE_TAG); + SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] The wrong type, root node is NOT %s", TTS_TAG_CONFIG_BASE_TAG); return -1; } cur = cur->xmlChildrenNode; if (cur == NULL) { - SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document"); + SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Empty document"); return -1; } @@ -805,14 +921,31 @@ int tts_parser_set_pitch(int value) snprintf(temp, 10, "%d", value); xmlNodeSetContent(cur, (const xmlChar *)temp); break; - } + } cur = cur->next; } - int ret = xmlSaveFile(TTS_CONFIG, g_config_doc); - if (0 > ret) { - SLOG(LOG_ERROR, tts_tag(), "[ERROR] Save result : %d", ret); + if (0 == access(TTS_CONFIG, F_OK)) { + int ret = xmlSaveFile(TTS_CONFIG, g_config_doc); + if (0 > ret) { + SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Save result : %d", ret); + } else { + static FILE* pFile; + pFile = fopen(TTS_CONFIG, "r"); + int fd = -1; + if (NULL == pFile) { + SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to open file %s", TTS_CONFIG); + } else { + fd = fileno(pFile); + fsync(fd); + fclose(pFile); + SLOG(LOG_INFO, TAG_TTSCONFIG, "[DEBUG] Success to fsync %s", TTS_CONFIG); + } + SLOG(LOG_ERROR, TAG_TTSCONFIG, "[DEBUG] Success to save %s", TTS_CONFIG); + } + } else { + SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to access to %s", TTS_CONFIG); } return 0; @@ -822,7 +955,7 @@ int tts_parser_find_config_changed(char** engine, char**setting, bool* auto_voic int* speech_rate, int* pitch) { if (NULL == engine || NULL == setting || NULL == language || NULL == voice_type || NULL == speech_rate) { - SLOG(LOG_ERROR, tts_tag(), "[ERROR] Input parameter is NULL"); + SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Input parameter is NULL"); return -1; } @@ -835,15 +968,18 @@ int tts_parser_find_config_changed(char** engine, char**setting, bool* auto_voic int retry_count = 0; while (NULL == doc) { - doc = xmlParseFile(TTS_CONFIG); - if (NULL != doc) { - break; + if (0 == access(TTS_CONFIG, F_OK)) { + SLOG(LOG_DEBUG, TAG_TTSCONFIG, "[DEBUG] Success to access to %s", TTS_CONFIG); + doc = xmlParseFile(TTS_CONFIG); + if (NULL != doc) { + break; + } } retry_count++; usleep(10000); if (TTS_RETRY_COUNT == retry_count) { - SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to parse file error : %s", TTS_CONFIG); + SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to parse file error : %s", TTS_CONFIG); return -1; } } @@ -851,7 +987,7 @@ int tts_parser_find_config_changed(char** engine, char**setting, bool* auto_voic cur_new = xmlDocGetRootElement(doc); cur_old = xmlDocGetRootElement(g_config_doc); if (cur_new == NULL || cur_old == NULL) { - SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document"); + SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Empty document(%p)", doc); xmlFreeDoc(doc); doc = NULL; return -1; @@ -859,7 +995,7 @@ int tts_parser_find_config_changed(char** engine, char**setting, bool* auto_voic if (xmlStrcmp(cur_new->name, (const xmlChar*)TTS_TAG_CONFIG_BASE_TAG) || xmlStrcmp(cur_old->name, (const xmlChar*)TTS_TAG_CONFIG_BASE_TAG)) { - SLOG(LOG_ERROR, tts_tag(), "[ERROR] The wrong type, root node is NOT %s", TTS_TAG_CONFIG_BASE_TAG); + SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] The wrong type, root node is NOT %s. doc(%p)", TTS_TAG_CONFIG_BASE_TAG, doc); xmlFreeDoc(doc); doc = NULL; return -1; @@ -868,7 +1004,7 @@ int tts_parser_find_config_changed(char** engine, char**setting, bool* auto_voic cur_new = cur_new->xmlChildrenNode; cur_old = cur_old->xmlChildrenNode; if (cur_new == NULL || cur_old == NULL) { - SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document"); + SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Empty document(%p)", doc); xmlFreeDoc(doc); doc = NULL; return -1; @@ -882,7 +1018,7 @@ int tts_parser_find_config_changed(char** engine, char**setting, bool* auto_voic key_new = xmlNodeGetContent(cur_new); if (NULL != key_new) { if (0 != xmlStrcmp(key_old, key_new)) { - SLOG(LOG_DEBUG, tts_tag(), "Old engine id(%s), New engine(%s)", + SLOG(LOG_DEBUG, TAG_TTSCONFIG, "Old engine id(%s), New engine(%s)", (char*)key_old, (char*)key_new); if (NULL != *engine) { free(*engine); @@ -897,7 +1033,7 @@ int tts_parser_find_config_changed(char** engine, char**setting, bool* auto_voic key_old = NULL; } } else { - SLOG(LOG_ERROR, tts_tag(), "[ERROR] old config and new config are different"); + 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_old->name, (const xmlChar*)TTS_TAG_CONFIG_ENGINE_SETTING)) { @@ -906,7 +1042,7 @@ int tts_parser_find_config_changed(char** engine, char**setting, bool* auto_voic key_new = xmlNodeGetContent(cur_new); if (NULL != key_new) { if (0 != xmlStrcmp(key_old, key_new)) { - SLOG(LOG_DEBUG, tts_tag(), "Old engine setting(%s), New engine setting(%s)", + SLOG(LOG_DEBUG, TAG_TTSCONFIG, "Old engine setting(%s), New engine setting(%s)", (char*)key_old, (char*)key_new); if (NULL != *setting) { free(*setting); @@ -921,7 +1057,7 @@ int tts_parser_find_config_changed(char** engine, char**setting, bool* auto_voic key_old = NULL; } } else { - SLOG(LOG_ERROR, tts_tag(), "[ERROR] old config and new config are different"); + 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_AUTO_VOICE)) { if (0 == xmlStrcmp(cur_old->name, (const xmlChar*)TTS_TAG_CONFIG_AUTO_VOICE)) { @@ -930,7 +1066,7 @@ int tts_parser_find_config_changed(char** engine, char**setting, bool* auto_voic key_new = xmlNodeGetContent(cur_new); if (NULL != key_new) { if (0 != xmlStrcmp(key_old, key_new)) { - SLOG(LOG_DEBUG, tts_tag(), "Old auto voice (%s), New auto voice(%s)", + SLOG(LOG_DEBUG, TAG_TTSCONFIG, "Old auto voice (%s), New auto voice(%s)", (char*)key_old, (char*)key_new); if (0 == xmlStrcmp((const xmlChar*)"on", key_new)) { *auto_voice = true; @@ -945,7 +1081,7 @@ int tts_parser_find_config_changed(char** engine, char**setting, bool* auto_voic key_old = NULL; } } else { - SLOG(LOG_ERROR, tts_tag(), "[ERROR] old config and new config are different"); + 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_LANGUAGE)) { if (0 == xmlStrcmp(cur_old->name, (const xmlChar*)TTS_TAG_CONFIG_LANGUAGE)) { @@ -954,7 +1090,7 @@ int tts_parser_find_config_changed(char** engine, char**setting, bool* auto_voic key_new = xmlNodeGetContent(cur_new); if (NULL != key_new) { if (0 != xmlStrcmp(key_old, key_new)) { - SLOG(LOG_DEBUG, tts_tag(), "Old language(%s), New language(%s)", + SLOG(LOG_DEBUG, TAG_TTSCONFIG, "Old language(%s), New language(%s)", (char*)key_old, (char*)key_new); if (NULL != *language) { free(*language); @@ -969,7 +1105,7 @@ int tts_parser_find_config_changed(char** engine, char**setting, bool* auto_voic key_old = NULL; } } else { - SLOG(LOG_ERROR, tts_tag(), "[ERROR] old config and new config are different"); + 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_VOICE_TYPE)) { if (0 == xmlStrcmp(cur_old->name, (const xmlChar*)TTS_TAG_CONFIG_VOICE_TYPE)) { @@ -978,7 +1114,7 @@ int tts_parser_find_config_changed(char** engine, char**setting, bool* auto_voic key_new = xmlNodeGetContent(cur_new); if (NULL != key_new) { if (0 != xmlStrcmp(key_old, key_new)) { - SLOG(LOG_DEBUG, tts_tag(), "Old voice type(%s), New voice type(%s)", + SLOG(LOG_DEBUG, TAG_TTSCONFIG, "Old voice type(%s), New voice type(%s)", (char*)key_old, (char*)key_new); if (0 == xmlStrcmp(key_new, (const xmlChar *)TTS_TAG_VOICE_TYPE_FEMALE)) { *voice_type = (int)TTS_CONFIG_VOICE_TYPE_FEMALE; @@ -987,7 +1123,7 @@ int tts_parser_find_config_changed(char** engine, char**setting, bool* auto_voic } else if (0 == xmlStrcmp(key_new, (const xmlChar *)TTS_TAG_VOICE_TYPE_CHILD)) { *voice_type = (int)TTS_CONFIG_VOICE_TYPE_CHILD; } else { - SLOG(LOG_ERROR, tts_tag(), "[ERROR] New voice type is not valid"); + SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] New voice type is not valid"); } } xmlFree(key_new); @@ -997,7 +1133,7 @@ int tts_parser_find_config_changed(char** engine, char**setting, bool* auto_voic key_old = NULL; } } else { - SLOG(LOG_ERROR, tts_tag(), "[ERROR] old config and new config are different"); + 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_SPEECH_RATE)) { if (0 == xmlStrcmp(cur_old->name, (const xmlChar*)TTS_TAG_CONFIG_SPEECH_RATE)) { @@ -1006,7 +1142,7 @@ int tts_parser_find_config_changed(char** engine, char**setting, bool* auto_voic key_new = xmlNodeGetContent(cur_new); if (NULL != key_new) { if (0 != xmlStrcmp(key_old, key_new)) { - SLOG(LOG_DEBUG, tts_tag(), "Old speech rate(%s), New speech rate(%s)", + SLOG(LOG_DEBUG, TAG_TTSCONFIG, "Old speech rate(%s), New speech rate(%s)", (char*)key_old, (char*)key_new); *speech_rate = atoi((char*)key_new); } @@ -1017,7 +1153,7 @@ int tts_parser_find_config_changed(char** engine, char**setting, bool* auto_voic key_old = NULL; } } else { - SLOG(LOG_ERROR, tts_tag(), "[ERROR] old config and new config are different"); + 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_PITCH)) { if (0 == xmlStrcmp(cur_old->name, (const xmlChar*)TTS_TAG_CONFIG_PITCH)) { @@ -1026,7 +1162,7 @@ int tts_parser_find_config_changed(char** engine, char**setting, bool* auto_voic key_new = xmlNodeGetContent(cur_new); if (NULL != key_new) { if (0 != xmlStrcmp(key_old, key_new)) { - SLOG(LOG_DEBUG, tts_tag(), "Old pitch(%s), New pitch(%s)", + SLOG(LOG_DEBUG, TAG_TTSCONFIG, "Old pitch(%s), New pitch(%s)", (char*)key_old, (char*)key_new); *pitch = atoi((char*)key_new); } @@ -1037,7 +1173,7 @@ int tts_parser_find_config_changed(char** engine, char**setting, bool* auto_voic key_old = NULL; } } else { - SLOG(LOG_ERROR, tts_tag(), "[ERROR] old config and new config are different"); + SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] old config and new config are different"); } } else { @@ -1048,6 +1184,7 @@ int tts_parser_find_config_changed(char** engine, char**setting, bool* auto_voic } if (NULL != g_config_doc) { + SLOG(LOG_ERROR, TAG_TTSCONFIG, "[DEBUG] Free g_config_doc(%p)", g_config_doc); xmlFreeDoc(g_config_doc); g_config_doc = NULL; } @@ -1055,3 +1192,44 @@ int tts_parser_find_config_changed(char** engine, char**setting, bool* auto_voic return 0; } + +int tts_parser_reset() +{ + SLOG(LOG_DEBUG, TAG_TTSCONFIG, "[DEBUG] Reset g_config_doc as %s", TTS_DEFAULT_CONFIG); + + if (NULL != g_config_doc) { + SLOG(LOG_ERROR, TAG_TTSCONFIG, "[DEBUG] Free g_config_doc(%p)", g_config_doc); + xmlFreeDoc(g_config_doc); + g_config_doc = NULL; + } + + g_config_doc = xmlParseFile(TTS_DEFAULT_CONFIG); + if (NULL == g_config_doc) { + SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to parse %s", TTS_DEFAULT_CONFIG); + return -1; + } + + if (0 == access(TTS_CONFIG, F_OK)) { + int ret = xmlSaveFile(TTS_CONFIG, g_config_doc); + if (0 > ret) { + SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to save %s", TTS_CONFIG); + } else { + static FILE* pFile; + pFile = fopen(TTS_CONFIG, "r"); + int fd = -1; + if (NULL == pFile) { + SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to open file %s", TTS_CONFIG); + } else { + fd = fileno(pFile); + fsync(fd); + fclose(pFile); + SLOG(LOG_INFO, TAG_TTSCONFIG, "[DEBUG] Success to fsync %s", TTS_CONFIG); + } + SLOG(LOG_ERROR, TAG_TTSCONFIG, "[DEBUG] Success to save %s", TTS_CONFIG); + } + } else { + SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to access to %s", TTS_CONFIG); + } + + return 0; +}