Connect DB after service state is ready to avoid concurrency issue
authorwn.jang <wn.jang@samsung.com>
Tue, 25 Jun 2019 01:17:07 +0000 (10:17 +0900)
committerwn.jang <wn.jang@samsung.com>
Tue, 25 Jun 2019 01:17:07 +0000 (10:17 +0900)
Change-Id: I03caa096b651f4c61f626a6317bbd97f9aff0070
Signed-off-by: wn.jang <wn.jang@samsung.com>
client/vc.c
client/vc_mgr.c
client/vc_widget.c
server/vcd_config.c
server/vcd_server.c

index 47fffee62960f1f8016b46d470300b28faf8b594..936c019d2d6f9506a59e95fd8058150a7c15a867 100644 (file)
@@ -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 */
index 76d7c12cd12822d5c34058929056132773367ec2..6b654594aa74d7c32c06420d3243040569f46a15 100644 (file)
@@ -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 */
index 0fb74603cf72dadc2995f58ac1d4fd13dfece125..21bb79edce2eec475871be84abb278bda84ede48 100644 (file)
@@ -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;
        }
index 629487ec97e8d36b083ecdb24d17e20ca6d93dbf..03114d596506755e8e7052bbcafa560648512a99 100755 (executable)
@@ -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)
index e74003ffa9a2d74b8cbf32a315e3012b21511aae..59a29866c855d47f0aa77085f820c7b470d206fb 100644 (file)
@@ -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;