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;
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 downloadable 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_DEFAULT_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)
919 /* For engine directory monitoring */
920 tts_engine_inotify_s *ino = (tts_engine_inotify_s *)calloc(1, sizeof(tts_engine_inotify_s));
922 ino->dir_fd = inotify_init();
923 if (ino->dir_fd < 0) {
924 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to init inotify");
928 /* FIX_ME *//* It doesn't need check engine directory, because daemon will change engine-process */
929 ino->dir_wd = inotify_add_watch(ino->dir_fd, path, IN_CLOSE_WRITE);
930 SLOG(LOG_DEBUG, tts_tag(), "Add inotify watch(%s)", path);
931 if (ino->dir_wd < 0) {
932 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to add watch");
936 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);
937 if (NULL == ino->dir_fd_handler) {
938 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to add fd handler");
942 /* Set non-blocking mode of file */
944 value = fcntl(ino->dir_fd, F_GETFL, 0);
947 if (0 > fcntl(ino->dir_fd, F_SETFL, value)) {
948 SLOG(LOG_WARN, tts_tag(), "[WARNING] Fail to set non-block mode");
951 g_ino_list = g_list_append(g_ino_list, ino);
956 static int __tts_config_mgr_unregister_engine_config_updated_event()
958 /* delete all inotify variable */
959 if (0 < g_list_length(g_ino_list)) {
961 iter = g_list_first(g_ino_list);
963 while (NULL != iter) {
964 tts_engine_inotify_s *tmp = iter->data;
967 ecore_main_fd_handler_del(tmp->dir_fd_handler);
968 inotify_rm_watch(tmp->dir_fd, tmp->dir_wd);
974 g_ino_list = g_list_remove_link(g_ino_list, iter);
976 iter = g_list_first(g_ino_list);
983 int tts_config_mgr_initialize(int uid)
987 tts_config_client_s* temp_client = NULL;
990 if (0 < g_slist_length(g_config_client_list)) {
992 iter = g_slist_nth(g_config_client_list, 0);
994 while (NULL != iter) {
995 get_uid = iter->data;
997 if (uid == *get_uid) {
998 SECURE_SLOG(LOG_WARN, tts_tag(), "[CONFIG] uid(%d) has already registered", uid);
1002 iter = g_slist_next(iter);
1005 temp_client = (tts_config_client_s*)calloc(1, sizeof(tts_config_client_s));
1006 if (NULL == temp_client) {
1007 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to allocate memory");
1008 return TTS_CONFIG_ERROR_OUT_OF_MEMORY;
1010 temp_client->uid = uid;
1012 g_config_client_list = g_slist_append(g_config_client_list, temp_client);
1014 SECURE_SLOG(LOG_WARN, tts_tag(), "[CONFIG] Add uid(%d) but config has already initialized", uid);
1017 temp_client = (tts_config_client_s*)calloc(1, sizeof(tts_config_client_s));
1018 if (NULL == temp_client) {
1019 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to allocate memory");
1020 return TTS_CONFIG_ERROR_OUT_OF_MEMORY;
1022 temp_client->uid = uid;
1024 g_config_client_list = g_slist_append(g_config_client_list, temp_client);
1027 if (0 != access(TTS_CONFIG_BASE, F_OK)) {
1028 if (0 != mkdir(TTS_CONFIG_BASE, S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH)) {
1029 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to make directory : %s", TTS_CONFIG_BASE);
1032 SLOG(LOG_DEBUG, tts_tag(), "Success to make directory : %s", TTS_CONFIG_BASE);
1036 if (0 != access(TTS_DOWNLOAD_BASE, F_OK)) {
1037 if (0 != mkdir(TTS_DOWNLOAD_BASE, S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH)) {
1038 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to make directory : %s", TTS_DOWNLOAD_BASE);
1041 SLOG(LOG_DEBUG, tts_tag(), "Success to make directory : %s", TTS_DOWNLOAD_BASE);
1045 if (0 != access(TTS_DOWNLOAD_ENGINE_INFO, F_OK)) {
1046 if (0 != mkdir(TTS_DOWNLOAD_ENGINE_INFO, S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH)) {
1047 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to make directory : %s", TTS_DOWNLOAD_ENGINE_INFO);
1050 SLOG(LOG_DEBUG, tts_tag(), "Success to make directory : %s", TTS_DOWNLOAD_ENGINE_INFO);
1054 if (0 != __tts_config_mgr_get_engine_info()) {
1055 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to get engine info");
1056 __tts_config_release_client(uid);
1057 __tts_config_release_engine();
1058 return TTS_CONFIG_ERROR_ENGINE_NOT_FOUND;
1061 __tts_config_mgr_print_engine_info();
1063 if (0 != tts_parser_load_config(&g_config_info)) {
1064 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to parse configure information");
1065 __tts_config_release_client(uid);
1066 __tts_config_release_engine();
1067 return TTS_CONFIG_ERROR_OPERATION_FAILED;
1070 /* Check whether engine id is valid */
1071 if (0 != __tts_config_mgr_check_engine_is_valid(g_config_info->engine_id)) {
1072 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to get default engine");
1073 __tts_config_release_client(uid);
1074 __tts_config_release_engine();
1075 tts_parser_unload_config(g_config_info);
1076 return TTS_CONFIG_ERROR_ENGINE_NOT_FOUND;
1079 if (true == g_config_info->auto_voice) {
1080 /* Check language with display language */
1081 __tts_config_set_auto_language();
1083 if (false == __tts_config_mgr_check_lang_is_valid(g_config_info->engine_id, g_config_info->language, g_config_info->type)) {
1084 /* Default language is not valid */
1085 char* tmp_language = NULL;
1087 if (0 != __tts_config_mgr_select_lang(g_config_info->engine_id, &tmp_language, &tmp_type)) {
1088 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to select language");
1089 __tts_config_release_client(uid);
1090 __tts_config_release_engine();
1091 tts_parser_unload_config(g_config_info);
1092 return TTS_CONFIG_ERROR_OPERATION_FAILED;
1095 if (NULL != tmp_language) {
1096 if (NULL != g_config_info->language) {
1097 free(g_config_info->language);
1098 g_config_info->language = strdup(tmp_language);
1101 g_config_info->type = tmp_type;
1105 if (0 != tts_parser_set_voice(g_config_info->language, g_config_info->type)) {
1106 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to save config");
1107 __tts_config_release_client(uid);
1108 __tts_config_release_engine();
1109 tts_parser_unload_config(g_config_info);
1110 return TTS_CONFIG_ERROR_OPERATION_FAILED;
1116 /* print daemon config */
1117 SLOG(LOG_DEBUG, tts_tag(), "== TTS config ==");
1118 SECURE_SLOG(LOG_DEBUG, tts_tag(), " engine : %s", g_config_info->engine_id);
1119 SECURE_SLOG(LOG_DEBUG, tts_tag(), " setting : %s", g_config_info->setting);
1120 SECURE_SLOG(LOG_DEBUG, tts_tag(), " auto voice : %s", g_config_info->auto_voice ? "on" : "off");
1121 SECURE_SLOG(LOG_DEBUG, tts_tag(), " language : %s", g_config_info->language);
1122 SECURE_SLOG(LOG_DEBUG, tts_tag(), " voice type : %d", g_config_info->type);
1123 SECURE_SLOG(LOG_DEBUG, tts_tag(), " speech rate : %d", g_config_info->speech_rate);
1124 SECURE_SLOG(LOG_DEBUG, tts_tag(), " pitch : %d", g_config_info->pitch);
1125 SLOG(LOG_DEBUG, tts_tag(), "=================");
1127 if (0 != __tts_config_mgr_register_config_event()) {
1128 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to register config event");
1129 __tts_config_release_client(uid);
1130 __tts_config_release_engine();
1131 tts_parser_unload_config(g_config_info);
1132 return TTS_CONFIG_ERROR_OPERATION_FAILED;
1135 /* Register to detect display language change */
1136 vconf_notify_key_changed(TTS_LANGSET_KEY, __tts_config_display_language_changed_cb, NULL);
1137 vconf_notify_key_changed(TTS_ACCESSIBILITY_KEY, __tts_config_screen_reader_changed_cb, NULL);
1139 /* For engine directory monitoring */
1140 //if (0 != __tts_config_mgr_register_engine_config_updated_event()) {
1141 // SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to register engine config updated event");
1142 // __tts_config_release_client(uid);
1143 // __tts_config_release_engine();
1144 // tts_parser_unload_config(g_config_info);
1145 // __tts_config_mgr_unregister_config_event();
1146 // return TTS_CONFIG_ERROR_OPERATION_FAILED;
1152 int tts_config_mgr_finalize(int uid)
1154 if (0 < __tts_config_release_client(uid)) {
1158 tts_config_mgr_unset_callback(uid);
1160 __tts_config_release_engine();
1162 tts_parser_unload_config(g_config_info);
1164 __tts_config_mgr_unregister_engine_config_updated_event();
1166 __tts_config_mgr_unregister_config_event();
1168 vconf_ignore_key_changed(TTS_LANGSET_KEY, __tts_config_display_language_changed_cb);
1169 vconf_ignore_key_changed(TTS_ACCESSIBILITY_KEY, __tts_config_screen_reader_changed_cb);
1174 int tts_config_mgr_set_callback(int uid,
1175 tts_config_engine_changed_cb engine_cb,
1176 tts_config_voice_changed_cb voice_cb,
1177 tts_config_speech_rate_changed_cb speech_cb,
1178 tts_config_pitch_changed_cb pitch_cb,
1181 GSList *iter = NULL;
1182 tts_config_client_s* temp_client = NULL;
1184 /* Call all callbacks of client*/
1185 iter = g_slist_nth(g_config_client_list, 0);
1187 while (NULL != iter) {
1188 temp_client = iter->data;
1190 if (NULL != temp_client) {
1191 if (uid == temp_client->uid) {
1192 temp_client->engine_cb = engine_cb;
1193 temp_client->voice_cb = voice_cb;
1194 temp_client->speech_cb = speech_cb;
1195 temp_client->pitch_cb = pitch_cb;
1196 temp_client->user_data = user_data;
1200 iter = g_slist_next(iter);
1205 int tts_config_mgr_unset_callback(int uid)
1207 GSList *iter = NULL;
1208 tts_config_client_s* temp_client = NULL;
1210 /* Call all callbacks of client*/
1211 iter = g_slist_nth(g_config_client_list, 0);
1213 while (NULL != iter) {
1214 temp_client = iter->data;
1216 if (NULL != temp_client) {
1217 if (uid == temp_client->uid) {
1218 temp_client->engine_cb = NULL;
1219 temp_client->voice_cb = NULL;
1220 temp_client->speech_cb = NULL;
1221 temp_client->pitch_cb = NULL;
1222 temp_client->user_data = NULL;
1226 iter = g_slist_next(iter);
1232 int tts_config_set_screen_reader_callback(int uid, tts_config_screen_reader_changed_cb callback)
1234 if (NULL == callback) {
1235 SLOG(LOG_ERROR, tts_tag(), "Input parameter is NULL");
1236 return TTS_CONFIG_ERROR_INVALID_PARAMETER;
1239 GSList *iter = NULL;
1240 tts_config_client_s* temp_client = NULL;
1242 /* Call all callbacks of client*/
1243 iter = g_slist_nth(g_config_client_list, 0);
1245 while (NULL != iter) {
1246 temp_client = iter->data;
1248 if (NULL != temp_client) {
1249 if (uid == temp_client->uid) {
1250 temp_client->screen_cb = callback;
1254 iter = g_slist_next(iter);
1259 int tts_config_unset_screen_reader_callback(int uid)
1261 GSList *iter = NULL;
1262 tts_config_client_s* temp_client = NULL;
1264 /* Call all callbacks of client*/
1265 iter = g_slist_nth(g_config_client_list, 0);
1267 while (NULL != iter) {
1268 temp_client = iter->data;
1270 if (NULL != temp_client) {
1271 if (uid == temp_client->uid) {
1272 temp_client->screen_cb = NULL;
1276 iter = g_slist_next(iter);
1282 int tts_config_mgr_get_engine_list(tts_config_supported_engine_cb callback, void* user_data)
1284 if (0 >= g_slist_length(g_config_client_list)) {
1285 SLOG(LOG_ERROR, tts_tag(), "Not initialized");
1286 return TTS_CONFIG_ERROR_INVALID_STATE;
1289 GSList *iter = NULL;
1290 tts_engine_info_s *engine_info = NULL;
1292 if (0 >= g_slist_length(g_engine_list)) {
1293 SLOG(LOG_ERROR, tts_tag(), "There is no engine!!");
1294 return TTS_CONFIG_ERROR_ENGINE_NOT_FOUND;
1297 /* Get a first item */
1298 iter = g_slist_nth(g_engine_list, 0);
1300 while (NULL != iter) {
1301 engine_info = iter->data;
1303 if (NULL != engine_info) {
1304 if (false == callback(engine_info->uuid, engine_info->name, engine_info->setting, user_data)) {
1309 iter = g_slist_next(iter);
1315 int tts_config_mgr_get_engine(char** engine)
1317 if (0 >= g_slist_length(g_config_client_list)) {
1318 SLOG(LOG_ERROR, tts_tag(), "Not initialized");
1319 return TTS_CONFIG_ERROR_INVALID_STATE;
1322 if (NULL == engine) {
1323 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Input parameter is NULL");
1324 return TTS_CONFIG_ERROR_INVALID_PARAMETER;
1327 if (NULL != g_config_info->engine_id) {
1328 /* Check engine id is valid */
1329 GSList *iter = NULL;
1330 tts_engine_info_s *engine_info = NULL;
1332 if (0 >= g_slist_length(g_engine_list)) {
1333 SLOG(LOG_ERROR, tts_tag(), "[ERROR] There is no engine!!");
1334 return TTS_CONFIG_ERROR_ENGINE_NOT_FOUND;
1337 /* Get a first item */
1338 iter = g_slist_nth(g_engine_list, 0);
1340 while (NULL != iter) {
1341 engine_info = iter->data;
1343 if (NULL != engine_info) {
1344 if (0 == strcmp(engine_info->uuid, g_config_info->engine_id)) {
1345 *engine = strdup(g_config_info->engine_id);
1349 iter = g_slist_next(iter);
1352 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Current engine id is not valid");
1354 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Engine id is NULL");
1357 return TTS_CONFIG_ERROR_OPERATION_FAILED;
1360 int tts_config_mgr_set_engine(const char* engine)
1362 if (0 >= g_slist_length(g_config_client_list)) {
1363 SLOG(LOG_ERROR, tts_tag(), "Not initialized");
1364 return TTS_CONFIG_ERROR_INVALID_STATE;
1368 return TTS_CONFIG_ERROR_INVALID_PARAMETER;
1370 /* Check current engine id with new engine id */
1371 if (NULL != g_config_info->engine_id) {
1372 if (0 == strcmp(g_config_info->engine_id, engine))
1376 if (0 >= g_slist_length(g_engine_list)) {
1377 SLOG(LOG_ERROR, tts_tag(), "[ERROR] There is no engine!!");
1378 return TTS_CONFIG_ERROR_ENGINE_NOT_FOUND;
1381 SLOG(LOG_DEBUG, tts_tag(), "New engine id : %s", engine);
1383 GSList *iter = NULL;
1384 tts_engine_info_s *engine_info = NULL;
1385 bool is_valid_engine = false;
1387 /* Get a first item */
1388 iter = g_slist_nth(g_engine_list, 0);
1390 while (NULL != iter) {
1391 engine_info = iter->data;
1393 if (NULL == engine_info) {
1394 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Engine info is NULL");
1395 iter = g_slist_next(iter);
1399 /* Check engine id is valid */
1400 if (0 != strcmp(engine, engine_info->uuid)) {
1401 iter = g_slist_next(iter);
1405 if (NULL != g_config_info->engine_id)
1406 free(g_config_info->engine_id);
1408 g_config_info->engine_id = strdup(engine);
1410 if (NULL != g_config_info->setting)
1411 free(g_config_info->setting);
1413 if (NULL != engine_info->setting)
1414 g_config_info->setting = strdup(engine_info->setting);
1416 /* Engine is valid*/
1417 GSList *iter_voice = NULL;
1418 tts_config_voice_s* voice = NULL;
1419 bool is_valid_voice = false;
1421 /* Get a first item */
1422 iter_voice = g_slist_nth(engine_info->voices, 0);
1424 while (NULL != iter_voice) {
1425 /*Get handle data from list*/
1426 voice = iter_voice->data;
1428 if (NULL != voice) {
1429 if (NULL == voice->language)
1431 SLOG(LOG_DEBUG, tts_tag(), " lang(%s) type(%d)", voice->language, voice->type);
1433 if (0 == strcmp(voice->language, g_config_info->language)) {
1434 if (voice->type == g_config_info->type) {
1435 /* language is valid */
1436 is_valid_voice = true;
1437 g_config_info->type = voice->type;
1444 iter_voice = g_slist_next(iter_voice);
1447 if (false == is_valid_voice) {
1448 if (NULL != g_config_info->language) {
1449 free(g_config_info->language);
1451 iter_voice = g_slist_nth(engine_info->voices, 0);
1452 if (NULL != iter_voice) {
1453 voice = iter_voice->data;
1454 if (NULL != voice) {
1455 if (NULL != voice->language)
1456 g_config_info->language = strdup(voice->language);
1457 g_config_info->type = voice->type;
1463 is_valid_engine = true;
1467 if (true == is_valid_engine) {
1468 SLOG(LOG_DEBUG, tts_tag(), "[Config] Engine changed");
1469 SECURE_SLOG(LOG_DEBUG, tts_tag(), " Engine : %s", g_config_info->engine_id);
1470 SECURE_SLOG(LOG_DEBUG, tts_tag(), " Setting : %s", g_config_info->setting);
1471 SECURE_SLOG(LOG_DEBUG, tts_tag(), " Language : %s", g_config_info->language);
1472 SECURE_SLOG(LOG_DEBUG, tts_tag(), " Type : %d", g_config_info->type);
1474 if (0 != tts_parser_set_engine(g_config_info->engine_id, g_config_info->setting,
1475 g_config_info->language, g_config_info->type)) {
1476 SLOG(LOG_ERROR, tts_tag(), " Fail to save config");
1477 return TTS_CONFIG_ERROR_OPERATION_FAILED;
1480 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Engine id is not valid");
1481 return TTS_CONFIG_ERROR_OPERATION_FAILED;
1487 int tts_config_mgr_get_voice_list(const char* engine_id, tts_config_supported_voice_cb callback, void* user_data)
1489 if (0 >= g_slist_length(g_config_client_list)) {
1490 SLOG(LOG_ERROR, tts_tag(), "Not initialized");
1491 return TTS_CONFIG_ERROR_INVALID_STATE;
1494 if (0 >= g_slist_length(g_engine_list)) {
1495 SLOG(LOG_ERROR, tts_tag(), "[ERROR] There is no engine");
1496 return TTS_CONFIG_ERROR_ENGINE_NOT_FOUND;
1499 GSList *iter = NULL;
1500 tts_engine_info_s *engine_info = NULL;
1502 /* Get a first item */
1503 iter = g_slist_nth(g_engine_list, 0);
1505 while (NULL != iter) {
1506 engine_info = iter->data;
1508 if (NULL == engine_info) {
1509 SLOG(LOG_ERROR, tts_tag(), "[ERROR] engine info is NULL");
1510 return TTS_CONFIG_ERROR_OPERATION_FAILED;
1513 if (0 != strcmp(engine_id, engine_info->uuid)) {
1514 iter = g_slist_next(iter);
1518 GSList *iter_voice = NULL;
1519 tts_config_voice_s* voice = NULL;
1521 /* Get a first item */
1522 iter_voice = g_slist_nth(engine_info->voices, 0);
1524 while (NULL != iter_voice) {
1525 /*Get handle data from list*/
1526 voice = iter_voice->data;
1528 SLOG(LOG_DEBUG, tts_tag(), " lang(%s) type(%d)", voice->language, voice->type);
1529 if (NULL != voice->language) {
1530 if (false == callback(engine_info->uuid, voice->language, voice->type, user_data))
1535 iter_voice = g_slist_next(iter_voice);
1543 int tts_config_mgr_get_voice(char** language, int* type)
1545 if (0 >= g_slist_length(g_config_client_list)) {
1546 SLOG(LOG_ERROR, tts_tag(), "Not initialized");
1547 return TTS_CONFIG_ERROR_INVALID_PARAMETER;
1550 if (0 >= g_slist_length(g_engine_list)) {
1551 SLOG(LOG_ERROR, tts_tag(), "[ERROR] There is no engine");
1552 return TTS_CONFIG_ERROR_ENGINE_NOT_FOUND;
1555 if (NULL == language || NULL == type)
1556 return TTS_CONFIG_ERROR_INVALID_PARAMETER;
1558 if (NULL != g_config_info->language) {
1559 *language = strdup(g_config_info->language);
1560 *type = g_config_info->type;
1562 SLOG(LOG_ERROR, tts_tag(), "language is NULL");
1563 return TTS_CONFIG_ERROR_OPERATION_FAILED;
1569 int tts_config_mgr_set_voice(const char* language, int type)
1571 if (0 >= g_slist_length(g_config_client_list)) {
1572 SLOG(LOG_ERROR, tts_tag(), "Not initialized");
1573 return TTS_CONFIG_ERROR_INVALID_PARAMETER;
1576 if (NULL == language) {
1577 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Input parameter is NULL");
1578 return TTS_CONFIG_ERROR_INVALID_PARAMETER;
1581 if (0 >= g_slist_length(g_engine_list)) {
1582 SLOG(LOG_ERROR, tts_tag(), "[ERROR] There is no engine");
1583 return TTS_CONFIG_ERROR_ENGINE_NOT_FOUND;
1586 /* Check language is valid */
1587 if (NULL != g_config_info->language) {
1588 if (0 != tts_parser_set_voice(language, type)) {
1589 SLOG(LOG_ERROR, tts_tag(), "Fail to save default voice");
1590 return TTS_CONFIG_ERROR_OPERATION_FAILED;
1592 free(g_config_info->language);
1593 g_config_info->language = strdup(language);
1594 g_config_info->type = type;
1597 SLOG(LOG_ERROR, tts_tag(), "language is NULL");
1598 return TTS_CONFIG_ERROR_OPERATION_FAILED;
1604 int tts_config_mgr_get_auto_voice(bool* value)
1606 if (0 >= g_slist_length(g_config_client_list)) {
1607 SLOG(LOG_ERROR, tts_tag(), "Not initialized");
1608 return TTS_CONFIG_ERROR_INVALID_PARAMETER;
1612 return TTS_CONFIG_ERROR_INVALID_PARAMETER;
1614 *value = g_config_info->auto_voice;
1619 int tts_config_mgr_set_auto_voice(bool value)
1621 if (0 >= g_slist_length(g_config_client_list)) {
1622 SLOG(LOG_ERROR, tts_tag(), "Not initialized");
1623 return TTS_CONFIG_ERROR_INVALID_PARAMETER;
1626 if (g_config_info->auto_voice != value) {
1627 /* Check language is valid */
1628 if (0 != tts_parser_set_auto_voice(value)) {
1629 SLOG(LOG_ERROR, tts_tag(), "Fail to save auto voice option");
1630 return TTS_CONFIG_ERROR_OPERATION_FAILED;
1632 g_config_info->auto_voice = value;
1634 if (true == g_config_info->auto_voice) {
1635 __tts_config_set_auto_language();
1642 int tts_config_mgr_get_speech_rate(int* value)
1644 if (0 >= g_slist_length(g_config_client_list)) {
1645 SLOG(LOG_ERROR, tts_tag(), "Not initialized");
1646 return TTS_CONFIG_ERROR_INVALID_PARAMETER;
1649 if (NULL == value) {
1650 return TTS_CONFIG_ERROR_INVALID_PARAMETER;
1653 *value = g_config_info->speech_rate;
1658 int tts_config_mgr_set_speech_rate(int value)
1660 if (0 >= g_slist_length(g_config_client_list)) {
1661 SLOG(LOG_ERROR, tts_tag(), "Not initialized");
1662 return TTS_CONFIG_ERROR_INVALID_PARAMETER;
1665 if (TTS_CONFIG_SPEED_MIN <= value && value <= TTS_CONFIG_SPEED_MAX) {
1666 SLOG(LOG_DEBUG, tts_tag(), "[Config] Set speech rate : %d", value);
1667 if (0 != tts_parser_set_speech_rate(value)) {
1668 SLOG(LOG_ERROR, tts_tag(), "Fail to save speech rate");
1669 return TTS_CONFIG_ERROR_OPERATION_FAILED;
1672 g_config_info->speech_rate = value;
1674 SLOG(LOG_ERROR, tts_tag(), "[Config ERROR] Speech rate is invalid : %d", value);
1680 int tts_config_mgr_get_pitch(int* value)
1682 if (0 >= g_slist_length(g_config_client_list)) {
1683 SLOG(LOG_ERROR, tts_tag(), "Not initialized");
1684 return TTS_CONFIG_ERROR_INVALID_PARAMETER;
1687 if (NULL == value) {
1688 return TTS_CONFIG_ERROR_INVALID_PARAMETER;
1691 GSList *iter = NULL;
1692 tts_engine_info_s *engine_info = NULL;
1694 if (0 >= g_slist_length(g_engine_list)) {
1695 SLOG(LOG_ERROR, tts_tag(), "[ERROR] There is no engine!!");
1696 return TTS_CONFIG_ERROR_ENGINE_NOT_FOUND;
1699 /* Get a first item */
1700 iter = g_slist_nth(g_engine_list, 0);
1702 while (NULL != iter) {
1703 engine_info = iter->data;
1705 if (NULL == engine_info) {
1706 SLOG(LOG_ERROR, tts_tag(), "engine info is NULL");
1707 return TTS_CONFIG_ERROR_OPERATION_FAILED;
1710 if (0 != strcmp(g_config_info->engine_id, engine_info->uuid)) {
1711 iter = g_slist_next(iter);
1715 if (false == engine_info->pitch_support) {
1716 return TTS_CONFIG_ERROR_NOT_SUPPORTED_FEATURE;
1722 *value = g_config_info->pitch;
1727 int tts_config_mgr_set_pitch(int value)
1729 if (0 >= g_slist_length(g_config_client_list)) {
1730 SLOG(LOG_ERROR, tts_tag(), "Not initialized");
1734 GSList *iter = NULL;
1735 tts_engine_info_s *engine_info = NULL;
1737 if (0 >= g_slist_length(g_engine_list)) {
1738 SLOG(LOG_ERROR, tts_tag(), "[ERROR] There is no engine!!");
1739 return TTS_CONFIG_ERROR_ENGINE_NOT_FOUND;
1742 /* Get a first item */
1743 iter = g_slist_nth(g_engine_list, 0);
1745 while (NULL != iter) {
1746 engine_info = iter->data;
1748 if (NULL == engine_info) {
1749 SLOG(LOG_ERROR, tts_tag(), "engine info is NULL");
1750 return TTS_CONFIG_ERROR_OPERATION_FAILED;
1753 if (0 != strcmp(g_config_info->engine_id, engine_info->uuid)) {
1754 iter = g_slist_next(iter);
1758 if (false == engine_info->pitch_support) {
1759 return TTS_CONFIG_ERROR_NOT_SUPPORTED_FEATURE;
1765 if (0 != tts_parser_set_pitch(value)) {
1766 SLOG(LOG_ERROR, tts_tag(), "Fail to save speech rate");
1767 return TTS_CONFIG_ERROR_OPERATION_FAILED;
1770 g_config_info->pitch = value;
1775 bool tts_config_check_default_engine_is_valid(const char* engine)
1777 if (0 >= g_slist_length(g_config_client_list)) {
1778 SLOG(LOG_ERROR, tts_tag(), "Not initialized");
1785 if (0 >= g_slist_length(g_engine_list))
1788 GSList *iter = NULL;
1789 tts_engine_info_s *engine_info = NULL;
1791 /* Get a first item */
1792 iter = g_slist_nth(g_engine_list, 0);
1794 while (NULL != iter) {
1795 engine_info = iter->data;
1797 if (NULL != engine_info) {
1798 if (0 == strcmp(engine, engine_info->uuid)) {
1802 iter = g_slist_next(iter);
1808 bool tts_config_check_default_voice_is_valid(const char* language, int type)
1810 if (0 >= g_slist_length(g_config_client_list)) {
1811 SLOG(LOG_ERROR, tts_tag(), "Not initialized");
1815 if (NULL == language)
1818 if (NULL == g_config_info->engine_id) {
1819 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Default engine id is NULL");
1823 if (0 >= g_slist_length(g_engine_list))
1826 GSList *iter = NULL;
1827 tts_engine_info_s *engine_info = NULL;
1829 /* Get a first item */
1830 iter = g_slist_nth(g_engine_list, 0);
1832 while (NULL != iter) {
1833 engine_info = iter->data;
1835 if (NULL == engine_info) {
1836 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Engine info is NULL");
1837 iter = g_slist_next(iter);
1841 if (0 != strcmp(g_config_info->engine_id, engine_info->uuid)) {
1842 iter = g_slist_next(iter);
1846 GSList *iter_voice = NULL;
1847 tts_config_voice_s* voice = NULL;
1849 /* Get a first item */
1850 iter_voice = g_slist_nth(engine_info->voices, 0);
1852 while (NULL != iter_voice) {
1853 voice = iter_voice->data;
1855 if (0 == strcmp(language, voice->language) && voice->type == type)
1859 iter_voice = g_slist_next(iter_voice);
1869 int __tts_config_mgr_print_engine_info()
1871 GSList *iter = NULL;
1872 tts_engine_info_s *engine_info = NULL;
1874 if (0 >= g_slist_length(g_engine_list)) {
1875 SLOG(LOG_DEBUG, tts_tag(), "-------------- engine list -----------------");
1876 SLOG(LOG_DEBUG, tts_tag(), " No Engine in engine directory");
1877 SLOG(LOG_DEBUG, tts_tag(), "--------------------------------------------");
1881 /* Get a first item */
1882 iter = g_slist_nth(g_engine_list, 0);
1884 SLOG(LOG_DEBUG, tts_tag(), "--------------- engine list -----------------");
1887 while (NULL != iter) {
1888 engine_info = iter->data;
1890 SLOG(LOG_DEBUG, tts_tag(), "[%dth]", i);
1891 SLOG(LOG_DEBUG, tts_tag(), " name : %s", engine_info->name);
1892 SLOG(LOG_DEBUG, tts_tag(), " id : %s", engine_info->uuid);
1893 SLOG(LOG_DEBUG, tts_tag(), " setting : %s", engine_info->setting);
1895 SLOG(LOG_DEBUG, tts_tag(), " Voices");
1896 GSList *iter_voice = NULL;
1897 tts_config_voice_s* voice = NULL;
1899 if (g_slist_length(engine_info->voices) > 0) {
1900 /* Get a first item */
1901 iter_voice = g_slist_nth(engine_info->voices, 0);
1904 while (NULL != iter_voice) {
1905 /*Get handle data from list*/
1906 voice = iter_voice->data;
1908 SLOG(LOG_DEBUG, tts_tag(), " [%dth] lang(%s) type(%d)", j, voice->language, voice->type);
1911 iter_voice = g_slist_next(iter_voice);
1915 SLOG(LOG_ERROR, tts_tag(), " Voice is NONE");
1917 iter = g_slist_next(iter);
1920 SLOG(LOG_DEBUG, tts_tag(), "--------------------------------------------");