Unify error handling function 04/257104/2
authorSuyeon Hwang <stom.hwang@samsung.com>
Thu, 15 Apr 2021 07:55:55 +0000 (16:55 +0900)
committerSuyeon Hwang <stom.hwang@samsung.com>
Thu, 27 May 2021 04:45:11 +0000 (13:45 +0900)
Because tts_ipc layer is added, error handling code is duplicated.
To remove duplicated code, this patch unifies the functions for handling error from server.

Change-Id: Icc5a43cc8d66a956ef8aa050c01b718454ea8be7
Signed-off-by: Suyeon Hwang <stom.hwang@samsung.com>
client/tts.c
client/tts_core.c
client/tts_core.h
client/tts_dbus.c
client/tts_tidl.c

index 28b143f8b4e17c2ceba42b0e5d3839411f5110c8..f537b0838ce3909e24ece9c8c01ef7f0014e994a 100644 (file)
@@ -1133,7 +1133,7 @@ static void __tts_play_async(void *data)
        if (0 != ret) {
                SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to play tts : %s", __tts_get_error_code(ret));
 
-               tts_core_notify_error_async(client, -1, ret);
+               tts_core_notify_error_async(client, ret, -1, NULL);
                return;
        }
 
@@ -1307,7 +1307,7 @@ static void __tts_stop_async(void *data)
        if (0 != ret) {
                SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to stop tts : %s", __tts_get_error_code(ret));
 
-               tts_core_notify_error_async(client, -1, ret);
+               tts_core_notify_error_async(client, ret, -1, NULL);
                return;
        }
 
@@ -1468,7 +1468,7 @@ static void __tts_pause_async(void *data)
        if (0 != ret) {
                SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to pause tts : %s", __tts_get_error_code(ret));
 
-               tts_core_notify_error_async(data, -1, ret);
+               tts_core_notify_error_async(client, ret, -1, NULL);
                return;
        }
 
index e44dad17469bf482408742137f08bbd58878c8ec..e2ab7e9e122e47323eabcbdb9170f7d11647211a 100644 (file)
@@ -552,7 +552,7 @@ static Eina_Bool __prepare_sync_cb(tts_client_s* client)
 
        if (TTS_ERROR_ENGINE_NOT_FOUND == ret || TTS_ERROR_PERMISSION_DENIED == ret) {
                SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to initialize : %s", __tts_get_error_code(ret));
-               tts_core_notify_error_async(client, -1, ret);
+               tts_core_notify_error_async(client, ret, -1, NULL);
 
                return EINA_FALSE;
        } else if (TTS_ERROR_NONE != ret) {
@@ -724,20 +724,7 @@ int tts_core_notify_utt_completeted(tts_client_s* client, int utt_id)
        return TTS_ERROR_NONE;
 }
 
-int tts_core_notify_error(tts_client_s* client, int utt_id, tts_error_e reason)
-{
-       if (false == tts_client_is_valid_client(client)) {
-               SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Handle is not valid.");
-               return TTS_ERROR_INVALID_PARAMETER;
-       }
-
-       SLOG(LOG_DEBUG, TAG_TTSC, "Error data : utt_id(%d) reason(%s)", utt_id, __tts_get_error_code(reason));
-       __client_error_cb(client, utt_id, reason);
-
-       return TTS_ERROR_NONE;
-}
-
-int tts_core_notify_error_async(tts_client_s* client, int utt_id, tts_error_e reason)
+int tts_core_notify_error_async(tts_client_s* client, tts_error_e reason, int utt_id, char* err_msg)
 {
        if (false == tts_client_is_valid_client(client)) {
                SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Handle is not valid.");
@@ -747,6 +734,7 @@ int tts_core_notify_error_async(tts_client_s* client, int utt_id, tts_error_e re
        SLOG(LOG_DEBUG, TAG_TTSC, "Error data : utt_id(%d) reason(%s)", utt_id, __tts_get_error_code(reason));
        client->utt_id = utt_id;
        client->reason = reason;
+       tts_client_set_error_message(client, err_msg);
 
        SLOG(LOG_DEBUG, TAG_TTSC, "Notify error asynchronously");
        if (NULL != client->notify_error_timer) {
@@ -885,7 +873,7 @@ int tts_core_receive_hello(int uid, int ret, int credential_needed)
 
        if (TTS_ERROR_ENGINE_NOT_FOUND == ret || TTS_ERROR_PERMISSION_DENIED == ret) {
                SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to initialize : %s", __tts_get_error_code(ret));
-               tts_core_notify_error_async(client, -1, ret);
+               tts_core_notify_error_async(client, ret, -1, NULL);
 
                return TTS_ERROR_OPERATION_FAILED;
        } else if (TTS_ERROR_NONE != ret) {
@@ -1055,3 +1043,33 @@ int tts_core_foreach_supported_voices(tts_client_s* client, const char* engine_i
 
        return TTS_ERROR_NONE;
 }
+
+int tts_core_handle_service_reset()
+{
+       GList* client_list = tts_client_get_client_list();
+       if (NULL == client_list) {
+               SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to get client list");
+               return TTS_ERROR_OPERATION_FAILED;
+       }
+
+       if (g_list_length(client_list) > 0) {
+               GList *iter = g_list_first(client_list);
+               while (NULL != iter) {
+                       tts_client_s *client = iter->data;
+                       if (false == tts_client_is_valid_client(client)) {
+                               SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Client is not valid");
+                       } else {
+                               tts_core_notify_error_async(client, TTS_ERROR_SERVICE_RESET, -1, "Daemon Reset");
+                       }
+
+                       iter = g_list_next(iter);
+               }
+       }
+
+       g_list_free(client_list);
+
+       SLOG(LOG_WARN, TAG_TTSC, "[WARNING] Service Reset");
+       tts_core_reprepare();
+
+       return TTS_ERROR_NONE;
+}
index b3d95ca1b8e76b1d2b792875a05a479176e5fbc5..ebf3d667aadd5e228303e5a0b023b10bb75b70ec 100644 (file)
@@ -26,8 +26,7 @@ int tts_core_notify_state_changed(tts_client_s* client, tts_state_e before_state
 int tts_core_notify_state_changed_async(tts_client_s* client, tts_state_e before_state, tts_state_e current_state);
 int tts_core_notify_utt_started(tts_client_s* client, int utt_id);
 int tts_core_notify_utt_completeted(tts_client_s* client, int utt_id);
-int tts_core_notify_error(tts_client_s* client, int utt_id, tts_error_e reason);
-int tts_core_notify_error_async(tts_client_s* client, int utt_id, tts_error_e reason);
+int tts_core_notify_error_async(tts_client_s* client, tts_error_e reason, int utt_id, char* err_msg);
 int tts_core_notify_default_voice_changed(tts_client_s* client, const char* before_lang, int before_voice_type, const char* language, int voice_type);
 int tts_core_notify_engine_changed(tts_client_s* client, const char* engine_id, const char* language, int voice_type, bool need_credential);
 
@@ -46,9 +45,9 @@ int tts_core_reprepare();
 
 int tts_core_foreach_supported_voices(tts_client_s* client, const char* engine_id, tts_supported_voice_cb callback, void* user_data);
 
-// called by tts_dbus.c
+// called by tts_ipc
 int tts_core_receive_hello(int uid, int ret, int credential_needed);
-
+int tts_core_handle_service_reset();
 
 #ifdef __cplusplus
 }
index d47a8cef415e05b9e3b53d3bf51caf5e9932e5aa..b14b5c82ddeeab08d2659c9768578687ecf2ad20 100644 (file)
@@ -34,52 +34,6 @@ static Ecore_Fd_Handler* g_dbus_fd_handler = NULL;
 
 static volatile int g_connected_client = 0;
 
-static int __handle_service_reset()
-{
-       GList* client_list = NULL;
-       client_list = tts_client_get_client_list();
-
-       if (NULL == client_list) {
-               SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to get client list");
-               return TTS_ERROR_OPERATION_FAILED;
-       }
-
-       if (g_list_length(client_list) > 0) {
-               GList *iter = g_list_first(client_list);
-               while (NULL != iter) {
-                       tts_client_s *client = iter->data;
-                       if (false == tts_client_is_valid_client(client)) {
-                               SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Client is not valid");
-                       } else {
-                               tts_client_set_error_message(client, "Daemon Reset");
-                               tts_core_notify_error_async(client, -1, TTS_ERROR_SERVICE_RESET);
-                       }
-
-                       iter = g_list_next(iter);
-               }
-       }
-
-       g_list_free(client_list);
-
-       SLOG(LOG_WARN, TAG_TTSC, "[WARNING] Service Reset");
-       tts_core_reprepare();
-
-       return TTS_ERROR_NONE;
-}
-
-static int __handle_service_error(int uid, tts_error_e reason, int utt_id, char* err_msg)
-{
-       tts_client_s* client = tts_client_get_by_uid(uid);
-       if (NULL == client) {
-               SLOG(LOG_WARN, TAG_TTSC, "[WARNING] uid is not valid");
-               return TTS_ERROR_INVALID_PARAMETER;
-       }
-
-       tts_client_set_error_message(client, err_msg);
-       tts_core_notify_error_async(client, utt_id, reason);
-
-       return TTS_ERROR_NONE;
-}
 
 static int __tts_cb_set_state(int uid, int state)
 {
@@ -315,13 +269,13 @@ static Eina_Bool listener_event_callback(void* data, Ecore_Fd_Handler *fd_handle
                                dbus_error_free(&err);
                        } else {
                                SLOG(LOG_ERROR, TAG_TTSC, "<<<< Get Error message : uid(%d), error(%d), uttid(%d), err_msg(%s)", uid, reason, uttid, (NULL == err_msg) ? "NULL" : err_msg);
-                               __handle_service_error(uid, reason, uttid, err_msg);
+                               tts_core_notify_error_async(tts_client_get_by_uid(uid), reason, uttid, err_msg);
                        }
                } /* TTSD_SIGNAL_ERROR */
 
                else if (dbus_message_is_signal(msg, "org.freedesktop.DBus", "NameOwnerChanged")) {
                        SLOG(LOG_DEBUG, TAG_TTSC, "@@@ Owner Changed");
-                       __handle_service_reset();
+                       tts_core_handle_service_reset();
                        SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
                } /* NameOwnerChanged */
 
index 6051fb326a3c64268b17db98f243da57c794064f..c26e1b7f9fcbd080d63bb7295ffac1a11ee815e7 100644 (file)
 
 #define MAXSLEEP 128
 
-static int __handle_service_reset()
-{
-       GList* client_list = NULL;
-       client_list = tts_client_get_client_list();
-
-       if (NULL == client_list) {
-               SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to get client list");
-               return TTS_ERROR_OPERATION_FAILED;
-       }
-
-       if (g_list_length(client_list) > 0) {
-               GList *iter = g_list_first(client_list);
-               while (NULL != iter) {
-                       tts_client_s *client = iter->data;
-                       if (false == tts_client_is_valid_client(client)) {
-                               SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Client is not valid");
-                       } else {
-                               tts_client_set_error_message(client, "Daemon Reset");
-                               tts_core_notify_error_async(client, -1, TTS_ERROR_SERVICE_RESET);
-                       }
-
-                       iter = g_list_next(iter);
-               }
-       }
-
-       g_list_free(client_list);
-
-       SLOG(LOG_WARN, TAG_TTSC, "[WARNING] Service Reset");
-       tts_core_reprepare();
-
-       return TTS_ERROR_NONE;
-}
-
-static int __handle_service_error(int uid, tts_error_e reason, int utt_id, char* err_msg)
-{
-       tts_client_s* client = tts_client_get_by_uid(uid);
-       if (NULL == client) {
-               SLOG(LOG_WARN, TAG_TTSC, "[WARNING] uid is not valid");
-               return TTS_ERROR_INVALID_PARAMETER;
-       }
-
-       tts_client_set_error_message(client, err_msg);
-       tts_core_notify_error_async(client, utt_id, reason);
-
-       return TTS_ERROR_NONE;
-}
 
 static int __tts_cb_set_state(int uid, int state)
 {
@@ -179,7 +133,7 @@ static void __notify_cb(void *user_data, int pid, int uid, bundle *msg)
                bundle_get_str(msg, TTS_BUNDLE_UTTID, &uttid);
                bundle_get_str(msg, TTS_BUNDLE_ERR_MSG, &err_msg);
                if (reason && uttid) {
-                       __handle_service_error(uid, atoi(reason), atoi(uttid), err_msg);
+                       tts_core_notify_error_async(client, atoi(reason), atoi(uttid), err_msg);
                }
        }
        else {
@@ -230,7 +184,7 @@ static void __on_disconnected(rpc_port_proxy_tts_h h, void *user_data)
 
        tts->connected = false;
        if (tts_client_is_listening_started(uid)) {
-               __handle_service_reset();
+               tts_core_handle_service_reset();
                SLOG(LOG_DEBUG, TAG_TTSC, "Disconnected from server");
 
                ecore_main_loop_thread_safe_call_async(__reconnect, (void*)uid);
@@ -245,7 +199,7 @@ static void __on_rejected(rpc_port_proxy_tts_h h, void *user_data)
        if (!client)
                return;
 
-       __handle_service_error(uid, TTS_ERROR_PERMISSION_DENIED, client->utt_id, "Rejected");
+       tts_core_notify_error_async(client, TTS_ERROR_PERMISSION_DENIED, client->utt_id, "Rejected");
        SLOG(LOG_DEBUG, TAG_TTSC, "Rejected from server");
 }