Extract codes to check retrying dbus request 51/277751/1
authorwn.jang <wn.jang@samsung.com>
Wed, 13 Jul 2022 01:08:47 +0000 (10:08 +0900)
committerwn.jang <wn.jang@samsung.com>
Wed, 13 Jul 2022 01:08:47 +0000 (10:08 +0900)
Change-Id: I98b4b6348f974c82f87dc61f601143730f4b32e5

client/stt.c

index a5afb3e..cf182a9 100644 (file)
@@ -735,6 +735,22 @@ int stt_set_credential(stt_h stt, const char* credential)
        return STT_ERROR_NONE;
 }
 
+static bool __stt_is_necessary_to_retry_dbus_request(int count, int return_value)
+{
+       bool ret = true;
+       if (STT_ERROR_TIMED_OUT != return_value) {
+               ret = false;
+       } else {
+               SLOG(LOG_WARN, TAG_STTC, "[WARNING][%d] retry : %s", count, __stt_get_error_code(ret));
+               usleep(10000);
+               if (STT_RETRY_COUNT == count) {
+                       SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to request");
+                       ret = false;
+               }
+       }
+       return ret;
+}
+
 int stt_set_private_data(stt_h stt, const char* key, const char* data)
 {
        stt_client_s* client = NULL;
@@ -756,18 +772,11 @@ int stt_set_private_data(stt_h stt, const char* key, const char* data)
                ret = stt_dbus_request_set_private_data(client->uid, key, data);
                if (0 != ret) {
                        //LCOV_EXCL_START
-                       if (STT_ERROR_TIMED_OUT != ret) {
+                       if (false == __stt_is_necessary_to_retry_dbus_request(count, ret)) {
                                SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to set private data : %s", __stt_get_error_code(ret));
                                return ret;
-                       } else {
-                               SLOG(LOG_WARN, TAG_STTC, "[WARNING] retry : %s", __stt_get_error_code(ret));
-                               usleep(10000);
-                               count++;
-                               if (STT_RETRY_COUNT == count) {
-                                       SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to request");
-                                       return ret;
-                               }
                        }
+                       count++;
                        //LCOV_EXCL_STOP
                }
        }
@@ -794,18 +803,11 @@ int stt_get_private_data(stt_h stt, const char* key, char** data)
                ret = stt_dbus_request_get_private_data(client->uid, key, data);
                if (0 != ret) {
                        //LCOV_EXCL_START
-                       if (STT_ERROR_TIMED_OUT != ret) {
+                       if (false == __stt_is_necessary_to_retry_dbus_request(count, ret)) {
                                SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to get private data : %s", __stt_get_error_code(ret));
                                return ret;
-                       } else {
-                               SLOG(LOG_WARN, TAG_STTC, "[WARNING] retry : %s", __stt_get_error_code(ret));
-                               usleep(10000);
-                               count++;
-                               if (STT_RETRY_COUNT == count) {
-                                       SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to request");
-                                       return ret;
-                               }
                        }
+                       count++;
                        //LCOV_EXCL_STOP
                }
        }
@@ -950,18 +952,11 @@ static Eina_Bool __stt_connect_daemon(void *data)
                while (0 != ret) {
                        ret = stt_dbus_request_set_current_engine(client->uid, client->current_engine_id, &silence_supported, &credential_needed);
                        if (0 != ret) {
-                               if (STT_ERROR_TIMED_OUT != ret) {
+                               if (false == __stt_is_necessary_to_retry_dbus_request(count, ret)) {
                                        SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to set current engine : %s", __stt_get_error_code(ret));
                                        return ret;
-                               } else {
-                                       SLOG(LOG_WARN, TAG_STTC, "[WARNING] retry");
-                                       usleep(10000);
-                                       count++;
-                                       if (STT_RETRY_COUNT == count) {
-                                               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to request");
-                                               return ret;
-                                       }
                                }
+                               count++;
                        } else {
                                SLOG(LOG_DEBUG, TAG_STTC, "[SUCCESS] Current engine uuid = %s", client->current_engine_id);
 
@@ -1237,18 +1232,11 @@ int stt_is_recognition_type_supported(stt_h stt, const char* type, bool* support
                ret = stt_dbus_request_is_recognition_type_supported(client->uid, type, support);
                if (0 != ret) {
                        //LCOV_EXCL_START
-                       if (STT_ERROR_TIMED_OUT != ret) {
+                       if (false == __stt_is_necessary_to_retry_dbus_request(count, ret)) {
                                SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to get recognition type supported : %s", __stt_get_error_code(ret));
                                return ret;
-                       } else {
-                               SLOG(LOG_WARN, TAG_STTC, "[WARNING] retry");
-                               usleep(10000);
-                               count++;
-                               if (STT_RETRY_COUNT == count) {
-                                       SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to request");
-                                       return ret;
-                               }
                        }
+                       count++;
                        //LCOV_EXCL_STOP
                } else {
                        SLOG(LOG_INFO, TAG_STTC, "[SUCCESS] recognition type is %s", *support ? "true " : "false");
@@ -1301,18 +1289,11 @@ int stt_set_start_sound(stt_h stt, const char* filename)
                ret = stt_dbus_request_set_start_sound(client->uid, filename);
                if (0 != ret) {
                        //LCOV_EXCL_START
-                       if (STT_ERROR_TIMED_OUT != ret) {
+                       if (false == __stt_is_necessary_to_retry_dbus_request(count, ret)) {
                                SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to set start sound : %s", __stt_get_error_code(ret));
                                return ret;
-                       } else {
-                               SLOG(LOG_WARN, TAG_STTC, "[WARNING] retry");
-                               usleep(10000);
-                               count++;
-                               if (STT_RETRY_COUNT == count) {
-                                       SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to request");
-                                       return ret;
-                               }
                        }
+                       count++;
                        //LCOV_EXCL_STOP
                } else {
                        SLOG(LOG_INFO, TAG_STTC, "[SUCCESS] Set start sound : %s", filename);
@@ -1338,18 +1319,11 @@ int stt_unset_start_sound(stt_h stt)
                ret = stt_dbus_request_unset_start_sound(client->uid);
                if (0 != ret) {
                        //LCOV_EXCL_START
-                       if (STT_ERROR_TIMED_OUT != ret) {
+                       if (false == __stt_is_necessary_to_retry_dbus_request(count, ret)) {
                                SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to unset start sound : %s", __stt_get_error_code(ret));
                                return ret;
-                       } else {
-                               SLOG(LOG_WARN, TAG_STTC, "[WARNING] retry");
-                               usleep(10000);
-                               count++;
-                               if (STT_RETRY_COUNT == count) {
-                                       SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to request");
-                                       return ret;
-                               }
                        }
+                       count++;
                        //LCOV_EXCL_STOP
                } else {
                        SLOG(LOG_INFO, TAG_STTC, "[SUCCESS] Unset start sound");
@@ -1378,18 +1352,11 @@ int stt_set_stop_sound(stt_h stt, const char* filename)
                ret = stt_dbus_request_set_stop_sound(client->uid, filename);
                if (0 != ret) {
                        //LCOV_EXCL_START
-                       if (STT_ERROR_TIMED_OUT != ret) {
+                       if (false == __stt_is_necessary_to_retry_dbus_request(count, ret)) {
                                SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to set stop sound : %s", __stt_get_error_code(ret));
                                return ret;
-                       } else {
-                               SLOG(LOG_WARN, TAG_STTC, "[WARNING] retry");
-                               usleep(10000);
-                               count++;
-                               if (STT_RETRY_COUNT == count) {
-                                       SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to request");
-                                       return ret;
-                               }
                        }
+                       count++;
                        //LCOV_EXCL_STOP
                } else {
                        SLOG(LOG_INFO, TAG_STTC, "[SUCCESS] Set stop sound : %s", filename);
@@ -1415,18 +1382,11 @@ int stt_unset_stop_sound(stt_h stt)
                ret = stt_dbus_request_unset_stop_sound(client->uid);
                if (0 != ret) {
                        //LCOV_EXCL_START
-                       if (STT_ERROR_TIMED_OUT != ret) {
+                       if (false == __stt_is_necessary_to_retry_dbus_request(count, ret)) {
                                SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to unset stop sound : %s", __stt_get_error_code(ret));
                                return ret;
-                       } else {
-                               SLOG(LOG_WARN, TAG_STTC, "[WARNING] retry");
-                               usleep(10000);
-                               count++;
-                               if (STT_RETRY_COUNT == count) {
-                                       SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to request");
-                                       return ret;
-                               }
                        }
+                       count++;
                        //LCOV_EXCL_STOP
                } else {
                        SLOG(LOG_INFO, TAG_STTC, "[SUCCESS] Unset stop sound");