Fix loop statement from 'while' to 'for' 13/257113/2
authorSuyeon Hwang <stom.hwang@samsung.com>
Mon, 21 Dec 2020 11:47:13 +0000 (20:47 +0900)
committerSuyeon Hwang <stom.hwang@samsung.com>
Thu, 27 May 2021 04:45:11 +0000 (13:45 +0900)
Change-Id: I2f42eb7943d6ddd2c56e75eb91eb5e913fe344d3
Signed-off-by: Suyeon Hwang <stom.hwang@samsung.com>
client/tts_core.c

index 77b88604b672eedba6da07039abfa75bef127e72..5df2cbe76f1872bc3e5cb7dd64c61d0cb2b4fcab 100644 (file)
@@ -652,17 +652,15 @@ static inline int __request_add_text(tts_client_s* client, const char* text, con
                return TTS_ERROR_OPERATION_FAILED;
        }
 
+       // TODO: If use cpp, remove dupliceated code using command class pattern
        int uid = tts_client_get_uid(client);
        int ret = -1;
-       int count = 0;
        bool is_prepared = false;
-       while (TTS_RETRY_COUNT > count) {
+       for (int count = 0; count < TTS_RETRY_COUNT; count++) {
                ret = tts_ipc_request_add_text(uid, text, convert_language, voice_type, speed, new_utt_id, client->credential);
                if (false == __handle_dbus_request_result(client, ret, &is_prepared)) {
                        break;
                }
-
-               count++;
        }
 
        if (TTS_ERROR_NONE != ret) {
@@ -679,15 +677,12 @@ static inline int __request_play(tts_client_s* client)
 {
        int uid = tts_client_get_uid(client);
        int ret = -1;
-       int count = 0;
        bool is_prepared = false;
-       while (TTS_RETRY_COUNT > count) {
+       for (int count = 0; count < TTS_RETRY_COUNT; count++) {
                ret = tts_ipc_request_play(uid, client->credential);
                if (false == __handle_dbus_request_result(client, ret, &is_prepared)) {
                        break;
                }
-
-               count++;
        }
 
        if (TTS_ERROR_NONE != ret) {
@@ -699,7 +694,6 @@ static inline int __request_play(tts_client_s* client)
        return tts_core_set_current_state(client, TTS_STATE_PLAYING);
 }
 
-/* Public functions */
 int tts_core_initialize()
 {
        ecore_main_loop_thread_safe_call_async(__pkgmgr_thread, NULL);
@@ -1120,7 +1114,6 @@ int tts_core_unprepare(tts_client_s* client)
        SLOG(LOG_INFO, TAG_TTSC, "[INFO] screen_reader(%s), mode(%d)", (true == g_is_screen_reader_on) ? "True" : "False", mode);
 
        int ret = -1;
-       int count = 0;
        if (false == g_is_screen_reader_on && TTS_MODE_SCREEN_READER == mode) {
                SLOG(LOG_WARN, TAG_TTSC, "[WARNING] Do not request finalize : is_screen_reader(%d) mode(%d)", g_is_screen_reader_on, mode);
 
@@ -1130,14 +1123,11 @@ int tts_core_unprepare(tts_client_s* client)
                }
        } else {
                bool is_prepared = false;
-
-               while(TTS_RETRY_COUNT > count) {
+               for (int count = 0; count < TTS_RETRY_COUNT; count++) {
                        ret = tts_ipc_request_finalize(uid);
                        if (false == __handle_dbus_request_result(client, ret, &is_prepared)) {
                                break;
                        }
-
-                       count++;
                }
 
                if (TTS_ERROR_NONE == ret) {
@@ -1298,16 +1288,13 @@ int tts_core_pause(tts_client_s* client)
        }
 
        int uid = tts_client_get_uid(client);
-       int ret = 0;
-       int count = 0;
+       int ret = -1;
        bool is_prepared = false;
-       while (TTS_RETRY_COUNT > count) {
+       for (int count = 0; count < TTS_RETRY_COUNT; count++) {
                ret = tts_ipc_request_pause(uid);
                if (false == __handle_dbus_request_result(client, ret, &is_prepared)) {
                        break;
                }
-
-               count++;
        }
 
        if (TTS_ERROR_NONE != ret) {
@@ -1366,16 +1353,13 @@ int tts_core_add_pcm(tts_client_s* client, int event, const void* data, unsigned
        }
 
        int uid = tts_client_get_uid(client);
-       int ret = 0;
-       int count = 0;
+       int ret = -1;
        bool is_prepared = false;
-       while (TTS_RETRY_COUNT > count) {
+       for (int count = 0; count < TTS_RETRY_COUNT; count++) {
                ret = tts_ipc_request_add_pcm(uid, event, data, data_size, audio_type, rate);
                if (false == __handle_dbus_request_result(client, ret, &is_prepared)) {
                        break;
                }
-
-               count++;
        }
 
        if (TTS_ERROR_NONE != ret) {
@@ -1395,16 +1379,13 @@ int tts_core_play_pcm(tts_client_s* client)
        }
 
        int uid = tts_client_get_uid(client);
-       int ret = 0;
-       int count = 0;
+       int ret = -1;
        bool is_prepared = false;
-       while (TTS_RETRY_COUNT > count) {
+       for (int count = 0; count < TTS_RETRY_COUNT; count++) {
                ret = tts_ipc_request_play_pcm(uid);
                if (false == __handle_dbus_request_result(client, ret, &is_prepared)) {
                        break;
                }
-
-               count++;
        }
 
        if (TTS_ERROR_NONE != ret) {
@@ -1424,16 +1405,13 @@ int tts_core_stop_pcm(tts_client_s* client)
        }
 
        int uid = tts_client_get_uid(client);
-       int ret = 0;
-       int count = 0;
+       int ret = -1;
        bool is_prepared = false;
-       while (TTS_RETRY_COUNT > count) {
+       for (int count = 0; count < TTS_RETRY_COUNT; count++) {
                ret = tts_ipc_request_stop_pcm(uid);
                if (false == __handle_dbus_request_result(client, ret, &is_prepared)) {
                        break;
                }
-
-               count++;
        }
 
        if (TTS_ERROR_NONE != ret) {
@@ -1454,15 +1432,12 @@ int tts_core_set_private_data(tts_client_s* client, const char* key, const char*
 
        int uid = tts_client_get_uid(client);
        int ret = -1;
-       int count = 0;
        bool is_prepared = false;
-       while (TTS_RETRY_COUNT > count) {
+       for (int count = 0; count < TTS_RETRY_COUNT; count++) {
                ret = tts_ipc_request_set_private_data(uid, key, data);
                if (false == __handle_dbus_request_result(client, ret, &is_prepared)) {
                        break;
                }
-
-               count++;
        }
 
        if (TTS_ERROR_NONE != ret) {
@@ -1483,15 +1458,12 @@ int tts_core_get_private_data(tts_client_s* client, const char* key, char** data
 
        int uid = tts_client_get_uid(client);
        int ret = -1;
-       int count = 0;
        bool is_prepared = false;
-       while (TTS_RETRY_COUNT > count) {
+       for (int count = 0; count < TTS_RETRY_COUNT; count++) {
                ret = tts_ipc_request_get_private_data(uid, key, data);
                if (false == __handle_dbus_request_result(client, ret, &is_prepared)) {
                        break;
                }
-
-               count++;
        }
 
        if (TTS_ERROR_NONE != ret) {