From f09e5290b213b4bb7f6f2bdf49188008e363aec6 Mon Sep 17 00:00:00 2001 From: "sooyeon.kim" Date: Tue, 2 Jan 2018 11:47:44 +0900 Subject: [PATCH] Add to check RW config file and reset config info Change-Id: I44a3bad303a76c5759182cd2a75b975bf4c8a995 Signed-off-by: sooyeon.kim (cherry picked from commit 235a24ea1ec48f252c47df8b6281df79a3be520d) --- common/tts_config_mgr.c | 8 +++++--- common/tts_config_parser.c | 39 +++++++++++++++++++++++++++++++++++++-- common/tts_config_parser.h | 2 ++ 3 files changed, 44 insertions(+), 5 deletions(-) diff --git a/common/tts_config_mgr.c b/common/tts_config_mgr.c index 21ccd8a..1522950 100644 --- a/common/tts_config_mgr.c +++ b/common/tts_config_mgr.c @@ -495,9 +495,11 @@ Eina_Bool tts_config_mgr_inotify_event_cb(void* data, Ecore_Fd_Handler *fd_handl free(lang); lang = NULL; } - } else if (IN_IGNORED == event.mask) { - SLOG(LOG_ERROR, tts_tag(), "[ERROR] IN_IGNORED event"); + } else if (IN_DELETE_SELF == event.mask) { + SLOG(LOG_ERROR, tts_tag(), "[ERROR] IN_DELETE_SELF event"); + tts_parser_unload_config(g_config_info); + tts_parser_reset(); tts_parser_load_config(&g_config_info); } else { SLOG(LOG_ERROR, tts_tag(), "[ERROR] Undefined event (0x%x)", event.mask); @@ -521,7 +523,7 @@ int __tts_config_mgr_register_config_event() } g_config_fd_noti = fd; - wd = inotify_add_watch(fd, TTS_CONFIG, IN_CLOSE_WRITE); + wd = inotify_add_watch(fd, TTS_CONFIG, IN_CLOSE_WRITE|IN_DELETE_SELF); g_config_wd_noti = wd; g_config_fd_handler_noti = ecore_main_fd_handler_add(fd, ECORE_FD_READ, diff --git a/common/tts_config_parser.c b/common/tts_config_parser.c index a042797..fe31e24 100644 --- a/common/tts_config_parser.c +++ b/common/tts_config_parser.c @@ -584,6 +584,8 @@ int tts_parser_copy_xml(const char* original, const char* destination) int ret = xmlSaveFile(destination, doc); if (0 > ret) { SLOG(LOG_ERROR, tts_tag(), "[ERROR] Save result : %d", ret); + } else { + SLOG(LOG_DEBUG, tts_tag(), "[DEBUG] Success to save %s", destination); } /* Set mode */ @@ -651,6 +653,8 @@ int tts_parser_set_engine(const char* engine_id, const char* setting, const char int ret = xmlSaveFile(TTS_CONFIG, g_config_doc); if (0 > ret) { SLOG(LOG_ERROR, tts_tag(), "[ERROR] Save result : %d", ret); + } else { + SLOG(LOG_DEBUG, tts_tag(), "[DEBUG] Success to save %s", TTS_CONFIG); } return 0; @@ -684,7 +688,7 @@ int tts_parser_set_voice(const char* language, int type) 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) { @@ -704,6 +708,8 @@ int tts_parser_set_voice(const char* language, int type) int ret = xmlSaveFile(TTS_CONFIG, g_config_doc); if (0 > ret) { SLOG(LOG_ERROR, tts_tag(), "[ERROR] Save result : %d", ret); + } else { + SLOG(LOG_DEBUG, tts_tag(), "[DEBUG] Success to save %s", TTS_CONFIG); } return 0; @@ -747,6 +753,8 @@ int tts_parser_set_auto_voice(bool value) int ret = xmlSaveFile(TTS_CONFIG, g_config_doc); if (0 > ret) { SLOG(LOG_ERROR, tts_tag(), "[ERROR] Save result : %d", ret); + } else { + SLOG(LOG_DEBUG, tts_tag(), "[DEBUG] Success to save %s", TTS_CONFIG); } return 0; @@ -790,6 +798,8 @@ int tts_parser_set_speech_rate(int value) int ret = xmlSaveFile(TTS_CONFIG, g_config_doc); if (0 > ret) { SLOG(LOG_ERROR, tts_tag(), "[ERROR] Save result : %d", ret); + } else { + SLOG(LOG_DEBUG, tts_tag(), "[DEBUG] Success to save %s", TTS_CONFIG); } return 0; @@ -822,7 +832,7 @@ int tts_parser_set_pitch(int value) snprintf(temp, 10, "%d", value); xmlNodeSetContent(cur, (const xmlChar *)temp); break; - } + } cur = cur->next; } @@ -830,6 +840,8 @@ int tts_parser_set_pitch(int value) int ret = xmlSaveFile(TTS_CONFIG, g_config_doc); if (0 > ret) { SLOG(LOG_ERROR, tts_tag(), "[ERROR] Save result : %d", ret); + } else { + SLOG(LOG_DEBUG, tts_tag(), "[DEBUG] Success to save %s", TTS_CONFIG); } return 0; @@ -1072,3 +1084,26 @@ int tts_parser_find_config_changed(char** engine, char**setting, bool* auto_voic return 0; } + +int tts_parser_reset() +{ + SLOG(LOG_DEBUG, tts_tag(), "[DEBUG] Reset g_config_doc as %s", TTS_DEFAULT_CONFIG); + + if (NULL != 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, tts_tag(), "[ERROR] Fail to parse %s", TTS_DEFAULT_CONFIG); + return -1; + } + + int ret = xmlSaveFile(TTS_CONFIG, g_config_doc); + if (0 > ret) { + SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to save %s", TTS_CONFIG); + } + + return 0; +} diff --git a/common/tts_config_parser.h b/common/tts_config_parser.h index 87ba839..ad736b8 100644 --- a/common/tts_config_parser.h +++ b/common/tts_config_parser.h @@ -82,6 +82,8 @@ int tts_parser_find_config_changed(char** engine, char**setting, bool* auto_voic int tts_parser_copy_xml(const char* original, const char* destination); +int tts_parser_reset(); + #ifdef __cplusplus } #endif -- 2.7.4