From: Ji-hoon Lee Date: Tue, 7 Jan 2020 12:06:47 +0000 (+0900) Subject: Move retry connection logic to a timer function X-Git-Tag: submit/tizen/20200113.120709^2~4 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=06953cdd6ac50c354375dadc671bac9311cbca94;p=platform%2Fcore%2Fuifw%2Fmulti-assistant.git Move retry connection logic to a timer function Change-Id: Ia0c11d65eb3afa7c089e9c5cf3c71f804828d541 --- diff --git a/client/ma.c b/client/ma.c index 46ecc05..673d282 100644 --- a/client/ma.c +++ b/client/ma.c @@ -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)) { diff --git a/client/ma_dbus.c b/client/ma_dbus.c index 128b945..8e6c9ad 100644 --- a/client/ma_dbus.c +++ b/client/ma_dbus.c @@ -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