Update error msg
[platform/core/uifw/voice-control.git] / server / vcd_server.c
old mode 100755 (executable)
new mode 100644 (file)
index 58d6d7d..fe5f960
 #include "vc_info_parser.h"
 #include "vcd_main.h"
 #include "vcd_server.h"
+#include "vcd_server_data.h"
 #include "vcd_client_data.h"
 
 #include "vcd_engine_agent.h"
 #include "vcd_config.h"
 #include "vcd_recorder.h"
 #include "vcd_dbus.h"
+#include "vce_internal.h"
 
 #include "voice_control_command_expand.h"
 #include "voice_control_common.h"
 
+#define CLIENT_CLEAN_UP_TIME 500
 /*
 * VC Server static variable
 */
@@ -40,6 +43,11 @@ static GList *g_proc_list = NULL;
 
 static Ecore_Timer *g_restart_timer = NULL;
 static Ecore_Timer *g_check_widget_client_timer = NULL;
+static Ecore_Timer *g_check_client_timer = NULL;
+
+static Ecore_Thread* g_tts_thread = NULL;
+static int g_current_uid = -1;
+static int g_current_utt_id = -1;
 
 /**
 * @brief Enumerations of send event type.
@@ -51,6 +59,7 @@ typedef enum {
 } vcd_send_event_type_e;
 
 static int __vcd_server_launch_manager_app();
+static int __start_internal_recognition();
 
 /*
 * VC Server Internal Functions
@@ -100,7 +109,8 @@ static Eina_Bool __restart_engine(void *data)
 
        SLOG(LOG_DEBUG, TAG_VCD, "[Server Success] Start engine");
 
-       if (VCD_RECOGNITION_MODE_RESTART_AFTER_REJECT == vcd_client_get_recognition_mode()) {
+       vcd_recognition_mode_e mode = vcd_client_get_recognition_mode();
+       if (VCD_RECOGNITION_MODE_RESTART_AFTER_REJECT == mode || VCD_RECOGNITION_MODE_RESTART_CONTINUOUSLY == mode) {
                vcd_config_set_service_state(VCD_STATE_RECORDING);
                vcdc_send_service_state(VCD_STATE_RECORDING);
        }
@@ -131,9 +141,9 @@ static int __server_recorder_callback(const void* data, const unsigned int lengt
                ecore_timer_add(0, __cancel_by_interrupt, NULL);
                /* Send error cb to manager */
                if (VCE_ERROR_OUT_OF_NETWORK == ret) {
-                       vcdc_send_error_signal_to_manager(vcd_client_manager_get_pid(), VCD_ERROR_TIMED_OUT, "Engine connection failed");
+                       vcdc_send_error_signal_to_manager(vcd_client_manager_get_pid(), VCD_ERROR_TIMED_OUT, "voice_framework.error.engine.set_recording_fail");
                } else {
-                       vcdc_send_error_signal_to_manager(vcd_client_manager_get_pid(), VCD_ERROR_OPERATION_FAILED, "Engine recognition failed");
+                       vcdc_send_error_signal_to_manager(vcd_client_manager_get_pid(), VCD_ERROR_OPERATION_FAILED, "voice_framework.error.engine.set_recording_fail");
                }
                return 0;
        }
@@ -307,7 +317,7 @@ static bool __vcd_launch_app(const char* result)
        }
 
        if (0 != g_slist_length(app_list)) {
-               /* releaes data */
+               /* release data */
                GSList *iter = NULL;
                vc_deactivated_app_s* temp_app = NULL;
                iter = g_slist_nth(app_list, 0);
@@ -425,9 +435,28 @@ static Eina_Bool __vcd_send_selected_result(void *data)
 
 int vcd_send_asr_result(vce_asr_result_event_e event, const char* asr_result, void *user_data)
 {
+       int ret = __vcd_server_launch_manager_app();
+       if (0 != ret) {
+               SECURE_SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to send ASR result : mgr_pid(%d), asr_result(%s)", vcd_client_manager_get_pid(), asr_result);
+               return ret;
+       }
+
        if (NULL != asr_result) {
                SECURE_SLOG(LOG_DEBUG, TAG_VCD, "[Server] ASR result - Event(%d), Text(%s)", event, asr_result);
-               vcdc_send_pre_result_to_manager(vcd_client_manager_get_pid(), event, asr_result);
+               ret = vcdc_send_pre_result_to_manager(vcd_client_manager_get_pid(), event, asr_result);
+               if (0 != ret) {
+                       SECURE_SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to send ASR result : mgr_pid(%d), asr_result(%s)", vcd_client_manager_get_pid(), asr_result);
+               }
+       }
+
+       return ret;
+}
+
+int vcd_send_specific_engine_result(const char* engine_app_id, const char* event, const char* result, void *user_info)
+{
+       if (NULL != result) {
+               SLOG(LOG_DEBUG, TAG_VCD, "[Server] specific engine result - Event(%s), Text(%s)", event, result);
+               vcdc_send_specific_engine_result_to_manager(vcd_client_manager_get_pid(), engine_app_id, event, result);
        }
 
        return VCD_ERROR_NONE;
@@ -457,9 +486,10 @@ static void* __recorder_stop(void *data)
 int vcd_send_result(vce_result_event_e event, int* result_id, int count, const char* all_result, const char* non_fixed_result, const char* nlu_result, const char* msg, int* user_info, void *user_data)
 {
        int ret = 0;
+       vcd_recognition_mode_e recognition_mode = vcd_client_get_recognition_mode();
 
        if (VCD_STATE_PROCESSING != vcd_config_get_service_state()) {
-               if (VCD_RECOGNITION_MODE_RESTART_CONTINUOUSLY != vcd_client_get_recognition_mode()) {
+               if (VCD_RECOGNITION_MODE_RESTART_CONTINUOUSLY != recognition_mode) {
                        SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Current state is not 'Processing' and mode is not 'Restart continuously'");
                        return VCD_ERROR_INVALID_STATE;
                }
@@ -471,40 +501,8 @@ int vcd_send_result(vce_result_event_e event, int* result_id, int count, const c
        SECURE_SLOG(LOG_INFO, TAG_VCD, "[Server] Event(%d), Text(%s) Nonfixed(%s) Msg(%s) Result count(%d)",
                event, all_result, non_fixed_result, msg, count);
 
-       SLOG(LOG_ERROR, TAG_VCD, "[Server] NLU result(%s)", nlu_result);
-
-       if (VCD_RECOGNITION_MODE_RESTART_AFTER_REJECT == vcd_client_get_recognition_mode()) {
-               if (VCE_RESULT_EVENT_REJECTED == event) {
-                       SLOG(LOG_DEBUG, TAG_VCD, "[Server] Restart by no or rejected result");
-                       /* If no result and restart option is ON */
-                       /* Send reject message */
-                       bool temp = vcd_client_manager_get_exclusive();
-                       vc_info_parser_set_result(all_result, event, msg, NULL, temp);
-                       ret = vcdc_send_result_to_manager(vcd_client_manager_get_pid(), VC_RESULT_TYPE_NOTIFICATION);
-                       if (0 != ret) {
-                               SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Fail to send result");
-                       }
+       SECURE_SLOG(LOG_ERROR, TAG_VCD, "[Server] NLU result(%s)", nlu_result);
 
-                       g_restart_timer = ecore_timer_add(0, __restart_engine, NULL);
-                       return ret;
-               }
-               SLOG(LOG_DEBUG, TAG_VCD, "[Server] Stop recorder due to success");
-               //vcd_recorder_stop();
-               ecore_main_loop_thread_safe_call_sync(__recorder_stop, NULL);
-       } else if (VCD_RECOGNITION_MODE_RESTART_CONTINUOUSLY == vcd_client_get_recognition_mode()) {
-               SLOG(LOG_DEBUG, TAG_VCD, "[Server] Restart continuously");
-               /* Restart option is ON */
-               g_restart_timer = ecore_timer_add(0, __restart_engine, NULL);
-               if (VCE_RESULT_EVENT_REJECTED == event) {
-                       bool temp = vcd_client_manager_get_exclusive();
-                       vc_info_parser_set_result(all_result, event, msg, NULL, temp);
-                       ret = vcdc_send_result_to_manager(vcd_client_manager_get_pid(), VC_RESULT_TYPE_NOTIFICATION);
-                       if (0 != ret) {
-                               SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Fail to send result");
-                       }
-                       return ret;
-               }
-       }
 #if 1
        /* if nlu_result is exist, Add command handle(is_action) into result list */
        /* Normal result */
@@ -514,7 +512,7 @@ int vcd_send_result(vce_result_event_e event, int* result_id, int count, const c
        vc_cmd_list_h vc_cmd_list = NULL;
 
        if (0 != vc_cmd_list_create(&vc_cmd_list)) {
-               SLOG(LOG_DEBUG, TAG_VCD, "[Server] Fail to create command list");
+               SLOG(LOG_INFO, TAG_VCD, "[Server] Fail to create command list");
                vcd_client_manager_set_exclusive(false);
                vcd_config_set_service_state(VCD_STATE_READY);
                vcdc_send_service_state(VCD_STATE_READY);
@@ -522,11 +520,12 @@ int vcd_send_result(vce_result_event_e event, int* result_id, int count, const c
        }
 
        /* priority filter */
-       /* system > exclusive > widget > foreground > system_background > background */
+       /* system > exclusive > widget > foreground > system_background > widget partial > foreground partial > background */
        int i = 0;
        int* filtered_id = (int*)calloc(count, sizeof(int));
        if (!filtered_id) {
                SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to allocate memory");
+               vc_cmd_list_destroy(vc_cmd_list, true);
                return VCD_ERROR_OUT_OF_MEMORY;
        }
        int filtered_count = 0;
@@ -588,6 +587,8 @@ int vcd_send_result(vce_result_event_e event, int* result_id, int count, const c
                                                                }
                                                        }
 
+                                                       // Set state manually, because the result is already handled in ASR result by client.
+                                                       // So, the daemon does not need to send the result to client.
                                                        vcd_client_manager_set_exclusive(false);
 
                                                        vcd_config_set_service_state(VCD_STATE_READY);
@@ -638,7 +639,7 @@ int vcd_send_result(vce_result_event_e event, int* result_id, int count, const c
                                temp_cmd = NULL;
                        }
                } else {
-                       SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] NOT found matached result(%d)", filtered_id[i]);
+                       SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] NOT found matched result(%d)", filtered_id[i]);
                }
        }
 
@@ -679,71 +680,228 @@ int vcd_send_result(vce_result_event_e event, int* result_id, int count, const c
        int result_count = 0;
        vc_cmd_list_get_count(vc_cmd_list, &result_count);
 
+       /* Handle the result list */
        if (0 == result_count) {
                /* No result */
+               vc_cmd_list_h widget_cmd_list = NULL;
+               vc_cmd_list_h foreground_cmd_list = NULL;
                if (NULL != all_result) {
                        SECURE_SLOG(LOG_DEBUG, TAG_VCD, "[Server] Engine result is no command : %s", all_result);
+                       int cnt = 0;
+
+                       if (0 != vc_cmd_list_create(&widget_cmd_list)) {
+                               SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to create widget command list handle");
+                               vc_cmd_list_destroy(vc_cmd_list, true);
+                               return VCD_ERROR_OUT_OF_MEMORY;
+                       }
+
+                       /* Get the list of widget type commands */
+                       vcd_client_append_cmd_from_type(VC_COMMAND_TYPE_WIDGET, widget_cmd_list);
+                       vc_cmd_list_get_count(widget_cmd_list, &cnt);
+                       if (0 < cnt) {
+                               /* Matched with widget command partially */
+                               vc_cmd_get_partially_matched_cmd_list(all_result, widget_cmd_list, vc_cmd_list, VC_SEARCH_NONE_LEVEL);
+                               vc_cmd_list_get_count(vc_cmd_list, &cnt);
+                               if (0 < cnt) {
+                                       top_priority = VC_COMMAND_PRIORITY_WIDGET;
+                                       SLOG(LOG_INFO, TAG_VCD, "[INFO] Partially matched widget command");
+                               }
+                       } else {
+                               if (0 != vc_cmd_list_create(&foreground_cmd_list)) {
+                                       SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to create foreground command list handle");
+                                       vc_cmd_list_destroy(vc_cmd_list, true);
+                                       vc_cmd_list_destroy(widget_cmd_list, true);
+                                       return VCD_ERROR_OUT_OF_MEMORY;
+                               }
+
+                               /* Get the list of foreground type commands */
+                               vcd_client_append_cmd_from_type(VC_COMMAND_TYPE_FOREGROUND, foreground_cmd_list);
+                               vc_cmd_list_get_count(foreground_cmd_list, &cnt);
+                               if (0 < cnt) {
+                                       /* Matched with foreground command partially */
+                                       vc_cmd_get_partially_matched_cmd_list(all_result, foreground_cmd_list, vc_cmd_list, VC_SEARCH_NONE_LEVEL);
+                                       vc_cmd_list_get_count(vc_cmd_list, &cnt);
+                                       if (0 < cnt) {
+                                               top_priority = VC_COMMAND_PRIORITY_FOREGROUND;
+                                               SLOG(LOG_INFO, TAG_VCD, "[INFO] Partially matched foreground command");
+                                       }
+                               }
+                               vc_cmd_list_destroy(foreground_cmd_list, true);
+                       }
+                       vc_cmd_list_destroy(widget_cmd_list, true);
                } else {
                        SLOG(LOG_DEBUG, TAG_VCD, "[Server] Engine result is NULL");
                }
-               bool temp = vcd_client_manager_get_exclusive();
-               vc_info_parser_set_result(all_result, event, msg, NULL, temp);
 
-               int pid = vcd_client_widget_get_foreground_pid();
-               if (-1 != pid) {
-                       SLOG(LOG_DEBUG, TAG_VCD, "[Server] Request tooltip hide");
-                       /* Send to hide tooltip */
-                       vcdc_send_show_tooltip(pid, false);
-               }
+               vc_cmd_list_get_count(vc_cmd_list, &result_count);
 
-               if (-1 != vcd_client_manager_get_pid()) {
-                       /* Manager client is available */
-                       if (0 != vcdc_send_result_to_manager(vcd_client_manager_get_pid(), VC_RESULT_TYPE_NORMAL)) {
-                               SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Fail to send result");
-                       }
-               }
+               // After running partial matching algorithm, if there is no result.
+               if (0 == result_count) {
+                       SLOG(LOG_DEBUG, TAG_VCD, "[Server] No commands even after partial matching");
 
-               vcd_client_manager_set_exclusive(false);
+                       bool temp = vcd_client_manager_get_exclusive();
+                       vc_info_parser_set_result(all_result, event, msg, NULL, temp);
 
-               return VCD_ERROR_NONE;
-       } else {
-               if (false == vcd_client_manager_get_exclusive()) {
                        int pid = vcd_client_widget_get_foreground_pid();
                        if (-1 != pid) {
                                SLOG(LOG_DEBUG, TAG_VCD, "[Server] Request tooltip hide");
+                               /* Send to hide tooltip */
                                vcdc_send_show_tooltip(pid, false);
                        }
 
-                       vc_info_parser_set_result(all_result, event, msg, vc_cmd_list, false);
-
                        if (-1 != vcd_client_manager_get_pid()) {
                                /* Manager client is available */
                                if (0 != vcdc_send_result_to_manager(vcd_client_manager_get_pid(), VC_RESULT_TYPE_NORMAL)) {
                                        SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Fail to send result");
                                }
-                       } else {
-                               SLOG(LOG_DEBUG, TAG_VCD, "[Server] Manager is NOT available. Send result to client directly");
-                               /* Send result to client */
-                               ecore_timer_add(0, __vcd_send_selected_result, NULL);
                        }
-               } else {
-                       /* exclusive command */
-                       vc_info_parser_set_result(all_result, event, msg, vc_cmd_list, true);
 
-                       if (-1 != vcd_client_manager_get_pid()) {
-                               /* Manager client is available */
-                               if (0 != vcdc_send_result_to_manager(vcd_client_manager_get_pid(), VC_RESULT_TYPE_NORMAL)) {
-                                       SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Fail to send result");
+                       vcd_client_manager_set_exclusive(false);
+                       vc_cmd_list_destroy(vc_cmd_list, true);
+
+                       return VCD_ERROR_NONE;
+               }
+
+               // Partial matching algorithm find some commands
+               event = VC_RESULT_EVENT_RESULT_SUCCESS;
+       }
+
+       // There are more than one result.
+       if (false == vcd_client_manager_get_exclusive()) {
+               vc_cmd_list_h temp_list = NULL;
+
+               /* Foreground, Widget, Background, System, System-Background */
+               if (top_priority >= VC_COMMAND_PRIORITY_BACKGROUND) {
+                       vc_cmd_list_h widget_cmd_list = NULL;
+                       vc_cmd_list_h foreground_cmd_list = NULL;
+                       int cnt = 0;
+
+                       if (0 != vc_cmd_list_create(&temp_list)) {
+                               SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to create widget command list handle");
+                               vc_cmd_list_destroy(vc_cmd_list, true);
+                               return VCD_ERROR_OUT_OF_MEMORY;
+                       }
+
+                       if (0 != vc_cmd_list_create(&widget_cmd_list)) {
+                               SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to create widget command list handle");
+                               vc_cmd_list_destroy(vc_cmd_list, true);
+                               vc_cmd_list_destroy(temp_list, true);
+                               return VCD_ERROR_OUT_OF_MEMORY;
+                       }
+
+                       /* Get the list of widget type commands */
+                       vcd_client_append_cmd_from_type(VC_COMMAND_TYPE_WIDGET, widget_cmd_list);
+                       vc_cmd_list_get_count(widget_cmd_list, &cnt);
+                       if (0 < cnt) {
+                               /* Matched with widget command partially */
+                               vc_cmd_get_partially_matched_cmd_list(all_result, widget_cmd_list, temp_list, VC_SEARCH_NONE_LEVEL);
+                               vc_cmd_list_get_count(temp_list, &cnt);
+                               if (0 < cnt) {
+                                       if (0 != vc_cmd_list_destroy(vc_cmd_list, true)) {
+                                               SLOG(LOG_WARN, TAG_VCD, "[WARNING] Fail to destroy list");
+                                       }
+                                       vc_cmd_list = temp_list;
+                                       top_priority = VC_COMMAND_PRIORITY_WIDGET;
+                                       event = VC_RESULT_EVENT_RESULT_SUCCESS;
+                                       SLOG(LOG_INFO, TAG_VCD, "[INFO] Partially matched widget command when background cmd exists");
                                }
                        } else {
-                               SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Manager is NOT available");
+                               if (0 != vc_cmd_list_create(&foreground_cmd_list)) {
+                                       SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to create foreground command list handle");
+                                       vc_cmd_list_destroy(vc_cmd_list, true);
+                                       vc_cmd_list_destroy(widget_cmd_list, true);
+                                       return VCD_ERROR_OUT_OF_MEMORY;
+                               }
+
+                               /* Get the list of foreground type commands */
+                               vcd_client_append_cmd_from_type(VC_COMMAND_TYPE_FOREGROUND, foreground_cmd_list);
+                               vc_cmd_list_get_count(foreground_cmd_list, &cnt);
+                               if (0 < cnt) {
+                                       /* Matched with foreground command partially */
+                                       vc_cmd_get_partially_matched_cmd_list(all_result, foreground_cmd_list, temp_list, VC_SEARCH_NONE_LEVEL);
+                                       vc_cmd_list_get_count(temp_list, &cnt);
+                                       if (0 < cnt) {
+                                               if (0 != vc_cmd_list_destroy(vc_cmd_list, true)) {
+                                                       SLOG(LOG_WARN, TAG_VCD, "[WARNING] Fail to destroy list");
+                                               }
+                                               vc_cmd_list = temp_list;
+                                               top_priority = VC_COMMAND_PRIORITY_FOREGROUND;
+                                               event = VC_RESULT_EVENT_RESULT_SUCCESS;
+                                               SLOG(LOG_INFO, TAG_VCD, "[INFO] Partially matched foreground command when background cmd exists");
+                                       }
+                               }
+                               vc_cmd_list_destroy(foreground_cmd_list, true);
                        }
+                       vc_cmd_list_destroy(widget_cmd_list, true);
+               }
 
-                       vcd_client_manager_set_exclusive(false);
+               int pid = vcd_client_widget_get_foreground_pid();
+               if (-1 != pid) {
+                       SLOG(LOG_DEBUG, TAG_VCD, "[Server] Request tooltip hide");
+                       vcdc_send_show_tooltip(pid, false);
                }
+
+               vc_info_parser_set_result(all_result, event, msg, vc_cmd_list, false);
+               vc_cmd_list_destroy(vc_cmd_list, true);
+
+               if (-1 != vcd_client_manager_get_pid()) {
+                       /* Manager client is available */
+                       if (0 != vcdc_send_result_to_manager(vcd_client_manager_get_pid(), VC_RESULT_TYPE_NORMAL)) {
+                               SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Fail to send result");
+                       }
+               } else {
+                       SLOG(LOG_DEBUG, TAG_VCD, "[Server] Manager is NOT available. Send result to client directly");
+                       ecore_timer_add(0, __vcd_send_selected_result, NULL);
+               }
+       } else {
+               /* exclusive command */
+               vc_info_parser_set_result(all_result, event, msg, vc_cmd_list, true);
+               vc_cmd_list_destroy(vc_cmd_list, true);
+
+               if (-1 != vcd_client_manager_get_pid()) {
+                       /* Manager client is available */
+                       if (0 != vcdc_send_result_to_manager(vcd_client_manager_get_pid(), VC_RESULT_TYPE_NORMAL)) {
+                               SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Fail to send result");
+                       }
+               } else {
+                       SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Manager is NOT available");
+               }
+
+               vcd_client_manager_set_exclusive(false);
        }
 
-       vc_cmd_list_destroy(vc_cmd_list, true);
+       if (VCD_RECOGNITION_MODE_RESTART_AFTER_REJECT == recognition_mode) {
+               if (VCE_RESULT_EVENT_REJECTED == event) {
+                       SLOG(LOG_DEBUG, TAG_VCD, "[Server] Restart by no or rejected result");
+                       /* If no result and restart option is ON */
+                       /* Send reject message */
+                       bool temp = vcd_client_manager_get_exclusive();
+                       vc_info_parser_set_result(all_result, event, msg, NULL, temp);
+                       ret = vcdc_send_result_to_manager(vcd_client_manager_get_pid(), VC_RESULT_TYPE_NOTIFICATION);
+                       if (0 != ret) {
+                               SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Fail to send result");
+                       }
+
+                       g_restart_timer = ecore_timer_add(0, __restart_engine, NULL);
+                       return ret;
+               }
+               SLOG(LOG_DEBUG, TAG_VCD, "[Server] Stop recorder due to success");
+               //vcd_recorder_stop();
+               ecore_main_loop_thread_safe_call_sync(__recorder_stop, NULL);
+       } else if (VCD_RECOGNITION_MODE_RESTART_CONTINUOUSLY == recognition_mode) {
+               SLOG(LOG_DEBUG, TAG_VCD, "[Server] Restart continuously");
+               /* Restart option is ON */
+               g_restart_timer = ecore_timer_add(0, __restart_engine, NULL);
+               if (VCE_RESULT_EVENT_REJECTED == event) {
+                       bool temp = vcd_client_manager_get_exclusive();
+                       vc_info_parser_set_result(all_result, event, msg, NULL, temp);
+                       ret = vcdc_send_result_to_manager(vcd_client_manager_get_pid(), VC_RESULT_TYPE_NOTIFICATION);
+                       if (0 != ret) {
+                               SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Fail to send result");
+                       }
+                       return ret;
+               }
+       }
 
        return VCD_ERROR_NONE;
 
@@ -820,7 +978,7 @@ int vcd_send_result(vce_result_event_e event, int* result_id, int count, const c
                                                temp_cmd->parameter = strdup(non_fixed_result);
                                        }
                                } else {
-                                       SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Command type is NOT vaild. Parameter (%s)", temp_cmd->parameter);
+                                       SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Command type is NOT valid. Parameter (%s)", temp_cmd->parameter);
                                }
                                break;
                        case VC_CMD_FORMAT_NONFIXED_AND_FIXED:
@@ -829,7 +987,7 @@ int vcd_send_result(vce_result_event_e event, int* result_id, int count, const c
                                                temp_cmd->command = strdup(non_fixed_result);
                                        }
                                } else {
-                                       SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Command type is NOT vaild. Command (%s)", temp_cmd->command);
+                                       SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Command type is NOT valid. Command (%s)", temp_cmd->command);
                                }
 
                                break;
@@ -843,7 +1001,7 @@ int vcd_send_result(vce_result_event_e event, int* result_id, int count, const c
                                vc_cmd_destroy((vc_cmd_h)temp_cmd);
                        }
                } else {
-                       SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] NOT found matached result(%d)", result_id[i]);
+                       SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] NOT found matched result(%d)", result_id[i]);
                }
        }
 
@@ -918,9 +1076,14 @@ int vcd_send_error(vce_error_e error, const char* msg, void *user_data)
        char* error_msg = NULL;
        if (NULL != msg) {
                error_msg = strdup(msg);
+               if (NULL == error_msg) {
+                       return VCD_ERROR_OUT_OF_MEMORY;
+               }
        }
 
-       if (0 != vcdc_send_error_signal_to_manager(vcd_client_manager_get_pid(), error, error_msg)) {
+       int ret = VCD_ERROR_NONE;
+       ret = vcdc_send_error_signal_to_manager(vcd_client_manager_get_pid(), error, error_msg);
+       if (VCD_ERROR_NONE != ret) {
                SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to send error signal");
        }
 
@@ -929,9 +1092,72 @@ int vcd_send_error(vce_error_e error, const char* msg, void *user_data)
                error_msg = NULL;
        }
 
-       return VCD_ERROR_NONE;
+       return ret;
 }
 
+/* for TTS feedback */
+int vcd_send_feedback_audio_format(int rate, vce_audio_channel_e channel, vce_audio_type_e audio_type)
+{
+       SLOG(LOG_INFO, TAG_VCD, "[Server DEBUG] Engine - Send TTS feedback audio format, g_current_uid(%d)", g_current_uid);
+
+       /* send TTS feedback audio format to VC manager */
+       int ret = VCD_ERROR_NONE;
+       int pid = g_current_uid / 1000;
+       if (-1 == g_current_uid || vcd_client_manager_get_pid() == pid) {
+               ret = vcdc_send_feedback_audio_format_to_manager(vcd_client_manager_get_pid(), rate, channel, audio_type);
+               if (VCD_ERROR_NONE != ret) {
+                       SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to send TTS feedback audio format to VC manager");
+               }
+       } else {
+               SLOG(LOG_INFO, TAG_VCD, "[Server INFO] Do not send TTS feedback audio format to VC manager");
+       }
+
+       return ret;
+}
+
+int vcd_send_feedback_streaming(vce_feedback_event_e event, char* buffer, int len)
+{
+       if (-1 == g_current_uid && VCE_FEEDBACK_EVENT_START == event) {
+               g_current_utt_id = (g_current_utt_id + 1) % 1000;
+               g_current_uid = vcd_client_manager_get_pid() * 1000 + g_current_utt_id;
+               SLOG(LOG_INFO, TAG_VCD, "[Server info] set current uid and utt_id as manager pid(%d)", vcd_client_manager_get_pid());
+       }
+
+       int ret = VCD_ERROR_NONE;
+       int pid = g_current_uid / 1000;
+       int utt_id = g_current_uid % 1000;
+
+       SLOG(LOG_INFO, TAG_VCD, "[Server DEBUG] Engine - Send TTS feedback streaming event(%d), uid(%d), is_mgr_client(%d)", event, g_current_uid, (pid == vcd_client_manager_get_pid() ? true : false));
+
+       if (pid == vcd_client_manager_get_pid()) {
+               /* send TTS feedback streaming to manager client */
+               ret = vcdc_send_feedback_streaming_to_manager(vcd_client_manager_get_pid(), pid, utt_id, event, buffer, len);
+               if (VCD_ERROR_NONE != ret) {
+                       SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to send TTS feedback streaming to manager client");
+               }
+       } else {
+               /* send TTS feedback streaming to client */
+               ret = vcdc_send_feedback_streaming(pid, utt_id, event, buffer, len);
+               if (VCD_ERROR_NONE != ret) {
+                       SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to send TTS feedback streaming to client");
+               }
+       }
+
+       if (VCE_FEEDBACK_EVENT_FINISH == event) {
+               /* reset current uid */
+               g_current_uid = -1;
+
+               /* Set service state to ready if state is synthesizing */
+               vcd_state_e state = vcd_config_get_service_state();
+               if (VCD_STATE_SYNTHESIZING == state) {
+                       vcd_config_set_service_state(VCD_STATE_READY);
+               }
+               SLOG(LOG_INFO, TAG_VCD, "[Server info] feedback streaming finish event, reset current uid & service state(%d)", vcd_config_get_service_state());
+       }
+       return ret;
+}
+
+
 /*
 * vcd server Interfaces
 */
@@ -1026,14 +1252,23 @@ int vcd_initialize(vce_request_callback_s *callback)
        vcd_client_manager_unset();
 
        vcd_config_set_service_state(VCD_STATE_READY);
-       vcdc_send_service_state(VCD_STATE_READY);
+//     vcdc_send_service_state(VCD_STATE_READY);
+
+       /* Set timer cleanup client all */
+       g_check_client_timer = ecore_timer_add(CLIENT_CLEAN_UP_TIME, vcd_cleanup_client_all, NULL);
+       if (NULL == g_check_client_timer) {
+               SLOG(LOG_WARN, TAG_VCD, "[Server Warning] Fail to create timer of client check");
+       }
+
+       g_current_uid = -1;
+       g_current_utt_id = -1;
 
        SLOG(LOG_ERROR, TAG_VCD, "[Server SUCCESS] initialize");
 
        return 0;
 }
 
-void vcd_finalize()
+bool vcd_finalize()
 {
        GList *iter = NULL;
        if (0 < g_list_length(g_proc_list)) {
@@ -1044,11 +1279,16 @@ void vcd_finalize()
                }
        }
 
-       if (g_restart_timer != NULL) {
+       if (NULL != g_restart_timer) {
                ecore_timer_del(g_restart_timer);
                g_restart_timer = NULL;
        }
 
+       if (NULL != g_check_client_timer) {
+               ecore_timer_del(g_check_client_timer);
+               g_check_client_timer = NULL;
+       }
+
        vcd_state_e state = vcd_config_get_service_state();
        if (VCD_STATE_READY != state) {
                if (VCD_STATE_RECORDING == state) {
@@ -1056,14 +1296,17 @@ void vcd_finalize()
                }
                vcd_engine_recognize_cancel();
        }
+
        if (0 != vcd_recorder_destroy()) {
                SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to destroy recorder");
+               return false;
        } else {
                SLOG(LOG_DEBUG, TAG_VCD, "[Server] destroy recorder");
        }
 
        if (0 != vcd_engine_agent_release()) {
                SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to release engine");
+               return false;
        } else {
                SLOG(LOG_DEBUG, TAG_VCD, "[Server] release engine");
        }
@@ -1075,14 +1318,18 @@ void vcd_finalize()
 
        SLOG(LOG_ERROR, TAG_VCD, "[Server] mode finalize");
 
-       return;
+       return true;
 }
 
 static Eina_Bool __finalize_quit_ecore_loop(void *data)
 {
-       SLOG(LOG_ERROR, TAG_VCD, "[Server] quit ecore main loop");
-       ecore_main_loop_quit();
-       return EINA_FALSE;
+       bool ret = vcd_finalize();
+       if (false == ret) {
+               return EINA_TRUE;
+       } else {
+               ecore_main_loop_quit();
+               return EINA_FALSE;
+       }
 }
 
 static void __read_proc()
@@ -1321,7 +1568,8 @@ int vcd_server_mgr_initialize(int pid)
        }
 
        /* Add client information to client manager */
-       if (0 != vcd_client_manager_set(pid)) {
+       int ret = vcd_client_manager_set(pid);
+       if (0 != ret) {
                SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to add manager");
                return VCD_ERROR_OPERATION_FAILED;
        }
@@ -1468,7 +1716,7 @@ int vcd_server_mgr_set_client_info(int pid)
 
 static int __reset_waiting_for_widget_recording(void)
 {
-       SLOG(LOG_ERROR, TAG_VCD, "[Server] Reet waiting for widget recording");
+       SLOG(LOG_ERROR, TAG_VCD, "[Server] Reset waiting for widget recording");
        // Delete timer to check that widget client is terminated
        if (g_check_widget_client_timer) {
                ecore_timer_del(g_check_widget_client_timer);
@@ -1479,6 +1727,7 @@ static int __reset_waiting_for_widget_recording(void)
        return 0;
 }
 
+#if 0
 static Eina_Bool __send_waiting_timeout_error_to_manager(void* data)
 {
        intptr_t ppid = (intptr_t)data;
@@ -1489,6 +1738,21 @@ static Eina_Bool __send_waiting_timeout_error_to_manager(void* data)
        vcdc_send_error_signal_to_manager(vcd_client_manager_get_pid(), VCD_ERROR_OPERATION_FAILED, "voice_engine.error.proc_fail");
        return EINA_FALSE;
 }
+#else
+static Eina_Bool __send_waiting_timeout_start_recording(void* data)
+{
+       intptr_t ppid = (intptr_t)data;
+       int pid = (int)ppid;
+       SLOG(LOG_ERROR, TAG_VCD, "Widget client didn't send to start recording, pid(%d)", pid);
+
+       int ret = __start_internal_recognition();
+       if (0 != ret) {
+               SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to start recognition : %d", ret);
+               return ret;
+       }
+       return EINA_FALSE;
+}
+#endif
 
 static int __set_waiting_for_widget_recording(int pid)
 {
@@ -1497,7 +1761,7 @@ static int __set_waiting_for_widget_recording(int pid)
        // Check if the app included widget client is terminated or not. If it is terminated, vcd_server_widget_finalize() function will be called
        // In that function, it will start recording
        intptr_t ppid = (intptr_t)pid;
-       g_check_widget_client_timer = ecore_timer_add(2.0, __send_waiting_timeout_error_to_manager, (void*)ppid);
+       g_check_widget_client_timer = ecore_timer_add(2.0, __send_waiting_timeout_start_recording, (void*)ppid);
 
        // Set flag to wait for recording from widget client
        vcd_client_widget_set_waiting_for_recording(pid, true);
@@ -1514,7 +1778,7 @@ static int __start_internal_recognition()
                /* Send error cb to manager */
                int pid = vcd_client_widget_get_foreground_pid();
                if (-1 != pid)
-                       vcdc_send_error_signal_to_manager(vcd_client_manager_get_pid(), VCD_ERROR_OPERATION_FAILED, "voice_engine.error.proc_fail");
+                       vcdc_send_error_signal_to_manager(vcd_client_manager_get_pid(), VCD_ERROR_OPERATION_FAILED, "voice_framework.error.vcfw.collect_command_fail");
                return VCD_ERROR_OPERATION_FAILED;
        }
 
@@ -1525,7 +1789,7 @@ static int __start_internal_recognition()
                /* Send error cb to manager */
                int pid = vcd_client_widget_get_foreground_pid();
                if (-1 != pid)
-                       vcdc_send_error_signal_to_manager(vcd_client_manager_get_pid(), VCD_ERROR_OPERATION_FAILED, "voice_engine.error.proc_fail");
+                       vcdc_send_error_signal_to_manager(vcd_client_manager_get_pid(), VCD_ERROR_OPERATION_FAILED, "voice_framework.error.engine.set_commands_fail");
                return VCD_ERROR_OPERATION_FAILED;
        }
 
@@ -1545,7 +1809,7 @@ static int __start_internal_recognition()
                /* Send error cb to manager */
                int pid = vcd_client_widget_get_foreground_pid();
                if (-1 != pid)
-                       vcdc_send_error_signal_to_manager(vcd_client_manager_get_pid(), VCD_ERROR_OPERATION_FAILED, "voice_engine.error.proc_fail");
+                       vcdc_send_error_signal_to_manager(vcd_client_manager_get_pid(), VCD_ERROR_OPERATION_FAILED, "voice_framework.error.engine.start_fail");
                return VCD_ERROR_OPERATION_FAILED;
        }
 
@@ -1560,7 +1824,7 @@ static int __start_internal_recognition()
                /* Send error cb to manager */
                int pid = vcd_client_widget_get_foreground_pid();
                if (-1 != pid)
-                       vcdc_send_error_signal_to_manager(vcd_client_manager_get_pid(), VCD_ERROR_OPERATION_FAILED, "voice_engine.error.proc_fail");
+                       vcdc_send_error_signal_to_manager(vcd_client_manager_get_pid(), VCD_ERROR_OPERATION_FAILED, "voice_framework.error.vcfw.send_rc_fail");
                return ret;
        }
 #endif
@@ -1589,8 +1853,8 @@ int vcd_server_mgr_start(vcd_recognition_mode_e recognition_mode, bool exclusive
        /* 1. check current state */
        vcd_state_e state = vcd_config_get_service_state();
 
-       if (VCD_STATE_READY != state) {
-               SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Current state is not ready");
+       if (VCD_STATE_READY != state && VCD_STATE_SYNTHESIZING != state) {
+               SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Current state is not ready and not synthesizine, state(%d)", state);
                return VCD_ERROR_INVALID_STATE;
        }
        if (-1 == vcd_client_manager_get_pid()) {
@@ -1636,7 +1900,7 @@ int vcd_server_mgr_start(vcd_recognition_mode_e recognition_mode, bool exclusive
 
        int ret = __start_internal_recognition();
        if (0 != ret) {
-               SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to start recongition : %d", ret);
+               SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to start recognition : %d", ret);
                return ret;
        }
 
@@ -1827,6 +2091,30 @@ int vcd_server_mgr_get_private_data(int pid, const char* key, char** data)
        return ret;
 }
 
+int vcd_server_mgr_send_specific_engine_request(int pid, const char* engine_app_id, const char* event, const char* request)
+{
+       /* check if pid is valid */
+       if (false == vcd_client_manager_is_valid(pid)) {
+               SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] The manager pid(%d) is NOT valid", pid);
+               return VCD_ERROR_INVALID_PARAMETER;
+       }
+       vcd_state_e state = vcd_config_get_service_state();
+       if (VCD_STATE_READY != state && VCD_STATE_SYNTHESIZING != state) {
+               SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Current state is not ready and not synthesizing, state(%d)", state);
+               return VCD_ERROR_INVALID_STATE;
+       }
+
+       /* Get private data to engine */
+       int ret = vcd_engine_send_specific_engine_request(engine_app_id, event, request);
+       if (0 != ret) {
+               SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to set specific engine request : %d", ret);
+       } else {
+               SLOG(LOG_DEBUG, TAG_VCD, "[Server SUCCESS] Set specific engine request ");
+       }
+
+       return ret;
+}
+
 int vcd_server_mgr_do_action(int pid, int type, const char* action)
 {
        int ret = -1;
@@ -1838,12 +2126,12 @@ int vcd_server_mgr_do_action(int pid, int type, const char* action)
        }
 
        vcd_state_e state = vcd_config_get_service_state();
-       if (VCD_STATE_READY != state) {
-               SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Current state is not ready");
+       if (VCD_STATE_READY != state && VCD_STATE_SYNTHESIZING != state) {
+               SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Current state is not ready and not synthesizing, state(%d)", state);
                return VCD_ERROR_INVALID_STATE;
        }
 
-       /* Reqeust do action to engine */
+       /* Request do action to engine */
        if (VCD_SEND_EVENT_TYPE_TEXT == type)
                ret = vcd_engine_process_text(pid, action);
        else if (VCD_SEND_EVENT_TYPE_LIST_EVENT == type)
@@ -1914,6 +2202,92 @@ int vcd_server_mgr_disable_command_type(int pid, int cmd_type)
        return ret;
 }
 
+/* for TTS feedback */
+int vcd_server_mgr_start_feedback(void)
+{
+       /* check current state */
+       /* not Recording??? */
+
+       if (-1 == vcd_client_manager_get_pid()) {
+               SLOG(LOG_ERROR, TAG_VCD, "[Server] Manager is NOT available");
+               return VCD_ERROR_OPERATION_FAILED;
+       }
+
+       SLOG(LOG_DEBUG, TAG_VCD, "[Server] start TTS feedback");
+
+       /* check there is TTS buffer to be spoken */
+
+       return VCD_ERROR_NONE;
+}
+
+int vcd_server_mgr_stop_feedback(void)
+{
+       /* check current state */
+       /* not Recording??? */
+
+       if (-1 == vcd_client_manager_get_pid()) {
+               SLOG(LOG_ERROR, TAG_VCD, "[Server] Manager is NOT available");
+               return VCD_ERROR_OPERATION_FAILED;
+       }
+
+       SLOG(LOG_DEBUG, TAG_VCD, "[Server] stop TTS feedback");
+
+       return VCD_ERROR_NONE;
+}
+
+int vcd_server_mgr_send_audio_streaming(int pid, int event, unsigned char* buffer, unsigned int len)
+{
+       SLOG(LOG_DEBUG, TAG_VCD, "[DEBUG] Send Audio Streaming from Multi-assistant. event(%d), buffer(%p), len(%d)", event, &buffer, len);
+
+       int ret = 0;
+       if (VCD_AUDIO_STREAMING_EVENT_START == event) {
+               ret = vcd_recorder_start_streaming();
+               if (0 != ret) {
+                       SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to start streaming, ret(%d)", ret);
+                       return ret;
+               }
+       }
+
+       ret = vcd_recorder_send_streaming((const void*)buffer, (const unsigned int)len);
+       if (0 != ret) {
+               SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to start streaming, ret(%d)", ret);
+               return ret;
+       }
+
+       if (VCD_AUDIO_STREAMING_EVENT_FINISH == event) {
+               ret = vcd_recorder_stop_streaming();
+               if (0 != ret) {
+                       SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to stop streaming, ret(%d)", ret);
+                       return ret;
+               }
+       }
+
+       return VCD_ERROR_NONE;
+}
+
+int vcd_server_mgr_change_system_volume(int pid, vcd_system_volume_event_e system_volume_event)
+{
+       SLOG(LOG_DEBUG, TAG_VCD, "[DEBUG] change system volume, system volume event(%d)", system_volume_event);
+
+       int ret = 0;
+       if (VCD_SYSTEM_VOLUME_EVENT_CHANGE == system_volume_event) {
+               ret = vcd_recorder_change_system_volume();
+               if (0 != ret) {
+                       SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to change system volume, ret(%d)", ret);
+                       return ret;
+               }
+       } else if (VCD_SYSTEM_VOLUME_EVENT_RECOVER == system_volume_event) {
+               ret = vcd_recorder_recover_system_volume();
+               if (0 != ret) {
+                       SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to recover system volume, ret(%d)", ret);
+                       return ret;
+               }
+       }
+
+       return ret;
+}
+
+
 /*
 * VC Server Functions for Client
 */
@@ -1926,8 +2300,8 @@ int vcd_server_initialize(int pid)
 
        /* check if pid is valid */
        if (true == vcd_client_is_available(pid)) {
-               SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] The pid is already exist");
-               return VCD_ERROR_INVALID_PARAMETER;
+               SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] The pid is already exist");
+               return VCD_ERROR_NONE;
        }
 
        /* Add client information to client manager */
@@ -2061,26 +2435,66 @@ static int __vcd_server_launch_manager_app()
        return VCD_ERROR_NONE;
 }
 
-int vcd_server_dialog(int pid, const char* disp_text, const char* utt_text, int continuous)
+int vcd_server_set_server_dialog(int pid, const char* app_id, const char* credential)
 {
        /* check if pid is valid */
-       if (false == vcd_client_is_available(pid) && false == vcd_client_widget_is_available(pid)) {
+       if (false == vcd_client_is_available(pid)) {
                SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] pid is NOT valid ");
                return VCD_ERROR_INVALID_PARAMETER;
        }
 
-       int ret = __vcd_server_launch_manager_app();
+       int ret = vcd_engine_set_server_dialog(app_id, credential);
        if (0 != ret) {
-               SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to send dialog : mgr_pid(%d), pid(%d), disp_text(%s), utt_text(%s), continue(%d)", vcd_client_manager_get_pid(), pid, disp_text, utt_text, continuous);
+               SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to set server dialog, pid(%d), app_id(%s), ret(%d)", pid, app_id, ret);
+               vcd_client_set_server_dialog(pid, false);
                return ret;
        }
+       SLOG(LOG_ERROR, TAG_VCD, "[Success] Set server dialog, pid(%d), app_id(%s)", pid, app_id);
+
+       if (0 != strncmp(credential, "#NULL", strlen(credential))) {
+               ret = vcd_client_set_server_dialog(pid, true);
+               if (0 != ret)
+                       SLOG(LOG_DEBUG, TAG_VCD, "[Server] Set to true for server dialog, app_id(%s)", app_id);
+       } else {
+               ret = vcd_client_set_server_dialog(pid, false);
+               if (0 != ret)
+                       SLOG(LOG_DEBUG, TAG_VCD, "[Server] Set to false for server dialog, app_id(%s)", app_id);
+       }
+
+       return 0;
+}
 
-       ret = vcdc_send_dialog(vcd_client_manager_get_pid(), pid, disp_text, utt_text, continuous);
+int vcd_server_dialog(int pid, const char* disp_text, const char* utt_text, int continuous)
+{
+       /* check if pid is valid */
+       if (false == vcd_client_is_available(pid) && false == vcd_client_widget_is_available(pid)) {
+               SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] pid is NOT valid ");
+               return VCD_ERROR_INVALID_PARAMETER;
+       }
+
+       bool is_server_dialog = false;
+       int ret = vcd_client_get_server_dialog(pid, &is_server_dialog);
        if (0 != ret) {
-               SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to send dialog : mgr_pid(%d), pid(%d), disp_text(%s), utt_text(%s), continue(%d)", vcd_client_manager_get_pid(), pid, disp_text, utt_text, continuous);
-               return ret;
+               SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to get server dialog, pid(%d), ret(%d)", pid, ret);
        }
 
+       if (true == is_server_dialog) {
+               /* ++ Request tts event to engine */
+
+               /* -- Request tts event to engine */
+       } else {
+               ret = __vcd_server_launch_manager_app();
+               if (0 != ret) {
+                       SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to send dialog : mgr_pid(%d), pid(%d), disp_text(%s), utt_text(%s), continue(%d)", vcd_client_manager_get_pid(), pid, disp_text, utt_text, continuous);
+                       return ret;
+               }
+
+               ret = vcdc_send_dialog(vcd_client_manager_get_pid(), pid, disp_text, utt_text, continuous);
+               if (0 != ret) {
+                       SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to send dialog : mgr_pid(%d), pid(%d), disp_text(%s), utt_text(%s), continue(%d)", vcd_client_manager_get_pid(), pid, disp_text, utt_text, continuous);
+                       return ret;
+               }
+       }
        return 0;
 }
 
@@ -2101,6 +2515,176 @@ int vcd_server_is_system_command_valid(int pid, int* is_sys_cmd_valid)
        return 0;
 }
 
+static void __start_tts_request_thread(void* data, Ecore_Thread* thread)
+{
+       SLOG(LOG_DEBUG, TAG_VCD, "[SUCCESS] Start tts request thread");
+       vc_tts_text_data_s* tts_text_data = NULL;
+
+       while (1) {
+               int ret = -1;
+               int cnt = 0;
+
+               /* Get tts text data */
+               ret = vcd_data_get_first_tts_text_data(&tts_text_data);
+               if (0 != ret || NULL == tts_text_data) {
+                       /* empty queue */
+                       if (0 >= vcd_data_get_tts_text_data_size()) {
+                               SLOG(LOG_DEBUG, TAG_VCD, "[DEBUG] No tts text data");
+                               return;
+                       }
+                       SLOG(LOG_INFO, TAG_VCD, "[INFO] tts text data is just incoming");
+                       continue;
+               }
+
+               while (1) {
+                       vcd_state_e state = vcd_config_get_service_state();
+                       if (VCD_STATE_READY != state) {
+                               if (0 == cnt++ % 10)
+                                       SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Waiting to request TTS, state(%d)", state);
+                               usleep(100000);
+                               continue;
+                       }
+                       break;
+               }
+
+               /* Set service state to synthesizing */
+               vcd_config_set_service_state(VCD_STATE_SYNTHESIZING);
+
+               /* Set current uid */
+               g_current_uid = tts_text_data->uid;
+
+               /* Request tts to engine */
+               ret = vcd_engine_request_tts(tts_text_data->pid, tts_text_data->utt_id, tts_text_data->text, tts_text_data->language);
+               if (0 != ret) {
+                       SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to request tts : %d", ret);
+               } else {
+                       SLOG(LOG_DEBUG, TAG_VCD, "[Server SUCCESS] request tts, uid(%d) pid(%d), text(%s), language(%s), utt_id(%d)",
+                               tts_text_data->uid, tts_text_data->pid, tts_text_data->text, tts_text_data->language, tts_text_data->utt_id);
+               }
+               /* clear tts text data after use */
+               vcd_data_clear_tts_text_data(&tts_text_data);
+
+       }
+}
+
+static void __end_tts_request_thread(void* data, Ecore_Thread* thread)
+{
+       SLOG(LOG_DEBUG, TAG_VCD, "[SUCCESS] End tts request thread");
+       g_tts_thread = NULL;
+}
+
+int vcd_server_request_tts(int pid, const char* text, const char* language, int to_vcm, int* utt_id)
+{
+       /* check if pid is valid */
+       if (false == vcd_client_is_available(pid)) {
+               SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] pid is NOT valid ");
+               return VCD_ERROR_INVALID_PARAMETER;
+       }
+
+       vcd_state_e state = vcd_config_get_service_state();
+       if (VCD_STATE_READY != state && VCD_STATE_SYNTHESIZING != state) {
+               SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Current state is not ready, state(%d)", state);
+               return VCD_ERROR_INVALID_STATE;
+       }
+
+       int uid = -1;
+       g_current_utt_id = (g_current_utt_id + 1) % 1000;
+       *utt_id = g_current_utt_id;
+       if (0 == to_vcm) {
+               uid = pid * 1000 + g_current_utt_id;
+       } else {
+               uid = vcd_client_manager_get_pid() * 1000 + g_current_utt_id;
+       }
+       SLOG(LOG_INFO, TAG_VCD, "[Server INFO] pid(%d), text(%s), language(%s), to_vcm(%d), ", pid, text, language, to_vcm);
+       SLOG(LOG_INFO, TAG_VCD, "[Server INFO] current_uid(%d), current_utt_id(%d)", uid, g_current_utt_id);
+
+       vc_tts_text_data_s* tts_text_data;
+       tts_text_data = (vc_tts_text_data_s*)calloc(1, sizeof(vc_tts_text_data_s));
+       if (!tts_text_data) {
+               SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to callocate memory ");
+               return VCD_ERROR_OUT_OF_MEMORY;
+       }
+       tts_text_data->uid = uid;
+       tts_text_data->pid = pid;
+       tts_text_data->utt_id = g_current_utt_id;
+       tts_text_data->text = strdup(text);
+       tts_text_data->language = strdup(language);
+
+       int ret = vcd_data_add_tts_text_data(tts_text_data->uid, tts_text_data);
+       if (0 != ret) {
+               SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to add tts text data : %d", ret);
+       }
+
+       bool is_canceled = ecore_thread_check(g_tts_thread);
+       if (NULL == g_tts_thread || TRUE == is_canceled) {
+               SLOG(LOG_INFO, TAG_VCD, "[Server INFO] ecore thread run : start_tts_request_thread ");
+               g_tts_thread = ecore_thread_run(__start_tts_request_thread, __end_tts_request_thread, NULL, NULL);
+       }
+
+       return 0;
+}
+
+int vcd_server_cancel_tts(int pid, int utt_id)
+{
+       /* check if pid is valid */
+       if (false == vcd_client_is_available(pid)) {
+               SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] pid is NOT valid ");
+               return VCD_ERROR_INVALID_PARAMETER;
+       }
+
+       vcd_state_e state = vcd_config_get_service_state();
+       if (VCD_STATE_READY != state && VCD_STATE_SYNTHESIZING != state) {
+               SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Current state is not ready, state(%d)", state);
+               return VCD_ERROR_INVALID_STATE;
+       }
+
+       vc_tts_text_data_s* tts_text_data = NULL;
+
+       int uid = pid * 1000 + utt_id;
+       int ret = vcd_data_get_tts_text_data(uid, &tts_text_data);
+       if (0 != ret) {
+               SLOG(LOG_WARN, TAG_VCD, "[Server WARN] No data in vcd tts text queue");
+       } else {
+               SLOG(LOG_DEBUG, TAG_VCD, "[Server] Clear tts text data, pid(%d), utt_id(%d), text(%s)", pid, utt_id, tts_text_data->text);
+               vcd_data_clear_tts_text_data(&tts_text_data);
+       }
+
+       /* Request tts to engine */
+       ret = vcd_engine_cancel_tts(pid, utt_id);
+       if (0 != ret) {
+               SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to cancel tts : %d", ret);
+       } else {
+               SLOG(LOG_DEBUG, TAG_VCD, "[Server SUCCESS] request tts, pid(%d), utt_id(%d)", pid, utt_id);
+       }
+
+       return 0;
+}
+
+int vcd_server_get_tts_audio_format(int pid, int* rate, int* channel, int* audio_type)
+{
+       /* check if pid is valid */
+       if (false == vcd_client_is_available(pid)) {
+               SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] pid is NOT valid ");
+               return VCD_ERROR_INVALID_PARAMETER;
+       }
+
+       vcd_state_e state = vcd_config_get_service_state();
+       if (VCD_STATE_READY != state && VCD_STATE_SYNTHESIZING != state) {
+               SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Current state is not ready and not synthesizing, state(%d)", state);
+               return VCD_ERROR_INVALID_STATE;
+       }
+
+       /* Request tts to engine */
+       int ret = vcd_engine_get_tts_audio_format(rate, channel, audio_type);
+       if (0 != ret) {
+               SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to get tts audio format : %d", ret);
+       } else {
+               SLOG(LOG_DEBUG, TAG_VCD, "[Server SUCCESS] get tts audio format, pid(%d), rate(%d), channel(%d), audio_type(%d)", pid, *rate, *channel, *audio_type);
+       }
+
+       return ret;
+}
+
 #if 0
 int vcd_server_set_exclusive_command(int pid, bool value)
 {
@@ -2129,7 +2713,7 @@ int vcd_server_request_start(int pid, bool stop_by_silence)
 {
        /* check if pid is valid */
        if (false == vcd_client_is_available(pid)) {
-               SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] pid(%d) is NOT forground client", pid);
+               SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] pid(%d) is NOT foreground client", pid);
                return VCD_ERROR_INVALID_PARAMETER;
        }
 
@@ -2251,7 +2835,7 @@ static void __vcd_server_widget_start_recording(void *data)
        SLOG(LOG_ERROR, TAG_VCD, "[Server INFO] start recording");
 
        if (0 != __start_internal_recognition()) {
-               SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to start recongition");
+               SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to start recognition");
        }
 }
 
@@ -2308,10 +2892,10 @@ int vcd_server_widget_start_recording(int pid, bool widget_command)
                SLOG(LOG_WARN, TAG_VCD, "[Server] widget command is NOT available");
        }
 
-       SLOG(LOG_ERROR, TAG_VCD, "[Server] start internal recongition : %d", widget_command);
+       SLOG(LOG_ERROR, TAG_VCD, "[Server] start internal recognition : %d", widget_command);
        int ret = __start_internal_recognition();
        if (0 != ret) {
-               SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to start recongition : %d", ret);
+               SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to start recognition : %d", ret);
                ecore_timer_add(0, __vcd_request_show_tooltip, (void*)false);
        }
 
@@ -2450,13 +3034,13 @@ int vcd_get_foreach_command(vce_cmd_h vce_command, vce_command_cb callback, void
        return ret;
 }
 
-int vcd_get_command_count(vce_cmd_h vce_command)
+int vcd_get_command_count(vce_cmd_h vce_command, int* count)
 {
        SLOG(LOG_DEBUG, TAG_VCD, "[Server] Get command count");
 
        int ret = 0;
-       ret = vcd_engine_agent_get_command_count(vce_command);
-       if (0 > ret) {
+       ret = vcd_engine_agent_get_command_count(vce_command, count);
+       if (0 != ret) {
                SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to get command count : ret(%d)", ret);
        }
 
@@ -2508,7 +3092,7 @@ int vcd_get_private_data(const char* key, char** data)
        if (0 != ret) {
                SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to get private data from the manager client : ret(%d)", ret);
        } else {
-               SLOG(LOG_DEBUG, TAG_VCD, "[Server] Get private data from the manager client, key(%s), data(%s)", key, data);
+               SLOG(LOG_DEBUG, TAG_VCD, "[Server] Get private data from the manager client, key(%s), data(%s)", key, *data);
        }
 
        return ret;
@@ -2540,6 +3124,33 @@ int vcd_stop_recording()
        return ret;
 }
 
+int vcd_send_update_status(vce_update_event_e update_event, const char* msg)
+{
+       SLOG(LOG_DEBUG, TAG_VCD, "[Server] update status, update event(%d), msg(%s)", update_event, msg);
+
+       int ret = 0;
+       if (VCE_UPDATE_EVENT_START == update_event) {
+               if (VCD_STATE_RECORDING == vcd_config_get_service_state() || VCD_STATE_PROCESSING == vcd_config_get_service_state()) {
+                       ret = vcd_server_mgr_cancel();
+                       if (0 != ret) {
+                               SLOG(LOG_ERROR, TAG_VCD, "[Server Error] Fail to cancel, ret(%d)", ret);
+                               return ret;
+                       }
+               }
+               vcd_config_set_service_state(VCD_STATE_UPDATING);
+               vcdc_send_service_state(VCD_STATE_UPDATING);
+
+       } else if (VCE_UPDATE_EVENT_FINISH == update_event) {
+               vcd_config_set_service_state(VCD_STATE_READY);
+               vcdc_send_service_state(VCD_STATE_READY);
+
+       } else if (VCE_UPDATE_EVENT_FAIL == update_event) {
+               SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Update event : Fail - msg(%s)", msg);
+       }
+
+       return 0;
+}
+
 int vcd_set_private_data_set_cb(vce_private_data_set_cb callback_func)
 {
        SLOG(LOG_DEBUG, TAG_VCD, "[Server] Set private data set cb");
@@ -2579,3 +3190,50 @@ int vcd_set_nlu_base_info_requested_cb(vce_nlu_base_info_requested_cb callback_f
        return ret;
 }
 
+int vcd_set_specific_engine_request_cb(vce_specific_engine_request_cb callback_func)
+{
+       SLOG(LOG_DEBUG, TAG_VCD, "[Server] Set specific engine request cb");
+       int ret = 0;
+       ret = vcd_engine_agent_set_specific_engine_request_cb(callback_func);
+       if (0 != ret) {
+               SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to set specific engine request cb : ret(%d)", ret);
+       }
+
+       return ret;
+}
+
+int vcd_set_request_tts_cb(vce_request_tts_cb callback_func, void* user_data)
+{
+       SLOG(LOG_DEBUG, TAG_VCD, "[Server] Set request tts cb");
+       int ret = 0;
+       ret = vcd_engine_agent_set_request_tts_cb(callback_func, user_data);
+       if (0 != ret) {
+               SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to set request tts cb : ret(%d)", ret);
+       }
+
+       return ret;
+}
+
+int vcd_set_cancel_tts_cb(vce_cancel_tts_cb callback_func, void* user_data)
+{
+       SLOG(LOG_DEBUG, TAG_VCD, "[Server] Set cancel tts cb");
+       int ret = 0;
+       ret = vcd_engine_agent_set_cancel_tts_cb(callback_func, user_data);
+       if (0 != ret) {
+               SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to set cancel tts cb : ret(%d)", ret);
+       }
+
+       return ret;
+}
+
+int vcd_set_tts_audio_format_request_cb(vce_tts_audio_format_request_cb callback_func, void* user_data)
+{
+       SLOG(LOG_DEBUG, TAG_VCD, "[Server] Set tts audio format request cb");
+       int ret = 0;
+       ret = vcd_engine_agent_set_get_tts_audio_format_cb(callback_func, user_data);
+       if (0 != ret) {
+               SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to set tts audio format request : ret(%d)", ret);
+       }
+
+       return ret;
+}