Fix vc_widget_unprepare 66/179966/3
authorsooyeon.kim <sooyeon.kim@samsung.com>
Wed, 23 May 2018 13:36:46 +0000 (22:36 +0900)
committerWonnam Jang <wn.jang@samsung.com>
Thu, 24 May 2018 01:56:04 +0000 (10:56 +0900)
Change-Id: Ica2f4dde4da7a3e9d17ce8d24d8826913f3f7cf8
Signed-off-by: sooyeon.kim <sooyeon.kim@samsung.com>
client/vc_widget.c

index ea0d2cf..0dcca65 100644 (file)
@@ -45,6 +45,7 @@ static int g_feature_enabled = -1;
 
 static Eina_Bool __vc_widget_notify_state_changed(void *data);
 static void __vc_widget_notify_error(void *data);
+static void __vc_widget_delete_focus_event_handler(void *data);
 
 static int __vc_widget_get_feature_enabled()
 {
@@ -213,14 +214,7 @@ static void __vc_widget_internal_unprepare(vc_h vc_w)
                SLOG(LOG_WARN, TAG_VCW, "[ERROR] Fail to request finalize : %s", __vc_widget_get_error_code(ret));
        }
 
-       if (NULL != g_focus_in_handler) {
-               ecore_event_handler_del(g_focus_in_handler);
-               g_focus_in_handler = NULL;
-       }
-       if (NULL != g_focus_out_handler) {
-               ecore_event_handler_del(g_focus_out_handler);
-               g_focus_out_handler = NULL;
-       }
+       __vc_widget_delete_focus_event_handler(NULL);
 
        ret = vc_cmd_parser_delete_file(getpid(), VC_COMMAND_TYPE_WIDGET);
        if (0 != ret)
@@ -262,21 +256,6 @@ int vc_widget_deinitialize(vc_h vc_w)
                return VC_ERROR_INVALID_STATE;
        }
 
-
-       int thread_count = ecore_thread_active_get();
-       int count = 0;
-       while (0 < thread_count) {
-               usleep(50000);
-               count++;
-               if (100 == count) {
-                       SLOG(LOG_WARN, TAG_VCW, "[WARNING!!] Thread is blocked, cnt(%d), thread count(%d)", count, thread_count);
-                       break;
-               } else if (0 == count % 5) {
-                       SLOG(LOG_WARN, TAG_VCW, "[WARNING!!] Thread is alive, cnt(%d), thread count(%d)", count, thread_count);
-               }
-               thread_count = ecore_thread_active_get();
-       }
-
        vc_state_e state;
        vc_widget_client_get_state(vc_w, &state);
        vc_widget_s* widget = widget_get(vc_w);
@@ -353,7 +332,35 @@ static Eina_Bool __focus_changed_cb(void *data, int type, void *event)
        return ECORE_CALLBACK_RENEW;
 }
 
-static void __vc_widget_connect_daemon(void *data)
+static void __vc_widget_add_focus_event_handler(void *data)
+{
+       SLOG(LOG_INFO, TAG_VCW, "@@@ [Widget] add focus event handler");
+
+       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)
+               g_focus_out_handler = ecore_event_handler_add(ECORE_WL_EVENT_FOCUS_OUT, __focus_changed_cb, NULL);
+
+       return;
+}
+
+static void __vc_widget_delete_focus_event_handler(void *data)
+{
+       SLOG(LOG_INFO, TAG_VCW, "@@@ [Widget] delete focus event handler");
+
+       if (NULL != g_focus_in_handler) {
+               ecore_event_handler_del(g_focus_in_handler);
+               g_focus_in_handler = NULL;
+       }
+       if (NULL != g_focus_out_handler) {
+               ecore_event_handler_del(g_focus_out_handler);
+               g_focus_out_handler = NULL;
+       }
+
+       return;
+}
+
+static Eina_Bool __vc_widget_connect_daemon(void *data)
 {
        vc_h vc_w = (vc_h)data;
 
@@ -374,7 +381,7 @@ static void __vc_widget_connect_daemon(void *data)
                ecore_main_loop_thread_safe_call_async(__vc_widget_notify_error, vc_w);
 
                SLOG(LOG_DEBUG, TAG_VCW, "@@@");
-               return;
+               return EINA_FALSE;
 
        } else if (VC_ERROR_INVALID_PARAMETER == ret) {
                SLOG(LOG_WARN, TAG_VCW, "[WARNING] Invalid Parameter");
@@ -385,18 +392,13 @@ static void __vc_widget_connect_daemon(void *data)
                ecore_main_loop_thread_safe_call_async(__vc_widget_notify_error, vc_w);
 
                SLOG(LOG_DEBUG, TAG_VCW, "@@@");
-               return;
+               return EINA_TRUE;
        }
 
        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)
-               g_focus_out_handler = ecore_event_handler_add(ECORE_WL_EVENT_FOCUS_OUT, __focus_changed_cb, NULL);
-
        char appid[1024] = {'\0',};
        aul_app_get_appid_bypid(getpid(), appid, sizeof(appid) - 1);
 
@@ -432,7 +434,7 @@ static void __vc_widget_connect_daemon(void *data)
 
        SLOG(LOG_DEBUG, TAG_VCW, "@@@");
 
-       return;
+       return EINA_FALSE;
 }
 
 static void __start_prepare_thread(void *data, Ecore_Thread *thread)
@@ -445,6 +447,7 @@ static void __start_prepare_thread(void *data, Ecore_Thread *thread)
        while (0 != ret) {
                if (retry_count == 30) {
                        SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Fail to request hello !!");
+                       ecore_main_loop_thread_safe_call_async(__vc_widget_delete_focus_event_handler, NULL);
                        return;
                }
 
@@ -457,12 +460,12 @@ static void __start_prepare_thread(void *data, Ecore_Thread *thread)
                }
        }
 
-#if 0
        ret = -1;
        retry_count = 0;
        while (0 != ret) {
                if (retry_count == 10) {
                        SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Fail to connect daemon !!");
+                       ecore_main_loop_thread_safe_call_async(__vc_widget_delete_focus_event_handler, NULL);
                        return;
                }
                ret = __vc_widget_connect_daemon((void*)vc_w);
@@ -471,9 +474,8 @@ static void __start_prepare_thread(void *data, Ecore_Thread *thread)
                else
                        retry_count++;
        }
-#endif
 
-       ecore_main_loop_thread_safe_call_async(__vc_widget_connect_daemon, vc_w);
+       SLOG(LOG_DEBUG, TAG_VCW, "@@@");
 
        return;
 }
@@ -513,6 +515,9 @@ int vc_widget_prepare(vc_h vc_w)
                return VC_ERROR_INVALID_STATE;
        }
 
+       // Add focus event handler before start sub thread. If connection fails, event handler will be deleted.
+       __vc_widget_add_focus_event_handler(NULL);
+
        ecore_thread_run(__start_prepare_thread, __end_prepare_thread, NULL, (void*)vc_w);
 
        SLOG(LOG_DEBUG, TAG_VCW, "@@@");
@@ -529,6 +534,21 @@ int vc_widget_unprepare(vc_h vc_w)
                return VC_ERROR_NONE;
        }
 
+       int thread_count = ecore_thread_active_get();
+       int count = 0;
+       SLOG(LOG_INFO, TAG_VCW, "[Widget] Thread count(%d)", thread_count);
+       while (0 < thread_count) {
+               usleep(50000);
+               if (100 == count) {
+                       SLOG(LOG_WARN, TAG_VCW, "[WARNING!!] Thread is blocked, cnt(%d), thread count(%d)", count, thread_count);
+                       break;
+               } else if (0 == count % 5) {
+                       SLOG(LOG_WARN, TAG_VCW, "[WARNING!!] Thread is alive, cnt(%d), thread count(%d)", count, thread_count);
+               }
+               count++;
+               thread_count = ecore_thread_active_get();
+       }
+
        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");
@@ -538,7 +558,7 @@ int vc_widget_unprepare(vc_h vc_w)
 
        /* check state */
        if (state != VC_STATE_READY) {
-               SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Invalid State: Current state is not 'READY'");
+               SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Invalid State: Current state is not 'READY', state(%d)", state);
                SLOG(LOG_DEBUG, TAG_VCW, "@@@");
                return VC_ERROR_INVALID_STATE;
        }