#include <unistd.h>
#include <sys/inotify.h>
#include <vconf.h>
+#include <buxton2.h>
#include "tts_config_mgr.h"
#include "tts_config_parser.h"
static GSList* g_config_client_list = NULL;
-static tts_config_s* g_config_info;
+static tts_config_s* g_config_info = NULL;
static Ecore_Fd_Handler* g_config_fd_handler_noti = NULL;
static int g_config_fd_noti;
/* Change default engine */
iter = g_slist_nth(g_engine_list, 0);
- if (NULL == iter) {
- SLOG(LOG_ERROR, tts_tag(), "[ERROR] No engine in list");
- return TTS_CONFIG_ERROR_OPERATION_FAILED;
- }
+ if (NULL == iter) {
+ SLOG(LOG_ERROR, tts_tag(), "[ERROR] No engine in list");
+ return TTS_CONFIG_ERROR_OPERATION_FAILED;
+ }
engine_info = iter->data;
if (NULL == g_config_info) {
- SLOG(LOG_ERROR, tts_tag(), "[ERROR] Invalid engine info in list");
+ SLOG(LOG_ERROR, tts_tag(), "[ERROR] Invalid engine info in list");
return TTS_CONFIG_ERROR_OPERATION_FAILED;
}
free(g_config_info->language);
iter_voice = g_slist_nth(engine_info->voices, 0);
- if (NULL == iter_voice) {
- SLOG(LOG_ERROR, tts_tag(), "Fail to get voice list");
- return TTS_CONFIG_ERROR_OPERATION_FAILED;
- }
+ if (NULL == iter_voice) {
+ SLOG(LOG_ERROR, tts_tag(), "Fail to get voice list");
+ return TTS_CONFIG_ERROR_OPERATION_FAILED;
+ }
voice = iter_voice->data;
- if (NULL == voice || NULL == voice->language) {
- SLOG(LOG_ERROR, tts_tag(), "Fail to get voice info from list");
- return TTS_CONFIG_ERROR_OPERATION_FAILED;
- }
+ if (NULL == voice || NULL == voice->language) {
+ SLOG(LOG_ERROR, tts_tag(), "Fail to get voice info from list");
+ return TTS_CONFIG_ERROR_OPERATION_FAILED;
+ }
g_config_info->language = strdup(voice->language);
g_config_info->type = voice->type;
SECURE_SLOG(LOG_DEBUG, tts_tag(), "Engine changed callback : uid(%d)", temp_client->uid);
temp_client->engine_cb(g_config_info->engine_id, g_config_info->setting,
g_config_info->language, g_config_info->type,
- g_config_info->auto_voice, temp_client->user_data);
+ g_config_info->auto_voice, g_config_info->credential, temp_client->user_data);
}
}
int __tts_config_mgr_get_engine_info()
{
DIR *dp = NULL;
- int ret = -1;
- struct dirent entry;
struct dirent *dirp = NULL;
char filepath[512] = {'\0',};
/* Copy default info directory to download directory */
dp = opendir(TTS_DEFAULT_ENGINE_INFO);
if (NULL == dp) {
- SLOG(LOG_DEBUG, tts_tag(), "[CONFIG] No downloadable directory : %s", TTS_DEFAULT_ENGINE_INFO);
+ SLOG(LOG_DEBUG, tts_tag(), "[CONFIG] No default directory : %s", TTS_DEFAULT_ENGINE_INFO);
} else {
do {
- ret = readdir_r(dp, &entry, &dirp);
- if (0 != ret) {
- SLOG(LOG_ERROR, tts_tag(), "[CONFIG] Fail to read directory");
- break;
- }
+ dirp = readdir(dp);
if (NULL != dirp) {
+ if (!strcmp(".", dirp->d_name) || !strcmp("..", dirp->d_name))
+ continue;
+
filesize = strlen(TTS_DEFAULT_ENGINE_INFO) + strlen(dirp->d_name) + 2;
if (filesize >= 512) {
SECURE_SLOG(LOG_ERROR, tts_tag(), "[CONFIG ERROR] File path is too long : %s", dirp->d_name);
/* Get engine info from default engine directory */
dp = opendir(TTS_DOWNLOAD_ENGINE_INFO);
if (NULL == dp) {
- SLOG(LOG_DEBUG, tts_tag(), "[CONFIG] No downloadable directory : %s", TTS_DEFAULT_ENGINE_INFO);
+ SLOG(LOG_DEBUG, tts_tag(), "[CONFIG] No downloadable directory : %s", TTS_DOWNLOAD_ENGINE_INFO);
} else {
do {
- ret = readdir_r(dp, &entry, &dirp);
- if (0 != ret) {
- SLOG(LOG_ERROR, tts_tag(), "[CONFIG] Fail to read directory");
- break;
- }
+ dirp = readdir(dp);
if (NULL != dirp) {
+ if (!strcmp(".", dirp->d_name) || !strcmp("..", dirp->d_name))
+ continue;
+
filesize = strlen(TTS_DOWNLOAD_ENGINE_INFO) + strlen(dirp->d_name) + 2;
if (filesize >= 512) {
SECURE_SLOG(LOG_ERROR, tts_tag(), "[CONFIG ERROR] File path is too long : %s", dirp->d_name);
if (NULL != temp_client) {
if (NULL != temp_client->engine_cb) {
SECURE_SLOG(LOG_DEBUG, tts_tag(), "Engine changed callback : uid(%d)", temp_client->uid);
- temp_client->engine_cb(g_config_info->engine_id, g_config_info->setting,
+ temp_client->engine_cb(g_config_info->engine_id, g_config_info->setting,
g_config_info->language, g_config_info->type,
- g_config_info->auto_voice, temp_client->user_data);
+ g_config_info->auto_voice, g_config_info->credential, temp_client->user_data);
}
}
static int __tts_config_mgr_register_engine_config_updated_event(const char* path)
{
+ if (NULL == path) {
+ SLOG(LOG_ERROR, tts_tag(), "[ERROR] Path is NULL");
+ return -1;
+ }
+
/* For engine directory monitoring */
tts_engine_inotify_s *ino = (tts_engine_inotify_s *)calloc(1, sizeof(tts_engine_inotify_s));
+ if (NULL == ino) {
+ SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to allocate memory");
+ return -1;
+ }
ino->dir_fd = inotify_init();
if (ino->dir_fd < 0) {
SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to init inotify");
+ free(ino);
+ ino = NULL;
+
return -1;
}
- /* FIX_ME *//* It doesn't need check engine directory, because daemon will change engine-process */
ino->dir_wd = inotify_add_watch(ino->dir_fd, path, IN_CLOSE_WRITE);
SLOG(LOG_DEBUG, tts_tag(), "Add inotify watch(%s)", path);
if (ino->dir_wd < 0) {
SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to add watch");
+ free(ino);
+ ino = NULL;
return -1;
}
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);
if (NULL == ino->dir_fd_handler) {
SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to add fd handler");
+ free(ino);
+ ino = NULL;
return -1;
}
if (0 < g_list_length(g_ino_list)) {
GList *iter = NULL;
iter = g_list_first(g_ino_list);
-
+
while (NULL != iter) {
tts_engine_inotify_s *tmp = iter->data;
-
+
if (NULL != tmp) {
ecore_main_fd_handler_del(tmp->dir_fd_handler);
inotify_rm_watch(tmp->dir_fd, tmp->dir_wd);
if (0 != access(TTS_CONFIG_BASE, F_OK)) {
if (0 != mkdir(TTS_CONFIG_BASE, S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH)) {
SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to make directory : %s", TTS_CONFIG_BASE);
- return -1;
+ __tts_config_release_client(uid);
+ return TTS_CONFIG_ERROR_OPERATION_FAILED;
} else {
SLOG(LOG_DEBUG, tts_tag(), "Success to make directory : %s", TTS_CONFIG_BASE);
}
}
+ if (0 != access(TTS_HOME, F_OK)) {
+ if (0 != mkdir(TTS_HOME, S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH)) {
+ SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to make directory : %s", TTS_HOME);
+ __tts_config_release_client(uid);
+ return TTS_CONFIG_ERROR_OPERATION_FAILED;
+ } else {
+ SLOG(LOG_DEBUG, tts_tag(), "Success to make directory : %s", TTS_HOME);
+ }
+ }
+
if (0 != access(TTS_DOWNLOAD_BASE, F_OK)) {
if (0 != mkdir(TTS_DOWNLOAD_BASE, S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH)) {
SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to make directory : %s", TTS_DOWNLOAD_BASE);
- return -1;
+ __tts_config_release_client(uid);
+ return TTS_CONFIG_ERROR_OPERATION_FAILED;
} else {
SLOG(LOG_DEBUG, tts_tag(), "Success to make directory : %s", TTS_DOWNLOAD_BASE);
}
if (0 != access(TTS_DOWNLOAD_ENGINE_INFO, F_OK)) {
if (0 != mkdir(TTS_DOWNLOAD_ENGINE_INFO, S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH)) {
SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to make directory : %s", TTS_DOWNLOAD_ENGINE_INFO);
- return -1;
+ __tts_config_release_client(uid);
+ return TTS_CONFIG_ERROR_OPERATION_FAILED;
} else {
SLOG(LOG_DEBUG, tts_tag(), "Success to make directory : %s", TTS_DOWNLOAD_ENGINE_INFO);
}
return TTS_CONFIG_ERROR_OPERATION_FAILED;
}
+int __tts_set_buxtonkey(const char* engine)
+{
+ /* Set vconfkey */
+ struct buxton_client * bux_cli;
+ struct buxton_layer * bux_layer;
+ struct buxton_value * bux_val;
+
+ int ret = buxton_open(&bux_cli, NULL, NULL);
+ if (0 != ret) {
+ SLOG(LOG_ERROR, tts_tag(), "[DBUS-BUXTON2] buxton_open failed!! (%d)", ret);
+ return TTS_CONFIG_ERROR_OPERATION_FAILED;
+ }
+ bux_layer = buxton_create_layer("system");
+ if (NULL == bux_layer) {
+ SLOG(LOG_ERROR, tts_tag(), "[DBUS-BUXTON2] buxton_create_layer FAIL");
+ buxton_close(bux_cli);
+ return TTS_CONFIG_ERROR_OPERATION_FAILED;
+ }
+ bux_val = buxton_value_create_string(engine);
+ if (NULL == bux_val) {
+ SLOG(LOG_ERROR, tts_tag(), "[DBUS-BUXTON2] buxton_value_create_string FAIL");
+ buxton_free_layer(bux_layer);
+ buxton_close(bux_cli);
+ return TTS_CONFIG_ERROR_OPERATION_FAILED;
+ } else {
+ SLOG(LOG_DEBUG, tts_tag(), "[DBUS-BUXTON2] layer: %s", buxton_layer_get_name(bux_layer));
+ }
+
+ ret = buxton_set_value_sync(bux_cli, bux_layer, TTS_ENGINE_DB_DEFAULT, bux_val);
+ if (0 != ret) {
+ SLOG(LOG_ERROR, tts_tag(), "[DBUS-BUXTON2] buxton_set_value_sync failed!! (%d)", ret);
+ buxton_value_free(bux_val);
+ buxton_free_layer(bux_layer);
+ buxton_close(bux_cli);
+
+ bux_cli = NULL;
+ bux_layer = NULL;
+ bux_val = NULL;
+
+ return TTS_CONFIG_ERROR_OPERATION_FAILED;
+ } else {
+ SLOG(LOG_DEBUG, tts_tag(), "[DBUS-BUXTON2] buxton_set_value_sync: %d, %s", ret, TTS_ENGINE_DB_DEFAULT);
+ }
+
+ buxton_value_free(bux_val);
+ buxton_free_layer(bux_layer);
+ buxton_close(bux_cli);
+
+ bux_cli = NULL;
+ bux_layer = NULL;
+ bux_val = NULL;
+
+ return TTS_CONFIG_ERROR_NONE;
+}
+
int tts_config_mgr_set_engine(const char* engine)
{
if (0 >= g_slist_length(g_config_client_list)) {
SLOG(LOG_DEBUG, tts_tag(), "New engine id : %s", engine);
+ int ret = __tts_set_buxtonkey(engine);
+ if (0 != ret) {
+ SLOG(LOG_DEBUG, tts_tag(), "[DEBUG] set_buxtonkey Fail!!");
+ return ret;
+ }
+
GSList *iter = NULL;
tts_engine_info_s *engine_info = NULL;
bool is_valid_engine = false;
g_config_info->engine_id = strdup(engine);
- if (NULL != g_config_info->setting)
- free(g_config_info->setting);
-
- if (NULL != engine_info->setting)
+ if (NULL != engine_info->setting) {
+ if (NULL != g_config_info->setting) {
+ free(g_config_info->setting);
+ g_config_info->setting = NULL;
+ }
g_config_info->setting = strdup(engine_info->setting);
+ }
/* Engine is valid*/
GSList *iter_voice = NULL;