From: Wonnam Jang Date: Wed, 23 Nov 2016 00:36:41 +0000 (+0900) Subject: Add codes to check that dbus connection is valid X-Git-Tag: accepted/tizen/common/20161130.134133~4^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=15c3d83a25d11e8450deb3dbc4b8ea60b1e14b35;p=platform%2Fcore%2Fuifw%2Fvoice-control.git Add codes to check that dbus connection is valid Change-Id: I085a64015e77c830d0778f802f3e4b0f6590e2b8 Signed-off-by: Wonnam Jang --- diff --git a/client/vc_dbus.c b/client/vc_dbus.c index 1cd3270..a48fcdc 100644 --- a/client/vc_dbus.c +++ b/client/vc_dbus.c @@ -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) { diff --git a/server/vcd_dbus.c b/server/vcd_dbus.c index 58f3bdf..cf3a011 100644 --- a/server/vcd_dbus.c +++ b/server/vcd_dbus.c @@ -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 +} diff --git a/server/vcd_main.c b/server/vcd_main.c index f31ed91..2996ba0 100644 --- a/server/vcd_main.c +++ b/server/vcd_main.c @@ -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; }