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) free(temp->name);
111 temp->name = strdup((char*)key);
114 SLOG(LOG_ERROR, tts_tag(), "[ERROR] <%s> has no content", TTS_TAG_ENGINE_NAME);
116 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_ENGINE_ID)) {
117 key = xmlNodeGetContent(cur);
119 if (NULL != temp->uuid) free(temp->uuid);
120 temp->uuid = strdup((char*)key);
123 SLOG(LOG_ERROR, tts_tag(), "[ERROR] <%s> has no content", TTS_TAG_ENGINE_ID);
125 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_ENGINE_SETTING)) {
126 key = xmlNodeGetContent(cur);
128 if (NULL != temp->setting) free(temp->setting);
129 temp->setting = strdup((char*)key);
132 SLOG(LOG_ERROR, tts_tag(), "[ERROR] <%s> has no content", TTS_TAG_ENGINE_SETTING);
134 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_ENGINE_VOICE_SET)) {
135 xmlNodePtr voice_node = NULL;
136 voice_node = cur->xmlChildrenNode;
138 while (NULL != voice_node) {
139 if (0 == xmlStrcmp(voice_node->name, (const xmlChar *)TTS_TAG_ENGINE_VOICE)) {
140 tts_config_voice_s* temp_voice = (tts_config_voice_s*)calloc(1, sizeof(tts_config_voice_s));
141 if (NULL == temp_voice) {
142 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Out of memory");
146 attr = xmlGetProp(voice_node, (const xmlChar*)TTS_TAG_ENGINE_VOICE_TYPE);
148 if (0 == xmlStrcmp(attr, (const xmlChar *)TTS_TAG_VOICE_TYPE_FEMALE)) {
149 temp_voice->type = (int)TTS_CONFIG_VOICE_TYPE_FEMALE;
150 } else if (0 == xmlStrcmp(attr, (const xmlChar *)TTS_TAG_VOICE_TYPE_MALE)) {
151 temp_voice->type = (int)TTS_CONFIG_VOICE_TYPE_MALE;
152 } else if (0 == xmlStrcmp(attr, (const xmlChar *)TTS_TAG_VOICE_TYPE_CHILD)) {
153 temp_voice->type = (int)TTS_CONFIG_VOICE_TYPE_CHILD;
155 temp_voice->type = (int)TTS_CONFIG_VOICE_TYPE_USER_DEFINED;
159 SLOG(LOG_ERROR, tts_tag(), "[ERROR] <%s> has no content", TTS_TAG_ENGINE_VOICE_TYPE);
165 key = xmlNodeGetContent(voice_node);
167 if (NULL != temp_voice->language) free(temp_voice->language);
168 temp_voice->language = strdup((char*)key);
170 temp->voices = g_slist_append(temp->voices, temp_voice);
172 SLOG(LOG_ERROR, tts_tag(), "[ERROR] <%s> has no content", TTS_TAG_ENGINE_VOICE);
173 if (NULL != temp_voice) {
179 voice_node = voice_node->next;
181 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_ENGINE_PITCH_SUPPORT)) {
182 key = xmlNodeGetContent(cur);
184 if (0 == xmlStrcmp(key, (const xmlChar *)"true")) {
185 temp->pitch_support = true;
190 SLOG(LOG_ERROR, tts_tag(), "[ERROR] <%s> has no content", TTS_TAG_ENGINE_PITCH_SUPPORT);
199 if (NULL == temp->name || NULL == temp->uuid) {
201 SECURE_SLOG(LOG_ERROR, tts_tag(), "[ERROR] Invalid engine : %s", path);
202 tts_parser_free_engine_info(temp);
211 int tts_parser_free_engine_info(tts_engine_info_s* engine_info)
213 if (NULL == engine_info) {
214 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Input parameter is NULL");
218 if (NULL != engine_info->name) free(engine_info->name);
219 if (NULL != engine_info->uuid) free(engine_info->uuid);
220 if (NULL != engine_info->setting) free(engine_info->setting);
222 tts_config_voice_s *temp_voice;
223 temp_voice = g_slist_nth_data(engine_info->voices, 0);
225 while (NULL != temp_voice) {
226 if (NULL != temp_voice) {
227 if (NULL != temp_voice->language) free(temp_voice->language);
228 engine_info->voices = g_slist_remove(engine_info->voices, temp_voice);
232 temp_voice = g_slist_nth_data(engine_info->voices, 0);
235 if (NULL != engine_info) free(engine_info);
240 int tts_parser_print_engine_info(tts_engine_info_s* engine_info)
242 if (NULL == engine_info) {
243 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Input parameter is NULL");
247 SLOG(LOG_DEBUG, tts_tag(), "== get engine info ==");
248 SLOG(LOG_DEBUG, tts_tag(), " name : %s", engine_info->name);
249 SLOG(LOG_DEBUG, tts_tag(), " id : %s", engine_info->uuid);
250 if (NULL != engine_info->setting)
251 SLOG(LOG_DEBUG, tts_tag(), " setting : %s", engine_info->setting);
253 SLOG(LOG_DEBUG, tts_tag(), " voices");
255 tts_config_voice_s *temp_voice;
257 if (g_slist_length(engine_info->voices) > 0) {
258 /* Get a first item */
259 iter = g_slist_nth(engine_info->voices, 0);
262 while (NULL != iter) {
263 /*Get handle data from list*/
264 temp_voice = iter->data;
266 SLOG(LOG_DEBUG, tts_tag(), " [%dth] type(%d) lang(%s)",
267 i, temp_voice->type, temp_voice->language);
270 iter = g_slist_next(iter);
274 SLOG(LOG_ERROR, tts_tag(), " Voice is NONE");
277 SLOG(LOG_DEBUG, tts_tag(), "=====================");
282 int tts_parser_load_config(tts_config_s** config_info)
284 if (NULL == config_info) {
285 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Input parameter is NULL");
289 xmlDocPtr doc = NULL;
290 xmlNodePtr cur = NULL;
292 bool is_default_open = false;
294 /* For Thread safety */
297 if (0 != access(TTS_CONFIG, F_OK)) {
298 doc = xmlParseFile(TTS_DEFAULT_CONFIG);
300 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to parse file error : %s", TTS_DEFAULT_CONFIG);
303 is_default_open = true;
307 while (NULL == doc) {
308 doc = xmlParseFile(TTS_CONFIG);
315 if (TTS_RETRY_COUNT == retry_count) {
316 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to parse file error : %s", TTS_CONFIG);
322 cur = xmlDocGetRootElement(doc);
324 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document");
330 if (xmlStrcmp(cur->name, (const xmlChar *) TTS_TAG_CONFIG_BASE_TAG)) {
331 SLOG(LOG_ERROR, tts_tag(), "[ERROR] The wrong type, root node is NOT %s", TTS_TAG_CONFIG_BASE_TAG);
337 cur = cur->xmlChildrenNode;
339 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document");
345 /* alloc engine info */
347 temp = (tts_config_s*)calloc(1, sizeof(tts_config_s));
349 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Out of memory");
354 temp->engine_id = NULL;
355 temp->setting = NULL;
356 temp->language = NULL;
358 while (cur != NULL) {
359 if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_ENGINE_ID)) {
360 key = xmlNodeGetContent(cur);
362 if (NULL != temp->engine_id) free(temp->engine_id);
363 temp->engine_id = strdup((char*)key);
366 SLOG(LOG_ERROR, tts_tag(), "[ERROR] engine id is NULL");
368 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_ENGINE_SETTING)) {
369 key = xmlNodeGetContent(cur);
371 if (NULL != temp->setting) free(temp->setting);
372 temp->setting = strdup((char*)key);
375 SLOG(LOG_ERROR, tts_tag(), "[ERROR] setting path is NULL");
378 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_AUTO_VOICE)) {
379 key = xmlNodeGetContent(cur);
381 if (0 == xmlStrcmp(key, (const xmlChar *)"on")) {
382 temp->auto_voice = true;
383 } else if (0 == xmlStrcmp(key, (const xmlChar *)"off")) {
384 temp->auto_voice = false;
386 SLOG(LOG_ERROR, tts_tag(), "Auto voice is wrong");
387 temp->auto_voice = true;
392 SLOG(LOG_ERROR, tts_tag(), "[ERROR] voice type is NULL");
394 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_VOICE_TYPE)) {
395 key = xmlNodeGetContent(cur);
397 if (0 == xmlStrcmp(key, (const xmlChar *)TTS_TAG_VOICE_TYPE_MALE)) {
398 temp->type = (int)TTS_CONFIG_VOICE_TYPE_MALE;
399 } else if (0 == xmlStrcmp(key, (const xmlChar *)TTS_TAG_VOICE_TYPE_FEMALE)) {
400 temp->type = (int)TTS_CONFIG_VOICE_TYPE_FEMALE;
401 } else if (0 == xmlStrcmp(key, (const xmlChar *)TTS_TAG_VOICE_TYPE_CHILD)) {
402 temp->type = (int)TTS_CONFIG_VOICE_TYPE_CHILD;
404 SLOG(LOG_WARN, tts_tag(), "Voice type is user defined");
405 temp->type = (int)TTS_CONFIG_VOICE_TYPE_USER_DEFINED;
410 SLOG(LOG_ERROR, tts_tag(), "[ERROR] voice type is NULL");
412 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_LANGUAGE)) {
413 key = xmlNodeGetContent(cur);
415 if (NULL != temp->language) free(temp->language);
416 temp->language = strdup((char*)key);
419 SLOG(LOG_ERROR, tts_tag(), "[ERROR] engine uuid is NULL");
422 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_SPEECH_RATE)) {
423 key = xmlNodeGetContent(cur);
425 temp->speech_rate = atoi((char*)key);
428 SLOG(LOG_ERROR, tts_tag(), "[ERROR] speech rate is NULL");
430 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_PITCH)) {
431 key = xmlNodeGetContent(cur);
433 temp->pitch = atoi((char*)key);
436 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Pitch is NULL");
448 if (true == is_default_open) {
449 int ret = xmlSaveFile(TTS_CONFIG, g_config_doc);
451 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Save result : %d", ret);
455 if (0 > chmod(TTS_CONFIG, 0666)) {
456 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to change file mode : %d", ret);
460 if (0 > chown(TTS_CONFIG, 5000, 5000)) {
461 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to change file owner : %d", ret);
463 SLOG(LOG_DEBUG, tts_tag(), "Default config is changed : pid(%d)", getpid());
469 int tts_parser_unload_config(tts_config_s* config_info)
471 if (NULL != g_config_doc) {
472 xmlFreeDoc(g_config_doc);
475 if (NULL != config_info) {
476 if (NULL != config_info->engine_id) {
477 free(config_info->engine_id);
478 config_info->engine_id = NULL;
480 if (NULL != config_info->setting) {
481 free(config_info->setting);
482 config_info->setting = NULL;
484 if (NULL != config_info->language) {
485 free(config_info->language);
486 config_info->language = NULL;
496 int tts_parser_copy_xml(const char* original, const char* destination)
498 if (NULL == original || NULL == destination) {
499 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Input parameter is NULL");
503 xmlDocPtr doc = NULL;
504 doc = xmlParseFile(original);
506 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to parse file error : %s", original);
510 int ret = xmlSaveFile(destination, doc);
512 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Save result : %d", ret);
516 if (0 > chmod(destination, 0666)) {
517 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to change file mode : %d", ret);
521 SLOG(LOG_DEBUG, tts_tag(), "[SUCCESS] Copying xml");
526 int tts_parser_set_engine(const char* engine_id, const char* setting, const char* language, int type)
528 if (NULL == engine_id) {
529 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Input parameter is NULL");
533 xmlNodePtr cur = NULL;
534 cur = xmlDocGetRootElement(g_config_doc);
536 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document");
540 if (xmlStrcmp(cur->name, (const xmlChar *) TTS_TAG_CONFIG_BASE_TAG)) {
541 SLOG(LOG_ERROR, tts_tag(), "[ERROR] The wrong type, root node is NOT %s", TTS_TAG_CONFIG_BASE_TAG);
545 cur = cur->xmlChildrenNode;
547 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document");
551 while (cur != NULL) {
552 if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_ENGINE_ID)) {
553 xmlNodeSetContent(cur, (const xmlChar *)engine_id);
556 if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_LANGUAGE)) {
557 xmlNodeSetContent(cur, (const xmlChar *)language);
560 if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_ENGINE_SETTING)) {
561 xmlNodeSetContent(cur, (const xmlChar *)setting);
564 if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_VOICE_TYPE)) {
566 case TTS_CONFIG_VOICE_TYPE_MALE: xmlNodeSetContent(cur, (const xmlChar*)TTS_TAG_VOICE_TYPE_MALE); break;
567 case TTS_CONFIG_VOICE_TYPE_FEMALE: xmlNodeSetContent(cur, (const xmlChar*)TTS_TAG_VOICE_TYPE_FEMALE); break;
568 case TTS_CONFIG_VOICE_TYPE_CHILD: xmlNodeSetContent(cur, (const xmlChar*)TTS_TAG_VOICE_TYPE_CHILD); break;
569 default: xmlNodeSetContent(cur, (const xmlChar*)TTS_TAG_VOICE_TYPE_FEMALE); break;
576 int ret = xmlSaveFile(TTS_CONFIG, g_config_doc);
578 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Save result : %d", ret);
584 int tts_parser_set_voice(const char* language, int type)
586 if (NULL == language) {
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_LANGUAGE)) {
611 xmlNodeSetContent(cur, (const xmlChar *)language);
614 if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_VOICE_TYPE)) {
616 case TTS_CONFIG_VOICE_TYPE_MALE: xmlNodeSetContent(cur, (const xmlChar*)TTS_TAG_VOICE_TYPE_MALE); break;
617 case TTS_CONFIG_VOICE_TYPE_FEMALE: xmlNodeSetContent(cur, (const xmlChar*)TTS_TAG_VOICE_TYPE_FEMALE); break;
618 case TTS_CONFIG_VOICE_TYPE_CHILD: xmlNodeSetContent(cur, (const xmlChar*)TTS_TAG_VOICE_TYPE_CHILD); break;
620 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Invalid type : %d", type);
621 xmlNodeSetContent(cur, (const xmlChar*)TTS_TAG_VOICE_TYPE_FEMALE);
629 int ret = xmlSaveFile(TTS_CONFIG, g_config_doc);
631 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Save result : %d", ret);
637 int tts_parser_set_auto_voice(bool value)
639 xmlNodePtr cur = NULL;
640 cur = xmlDocGetRootElement(g_config_doc);
642 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document");
646 if (xmlStrcmp(cur->name, (const xmlChar *) TTS_TAG_CONFIG_BASE_TAG)) {
647 SLOG(LOG_ERROR, tts_tag(), "[ERROR] The wrong type, root node is NOT %s", TTS_TAG_CONFIG_BASE_TAG);
651 cur = cur->xmlChildrenNode;
653 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document");
657 while (cur != NULL) {
658 if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_AUTO_VOICE)) {
660 xmlNodeSetContent(cur, (const xmlChar *)"on");
661 } else if (false == value) {
662 xmlNodeSetContent(cur, (const xmlChar *)"off");
664 SLOG(LOG_ERROR, tts_tag(), "[ERROR] The wrong value of auto voice");
672 int ret = xmlSaveFile(TTS_CONFIG, g_config_doc);
674 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Save result : %d", ret);
680 int tts_parser_set_speech_rate(int value)
682 xmlNodePtr cur = NULL;
683 cur = xmlDocGetRootElement(g_config_doc);
685 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document");
689 if (xmlStrcmp(cur->name, (const xmlChar *) TTS_TAG_CONFIG_BASE_TAG)) {
690 SLOG(LOG_ERROR, tts_tag(), "[ERROR] The wrong type, root node is NOT %s", TTS_TAG_CONFIG_BASE_TAG);
694 cur = cur->xmlChildrenNode;
696 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document");
700 while (cur != NULL) {
701 if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_SPEECH_RATE)) {
703 memset(temp, '\0', 10);
704 snprintf(temp, 10, "%d", value);
706 xmlNodeSetContent(cur, (const xmlChar *)temp);
708 SLOG(LOG_DEBUG, tts_tag(), "Set speech rate : %s", temp);
715 int ret = xmlSaveFile(TTS_CONFIG, g_config_doc);
717 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Save result : %d", ret);
723 int tts_parser_set_pitch(int value)
725 xmlNodePtr cur = NULL;
726 cur = xmlDocGetRootElement(g_config_doc);
728 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document");
732 if (xmlStrcmp(cur->name, (const xmlChar *) TTS_TAG_CONFIG_BASE_TAG)) {
733 SLOG(LOG_ERROR, tts_tag(), "[ERROR] The wrong type, root node is NOT %s", TTS_TAG_CONFIG_BASE_TAG);
737 cur = cur->xmlChildrenNode;
739 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document");
743 while (cur != NULL) {
744 if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_PITCH)) {
746 memset(temp, '\0', 10);
747 snprintf(temp, 10, "%d", value);
748 xmlNodeSetContent(cur, (const xmlChar *)temp);
755 int ret = xmlSaveFile(TTS_CONFIG, g_config_doc);
757 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Save result : %d", ret);
763 int tts_parser_find_config_changed(char** engine, char**setting, bool* auto_voice, char** language, int* voice_type,
764 int* speech_rate, int* pitch)
766 if (NULL == engine || NULL == setting || NULL == language || NULL == voice_type || NULL == speech_rate) {
767 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Input parameter is NULL");
771 xmlDocPtr doc = NULL;
772 xmlNodePtr cur_new = NULL;
773 xmlNodePtr cur_old = NULL;
779 while (NULL == doc) {
780 doc = xmlParseFile(TTS_CONFIG);
787 if (TTS_RETRY_COUNT == retry_count) {
788 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to parse file error : %s", TTS_CONFIG);
793 cur_new = xmlDocGetRootElement(doc);
794 cur_old = xmlDocGetRootElement(g_config_doc);
795 if (cur_new == NULL || cur_old == NULL) {
796 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document");
802 if (xmlStrcmp(cur_new->name, (const xmlChar*)TTS_TAG_CONFIG_BASE_TAG) ||
803 xmlStrcmp(cur_old->name, (const xmlChar*)TTS_TAG_CONFIG_BASE_TAG)) {
804 SLOG(LOG_ERROR, tts_tag(), "[ERROR] The wrong type, root node is NOT %s", TTS_TAG_CONFIG_BASE_TAG);
810 cur_new = cur_new->xmlChildrenNode;
811 cur_old = cur_old->xmlChildrenNode;
812 if (cur_new == NULL || cur_old == NULL) {
813 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document");
819 while (cur_new != NULL && cur_old != NULL) {
820 if (0 == xmlStrcmp(cur_new->name, (const xmlChar*)TTS_TAG_CONFIG_ENGINE_ID)) {
821 if (0 == xmlStrcmp(cur_old->name, (const xmlChar*)TTS_TAG_CONFIG_ENGINE_ID)) {
822 key_old = xmlNodeGetContent(cur_old);
823 if (NULL != key_old) {
824 key_new = xmlNodeGetContent(cur_new);
825 if (NULL != key_new) {
826 if (0 != xmlStrcmp(key_old, key_new)) {
827 SLOG(LOG_DEBUG, tts_tag(), "Old engine id(%s), New engine(%s)",
828 (char*)key_old, (char*)key_new);
829 if (NULL != *engine) free(*engine);
830 *engine = strdup((char*)key_new);
837 SLOG(LOG_ERROR, tts_tag(), "[ERROR] old config and new config are different");
839 } else if (0 == xmlStrcmp(cur_new->name, (const xmlChar*)TTS_TAG_CONFIG_ENGINE_SETTING)) {
840 if (0 == xmlStrcmp(cur_old->name, (const xmlChar*)TTS_TAG_CONFIG_ENGINE_SETTING)) {
841 key_old = xmlNodeGetContent(cur_old);
842 if (NULL != key_old) {
843 key_new = xmlNodeGetContent(cur_new);
844 if (NULL != key_new) {
845 if (0 != xmlStrcmp(key_old, key_new)) {
846 SLOG(LOG_DEBUG, tts_tag(), "Old engine setting(%s), New engine setting(%s)",
847 (char*)key_old, (char*)key_new);
848 if (NULL != *setting) free(*setting);
849 *setting = strdup((char*)key_new);
856 SLOG(LOG_ERROR, tts_tag(), "[ERROR] old config and new config are different");
858 } else if (0 == xmlStrcmp(cur_new->name, (const xmlChar*)TTS_TAG_CONFIG_AUTO_VOICE)) {
859 if (0 == xmlStrcmp(cur_old->name, (const xmlChar*)TTS_TAG_CONFIG_AUTO_VOICE)) {
860 key_old = xmlNodeGetContent(cur_old);
861 if (NULL != key_old) {
862 key_new = xmlNodeGetContent(cur_new);
863 if (NULL != key_new) {
864 if (0 != xmlStrcmp(key_old, key_new)) {
865 SLOG(LOG_DEBUG, tts_tag(), "Old auto voice (%s), New auto voice(%s)",
866 (char*)key_old, (char*)key_new);
867 if (0 == xmlStrcmp((const xmlChar*)"on", key_new)) {
878 SLOG(LOG_ERROR, tts_tag(), "[ERROR] old config and new config are different");
880 } else if (0 == xmlStrcmp(cur_new->name, (const xmlChar*)TTS_TAG_CONFIG_LANGUAGE)) {
881 if (0 == xmlStrcmp(cur_old->name, (const xmlChar*)TTS_TAG_CONFIG_LANGUAGE)) {
882 key_old = xmlNodeGetContent(cur_old);
883 if (NULL != key_old) {
884 key_new = xmlNodeGetContent(cur_new);
885 if (NULL != key_new) {
886 if (0 != xmlStrcmp(key_old, key_new)) {
887 SLOG(LOG_DEBUG, tts_tag(), "Old language(%s), New language(%s)",
888 (char*)key_old, (char*)key_new);
889 if (NULL != *language) free(*language);
890 *language = strdup((char*)key_new);
897 SLOG(LOG_ERROR, tts_tag(), "[ERROR] old config and new config are different");
899 } else if (0 == xmlStrcmp(cur_new->name, (const xmlChar*)TTS_TAG_CONFIG_VOICE_TYPE)) {
900 if (0 == xmlStrcmp(cur_old->name, (const xmlChar*)TTS_TAG_CONFIG_VOICE_TYPE)) {
901 key_old = xmlNodeGetContent(cur_old);
902 if (NULL != key_old) {
903 key_new = xmlNodeGetContent(cur_new);
904 if (NULL != key_new) {
905 if (0 != xmlStrcmp(key_old, key_new)) {
906 SLOG(LOG_DEBUG, tts_tag(), "Old voice type(%s), New voice type(%s)",
907 (char*)key_old, (char*)key_new);
908 if (0 == xmlStrcmp(key_new, (const xmlChar *)TTS_TAG_VOICE_TYPE_FEMALE)) {
909 *voice_type = (int)TTS_CONFIG_VOICE_TYPE_FEMALE;
910 } else if (0 == xmlStrcmp(key_new, (const xmlChar *)TTS_TAG_VOICE_TYPE_MALE)) {
911 *voice_type = (int)TTS_CONFIG_VOICE_TYPE_MALE;
912 } else if (0 == xmlStrcmp(key_new, (const xmlChar *)TTS_TAG_VOICE_TYPE_CHILD)) {
913 *voice_type = (int)TTS_CONFIG_VOICE_TYPE_CHILD;
915 SLOG(LOG_ERROR, tts_tag(), "[ERROR] New voice type is not valid");
923 SLOG(LOG_ERROR, tts_tag(), "[ERROR] old config and new config are different");
925 } else if (0 == xmlStrcmp(cur_new->name, (const xmlChar*)TTS_TAG_CONFIG_SPEECH_RATE)) {
926 if (0 == xmlStrcmp(cur_old->name, (const xmlChar*)TTS_TAG_CONFIG_SPEECH_RATE)) {
927 key_old = xmlNodeGetContent(cur_old);
928 if (NULL != key_old) {
929 key_new = xmlNodeGetContent(cur_new);
930 if (NULL != key_new) {
931 if (0 != xmlStrcmp(key_old, key_new)) {
932 SLOG(LOG_DEBUG, tts_tag(), "Old speech rate(%s), New speech rate(%s)",
933 (char*)key_old, (char*)key_new);
934 *speech_rate = atoi((char*)key_new);
941 SLOG(LOG_ERROR, tts_tag(), "[ERROR] old config and new config are different");
943 } else if (0 == xmlStrcmp(cur_new->name, (const xmlChar*)TTS_TAG_CONFIG_PITCH)) {
944 if (0 == xmlStrcmp(cur_old->name, (const xmlChar*)TTS_TAG_CONFIG_PITCH)) {
945 key_old = xmlNodeGetContent(cur_old);
946 if (NULL != key_old) {
947 key_new = xmlNodeGetContent(cur_new);
948 if (NULL != key_new) {
949 if (0 != xmlStrcmp(key_old, key_new)) {
950 SLOG(LOG_DEBUG, tts_tag(), "Old pitch(%s), New pitch(%s)",
951 (char*)key_old, (char*)key_new);
952 *pitch = atoi((char*)key_new);
959 SLOG(LOG_ERROR, tts_tag(), "[ERROR] old config and new config are different");
965 cur_new = cur_new->next;
966 cur_old = cur_old->next;
969 if (NULL != g_config_doc) {
970 xmlFreeDoc(g_config_doc);