Clean up the code and mark the future task 10/257110/2
authorSuyeon Hwang <stom.hwang@samsung.com>
Fri, 27 Nov 2020 05:19:37 +0000 (14:19 +0900)
committerSuyeon Hwang <stom.hwang@samsung.com>
Thu, 27 May 2021 04:45:11 +0000 (13:45 +0900)
This patch includes next changes
- Remove unused variables.
- Remove not necessary check code.
- Add missing code for finalization.
- Add missing const keyword.

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

index b14dff4a0c37d49a2d3e697e53c37989d8c2d3a1..59bb04f4df881b1ce1755b42effcc2e433619df6 100644 (file)
@@ -34,8 +34,6 @@
 
 static int g_feature_enabled = -1;
 
-static int g_max_text_size = -1;
-
 
 static int __tts_get_feature_enabled()
 {
@@ -103,34 +101,33 @@ static int __tts_convert_config_error_code(tts_config_error_e code)
 }
 
 //LCOV_EXCL_START
-void __tts_config_voice_changed_cb(const char* before_lang, int before_voice_type, const char* language, int voice_type, bool auto_voice, void* user_data)
+static void __tts_config_voice_changed_cb(const char* before_lang, int before_voice_type, const char* language, int voice_type, bool auto_voice, void* user_data)
 {
        SLOG(LOG_DEBUG, TAG_TTSC, "Voice changed : Before lang(%s) type(%d) , Current lang(%s), type(%d)",
                before_lang, before_voice_type, language, voice_type);
 
-       GList* client_list = NULL;
-       client_list = tts_client_get_client_list();
-
+       GList* client_list = tts_client_get_client_list();
        if (NULL == client_list) {
                SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to get client list");
                return;
        }
 
        GList *iter = NULL;
-       tts_client_s *data = NULL;
-
        if (g_list_length(client_list) > 0) {
                /* Get a first item */
                iter = g_list_first(client_list);
 
                while (NULL != iter) {
-                       data = iter->data;
-                       // TODO: add client validation check code
-                       tts_core_notify_default_voice_changed(data, before_lang, before_voice_type, language, voice_type);
+                       tts_client_s *client = iter->data;
+                       if (tts_client_is_valid_client(client)) {
+                               tts_core_notify_default_voice_changed(client, before_lang, before_voice_type, language, voice_type);
 
-                       /* Check whether language is changed or not. If it is changed, make 'text_repeat' NULL */
-                       if (0 != strncmp(before_lang, language, strlen(before_lang))) {
-                               tts_client_set_repeat_text(data, NULL);
+                               /* Check whether language is changed or not. If it is changed, make 'text_repeat' NULL */
+                               if (0 != strncmp(before_lang, language, strlen(before_lang))) {
+                                       tts_client_set_repeat_text(client, NULL);
+                               }
+                       } else {
+                               SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Client is not valid (%p)", client);
                        }
 
                        /* Next item */
@@ -159,6 +156,7 @@ static Eina_Bool __reconnect_by_engine_changed(void* data)
                return EINA_TRUE;
        }
 
+       // TODO: change to tts_core function
        int ret = tts_unprepare(tts);
        if (0 != ret) {
                SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to prepare for setting a new engine... (%d)", ret);
@@ -171,7 +169,7 @@ static Eina_Bool __reconnect_by_engine_changed(void* data)
        return EINA_FALSE;
 }
 
-void _tts_config_engine_changed_cb(const char* engine_id, const char* setting, const char* language, int voice_type, bool auto_voice, bool need_credential, void* user_data)
+static void __tts_config_engine_changed_cb(const char* engine_id, const char* setting, const char* language, int voice_type, bool auto_voice, bool need_credential, void* user_data)
 {
        tts_h tts = (tts_h)user_data;
 
@@ -198,6 +196,7 @@ void _tts_config_engine_changed_cb(const char* engine_id, const char* setting, c
 
                ecore_idler_add(__reconnect_by_engine_changed, (void*)tts);
        } else if (TTS_STATE_READY == current_state) {
+               // TODO: change to tts_core function
                ret = tts_unprepare(tts);
                if (0 != ret) {
                        SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to unprepare for setting a new engine... (%d)", ret);
@@ -276,9 +275,10 @@ int tts_create(tts_h* tts)
                return __tts_convert_config_error_code(ret);
        }
 
-       ret = tts_config_mgr_set_callback(uid, _tts_config_engine_changed_cb, __tts_config_voice_changed_cb, NULL, NULL, NULL, tts);
+       ret = tts_config_mgr_set_callback(uid, __tts_config_engine_changed_cb, __tts_config_voice_changed_cb, NULL, NULL, NULL, tts);
        if (0 != ret) {
                SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to set config changed : %d", ret);
+               tts_config_mgr_finalize(uid);
                tts_client_destroy(*tts);
                return __tts_convert_config_error_code(ret);
        }
@@ -287,6 +287,7 @@ int tts_create(tts_h* tts)
                // These function would be called only when first client is created.
                if (0 != tts_core_initialize()) {
                        SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to initialize core");
+                       tts_config_mgr_finalize(uid);
                        tts_client_destroy(*tts);
                        return TTS_ERROR_OPERATION_FAILED;
                }
@@ -327,13 +328,7 @@ int tts_destroy(tts_h tts)
                client->hello_timer = NULL;
        }
 
-       tts_state_e current_state = tts_client_get_current_state(client);
-       if (TTS_STATE_INVALID == current_state) {
-               SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Client is not valid");
-               return TTS_ERROR_INVALID_PARAMETER;
-       }
-
-       switch (current_state) {
+       switch (tts_client_get_current_state(client)) {
        case TTS_STATE_PAUSED:
        case TTS_STATE_PLAYING:
        case TTS_STATE_READY:
@@ -367,9 +362,9 @@ int tts_destroy(tts_h tts)
                tts_client_destroy(tts);
 
                break;
-
        default:
-               break;
+               SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Client is not valid");
+               return TTS_ERROR_INVALID_PARAMETER;
        }
 
        int num_of_client = tts_client_get_size();
@@ -382,7 +377,6 @@ int tts_destroy(tts_h tts)
        }
 
        SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
-
        return TTS_ERROR_NONE;
 }
 
@@ -418,7 +412,6 @@ int tts_set_mode(tts_h tts, tts_mode_e mode)
        }
 
        SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
-
        return TTS_ERROR_NONE;
 }
 
@@ -476,6 +469,7 @@ int tts_set_credential(tts_h tts, const char* credential)
                return TTS_ERROR_INVALID_STATE;
        }
 
+       // TODO: move into tts_client
        if (NULL != client->credential) {
                free(client->credential);
                client->credential = NULL;
@@ -505,11 +499,13 @@ int tts_set_server_tts(tts_h tts, const char* credential)
                return TTS_ERROR_INVALID_STATE;
        }
 
+       // TODO: move into tts_client
        if (NULL != client->credential) {
                free(client->credential);
                client->credential = NULL;
        }
 
+       // TODO: fix name more clear and move into tts_client
        client->internal = true;
 
        char* key = NULL;
@@ -686,18 +682,15 @@ int tts_foreach_supported_voices(tts_h tts, tts_supported_voice_cb callback, voi
        }
 
        ret = tts_core_foreach_supported_voices(client, current_engine, callback, user_data);
-
-       if (NULL != current_engine) {
-               free(current_engine);
-               current_engine = NULL;
-       }
+       free(current_engine);
 
        if (0 != ret) {
                SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Result : %d", ret);
+               return ret;
        }
 
        SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
-       return ret;
+       return TTS_ERROR_NONE;
 }
 
 int tts_get_default_voice(tts_h tts, char** lang, int* vctype)
@@ -725,13 +718,11 @@ int tts_get_default_voice(tts_h tts, char** lang, int* vctype)
        if (0 != ret) {
                SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] result : %d", ret);
                return __tts_convert_config_error_code(ret);
-       } else {
-               SLOG(LOG_DEBUG, TAG_TTSC, "[DEBUG] Default language(%s), type(%d)", *lang, *vctype);
        }
 
+       SLOG(LOG_DEBUG, TAG_TTSC, "[DEBUG] Default language(%s), type(%d)", *lang, *vctype);
        SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
-
-       return ret;
+       return TTS_ERROR_NONE;
 }
 
 int tts_get_max_text_size(tts_h tts, unsigned int* size)
@@ -762,9 +753,8 @@ int tts_get_max_text_size(tts_h tts, unsigned int* size)
                return TTS_ERROR_OPERATION_FAILED;
        }
 
-       g_max_text_size = (int)*size;
-
        SLOG(LOG_INFO, TAG_TTSC, "Get max text size : %d byte", *size);
+       SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
        return TTS_ERROR_NONE;
 }
 
@@ -786,20 +776,17 @@ int tts_get_state(tts_h tts, tts_state_e* state)
        }
 
        tts_state_e current_state = tts_client_get_current_state(client);
-       if (TTS_STATE_INVALID == current_state) {
-               SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] client is invalid");
-               return TTS_ERROR_INVALID_PARAMETER;
-       }
-
        switch (current_state) {
        case TTS_STATE_CREATED: SLOG(LOG_INFO, TAG_TTSC, "Current state is 'Created'"); break;
        case TTS_STATE_READY:   SLOG(LOG_INFO, TAG_TTSC, "Current state is 'Ready'");   break;
        case TTS_STATE_PLAYING: SLOG(LOG_INFO, TAG_TTSC, "Current state is 'Playing'"); break;
        case TTS_STATE_PAUSED:  SLOG(LOG_INFO, TAG_TTSC, "Current state is 'Paused'");  break;
+       default:
+               SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Client is not valid");
+               return TTS_ERROR_INVALID_PARAMETER;
        }
 
        *state = current_state;
-
        return TTS_ERROR_NONE;
 }
 
@@ -914,7 +901,7 @@ int tts_add_text(tts_h tts, const char* text, const char* language, int voice_ty
        }
 
        SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
-       return ret;
+       return TTS_ERROR_NONE;
 }
 
 //LCOV_EXCL_START
@@ -1224,6 +1211,7 @@ int tts_set_private_data(tts_h tts, const char* key, const char* data)
                return TTS_ERROR_INVALID_PARAMETER;
        }
 
+       // TODO: move into tts_core
        int uid = tts_client_get_uid(client);
        int ret = -1;
        int count = 0;
@@ -1255,7 +1243,6 @@ int tts_set_private_data(tts_h tts, const char* key, const char* data)
        }
 
        SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
-
        return 0;
 }
 
@@ -1284,6 +1271,7 @@ int tts_get_private_data(tts_h tts, const char* key, char** data)
                return TTS_ERROR_INVALID_STATE;
        }
 
+       // TODO: move into tts_core
        int uid = tts_client_get_uid(client);
        int ret = -1;
        int count = 0;
@@ -1320,7 +1308,6 @@ int tts_get_private_data(tts_h tts, const char* key, char** data)
        }
 
        SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
-
        return 0;
 }
 
index ec2e6f2bc6662315d6280e458427f4a8b62a1484..0a688fe4e1d5b80daf167a8784ca0bb8c0ad1bc9 100644 (file)
@@ -200,36 +200,32 @@ static bool __is_engine_installed(const char* appid)
        return true;
 }
 
-static bool __is_engine_launched(int mode)
+static bool __is_engine_launched(tts_mode_e mode)
 {
-       int ret = -1;
-       bool is_installed = false;
-       bool is_running = false;
-
        char* appid = __get_engine_appid(mode);
        if (NULL == appid) {
                SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to get engine app ID");
                return false;
        }
 
-       is_installed = __is_engine_installed(appid);
+       bool is_installed = __is_engine_installed(appid);
        if (false == is_installed) {
                SLOG(LOG_WARN, TAG_TTSC, "[WARNING] tts engine(%s) is not installed", appid);
                free(appid);
                return false;
        }
 
-       ret = app_manager_is_running(appid, &is_running);
+       bool is_running = false;
+       int ret = app_manager_is_running(appid, &is_running);
        if (APP_MANAGER_ERROR_NONE != ret) {
                SLOG(LOG_WARN, TAG_TTSC, "[WARNING] Fail to check whether appid(%s) is running or not. ret(%d)", appid, ret);
                SLOG(LOG_INFO, TAG_TTSC, "[INFO] tts engine is installed(%d)", is_installed);
                free(appid);
                return false;
-       } else {
-               SLOG(LOG_INFO, TAG_TTSC, "[INFO] tts engine is %s running. is_installed(%d)", (is_running) ? "" : " not", is_installed);
        }
 
        free(appid);
+       SLOG(LOG_INFO, TAG_TTSC, "[INFO] tts engine is %s running. is_installed(%d)", (is_running) ? "" : " not", is_installed);
        return is_running;
 }
 
@@ -351,7 +347,7 @@ static void __pkgmgr_thread(void* data)
                g_pkgmgr_thread = ecore_thread_run(__create_pkgmgr_thread, __finish_pkgmgr_thread, __cancel_pkgmgr_thread, NULL);
        }
 
-       return ;
+       return;
 }
 
 static void __start_reprepare_thread(void* data, Ecore_Thread* thread)
@@ -437,11 +433,6 @@ static inline void __run_client_reprepare_thread()
 
 static int __send_hello_msg(tts_client_s* client)
 {
-       if (NULL == client) {
-               SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] A handle is not valid");
-               return TTS_ERROR_INVALID_PARAMETER;
-       }
-
        tts_state_e current_state = tts_client_get_current_state(client);
        if (TTS_STATE_READY == current_state) {
                SLOG(LOG_INFO, TAG_TTSC, "[INFO] TTS client has been already connected to tts service"); //LCOV_EXCL_LINE
@@ -464,9 +455,7 @@ static int __send_hello_msg(tts_client_s* client)
                }
        }
 
-       /* Send hello */
-       int ret = tts_ipc_request_hello(uid);
-       if (0 != ret) {
+       if (0 != tts_ipc_request_hello(uid)) {
                SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to request hello !!"); //LCOV_EXCL_LINE
        } else {
                SLOG(LOG_INFO, TAG_TTSC, "@@@ Send Hello");
@@ -479,7 +468,6 @@ static Eina_Bool __prepare_cb(void *data)
 {
        int uid = (int)data;
        tts_client_s* client = tts_client_get_by_uid(uid);
-
        if (NULL == client) {
                SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Handle is not valid.");
                return EINA_FALSE;
@@ -511,7 +499,6 @@ static Eina_Bool __prepare_first_cb(void *data)
        /* send first hello message */
        int uid = (int)data;
        tts_client_s* client = tts_client_get_by_uid(uid);
-
        if (NULL == client) {
                SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Handle is not valid.");
                return EINA_FALSE;
@@ -602,11 +589,12 @@ static bool __supported_voice_cb(const char* engine_id, const char* language, in
        tts_supported_voice_cb callback = tts_client_get_supported_voice_cb(client);
        void* data = tts_client_get_supported_voice_user_data(client);
 
-       if (NULL != callback) {
-               return callback(tts_client_get_handle(client), language, type, data);
+       if (NULL == callback) {
+               SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to get callback.");
+               return false;
        }
 
-       return false;
+       return callback(tts_client_get_handle(client), language, type, data);
 }
 
 static int __update_screen_reader_state()
@@ -844,7 +832,7 @@ int tts_core_notify_utt_completeted(tts_client_s* client, int utt_id)
        return TTS_ERROR_NONE;
 }
 
-int tts_core_notify_error_async(tts_client_s* client, tts_error_e reason, int utt_id, char* err_msg)
+int tts_core_notify_error_async(tts_client_s* client, tts_error_e reason, int utt_id, const char* err_msg)
 {
        if (false == tts_client_is_valid_client(client)) {
                SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Handle is not valid.");
index af3fdc5d348347ff9b97c453f70cf45fe5ae1405..64a278fd356c2e3ba994cc69b6fc4bfff5c966d6 100644 (file)
@@ -26,7 +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_async(tts_client_s* client, tts_error_e reason, int utt_id, char* err_msg);
+int tts_core_notify_error_async(tts_client_s* client, tts_error_e reason, int utt_id, const 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);