2 * Copyright (c) 2011-2016 Samsung Electronics Co., Ltd All Rights Reserved
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 * http://www.apache.org/licenses/LICENSE-2.0
7 * Unless required by applicable law or agreed to in writing, software
8 * distributed under the License is distributed on an "AS IS" BASIS,
9 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10 * See the License for the specific language governing permissions and
11 * limitations under the License.
20 #include "tts_config_parser.h"
24 #define TTS_TAG_ENGINE_BASE_TAG "tts-engine"
25 #define TTS_TAG_ENGINE_NAME "name"
26 #define TTS_TAG_ENGINE_ID "id"
27 #define TTS_TAG_ENGINE_SETTING "setting"
28 #define TTS_TAG_ENGINE_VOICE_SET "voices"
29 #define TTS_TAG_ENGINE_VOICE "voice"
30 #define TTS_TAG_ENGINE_VOICE_TYPE "type"
31 #define TTS_TAG_ENGINE_PITCH_SUPPORT "pitch-support"
33 #define TTS_TAG_CONFIG_BASE_TAG "tts-config"
34 #define TTS_TAG_CONFIG_ENGINE_ID "engine"
35 #define TTS_TAG_CONFIG_ENGINE_SETTING "engine-setting"
36 #define TTS_TAG_CONFIG_AUTO_VOICE "auto"
37 #define TTS_TAG_CONFIG_VOICE_TYPE "voice-type"
38 #define TTS_TAG_CONFIG_LANGUAGE "language"
39 #define TTS_TAG_CONFIG_SPEECH_RATE "speech-rate"
40 #define TTS_TAG_CONFIG_PITCH "pitch"
41 #define TTS_TAG_VOICE_TYPE_FEMALE "female"
42 #define TTS_TAG_VOICE_TYPE_MALE "male"
43 #define TTS_TAG_VOICE_TYPE_CHILD "child"
46 extern char* tts_tag();
48 static xmlDocPtr g_config_doc = NULL;
50 int tts_parser_get_engine_info(const char* path, tts_engine_info_s** engine_info)
52 if (NULL == path || NULL == engine_info) {
53 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Input parameter is NULL");
58 xmlNodePtr cur = NULL;
62 doc = xmlParseFile(path);
64 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to parse xml file");
68 cur = xmlDocGetRootElement(doc);
70 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document");
76 if (xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_ENGINE_BASE_TAG)) {
77 SLOG(LOG_ERROR, tts_tag(), "[ERROR] The wrong type, root node is NOT 'tts-engine'");
83 cur = cur->xmlChildrenNode;
85 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document");
91 /* alloc engine info */
92 tts_engine_info_s* temp;
93 temp = (tts_engine_info_s*)calloc(1, sizeof(tts_engine_info_s));
95 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Out of memory");
104 temp->setting = NULL;
105 temp->pitch_support = false;
107 while (cur != NULL) {
108 if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_ENGINE_NAME)) {
109 key = xmlNodeGetContent(cur);
111 if (NULL != temp->name) {
115 temp->name = strdup((char*)key);
119 SLOG(LOG_ERROR, tts_tag(), "[ERROR] <%s> has no content", TTS_TAG_ENGINE_NAME);
121 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_ENGINE_ID)) {
122 key = xmlNodeGetContent(cur);
124 if (NULL != temp->uuid) {
128 temp->uuid = strdup((char*)key);
132 SLOG(LOG_ERROR, tts_tag(), "[ERROR] <%s> has no content", TTS_TAG_ENGINE_ID);
134 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_ENGINE_SETTING)) {
135 key = xmlNodeGetContent(cur);
137 if (NULL != temp->setting) {
139 temp->setting = NULL;
141 temp->setting = strdup((char*)key);
145 SLOG(LOG_ERROR, tts_tag(), "[ERROR] <%s> has no content", TTS_TAG_ENGINE_SETTING);
147 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_ENGINE_VOICE_SET)) {
148 xmlNodePtr voice_node = NULL;
149 voice_node = cur->xmlChildrenNode;
151 while (NULL != voice_node) {
152 if (0 == xmlStrcmp(voice_node->name, (const xmlChar *)TTS_TAG_ENGINE_VOICE)) {
153 tts_config_voice_s* temp_voice = (tts_config_voice_s*)calloc(1, sizeof(tts_config_voice_s));
154 if (NULL == temp_voice) {
155 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Out of memory");
159 attr = xmlGetProp(voice_node, (const xmlChar*)TTS_TAG_ENGINE_VOICE_TYPE);
161 if (0 == xmlStrcmp(attr, (const xmlChar *)TTS_TAG_VOICE_TYPE_FEMALE)) {
162 temp_voice->type = (int)TTS_CONFIG_VOICE_TYPE_FEMALE;
163 } else if (0 == xmlStrcmp(attr, (const xmlChar *)TTS_TAG_VOICE_TYPE_MALE)) {
164 temp_voice->type = (int)TTS_CONFIG_VOICE_TYPE_MALE;
165 } else if (0 == xmlStrcmp(attr, (const xmlChar *)TTS_TAG_VOICE_TYPE_CHILD)) {
166 temp_voice->type = (int)TTS_CONFIG_VOICE_TYPE_CHILD;
168 temp_voice->type = (int)TTS_CONFIG_VOICE_TYPE_USER_DEFINED;
173 SLOG(LOG_ERROR, tts_tag(), "[ERROR] <%s> has no content", TTS_TAG_ENGINE_VOICE_TYPE);
179 key = xmlNodeGetContent(voice_node);
181 if (NULL != temp_voice->language) {
182 free(temp_voice->language);
183 temp_voice->language = NULL;
185 temp_voice->language = strdup((char*)key);
188 temp->voices = g_slist_append(temp->voices, temp_voice);
190 SLOG(LOG_ERROR, tts_tag(), "[ERROR] <%s> has no content", TTS_TAG_ENGINE_VOICE);
191 if (NULL != temp_voice) {
197 voice_node = voice_node->next;
199 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_ENGINE_PITCH_SUPPORT)) {
200 key = xmlNodeGetContent(cur);
202 if (0 == xmlStrcmp(key, (const xmlChar *)"true")) {
203 temp->pitch_support = true;
208 SLOG(LOG_ERROR, tts_tag(), "[ERROR] <%s> has no content", TTS_TAG_ENGINE_PITCH_SUPPORT);
217 if (NULL == temp->name || NULL == temp->uuid) {
219 SECURE_SLOG(LOG_ERROR, tts_tag(), "[ERROR] Invalid engine : %s", path);
220 tts_parser_free_engine_info(temp);
229 int tts_parser_free_engine_info(tts_engine_info_s* engine_info)
231 if (NULL == engine_info) {
232 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Input parameter is NULL");
236 if (NULL != engine_info->name) {
237 free(engine_info->name);
238 engine_info->name = NULL;
240 if (NULL != engine_info->uuid) {
241 free(engine_info->uuid);
242 engine_info->uuid = NULL;
244 if (NULL != engine_info->setting) {
245 free(engine_info->setting);
246 engine_info->setting = NULL;
249 tts_config_voice_s *temp_voice;
250 temp_voice = g_slist_nth_data(engine_info->voices, 0);
252 while (NULL != temp_voice) {
253 if (NULL != temp_voice) {
254 if (NULL != temp_voice->language) {
255 free(temp_voice->language);
256 temp_voice->language = NULL;
258 engine_info->voices = g_slist_remove(engine_info->voices, temp_voice);
263 temp_voice = g_slist_nth_data(engine_info->voices, 0);
266 if (NULL != engine_info) {
274 int tts_parser_print_engine_info(tts_engine_info_s* engine_info)
276 if (NULL == engine_info) {
277 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Input parameter is NULL");
281 SLOG(LOG_DEBUG, tts_tag(), "== get engine info ==");
282 SLOG(LOG_DEBUG, tts_tag(), " name : %s", engine_info->name);
283 SLOG(LOG_DEBUG, tts_tag(), " id : %s", engine_info->uuid);
284 if (NULL != engine_info->setting)
285 SLOG(LOG_DEBUG, tts_tag(), " setting : %s", engine_info->setting);
287 SLOG(LOG_DEBUG, tts_tag(), " voices");
289 tts_config_voice_s *temp_voice;
291 if (g_slist_length(engine_info->voices) > 0) {
292 /* Get a first item */
293 iter = g_slist_nth(engine_info->voices, 0);
296 while (NULL != iter) {
297 /*Get handle data from list*/
298 temp_voice = iter->data;
300 SLOG(LOG_DEBUG, tts_tag(), " [%dth] type(%d) lang(%s)",
301 i, temp_voice->type, temp_voice->language);
304 iter = g_slist_next(iter);
308 SLOG(LOG_ERROR, tts_tag(), " Voice is NONE");
311 SLOG(LOG_DEBUG, tts_tag(), "=====================");
316 int tts_parser_load_config(tts_config_s** config_info)
318 if (NULL == config_info) {
319 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Input parameter is NULL");
323 xmlDocPtr doc = NULL;
324 xmlNodePtr cur = NULL;
326 bool is_default_open = false;
328 /* For Thread safety */
331 if (0 != access(TTS_CONFIG, F_OK)) {
332 doc = xmlParseFile(TTS_DEFAULT_CONFIG);
334 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to parse file error : %s", TTS_DEFAULT_CONFIG);
338 is_default_open = true;
342 while (NULL == doc) {
343 doc = xmlParseFile(TTS_CONFIG);
350 if (TTS_RETRY_COUNT == retry_count) {
351 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to parse file error : %s", TTS_CONFIG);
358 cur = xmlDocGetRootElement(doc);
360 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document");
367 if (xmlStrcmp(cur->name, (const xmlChar *) TTS_TAG_CONFIG_BASE_TAG)) {
368 SLOG(LOG_ERROR, tts_tag(), "[ERROR] The wrong type, root node is NOT %s", TTS_TAG_CONFIG_BASE_TAG);
375 cur = cur->xmlChildrenNode;
377 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document");
384 /* alloc engine info */
386 temp = (tts_config_s*)calloc(1, sizeof(tts_config_s));
388 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Out of memory");
395 temp->engine_id = NULL;
396 temp->setting = NULL;
397 temp->language = NULL;
399 while (cur != NULL) {
400 if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_ENGINE_ID)) {
401 key = xmlNodeGetContent(cur);
403 if (NULL != temp->engine_id) {
404 free(temp->engine_id);
405 temp->engine_id = NULL;
407 temp->engine_id = strdup((char*)key);
411 SLOG(LOG_ERROR, tts_tag(), "[ERROR] engine id is NULL");
413 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_ENGINE_SETTING)) {
414 key = xmlNodeGetContent(cur);
416 if (NULL != temp->setting) {
418 temp->setting = NULL;
420 temp->setting = strdup((char*)key);
424 SLOG(LOG_ERROR, tts_tag(), "[ERROR] setting path is NULL");
426 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_AUTO_VOICE)) {
427 key = xmlNodeGetContent(cur);
429 if (0 == xmlStrcmp(key, (const xmlChar *)"on")) {
430 temp->auto_voice = true;
431 } else if (0 == xmlStrcmp(key, (const xmlChar *)"off")) {
432 temp->auto_voice = false;
434 SLOG(LOG_ERROR, tts_tag(), "Auto voice is wrong");
435 temp->auto_voice = true;
441 SLOG(LOG_ERROR, tts_tag(), "[ERROR] voice type is NULL");
443 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_VOICE_TYPE)) {
444 key = xmlNodeGetContent(cur);
446 if (0 == xmlStrcmp(key, (const xmlChar *)TTS_TAG_VOICE_TYPE_MALE)) {
447 temp->type = (int)TTS_CONFIG_VOICE_TYPE_MALE;
448 } else if (0 == xmlStrcmp(key, (const xmlChar *)TTS_TAG_VOICE_TYPE_FEMALE)) {
449 temp->type = (int)TTS_CONFIG_VOICE_TYPE_FEMALE;
450 } else if (0 == xmlStrcmp(key, (const xmlChar *)TTS_TAG_VOICE_TYPE_CHILD)) {
451 temp->type = (int)TTS_CONFIG_VOICE_TYPE_CHILD;
453 SLOG(LOG_WARN, tts_tag(), "Voice type is user defined");
454 temp->type = (int)TTS_CONFIG_VOICE_TYPE_USER_DEFINED;
460 SLOG(LOG_ERROR, tts_tag(), "[ERROR] voice type is NULL");
462 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_LANGUAGE)) {
463 key = xmlNodeGetContent(cur);
465 if (NULL != temp->language) {
466 free(temp->language);
467 temp->language = NULL;
469 temp->language = strdup((char*)key);
473 SLOG(LOG_ERROR, tts_tag(), "[ERROR] engine uuid is NULL");
476 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_SPEECH_RATE)) {
477 key = xmlNodeGetContent(cur);
479 temp->speech_rate = atoi((char*)key);
482 SLOG(LOG_ERROR, tts_tag(), "[ERROR] speech rate is NULL");
484 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_PITCH)) {
485 key = xmlNodeGetContent(cur);
487 temp->pitch = atoi((char*)key);
491 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Pitch is NULL");
503 if (true == is_default_open) {
504 int ret = xmlSaveFile(TTS_CONFIG, g_config_doc);
506 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Save result : %d", ret);
510 if (0 > chmod(TTS_CONFIG, 0666)) {
511 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to change file mode : %d", ret);
515 if (0 > chown(TTS_CONFIG, 5000, 5000)) {
516 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to change file owner : %d", ret);
518 SLOG(LOG_DEBUG, tts_tag(), "Default config is changed : pid(%d)", getpid());
524 int tts_parser_unload_config(tts_config_s* config_info)
526 if (NULL != g_config_doc) {
527 xmlFreeDoc(g_config_doc);
530 if (NULL != config_info) {
531 if (NULL != config_info->engine_id) {
532 free(config_info->engine_id);
533 config_info->engine_id = NULL;
535 if (NULL != config_info->setting) {
536 free(config_info->setting);
537 config_info->setting = NULL;
539 if (NULL != config_info->language) {
540 free(config_info->language);
541 config_info->language = NULL;
553 int tts_parser_copy_xml(const char* original, const char* destination)
555 if (NULL == original || NULL == destination) {
556 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Input parameter is NULL");
560 xmlDocPtr doc = NULL;
561 doc = xmlParseFile(original);
563 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to parse file error : %s", original);
567 int ret = xmlSaveFile(destination, doc);
569 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Save result : %d", ret);
573 if (0 > chmod(destination, 0666)) {
574 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to change file mode : %d", ret);
579 SLOG(LOG_DEBUG, tts_tag(), "[SUCCESS] Copying xml");
584 int tts_parser_set_engine(const char* engine_id, const char* setting, const char* language, int type)
586 if (NULL == engine_id) {
587 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Input parameter is NULL");
591 xmlNodePtr cur = NULL;
592 cur = xmlDocGetRootElement(g_config_doc);
594 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document");
598 if (xmlStrcmp(cur->name, (const xmlChar *) TTS_TAG_CONFIG_BASE_TAG)) {
599 SLOG(LOG_ERROR, tts_tag(), "[ERROR] The wrong type, root node is NOT %s", TTS_TAG_CONFIG_BASE_TAG);
603 cur = cur->xmlChildrenNode;
605 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document");
609 while (cur != NULL) {
610 if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_ENGINE_ID)) {
611 xmlNodeSetContent(cur, (const xmlChar *)engine_id);
614 if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_LANGUAGE)) {
615 xmlNodeSetContent(cur, (const xmlChar *)language);
618 if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_ENGINE_SETTING)) {
619 xmlNodeSetContent(cur, (const xmlChar *)setting);
622 if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_VOICE_TYPE)) {
624 case TTS_CONFIG_VOICE_TYPE_MALE: xmlNodeSetContent(cur, (const xmlChar*)TTS_TAG_VOICE_TYPE_MALE); break;
625 case TTS_CONFIG_VOICE_TYPE_FEMALE: xmlNodeSetContent(cur, (const xmlChar*)TTS_TAG_VOICE_TYPE_FEMALE); break;
626 case TTS_CONFIG_VOICE_TYPE_CHILD: xmlNodeSetContent(cur, (const xmlChar*)TTS_TAG_VOICE_TYPE_CHILD); break;
627 default: xmlNodeSetContent(cur, (const xmlChar*)TTS_TAG_VOICE_TYPE_FEMALE); break;
634 int ret = xmlSaveFile(TTS_CONFIG, g_config_doc);
636 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Save result : %d", ret);
642 int tts_parser_set_voice(const char* language, int type)
644 if (NULL == language) {
645 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Input parameter is NULL");
649 xmlNodePtr cur = NULL;
650 cur = xmlDocGetRootElement(g_config_doc);
652 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document");
656 if (xmlStrcmp(cur->name, (const xmlChar *) TTS_TAG_CONFIG_BASE_TAG)) {
657 SLOG(LOG_ERROR, tts_tag(), "[ERROR] The wrong type, root node is NOT %s", TTS_TAG_CONFIG_BASE_TAG);
661 cur = cur->xmlChildrenNode;
663 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document");
667 while (cur != NULL) {
668 if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_LANGUAGE)) {
669 xmlNodeSetContent(cur, (const xmlChar *)language);
672 if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_VOICE_TYPE)) {
674 case TTS_CONFIG_VOICE_TYPE_MALE: xmlNodeSetContent(cur, (const xmlChar*)TTS_TAG_VOICE_TYPE_MALE); break;
675 case TTS_CONFIG_VOICE_TYPE_FEMALE: xmlNodeSetContent(cur, (const xmlChar*)TTS_TAG_VOICE_TYPE_FEMALE); break;
676 case TTS_CONFIG_VOICE_TYPE_CHILD: xmlNodeSetContent(cur, (const xmlChar*)TTS_TAG_VOICE_TYPE_CHILD); break;
678 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Invalid type : %d", type);
679 xmlNodeSetContent(cur, (const xmlChar*)TTS_TAG_VOICE_TYPE_FEMALE);
687 int ret = xmlSaveFile(TTS_CONFIG, g_config_doc);
689 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Save result : %d", ret);
695 int tts_parser_set_auto_voice(bool value)
697 xmlNodePtr cur = NULL;
698 cur = xmlDocGetRootElement(g_config_doc);
700 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document");
704 if (xmlStrcmp(cur->name, (const xmlChar *) TTS_TAG_CONFIG_BASE_TAG)) {
705 SLOG(LOG_ERROR, tts_tag(), "[ERROR] The wrong type, root node is NOT %s", TTS_TAG_CONFIG_BASE_TAG);
709 cur = cur->xmlChildrenNode;
711 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document");
715 while (cur != NULL) {
716 if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_AUTO_VOICE)) {
718 xmlNodeSetContent(cur, (const xmlChar *)"on");
719 } else if (false == value) {
720 xmlNodeSetContent(cur, (const xmlChar *)"off");
722 SLOG(LOG_ERROR, tts_tag(), "[ERROR] The wrong value of auto voice");
730 int ret = xmlSaveFile(TTS_CONFIG, g_config_doc);
732 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Save result : %d", ret);
738 int tts_parser_set_speech_rate(int value)
740 xmlNodePtr cur = NULL;
741 cur = xmlDocGetRootElement(g_config_doc);
743 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document");
747 if (xmlStrcmp(cur->name, (const xmlChar *) TTS_TAG_CONFIG_BASE_TAG)) {
748 SLOG(LOG_ERROR, tts_tag(), "[ERROR] The wrong type, root node is NOT %s", TTS_TAG_CONFIG_BASE_TAG);
752 cur = cur->xmlChildrenNode;
754 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document");
758 while (cur != NULL) {
759 if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_SPEECH_RATE)) {
761 memset(temp, '\0', 10);
762 snprintf(temp, 10, "%d", value);
764 xmlNodeSetContent(cur, (const xmlChar *)temp);
766 SLOG(LOG_DEBUG, tts_tag(), "Set speech rate : %s", temp);
773 int ret = xmlSaveFile(TTS_CONFIG, g_config_doc);
775 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Save result : %d", ret);
781 int tts_parser_set_pitch(int value)
783 xmlNodePtr cur = NULL;
784 cur = xmlDocGetRootElement(g_config_doc);
786 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document");
790 if (xmlStrcmp(cur->name, (const xmlChar *) TTS_TAG_CONFIG_BASE_TAG)) {
791 SLOG(LOG_ERROR, tts_tag(), "[ERROR] The wrong type, root node is NOT %s", TTS_TAG_CONFIG_BASE_TAG);
795 cur = cur->xmlChildrenNode;
797 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document");
801 while (cur != NULL) {
802 if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_PITCH)) {
804 memset(temp, '\0', 10);
805 snprintf(temp, 10, "%d", value);
806 xmlNodeSetContent(cur, (const xmlChar *)temp);
813 int ret = xmlSaveFile(TTS_CONFIG, g_config_doc);
815 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Save result : %d", ret);
821 int tts_parser_find_config_changed(char** engine, char**setting, bool* auto_voice, char** language, int* voice_type,
822 int* speech_rate, int* pitch)
824 if (NULL == engine || NULL == setting || NULL == language || NULL == voice_type || NULL == speech_rate) {
825 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Input parameter is NULL");
829 xmlDocPtr doc = NULL;
830 xmlNodePtr cur_new = NULL;
831 xmlNodePtr cur_old = NULL;
837 while (NULL == doc) {
838 doc = xmlParseFile(TTS_CONFIG);
845 if (TTS_RETRY_COUNT == retry_count) {
846 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to parse file error : %s", TTS_CONFIG);
851 cur_new = xmlDocGetRootElement(doc);
852 cur_old = xmlDocGetRootElement(g_config_doc);
853 if (cur_new == NULL || cur_old == NULL) {
854 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document");
860 if (xmlStrcmp(cur_new->name, (const xmlChar*)TTS_TAG_CONFIG_BASE_TAG) ||
861 xmlStrcmp(cur_old->name, (const xmlChar*)TTS_TAG_CONFIG_BASE_TAG)) {
862 SLOG(LOG_ERROR, tts_tag(), "[ERROR] The wrong type, root node is NOT %s", TTS_TAG_CONFIG_BASE_TAG);
868 cur_new = cur_new->xmlChildrenNode;
869 cur_old = cur_old->xmlChildrenNode;
870 if (cur_new == NULL || cur_old == NULL) {
871 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document");
877 while (cur_new != NULL && cur_old != NULL) {
878 if (0 == xmlStrcmp(cur_new->name, (const xmlChar*)TTS_TAG_CONFIG_ENGINE_ID)) {
879 if (0 == xmlStrcmp(cur_old->name, (const xmlChar*)TTS_TAG_CONFIG_ENGINE_ID)) {
880 key_old = xmlNodeGetContent(cur_old);
881 if (NULL != key_old) {
882 key_new = xmlNodeGetContent(cur_new);
883 if (NULL != key_new) {
884 if (0 != xmlStrcmp(key_old, key_new)) {
885 SLOG(LOG_DEBUG, tts_tag(), "Old engine id(%s), New engine(%s)",
886 (char*)key_old, (char*)key_new);
887 if (NULL != *engine) {
891 *engine = strdup((char*)key_new);
900 SLOG(LOG_ERROR, tts_tag(), "[ERROR] old config and new config are different");
902 } else if (0 == xmlStrcmp(cur_new->name, (const xmlChar*)TTS_TAG_CONFIG_ENGINE_SETTING)) {
903 if (0 == xmlStrcmp(cur_old->name, (const xmlChar*)TTS_TAG_CONFIG_ENGINE_SETTING)) {
904 key_old = xmlNodeGetContent(cur_old);
905 if (NULL != key_old) {
906 key_new = xmlNodeGetContent(cur_new);
907 if (NULL != key_new) {
908 if (0 != xmlStrcmp(key_old, key_new)) {
909 SLOG(LOG_DEBUG, tts_tag(), "Old engine setting(%s), New engine setting(%s)",
910 (char*)key_old, (char*)key_new);
911 if (NULL != *setting) {
915 *setting = strdup((char*)key_new);
924 SLOG(LOG_ERROR, tts_tag(), "[ERROR] old config and new config are different");
926 } else if (0 == xmlStrcmp(cur_new->name, (const xmlChar*)TTS_TAG_CONFIG_AUTO_VOICE)) {
927 if (0 == xmlStrcmp(cur_old->name, (const xmlChar*)TTS_TAG_CONFIG_AUTO_VOICE)) {
928 key_old = xmlNodeGetContent(cur_old);
929 if (NULL != key_old) {
930 key_new = xmlNodeGetContent(cur_new);
931 if (NULL != key_new) {
932 if (0 != xmlStrcmp(key_old, key_new)) {
933 SLOG(LOG_DEBUG, tts_tag(), "Old auto voice (%s), New auto voice(%s)",
934 (char*)key_old, (char*)key_new);
935 if (0 == xmlStrcmp((const xmlChar*)"on", key_new)) {
948 SLOG(LOG_ERROR, tts_tag(), "[ERROR] old config and new config are different");
950 } else if (0 == xmlStrcmp(cur_new->name, (const xmlChar*)TTS_TAG_CONFIG_LANGUAGE)) {
951 if (0 == xmlStrcmp(cur_old->name, (const xmlChar*)TTS_TAG_CONFIG_LANGUAGE)) {
952 key_old = xmlNodeGetContent(cur_old);
953 if (NULL != key_old) {
954 key_new = xmlNodeGetContent(cur_new);
955 if (NULL != key_new) {
956 if (0 != xmlStrcmp(key_old, key_new)) {
957 SLOG(LOG_DEBUG, tts_tag(), "Old language(%s), New language(%s)",
958 (char*)key_old, (char*)key_new);
959 if (NULL != *language) {
963 *language = strdup((char*)key_new);
972 SLOG(LOG_ERROR, tts_tag(), "[ERROR] old config and new config are different");
974 } else if (0 == xmlStrcmp(cur_new->name, (const xmlChar*)TTS_TAG_CONFIG_VOICE_TYPE)) {
975 if (0 == xmlStrcmp(cur_old->name, (const xmlChar*)TTS_TAG_CONFIG_VOICE_TYPE)) {
976 key_old = xmlNodeGetContent(cur_old);
977 if (NULL != key_old) {
978 key_new = xmlNodeGetContent(cur_new);
979 if (NULL != key_new) {
980 if (0 != xmlStrcmp(key_old, key_new)) {
981 SLOG(LOG_DEBUG, tts_tag(), "Old voice type(%s), New voice type(%s)",
982 (char*)key_old, (char*)key_new);
983 if (0 == xmlStrcmp(key_new, (const xmlChar *)TTS_TAG_VOICE_TYPE_FEMALE)) {
984 *voice_type = (int)TTS_CONFIG_VOICE_TYPE_FEMALE;
985 } else if (0 == xmlStrcmp(key_new, (const xmlChar *)TTS_TAG_VOICE_TYPE_MALE)) {
986 *voice_type = (int)TTS_CONFIG_VOICE_TYPE_MALE;
987 } else if (0 == xmlStrcmp(key_new, (const xmlChar *)TTS_TAG_VOICE_TYPE_CHILD)) {
988 *voice_type = (int)TTS_CONFIG_VOICE_TYPE_CHILD;
990 SLOG(LOG_ERROR, tts_tag(), "[ERROR] New voice type is not valid");
1000 SLOG(LOG_ERROR, tts_tag(), "[ERROR] old config and new config are different");
1002 } else if (0 == xmlStrcmp(cur_new->name, (const xmlChar*)TTS_TAG_CONFIG_SPEECH_RATE)) {
1003 if (0 == xmlStrcmp(cur_old->name, (const xmlChar*)TTS_TAG_CONFIG_SPEECH_RATE)) {
1004 key_old = xmlNodeGetContent(cur_old);
1005 if (NULL != key_old) {
1006 key_new = xmlNodeGetContent(cur_new);
1007 if (NULL != key_new) {
1008 if (0 != xmlStrcmp(key_old, key_new)) {
1009 SLOG(LOG_DEBUG, tts_tag(), "Old speech rate(%s), New speech rate(%s)",
1010 (char*)key_old, (char*)key_new);
1011 *speech_rate = atoi((char*)key_new);
1020 SLOG(LOG_ERROR, tts_tag(), "[ERROR] old config and new config are different");
1022 } else if (0 == xmlStrcmp(cur_new->name, (const xmlChar*)TTS_TAG_CONFIG_PITCH)) {
1023 if (0 == xmlStrcmp(cur_old->name, (const xmlChar*)TTS_TAG_CONFIG_PITCH)) {
1024 key_old = xmlNodeGetContent(cur_old);
1025 if (NULL != key_old) {
1026 key_new = xmlNodeGetContent(cur_new);
1027 if (NULL != key_new) {
1028 if (0 != xmlStrcmp(key_old, key_new)) {
1029 SLOG(LOG_DEBUG, tts_tag(), "Old pitch(%s), New pitch(%s)",
1030 (char*)key_old, (char*)key_new);
1031 *pitch = atoi((char*)key_new);
1040 SLOG(LOG_ERROR, tts_tag(), "[ERROR] old config and new config are different");
1046 cur_new = cur_new->next;
1047 cur_old = cur_old->next;
1050 if (NULL != g_config_doc) {
1051 xmlFreeDoc(g_config_doc);
1052 g_config_doc = NULL;