-int ttsd_engine_agent_init(synth_result_callback result_cb)
-{
- /* initialize static data */
- if (result_cb == NULL) {
- SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] invalid parameter");
- return TTSD_ERROR_INVALID_PARAMETER;
- }
-
- g_result_cb = result_cb;
-
- g_cur_engine.engine_uuid = NULL;
- g_cur_engine.engine_name = NULL;
- g_cur_engine.engine_path = NULL;
-
- g_cur_engine.is_set = false;
- g_cur_engine.handle = NULL;
- g_cur_engine.pefuncs = (ttspe_funcs_s*)calloc(1, sizeof(ttspe_funcs_s));
- g_cur_engine.pdfuncs = (ttspd_funcs_s*)calloc(1, sizeof(ttspd_funcs_s));
-
- g_agent_init = true;
-
- if (0 != ttsd_config_get_default_voice(&(g_cur_engine.default_lang), &(g_cur_engine.default_vctype))) {
- SLOG(LOG_WARN, get_tag(), "[Server WARNING] There is No default voice in config");
- /* Set default voice */
- g_cur_engine.default_lang = strdup(TTS_BASE_LANGUAGE);
- g_cur_engine.default_vctype = TTSP_VOICE_TYPE_FEMALE;
- }
-
- if (0 != ttsd_config_get_default_speed(&(g_cur_engine.default_speed))) {
- SLOG(LOG_WARN, get_tag(), "[Server WARNING] There is No default speed in config");
- g_cur_engine.default_speed = TTS_SPEED_NORMAL;
- }
-
- if (0 != ttsd_config_get_default_pitch(&(g_cur_engine.default_pitch))) {
- SLOG(LOG_WARN, get_tag(), "[Server WARNING] There is No default pitch in config");
- g_cur_engine.default_pitch = TTS_PITCH_NORMAL;
- }
-
- SLOG(LOG_DEBUG, get_tag(), "[Engine Agent SUCCESS] Initialize Engine Agent");
-
- return 0;
-}
-
-int ttsd_engine_agent_release()
-{
- if (false == g_agent_init) {
- SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] Not Initialized");
- return TTSD_ERROR_OPERATION_FAILED;
- }
-
- /* unload current engine */
- ttsd_engine_agent_unload_current_engine();
-
- /* release engine list */
- GList *iter = NULL;
- ttsengine_info_s *data = NULL;
-
- if (g_list_length(g_engine_list) > 0) {
- /* Get a first item */
- iter = g_list_first(g_engine_list);
- while (NULL != iter) {
- /* Get data from item */
- data = iter->data;
- iter = g_list_remove(iter, data);
-
- if (NULL != data) {
- if (NULL != data->engine_uuid) free(data->engine_uuid);
- if (NULL != data->engine_name) free(data->engine_name);
- if (NULL != data->setting_ug_path) free(data->setting_ug_path);
- if (NULL != data->engine_path) free(data->engine_path);
- free(data);
- }
- }
- }
- g_list_free(iter);
-
- /* release current engine data */
- if (g_cur_engine.engine_uuid != NULL) free(g_cur_engine.engine_uuid);
- if (g_cur_engine.engine_name != NULL) free(g_cur_engine.engine_name);
- if (g_cur_engine.engine_path != NULL) free(g_cur_engine.engine_path);
-
- if (g_cur_engine.pefuncs != NULL) free(g_cur_engine.pefuncs);
- if (g_cur_engine.pdfuncs != NULL) free(g_cur_engine.pdfuncs);
- if (g_cur_engine.default_lang != NULL) free(g_cur_engine.default_lang);
- g_result_cb = NULL;
- g_agent_init = false;
-
- SLOG(LOG_DEBUG, get_tag(), "[Engine Agent SUCCESS] Release Engine Agent");
-
- return 0;
-}
-
-int ttsd_engine_agent_initialize_current_engine()
-{
- if (false == g_agent_init) {
- SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] Not Initialized");
- return TTSD_ERROR_OPERATION_FAILED;
- }
-
- /* update engine list */
- if (0 != __internal_update_engine_list()) {
- SLOG(LOG_WARN, get_tag(), "[Engine Agent WARNING] No engine error");
- return TTSD_ERROR_OPERATION_FAILED;
- }
-
- /* 2. get current engine from config */
- char* cur_engine_uuid = NULL;
- bool is_get_engineid_from_config = false;
-
- if (0 != ttsd_config_get_default_engine(&cur_engine_uuid)) {
- /*not set current engine */
- /*set system default engine*/
- GList *iter = NULL;
- ttsengine_info_s *data = NULL;
-
- if (g_list_length(g_engine_list) > 0) {
- iter = g_list_first(g_engine_list);
- data = iter->data;
-
- if (NULL != data) {
- if (NULL != data->engine_uuid) {
- cur_engine_uuid = strdup(data->engine_uuid);
- ttsd_config_set_default_engine(cur_engine_uuid);
- } else {
- SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] Data of current engine is corrupt");
- return TTSD_ERROR_OPERATION_FAILED;
- }
- }
- } else {
- SLOG(LOG_WARN, get_tag(), "[Engine Agent WARNING] Fail to set a engine of engine list");
- return TTSD_ERROR_OPERATION_FAILED;
- }
-
- is_get_engineid_from_config = false;
- } else {
- is_get_engineid_from_config = true;
- }
-
- if (NULL == cur_engine_uuid) {
- SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] Current engine id is NULL");
- return TTSD_ERROR_OPERATION_FAILED;
- }
-
- /* check whether cur engine uuid is valid or not. */
- if (0 != __internal_check_engine_id(cur_engine_uuid)) {
- SLOG(LOG_WARN, get_tag(), "[Engine Agent WARNING] It is not valid engine id from config");
-
- GList *iter = NULL;
-
- if (g_list_length(g_engine_list) > 0)
- iter = g_list_first(g_engine_list);
- else {
- SLOG(LOG_WARN, get_tag(), "[Engine Agent ERROR] NO TTS Engine !!");
- if (NULL != cur_engine_uuid) free(cur_engine_uuid);
- return TTSD_ERROR_OPERATION_FAILED;
- }
-
- if (cur_engine_uuid != NULL) free(cur_engine_uuid);
- ttsengine_info_s *data = NULL;
- data = iter->data;
-
- cur_engine_uuid = strdup(data->engine_uuid);
-
- is_get_engineid_from_config = false;
- }
-
- if (NULL != cur_engine_uuid)
- SECURE_SLOG(LOG_DEBUG, get_tag(), "[Engine Agent] Current Engine Id : %s", cur_engine_uuid);
- else
- return TTSD_ERROR_OPERATION_FAILED;
-
- /* set current engine */
- if (0 != __internal_set_current_engine(cur_engine_uuid)) {
- SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] fail to set current engine ");
- if (NULL != cur_engine_uuid) free(cur_engine_uuid);
- return TTSD_ERROR_OPERATION_FAILED;
- }
-
- if (false == is_get_engineid_from_config) {
- if (0 != ttsd_config_set_default_engine(cur_engine_uuid)) {
- SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] fail to set id to config");
- }
- }
-
- if (NULL != cur_engine_uuid) free(cur_engine_uuid);
-
- SLOG(LOG_DEBUG, get_tag(), "[Engine Agent SUCCESS] Set current engine");
-
- return 0;
-}
-
-int __internal_check_engine_id(const char* engine_uuid)