/*
-* Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
+* Copyright (c) 2011-2016 Samsung Electronics Co., Ltd All Rights Reserved
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* limitations under the License.
*/
-#include <Ecore_File.h>
-#include "ttsd_main.h"
-#include "ttsd_config.h"
-#define CONFIG_FILE_PATH BASE_DIRECTORY_DOWNLOAD"/ttsd.conf"
-#define CONFIG_DEFAULT BASE_DIRECTORY_DEFAULT"/ttsd.conf"
+/* For multi-user support */
+#include <tzplatform_config.h>
-#define ENGINE_ID "ENGINE_ID"
-#define VOICE "VOICE"
-#define SPEED "SPEED"
+#include "tts_config_mgr.h"
+#include "ttsd_config.h"
+#include "ttsd_main.h"
-static char* g_engine_id;
-static char* g_language;
-static int g_vc_type;
-static int g_speed;
+static ttsd_config_changed_cb g_callback;
-int __ttsd_config_save()
-{
- if (0 != access(CONFIG_FILE_PATH, R_OK|W_OK)) {
- if (0 == ecore_file_mkpath(BASE_DIRECTORY_DOWNLOAD)) {
- SLOG(LOG_ERROR, TAG_TTSD, "[Config ERROR ] Fail to create directory (%s)", BASE_DIRECTORY_DOWNLOAD);
- return -1;
- }
+static ttsd_config_screen_reader_changed_cb g_sr_callback;
- SLOG(LOG_WARN, TAG_TTSD, "[Config] Create directory (%s)", BASE_DIRECTORY_DOWNLOAD);
+void __ttsd_config_engine_changed_cb(const char* engine_id, const char* setting, const char* language, int voice_type, bool auto_voice, bool need_credential, void* user_data)
+{
+ /* Need to check engine is valid */
+ if (false == tts_config_check_default_engine_is_valid(engine_id)) {
+ SLOG(LOG_ERROR, tts_tag(), "Engine id is NOT valid : %s", engine_id);
+ return;
}
- FILE* config_fp;
- config_fp = fopen(CONFIG_FILE_PATH, "w+");
-
- if (NULL == config_fp) {
- /* make file and file default */
- SLOG(LOG_WARN, TAG_TTSD, "[Config WARNING] Fail to open config (%s)", CONFIG_FILE_PATH);
- return -1;
+ if (NULL != g_callback) {
+ SECURE_SLOG(LOG_DEBUG, tts_tag(), "Call the engine reload callback : engine id(%s)", engine_id);
+ g_callback(TTS_CONFIG_TYPE_ENGINE, engine_id, 0, 0);
+ SECURE_SLOG(LOG_DEBUG, tts_tag(), "Call the voice changed callback : lang(%s), type(%d)", language, voice_type);
+ g_callback(TTS_CONFIG_TYPE_VOICE, language, voice_type, 0);
+ } else {
+ SLOG(LOG_ERROR, tts_tag(), "Config changed callback is NULL");
}
-
- SLOG(LOG_DEBUG, TAG_TTSD, "[Config] Rewrite config file");
-
- /* Write engine id */
- fprintf(config_fp, "%s %s\n", ENGINE_ID, g_engine_id);
-
- /* Write voice */
- fprintf(config_fp, "%s %s %d\n", VOICE, g_language, g_vc_type);
-
- /* Read speed */
- fprintf(config_fp, "%s %d\n", SPEED, g_speed);
-
- fclose(config_fp);
-
- return 0;
}
-
-int __ttsd_config_load()
+void __ttsd_config_voice_changed_cb(const char* before_language, int before_type, const char* language, int type, bool auto_voice, void* user_data)
{
- FILE* config_fp;
- char buf_id[256] = {0};
- char buf_param[256] = {0};
- int int_param = 0;
- bool is_default_open = false;
+ /* Need to check voice is valid */
+ if (false == tts_config_check_default_voice_is_valid(language, type)) {
+ SLOG(LOG_ERROR, tts_tag(), "Lang(%s) type(%d) is NOT valid", language, type);
+ return;
+ }
- config_fp = fopen(CONFIG_FILE_PATH, "r");
+ if (NULL != g_callback) {
+ g_callback(TTS_CONFIG_TYPE_VOICE, language, type, 0);
+ } else {
+ SLOG(LOG_ERROR, tts_tag(), "Config changed callback is NULL");
+ }
+}
- if (NULL == config_fp) {
- SLOG(LOG_WARN, TAG_TTSD, "[Config WARNING] Not open file(%s)", CONFIG_FILE_PATH);
-
- config_fp = fopen(CONFIG_DEFAULT, "r");
- if (NULL == config_fp) {
- SLOG(LOG_ERROR, TAG_TTSD, "[Config WARNING] Not open original config file(%s)", CONFIG_FILE_PATH);
- return -1;
- }
- is_default_open = true;
+void __ttsd_config_speech_rate_changed_cb(int value, void* user_data)
+{
+ if (NULL != g_callback) {
+ g_callback(TTS_CONFIG_TYPE_SPEED, NULL, value, 0);
+ } else {
+ SLOG(LOG_ERROR, tts_tag(), "Config changed callback is NULL");
}
+}
- /* Read engine id */
- if (EOF == fscanf(config_fp, "%s %s", buf_id, buf_param)) {
- fclose(config_fp);
- SLOG(LOG_WARN, TAG_TTSD, "[Config WARNING] Fail to read config (engine id)");
- __ttsd_config_save();
- return -1;
+void __ttsd_config_pitch_changed_cb(int value, void* user_data)
+{
+ if (NULL != g_callback) {
+ g_callback(TTS_CONFIG_TYPE_PITCH, NULL, value, 0);
} else {
- if (0 == strncmp(ENGINE_ID, buf_id, strlen(ENGINE_ID))) {
- g_engine_id = strdup(buf_param);
- } else {
- fclose(config_fp);
- SLOG(LOG_WARN, TAG_TTSD, "[Config WARNING] Fail to load config (engine id)");
- __ttsd_config_save();
- return -1;
- }
+ SLOG(LOG_ERROR, tts_tag(), "Config changed callback is NULL");
}
+}
-
+void __ttsd_config_screen_reader_changed_cb(bool value)
+{
+ if (NULL != g_sr_callback) {
+ g_sr_callback(value);
+ }
+}
- /* Read voice */
- if (EOF == fscanf(config_fp, "%s %s %d", buf_id, buf_param, &int_param)) {
- fclose(config_fp);
- SLOG(LOG_WARN, TAG_TTSD, "[Config WARNING] Fail to read config (voice)");
- __ttsd_config_save();
+void __ttsd_config_bg_volume_ratio_changed_cb(double value, void* user_data)
+{
+ if (NULL != g_callback)
+ g_callback(TTS_CONFIG_TYPE_BACKGROUND_VOLUME_RATIO, NULL, 0, value);
+ else
+ SLOG(LOG_ERROR, tts_tag(), "Config changed callback is NULL");
+}
+
+int ttsd_config_initialize(ttsd_config_changed_cb config_cb)
+{
+ if (NULL == config_cb) {
+ SLOG(LOG_ERROR, tts_tag(), "[Config] Invalid parameter");
return -1;
- } else {
- if (0 == strncmp(VOICE, buf_id, strlen(VOICE))) {
- g_language = strdup(buf_param);
- g_vc_type = int_param;
- } else {
- fclose(config_fp);
- SLOG(LOG_WARN, TAG_TTSD, "[Config WARNING] Fail to load config (voice)");
- __ttsd_config_save();
- return -1;
- }
}
-
- /* Read speed */
- if (EOF == fscanf(config_fp, "%s %d", buf_id, &int_param)) {
- fclose(config_fp);
- SLOG(LOG_WARN, TAG_TTSD, "[Config WARNING] Fail to read config (speed)");
- __ttsd_config_save();
+
+ g_callback = config_cb;
+ g_sr_callback = NULL;
+
+ int ret = -1;
+ ret = tts_config_mgr_initialize(getpid());
+ if (0 != ret) {
+ SLOG(LOG_ERROR, tts_tag(), "[Config] Fail to initialize config manager");
return -1;
- } else {
- if (0 == strncmp(SPEED, buf_id, strlen(SPEED))) {
- g_speed = int_param;
- } else {
- fclose(config_fp);
- SLOG(LOG_WARN, TAG_TTSD, "[Config WARNING] Fail to load config (speed)");
- __ttsd_config_save();
- return -1;
- }
}
-
- fclose(config_fp);
- SLOG(LOG_DEBUG, TAG_TTSD, "[Config] Load config : engine(%s), voice(%s,%d), speed(%d)",
- g_engine_id, g_language, g_vc_type, g_speed);
-
- if (true == is_default_open) {
- if(0 == __ttsd_config_save()) {
- SLOG(LOG_DEBUG, TAG_TTSD, "[Config] Create config(%s)", CONFIG_FILE_PATH);
- }
+ ret = tts_config_mgr_set_callback(getpid(), __ttsd_config_engine_changed_cb, __ttsd_config_voice_changed_cb,
+ __ttsd_config_speech_rate_changed_cb, __ttsd_config_pitch_changed_cb, __ttsd_config_bg_volume_ratio_changed_cb, NULL);
+ if (0 != ret) {
+ SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to set config changed : %d", ret);
+ return -1;
}
return 0;
}
-int ttsd_config_initialize()
+int ttsd_config_finalize()
{
- g_engine_id = NULL;
- g_language = NULL;
- g_vc_type = 1;
- g_speed = 3;
+ tts_config_unset_screen_reader_callback(getpid());
- __ttsd_config_load();
+ tts_config_mgr_finalize(getpid());
return 0;
}
-int ttsd_config_finalize()
+int ttsd_config_set_screen_reader_callback(ttsd_config_screen_reader_changed_cb sr_cb)
{
- __ttsd_config_save();
+ if (NULL == sr_cb) {
+ SLOG(LOG_ERROR, tts_tag(), "[Config] Invalid parameter");
+ return -1;
+ }
+
+ g_sr_callback = sr_cb;
+
+ int ret = tts_config_set_screen_reader_callback(getpid(), __ttsd_config_screen_reader_changed_cb) ;
+ if (0 != ret) {
+ SLOG(LOG_ERROR, tts_tag(), "[Config] Fail to set screen reader callback");
+ return -1;
+ }
return 0;
}
if (NULL == engine_id)
return -1;
- *engine_id = strdup(g_engine_id);
+ if (0 != tts_config_mgr_get_engine(engine_id)) {
+ SLOG(LOG_ERROR, tts_tag(), "[Config ERROR] Fail to get engine id");
+ return TTSD_ERROR_OPERATION_FAILED;
+ }
+
return 0;
}
if (NULL == engine_id)
return -1;
- if (NULL != g_engine_id)
- free(g_engine_id);
+ if (true == tts_config_check_default_engine_is_valid(engine_id)) {
+ if (0 != tts_config_mgr_set_engine(engine_id)) {
+ SLOG(LOG_ERROR, tts_tag(), "[Config ERROR] Fail to set engine id");
+ }
+ }
- g_engine_id = strdup(engine_id);
- __ttsd_config_save();
return 0;
}
if (NULL == language || NULL == type)
return -1;
- *language = strdup(g_language);
- *type = g_vc_type;
+ if (0 != tts_config_mgr_get_voice(language, type)) {
+ SLOG(LOG_ERROR, tts_tag(), "[Config ERROR] Fail to get default voice");
+ return TTSD_ERROR_OPERATION_FAILED;
+ }
return 0;
}
-int ttsd_config_set_default_voice(const char* language, int type)
+int ttsd_config_get_default_speed(int* speed)
{
- if (NULL == language)
+ if (NULL == speed)
return -1;
- if (NULL != g_language)
- free(g_language);
+ if (0 != tts_config_mgr_get_speech_rate(speed)) {
+ SLOG(LOG_ERROR, tts_tag(), "[Config ERROR] Fail to get default speech rate");
+ return TTSD_ERROR_OPERATION_FAILED;
+ }
- g_language = strdup(language);
- g_vc_type = type;
+ return 0;
+}
- __ttsd_config_save();
+int ttsd_config_get_default_pitch(int* pitch)
+{
+ if (NULL == pitch)
+ return -1;
+
+ if (0 != tts_config_mgr_get_pitch(pitch)) {
+ SLOG(LOG_ERROR, tts_tag(), "[Config ERROR] Fail to get default pitch");
+ return TTSD_ERROR_OPERATION_FAILED;
+ }
return 0;
}
-int ttsd_config_get_default_speed(int* speed)
+int ttsd_config_get_bg_volume_ratio(double* ratio)
{
- if (NULL == speed)
+ if (NULL == ratio)
return -1;
- *speed = g_speed;
+ if (0 != tts_config_mgr_get_bg_volume_ratio(ratio)) {
+ SLOG(LOG_ERROR, tts_tag(), "[Config ERROR] Fail to get default bg volume ratio");
+ return TTSD_ERROR_OPERATION_FAILED;
+ }
return 0;
}
-int ttsd_config_set_default_speed(int speed)
+int ttsd_config_save_error(int uid, int uttid, const char* lang, int vctype, const char* text,
+ const char* func, int line, const char* message)
{
- g_speed = speed;
- __ttsd_config_save();
+ SLOG(LOG_DEBUG, tts_tag(), "@@@@@ TTS ERROR LOG @@@@@");
+
+ SLOG(LOG_DEBUG, tts_tag(), "uid(%d) uttid(%d)", uid, uttid);
+
+
+ SLOG(LOG_DEBUG, tts_tag(), "Function(%s) Line(%d)", (NULL == func) ? "NULL" : func, line);
+ SLOG(LOG_DEBUG, tts_tag(), "Message(%s)", (NULL == message) ? "NULL" : message);
+ SLOG(LOG_DEBUG, tts_tag(), "Lang(%s), type(%d)", (NULL == lang) ? "NULL" : lang, vctype);
+ SLOG(LOG_DEBUG, tts_tag(), "Text(%s)", (NULL == text) ? "NULL" : text);
+
+ SLOG(LOG_DEBUG, tts_tag(), "@@@@@");
+
return 0;
}