Fix tidl error handling code 35/278935/3
authorSuyeon Hwang <stom.hwang@samsung.com>
Thu, 28 Jul 2022 07:52:38 +0000 (16:52 +0900)
committerSuyeon Hwang <stom.hwang@samsung.com>
Mon, 1 Aug 2022 06:44:45 +0000 (15:44 +0900)
- Issue:
TIDL functions always return -1 even if those are failed by various
reasons.

- Solution:
The code generated by tidlc uses 'set_last_result()' and 'get_last_result()'
function for handling exception. Thus, the caller of those code should
check the error code of 'get_last_result()' first. However, current code
only check return value of each functions.
This patch adds logic for check the error from 'get_last_result()'.
Through this change, framework can handle error from tidl code properly.

Change-Id: Ic075a95ebb64074797633f5973c8c4d5fe8d07e0
Signed-off-by: Suyeon Hwang <stom.hwang@samsung.com>
client/tts_tidl.c

index 83b6293..3c32134 100644 (file)
@@ -198,7 +198,7 @@ static rpc_port_proxy_tts_h __create_rpc_port(unsigned int uid, const char* engi
 
        rpc_port_proxy_tts_h handle = NULL;
        uintptr_t ptr_uid = uid;
-       if (0 != rpc_port_proxy_tts_create(engine_app_id, &rpc_callback, (void*)ptr_uid, &handle)) {
+       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;
        }
@@ -247,7 +247,7 @@ int tts_tidl_close_connection(unsigned int uid)
        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 (0 != rpc_port_proxy_tts_destroy(info->rpc_h)) {
+       if (RPC_PORT_ERROR_NONE != rpc_port_proxy_tts_destroy(info->rpc_h)) {
                SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to disconnect");
                return TTS_ERROR_OPERATION_FAILED;
        }
@@ -317,7 +317,7 @@ static int __invoke_register_callback(int pid, tts_tidl_info_s* info)
        int ret = __create_notify_callback_handle(info);
        if (TTS_ERROR_NONE != ret) {
                SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to create callback handle. ret(%d)", ret);
-               return TTS_ERROR_OPERATION_FAILED;
+               return ret;
        }
 
        rpc_port_proxy_tts_invoke_register_cb(info->rpc_h, pid, info->uid, info->notify_cb_h);
@@ -340,7 +340,7 @@ int tts_tidl_request_hello(unsigned int uid)
 
        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 (0 != rpc_port_proxy_tts_destroy(info->rpc_h)) {
+               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;
                }
@@ -384,6 +384,15 @@ static int __request_tidl_connect_sync(tts_tidl_info_s* info)
        return TTS_ERROR_OPERATION_FAILED;
 }
 
+static int __convert_unhandled_error(int ret)
+{
+       if (RPC_PORT_ERROR_IO_ERROR == ret || RPC_PORT_ERROR_OUT_OF_MEMORY == ret) {
+               return TTS_ERROR_OPERATION_FAILED;
+       }
+
+       return ret;
+}
+
 static int __invoke_register_callback_sync(int pid, tts_tidl_info_s* info)
 {
        if (info->register_callback_invoked) {
@@ -391,17 +400,22 @@ static int __invoke_register_callback_sync(int pid, tts_tidl_info_s* info)
                return TTS_ERROR_NONE;
        }
 
-       int ret = RPC_PORT_ERROR_NONE;
+       int ret = TTS_ERROR_NONE;
        ret = __create_notify_callback_handle(info);
-       if (RPC_PORT_ERROR_NONE != ret) {
+       if (TTS_ERROR_NONE != ret) {
                SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to create callback handle. ret(%d/%s)", ret, get_error_message(ret));
-               return TTS_ERROR_OPERATION_FAILED;
+               return ret;
        }
 
        ret = rpc_port_proxy_tts_invoke_register_cb_sync(info->rpc_h, pid, info->uid, info->notify_cb_h);
-       if (RPC_PORT_ERROR_NONE != ret) {
+       int exception = get_last_result();
+       if (RPC_PORT_ERROR_NONE != exception) {
+               ret = __convert_unhandled_error(exception);
+       }
+
+       if (TTS_ERROR_NONE != ret) {
                SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to register callback. ret(%d/%s)", ret, get_error_message(ret));
-               return TTS_ERROR_OPERATION_FAILED;
+               return ret;
        }
 
        info->register_callback_invoked = true;
@@ -439,15 +453,6 @@ int tts_tidl_request_hello_sync(unsigned int uid)
        return TTS_ERROR_NONE;
 }
 
-static int __covert_unhandled_error(int ret)
-{
-       if (RPC_PORT_ERROR_IO_ERROR == ret || RPC_PORT_ERROR_OUT_OF_MEMORY == ret) {
-               return TTS_ERROR_OPERATION_FAILED;
-       }
-
-       return ret;
-}
-
 int tts_tidl_request_initialize(unsigned int uid, bool* credential_needed)
 {
        SLOG(LOG_DEBUG, TAG_TTSC, "[TIDL] tts_tidl_request_initialize");
@@ -462,9 +467,14 @@ int tts_tidl_request_initialize(unsigned int uid, bool* credential_needed)
 
        bool temp;
        int ret = rpc_port_proxy_tts_invoke_initialize(info->rpc_h, client->pid, uid, &temp);
-       if (RPC_PORT_ERROR_NONE != ret) {
+       int exception = get_last_result();
+       if (RPC_PORT_ERROR_NONE != exception) {
+               ret = __convert_unhandled_error(exception);
+       }
+
+       if (TTS_ERROR_NONE != ret) {
                SLOG(LOG_ERROR, TAG_TTSC, ">>>> Request tts initialize : Fail to invoke message");
-               return __covert_unhandled_error(ret);
+               return ret;
        }
 
        *credential_needed = temp;
@@ -488,9 +498,14 @@ int tts_tidl_request_finalize(unsigned int uid)
 
 
        int ret = rpc_port_proxy_tts_invoke_finalize(info->rpc_h, uid);
-       if (RPC_PORT_ERROR_NONE != ret) {
+       int exception = get_last_result();
+       if (RPC_PORT_ERROR_NONE != exception) {
+               ret = __convert_unhandled_error(exception);
+       }
+
+       if (TTS_ERROR_NONE != ret) {
                SLOG(LOG_ERROR, TAG_TTSC, ">>>> Request tts initialize : Fail to invoke message");
-               return __covert_unhandled_error(ret);
+               return ret;
        }
 
        tts_client_set_start_listening(uid, false);
@@ -514,9 +529,14 @@ int tts_tidl_request_add_text(unsigned int uid, const char* text, const char* la
 
        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);
-       if (RPC_PORT_ERROR_NONE != ret) {
+       int exception = get_last_result();
+       if (RPC_PORT_ERROR_NONE != exception) {
+               ret = __convert_unhandled_error(exception);
+       }
+
+       if (TTS_ERROR_NONE != ret) {
                SLOG(LOG_ERROR, TAG_TTSC, ">>>> Request add text : Fail to invoke message");
-               return __covert_unhandled_error(ret);
+               return ret;
        }
 
        return TTS_ERROR_NONE;
@@ -538,9 +558,14 @@ int tts_tidl_request_set_private_data(unsigned int uid, const char* key, const c
 
 
        int ret = rpc_port_proxy_tts_invoke_set_private(info->rpc_h, uid, key, data);
-       if (RPC_PORT_ERROR_NONE != ret) {
+       int exception = get_last_result();
+       if (RPC_PORT_ERROR_NONE != exception) {
+               ret = __convert_unhandled_error(exception);
+       }
+
+       if (TTS_ERROR_NONE != ret) {
                SLOG(LOG_ERROR, TAG_TTSC, ">>>> Request set private data : Fail to invoke message");
-               return __covert_unhandled_error(ret);
+               return ret;
        }
 
        return TTS_ERROR_NONE;
@@ -560,17 +585,21 @@ int tts_tidl_request_get_private_data(unsigned int uid, const char* key, char**
 
        RETVM_IF(!info->connected, TTS_ERROR_OPERATION_FAILED, "[ERROR] Not Connected");
 
-
        char *tmp = NULL;
        int ret = rpc_port_proxy_tts_invoke_get_private(info->rpc_h, uid, key, &tmp);
-       if (RPC_PORT_ERROR_NONE != ret) {
+       int exception = get_last_result();
+       if (RPC_PORT_ERROR_NONE != exception) {
+               ret = __convert_unhandled_error(exception);
+       }
+
+       if (TTS_ERROR_NONE != ret) {
                SLOG(LOG_ERROR, TAG_TTSC, ">>>> Request get private data : Fail to invoke message");
                free(tmp);
-               return __covert_unhandled_error(ret);
+               return ret;
        }
-       SLOG(LOG_DEBUG, TAG_TTSC, "<<<<");
 
        *data = tmp;
+       SLOG(LOG_DEBUG, TAG_TTSC, "<<<<");
 
        return TTS_ERROR_NONE;
 }
@@ -589,9 +618,14 @@ int tts_tidl_request_play(unsigned int uid, const char* credential)
 
        const char *not_null_credential = NULL == credential ? "NULL" : credential;
        int ret = rpc_port_proxy_tts_invoke_play(info->rpc_h, uid, not_null_credential);
-       if (RPC_PORT_ERROR_NONE != ret) {
+       int exception = get_last_result();
+       if (RPC_PORT_ERROR_NONE != exception) {
+               ret = __convert_unhandled_error(exception);
+       }
+
+       if (TTS_ERROR_NONE != ret) {
                SLOG(LOG_ERROR, TAG_TTSC, ">>>> Request play : Fail to invoke message");
-               return __covert_unhandled_error(ret);
+               return ret;
        }
 
        SLOG(LOG_DEBUG, TAG_TTSC, "<<<<");
@@ -612,9 +646,14 @@ int tts_tidl_request_stop(unsigned int uid)
        RETVM_IF(!info->connected, TTS_ERROR_OPERATION_FAILED, "[ERROR] Not Connected");
 
        int ret = rpc_port_proxy_tts_invoke_stop(info->rpc_h, uid);
-       if (RPC_PORT_ERROR_NONE != ret) {
+       int exception = get_last_result();
+       if (RPC_PORT_ERROR_NONE != exception) {
+               ret = __convert_unhandled_error(exception);
+       }
+
+       if (TTS_ERROR_NONE != ret) {
                SLOG(LOG_ERROR, TAG_TTSC, ">>>> Request stop : Fail to invoke message");
-               return __covert_unhandled_error(ret);
+               return ret;
        }
        SLOG(LOG_DEBUG, TAG_TTSC, "<<<<");
 
@@ -634,9 +673,14 @@ int tts_tidl_request_pause(unsigned int uid)
        RETVM_IF(!info->connected, TTS_ERROR_OPERATION_FAILED, "[ERROR] Not Connected");
 
        int ret = rpc_port_proxy_tts_invoke_pause(info->rpc_h, uid);
-       if (RPC_PORT_ERROR_NONE != ret) {
+       int exception = get_last_result();
+       if (RPC_PORT_ERROR_NONE != exception) {
+               ret = __convert_unhandled_error(exception);
+       }
+
+       if (TTS_ERROR_NONE != ret) {
                SLOG(LOG_ERROR, TAG_TTSC, ">>>> Request pause : Fail to invoke message(%d)", ret);
-               return __covert_unhandled_error(ret);
+               return ret;
        }
 
        SLOG(LOG_DEBUG, TAG_TTSC, "<<<<");
@@ -657,9 +701,14 @@ int tts_tidl_request_play_pcm(unsigned int uid)
        RETVM_IF(!info->connected, TTS_ERROR_OPERATION_FAILED, "[ERROR] Not Connected");
 
        int ret = rpc_port_proxy_tts_invoke_play_pcm(info->rpc_h, uid);
-       if (RPC_PORT_ERROR_NONE != ret) {
+       int exception = get_last_result();
+       if (RPC_PORT_ERROR_NONE != exception) {
+               ret = __convert_unhandled_error(exception);
+       }
+
+       if (TTS_ERROR_NONE != ret) {
                SLOG(LOG_ERROR, TAG_TTSC, ">>>> Request play pcm : Fail to invoke message(%d)", ret);
-               return __covert_unhandled_error(ret);
+               return ret;
        }
 
        SLOG(LOG_DEBUG, TAG_TTSC, "<<<<");
@@ -680,9 +729,14 @@ int tts_tidl_request_stop_pcm(unsigned int uid)
        RETVM_IF(!info->connected, TTS_ERROR_OPERATION_FAILED, "[ERROR] Not Connected");
 
        int ret = rpc_port_proxy_tts_invoke_stop_pcm(info->rpc_h, uid);
-       if (RPC_PORT_ERROR_NONE != ret) {
+       int exception = get_last_result();
+       if (RPC_PORT_ERROR_NONE != exception) {
+               ret = __convert_unhandled_error(exception);
+       }
+
+       if (TTS_ERROR_NONE != ret) {
                SLOG(LOG_ERROR, TAG_TTSC, ">>>> Request pause pcm : Fail to invoke message(%d)", ret);
-               return __covert_unhandled_error(ret);
+               return ret;
        }
 
        SLOG(LOG_DEBUG, TAG_TTSC, "<<<<");
@@ -717,9 +771,14 @@ int tts_tidl_request_add_pcm(unsigned int uid, int event, const char* data, int
 
        int ret = rpc_port_proxy_tts_invoke_add_pcm(info->rpc_h, uid, event, pcm_data, data_size, audio_type, rate);
        rpc_port_proxy_array_char_destroy(pcm_data);
-       if (RPC_PORT_ERROR_NONE != ret) {
+       int exception = get_last_result();
+       if (RPC_PORT_ERROR_NONE != exception) {
+               ret = __convert_unhandled_error(exception);
+       }
+
+       if (TTS_ERROR_NONE != ret) {
                SLOG(LOG_ERROR, TAG_TTSC, ">>>> Request pause pcm : Fail to invoke message(%d)", ret);
-               return __covert_unhandled_error(ret);
+               return ret;
        }
 
        SLOG(LOG_DEBUG, TAG_TTSC, "<<<<");
@@ -740,9 +799,14 @@ int tts_tidl_request_set_mode(unsigned int uid, tts_mode_e mode)
        RETVM_IF(!info->connected, TTS_ERROR_OPERATION_FAILED, "[ERROR] Not Connected");
 
        int ret = rpc_port_proxy_tts_invoke_set_mode(info->rpc_h, uid, mode);
-       if (RPC_PORT_ERROR_NONE != ret) {
+       int exception = get_last_result();
+       if (RPC_PORT_ERROR_NONE != exception) {
+               ret = __convert_unhandled_error(exception);
+       }
+
+       if (TTS_ERROR_NONE != ret) {
                SLOG(LOG_ERROR, TAG_TTSC, ">>>> Request set private data : Fail to invoke message(%d)", ret);
-               return __covert_unhandled_error(ret);
+               return ret;
        }
 
        return TTS_ERROR_NONE;