Change ecore timer to thread for connecting daemon 63/159163/1
authorWonnam Jang <wn.jang@samsung.com>
Tue, 7 Nov 2017 07:30:10 +0000 (16:30 +0900)
committerWonnam Jang <wn.jang@samsung.com>
Tue, 7 Nov 2017 07:57:18 +0000 (07:57 +0000)
Change-Id: I92e6f9cd5a6e4f1db86041747efc9cb3fad4120c
Signed-off-by: Wonnam Jang <wn.jang@samsung.com>
(cherry picked from commit 7e35c08d1960335a77963ba6a299e2ef5742a22e)

client/vc.c
client/vc_dbus.c
client/vc_mgr.c
client/vc_mgr_dbus.c

index 2afb878..c89e7f9 100644 (file)
@@ -56,8 +56,8 @@ static bool g_backup = false;
 static int g_privilege_allowed = -1;
 static cynara *p_cynara = NULL;
 
-Eina_Bool __vc_notify_state_changed(void *data);
-Eina_Bool __vc_notify_error(void *data);
+static void __vc_notify_state_changed(void *data);
+static void __vc_notify_error(void *data);
 
 static int __vc_get_feature_enabled()
 {
@@ -110,7 +110,7 @@ static int __check_privilege(const char* uid, const char * privilege)
 
        fp = fopen(label_path, "r");
        if (fp != NULL) {
-               if (sizeof(smack_label) != fread(smack_label, 1, sizeof(smack_label), fp))
+               if (strlen(smack_label) != fread(smack_label, 1, sizeof(smack_label), fp))
                        SLOG(LOG_ERROR, TAG_VCC, "[ERROR] fail to fread");
 
                fclose(fp);
@@ -489,7 +489,7 @@ static Eina_Bool __vc_connect_daemon(void *data)
                SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Fail to initialize : %s", __vc_get_error_code(ret));
 
                vc_client_set_error(g_vc, VC_ERROR_ENGINE_NOT_FOUND);
-               ecore_timer_add(0, __vc_notify_error, g_vc);
+               ecore_main_loop_thread_safe_call_async(__vc_notify_error, (void*)g_vc);
 
                SLOG(LOG_DEBUG, TAG_VCC, "@@@");
                return EINA_FALSE;
@@ -498,7 +498,7 @@ static Eina_Bool __vc_connect_daemon(void *data)
                SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Fail to initialize :%s", __vc_get_error_code(ret));
 
                vc_client_set_error(g_vc, VC_ERROR_TIMED_OUT);
-               ecore_timer_add(0, __vc_notify_error, g_vc);
+               ecore_main_loop_thread_safe_call_async(__vc_notify_error, (void*)g_vc);
 
                SLOG(LOG_DEBUG, TAG_VCC, "@@@");
                return EINA_FALSE;
@@ -542,7 +542,7 @@ static Eina_Bool __vc_connect_daemon(void *data)
        }
 
        vc_client_set_client_state(g_vc, VC_STATE_READY);
-       ecore_timer_add(0, __vc_notify_state_changed, g_vc);
+       ecore_main_loop_thread_safe_call_async(__vc_notify_state_changed, (void*)g_vc);
 
        vc_client_set_mgr_pid(g_vc, mgr_pid);
 
@@ -551,6 +551,50 @@ static Eina_Bool __vc_connect_daemon(void *data)
        return EINA_FALSE;
 }
 
+static void __start_prepare_thread(void *data, Ecore_Thread *thread)
+{
+       SLOG(LOG_ERROR, TAG_VCC, "@@@ Start prepare thread");
+       int ret = -1, retry_count = 0;
+
+       /* Send hello */
+       while (0 != ret) {
+
+               if (retry_count == 10) {
+                       SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Fail to request hello !!");
+                       return;
+               }
+
+               ret = vc_dbus_request_hello();
+               if (ret == 0) {
+                       SLOG(LOG_DEBUG, TAG_VCC, "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_VCC, "[ERROR] Fail to connect daemon !!");
+                       return;
+               }
+               ret = __vc_connect_daemon(NULL);
+               if (ret == 0)
+                       break;
+               else
+                       retry_count++;
+       }
+
+       return;
+}
+
+static void __end_prepare_thread(void *data, Ecore_Thread *thread)
+{
+       SLOG(LOG_DEBUG, TAG_VCC, "@@@ End prepare thread");
+}
+
 int vc_prepare(void)
 {
        if (0 != __vc_get_feature_enabled()) {
@@ -576,7 +620,7 @@ int vc_prepare(void)
                return VC_ERROR_INVALID_STATE;
        }
 
-       g_connect_timer = ecore_timer_add(0, __vc_connect_daemon, NULL);
+       ecore_thread_run(__start_prepare_thread, __end_prepare_thread, NULL, NULL);
 
        SLOG(LOG_DEBUG, TAG_VCC, "@@@");
 
@@ -651,7 +695,7 @@ int vc_unprepare(void)
        __vc_internal_unprepare();
 
        vc_client_set_client_state(g_vc, VC_STATE_INITIALIZED);
-       ecore_timer_add(0, __vc_notify_state_changed, g_vc);
+       ecore_main_loop_thread_safe_call_async(__vc_notify_state_changed, (void*)g_vc);
 
        SLOG(LOG_DEBUG, TAG_VCC, "@@@");
 
@@ -1522,7 +1566,7 @@ int vc_request_cancel(void)
 }
 #endif
 
-Eina_Bool __vc_notify_error(void *data)
+static void __vc_notify_error(void *data)
 {
        vc_h vc = (vc_h)data;
 
@@ -1541,8 +1585,6 @@ Eina_Bool __vc_notify_error(void *data)
        } else {
                SLOG(LOG_WARN, TAG_VCC, "[WARNING] Error callback is null");
        }
-
-       return EINA_FALSE;
 }
 
 int __vc_cb_error(int reason, int daemon_pid, char* msg)
@@ -1563,22 +1605,22 @@ int __vc_cb_error(int reason, int daemon_pid, char* msg)
                SLOG(LOG_ERROR, TAG_VCC, "[ERROR] VC daemon reset");
 
                vc_client_set_client_state(g_vc, VC_STATE_INITIALIZED);
-               __vc_notify_state_changed(g_vc);
+               ecore_main_loop_thread_safe_call_async(__vc_notify_state_changed, (void*)g_vc);
 
                if (0 != vc_prepare()) {
                        SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Fail to prepare");
                }
        }
 
-       SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Error reason(%d), msg(%s)", reason, msg);
+       SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Error reason(%d), msg(%s)", reason, msg);
 
        vc_client_set_error(g_vc, reason);
-       ecore_timer_add(0, __vc_notify_error, g_vc);
+       ecore_main_loop_thread_safe_call_async(__vc_notify_error, (void*)g_vc);
 
        return 0;
 }
 
-Eina_Bool __vc_notify_state_changed(void *data)
+static void __vc_notify_state_changed(void *data)
 {
        vc_h vc = (vc_h)data;
 
@@ -1600,8 +1642,6 @@ Eina_Bool __vc_notify_state_changed(void *data)
        } else {
                SLOG(LOG_WARN, TAG_VCC, "[WARNING] State changed callback is null");
        }
-
-       return EINA_FALSE;
 }
 
 static Eina_Bool __vc_notify_result(void *data)
index 49d4510..7ab57c5 100644 (file)
@@ -401,6 +401,7 @@ int vc_dbus_request_hello()
        result_msg = dbus_connection_send_with_reply_and_block(g_conn_sender, msg, 500, &err);
 
        if (dbus_error_is_set(&err)) {
+               SLOG(LOG_DEBUG, TAG_VCC, "[ERROR] Dbus Error (%s)", err.message);
                dbus_error_free(&err);
        }
 
index b8c5458..f29f08c 100644 (file)
@@ -55,7 +55,7 @@ static int g_feature_enabled = -1;
 static bool g_err_callback_status = false;
 
 static Eina_Bool __vc_mgr_notify_state_changed(void *data);
-static Eina_Bool __vc_mgr_notify_error(void *data);
+static void __vc_mgr_notify_error(void *data);
 static Eina_Bool __vc_mgr_notify_result(void *data);
 
 static const char* __vc_mgr_get_error_code(vc_error_e err)
@@ -262,7 +262,7 @@ static Eina_Bool __vc_mgr_connect_daemon(void *data)
                SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to initialize : %s", __vc_mgr_get_error_code(ret));
 
                vc_mgr_client_set_error(g_vc_m, VC_ERROR_ENGINE_NOT_FOUND);
-               ecore_timer_add(0, __vc_mgr_notify_error, g_vc_m);
+               ecore_main_loop_thread_safe_call_async(__vc_mgr_notify_error, (void*)g_vc_m);
 
                SLOG(LOG_DEBUG, TAG_VCM, "@@@");
                return EINA_FALSE;
@@ -314,7 +314,7 @@ static void __start_prepare_thread(void *data, Ecore_Thread *thread)
        int ret = 1, retry_count = 0;
 
        /* Send hello */
-       while (ret) {
+       while (0 != ret) {
 
                if (retry_count == 10) {
                        SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to request hello !!");
@@ -332,7 +332,7 @@ static void __start_prepare_thread(void *data, Ecore_Thread *thread)
 
        ret = 1;
        retry_count = 0;
-       while (ret) {
+       while (0 != ret) {
                if (retry_count == 10) {
                        SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to connect daemon !!");
                        return;
@@ -2321,7 +2321,7 @@ int vc_mgr_get_error_message(char** err_msg)
        return ret;
 }
 
-static Eina_Bool __vc_mgr_notify_error(void *data)
+static void __vc_mgr_notify_error(void *data)
 {
        vc_h vc_m = (vc_h)data;
 
@@ -2342,8 +2342,6 @@ static Eina_Bool __vc_mgr_notify_error(void *data)
        } else {
                SLOG(LOG_WARN, TAG_VCM, "[WARNING] Error callback is null");
        }
-
-       return EINA_FALSE;
 }
 
 int __vc_mgr_cb_error(int reason, int daemon_pid, char* msg)
index 2cfd533..4c43f45 100644 (file)
@@ -788,6 +788,7 @@ int vc_mgr_dbus_request_hello()
        result_msg = dbus_connection_send_with_reply_and_block(g_m_conn_sender, msg, 500, &err);
 
        if (dbus_error_is_set(&err)) {
+               SLOG(LOG_DEBUG, TAG_VCM, "[ERROR] Dbus Error (%s)", err.message);
                dbus_error_free(&err);
        }