Send error about tts failed to client app 36/266936/2
authorSuyeon Hwang <stom.hwang@samsung.com>
Mon, 22 Nov 2021 10:32:57 +0000 (19:32 +0900)
committerSuyeon Hwang <stom.hwang@samsung.com>
Mon, 27 Dec 2021 07:05:20 +0000 (16:05 +0900)
Change-Id: Ic7736f0f2381bc873f87da0f8d455b61ebd87d1a
Signed-off-by: Suyeon Hwang <stom.hwang@samsung.com>
client/vc.c
client/vc_client.c
client/vc_client.h
client/vc_dbus.c
common/vc_defs.h
server/vcd_dbus.c
server/vcd_dbus.h
server/vcd_server.c

index 60143a2..f42cc66 100644 (file)
@@ -1713,6 +1713,24 @@ int __vc_cb_error(int reason, int daemon_pid, char* msg)
        return 0;
 }
 
+int __vc_cb_error_to_app(int pid, int reason, const char* msg)
+{
+       SLOG(LOG_INFO, TAG_VCC, "[INFO] send error to app(%d)", pid);
+
+       vc_h vc;
+       if (0 != vc_client_get_handle(pid, &vc)) {
+               SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Fail to get vc handle");
+               return VC_ERROR_INVALID_PARAMETER;
+       }
+
+       SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Error reason(%d), msg(%s)", reason, msg);
+
+       vc_client_set_error(vc, reason);
+       ecore_main_loop_thread_safe_call_async(__vc_notify_error, (void*)vc);
+
+       return VC_ERROR_NONE;
+}
+
 static void __vc_notify_state_changed(void *data)
 {
        vc_h vc = (vc_h)data;
index 60194c0..fe116b0 100644 (file)
@@ -164,6 +164,8 @@ int vc_client_create(vc_h* vc)
        client->is_foreground = false;
        client->invocation_name = NULL;
 
+       SLOG(LOG_INFO, TAG_VCC, "[INFO] client create. uid(%u)", client->uid);
+
        g_client_list = g_slist_append(g_client_list, client);
 
        *vc = temp;
@@ -246,18 +248,21 @@ bool vc_client_is_valid_by_uid(unsigned int uid)
 }
 
 //LCOV_EXCL_START
-int vc_client_get_handle(unsigned int uid, vc_h* vc)
+int vc_client_get_handle(int pid, vc_h* vc)
 {
        vc_client_s *data = NULL;
 
        int count = g_slist_length(g_client_list);
        int i;
 
+       SLOG(LOG_DEBUG, TAG_VCC, "[DEBUG] The number of VC clients(%d)", count);
+
        for (i = 0; i < count; i++) {
                data = g_slist_nth_data(g_client_list, i);
 
                if (NULL != data) {
-                       if (uid == data->vc->handle) {
+                       SLOG(LOG_DEBUG, TAG_VCC, "[DEBUG] pid(%d), handle(%d)", pid, data->vc->handle);
+                       if (pid == data->vc->handle) {
                                *vc = data->vc;
                                return 0;
                        }
index 7c22e2c..cfc8d4b 100644 (file)
@@ -40,7 +40,7 @@ bool vc_client_is_valid(vc_h vc);
 
 bool vc_client_is_valid_by_uid(unsigned int uid);
 
-int vc_client_get_handle(unsigned int uid, vc_h* vc);
+int vc_client_get_handle(int pid, vc_h* vc);
 
 /*
 * set/get callback function
index e41b7ef..05e5bed 100644 (file)
@@ -31,6 +31,8 @@ static DBusConnection* g_conn_listener = NULL;
 
 extern int __vc_cb_error(int reason, int daemon_pid, char* msg);
 
+extern int __vc_cb_error_to_app(int pid, int reason, char* msg);
+
 extern void __vc_cb_result();
 
 extern int __vc_cb_service_state(int state);
@@ -163,6 +165,29 @@ static Eina_Bool listener_event_callback(void* data, Ecore_Fd_Handler *fd_handle
                        SLOG(LOG_DEBUG, TAG_VCC, "@@@");
                } /* VCD_METHOD_ERROR */
 
+               else if (dbus_message_is_signal(msg, if_name, VCD_METHOD_ERROR_TO_APP)) {
+                       SLOG(LOG_DEBUG, TAG_VCC, "@@@ Get Error and send to client app");
+                       int pid;
+                       int reason;
+                       char* err_msg;
+
+                       dbus_message_get_args(msg, &err,
+                               DBUS_TYPE_INT32, &pid,
+                               DBUS_TYPE_INT32, &reason,
+                               DBUS_TYPE_STRING, &err_msg,
+                               DBUS_TYPE_INVALID);
+
+                       if (dbus_error_is_set(&err)) {
+                               SLOG(LOG_ERROR, TAG_VCC, "@@ vc Get Error message : Get arguments error (%s)", err.message);
+                               dbus_error_free(&err);
+                       } else {
+                               SLOG(LOG_DEBUG, TAG_VCC, "@@ vc Get Error message : reason(%d), pid(%d), msg(%s)", reason, pid, err_msg);
+                               __vc_cb_error_to_app(pid, reason, err_msg);
+                       }
+
+                       SLOG(LOG_DEBUG, TAG_VCC, "@@@");
+               } /* VCD_METHOD_ERROR_TO_APP */
+
                else if (dbus_message_is_method_call(msg, if_name, VCD_METHOD_FEEDBACK_STREAMING)) {
                        SLOG(LOG_INFO, TAG_VCC, "@@@ Get TTS feedback streaming");
                        int utt_id;
index 21c2e58..121950e 100644 (file)
@@ -82,6 +82,7 @@ extern "C" {
 
 #define VCD_METHOD_RESULT              "vcd_method_result"
 #define VCD_METHOD_ERROR               "vcd_method_error"
+#define VCD_METHOD_ERROR_TO_APP "vcd_method_error_to_app"
 #define VCD_METHOD_HELLO               "vcd_method_hello"
 #define VCD_METHOD_SET_SERVICE_STATE   "vcd_method_set_service_state"
 #define VCD_METHOD_SEND_MANAGER_PID    "vcd_method_send_manager_pid"
index 7811988..9ac4f0c 100755 (executable)
@@ -864,6 +864,46 @@ int vcdc_send_error_signal(int reason, char *err_msg)
        return 0;
 }
 
+int vcdc_send_error_signal_to_app(int pid, int reason, char *err_msg)
+{
+       if (NULL == err_msg) {
+               SLOG(LOG_ERROR, TAG_VCD, "[Dbus ERROR] Input parameter is NULL");
+               return VCD_ERROR_INVALID_PARAMETER;
+       }
+
+       if (VCD_ERROR_NONE != __dbus_check()) {
+               return VCD_ERROR_OPERATION_FAILED;
+       }
+
+       DBusError err;
+       dbus_error_init(&err);
+
+       SLOG(LOG_ERROR, TAG_VCD, "@@ Send error to app(%d)", pid);
+
+       DBusMessage* msg = __get_message(pid, VCD_METHOD_ERROR_TO_APP, VCD_CLIENT_TYPE_NORMAL);
+       if (NULL == msg) {
+               SLOG(LOG_ERROR, TAG_VCD, "[Dbus ERROR] Message is NULL");
+               return VCD_ERROR_OUT_OF_MEMORY;
+       }
+
+       dbus_message_append_args(msg, DBUS_TYPE_INT32, &pid, DBUS_TYPE_INT32, &reason, DBUS_TYPE_STRING, &err_msg, DBUS_TYPE_INVALID);
+
+       dbus_message_set_no_reply(msg, TRUE);
+
+       if (TRUE != dbus_connection_send(g_conn_sender, msg, NULL)) {
+               SLOG(LOG_ERROR, TAG_VCD, "[Dbus ERROR] Fail to Send");
+               dbus_message_unref(msg);
+               return VCD_ERROR_OPERATION_FAILED;
+       } else {
+               SLOG(LOG_DEBUG, TAG_VCD, "@@ Send error to app: pid(%d), reason(%d), Error Msg(%s)", pid, reason, err_msg);
+               dbus_connection_flush(g_conn_sender);
+       }
+
+       dbus_message_unref(msg);
+
+       return VCD_ERROR_NONE;
+}
+
 int vcdc_send_request_set_private_data(int pid, const char* key, const char* data)
 {
        if (0 != __dbus_check()) {
index a6d97a5..5fd1b7b 100644 (file)
@@ -58,6 +58,8 @@ int vcdc_send_error_signal(int reason, char *err_msg);
 
 int vcdc_send_error_signal_to_manager(int manager_pid, int reason, char *err_msg);
 
+int vcdc_send_error_signal_to_app(int pid, int reason, char *err_msg);
+
 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);
index 853597c..19b3950 100644 (file)
@@ -1114,7 +1114,14 @@ int vcd_send_error(vce_error_e error, const char* msg, void *user_data)
        }
 
        int ret = VCD_ERROR_NONE;
-       ret = vcdc_send_error_signal_to_manager(vcd_client_manager_get_pid(), error, error_msg);
+       if (VCE_ERROR_TTS_FAILED == error) {
+               int pid = g_current_uid / 1000;
+               ret = vcdc_send_error_signal_to_app(pid, error, error_msg);
+       } else {
+               ret = vcdc_send_error_signal_to_manager(vcd_client_manager_get_pid(), error, error_msg);
+               ecore_main_loop_thread_safe_call_async(__cancel_by_error, NULL);
+       }
+
        if (VCD_ERROR_NONE != ret) {
                SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to send error signal");
        }
@@ -1124,8 +1131,6 @@ int vcd_send_error(vce_error_e error, const char* msg, void *user_data)
                error_msg = NULL;
        }
 
-       ecore_main_loop_thread_safe_call_async(__cancel_by_error, NULL);
-
        return ret;
 }
 
@@ -2759,7 +2764,10 @@ int vcd_server_cancel_tts(int pid, int utt_id)
                SLOG(LOG_INFO, TAG_VCD, "[Server SUCCESS] request tts, pid(%d), utt_id(%d)", pid, utt_id);
        }
 
-       return 0;
+       /* Set service state */
+       vcd_config_set_service_state(VCD_STATE_READY);
+
+       return VCD_ERROR_NONE;
 }
 
 int vcd_server_get_tts_audio_format(int pid, int* rate, int* channel, int* audio_type)