static int ttsd_print_voicelist();
-/** Get engine info */
-static int __internal_get_engine_info(ttse_request_callback_s* callback);
-
static const char* __ttsd_get_engine_error_code(ttse_error_e err)
{
switch (err) {
return TTSD_ERROR_NONE;
}
-int ttsd_engine_agent_init()
+static bool __is_callback_valid(ttse_request_callback_s *callback)
+{
+ if (NULL == callback) {
+ SLOG(LOG_ERROR, tts_tag(), "[Engine Agent ERROR] Invalid engine");
+ return false;
+ }
+
+ if (NULL == callback->get_info
+ || NULL == callback->initialize || NULL == callback->deinitialize
+ || NULL == callback->foreach_voices || NULL == callback->is_valid_voice
+ || NULL == callback->set_pitch
+ || NULL == callback->load_voice || NULL == callback->unload_voice
+ || NULL == callback->start_synth || NULL == callback->cancel_synth
+ || NULL == callback->check_app_agreed || NULL == callback->need_app_credential) {
+ SLOG(LOG_ERROR, tts_tag(), "[Engine Agent ERROR] Invalid engine");
+ return false;
+ }
+
+ return true;
+}
+
+static int __set_engine_callback(ttse_request_callback_s* callback, ttsengine_info_s* engine_info)
+{
+ SLOG(LOG_DEBUG, tts_tag(), "[Engine Agent DEBUG] internal get engine info");
+
+ if (0 != callback->get_info(&(engine_info->engine_uuid), &(engine_info->engine_name), &(engine_info->engine_setting_path), &(engine_info->use_network))) {
+ SLOG(LOG_ERROR, tts_tag(), "[Engine Agent ERROR] Fail to get engine info");
+ return TTSD_ERROR_ENGINE_NOT_FOUND;
+ }
+
+ if (NULL != engine_info->engine_path) {
+ free(engine_info->engine_path);
+ engine_info->engine_path = NULL;
+ }
+ engine_info->engine_path = strdup("empty");
+ engine_info->is_loaded = false;
+
+ if (NULL != engine_info->callbacks) {
+ free(engine_info->callbacks);
+ engine_info->callbacks = NULL;
+ }
+
+ engine_info->callbacks = (tts_engine_callback_s*)calloc(1, sizeof(tts_engine_callback_s));
+ if (NULL == engine_info->callbacks) {
+ SLOG(LOG_ERROR, tts_tag(), "[Engine Agent ERROR] Fail to allocate memory");
+ return TTSD_ERROR_OUT_OF_MEMORY;
+ }
+
+ engine_info->callbacks->get_info = callback->get_info;
+ engine_info->callbacks->initialize = callback->initialize;
+ engine_info->callbacks->deinitialize = callback->deinitialize;
+ engine_info->callbacks->foreach_voices = callback->foreach_voices;
+ engine_info->callbacks->is_valid_voice = callback->is_valid_voice;
+ engine_info->callbacks->set_pitch = callback->set_pitch;
+ engine_info->callbacks->load_voice = callback->load_voice;
+ engine_info->callbacks->unload_voice = callback->unload_voice;
+ engine_info->callbacks->start_synth = callback->start_synth;
+ engine_info->callbacks->cancel_synth = callback->cancel_synth;
+ engine_info->callbacks->check_app_agreed = callback->check_app_agreed;
+ engine_info->callbacks->need_app_credential = callback->need_app_credential;
+
+ engine_info->callbacks->private_data_set = NULL;
+ engine_info->callbacks->private_data_requested = NULL;
+
+ SLOG(LOG_DEBUG, tts_tag(), "--- Valid Engine ---");
+ SLOG(LOG_DEBUG, tts_tag(), "Engine uuid : %s", engine_info->engine_uuid);
+ SLOG(LOG_DEBUG, tts_tag(), "Engine name : %s", engine_info->engine_name);
+ SLOG(LOG_DEBUG, tts_tag(), "Engine path : %s", engine_info->engine_path);
+ SLOG(LOG_DEBUG, tts_tag(), "Engine setting path : %s", engine_info->engine_setting_path);
+ SLOG(LOG_DEBUG, tts_tag(), "Use network : %s", engine_info->use_network ? "true" : "false");
+ SLOG(LOG_DEBUG, tts_tag(), "--------------------");
+ SLOG(LOG_DEBUG, tts_tag(), " ");
+
+ return TTSD_ERROR_NONE;
+}
+
+int ttsd_engine_agent_init(ttse_request_callback_s *callback)
{
if (__is_agent_initialized()) {
SLOG(LOG_WARN, tts_tag(), "[Engine Agent] Already initialized");
return TTSD_ERROR_NONE;
}
+ if (false == __is_callback_valid(callback)) {
+ SLOG(LOG_ERROR, tts_tag(), "[Engine Agent ERROR] Invalid engine");
+ return TTSD_ERROR_ENGINE_NOT_FOUND;
+ }
+
ttsengine_info_s* temp;
temp = (ttsengine_info_s*)calloc(1, sizeof(ttsengine_info_s));
if (NULL == temp) {
temp->default_pitch = TTS_PITCH_NORMAL;
}
- temp->is_loaded = false;
- g_engine_info = temp;
+ /* Get current engine info */
+ int ret = __set_engine_callback(callback, temp);
+ if (TTSD_ERROR_NONE != ret) {
+ SLOG(LOG_ERROR, tts_tag(), "[Engine Agent ERROR] Fail to get engine info");
+ free(temp);
+ temp = NULL;
+ return ret;
+ }
+ g_engine_info = temp;
g_agent_init = true;
SLOG(LOG_DEBUG, tts_tag(), "[Engine Agent SUCCESS] Initialize Engine Agent");
return TTSD_ERROR_NONE;
}
-int ttsd_engine_agent_load_current_engine(ttse_request_callback_s* callback)
+int ttsd_engine_agent_load_current_engine()
{
SLOG(LOG_DEBUG, tts_tag(), "[Engine Agent DEBUG] load current engine START");
- if (NULL == callback) {
- SLOG(LOG_ERROR, tts_tag(), "[Engine Agent ERROR] Invalid engine");
- return TTSD_ERROR_ENGINE_NOT_FOUND;
- }
-
- if (NULL == callback->get_info
- || NULL == callback->initialize || NULL == callback->deinitialize
- || NULL == callback->foreach_voices || NULL == callback->is_valid_voice
- || NULL == callback->set_pitch
- || NULL == callback->load_voice || NULL == callback->unload_voice
- || NULL == callback->start_synth || NULL == callback->cancel_synth
- || NULL == callback->check_app_agreed || NULL == callback->need_app_credential) {
- SLOG(LOG_ERROR, tts_tag(), "[Engine Agent ERROR] Invalid engine");
- return TTSD_ERROR_ENGINE_NOT_FOUND;
- }
-
if (false == __is_agent_initialized()) {
SLOG(LOG_ERROR, tts_tag(), "[Engine Agent ERROR] Not Initialized");
return TTSD_ERROR_INVALID_STATE;
return TTSD_ERROR_NONE;
}
- /* Get current engine info */
- int ret = __internal_get_engine_info(callback);
- if (0 != ret) {
- SLOG(LOG_ERROR, tts_tag(), "[Engine Agent ERROR] Fail to get engine info");
- return ret;
- }
-
/* Initialize engine */
- ret = g_engine_info->callbacks->initialize();
+ int ret = g_engine_info->callbacks->initialize();
if (0 != ret) {
SLOG(LOG_ERROR, tts_tag(), "[Engine Agent ERROR] Fail to initialize current engine : %s", __ttsd_get_engine_error_code(ret));
return TTSD_ERROR_OPERATION_FAILED;
return TTSD_ERROR_NONE;
}
-static int __internal_get_engine_info(ttse_request_callback_s* callback)
-{
- SLOG(LOG_DEBUG, tts_tag(), "[Engine Agent DEBUG] internal get engine info");
-
- if (NULL == callback) {
- SLOG(LOG_ERROR, tts_tag(), "[Engine Agent ERROR] Invalid engine");
- return TTSD_ERROR_ENGINE_NOT_FOUND;
- }
-
- if (NULL == callback->get_info) {
- SLOG(LOG_ERROR, tts_tag(), "[Engine Agent ERROR] Invalid engine");
- return TTSD_ERROR_ENGINE_NOT_FOUND;
- }
-
- if (0 != callback->get_info(&(g_engine_info->engine_uuid), &(g_engine_info->engine_name), &(g_engine_info->engine_setting_path), &(g_engine_info->use_network))) {
- SLOG(LOG_ERROR, tts_tag(), "[Engine Agent ERROR] Fail to get engine info");
- return TTSD_ERROR_ENGINE_NOT_FOUND;
- }
-
- if (NULL != g_engine_info->engine_path) {
- free(g_engine_info->engine_path);
- g_engine_info->engine_path = NULL;
- }
- g_engine_info->engine_path = strdup("empty");
- g_engine_info->is_loaded = false;
-
- if (NULL != g_engine_info->callbacks) {
- free(g_engine_info->callbacks);
- g_engine_info->callbacks = NULL;
- }
- g_engine_info->callbacks = (tts_engine_callback_s*)calloc(1, sizeof(tts_engine_callback_s));
- if (NULL == g_engine_info->callbacks) {
- SLOG(LOG_ERROR, tts_tag(), "[Engine Agent ERROR] Fail to allocate memory");
- return TTSD_ERROR_OUT_OF_MEMORY;
- }
-
- g_engine_info->callbacks->get_info = callback->get_info;
- g_engine_info->callbacks->initialize = callback->initialize;
- g_engine_info->callbacks->deinitialize = callback->deinitialize;
- g_engine_info->callbacks->foreach_voices = callback->foreach_voices;
- g_engine_info->callbacks->is_valid_voice = callback->is_valid_voice;
- g_engine_info->callbacks->set_pitch = callback->set_pitch;
- g_engine_info->callbacks->load_voice = callback->load_voice;
- g_engine_info->callbacks->unload_voice = callback->unload_voice;
- g_engine_info->callbacks->start_synth = callback->start_synth;
- g_engine_info->callbacks->cancel_synth = callback->cancel_synth;
- g_engine_info->callbacks->check_app_agreed = callback->check_app_agreed;
- g_engine_info->callbacks->need_app_credential = callback->need_app_credential;
-
- g_engine_info->callbacks->private_data_set = NULL;
- g_engine_info->callbacks->private_data_requested = NULL;
-
- SLOG(LOG_DEBUG, tts_tag(), "--- Valid Engine ---");
- SLOG(LOG_DEBUG, tts_tag(), "Engine uuid : %s", g_engine_info->engine_uuid);
- SLOG(LOG_DEBUG, tts_tag(), "Engine name : %s", g_engine_info->engine_name);
- SLOG(LOG_DEBUG, tts_tag(), "Engine path : %s", g_engine_info->engine_path);
- SLOG(LOG_DEBUG, tts_tag(), "Engine setting path : %s", g_engine_info->engine_setting_path);
- SLOG(LOG_DEBUG, tts_tag(), "Use network : %s", g_engine_info->use_network ? "true" : "false");
- SLOG(LOG_DEBUG, tts_tag(), "--------------------");
- SLOG(LOG_DEBUG, tts_tag(), " ");
-
- return TTSD_ERROR_NONE;
-}
-
/** Set callbacks of the current engine */
int ttsd_engine_agent_set_private_data_set_cb(ttse_private_data_set_cb callback)
{
- int ret = __check_engine_initialized_and_loaded();
- if (TTSD_ERROR_NONE != ret) {
- SLOG(LOG_ERROR, tts_tag(), "[Engine Agent ERROR] Precondition is not met(%s)", get_error_message(ret));
- return ret;
+ if (false == __is_agent_initialized()) {
+ SLOG(LOG_ERROR, tts_tag(), "[Engine Agent ERROR] Not Initialized");
+ return TTSD_ERROR_INVALID_STATE;
}
g_engine_info->callbacks->private_data_set = callback;
int ttsd_engine_agent_set_private_data_requested_cb(ttse_private_data_requested_cb callback)
{
- int ret = __check_engine_initialized_and_loaded();
- if (TTSD_ERROR_NONE != ret) {
- SLOG(LOG_ERROR, tts_tag(), "[Engine Agent ERROR] Precondition is not met(%s)", get_error_message(ret));
- return ret;
+ if (false == __is_agent_initialized()) {
+ SLOG(LOG_ERROR, tts_tag(), "[Engine Agent ERROR] Not Initialized");
+ return TTSD_ERROR_INVALID_STATE;
}
g_engine_info->callbacks->private_data_requested = callback;
}
/* Engine Agent initialize */
- if (0 != ttsd_engine_agent_init()) {
+ if (TTSD_ERROR_NONE != ttsd_engine_agent_init(callback)) {
SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to engine agent initialize.");
return TTSD_ERROR_OPERATION_FAILED;
}
- if (0 != ttsd_engine_agent_load_current_engine(callback)) {
- SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to load current engine");
- return TTSD_ERROR_OPERATION_FAILED;
- }
-
ttsd_data_set_synth_control(TTSD_SYNTHESIS_CONTROL_EXPIRED);
ttsd_config_set_screen_reader_callback(__screen_reader_changed_cb);
return TTSD_ERROR_NONE;
}
+ if (0 != ttsd_data_new_client(pid, uid, mode, method)) {
+ SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to add client info");
+ return TTSD_ERROR_OPERATION_FAILED;
+ }
+
+ if (TTSD_ERROR_NONE != ttsd_engine_agent_load_current_engine()) {
+ SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to load current engine");
+ ttsd_data_delete_client(uid);
+ return TTSD_ERROR_OPERATION_FAILED;
+ }
+
if (0 != ttsd_engine_agent_is_credential_needed(uid, credential_needed)) {
SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to get credential necessity");
+ ttsd_data_delete_client(uid);
return TTSD_ERROR_OPERATION_FAILED;
}
SLOG(LOG_ERROR, tts_tag(), "Server ERROR] Fail to check app agreed");
if (!appid)
free(appid);
+ ttsd_data_delete_client(uid);
return TTSD_ERROR_OPERATION_FAILED;
}
if (!appid)
if (false == is_agreed) {
SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] App is not agreed");
+ ttsd_data_delete_client(uid);
return TTSD_ERROR_PERMISSION_DENIED;
}
}
- if (0 != ttsd_data_new_client(pid, uid, mode, method)) {
- SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to add client info");
- return TTSD_ERROR_OPERATION_FAILED;
- }
-
return TTSD_ERROR_NONE;
}