Add codes to check that dbus connection is valid 16/99416/1
authorWonnam Jang <wn.jang@samsung.com>
Wed, 23 Nov 2016 00:36:41 +0000 (09:36 +0900)
committerWonnam Jang <wn.jang@samsung.com>
Wed, 23 Nov 2016 00:36:41 +0000 (09:36 +0900)
Change-Id: I085a64015e77c830d0778f802f3e4b0f6590e2b8
Signed-off-by: Wonnam Jang <wn.jang@samsung.com>
client/vc_dbus.c
server/vcd_dbus.c
server/vcd_main.c

index 1cd3270..a48fcdc 100644 (file)
@@ -290,7 +290,7 @@ int vc_dbus_reconnect()
 {
        bool sender_connected = dbus_connection_get_is_connected(g_conn_sender);
        bool listener_connected = dbus_connection_get_is_connected(g_conn_listener);
-       SLOG(LOG_DEBUG, TAG_VCC, "[DBUS] Sender(%s) Listener(%s)",
+       SLOG(LOG_WARN, TAG_VCC, "[DBUS] Sender(%s) Listener(%s)",
                 sender_connected ? "Connected" : "Not connected", listener_connected ? "Connected" : "Not connected");
 
        if (false == sender_connected || false == listener_connected) {
index 58f3bdf..cf3a011 100644 (file)
@@ -56,8 +56,42 @@ static DBusMessage* __get_message(int pid, const char* method, vcd_client_type_e
        return dbus_message_new_method_call(service_name, object_path, target_if_name, method);
 }
 
+int vcd_dbus_reconnect()
+{
+       bool sender_connected = dbus_connection_get_is_connected(g_conn_sender);
+       bool listener_connected = dbus_connection_get_is_connected(g_conn_listener);
+       SLOG(LOG_WARN, TAG_VCD, "[DBUS] Sender(%s) Listener(%s)",
+                sender_connected ? "Connected" : "Not connected", listener_connected ? "Connected" : "Not connected");
+
+       if (false == sender_connected || false == listener_connected) {
+               vcd_dbus_close_connection();
+
+               if (0 != vcd_dbus_open_connection()) {
+                       SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to reconnect");
+                       return -1;
+               }
+
+               SLOG(LOG_DEBUG, TAG_VCD, "[DBUS] Reconnect");
+       }
+
+       return 0;
+}
+
+static int __dbus_check()
+{
+       if (NULL == g_conn_sender) {
+               SLOG(LOG_ERROR, TAG_VCD, "[ERROR] NULL connection");
+               return vcd_dbus_reconnect();
+       }
+       return 0;
+}
+
 int vcdc_send_hello(int pid, vcd_client_type_e type)
 {
+       if (0 != __dbus_check()) {
+               return VCD_ERROR_OPERATION_FAILED;
+       }
+
        DBusMessage* msg = NULL;
 
        if (VCD_CLIENT_TYPE_NORMAL == type) {
@@ -118,6 +152,10 @@ int vcdc_send_hello(int pid, vcd_client_type_e type)
 
 int vcdc_send_show_tooltip(int pid, bool show)
 {
+       if (0 != __dbus_check()) {
+               return VCD_ERROR_OPERATION_FAILED;
+       }
+
        if (0 > pid) {
                SLOG(LOG_ERROR, TAG_VCD, "[Dbus ERROR] widget pid is NOT valid");
                return -1;
@@ -171,6 +209,10 @@ int vcdc_send_show_tooltip(int pid, bool show)
 
 int vcdc_send_set_volume(int manger_pid, float volume)
 {
+       if (0 != __dbus_check()) {
+               return VCD_ERROR_OPERATION_FAILED;
+       }
+
        DBusMessage* msg = NULL;
 
        /* SLOG(LOG_DEBUG, TAG_VCD, "[Dbus] Set volume (%f)", volume); */
@@ -209,6 +251,10 @@ int vcdc_send_set_volume(int manger_pid, float volume)
 
 int vcdc_send_result(int pid, int manager_pid, int cmd_type)
 {
+       if (0 != __dbus_check()) {
+               return VCD_ERROR_OPERATION_FAILED;
+       }
+
        DBusMessage* msg = NULL;
 
        SLOG(LOG_DEBUG, TAG_VCD, "[Dbus] Result command type(%d)", cmd_type);
@@ -258,6 +304,10 @@ int vcdc_send_result(int pid, int manager_pid, int cmd_type)
 
 int vcdc_send_pre_result_to_manager(int manager_pid, int event, const char* pre_result)
 {
+       if (0 != __dbus_check()) {
+               return VCD_ERROR_OPERATION_FAILED;
+       }
+
        DBusError err;
        dbus_error_init(&err);
 
@@ -287,6 +337,10 @@ int vcdc_send_pre_result_to_manager(int manager_pid, int event, const char* pre_
 
 int vcdc_send_result_to_manager(int manger_pid, int result_type)
 {
+       if (0 != __dbus_check()) {
+               return VCD_ERROR_OPERATION_FAILED;
+       }
+
        DBusError err;
        dbus_error_init(&err);
 
@@ -320,6 +374,10 @@ int vcdc_send_result_to_manager(int manger_pid, int result_type)
 
 int vcdc_send_speech_detected(int manger_pid)
 {
+       if (0 != __dbus_check()) {
+               return VCD_ERROR_OPERATION_FAILED;
+       }
+
        DBusError err;
        dbus_error_init(&err);
 
@@ -350,6 +408,10 @@ int vcdc_send_speech_detected(int manger_pid)
 
 int vcdc_send_service_state(vcd_state_e state)
 {
+       if (0 != __dbus_check()) {
+               return VCD_ERROR_OPERATION_FAILED;
+       }
+
        DBusError err;
        dbus_error_init(&err);
 
@@ -432,6 +494,10 @@ int vcdc_send_service_state(vcd_state_e state)
 
 int vcdc_send_dialog(int manger_pid, int pid, const char* disp_text, const char* utt_text, int continuous)
 {
+       if (0 != __dbus_check()) {
+               return VCD_ERROR_OPERATION_FAILED;
+       }
+
        DBusError err;
        dbus_error_init(&err);
 
@@ -477,6 +543,10 @@ int vcdc_send_error_signal_to_manager(int manager_pid, int reason, char *err_msg
                return VCD_ERROR_INVALID_PARAMETER;
        }
 
+       if (0 != __dbus_check()) {
+               return VCD_ERROR_OPERATION_FAILED;
+       }
+
        int daemon_pid;
        DBusError err;
        dbus_error_init(&err);
@@ -518,6 +588,10 @@ int vcdc_send_error_signal(int reason, char *err_msg)
                return VCD_ERROR_INVALID_PARAMETER;
        }
 
+       if (0 != __dbus_check()) {
+               return VCD_ERROR_OPERATION_FAILED;
+       }
+
        int daemon_pid;
        DBusError err;
        dbus_error_init(&err);
@@ -833,4 +907,4 @@ int vcd_dbus_close_connection()
        g_conn_sender = NULL;
 
        return 0;
-}
\ No newline at end of file
+}
index f31ed91..2996ba0 100644 (file)
@@ -36,11 +36,13 @@ int main(int argc, char** argv)
 
        if (0 != vcd_dbus_open_connection()) {
                SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to open connection");
+               ecore_shutdown();
                return EXIT_FAILURE;
        }
 
        if (0 != vcd_initialize()) {
                SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to initialize vc-daemon");
+               ecore_shutdown();
                return EXIT_FAILURE;
        }