From: wn.jang Date: Tue, 25 Jun 2019 01:17:07 +0000 (+0900) Subject: Connect DB after service state is ready to avoid concurrency issue X-Git-Tag: submit/tizen/20190625.100758~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=50daee94da73a16b05a06e35f275cac7e926c51c;p=platform%2Fcore%2Fuifw%2Fvoice-control.git Connect DB after service state is ready to avoid concurrency issue Change-Id: I03caa096b651f4c61f626a6317bbd97f9aff0070 Signed-off-by: wn.jang --- diff --git a/client/vc.c b/client/vc.c index 47fffee..936c019 100644 --- a/client/vc.c +++ b/client/vc.c @@ -355,14 +355,6 @@ int vc_initialize(void) return __vc_convert_config_error_code(ret); } - ret = vc_db_initialize(); - if (0 != ret) { - SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Fail to initialize DB : %d", ret); //LCOV_EXCL_LINE - vc_config_mgr_finalize(g_vc->handle); //LCOV_EXCL_LINE - vc_client_destroy(g_vc); //LCOV_EXCL_LINE - return ret; - } - SLOG(LOG_DEBUG, TAG_VCC, "[Success] pid(%d)", g_vc->handle); SLOG(LOG_DEBUG, TAG_VCC, "@@@"); @@ -492,6 +484,13 @@ static Eina_Bool __vc_connect_daemon(void *data) if (true == vc_client_is_valid(g_vc)) { SLOG(LOG_DEBUG, TAG_VCC, "[DEBUG] g_vc is valid"); + /* Initialize DB */ + ret = vc_db_initialize(); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Fail to initialize DB : %d", ret); //LCOV_EXCL_LINE + return EINA_TRUE; + } + ret = vc_dbus_request_initialize(g_vc->handle, &mgr_pid, &service_state, &g_daemon_pid); //LCOV_EXCL_START if (VC_ERROR_ENGINE_NOT_FOUND == ret) { @@ -508,6 +507,11 @@ static Eina_Bool __vc_connect_daemon(void *data) vc_client_set_error(g_vc, VC_ERROR_TIMED_OUT); ecore_main_loop_thread_safe_call_async(__vc_notify_error, (void*)g_vc); + ret = vc_db_finalize(); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Fail to finalize DB : %d", ret); //LCOV_EXCL_LINE + } + return EINA_TRUE; } else { /* Success to connect */ diff --git a/client/vc_mgr.c b/client/vc_mgr.c index 76d7c12..6b65459 100644 --- a/client/vc_mgr.c +++ b/client/vc_mgr.c @@ -293,14 +293,6 @@ int vc_mgr_initialize(void) return VC_ERROR_OPERATION_FAILED; } - ret = vc_db_initialize(); - if (0 != ret) { - SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to initialize DB : %d", ret); - vc_config_mgr_finalize(g_vc_m->handle + VC_MANAGER_CONFIG_HANDLE); - vc_mgr_client_destroy(g_vc_m); - return ret; - } - ret = vc_mgr_client_set_audio_streaming_mode(g_vc_m, VC_AUDIO_STREAMING_MODE_VC_SERVICE); if (0 != ret) { SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to set audio streaming mode : %d", ret); @@ -420,6 +412,13 @@ static Eina_Bool __vc_mgr_connect_daemon(void *data) if (true == vc_mgr_client_is_valid(g_vc_m)) { SLOG(LOG_DEBUG, TAG_VCM, "[DEBUG] g_vc_m is valid"); + /* Initialize DB */ + ret = vc_db_initialize(); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to initialize DB : %d", ret); + return EINA_TRUE; + } + vc_audio_streaming_mode_e streaming_mode; vc_mgr_client_get_audio_streaming_mode(g_vc_m, &streaming_mode); @@ -436,6 +435,10 @@ static Eina_Bool __vc_mgr_connect_daemon(void *data) } else if (0 != ret) { SLOG(LOG_ERROR, TAG_VCM, "[WARNING] Fail to connection. Retry to connect : %s", __vc_mgr_get_error_code(ret)); + ret = vc_db_finalize(); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to finalize DB : %d", ret); + } return EINA_TRUE; } else { /* Success to connect */ diff --git a/client/vc_widget.c b/client/vc_widget.c index 0fb7460..21bb79e 100644 --- a/client/vc_widget.c +++ b/client/vc_widget.c @@ -200,17 +200,6 @@ int vc_widget_initialize(vc_h* vc_w) return __vc_widget_convert_config_error_code(ret); } - if (1 == vc_widget_client_get_count()) { - ret = vc_db_initialize(); - if (0 != ret) { - SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Fail to initialize DB : %d", ret); - vc_config_mgr_finalize((*vc_w)->handle); - vc_widget_client_destroy((*vc_w)); - pthread_mutex_unlock(&g_w_init_mutex); - return ret; - } - } - SLOG(LOG_DEBUG, TAG_VCW, "[Success] uid(%d)", (*vc_w)->handle); SLOG(LOG_DEBUG, TAG_VCW, "@@@"); @@ -386,6 +375,15 @@ static Eina_Bool __vc_widget_connect_daemon(void *data) widget->conn_timer = NULL; } + /* Initialize DB */ + if (1 == vc_widget_client_get_count()) { + ret = vc_db_initialize(); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Fail to initialize DB : %d", ret); + return EINA_TRUE; + } + } + /* request initialization */ int ret = -1; int service_state = 0; @@ -408,6 +406,11 @@ static Eina_Bool __vc_widget_connect_daemon(void *data) vc_widget_client_set_error(vc_w, VC_ERROR_TIMED_OUT); ecore_main_loop_thread_safe_call_async(__vc_widget_notify_error, vc_w); + ret = vc_db_finalize(); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Fail to finalize DB : %d", ret); + } + SLOG(LOG_DEBUG, TAG_VCW, "@@@"); return EINA_TRUE; } diff --git a/server/vcd_config.c b/server/vcd_config.c index 629487e..03114d5 100755 --- a/server/vcd_config.c +++ b/server/vcd_config.c @@ -14,7 +14,6 @@ * limitations under the License. */ -#include "vc_cmd_db.h" #include "vc_config_mgr.h" #include "vcd_config.h" #include "vcd_main.h" @@ -72,12 +71,6 @@ int vcd_config_initialize(vcd_config_lang_changed_cb lang_cb, vcd_config_foregro return VCD_ERROR_OPERATION_FAILED; } - ret = vc_db_initialize(); - if (0 != ret) { - SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to initialize DB : %d", ret); - return ret; - } - g_lang_cb = lang_cb; g_user_data = user_data; @@ -91,11 +84,7 @@ int vcd_config_finalize() vc_config_mgr_unset_lang_cb(getpid()); vc_config_mgr_finalize(getpid()); - int ret = vc_db_finalize(); - if (0 != ret) { - SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to finalize DB, ret(%d)", ret); - } - return ret; + return 0; } int vcd_config_get_default_language(char** language) diff --git a/server/vcd_server.c b/server/vcd_server.c index e74003f..59a2986 100644 --- a/server/vcd_server.c +++ b/server/vcd_server.c @@ -1222,6 +1222,12 @@ int vcd_initialize(vce_request_callback_s *callback) SLOG(LOG_ERROR, TAG_VCD, "[Server WARNING] Fail to initialize config."); } + ret = vc_db_initialize(); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to initialize DB : %d", ret); + return ret; + } + /* Remove db data */ ret = __vcd_db_clean_up(); if (0 != ret) { @@ -1318,9 +1324,24 @@ bool vcd_finalize() vcd_client_manager_unset_appid(); + ret = vcd_config_finalize(); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_VCD, "[Server WARNING] Fail to finalize config."); + } + + ret = vc_db_finalize(); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to finalize DB : %d", ret); + } + vcd_config_set_service_state(VCD_STATE_NONE); vcdc_send_service_state(VCD_STATE_NONE); + /* Open dbus connection */ + if (0 != vcd_dbus_close_connection()) { + SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to close connection"); + } + SLOG(LOG_ERROR, TAG_VCD, "[Server] mode finalize"); return true;