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.
21 #include <sys/inotify.h>
24 #include "tts_config_mgr.h"
25 #include "tts_config_parser.h"
30 tts_config_engine_changed_cb engine_cb;
31 tts_config_voice_changed_cb voice_cb;
32 tts_config_speech_rate_changed_cb speech_cb;
33 tts_config_screen_reader_changed_cb screen_cb;
34 tts_config_pitch_changed_cb pitch_cb;
36 } tts_config_client_s;
38 extern char* tts_tag();
40 static GSList* g_engine_list = NULL;
42 static GSList* g_config_client_list = NULL;
44 static tts_config_s* g_config_info = NULL;
46 static Ecore_Fd_Handler* g_config_fd_handler_noti = NULL;
47 static int g_config_fd_noti;
48 static int g_config_wd_noti;
50 /* For engine directory monitoring */
52 Ecore_Fd_Handler* dir_fd_handler;
55 } tts_engine_inotify_s;
57 static GList* g_ino_list = NULL;
59 int __tts_config_mgr_print_engine_info();
60 static int __tts_config_mgr_register_engine_config_updated_event(const char* path);
61 static int __tts_config_mgr_unregister_engine_config_updated_event();
63 int __tts_config_mgr_check_engine_is_valid(const char* engine_id)
65 if (NULL == engine_id) {
66 SLOG(LOG_ERROR, tts_tag(), "Input parameter is NULL");
71 tts_engine_info_s *engine_info = NULL;
73 if (0 >= g_slist_length(g_engine_list)) {
74 SLOG(LOG_ERROR, tts_tag(), "There is no engine!!");
78 /* Get a first item */
79 iter = g_slist_nth(g_engine_list, 0);
81 while (NULL != iter) {
82 engine_info = iter->data;
84 if (NULL == engine_info) {
85 SLOG(LOG_ERROR, tts_tag(), "engine info is NULL");
89 if (0 == strcmp(engine_id, engine_info->uuid)) {
90 SLOG(LOG_DEBUG, tts_tag(), "Default engine is valid : %s", engine_id);
94 iter = g_slist_next(iter);
97 /* Change default engine */
98 iter = g_slist_nth(g_engine_list, 0);
100 SLOG(LOG_ERROR, tts_tag(), "[ERROR] No engine in list");
101 return TTS_CONFIG_ERROR_OPERATION_FAILED;
104 engine_info = iter->data;
105 if (NULL == g_config_info) {
106 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Invalid engine info in list");
107 return TTS_CONFIG_ERROR_OPERATION_FAILED;
110 if (NULL != g_config_info->engine_id) free(g_config_info->engine_id);
111 if (NULL != g_config_info->setting) free(g_config_info->setting);
113 g_config_info->engine_id = strdup(engine_info->uuid);
114 g_config_info->setting = strdup(engine_info->setting);
116 SLOG(LOG_DEBUG, tts_tag(), "Default engine is changed : %s", g_config_info->engine_id);
118 /* Change is default voice */
119 GSList *iter_voice = NULL;
120 tts_config_voice_s* voice = NULL;
121 bool is_valid_voice = false;
123 /* Get a first item */
124 iter_voice = g_slist_nth(engine_info->voices, 0);
126 while (NULL != iter_voice) {
127 /*Get handle data from list*/
128 voice = iter_voice->data;
131 if (NULL != voice->language && NULL != g_config_info->language) {
132 if (0 == strcmp(voice->language, g_config_info->language)) {
133 if (voice->type == g_config_info->type) {
134 /* language is valid */
135 is_valid_voice = true;
137 free(g_config_info->language);
138 g_config_info->language = strdup(voice->language);
139 g_config_info->type = voice->type;
141 SLOG(LOG_DEBUG, tts_tag(), "Default voice is changed : lang(%s) type(%d)", voice->language, voice->type);
148 iter_voice = g_slist_next(iter_voice);
151 if (false == is_valid_voice) {
152 /* Select first voice as default */
153 if (NULL != g_config_info->language) {
154 free(g_config_info->language);
156 iter_voice = g_slist_nth(engine_info->voices, 0);
157 if (NULL == iter_voice) {
158 SLOG(LOG_ERROR, tts_tag(), "Fail to get voice list");
159 return TTS_CONFIG_ERROR_OPERATION_FAILED;
161 voice = iter_voice->data;
163 if (NULL == voice || NULL == voice->language) {
164 SLOG(LOG_ERROR, tts_tag(), "Fail to get voice info from list");
165 return TTS_CONFIG_ERROR_OPERATION_FAILED;
168 g_config_info->language = strdup(voice->language);
169 g_config_info->type = voice->type;
170 SLOG(LOG_DEBUG, tts_tag(), "Default voice is changed : lang(%s) type(%d)", voice->language, voice->type);
174 if (0 != tts_parser_set_engine(g_config_info->engine_id, g_config_info->setting,
175 g_config_info->language, g_config_info->type)) {
176 SLOG(LOG_ERROR, tts_tag(), " Fail to save config");
177 return TTS_CONFIG_ERROR_OPERATION_FAILED;
183 bool __tts_config_mgr_check_lang_is_valid(const char* engine_id, const char* language, int type)
185 if (NULL == engine_id || NULL == language) {
186 SLOG(LOG_ERROR, tts_tag(), "Input parameter is NULL");
191 tts_engine_info_s *engine_info = NULL;
193 if (0 >= g_slist_length(g_engine_list)) {
194 SLOG(LOG_ERROR, tts_tag(), "There is no engine!!");
198 /* Get a first item */
199 iter = g_slist_nth(g_engine_list, 0);
201 while (NULL != iter) {
202 engine_info = iter->data;
204 if (NULL == engine_info) {
205 SLOG(LOG_ERROR, tts_tag(), "engine info is NULL");
209 if (0 != strcmp(engine_id, engine_info->uuid)) {
210 iter = g_slist_next(iter);
214 GSList *iter_voice = NULL;
215 tts_config_voice_s* voice = NULL;
217 if (g_slist_length(engine_info->voices) <= 0) {
218 SLOG(LOG_ERROR, tts_tag(), "There is no voice : %s", engine_info->uuid);
219 iter = g_slist_next(iter);
223 /* Get a first item */
224 iter_voice = g_slist_nth(engine_info->voices, 0);
227 while (NULL != iter_voice) {
228 /*Get handle data from list*/
229 voice = iter_voice->data;
232 if (0 == strcmp(language, voice->language)) {
233 if (type == voice->type) {
240 iter_voice = g_slist_next(iter_voice);
250 int __tts_config_mgr_select_lang(const char* engine_id, char** language, int* type)
252 if (NULL == engine_id || NULL == language) {
253 SLOG(LOG_ERROR, tts_tag(), "Input parameter is NULL");
258 tts_engine_info_s *engine_info = NULL;
260 if (0 >= g_slist_length(g_engine_list)) {
261 SLOG(LOG_ERROR, tts_tag(), "There is no engine!!");
265 /* Get a first item */
266 iter = g_slist_nth(g_engine_list, 0);
268 while (NULL != iter) {
269 engine_info = iter->data;
271 if (NULL == engine_info) {
272 SLOG(LOG_ERROR, tts_tag(), "engine info is NULL");
276 if (0 != strcmp(engine_id, engine_info->uuid)) {
277 iter = g_slist_next(iter);
281 GSList *iter_voice = NULL;
282 tts_config_voice_s* voice = NULL;
284 if (g_slist_length(engine_info->voices) <= 0) {
285 SLOG(LOG_ERROR, tts_tag(), "There is no voice : %s", engine_info->uuid);
289 /* Get a first item */
290 iter_voice = g_slist_nth(engine_info->voices, 0);
292 while (NULL != iter_voice) {
293 voice = iter_voice->data;
295 /* Default language */
296 if (0 == strcmp(TTS_BASE_LANGUAGE, voice->language)) {
297 *language = strdup(voice->language);
300 SECURE_SLOG(LOG_DEBUG, tts_tag(), "Selected language(%s) type(%d)", *language, *type);
304 iter_voice = g_slist_next(iter_voice);
307 /* Not support base language */
309 *language = strdup(voice->language);
312 SECURE_SLOG(LOG_DEBUG, tts_tag(), "Selected language(%s) type(%d)", *language, *type);
321 Eina_Bool tts_config_mgr_inotify_event_cb(void* data, Ecore_Fd_Handler *fd_handler)
323 SLOG(LOG_DEBUG, tts_tag(), "===== Config changed callback event");
326 struct inotify_event event;
327 memset(&event, '\0', sizeof(struct inotify_event));
329 length = read(g_config_fd_noti, &event, sizeof(struct inotify_event));
331 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty Inotify event");
332 SLOG(LOG_DEBUG, tts_tag(), "=====");
333 SLOG(LOG_DEBUG, tts_tag(), " ");
334 return ECORE_CALLBACK_DONE;
337 if (IN_CLOSE_WRITE == event.mask) {
338 /* check config changed state */
340 char* setting = NULL;
342 bool auto_voice = g_config_info->auto_voice;
344 int speech_rate = -1;
348 tts_config_client_s* temp_client = NULL;
350 if (0 != tts_parser_find_config_changed(&engine, &setting, &auto_voice, &lang, &voice_type, &speech_rate, &pitch))
351 return ECORE_CALLBACK_PASS_ON;
354 if (NULL != engine || NULL != setting) {
355 if (NULL != engine) {
356 if (NULL != g_config_info->engine_id)
357 free(g_config_info->engine_id);
359 g_config_info->engine_id = strdup(engine);
361 if (NULL != setting) {
362 if (NULL != g_config_info->setting)
363 free(g_config_info->setting);
365 g_config_info->setting = strdup(setting);
368 SECURE_SLOG(LOG_DEBUG, tts_tag(), "Engine change(%s)", g_config_info->engine_id);
370 /* Call all callbacks of client*/
371 iter = g_slist_nth(g_config_client_list, 0);
373 while (NULL != iter) {
374 temp_client = iter->data;
376 if (NULL != temp_client) {
377 if (NULL != temp_client->engine_cb) {
378 SECURE_SLOG(LOG_DEBUG, tts_tag(), "Engine changed callback : uid(%d)", temp_client->uid);
379 temp_client->engine_cb(g_config_info->engine_id, g_config_info->setting,
380 g_config_info->language, g_config_info->type,
381 g_config_info->auto_voice, g_config_info->credential, temp_client->user_data);
385 iter = g_slist_next(iter);
389 if (auto_voice != g_config_info->auto_voice) {
390 g_config_info->auto_voice = auto_voice;
393 if (NULL != lang || -1 != voice_type) {
394 char* before_lang = NULL;
397 before_lang = strdup(g_config_info->language);
398 before_type = g_config_info->type;
401 if (NULL != g_config_info->language)
402 free(g_config_info->language);
404 g_config_info->language = strdup(lang);
406 if (-1 != voice_type) {
407 g_config_info->type = voice_type;
410 SECURE_SLOG(LOG_DEBUG, tts_tag(), "Voice change(%s, %d)", g_config_info->language, g_config_info->type);
412 /* Call all callbacks of client*/
413 iter = g_slist_nth(g_config_client_list, 0);
415 while (NULL != iter) {
416 temp_client = iter->data;
418 if (NULL != temp_client) {
419 if (NULL != temp_client->voice_cb) {
420 SECURE_SLOG(LOG_DEBUG, tts_tag(), "Voice changed callback : uid(%d)", temp_client->uid);
421 temp_client->voice_cb(before_lang, before_type,
422 g_config_info->language, g_config_info->type,
423 g_config_info->auto_voice, temp_client->user_data);
427 iter = g_slist_next(iter);
430 if (NULL != before_lang) {
435 if (-1 != speech_rate) {
436 g_config_info->speech_rate = speech_rate;
438 SECURE_SLOG(LOG_DEBUG, tts_tag(), "Speech rate change(%d)", g_config_info->speech_rate);
440 /* Call all callbacks of client*/
441 iter = g_slist_nth(g_config_client_list, 0);
443 while (NULL != iter) {
444 temp_client = iter->data;
446 if (NULL != temp_client) {
447 if (NULL != temp_client->speech_cb) {
448 SECURE_SLOG(LOG_DEBUG, tts_tag(), "Speech rate changed callback : uid(%d)", temp_client->uid);
449 temp_client->speech_cb(g_config_info->speech_rate, temp_client->user_data);
453 iter = g_slist_next(iter);
458 g_config_info->pitch = pitch;
460 SECURE_SLOG(LOG_DEBUG, tts_tag(), "pitch change(%d)", g_config_info->pitch);
462 /* Call all callbacks of client*/
463 iter = g_slist_nth(g_config_client_list, 0);
465 while (NULL != iter) {
466 temp_client = iter->data;
468 if (NULL != temp_client) {
469 if (NULL != temp_client->pitch_cb) {
470 SECURE_SLOG(LOG_DEBUG, tts_tag(), "Pitch changed callback : uid(%d)", temp_client->uid);
471 temp_client->pitch_cb(g_config_info->pitch, temp_client->user_data);
475 iter = g_slist_next(iter);
479 if (NULL != engine) free(engine);
480 if (NULL != setting) free(setting);
481 if (NULL != lang) free(lang);
483 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Undefined event");
486 SLOG(LOG_DEBUG, tts_tag(), "=====");
487 SLOG(LOG_DEBUG, tts_tag(), " ");
489 return ECORE_CALLBACK_PASS_ON;
492 int __tts_config_mgr_register_config_event()
494 /* get file notification handler */
500 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail get inotify fd");
503 g_config_fd_noti = fd;
505 wd = inotify_add_watch(fd, TTS_CONFIG, IN_CLOSE_WRITE);
506 g_config_wd_noti = wd;
508 g_config_fd_handler_noti = ecore_main_fd_handler_add(fd, ECORE_FD_READ,
509 (Ecore_Fd_Cb)tts_config_mgr_inotify_event_cb, NULL, NULL, NULL);
510 if (NULL == g_config_fd_handler_noti) {
511 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to get handler_noti");
515 /* Set non-blocking mode of file */
517 value = fcntl(fd, F_GETFL, 0);
520 if (0 > fcntl(fd, F_SETFL, value)) {
521 SLOG(LOG_WARN, tts_tag(), "[WARNING] Fail to set non-block mode");
527 int __tts_config_mgr_unregister_config_event()
529 /* delete inotify variable */
530 ecore_main_fd_handler_del(g_config_fd_handler_noti);
531 inotify_rm_watch(g_config_fd_noti, g_config_wd_noti);
532 close(g_config_fd_noti);
537 int __tts_config_set_auto_language()
540 value = vconf_get_str(TTS_LANGSET_KEY);
542 SLOG(LOG_ERROR, tts_tag(), "[Config ERROR] Fail to get display language");
546 char temp_lang[6] = {'\0', };
547 strncpy(temp_lang, value, 5);
550 if (true == __tts_config_mgr_check_lang_is_valid(g_config_info->engine_id, temp_lang, g_config_info->type)) {
551 /* tts default voice change */
552 if (NULL == g_config_info->language) {
553 SLOG(LOG_ERROR, tts_tag(), "Current config language is NULL");
557 char* before_lang = NULL;
560 if (0 != tts_parser_set_voice(temp_lang, g_config_info->type)) {
561 SLOG(LOG_ERROR, tts_tag(), "Fail to save default voice");
565 before_lang = strdup(g_config_info->language);
566 before_type = g_config_info->type;
568 free(g_config_info->language);
569 g_config_info->language = strdup(temp_lang);
571 SECURE_SLOG(LOG_DEBUG, tts_tag(), "[Config] Default voice : lang(%s) type(%d)",
572 g_config_info->language, g_config_info->type);
575 tts_config_client_s* temp_client = NULL;
577 /* Call all callbacks of client*/
578 iter = g_slist_nth(g_config_client_list, 0);
580 while (NULL != iter) {
581 temp_client = iter->data;
583 if (NULL != temp_client) {
584 if (NULL != temp_client->voice_cb) {
585 temp_client->voice_cb(before_lang, before_type,
586 g_config_info->language, g_config_info->type,
587 g_config_info->auto_voice, temp_client->user_data);
591 iter = g_slist_next(iter);
594 if (NULL != before_lang) {
598 /* Display language is not valid */
599 char* tmp_language = NULL;
601 if (0 != __tts_config_mgr_select_lang(g_config_info->engine_id, &tmp_language, &tmp_type)) {
602 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to select language");
606 if (NULL == tmp_language) {
607 SLOG(LOG_ERROR, tts_tag(), "[ERROR] language is NULL");
611 if (0 != tts_parser_set_voice(tmp_language, tmp_type)) {
612 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to save config");
616 SECURE_SLOG(LOG_DEBUG, tts_tag(), "[Config] Default voice : lang(%s) type(%d)",
617 tmp_language, tmp_type);
620 tts_config_client_s* temp_client = NULL;
622 /* Call all callbacks of client*/
623 iter = g_slist_nth(g_config_client_list, 0);
625 while (NULL != iter) {
626 temp_client = iter->data;
628 if (NULL != temp_client) {
629 if (NULL != temp_client->voice_cb) {
630 temp_client->voice_cb(g_config_info->language, g_config_info->type,
631 tmp_language, tmp_type, g_config_info->auto_voice, temp_client->user_data);
635 iter = g_slist_next(iter);
638 if (NULL != g_config_info->language) {
639 free(g_config_info->language);
640 g_config_info->language = strdup(tmp_language);
643 g_config_info->type = tmp_type;
651 void __tts_config_display_language_changed_cb(keynode_t *key, void *data)
653 if (true == g_config_info->auto_voice) {
654 __tts_config_set_auto_language();
660 void __tts_config_screen_reader_changed_cb(keynode_t *key, void *data)
664 ret = vconf_get_bool(TTS_ACCESSIBILITY_KEY, &screen_reader);
666 SLOG(LOG_ERROR, tts_tag(), "[Config ERROR] Fail to get screen reader");
671 tts_config_client_s* temp_client = NULL;
673 /* Call all callbacks of client*/
674 iter = g_slist_nth(g_config_client_list, 0);
676 while (NULL != iter) {
677 temp_client = iter->data;
679 if (NULL != temp_client) {
680 if (NULL != temp_client->screen_cb) {
681 temp_client->screen_cb((bool)screen_reader);
685 iter = g_slist_next(iter);
689 int __tts_config_release_client(int uid)
692 tts_config_client_s* temp_client = NULL;
694 if (0 < g_slist_length(g_config_client_list)) {
696 iter = g_slist_nth(g_config_client_list, 0);
698 while (NULL != iter) {
699 temp_client = iter->data;
701 if (NULL != temp_client) {
702 if (uid == temp_client->uid) {
703 g_config_client_list = g_slist_remove(g_config_client_list, temp_client);
710 iter = g_slist_next(iter);
714 SLOG(LOG_DEBUG, tts_tag(), "Client count (%d)", g_slist_length(g_config_client_list));
716 return g_slist_length(g_config_client_list);
719 void __tts_config_release_engine()
722 tts_engine_info_s *engine_info = NULL;
724 if (0 < g_slist_length(g_engine_list)) {
726 /* Get a first item */
727 iter = g_slist_nth(g_engine_list, 0);
729 while (NULL != iter) {
730 engine_info = iter->data;
732 if (NULL != engine_info) {
733 g_engine_list = g_slist_remove(g_engine_list, engine_info);
735 tts_parser_free_engine_info(engine_info);
738 iter = g_slist_nth(g_engine_list, 0);
745 int __tts_config_mgr_get_engine_info()
750 struct dirent *dirp = NULL;
752 char filepath[512] = {'\0',};
754 tts_engine_info_s* info = NULL;
756 __tts_config_release_engine();
757 g_engine_list = NULL;
758 __tts_config_mgr_unregister_engine_config_updated_event();
760 /* Copy default info directory to download directory */
761 dp = opendir(TTS_DEFAULT_ENGINE_INFO);
763 SLOG(LOG_DEBUG, tts_tag(), "[CONFIG] No default directory : %s", TTS_DEFAULT_ENGINE_INFO);
766 ret = readdir_r(dp, &entry, &dirp);
768 SLOG(LOG_ERROR, tts_tag(), "[CONFIG] Fail to read directory");
773 filesize = strlen(TTS_DEFAULT_ENGINE_INFO) + strlen(dirp->d_name) + 2;
774 if (filesize >= 512) {
775 SECURE_SLOG(LOG_ERROR, tts_tag(), "[CONFIG ERROR] File path is too long : %s", dirp->d_name);
780 memset(filepath, '\0', 512);
781 snprintf(filepath, 512, "%s/%s", TTS_DEFAULT_ENGINE_INFO, dirp->d_name);
783 SECURE_SLOG(LOG_DEBUG, tts_tag(), "[CONFIG] Filepath(%s)", filepath);
785 char dest[512] = {'\0',};
786 snprintf(dest, 512, "%s/%s", TTS_DOWNLOAD_ENGINE_INFO, dirp->d_name);
788 if (0 != access(dest, F_OK)) {
789 if (0 != tts_parser_copy_xml(filepath, dest)) {
790 SLOG(LOG_ERROR, tts_tag(), "[CONFIG ERROR] Fail to copy engine info");
794 } while (NULL != dirp);
799 /* Get engine info from default engine directory */
800 dp = opendir(TTS_DOWNLOAD_ENGINE_INFO);
802 SLOG(LOG_DEBUG, tts_tag(), "[CONFIG] No downloadable directory : %s", TTS_DOWNLOAD_ENGINE_INFO);
805 ret = readdir_r(dp, &entry, &dirp);
807 SLOG(LOG_ERROR, tts_tag(), "[CONFIG] Fail to read directory");
812 filesize = strlen(TTS_DOWNLOAD_ENGINE_INFO) + strlen(dirp->d_name) + 2;
813 if (filesize >= 512) {
814 SECURE_SLOG(LOG_ERROR, tts_tag(), "[CONFIG ERROR] File path is too long : %s", dirp->d_name);
819 memset(filepath, '\0', 512);
820 snprintf(filepath, 512, "%s/%s", TTS_DOWNLOAD_ENGINE_INFO, dirp->d_name);
822 SECURE_SLOG(LOG_DEBUG, tts_tag(), "[CONFIG] Filepath(%s)", filepath);
824 if (0 == tts_parser_get_engine_info(filepath, &info)) {
825 g_engine_list = g_slist_append(g_engine_list, info);
826 if (0 != __tts_config_mgr_register_engine_config_updated_event(filepath)) {
827 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to register engine config updated event");
831 } while (NULL != dirp);
836 if (0 >= g_slist_length(g_engine_list)) {
837 SLOG(LOG_ERROR, tts_tag(), "[ERROR] No engine");
844 static Eina_Bool __tts_config_mgr_engine_config_inotify_event_callback(void* data, Ecore_Fd_Handler *fd_handler)
846 SLOG(LOG_DEBUG, tts_tag(), "===== Engine config updated callback event");
848 tts_engine_inotify_s *ino = (tts_engine_inotify_s *)data;
849 int dir_fd = ino->dir_fd;
852 struct inotify_event event;
853 memset(&event, '\0', sizeof(struct inotify_event));
855 length = read(dir_fd, &event, sizeof(struct inotify_event));
857 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty Inotify event");
858 SLOG(LOG_DEBUG, tts_tag(), "=====");
859 SLOG(LOG_DEBUG, tts_tag(), " ");
860 return ECORE_CALLBACK_DONE;
863 if (IN_CLOSE_WRITE == event.mask) {
864 int ret = __tts_config_mgr_get_engine_info();
866 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to get engine info when config updated");
868 __tts_config_mgr_print_engine_info();
869 bool support = tts_config_check_default_voice_is_valid(g_config_info->language, g_config_info->type);
870 if (false == support) {
871 SLOG(LOG_DEBUG, tts_tag(), "[ERROR] Default voice is valid");
872 char* temp_lang = NULL;
874 ret = __tts_config_mgr_select_lang(g_config_info->engine_id, &temp_lang, &temp_type);
876 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to get voice");
879 ret = tts_config_mgr_set_voice(temp_lang, temp_type);
881 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to set voice");
883 SLOG(LOG_DEBUG, tts_tag(), "[DEBUG] Saved default voice : lang(%s), type(%d)", g_config_info->language, g_config_info->type);
885 if (NULL != temp_lang) free(temp_lang);
889 tts_config_client_s* temp_client = NULL;
890 /* Call all callbacks of client*/
891 iter = g_slist_nth(g_config_client_list, 0);
893 while (NULL != iter) {
894 temp_client = iter->data;
896 if (NULL != temp_client) {
897 if (NULL != temp_client->engine_cb) {
898 SECURE_SLOG(LOG_DEBUG, tts_tag(), "Engine changed callback : uid(%d)", temp_client->uid);
899 temp_client->engine_cb(g_config_info->engine_id, g_config_info->setting,
900 g_config_info->language, g_config_info->type,
901 g_config_info->auto_voice, g_config_info->credential, temp_client->user_data);
905 iter = g_slist_next(iter);
908 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Undefined event");
911 SLOG(LOG_DEBUG, tts_tag(), "=====");
912 SLOG(LOG_DEBUG, tts_tag(), " ");
914 return ECORE_CALLBACK_PASS_ON;
917 static int __tts_config_mgr_register_engine_config_updated_event(const char* path)
920 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Path is NULL");
924 /* For engine directory monitoring */
925 tts_engine_inotify_s *ino = (tts_engine_inotify_s *)calloc(1, sizeof(tts_engine_inotify_s));
927 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to allocate memory");
931 ino->dir_fd = inotify_init();
932 if (ino->dir_fd < 0) {
933 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to init inotify");
940 ino->dir_wd = inotify_add_watch(ino->dir_fd, path, IN_CLOSE_WRITE);
941 SLOG(LOG_DEBUG, tts_tag(), "Add inotify watch(%s)", path);
942 if (ino->dir_wd < 0) {
943 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to add watch");
947 ino->dir_fd_handler = ecore_main_fd_handler_add(ino->dir_fd, ECORE_FD_READ, (Ecore_Fd_Cb)__tts_config_mgr_engine_config_inotify_event_callback, (void *)ino, NULL, NULL);
948 if (NULL == ino->dir_fd_handler) {
949 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to add fd handler");
953 /* Set non-blocking mode of file */
955 value = fcntl(ino->dir_fd, F_GETFL, 0);
958 if (0 > fcntl(ino->dir_fd, F_SETFL, value)) {
959 SLOG(LOG_WARN, tts_tag(), "[WARNING] Fail to set non-block mode");
962 g_ino_list = g_list_append(g_ino_list, ino);
967 static int __tts_config_mgr_unregister_engine_config_updated_event()
969 /* delete all inotify variable */
970 if (0 < g_list_length(g_ino_list)) {
972 iter = g_list_first(g_ino_list);
974 while (NULL != iter) {
975 tts_engine_inotify_s *tmp = iter->data;
978 ecore_main_fd_handler_del(tmp->dir_fd_handler);
979 inotify_rm_watch(tmp->dir_fd, tmp->dir_wd);
985 g_ino_list = g_list_remove_link(g_ino_list, iter);
987 iter = g_list_first(g_ino_list);
994 int tts_config_mgr_initialize(int uid)
998 tts_config_client_s* temp_client = NULL;
1001 if (0 < g_slist_length(g_config_client_list)) {
1003 iter = g_slist_nth(g_config_client_list, 0);
1005 while (NULL != iter) {
1006 get_uid = iter->data;
1008 if (uid == *get_uid) {
1009 SECURE_SLOG(LOG_WARN, tts_tag(), "[CONFIG] uid(%d) has already registered", uid);
1013 iter = g_slist_next(iter);
1016 temp_client = (tts_config_client_s*)calloc(1, sizeof(tts_config_client_s));
1017 if (NULL == temp_client) {
1018 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to allocate memory");
1019 return TTS_CONFIG_ERROR_OUT_OF_MEMORY;
1021 temp_client->uid = uid;
1023 g_config_client_list = g_slist_append(g_config_client_list, temp_client);
1025 SECURE_SLOG(LOG_WARN, tts_tag(), "[CONFIG] Add uid(%d) but config has already initialized", uid);
1028 temp_client = (tts_config_client_s*)calloc(1, sizeof(tts_config_client_s));
1029 if (NULL == temp_client) {
1030 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to allocate memory");
1031 return TTS_CONFIG_ERROR_OUT_OF_MEMORY;
1033 temp_client->uid = uid;
1035 g_config_client_list = g_slist_append(g_config_client_list, temp_client);
1038 if (0 != access(TTS_CONFIG_BASE, F_OK)) {
1039 if (0 != mkdir(TTS_CONFIG_BASE, S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH)) {
1040 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to make directory : %s", TTS_CONFIG_BASE);
1041 __tts_config_release_client(uid);
1042 __tts_config_release_engine();
1043 return TTS_CONFIG_ERROR_OPERATION_FAILED;
1045 SLOG(LOG_DEBUG, tts_tag(), "Success to make directory : %s", TTS_CONFIG_BASE);
1049 if (0 != access(TTS_HOME, F_OK)) {
1050 if (0 != mkdir(TTS_HOME, S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH)) {
1051 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to make directory : %s", TTS_HOME);
1052 __tts_config_release_client(uid);
1053 __tts_config_release_engine();
1054 return TTS_CONFIG_ERROR_OPERATION_FAILED;
1056 SLOG(LOG_DEBUG, tts_tag(), "Success to make directory : %s", TTS_HOME);
1060 if (0 != access(TTS_DOWNLOAD_BASE, F_OK)) {
1061 if (0 != mkdir(TTS_DOWNLOAD_BASE, S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH)) {
1062 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to make directory : %s", TTS_DOWNLOAD_BASE);
1063 __tts_config_release_client(uid);
1064 __tts_config_release_engine();
1065 return TTS_CONFIG_ERROR_OPERATION_FAILED;
1067 SLOG(LOG_DEBUG, tts_tag(), "Success to make directory : %s", TTS_DOWNLOAD_BASE);
1071 if (0 != access(TTS_DOWNLOAD_ENGINE_INFO, F_OK)) {
1072 if (0 != mkdir(TTS_DOWNLOAD_ENGINE_INFO, S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH)) {
1073 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to make directory : %s", TTS_DOWNLOAD_ENGINE_INFO);
1074 __tts_config_release_client(uid);
1075 __tts_config_release_engine();
1076 return TTS_CONFIG_ERROR_OPERATION_FAILED;
1078 SLOG(LOG_DEBUG, tts_tag(), "Success to make directory : %s", TTS_DOWNLOAD_ENGINE_INFO);
1082 if (0 != __tts_config_mgr_get_engine_info()) {
1083 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to get engine info");
1084 __tts_config_release_client(uid);
1085 __tts_config_release_engine();
1086 return TTS_CONFIG_ERROR_ENGINE_NOT_FOUND;
1089 __tts_config_mgr_print_engine_info();
1091 if (0 != tts_parser_load_config(&g_config_info)) {
1092 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to parse configure information");
1093 __tts_config_release_client(uid);
1094 __tts_config_release_engine();
1095 return TTS_CONFIG_ERROR_OPERATION_FAILED;
1098 /* Check whether engine id is valid */
1099 if (0 != __tts_config_mgr_check_engine_is_valid(g_config_info->engine_id)) {
1100 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to get default engine");
1101 __tts_config_release_client(uid);
1102 __tts_config_release_engine();
1103 tts_parser_unload_config(g_config_info);
1104 return TTS_CONFIG_ERROR_ENGINE_NOT_FOUND;
1107 if (true == g_config_info->auto_voice) {
1108 /* Check language with display language */
1109 __tts_config_set_auto_language();
1111 if (false == __tts_config_mgr_check_lang_is_valid(g_config_info->engine_id, g_config_info->language, g_config_info->type)) {
1112 /* Default language is not valid */
1113 char* tmp_language = NULL;
1115 if (0 != __tts_config_mgr_select_lang(g_config_info->engine_id, &tmp_language, &tmp_type)) {
1116 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to select language");
1117 __tts_config_release_client(uid);
1118 __tts_config_release_engine();
1119 tts_parser_unload_config(g_config_info);
1120 return TTS_CONFIG_ERROR_OPERATION_FAILED;
1123 if (NULL != tmp_language) {
1124 if (NULL != g_config_info->language) {
1125 free(g_config_info->language);
1126 g_config_info->language = strdup(tmp_language);
1129 g_config_info->type = tmp_type;
1133 if (0 != tts_parser_set_voice(g_config_info->language, g_config_info->type)) {
1134 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to save config");
1135 __tts_config_release_client(uid);
1136 __tts_config_release_engine();
1137 tts_parser_unload_config(g_config_info);
1138 return TTS_CONFIG_ERROR_OPERATION_FAILED;
1144 /* print daemon config */
1145 SLOG(LOG_DEBUG, tts_tag(), "== TTS config ==");
1146 SECURE_SLOG(LOG_DEBUG, tts_tag(), " engine : %s", g_config_info->engine_id);
1147 SECURE_SLOG(LOG_DEBUG, tts_tag(), " setting : %s", g_config_info->setting);
1148 SECURE_SLOG(LOG_DEBUG, tts_tag(), " auto voice : %s", g_config_info->auto_voice ? "on" : "off");
1149 SECURE_SLOG(LOG_DEBUG, tts_tag(), " language : %s", g_config_info->language);
1150 SECURE_SLOG(LOG_DEBUG, tts_tag(), " voice type : %d", g_config_info->type);
1151 SECURE_SLOG(LOG_DEBUG, tts_tag(), " speech rate : %d", g_config_info->speech_rate);
1152 SECURE_SLOG(LOG_DEBUG, tts_tag(), " pitch : %d", g_config_info->pitch);
1153 SLOG(LOG_DEBUG, tts_tag(), "=================");
1155 if (0 != __tts_config_mgr_register_config_event()) {
1156 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to register config event");
1157 __tts_config_release_client(uid);
1158 __tts_config_release_engine();
1159 tts_parser_unload_config(g_config_info);
1160 return TTS_CONFIG_ERROR_OPERATION_FAILED;
1163 /* Register to detect display language change */
1164 vconf_notify_key_changed(TTS_LANGSET_KEY, __tts_config_display_language_changed_cb, NULL);
1165 vconf_notify_key_changed(TTS_ACCESSIBILITY_KEY, __tts_config_screen_reader_changed_cb, NULL);
1167 /* For engine directory monitoring */
1168 //if (0 != __tts_config_mgr_register_engine_config_updated_event()) {
1169 // SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to register engine config updated event");
1170 // __tts_config_release_client(uid);
1171 // __tts_config_release_engine();
1172 // tts_parser_unload_config(g_config_info);
1173 // __tts_config_mgr_unregister_config_event();
1174 // return TTS_CONFIG_ERROR_OPERATION_FAILED;
1180 int tts_config_mgr_finalize(int uid)
1182 if (0 < __tts_config_release_client(uid)) {
1186 tts_config_mgr_unset_callback(uid);
1188 __tts_config_release_engine();
1190 tts_parser_unload_config(g_config_info);
1192 __tts_config_mgr_unregister_engine_config_updated_event();
1194 __tts_config_mgr_unregister_config_event();
1196 vconf_ignore_key_changed(TTS_LANGSET_KEY, __tts_config_display_language_changed_cb);
1197 vconf_ignore_key_changed(TTS_ACCESSIBILITY_KEY, __tts_config_screen_reader_changed_cb);
1202 int tts_config_mgr_set_callback(int uid,
1203 tts_config_engine_changed_cb engine_cb,
1204 tts_config_voice_changed_cb voice_cb,
1205 tts_config_speech_rate_changed_cb speech_cb,
1206 tts_config_pitch_changed_cb pitch_cb,
1209 GSList *iter = NULL;
1210 tts_config_client_s* temp_client = NULL;
1212 /* Call all callbacks of client*/
1213 iter = g_slist_nth(g_config_client_list, 0);
1215 while (NULL != iter) {
1216 temp_client = iter->data;
1218 if (NULL != temp_client) {
1219 if (uid == temp_client->uid) {
1220 temp_client->engine_cb = engine_cb;
1221 temp_client->voice_cb = voice_cb;
1222 temp_client->speech_cb = speech_cb;
1223 temp_client->pitch_cb = pitch_cb;
1224 temp_client->user_data = user_data;
1228 iter = g_slist_next(iter);
1233 int tts_config_mgr_unset_callback(int uid)
1235 GSList *iter = NULL;
1236 tts_config_client_s* temp_client = NULL;
1238 /* Call all callbacks of client*/
1239 iter = g_slist_nth(g_config_client_list, 0);
1241 while (NULL != iter) {
1242 temp_client = iter->data;
1244 if (NULL != temp_client) {
1245 if (uid == temp_client->uid) {
1246 temp_client->engine_cb = NULL;
1247 temp_client->voice_cb = NULL;
1248 temp_client->speech_cb = NULL;
1249 temp_client->pitch_cb = NULL;
1250 temp_client->user_data = NULL;
1254 iter = g_slist_next(iter);
1260 int tts_config_set_screen_reader_callback(int uid, tts_config_screen_reader_changed_cb callback)
1262 if (NULL == callback) {
1263 SLOG(LOG_ERROR, tts_tag(), "Input parameter is NULL");
1264 return TTS_CONFIG_ERROR_INVALID_PARAMETER;
1267 GSList *iter = NULL;
1268 tts_config_client_s* temp_client = NULL;
1270 /* Call all callbacks of client*/
1271 iter = g_slist_nth(g_config_client_list, 0);
1273 while (NULL != iter) {
1274 temp_client = iter->data;
1276 if (NULL != temp_client) {
1277 if (uid == temp_client->uid) {
1278 temp_client->screen_cb = callback;
1282 iter = g_slist_next(iter);
1287 int tts_config_unset_screen_reader_callback(int uid)
1289 GSList *iter = NULL;
1290 tts_config_client_s* temp_client = NULL;
1292 /* Call all callbacks of client*/
1293 iter = g_slist_nth(g_config_client_list, 0);
1295 while (NULL != iter) {
1296 temp_client = iter->data;
1298 if (NULL != temp_client) {
1299 if (uid == temp_client->uid) {
1300 temp_client->screen_cb = NULL;
1304 iter = g_slist_next(iter);
1310 int tts_config_mgr_get_engine_list(tts_config_supported_engine_cb callback, void* user_data)
1312 if (0 >= g_slist_length(g_config_client_list)) {
1313 SLOG(LOG_ERROR, tts_tag(), "Not initialized");
1314 return TTS_CONFIG_ERROR_INVALID_STATE;
1317 GSList *iter = NULL;
1318 tts_engine_info_s *engine_info = NULL;
1320 if (0 >= g_slist_length(g_engine_list)) {
1321 SLOG(LOG_ERROR, tts_tag(), "There is no engine!!");
1322 return TTS_CONFIG_ERROR_ENGINE_NOT_FOUND;
1325 /* Get a first item */
1326 iter = g_slist_nth(g_engine_list, 0);
1328 while (NULL != iter) {
1329 engine_info = iter->data;
1331 if (NULL != engine_info) {
1332 if (false == callback(engine_info->uuid, engine_info->name, engine_info->setting, user_data)) {
1337 iter = g_slist_next(iter);
1343 int tts_config_mgr_get_engine(char** engine)
1345 if (0 >= g_slist_length(g_config_client_list)) {
1346 SLOG(LOG_ERROR, tts_tag(), "Not initialized");
1347 return TTS_CONFIG_ERROR_INVALID_STATE;
1350 if (NULL == engine) {
1351 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Input parameter is NULL");
1352 return TTS_CONFIG_ERROR_INVALID_PARAMETER;
1355 if (NULL != g_config_info->engine_id) {
1356 /* Check engine id is valid */
1357 GSList *iter = NULL;
1358 tts_engine_info_s *engine_info = NULL;
1360 if (0 >= g_slist_length(g_engine_list)) {
1361 SLOG(LOG_ERROR, tts_tag(), "[ERROR] There is no engine!!");
1362 return TTS_CONFIG_ERROR_ENGINE_NOT_FOUND;
1365 /* Get a first item */
1366 iter = g_slist_nth(g_engine_list, 0);
1368 while (NULL != iter) {
1369 engine_info = iter->data;
1371 if (NULL != engine_info) {
1372 if (0 == strcmp(engine_info->uuid, g_config_info->engine_id)) {
1373 *engine = strdup(g_config_info->engine_id);
1377 iter = g_slist_next(iter);
1380 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Current engine id is not valid");
1382 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Engine id is NULL");
1385 return TTS_CONFIG_ERROR_OPERATION_FAILED;
1388 int tts_config_mgr_set_engine(const char* engine)
1390 if (0 >= g_slist_length(g_config_client_list)) {
1391 SLOG(LOG_ERROR, tts_tag(), "Not initialized");
1392 return TTS_CONFIG_ERROR_INVALID_STATE;
1396 return TTS_CONFIG_ERROR_INVALID_PARAMETER;
1398 /* Check current engine id with new engine id */
1399 if (NULL != g_config_info->engine_id) {
1400 if (0 == strcmp(g_config_info->engine_id, engine))
1404 if (0 >= g_slist_length(g_engine_list)) {
1405 SLOG(LOG_ERROR, tts_tag(), "[ERROR] There is no engine!!");
1406 return TTS_CONFIG_ERROR_ENGINE_NOT_FOUND;
1409 SLOG(LOG_DEBUG, tts_tag(), "New engine id : %s", engine);
1411 GSList *iter = NULL;
1412 tts_engine_info_s *engine_info = NULL;
1413 bool is_valid_engine = false;
1415 /* Get a first item */
1416 iter = g_slist_nth(g_engine_list, 0);
1418 while (NULL != iter) {
1419 engine_info = iter->data;
1421 if (NULL == engine_info) {
1422 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Engine info is NULL");
1423 iter = g_slist_next(iter);
1427 /* Check engine id is valid */
1428 if (0 != strcmp(engine, engine_info->uuid)) {
1429 iter = g_slist_next(iter);
1433 if (NULL != g_config_info->engine_id)
1434 free(g_config_info->engine_id);
1436 g_config_info->engine_id = strdup(engine);
1438 if (NULL != g_config_info->setting)
1439 free(g_config_info->setting);
1441 if (NULL != engine_info->setting)
1442 g_config_info->setting = strdup(engine_info->setting);
1444 /* Engine is valid*/
1445 GSList *iter_voice = NULL;
1446 tts_config_voice_s* voice = NULL;
1447 bool is_valid_voice = false;
1449 /* Get a first item */
1450 iter_voice = g_slist_nth(engine_info->voices, 0);
1452 while (NULL != iter_voice) {
1453 /*Get handle data from list*/
1454 voice = iter_voice->data;
1456 if (NULL != voice) {
1457 if (NULL == voice->language)
1459 SLOG(LOG_DEBUG, tts_tag(), " lang(%s) type(%d)", voice->language, voice->type);
1461 if (0 == strcmp(voice->language, g_config_info->language)) {
1462 if (voice->type == g_config_info->type) {
1463 /* language is valid */
1464 is_valid_voice = true;
1465 g_config_info->type = voice->type;
1472 iter_voice = g_slist_next(iter_voice);
1475 if (false == is_valid_voice) {
1476 if (NULL != g_config_info->language) {
1477 free(g_config_info->language);
1479 iter_voice = g_slist_nth(engine_info->voices, 0);
1480 if (NULL != iter_voice) {
1481 voice = iter_voice->data;
1482 if (NULL != voice) {
1483 if (NULL != voice->language)
1484 g_config_info->language = strdup(voice->language);
1485 g_config_info->type = voice->type;
1491 is_valid_engine = true;
1495 if (true == is_valid_engine) {
1496 SLOG(LOG_DEBUG, tts_tag(), "[Config] Engine changed");
1497 SECURE_SLOG(LOG_DEBUG, tts_tag(), " Engine : %s", g_config_info->engine_id);
1498 SECURE_SLOG(LOG_DEBUG, tts_tag(), " Setting : %s", g_config_info->setting);
1499 SECURE_SLOG(LOG_DEBUG, tts_tag(), " Language : %s", g_config_info->language);
1500 SECURE_SLOG(LOG_DEBUG, tts_tag(), " Type : %d", g_config_info->type);
1502 if (0 != tts_parser_set_engine(g_config_info->engine_id, g_config_info->setting,
1503 g_config_info->language, g_config_info->type)) {
1504 SLOG(LOG_ERROR, tts_tag(), " Fail to save config");
1505 return TTS_CONFIG_ERROR_OPERATION_FAILED;
1508 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Engine id is not valid");
1509 return TTS_CONFIG_ERROR_OPERATION_FAILED;
1515 int tts_config_mgr_get_voice_list(const char* engine_id, tts_config_supported_voice_cb callback, void* user_data)
1517 if (0 >= g_slist_length(g_config_client_list)) {
1518 SLOG(LOG_ERROR, tts_tag(), "Not initialized");
1519 return TTS_CONFIG_ERROR_INVALID_STATE;
1522 if (0 >= g_slist_length(g_engine_list)) {
1523 SLOG(LOG_ERROR, tts_tag(), "[ERROR] There is no engine");
1524 return TTS_CONFIG_ERROR_ENGINE_NOT_FOUND;
1527 GSList *iter = NULL;
1528 tts_engine_info_s *engine_info = NULL;
1530 /* Get a first item */
1531 iter = g_slist_nth(g_engine_list, 0);
1533 while (NULL != iter) {
1534 engine_info = iter->data;
1536 if (NULL == engine_info) {
1537 SLOG(LOG_ERROR, tts_tag(), "[ERROR] engine info is NULL");
1538 return TTS_CONFIG_ERROR_OPERATION_FAILED;
1541 if (0 != strcmp(engine_id, engine_info->uuid)) {
1542 iter = g_slist_next(iter);
1546 GSList *iter_voice = NULL;
1547 tts_config_voice_s* voice = NULL;
1549 /* Get a first item */
1550 iter_voice = g_slist_nth(engine_info->voices, 0);
1552 while (NULL != iter_voice) {
1553 /*Get handle data from list*/
1554 voice = iter_voice->data;
1556 SLOG(LOG_DEBUG, tts_tag(), " lang(%s) type(%d)", voice->language, voice->type);
1557 if (NULL != voice->language) {
1558 if (false == callback(engine_info->uuid, voice->language, voice->type, user_data))
1563 iter_voice = g_slist_next(iter_voice);
1571 int tts_config_mgr_get_voice(char** language, int* type)
1573 if (0 >= g_slist_length(g_config_client_list)) {
1574 SLOG(LOG_ERROR, tts_tag(), "Not initialized");
1575 return TTS_CONFIG_ERROR_INVALID_PARAMETER;
1578 if (0 >= g_slist_length(g_engine_list)) {
1579 SLOG(LOG_ERROR, tts_tag(), "[ERROR] There is no engine");
1580 return TTS_CONFIG_ERROR_ENGINE_NOT_FOUND;
1583 if (NULL == language || NULL == type)
1584 return TTS_CONFIG_ERROR_INVALID_PARAMETER;
1586 if (NULL != g_config_info->language) {
1587 *language = strdup(g_config_info->language);
1588 *type = g_config_info->type;
1590 SLOG(LOG_ERROR, tts_tag(), "language is NULL");
1591 return TTS_CONFIG_ERROR_OPERATION_FAILED;
1597 int tts_config_mgr_set_voice(const char* language, int type)
1599 if (0 >= g_slist_length(g_config_client_list)) {
1600 SLOG(LOG_ERROR, tts_tag(), "Not initialized");
1601 return TTS_CONFIG_ERROR_INVALID_PARAMETER;
1604 if (NULL == language) {
1605 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Input parameter is NULL");
1606 return TTS_CONFIG_ERROR_INVALID_PARAMETER;
1609 if (0 >= g_slist_length(g_engine_list)) {
1610 SLOG(LOG_ERROR, tts_tag(), "[ERROR] There is no engine");
1611 return TTS_CONFIG_ERROR_ENGINE_NOT_FOUND;
1614 /* Check language is valid */
1615 if (NULL != g_config_info->language) {
1616 if (0 != tts_parser_set_voice(language, type)) {
1617 SLOG(LOG_ERROR, tts_tag(), "Fail to save default voice");
1618 return TTS_CONFIG_ERROR_OPERATION_FAILED;
1620 free(g_config_info->language);
1621 g_config_info->language = strdup(language);
1622 g_config_info->type = type;
1625 SLOG(LOG_ERROR, tts_tag(), "language is NULL");
1626 return TTS_CONFIG_ERROR_OPERATION_FAILED;
1632 int tts_config_mgr_get_auto_voice(bool* value)
1634 if (0 >= g_slist_length(g_config_client_list)) {
1635 SLOG(LOG_ERROR, tts_tag(), "Not initialized");
1636 return TTS_CONFIG_ERROR_INVALID_PARAMETER;
1640 return TTS_CONFIG_ERROR_INVALID_PARAMETER;
1642 *value = g_config_info->auto_voice;
1647 int tts_config_mgr_set_auto_voice(bool value)
1649 if (0 >= g_slist_length(g_config_client_list)) {
1650 SLOG(LOG_ERROR, tts_tag(), "Not initialized");
1651 return TTS_CONFIG_ERROR_INVALID_PARAMETER;
1654 if (g_config_info->auto_voice != value) {
1655 /* Check language is valid */
1656 if (0 != tts_parser_set_auto_voice(value)) {
1657 SLOG(LOG_ERROR, tts_tag(), "Fail to save auto voice option");
1658 return TTS_CONFIG_ERROR_OPERATION_FAILED;
1660 g_config_info->auto_voice = value;
1662 if (true == g_config_info->auto_voice) {
1663 __tts_config_set_auto_language();
1670 int tts_config_mgr_get_speech_rate(int* value)
1672 if (0 >= g_slist_length(g_config_client_list)) {
1673 SLOG(LOG_ERROR, tts_tag(), "Not initialized");
1674 return TTS_CONFIG_ERROR_INVALID_PARAMETER;
1677 if (NULL == value) {
1678 return TTS_CONFIG_ERROR_INVALID_PARAMETER;
1681 *value = g_config_info->speech_rate;
1686 int tts_config_mgr_set_speech_rate(int value)
1688 if (0 >= g_slist_length(g_config_client_list)) {
1689 SLOG(LOG_ERROR, tts_tag(), "Not initialized");
1690 return TTS_CONFIG_ERROR_INVALID_PARAMETER;
1693 if (TTS_CONFIG_SPEED_MIN <= value && value <= TTS_CONFIG_SPEED_MAX) {
1694 SLOG(LOG_DEBUG, tts_tag(), "[Config] Set speech rate : %d", value);
1695 if (0 != tts_parser_set_speech_rate(value)) {
1696 SLOG(LOG_ERROR, tts_tag(), "Fail to save speech rate");
1697 return TTS_CONFIG_ERROR_OPERATION_FAILED;
1700 g_config_info->speech_rate = value;
1702 SLOG(LOG_ERROR, tts_tag(), "[Config ERROR] Speech rate is invalid : %d", value);
1708 int tts_config_mgr_get_pitch(int* value)
1710 if (0 >= g_slist_length(g_config_client_list)) {
1711 SLOG(LOG_ERROR, tts_tag(), "Not initialized");
1712 return TTS_CONFIG_ERROR_INVALID_PARAMETER;
1715 if (NULL == value) {
1716 return TTS_CONFIG_ERROR_INVALID_PARAMETER;
1719 GSList *iter = NULL;
1720 tts_engine_info_s *engine_info = NULL;
1722 if (0 >= g_slist_length(g_engine_list)) {
1723 SLOG(LOG_ERROR, tts_tag(), "[ERROR] There is no engine!!");
1724 return TTS_CONFIG_ERROR_ENGINE_NOT_FOUND;
1727 /* Get a first item */
1728 iter = g_slist_nth(g_engine_list, 0);
1730 while (NULL != iter) {
1731 engine_info = iter->data;
1733 if (NULL == engine_info) {
1734 SLOG(LOG_ERROR, tts_tag(), "engine info is NULL");
1735 return TTS_CONFIG_ERROR_OPERATION_FAILED;
1738 if (0 != strcmp(g_config_info->engine_id, engine_info->uuid)) {
1739 iter = g_slist_next(iter);
1743 if (false == engine_info->pitch_support) {
1744 return TTS_CONFIG_ERROR_NOT_SUPPORTED_FEATURE;
1750 *value = g_config_info->pitch;
1755 int tts_config_mgr_set_pitch(int value)
1757 if (0 >= g_slist_length(g_config_client_list)) {
1758 SLOG(LOG_ERROR, tts_tag(), "Not initialized");
1762 GSList *iter = NULL;
1763 tts_engine_info_s *engine_info = NULL;
1765 if (0 >= g_slist_length(g_engine_list)) {
1766 SLOG(LOG_ERROR, tts_tag(), "[ERROR] There is no engine!!");
1767 return TTS_CONFIG_ERROR_ENGINE_NOT_FOUND;
1770 /* Get a first item */
1771 iter = g_slist_nth(g_engine_list, 0);
1773 while (NULL != iter) {
1774 engine_info = iter->data;
1776 if (NULL == engine_info) {
1777 SLOG(LOG_ERROR, tts_tag(), "engine info is NULL");
1778 return TTS_CONFIG_ERROR_OPERATION_FAILED;
1781 if (0 != strcmp(g_config_info->engine_id, engine_info->uuid)) {
1782 iter = g_slist_next(iter);
1786 if (false == engine_info->pitch_support) {
1787 return TTS_CONFIG_ERROR_NOT_SUPPORTED_FEATURE;
1793 if (0 != tts_parser_set_pitch(value)) {
1794 SLOG(LOG_ERROR, tts_tag(), "Fail to save speech rate");
1795 return TTS_CONFIG_ERROR_OPERATION_FAILED;
1798 g_config_info->pitch = value;
1803 bool tts_config_check_default_engine_is_valid(const char* engine)
1805 if (0 >= g_slist_length(g_config_client_list)) {
1806 SLOG(LOG_ERROR, tts_tag(), "Not initialized");
1813 if (0 >= g_slist_length(g_engine_list))
1816 GSList *iter = NULL;
1817 tts_engine_info_s *engine_info = NULL;
1819 /* Get a first item */
1820 iter = g_slist_nth(g_engine_list, 0);
1822 while (NULL != iter) {
1823 engine_info = iter->data;
1825 if (NULL != engine_info) {
1826 if (0 == strcmp(engine, engine_info->uuid)) {
1830 iter = g_slist_next(iter);
1836 bool tts_config_check_default_voice_is_valid(const char* language, int type)
1838 if (0 >= g_slist_length(g_config_client_list)) {
1839 SLOG(LOG_ERROR, tts_tag(), "Not initialized");
1843 if (NULL == language)
1846 if (NULL == g_config_info->engine_id) {
1847 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Default engine id is NULL");
1851 if (0 >= g_slist_length(g_engine_list))
1854 GSList *iter = NULL;
1855 tts_engine_info_s *engine_info = NULL;
1857 /* Get a first item */
1858 iter = g_slist_nth(g_engine_list, 0);
1860 while (NULL != iter) {
1861 engine_info = iter->data;
1863 if (NULL == engine_info) {
1864 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Engine info is NULL");
1865 iter = g_slist_next(iter);
1869 if (0 != strcmp(g_config_info->engine_id, engine_info->uuid)) {
1870 iter = g_slist_next(iter);
1874 GSList *iter_voice = NULL;
1875 tts_config_voice_s* voice = NULL;
1877 /* Get a first item */
1878 iter_voice = g_slist_nth(engine_info->voices, 0);
1880 while (NULL != iter_voice) {
1881 voice = iter_voice->data;
1883 if (0 == strcmp(language, voice->language) && voice->type == type)
1887 iter_voice = g_slist_next(iter_voice);
1897 int __tts_config_mgr_print_engine_info()
1899 GSList *iter = NULL;
1900 tts_engine_info_s *engine_info = NULL;
1902 if (0 >= g_slist_length(g_engine_list)) {
1903 SLOG(LOG_DEBUG, tts_tag(), "-------------- engine list -----------------");
1904 SLOG(LOG_DEBUG, tts_tag(), " No Engine in engine directory");
1905 SLOG(LOG_DEBUG, tts_tag(), "--------------------------------------------");
1909 /* Get a first item */
1910 iter = g_slist_nth(g_engine_list, 0);
1912 SLOG(LOG_DEBUG, tts_tag(), "--------------- engine list -----------------");
1915 while (NULL != iter) {
1916 engine_info = iter->data;
1918 SLOG(LOG_DEBUG, tts_tag(), "[%dth]", i);
1919 SLOG(LOG_DEBUG, tts_tag(), " name : %s", engine_info->name);
1920 SLOG(LOG_DEBUG, tts_tag(), " id : %s", engine_info->uuid);
1921 SLOG(LOG_DEBUG, tts_tag(), " setting : %s", engine_info->setting);
1923 SLOG(LOG_DEBUG, tts_tag(), " Voices");
1924 GSList *iter_voice = NULL;
1925 tts_config_voice_s* voice = NULL;
1927 if (g_slist_length(engine_info->voices) > 0) {
1928 /* Get a first item */
1929 iter_voice = g_slist_nth(engine_info->voices, 0);
1932 while (NULL != iter_voice) {
1933 /*Get handle data from list*/
1934 voice = iter_voice->data;
1936 SLOG(LOG_DEBUG, tts_tag(), " [%dth] lang(%s) type(%d)", j, voice->language, voice->type);
1939 iter_voice = g_slist_next(iter_voice);
1943 SLOG(LOG_ERROR, tts_tag(), " Voice is NONE");
1945 iter = g_slist_next(iter);
1948 SLOG(LOG_DEBUG, tts_tag(), "--------------------------------------------");