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");
103 temp->setting = NULL;
104 temp->pitch_support = false;
106 while (cur != NULL) {
107 if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_ENGINE_NAME)) {
108 key = xmlNodeGetContent(cur);
110 if (NULL != temp->name) {
114 temp->name = strdup((char*)key);
117 SLOG(LOG_ERROR, tts_tag(), "[ERROR] <%s> has no content", TTS_TAG_ENGINE_NAME);
119 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_ENGINE_ID)) {
120 key = xmlNodeGetContent(cur);
122 if (NULL != temp->uuid) {
126 temp->uuid = strdup((char*)key);
129 SLOG(LOG_ERROR, tts_tag(), "[ERROR] <%s> has no content", TTS_TAG_ENGINE_ID);
131 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_ENGINE_SETTING)) {
132 key = xmlNodeGetContent(cur);
134 if (NULL != temp->setting) {
136 temp->setting = NULL;
138 temp->setting = strdup((char*)key);
141 SLOG(LOG_ERROR, tts_tag(), "[ERROR] <%s> has no content", TTS_TAG_ENGINE_SETTING);
143 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_ENGINE_VOICE_SET)) {
144 xmlNodePtr voice_node = NULL;
145 voice_node = cur->xmlChildrenNode;
147 while (NULL != voice_node) {
148 if (0 == xmlStrcmp(voice_node->name, (const xmlChar *)TTS_TAG_ENGINE_VOICE)) {
149 tts_config_voice_s* temp_voice = (tts_config_voice_s*)calloc(1, sizeof(tts_config_voice_s));
150 if (NULL == temp_voice) {
151 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Out of memory");
155 attr = xmlGetProp(voice_node, (const xmlChar*)TTS_TAG_ENGINE_VOICE_TYPE);
157 if (0 == xmlStrcmp(attr, (const xmlChar *)TTS_TAG_VOICE_TYPE_FEMALE)) {
158 temp_voice->type = (int)TTS_CONFIG_VOICE_TYPE_FEMALE;
159 } else if (0 == xmlStrcmp(attr, (const xmlChar *)TTS_TAG_VOICE_TYPE_MALE)) {
160 temp_voice->type = (int)TTS_CONFIG_VOICE_TYPE_MALE;
161 } else if (0 == xmlStrcmp(attr, (const xmlChar *)TTS_TAG_VOICE_TYPE_CHILD)) {
162 temp_voice->type = (int)TTS_CONFIG_VOICE_TYPE_CHILD;
164 temp_voice->type = (int)TTS_CONFIG_VOICE_TYPE_USER_DEFINED;
168 SLOG(LOG_ERROR, tts_tag(), "[ERROR] <%s> has no content", TTS_TAG_ENGINE_VOICE_TYPE);
174 key = xmlNodeGetContent(voice_node);
176 if (NULL != temp_voice->language) {
177 free(temp_voice->language);
178 temp_voice->language = NULL;
180 temp_voice->language = strdup((char*)key);
182 temp->voices = g_slist_append(temp->voices, temp_voice);
184 SLOG(LOG_ERROR, tts_tag(), "[ERROR] <%s> has no content", TTS_TAG_ENGINE_VOICE);
185 if (NULL != temp_voice) {
191 voice_node = voice_node->next;
193 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_ENGINE_PITCH_SUPPORT)) {
194 key = xmlNodeGetContent(cur);
196 if (0 == xmlStrcmp(key, (const xmlChar *)"true")) {
197 temp->pitch_support = true;
202 SLOG(LOG_ERROR, tts_tag(), "[ERROR] <%s> has no content", TTS_TAG_ENGINE_PITCH_SUPPORT);
211 if (NULL == temp->name || NULL == temp->uuid) {
213 SECURE_SLOG(LOG_ERROR, tts_tag(), "[ERROR] Invalid engine : %s", path);
214 tts_parser_free_engine_info(temp);
223 int tts_parser_free_engine_info(tts_engine_info_s* engine_info)
225 if (NULL == engine_info) {
226 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Input parameter is NULL");
230 if (NULL != engine_info->name) {
231 free(engine_info->name);
232 engine_info->name = NULL;
234 if (NULL != engine_info->uuid) {
235 free(engine_info->uuid);
236 engine_info->uuid = NULL;
238 if (NULL != engine_info->setting) {
239 free(engine_info->setting);
240 engine_info->setting = NULL;
243 tts_config_voice_s *temp_voice;
244 temp_voice = g_slist_nth_data(engine_info->voices, 0);
246 while (NULL != temp_voice) {
247 if (NULL != temp_voice) {
248 if (NULL != temp_voice->language) {
249 free(temp_voice->language);
250 temp_voice->language = NULL;
252 engine_info->voices = g_slist_remove(engine_info->voices, temp_voice);
257 temp_voice = g_slist_nth_data(engine_info->voices, 0);
260 if (NULL != engine_info) {
268 int tts_parser_print_engine_info(tts_engine_info_s* engine_info)
270 if (NULL == engine_info) {
271 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Input parameter is NULL");
275 SLOG(LOG_DEBUG, tts_tag(), "== get engine info ==");
276 SLOG(LOG_DEBUG, tts_tag(), " name : %s", engine_info->name);
277 SLOG(LOG_DEBUG, tts_tag(), " id : %s", engine_info->uuid);
278 if (NULL != engine_info->setting)
279 SLOG(LOG_DEBUG, tts_tag(), " setting : %s", engine_info->setting);
281 SLOG(LOG_DEBUG, tts_tag(), " voices");
283 tts_config_voice_s *temp_voice;
285 if (g_slist_length(engine_info->voices) > 0) {
286 /* Get a first item */
287 iter = g_slist_nth(engine_info->voices, 0);
290 while (NULL != iter) {
291 /*Get handle data from list*/
292 temp_voice = iter->data;
294 SLOG(LOG_DEBUG, tts_tag(), " [%dth] type(%d) lang(%s)",
295 i, temp_voice->type, temp_voice->language);
298 iter = g_slist_next(iter);
302 SLOG(LOG_ERROR, tts_tag(), " Voice is NONE");
305 SLOG(LOG_DEBUG, tts_tag(), "=====================");
310 int tts_parser_load_config(tts_config_s** config_info)
312 if (NULL == config_info) {
313 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Input parameter is NULL");
317 xmlDocPtr doc = NULL;
318 xmlNodePtr cur = NULL;
320 bool is_default_open = false;
322 /* For Thread safety */
325 if (0 != access(TTS_CONFIG, F_OK)) {
326 doc = xmlParseFile(TTS_DEFAULT_CONFIG);
328 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to parse file error : %s", TTS_DEFAULT_CONFIG);
331 is_default_open = true;
335 while (NULL == doc) {
336 doc = xmlParseFile(TTS_CONFIG);
343 if (TTS_RETRY_COUNT == retry_count) {
344 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to parse file error : %s", TTS_CONFIG);
350 cur = xmlDocGetRootElement(doc);
352 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document");
358 if (xmlStrcmp(cur->name, (const xmlChar *) TTS_TAG_CONFIG_BASE_TAG)) {
359 SLOG(LOG_ERROR, tts_tag(), "[ERROR] The wrong type, root node is NOT %s", TTS_TAG_CONFIG_BASE_TAG);
365 cur = cur->xmlChildrenNode;
367 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document");
373 /* alloc engine info */
375 temp = (tts_config_s*)calloc(1, sizeof(tts_config_s));
377 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Out of memory");
382 temp->engine_id = NULL;
383 temp->setting = NULL;
384 temp->language = NULL;
386 while (cur != NULL) {
387 if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_ENGINE_ID)) {
388 key = xmlNodeGetContent(cur);
390 if (NULL != temp->engine_id) {
391 free(temp->engine_id);
392 temp->engine_id = NULL;
394 temp->engine_id = strdup((char*)key);
397 SLOG(LOG_ERROR, tts_tag(), "[ERROR] engine id is NULL");
399 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_ENGINE_SETTING)) {
400 key = xmlNodeGetContent(cur);
402 if (NULL != temp->setting) {
404 temp->setting = NULL;
406 temp->setting = strdup((char*)key);
409 SLOG(LOG_ERROR, tts_tag(), "[ERROR] setting path is NULL");
411 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_AUTO_VOICE)) {
412 key = xmlNodeGetContent(cur);
414 if (0 == xmlStrcmp(key, (const xmlChar *)"on")) {
415 temp->auto_voice = true;
416 } else if (0 == xmlStrcmp(key, (const xmlChar *)"off")) {
417 temp->auto_voice = false;
419 SLOG(LOG_ERROR, tts_tag(), "Auto voice is wrong");
420 temp->auto_voice = true;
425 SLOG(LOG_ERROR, tts_tag(), "[ERROR] voice type is NULL");
427 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_VOICE_TYPE)) {
428 key = xmlNodeGetContent(cur);
430 if (0 == xmlStrcmp(key, (const xmlChar *)TTS_TAG_VOICE_TYPE_MALE)) {
431 temp->type = (int)TTS_CONFIG_VOICE_TYPE_MALE;
432 } else if (0 == xmlStrcmp(key, (const xmlChar *)TTS_TAG_VOICE_TYPE_FEMALE)) {
433 temp->type = (int)TTS_CONFIG_VOICE_TYPE_FEMALE;
434 } else if (0 == xmlStrcmp(key, (const xmlChar *)TTS_TAG_VOICE_TYPE_CHILD)) {
435 temp->type = (int)TTS_CONFIG_VOICE_TYPE_CHILD;
437 SLOG(LOG_WARN, tts_tag(), "Voice type is user defined");
438 temp->type = (int)TTS_CONFIG_VOICE_TYPE_USER_DEFINED;
443 SLOG(LOG_ERROR, tts_tag(), "[ERROR] voice type is NULL");
445 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_LANGUAGE)) {
446 key = xmlNodeGetContent(cur);
448 if (NULL != temp->language) {
449 free(temp->language);
450 temp->language = NULL;
452 temp->language = strdup((char*)key);
455 SLOG(LOG_ERROR, tts_tag(), "[ERROR] engine uuid is NULL");
458 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_SPEECH_RATE)) {
459 key = xmlNodeGetContent(cur);
461 temp->speech_rate = atoi((char*)key);
464 SLOG(LOG_ERROR, tts_tag(), "[ERROR] speech rate is NULL");
466 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_PITCH)) {
467 key = xmlNodeGetContent(cur);
469 temp->pitch = atoi((char*)key);
472 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Pitch is NULL");
484 if (true == is_default_open) {
485 int ret = xmlSaveFile(TTS_CONFIG, g_config_doc);
487 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Save result : %d", ret);
491 if (0 > chmod(TTS_CONFIG, 0666)) {
492 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to change file mode : %d", ret);
496 if (0 > chown(TTS_CONFIG, 5000, 5000)) {
497 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to change file owner : %d", ret);
499 SLOG(LOG_DEBUG, tts_tag(), "Default config is changed : pid(%d)", getpid());
505 int tts_parser_unload_config(tts_config_s* config_info)
507 if (NULL != g_config_doc) {
508 xmlFreeDoc(g_config_doc);
511 if (NULL != config_info) {
512 if (NULL != config_info->engine_id) {
513 free(config_info->engine_id);
514 config_info->engine_id = NULL;
516 if (NULL != config_info->setting) {
517 free(config_info->setting);
518 config_info->setting = NULL;
520 if (NULL != config_info->language) {
521 free(config_info->language);
522 config_info->language = NULL;
532 int tts_parser_copy_xml(const char* original, const char* destination)
534 if (NULL == original || NULL == destination) {
535 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Input parameter is NULL");
539 xmlDocPtr doc = NULL;
540 doc = xmlParseFile(original);
542 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to parse file error : %s", original);
546 int ret = xmlSaveFile(destination, doc);
548 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Save result : %d", ret);
552 if (0 > chmod(destination, 0666)) {
553 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to change file mode : %d", ret);
557 SLOG(LOG_DEBUG, tts_tag(), "[SUCCESS] Copying xml");
562 int tts_parser_set_engine(const char* engine_id, const char* setting, const char* language, int type)
564 if (NULL == engine_id) {
565 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Input parameter is NULL");
569 xmlNodePtr cur = NULL;
570 cur = xmlDocGetRootElement(g_config_doc);
572 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document");
576 if (xmlStrcmp(cur->name, (const xmlChar *) TTS_TAG_CONFIG_BASE_TAG)) {
577 SLOG(LOG_ERROR, tts_tag(), "[ERROR] The wrong type, root node is NOT %s", TTS_TAG_CONFIG_BASE_TAG);
581 cur = cur->xmlChildrenNode;
583 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document");
587 while (cur != NULL) {
588 if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_ENGINE_ID)) {
589 xmlNodeSetContent(cur, (const xmlChar *)engine_id);
592 if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_LANGUAGE)) {
593 xmlNodeSetContent(cur, (const xmlChar *)language);
596 if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_ENGINE_SETTING)) {
597 xmlNodeSetContent(cur, (const xmlChar *)setting);
600 if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_VOICE_TYPE)) {
602 case TTS_CONFIG_VOICE_TYPE_MALE: xmlNodeSetContent(cur, (const xmlChar*)TTS_TAG_VOICE_TYPE_MALE); break;
603 case TTS_CONFIG_VOICE_TYPE_FEMALE: xmlNodeSetContent(cur, (const xmlChar*)TTS_TAG_VOICE_TYPE_FEMALE); break;
604 case TTS_CONFIG_VOICE_TYPE_CHILD: xmlNodeSetContent(cur, (const xmlChar*)TTS_TAG_VOICE_TYPE_CHILD); break;
605 default: xmlNodeSetContent(cur, (const xmlChar*)TTS_TAG_VOICE_TYPE_FEMALE); break;
612 int ret = xmlSaveFile(TTS_CONFIG, g_config_doc);
614 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Save result : %d", ret);
620 int tts_parser_set_voice(const char* language, int type)
622 if (NULL == language) {
623 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Input parameter is NULL");
627 xmlNodePtr cur = NULL;
628 cur = xmlDocGetRootElement(g_config_doc);
630 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document");
634 if (xmlStrcmp(cur->name, (const xmlChar *) TTS_TAG_CONFIG_BASE_TAG)) {
635 SLOG(LOG_ERROR, tts_tag(), "[ERROR] The wrong type, root node is NOT %s", TTS_TAG_CONFIG_BASE_TAG);
639 cur = cur->xmlChildrenNode;
641 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document");
645 while (cur != NULL) {
646 if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_LANGUAGE)) {
647 xmlNodeSetContent(cur, (const xmlChar *)language);
650 if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_VOICE_TYPE)) {
652 case TTS_CONFIG_VOICE_TYPE_MALE: xmlNodeSetContent(cur, (const xmlChar*)TTS_TAG_VOICE_TYPE_MALE); break;
653 case TTS_CONFIG_VOICE_TYPE_FEMALE: xmlNodeSetContent(cur, (const xmlChar*)TTS_TAG_VOICE_TYPE_FEMALE); break;
654 case TTS_CONFIG_VOICE_TYPE_CHILD: xmlNodeSetContent(cur, (const xmlChar*)TTS_TAG_VOICE_TYPE_CHILD); break;
656 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Invalid type : %d", type);
657 xmlNodeSetContent(cur, (const xmlChar*)TTS_TAG_VOICE_TYPE_FEMALE);
665 int ret = xmlSaveFile(TTS_CONFIG, g_config_doc);
667 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Save result : %d", ret);
673 int tts_parser_set_auto_voice(bool value)
675 xmlNodePtr cur = NULL;
676 cur = xmlDocGetRootElement(g_config_doc);
678 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document");
682 if (xmlStrcmp(cur->name, (const xmlChar *) TTS_TAG_CONFIG_BASE_TAG)) {
683 SLOG(LOG_ERROR, tts_tag(), "[ERROR] The wrong type, root node is NOT %s", TTS_TAG_CONFIG_BASE_TAG);
687 cur = cur->xmlChildrenNode;
689 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document");
693 while (cur != NULL) {
694 if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_AUTO_VOICE)) {
696 xmlNodeSetContent(cur, (const xmlChar *)"on");
697 } else if (false == value) {
698 xmlNodeSetContent(cur, (const xmlChar *)"off");
700 SLOG(LOG_ERROR, tts_tag(), "[ERROR] The wrong value of auto voice");
708 int ret = xmlSaveFile(TTS_CONFIG, g_config_doc);
710 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Save result : %d", ret);
716 int tts_parser_set_speech_rate(int value)
718 xmlNodePtr cur = NULL;
719 cur = xmlDocGetRootElement(g_config_doc);
721 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document");
725 if (xmlStrcmp(cur->name, (const xmlChar *) TTS_TAG_CONFIG_BASE_TAG)) {
726 SLOG(LOG_ERROR, tts_tag(), "[ERROR] The wrong type, root node is NOT %s", TTS_TAG_CONFIG_BASE_TAG);
730 cur = cur->xmlChildrenNode;
732 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document");
736 while (cur != NULL) {
737 if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_SPEECH_RATE)) {
739 memset(temp, '\0', 10);
740 snprintf(temp, 10, "%d", value);
742 xmlNodeSetContent(cur, (const xmlChar *)temp);
744 SLOG(LOG_DEBUG, tts_tag(), "Set speech rate : %s", temp);
751 int ret = xmlSaveFile(TTS_CONFIG, g_config_doc);
753 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Save result : %d", ret);
759 int tts_parser_set_pitch(int value)
761 xmlNodePtr cur = NULL;
762 cur = xmlDocGetRootElement(g_config_doc);
764 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document");
768 if (xmlStrcmp(cur->name, (const xmlChar *) TTS_TAG_CONFIG_BASE_TAG)) {
769 SLOG(LOG_ERROR, tts_tag(), "[ERROR] The wrong type, root node is NOT %s", TTS_TAG_CONFIG_BASE_TAG);
773 cur = cur->xmlChildrenNode;
775 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document");
779 while (cur != NULL) {
780 if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_PITCH)) {
782 memset(temp, '\0', 10);
783 snprintf(temp, 10, "%d", value);
784 xmlNodeSetContent(cur, (const xmlChar *)temp);
791 int ret = xmlSaveFile(TTS_CONFIG, g_config_doc);
793 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Save result : %d", ret);
799 int tts_parser_find_config_changed(char** engine, char**setting, bool* auto_voice, char** language, int* voice_type,
800 int* speech_rate, int* pitch)
802 if (NULL == engine || NULL == setting || NULL == language || NULL == voice_type || NULL == speech_rate) {
803 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Input parameter is NULL");
807 xmlDocPtr doc = NULL;
808 xmlNodePtr cur_new = NULL;
809 xmlNodePtr cur_old = NULL;
815 while (NULL == doc) {
816 doc = xmlParseFile(TTS_CONFIG);
823 if (TTS_RETRY_COUNT == retry_count) {
824 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to parse file error : %s", TTS_CONFIG);
829 cur_new = xmlDocGetRootElement(doc);
830 cur_old = xmlDocGetRootElement(g_config_doc);
831 if (cur_new == NULL || cur_old == NULL) {
832 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document");
838 if (xmlStrcmp(cur_new->name, (const xmlChar*)TTS_TAG_CONFIG_BASE_TAG) ||
839 xmlStrcmp(cur_old->name, (const xmlChar*)TTS_TAG_CONFIG_BASE_TAG)) {
840 SLOG(LOG_ERROR, tts_tag(), "[ERROR] The wrong type, root node is NOT %s", TTS_TAG_CONFIG_BASE_TAG);
846 cur_new = cur_new->xmlChildrenNode;
847 cur_old = cur_old->xmlChildrenNode;
848 if (cur_new == NULL || cur_old == NULL) {
849 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document");
855 while (cur_new != NULL && cur_old != NULL) {
856 if (0 == xmlStrcmp(cur_new->name, (const xmlChar*)TTS_TAG_CONFIG_ENGINE_ID)) {
857 if (0 == xmlStrcmp(cur_old->name, (const xmlChar*)TTS_TAG_CONFIG_ENGINE_ID)) {
858 key_old = xmlNodeGetContent(cur_old);
859 if (NULL != key_old) {
860 key_new = xmlNodeGetContent(cur_new);
861 if (NULL != key_new) {
862 if (0 != xmlStrcmp(key_old, key_new)) {
863 SLOG(LOG_DEBUG, tts_tag(), "Old engine id(%s), New engine(%s)",
864 (char*)key_old, (char*)key_new);
865 if (NULL != *engine) {
869 *engine = strdup((char*)key_new);
876 SLOG(LOG_ERROR, tts_tag(), "[ERROR] old config and new config are different");
878 } else if (0 == xmlStrcmp(cur_new->name, (const xmlChar*)TTS_TAG_CONFIG_ENGINE_SETTING)) {
879 if (0 == xmlStrcmp(cur_old->name, (const xmlChar*)TTS_TAG_CONFIG_ENGINE_SETTING)) {
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 setting(%s), New engine setting(%s)",
886 (char*)key_old, (char*)key_new);
887 if (NULL != *setting) {
891 *setting = strdup((char*)key_new);
898 SLOG(LOG_ERROR, tts_tag(), "[ERROR] old config and new config are different");
900 } else if (0 == xmlStrcmp(cur_new->name, (const xmlChar*)TTS_TAG_CONFIG_AUTO_VOICE)) {
901 if (0 == xmlStrcmp(cur_old->name, (const xmlChar*)TTS_TAG_CONFIG_AUTO_VOICE)) {
902 key_old = xmlNodeGetContent(cur_old);
903 if (NULL != key_old) {
904 key_new = xmlNodeGetContent(cur_new);
905 if (NULL != key_new) {
906 if (0 != xmlStrcmp(key_old, key_new)) {
907 SLOG(LOG_DEBUG, tts_tag(), "Old auto voice (%s), New auto voice(%s)",
908 (char*)key_old, (char*)key_new);
909 if (0 == xmlStrcmp((const xmlChar*)"on", key_new)) {
920 SLOG(LOG_ERROR, tts_tag(), "[ERROR] old config and new config are different");
922 } else if (0 == xmlStrcmp(cur_new->name, (const xmlChar*)TTS_TAG_CONFIG_LANGUAGE)) {
923 if (0 == xmlStrcmp(cur_old->name, (const xmlChar*)TTS_TAG_CONFIG_LANGUAGE)) {
924 key_old = xmlNodeGetContent(cur_old);
925 if (NULL != key_old) {
926 key_new = xmlNodeGetContent(cur_new);
927 if (NULL != key_new) {
928 if (0 != xmlStrcmp(key_old, key_new)) {
929 SLOG(LOG_DEBUG, tts_tag(), "Old language(%s), New language(%s)",
930 (char*)key_old, (char*)key_new);
931 if (NULL != *language) {
935 *language = strdup((char*)key_new);
942 SLOG(LOG_ERROR, tts_tag(), "[ERROR] old config and new config are different");
944 } else if (0 == xmlStrcmp(cur_new->name, (const xmlChar*)TTS_TAG_CONFIG_VOICE_TYPE)) {
945 if (0 == xmlStrcmp(cur_old->name, (const xmlChar*)TTS_TAG_CONFIG_VOICE_TYPE)) {
946 key_old = xmlNodeGetContent(cur_old);
947 if (NULL != key_old) {
948 key_new = xmlNodeGetContent(cur_new);
949 if (NULL != key_new) {
950 if (0 != xmlStrcmp(key_old, key_new)) {
951 SLOG(LOG_DEBUG, tts_tag(), "Old voice type(%s), New voice type(%s)",
952 (char*)key_old, (char*)key_new);
953 if (0 == xmlStrcmp(key_new, (const xmlChar *)TTS_TAG_VOICE_TYPE_FEMALE)) {
954 *voice_type = (int)TTS_CONFIG_VOICE_TYPE_FEMALE;
955 } else if (0 == xmlStrcmp(key_new, (const xmlChar *)TTS_TAG_VOICE_TYPE_MALE)) {
956 *voice_type = (int)TTS_CONFIG_VOICE_TYPE_MALE;
957 } else if (0 == xmlStrcmp(key_new, (const xmlChar *)TTS_TAG_VOICE_TYPE_CHILD)) {
958 *voice_type = (int)TTS_CONFIG_VOICE_TYPE_CHILD;
960 SLOG(LOG_ERROR, tts_tag(), "[ERROR] New voice type is not valid");
968 SLOG(LOG_ERROR, tts_tag(), "[ERROR] old config and new config are different");
970 } else if (0 == xmlStrcmp(cur_new->name, (const xmlChar*)TTS_TAG_CONFIG_SPEECH_RATE)) {
971 if (0 == xmlStrcmp(cur_old->name, (const xmlChar*)TTS_TAG_CONFIG_SPEECH_RATE)) {
972 key_old = xmlNodeGetContent(cur_old);
973 if (NULL != key_old) {
974 key_new = xmlNodeGetContent(cur_new);
975 if (NULL != key_new) {
976 if (0 != xmlStrcmp(key_old, key_new)) {
977 SLOG(LOG_DEBUG, tts_tag(), "Old speech rate(%s), New speech rate(%s)",
978 (char*)key_old, (char*)key_new);
979 *speech_rate = atoi((char*)key_new);
986 SLOG(LOG_ERROR, tts_tag(), "[ERROR] old config and new config are different");
988 } else if (0 == xmlStrcmp(cur_new->name, (const xmlChar*)TTS_TAG_CONFIG_PITCH)) {
989 if (0 == xmlStrcmp(cur_old->name, (const xmlChar*)TTS_TAG_CONFIG_PITCH)) {
990 key_old = xmlNodeGetContent(cur_old);
991 if (NULL != key_old) {
992 key_new = xmlNodeGetContent(cur_new);
993 if (NULL != key_new) {
994 if (0 != xmlStrcmp(key_old, key_new)) {
995 SLOG(LOG_DEBUG, tts_tag(), "Old pitch(%s), New pitch(%s)",
996 (char*)key_old, (char*)key_new);
997 *pitch = atoi((char*)key_new);
1004 SLOG(LOG_ERROR, tts_tag(), "[ERROR] old config and new config are different");
1010 cur_new = cur_new->next;
1011 cur_old = cur_old->next;
1014 if (NULL != g_config_doc) {
1015 xmlFreeDoc(g_config_doc);
1016 g_config_doc = NULL;