SLOG(LOG_INFO, TAG_TTSC, "engine app id : %s", app_id);
}
-static rpc_port_proxy_tts_h __create_rpc_port(unsigned int uid, const char* engine_app_id)
-{
- rpc_port_proxy_tts_callback_s rpc_callback = {
- .connected = __on_connected,
- .disconnected = __on_disconnected,
- .rejected = __on_rejected
- };
-
- rpc_port_proxy_tts_h handle = NULL;
- uintptr_t ptr_uid = uid;
- if (RPC_PORT_ERROR_NONE != rpc_port_proxy_tts_create(engine_app_id, &rpc_callback, (void*)ptr_uid, &handle)) {
- SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to create proxy");
- return NULL;
- }
-
- return handle;
-}
-
int tts_tidl_open_connection(unsigned int uid)
{
SLOG(LOG_DEBUG, TAG_TTSC, "[TIDL] tts_tidl_open_connection");
return TTS_ERROR_OUT_OF_MEMORY;
}
- char engine_app_id[TTS_ENGINE_APPID_LEN] = {0, };
- __get_engine_app_id(TTS_ENGINE_APPID_LEN, engine_app_id);
+ info->uid = uid;
+ g_tidl_infos = g_list_append(g_tidl_infos, info);
+
+ SLOG(LOG_ERROR, TAG_TTSC, "[TIDL] uid(%u)", uid);
+ return TTS_ERROR_NONE;
+}
+
+static inline int __destroy_rpc_port(tts_tidl_info_s* info)
+{
+ RETVM_IF(NULL == info->rpc_h, TTS_ERROR_NONE, "[TIDL] Handle is already destroyed");
- info->rpc_h = __create_rpc_port(uid, engine_app_id);
- if (NULL == info->rpc_h) {
- SLOG(LOG_ERROR, TAG_TTSC, "[TIDL ERROR] Fail to create proxy");
- free(info);
+ if (RPC_PORT_ERROR_NONE != rpc_port_proxy_tts_destroy(info->rpc_h)) {
+ SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to destroy handle");
return TTS_ERROR_OPERATION_FAILED;
}
+ info->rpc_h = NULL;
+ info->notify_cb_h = NULL;
- info->engine_app_id = strdup(engine_app_id);
- info->uid = uid;
- g_tidl_infos = g_list_append(g_tidl_infos, info);
+ free(info->engine_app_id);
+ info->engine_app_id = NULL;
+
+ info->register_callback_invoked = false;
+ info->connection_requesting = false;
+ info->connected = false;
- SLOG(LOG_ERROR, TAG_TTSC, "[TIDL] uid(%u) rpc_h(%p), engine_app_id(%s)", uid, info->rpc_h, info->engine_app_id);
return TTS_ERROR_NONE;
}
tts_tidl_info_s* info = __get_tidl_info_s(uid);
RETVM_IF(NULL == info, TTS_ERROR_INVALID_PARAMETER, "[ERROR] Fail to get tidl info");
- if (RPC_PORT_ERROR_NONE != rpc_port_proxy_tts_destroy(info->rpc_h)) {
+ if (TTS_ERROR_NONE != __destroy_rpc_port(info)) {
SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to disconnect");
return TTS_ERROR_OPERATION_FAILED;
}
- info->rpc_h = NULL;
- info->notify_cb_h = NULL;
-
free(info->engine_app_id);
info->engine_app_id = NULL;
return TTS_ERROR_NONE;
}
+static inline bool __is_rpc_port_valid(tts_tidl_info_s* info, const char* engine_id)
+{
+ if (NULL == info->rpc_h || NULL == info->engine_app_id) {
+ SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Handle is empty");
+ return false;
+ }
+
+ if (NULL == engine_id) {
+ SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Engine ID is null");
+ return false;
+ }
+
+ if (0 != strncmp(info->engine_app_id, engine_id, TTS_ENGINE_APPID_LEN)) {
+ SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Engine id is not current engine");
+ return false;
+ }
+
+ return true;
+}
+
+static inline int __create_rpc_port(tts_tidl_info_s* info, const char* engine_id)
+{
+ RETVM_IF(NULL != info->rpc_h, TTS_ERROR_NONE, "[TIDL] Handle is already created");
+
+ rpc_port_proxy_tts_callback_s rpc_callback = {
+ .connected = __on_connected,
+ .disconnected = __on_disconnected,
+ .rejected = __on_rejected
+ };
+
+ rpc_port_proxy_tts_h handle = NULL;
+ uintptr_t ptr_uid = info->uid;
+ if (RPC_PORT_ERROR_NONE != rpc_port_proxy_tts_create(engine_id, &rpc_callback, (void*)ptr_uid, &handle) || NULL == handle) {
+ SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to create proxy");
+ return TTS_ERROR_OPERATION_FAILED;
+ }
+
+ info->rpc_h = handle;
+ info->engine_app_id = strdup(engine_id);
+
+ return TTS_ERROR_NONE;
+}
+
+static int __reset_rpc_port(tts_tidl_info_s* info, const char* engine_id)
+{
+ if (TTS_ERROR_NONE != __destroy_rpc_port(info)) {
+ SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to destroy old rpc port");
+ return TTS_ERROR_OPERATION_FAILED;
+ }
+
+ if (TTS_ERROR_NONE != __create_rpc_port(info, engine_id)) {
+ SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to create new rpc port");
+ return TTS_ERROR_OPERATION_FAILED;
+ }
+
+ SLOG(LOG_INFO, TAG_TTSC, "[TIDL] Reset rpc port. uid(%u). engine ID(%s)", info->uid, engine_id);
+ return TTS_ERROR_NONE;
+}
+
+static int __check_and_prepare_rpc_port(tts_tidl_info_s* info)
+{
+ char engine_id[TTS_ENGINE_APPID_LEN] = {0, };
+ __get_engine_app_id(TTS_ENGINE_APPID_LEN, engine_id);
+
+ if (__is_rpc_port_valid(info, engine_id)) {
+ SLOG(LOG_INFO, TAG_TTSC, "[TIDL] Current rpc port is valid");
+ return TTS_ERROR_NONE;
+ }
+
+ return __reset_rpc_port(info, engine_id);
+}
+
int tts_tidl_request_hello(unsigned int uid, tts_mode_e mode, int registered_event_mask)
{
SLOG(LOG_DEBUG, TAG_TTSC, "[TIDL] tts_tidl_request_hello");
tts_tidl_info_s* info = __get_tidl_info_s(uid);
RETVM_IF(NULL == info, TTS_ERROR_INVALID_PARAMETER, "[ERROR] Fail to get tidl info");
- char engine_app_id[TTS_ENGINE_APPID_LEN] = {0, };
- __get_engine_app_id(TTS_ENGINE_APPID_LEN, engine_app_id);
-
- if (NULL == info->engine_app_id || 0 != strncmp(info->engine_app_id, engine_app_id, TTS_ENGINE_APPID_LEN)) {
- SLOG(LOG_ERROR, TAG_TTSC, "[TIDL] tts engine is changed from (%s) to (%s)", info->engine_app_id, engine_app_id);
- if (RPC_PORT_ERROR_NONE != rpc_port_proxy_tts_destroy(info->rpc_h)) {
- SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to destroy old rpc_port");
- return TTS_ERROR_OPERATION_FAILED;
- }
- info->notify_cb_h = NULL;
- info->register_callback_invoked = false;
-
- info->rpc_h = __create_rpc_port(uid, engine_app_id);
- if (NULL == info->rpc_h) {
- SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to create proxy");
- return TTS_ERROR_OPERATION_FAILED;
- }
- free(info->engine_app_id);
- info->engine_app_id = strdup(engine_app_id);
- info->connection_requesting = false;
+ if (TTS_ERROR_NONE != __check_and_prepare_rpc_port(info)) {
+ SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to prepare rpc port");
+ return TTS_ERROR_OPERATION_FAILED;
}
if (!info->connected) {
return TTS_ERROR_OPERATION_FAILED;
}
-static int __convert_unhandled_error(int ret)
+static int __convert_and_handle_tidl_error(int ret, tts_tidl_info_s* info)
{
switch (ret) {
case RPC_PORT_ERROR_IO_ERROR:
+ SLOG(LOG_INFO, TAG_TTSC, "[INFO] IO error occurs. Destroy old rpc port");
+ __destroy_rpc_port(info);
return TTS_ERROR_IO_ERROR;
case RPC_PORT_ERROR_OUT_OF_MEMORY:
ret = rpc_port_proxy_tts_invoke_register_cb_sync(info->rpc_h, pid, info->uid, info->notify_cb_h);
int exception = get_last_result();
if (RPC_PORT_ERROR_NONE != exception) {
- ret = __convert_unhandled_error(exception);
+ ret = __convert_and_handle_tidl_error(exception, info);
}
info->register_callback_invoked = false;
tts_tidl_info_s* info = __get_tidl_info_s(uid);
RETVM_IF(NULL == info, TTS_ERROR_INVALID_PARAMETER, "[ERROR] Fail to get tidl info");
+ if (TTS_ERROR_NONE != __check_and_prepare_rpc_port(info)) {
+ SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to prepare rpc port");
+ return TTS_ERROR_OPERATION_FAILED;
+ }
+
if (!info->connected) {
SLOG(LOG_WARN, TAG_TTSC, "[WARNNING] Stub is not Connected. Try to connect..");
int ret = __request_tidl_connect_sync(info);
tts_tidl_info_s* info = __get_tidl_info_s(uid);
RETVM_IF(NULL == info, TTS_ERROR_INVALID_PARAMETER, "[ERROR] Fail to get tidl info");
- RETVM_IF(!info->connected, TTS_ERROR_OPERATION_FAILED, "[ERROR] Not Connected");
+ RETVM_IF(!info->connected, TTS_ERROR_IO_ERROR, "[ERROR] Not Connected");
bool temp;
int ret = rpc_port_proxy_tts_invoke_initialize(info->rpc_h, client->pid, uid, (int)mode, registered_event_mask, &temp);
int exception = get_last_result();
if (RPC_PORT_ERROR_NONE != exception) {
- ret = __convert_unhandled_error(exception);
+ ret = __convert_and_handle_tidl_error(exception, info);
}
SLOG(LOG_ERROR, TAG_TTSC, ">>>> Request tts initialize : ret(%d/%s)", ret, get_error_message(ret));
int tts_tidl_request_finalize(unsigned int uid)
{
- SLOG(LOG_DEBUG, TAG_TTSC, "[TIDL] tts_tidl_request_finalize");
+ SLOG(LOG_INFO, TAG_TTSC, "[TIDL] tts_tidl_request_finalize");
tts_client_s* client = tts_client_get_by_uid(uid);
- RETVM_IF(NULL == client, TTS_ERROR_INVALID_PARAMETER, "[ERROR] Fail to get client");
+ RETVM_IF(NULL == client, TTS_ERROR_INVALID_PARAMETER, "[ERROR] Fail to get client");
tts_tidl_info_s* info = __get_tidl_info_s(uid);
RETVM_IF(NULL == info, TTS_ERROR_INVALID_PARAMETER, "[ERROR] Fail to get tidl info");
- RETVM_IF(!info->connected, TTS_ERROR_OPERATION_FAILED, "[ERROR] Not Connected");
+ RETVM_IF(!info->connected, TTS_ERROR_IO_ERROR, "[ERROR] Not Connected");
int ret = rpc_port_proxy_tts_invoke_finalize(info->rpc_h, uid);
int exception = get_last_result();
if (RPC_PORT_ERROR_NONE != exception) {
- ret = __convert_unhandled_error(exception);
+ ret = __convert_and_handle_tidl_error(exception, info);
}
- SLOG(LOG_ERROR, TAG_TTSC, ">>>> Request tts finalize. ret(%d/%s)", ret, get_error_message(ret));
if (TTS_ERROR_NONE != ret) {
+ SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to tts finalize. ret(%d/%s)", ret, get_error_message(ret));
return ret;
}
tts_client_set_start_listening(uid, false);
+ if (TTS_ERROR_NONE != __destroy_rpc_port(info)) {
+ SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to destroy rpc port. ret(%d)", ret);
+ return TTS_ERROR_OPERATION_FAILED;
+ }
+ SLOG(LOG_ERROR, TAG_TTSC, ">>>> Success tts finalize. uid(%u)", uid);
+
return TTS_ERROR_NONE;
}
RETVM_IF(NULL == text || NULL == lang, TTS_ERROR_INVALID_PARAMETER, "Input parameter is NULL");
- RETVM_IF(!info->connected, TTS_ERROR_OPERATION_FAILED, "[ERROR] Not Connected");
-
+ RETVM_IF(!info->connected, TTS_ERROR_IO_ERROR, "[ERROR] Not Connected");
const char *not_null_credential = NULL == credential ? "NULL" : credential;
int ret = rpc_port_proxy_tts_invoke_add_text(info->rpc_h, uid, text, lang, vctype, speed, uttid, not_null_credential);
int exception = get_last_result();
if (RPC_PORT_ERROR_NONE != exception) {
- ret = __convert_unhandled_error(exception);
+ ret = __convert_and_handle_tidl_error(exception, info);
}
if (TTS_ERROR_NONE != ret) {
RETVM_IF(NULL == key || NULL == data, TTS_ERROR_INVALID_PARAMETER, "Input parameter is NULL");
- RETVM_IF(!info->connected, TTS_ERROR_OPERATION_FAILED, "[ERROR] Not Connected");
-
+ RETVM_IF(!info->connected, TTS_ERROR_IO_ERROR, "[ERROR] Not Connected");
int ret = rpc_port_proxy_tts_invoke_set_private(info->rpc_h, uid, key, data);
int exception = get_last_result();
if (RPC_PORT_ERROR_NONE != exception) {
- ret = __convert_unhandled_error(exception);
+ ret = __convert_and_handle_tidl_error(exception, info);
}
if (TTS_ERROR_NONE != ret) {
RETVM_IF(NULL == key || NULL == data, TTS_ERROR_INVALID_PARAMETER, "Input parameter is NULL");
- RETVM_IF(!info->connected, TTS_ERROR_OPERATION_FAILED, "[ERROR] Not Connected");
+ RETVM_IF(!info->connected, TTS_ERROR_IO_ERROR, "[ERROR] Not Connected");
char *tmp = NULL;
int ret = rpc_port_proxy_tts_invoke_get_private(info->rpc_h, uid, key, &tmp);
int exception = get_last_result();
if (RPC_PORT_ERROR_NONE != exception) {
- ret = __convert_unhandled_error(exception);
+ ret = __convert_and_handle_tidl_error(exception, info);
}
if (TTS_ERROR_NONE != ret) {
tts_tidl_info_s* info = __get_tidl_info_s(uid);
RETVM_IF(NULL == info, TTS_ERROR_INVALID_PARAMETER, "[ERROR] Fail to get tidl info");
- RETVM_IF(!info->connected, TTS_ERROR_OPERATION_FAILED, "[ERROR] Not Connected");
+ RETVM_IF(!info->connected, TTS_ERROR_IO_ERROR, "[ERROR] Not Connected");
const char *not_null_credential = NULL == credential ? "NULL" : credential;
int ret = rpc_port_proxy_tts_invoke_play(info->rpc_h, uid, not_null_credential);
int exception = get_last_result();
if (RPC_PORT_ERROR_NONE != exception) {
- ret = __convert_unhandled_error(exception);
+ ret = __convert_and_handle_tidl_error(exception, info);
}
if (TTS_ERROR_NONE != ret) {
tts_tidl_info_s* info = __get_tidl_info_s(uid);
RETVM_IF(NULL == info, TTS_ERROR_INVALID_PARAMETER, "[ERROR] Fail to get tidl info");
- RETVM_IF(!info->connected, TTS_ERROR_OPERATION_FAILED, "[ERROR] Not Connected");
+ RETVM_IF(!info->connected, TTS_ERROR_IO_ERROR, "[ERROR] Not Connected");
int ret = rpc_port_proxy_tts_invoke_stop(info->rpc_h, uid);
int exception = get_last_result();
if (RPC_PORT_ERROR_NONE != exception) {
- ret = __convert_unhandled_error(exception);
+ ret = __convert_and_handle_tidl_error(exception, info);
}
if (TTS_ERROR_NONE != ret) {
tts_tidl_info_s* info = __get_tidl_info_s(uid);
RETVM_IF(NULL == info, TTS_ERROR_INVALID_PARAMETER, "[ERROR] Fail to get tidl info");
- RETVM_IF(!info->connected, TTS_ERROR_OPERATION_FAILED, "[ERROR] Not Connected");
+ RETVM_IF(!info->connected, TTS_ERROR_IO_ERROR, "[ERROR] Not Connected");
int ret = rpc_port_proxy_tts_invoke_pause(info->rpc_h, uid);
int exception = get_last_result();
if (RPC_PORT_ERROR_NONE != exception) {
- ret = __convert_unhandled_error(exception);
+ ret = __convert_and_handle_tidl_error(exception, info);
}
if (TTS_ERROR_NONE != ret) {
tts_tidl_info_s* info = __get_tidl_info_s(uid);
RETVM_IF(NULL == info, TTS_ERROR_INVALID_PARAMETER, "[ERROR] Fail to get tidl info");
- RETVM_IF(!info->connected, TTS_ERROR_OPERATION_FAILED, "[ERROR] Not Connected");
+ RETVM_IF(!info->connected, TTS_ERROR_IO_ERROR, "[ERROR] Not Connected");
int ret = rpc_port_proxy_tts_invoke_play_pcm(info->rpc_h, uid);
int exception = get_last_result();
if (RPC_PORT_ERROR_NONE != exception) {
- ret = __convert_unhandled_error(exception);
+ ret = __convert_and_handle_tidl_error(exception, info);
}
if (TTS_ERROR_NONE != ret) {
tts_tidl_info_s* info = __get_tidl_info_s(uid);
RETVM_IF(NULL == info, TTS_ERROR_INVALID_PARAMETER, "[ERROR] Fail to get tidl info");
- RETVM_IF(!info->connected, TTS_ERROR_OPERATION_FAILED, "[ERROR] Not Connected");
+ RETVM_IF(!info->connected, TTS_ERROR_IO_ERROR, "[ERROR] Not Connected");
int ret = rpc_port_proxy_tts_invoke_stop_pcm(info->rpc_h, uid);
int exception = get_last_result();
if (RPC_PORT_ERROR_NONE != exception) {
- ret = __convert_unhandled_error(exception);
+ ret = __convert_and_handle_tidl_error(exception, info);
}
if (TTS_ERROR_NONE != ret) {
tts_tidl_info_s* info = __get_tidl_info_s(uid);
RETVM_IF(NULL == info, TTS_ERROR_INVALID_PARAMETER, "[ERROR] Fail to get tidl info");
- RETVM_IF(!info->connected, TTS_ERROR_OPERATION_FAILED, "[ERROR] Not Connected");
+ RETVM_IF(!info->connected, TTS_ERROR_IO_ERROR, "[ERROR] Not Connected");
rpc_port_proxy_array_char_h pcm_data = NULL;
rpc_port_proxy_array_char_create(&pcm_data);
rpc_port_proxy_array_char_destroy(pcm_data);
int exception = get_last_result();
if (RPC_PORT_ERROR_NONE != exception) {
- ret = __convert_unhandled_error(exception);
+ ret = __convert_and_handle_tidl_error(exception, info);
}
if (TTS_ERROR_NONE != ret) {
tts_tidl_info_s* info = __get_tidl_info_s(uid);
RETVM_IF(NULL == info, TTS_ERROR_INVALID_PARAMETER, "[ERROR] Fail to get tidl info");
- RETVM_IF(!info->connected, TTS_ERROR_OPERATION_FAILED, "[ERROR] Not Connected");
+ RETVM_IF(!info->connected, TTS_ERROR_IO_ERROR, "[ERROR] Not Connected");
int state = (int)TTS_SERVICE_STATE_READY;
int ret = rpc_port_proxy_tts_invoke_get_service_state(info->rpc_h, uid, &state);
int exception = get_last_result();
if (RPC_PORT_ERROR_NONE != exception) {
- ret = __convert_unhandled_error(exception);
+ ret = __convert_and_handle_tidl_error(exception, info);
}
if (TTS_ERROR_NONE != ret) {