Move retry connection logic to a timer function 93/221793/2
authorJi-hoon Lee <dalton.lee@samsung.com>
Tue, 7 Jan 2020 12:06:47 +0000 (21:06 +0900)
committerJi-hoon Lee <dalton.lee@samsung.com>
Tue, 7 Jan 2020 12:12:06 +0000 (21:12 +0900)
Change-Id: Ia0c11d65eb3afa7c089e9c5cf3c71f804828d541

client/ma.c
client/ma_dbus.c

index 46ecc05482794905aaaf2bc0e1a14793dd20c4ac..673d2828af81beba6843901149c0c27f588378ab 100644 (file)
@@ -384,48 +384,45 @@ static Eina_Bool __ma_connect_daemon(void *data)
        return EINA_FALSE;
 }
 
-static void __start_prepare_func()
+static Ecore_Timer* g_retry_connection_timer = NULL;
+static int g_retry_connection_count = 0;
+static Eina_Bool retry_connection(void* data)
 {
-       MA_SLOGE("[DEBUG] Start prepare func");
-       int ret = -1;
-       int retry_count = 0;
-
-       /* Send hello */
-       while (0 != ret) {
-               if (retry_count == 100) {
-                       MA_SLOGE("[ERROR] Fail to request hello !!"); //LCOV_EXCL_LINE
-                       return;
-               }
-
-               ret = ma_dbus_request_hello();
-               if (ret == 0) {
-                       MA_SLOGD("Success to request hello. retry count(%d)", retry_count);
-                       break;
-               } else {
-                       usleep(300000);
-                       retry_count++;
+       int ret = ma_dbus_request_hello();
+       if (ret == 0) {
+               MA_SLOGD("Success to request hello. retry count(%d)", g_retry_connection_count);
+               g_retry_connection_count = 0;
+               if (g_retry_connection_timer) ecore_timer_del(g_retry_connection_timer);
+               g_retry_connection_timer = NULL;
+
+               ret = -1;
+               int retry_count = 0;
+
+               while (0 != ret) {
+                       if (retry_count == 10) {
+                               MA_SLOGE("[ERROR] Fail to connect daemon !!"); //LCOV_EXCL_LINE
+                               break;
+                       }
+                       ret = __ma_connect_daemon(NULL);
+                       if (ret == 0) {
+                               MA_SLOGD("Success to connect daemon. retry count(%d)", retry_count);
+                               break;
+                       } else {
+                               usleep(10000);
+                               retry_count++;
+                       }
                }
+               return ECORE_CALLBACK_CANCEL;
        }
+       g_retry_connection_count++;
+       return ECORE_CALLBACK_RENEW;
+}
 
-       ret = -1;
-       retry_count = 0;
-
-       while (0 != ret) {
-               if (retry_count == 10) {
-                       MA_SLOGE("[ERROR] Fail to connect daemon !!"); //LCOV_EXCL_LINE
-                       return;
-               }
-               ret = __ma_connect_daemon(NULL);
-               if (ret == 0) {
-                       MA_SLOGD("Success to connect daemon. retry count(%d)", retry_count);
-                       break;
-               } else {
-                       usleep(10000);
-                       retry_count++;
-               }
+static void __start_prepare_func()
+{
+       if (ECORE_CALLBACK_RENEW == retry_connection(NULL)) {
+               ecore_timer_add(1.5f, retry_connection, NULL);
        }
-
-       return;
 }
 
 static void __end_prepare_func()
@@ -476,6 +473,9 @@ int ma_unprepare(void)
 
        MA_SLOGI("[Client DEBUG] Unprepare");
 
+       if (g_retry_connection_timer) ecore_timer_del(g_retry_connection_timer);
+       g_retry_connection_timer = NULL;
+
        ma_state_e state;
 
        if (0 != ma_client_get_client_state(g_ma, &state)) {
index 128b945e80dd0566294a07d8fb61059c7d68209e..8e6c9ad51f86e12e9c19b6792e91d4e0fea25937 100644 (file)
@@ -652,7 +652,7 @@ int ma_dbus_request_hello()
        DBusMessage* result_msg = NULL;
        int result = 0;
 
-       result_msg = dbus_connection_send_with_reply_and_block(g_conn_sender, msg, -1, &err);
+       result_msg = dbus_connection_send_with_reply_and_block(g_conn_sender, msg, 1000, &err);
 
        if (dbus_error_is_set(&err)) {
                MA_SLOGE("[ERROR] Dbus Error (%s)", err.message); //LCOV_EXCL_LINE