From 97559bed8a6dfe158a26f7dc14dc6a3089d2a9fe Mon Sep 17 00:00:00 2001 From: Wonnam Jang Date: Wed, 24 Jan 2018 17:16:20 +0900 Subject: [PATCH] Change to connect daemon from timer to thread Change-Id: Id7f2e5d38eabbb3880cad5a98f0bb3855d21eff0 Signed-off-by: Wonnam Jang (cherry picked from commit fe930a534021d4f59153c6d7428bcbb3344309eb) --- client/vc_widget.c | 99 ++++++++++++++++++++++++++++++----------- client/vc_widget_dbus.c | 2 + 2 files changed, 75 insertions(+), 26 deletions(-) diff --git a/client/vc_widget.c b/client/vc_widget.c index 89426e1..afe19f0 100644 --- a/client/vc_widget.c +++ b/client/vc_widget.c @@ -36,7 +36,6 @@ static Ecore_Event_Handler* g_focus_in_handler = NULL; static Ecore_Event_Handler* g_focus_out_handler = NULL; static Ecore_Timer* g_w_start_timer = NULL; -static Ecore_Timer* g_w_notify_error_timer = NULL; static Ecore_Timer* g_w_notify_state_timer = NULL; static Ecore_Timer* g_w_notify_result_timer = NULL; @@ -45,7 +44,7 @@ static int g_daemon_pid = 0; static int g_feature_enabled = -1; static Eina_Bool __vc_widget_notify_state_changed(void *data); -static Eina_Bool __vc_widget_notify_error(void *data); +static void __vc_widget_notify_error(void *data); static int __vc_widget_get_feature_enabled() { @@ -237,10 +236,6 @@ static void __vc_widget_delete_timer() ecore_timer_del(g_w_start_timer); g_w_start_timer = NULL; } - if (NULL != g_w_notify_error_timer) { - ecore_timer_del(g_w_notify_error_timer); - g_w_notify_error_timer = NULL; - } if (NULL != g_w_notify_state_timer) { ecore_timer_del(g_w_notify_state_timer); g_w_notify_state_timer = NULL; @@ -347,13 +342,6 @@ static Eina_Bool __vc_widget_connect_daemon(void *data) { vc_h vc_w = (vc_h)data; - /* Send hello */ - if (0 != vc_widget_dbus_request_hello()) { - return EINA_TRUE; - } - - SLOG(LOG_DEBUG, TAG_VCW, "@@@ [Widget] Connect daemon"); - vc_widget_s* widget = widget_get(vc_w); if (NULL != widget) { widget->conn_timer = NULL; @@ -368,7 +356,7 @@ static Eina_Bool __vc_widget_connect_daemon(void *data) SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Fail to initialize : %s", __vc_widget_get_error_code(ret)); vc_widget_client_set_error(vc_w, VC_ERROR_ENGINE_NOT_FOUND); - g_w_notify_error_timer = ecore_timer_add(0, __vc_widget_notify_error, vc_w); + ecore_main_loop_thread_safe_call_async(__vc_widget_notify_error, vc_w); SLOG(LOG_DEBUG, TAG_VCW, "@@@"); return EINA_FALSE; @@ -379,7 +367,7 @@ static Eina_Bool __vc_widget_connect_daemon(void *data) SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Fail to initialize : %s", __vc_widget_get_error_code(ret)); vc_widget_client_set_error(vc_w, VC_ERROR_TIMED_OUT); - g_w_notify_error_timer = ecore_timer_add(0, __vc_widget_notify_error, vc_w); + ecore_main_loop_thread_safe_call_async(__vc_widget_notify_error, vc_w); SLOG(LOG_DEBUG, TAG_VCW, "@@@"); return EINA_FALSE; @@ -387,6 +375,8 @@ static Eina_Bool __vc_widget_connect_daemon(void *data) vc_widget_client_set_service_state(vc_w, (vc_service_state_e)service_state); + SLOG(LOG_INFO, TAG_VCW, "@@@ [Widget] Connect daemon"); + if (NULL == g_focus_in_handler) g_focus_in_handler = ecore_event_handler_add(ECORE_WL_EVENT_FOCUS_IN, __focus_changed_cb, NULL); if (NULL == g_focus_out_handler) @@ -405,22 +395,79 @@ static Eina_Bool __vc_widget_connect_daemon(void *data) } vc_widget_client_set_state(vc_w, VC_STATE_READY); - g_w_notify_state_timer = ecore_timer_add(0, __vc_widget_notify_state_changed, vc_w); + + vc_state_changed_cb changed_callback = NULL; + void* user_data; + + vc_widget_client_get_state_changed_cb(vc_w, &changed_callback, &user_data); + + vc_state_e current_state; + vc_state_e before_state; + + vc_widget_client_get_before_state(vc_w, ¤t_state, &before_state); + + if (NULL != changed_callback) { + vc_widget_client_use_callback(vc_w); + changed_callback(before_state, current_state, user_data); + vc_widget_client_not_use_callback(vc_w); + SLOG(LOG_DEBUG, TAG_VCW, "State changed callback is called"); + } else { + SLOG(LOG_WARN, TAG_VCW, "[WARNING] State changed callback is null"); + } SLOG(LOG_DEBUG, TAG_VCW, "@@@"); return EINA_FALSE; } -int vc_widget_prepare(vc_h vc_w) +static void __start_prepare_thread(void *data, Ecore_Thread *thread) { - SLOG(LOG_DEBUG, TAG_VCW, "@@@ [Widget] Prepare"); + SLOG(LOG_INFO, TAG_VCW, "@@@ Start prepare thread"); + int ret = -1, retry_count = 0; + vc_h vc_w = (vc_h)data; - if (0 != __vc_widget_get_feature_enabled()) { - SLOG(LOG_INFO, TAG_VCW, "@@@ [Widget] not supported"); - return VC_ERROR_NONE; + /* Send hello */ + while (0 != ret) { + if (retry_count == 30) { + SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Fail to request hello !!"); + return; + } + + ret = vc_widget_dbus_request_hello(); + if (ret == 0) { + SLOG(LOG_DEBUG, TAG_VCW, "Success to request hello. retry count(%d)", retry_count); + break; + } else { + retry_count++; + } + } + + ret = -1; + retry_count = 0; + while (0 != ret) { + if (retry_count == 10) { + SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Fail to connect daemon !!"); + return; + } + ret = __vc_widget_connect_daemon((void*)vc_w); + if (ret == 0) + break; + else + retry_count++; } + return; +} + +static void __end_prepare_thread(void *data, Ecore_Thread *thread) +{ + SLOG(LOG_DEBUG, TAG_VCW, "@@@ End prepare thread"); +} + +int vc_widget_prepare(vc_h vc_w) +{ + SLOG(LOG_DEBUG, TAG_VCW, "@@@ [Widget] Prepare"); + vc_state_e state; if (0 != vc_widget_client_get_state(vc_w, &state)) { SLOG(LOG_ERROR, TAG_VCW, "[ERROR] A handle is not available"); @@ -442,7 +489,7 @@ int vc_widget_prepare(vc_h vc_w) return VC_ERROR_INVALID_STATE; } - widget->conn_timer = ecore_timer_add(0, __vc_widget_connect_daemon, (void*)vc_w); + ecore_thread_run(__start_prepare_thread, __end_prepare_thread, NULL, (void*)vc_w); SLOG(LOG_DEBUG, TAG_VCW, "@@@"); @@ -980,7 +1027,7 @@ int vc_widget_cancel(vc_h vc_w) return 0; } -static Eina_Bool __vc_widget_notify_error(void *data) +static void __vc_widget_notify_error(void *data) { vc_h vc_w = (vc_h)data; vc_error_cb callback = NULL; @@ -988,7 +1035,7 @@ static Eina_Bool __vc_widget_notify_error(void *data) int reason; if (NULL == vc_w) { SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Input parameter is NULL"); - return VC_ERROR_INVALID_PARAMETER; + return; } vc_widget_client_get_error_cb(vc_w, &callback, &user_data); @@ -1003,7 +1050,7 @@ static Eina_Bool __vc_widget_notify_error(void *data) SLOG(LOG_WARN, TAG_VCW, "[WARNING] Error callback is null"); } - return EINA_FALSE; + return; } int __vc_widget_cb_error(int reason, int daemon_pid, char* msg) @@ -1047,7 +1094,7 @@ int __vc_widget_cb_error(int reason, int daemon_pid, char* msg) SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Error reason(%d), msg(%s)", reason, msg); vc_widget_client_set_error(vc_w, reason); - g_w_notify_error_timer = ecore_timer_add(0, __vc_widget_notify_error, vc_w); + ecore_main_loop_thread_safe_call_async(__vc_widget_notify_error, vc_w); } } diff --git a/client/vc_widget_dbus.c b/client/vc_widget_dbus.c index 14d3f4d..db68c92 100644 --- a/client/vc_widget_dbus.c +++ b/client/vc_widget_dbus.c @@ -489,6 +489,8 @@ int vc_widget_dbus_request_hello() result_msg = dbus_connection_send_with_reply_and_block(g_w_conn_sender, msg, 500, &err); if (dbus_error_is_set(&err)) { + if (!strncmp(err.name, DBUS_ERROR_SERVICE_UNKNOWN, strlen(err.name))) + usleep(500000); dbus_error_free(&err); } -- 2.34.1