Merge "Reset waiting flag when recognition starts by widget" into tizen
[platform/core/uifw/voice-control.git] / server / vcd_server.c
old mode 100644 (file)
new mode 100755 (executable)
index 5f4adca..65fb25b
 * limitations under the License.
 */
 
+#include <app_control.h>
+#include <app_manager.h>
 #include <dirent.h>
 #include <sound_manager.h>
 
+#include "vc_cmd_db.h"
 #include "vc_info_parser.h"
 #include "vcd_main.h"
 #include "vcd_server.h"
 #include "vcd_dbus.h"
 
 #include "voice_control_command_expand.h"
+#include "voice_control_common.h"
 
 /*
 * VC Server static variable
 */
-static bool    g_is_engine;
+static GList *g_proc_list = NULL;
+
+static Ecore_Timer *g_restart_timer = NULL;
+
+/**
+* @brief Enumerations of send event type.
+*/
+typedef enum {
+       VCD_SEND_EVENT_TYPE_TEXT,               /**< send text event to vc engine*/
+       VCD_SEND_EVENT_TYPE_LIST_EVENT,         /**< send list event to vc engine */
+       VCD_SEND_EVENT_TYPE_HAPTIC_EVENT        /**< send haptic event to vc engine */
+} vcd_send_event_type_e;
+
+static int __vcd_server_launch_manager_app();
 
 /*
 * VC Server Internal Functions
 */
 static Eina_Bool __stop_by_silence(void *data)
 {
-       SLOG(LOG_DEBUG, TAG_VCD, "===== Silence Detected ");
+       SLOG(LOG_DEBUG, TAG_VCD, "@@@ Silence Detected ");
 
        vcd_server_mgr_stop();
 
-       SLOG(LOG_DEBUG, TAG_VCD, "=====");
-       SLOG(LOG_DEBUG, TAG_VCD, "  ");
+       SLOG(LOG_DEBUG, TAG_VCD, "@@@");
        return EINA_FALSE;
 }
 
 static Eina_Bool __cancel_by_interrupt(void *data)
 {
-       SLOG(LOG_DEBUG, TAG_VCD, "===== Cancel by interrupt");
+       SLOG(LOG_DEBUG, TAG_VCD, "@@@ Cancel by interrupt");
 
        vcd_server_mgr_cancel();
 
-       SLOG(LOG_DEBUG, TAG_VCD, "=====");
-       SLOG(LOG_DEBUG, TAG_VCD, "  ");
+       SLOG(LOG_DEBUG, TAG_VCD, "@@@");
+       return EINA_FALSE;
+}
+
+static void __cancel_by_error(void *data)
+{
+       SLOG(LOG_DEBUG, TAG_VCD, "@@@ Cancel by error");
+
+       vcd_server_mgr_cancel();
+
+       SLOG(LOG_DEBUG, TAG_VCD, "@@@");
+       return;
+}
+
+static Eina_Bool __restart_engine(void *data)
+{
+       SLOG(LOG_DEBUG, TAG_VCD, "@@@ Restart by no result");
+
+       g_restart_timer = NULL;
+
+       /* Restart recognition */
+       int ret = vcd_engine_recognize_start(true);
+       if (0 != ret) {
+               SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to restart recognition : result(%d)", ret);
+               return EINA_FALSE;
+       }
+
+       SLOG(LOG_DEBUG, TAG_VCD, "[Server Success] Start engine");
+
+       if (VCD_RECOGNITION_MODE_RESTART_AFTER_REJECT == vcd_client_get_recognition_mode()) {
+               vcd_config_set_service_state(VCD_STATE_RECORDING);
+               vcdc_send_service_state(VCD_STATE_RECORDING);
+       }
+
+       SLOG(LOG_DEBUG, TAG_VCD, "[Server Success] Restart recognition");
+
+       SLOG(LOG_DEBUG, TAG_VCD, "@@@");
        return EINA_FALSE;
 }
 
 static int __server_recorder_callback(const void* data, const unsigned int length)
 {
        vcd_state_e state = vcd_config_get_service_state();
-       if (VCD_STATE_RECORDING != state) {
+       if (VCD_STATE_READY == state) {
+               SLOG(LOG_DEBUG, TAG_VCD, "[Server] Ready state, but recording");
+       } else if (VCD_STATE_PROCESSING == state) {
                return 0;
        }
 
-       vcp_speech_detect_e speech_detected = VCP_SPEECH_DETECT_NONE;
+       vce_speech_detect_e speech_detected = VCE_SPEECH_DETECT_NONE;
        int ret;
 
        ret = vcd_engine_recognize_audio(data, length, &speech_detected);
@@ -75,19 +128,43 @@ static int __server_recorder_callback(const void* data, const unsigned int lengt
                /* Error */
                SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to set recording data to engine(%d)", ret);
                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");
+               } else {
+                       vcdc_send_error_signal_to_manager(vcd_client_manager_get_pid(), VCD_ERROR_OPERATION_FAILED, "Engine recognition failed");
+               }
                return 0;
        }
 
-       if (VCP_SPEECH_DETECT_BEGIN == speech_detected) {
+       if (VCE_SPEECH_DETECT_BEGIN == speech_detected) {
                if (-1 != vcd_client_manager_get_pid()) {
                        /* Manager client is available */
                        if (0 != vcdc_send_speech_detected(vcd_client_manager_get_pid())) {
                                SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Fail to send speech detected");
                        }
                }
-       } else if (VCP_SPEECH_DETECT_END == speech_detected && vcd_client_get_slience_detection()) {
-               /* silence detected */
-               ecore_timer_add(0, __stop_by_silence, NULL);
+       } else if (VCE_SPEECH_DETECT_END == speech_detected) {
+               if (VCD_RECOGNITION_MODE_STOP_BY_SILENCE == vcd_client_get_recognition_mode()) {
+                       /* silence detected */
+                       ecore_timer_add(0, __stop_by_silence, NULL);
+               } else if (VCD_RECOGNITION_MODE_RESTART_AFTER_REJECT == vcd_client_get_recognition_mode()) {
+                       /* Stop engine recognition */
+                       int ret = vcd_engine_recognize_stop();
+                       if (0 != ret) {
+                               SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to stop recognition : %d", ret);
+                       }
+                       vcd_config_set_service_state(VCD_STATE_PROCESSING);
+                       vcdc_send_service_state(VCD_STATE_PROCESSING);
+
+                       SLOG(LOG_DEBUG, TAG_VCD, "[Server] Stop engine only by silence");
+               } else if (VCD_RECOGNITION_MODE_RESTART_CONTINUOUSLY == vcd_client_get_recognition_mode()) {
+                       /* Stop engine recognition */
+                       int ret = vcd_engine_recognize_stop();
+                       if (0 != ret) {
+                               SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to stop recognition : %d", ret);
+                       }
+               }
        }
 
        return 0;
@@ -95,17 +172,16 @@ static int __server_recorder_callback(const void* data, const unsigned int lengt
 
 void __server_recorder_interrupt_callback()
 {
-       SLOG(LOG_DEBUG, TAG_VCD, "===== Cancel by sound interrupt");
+       SLOG(LOG_DEBUG, TAG_VCD, "@@@ Cancel by sound interrupt");
 
        ecore_timer_add(0, __cancel_by_interrupt, NULL);
 
-       SLOG(LOG_DEBUG, TAG_VCD, "=====");
-       SLOG(LOG_DEBUG, TAG_VCD, "  ");
+       SLOG(LOG_DEBUG, TAG_VCD, "@@@");
 }
 
 static void __config_lang_changed_cb(const char* current_lang, void* user_data)
 {
-       SLOG(LOG_DEBUG, TAG_VCD, "===== Change language ");
+       SLOG(LOG_DEBUG, TAG_VCD, "@@@ Change language ");
 
        /* Current state is recording */
        vcd_state_e state = vcd_config_get_service_state();
@@ -120,18 +196,17 @@ static void __config_lang_changed_cb(const char* current_lang, void* user_data)
                SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to set language of engine : %d", ret);
        }
 
-       SLOG(LOG_DEBUG, TAG_VCD, "=====");
-       SLOG(LOG_DEBUG, TAG_VCD, "  ");
+       SLOG(LOG_DEBUG, TAG_VCD, "@@@");
 
        return;
 }
 
 static void __config_foreground_changed_cb(int previous, int current, void* user_data)
 {
-       SLOG(LOG_DEBUG, TAG_VCD, "===== Change foreground");
+       SLOG(LOG_DEBUG, TAG_VCD, "@@@ Change foreground");
 
        SLOG(LOG_DEBUG, TAG_VCD, "Foreground pid(%d)", current);
-       
+
        if (VC_NO_FOREGROUND_PID != current) {
                /* Foreground app is changed */
                vcd_state_e state = vcd_config_get_service_state();
@@ -141,73 +216,537 @@ static void __config_foreground_changed_cb(int previous, int current, void* user
                }
        }
 
-       SLOG(LOG_DEBUG, TAG_VCD, "=====");
-       SLOG(LOG_DEBUG, TAG_VCD, "  ");
+       SLOG(LOG_DEBUG, TAG_VCD, "@@@");
 
        return;
 }
 
+static int __vcd_activate_app_by_appcontrol(const char* appid)
+{
+       if (NULL == appid) {
+               SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Invalid parameter");
+               return VCD_ERROR_INVALID_PARAMETER;
+       }
+
+       int ret = -1;
+       app_control_h app_control = NULL;
+       ret = app_control_create(&app_control);
+       if (APP_CONTROL_ERROR_NONE == ret) {
+               // Set extra data
+               ret = app_control_add_extra_data(app_control, "voice_launch", "get_result");
+               if (APP_CONTROL_ERROR_NONE != ret) {
+                       SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to add extra data, ret(%d)", ret);
+                       app_control_destroy(app_control);
+                       return VCD_ERROR_OPERATION_FAILED;
+               }
+               // Set an app ID.
+               ret = app_control_set_app_id(app_control, appid);
+               if (APP_CONTROL_ERROR_NONE != ret) {
+                       SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to set app id, ret(%d)", ret);
+                       app_control_destroy(app_control);
+                       return VCD_ERROR_OPERATION_FAILED;
+               }
+               // Sent launch request
+               ret = app_control_send_launch_request(app_control, NULL, NULL);
+               if (APP_CONTROL_ERROR_NONE != ret) {
+                       SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to send launch request, ret(%d)", ret);
+                       app_control_destroy(app_control);
+                       return VCD_ERROR_OPERATION_FAILED;
+               }
+               // Destroy app control
+               ret = app_control_destroy(app_control);
+               if (APP_CONTROL_ERROR_NONE != ret) {
+                       SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to destroy, ret(%d)", ret);
+                       return VCD_ERROR_OPERATION_FAILED;
+               }
+       }
+       return VCD_ERROR_NONE;
+}
+
+static int __vcd_resume_app(const char* appid)
+{
+       app_context_h app_context = NULL;
+       int ret = app_manager_get_app_context(appid, &app_context);
+       if (APP_MANAGER_ERROR_NONE != ret) {
+               SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to get app_context, ret(%d), appid(%s)", ret, appid);
+               return VCD_ERROR_OPERATION_FAILED;
+       }
+
+       ret = app_manager_resume_app(app_context);
+       if (APP_MANAGER_ERROR_NONE != ret) {
+               SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to resume app, ret(%d), appid(%s)", ret, appid);
+               return VCD_ERROR_OPERATION_FAILED;
+       }
+       return VCD_ERROR_NONE;
+}
+
+static bool __vcd_is_package_installed(const char* appid)
+{
+       app_info_h app_info = NULL;
+       int ret = app_manager_get_app_info(appid, &app_info);
+       if (APP_MANAGER_ERROR_NONE != ret || NULL == app_info)
+               return false;
+       ret = app_info_destroy(app_info);
+       if (APP_MANAGER_ERROR_NONE != ret)
+               SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to destroy app_info, ret(%d)", ret);
+       return true;
+}
+
+static bool __vcd_launch_app(const char* result)
+{
+       if (NULL == result) {
+               SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Invalid parameter");
+               return VCD_ERROR_INVALID_PARAMETER;
+       }
+
+       GSList* app_list = NULL;
+       if (0 != vc_db_get_appid_list(result, &app_list)) {
+               SLOG(LOG_ERROR, TAG_VCD, "[ERROR] result text is NULL");
+               return VCD_ERROR_INVALID_PARAMETER;
+       }
+
+       if (0 != g_slist_length(app_list)) {
+               /* releaes data */
+               GSList *iter = NULL;
+               vc_deactivated_app_s* temp_app = NULL;
+               iter = g_slist_nth(app_list, 0);
+
+               while (NULL != iter) {
+                       temp_app = iter->data;
+
+                       if (NULL != temp_app) {
+                               if (NULL != temp_app->appid) {
+                                       int ret = -1;
+                                       bool running = false;
+                                       ret = app_manager_is_running(temp_app->appid, &running);
+                                       if (APP_MANAGER_ERROR_NONE != ret) {
+                                               SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to check running with appid(%s)", temp_app->appid);
+                                               free(temp_app->appid);
+                                               temp_app->appid = NULL;
+                                               free(temp_app);
+                                               temp_app = NULL;
+                                               return VCD_ERROR_OPERATION_FAILED;
+                                       }
+                                       if (false == running) {
+                                               int tmp_ret = __vcd_is_package_installed(temp_app->appid);
+                                               if (false == tmp_ret) {
+                                                       SLOG(LOG_WARN, TAG_VCD, "[WARNING] app is not installed, appid(%s)", temp_app->appid);
+                                               } else {
+                                                       ret = __vcd_activate_app_by_appcontrol(temp_app->appid);
+                                                       if (0 != ret) {
+                                                               SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to activate app");
+                                                               free(temp_app->appid);
+                                                               temp_app->appid = NULL;
+                                                               free(temp_app);
+                                                               temp_app = NULL;
+                                                               return ret;
+                                                       }
+                                                       SLOG(LOG_ERROR, TAG_VCD, "Launch app: appid(%s) result(%s)", temp_app->appid, result);
+                                               }
+                                       } else {
+                                               ret = __vcd_resume_app(temp_app->appid);
+                                               if (0 != ret) {
+                                                       SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to resume app");
+                                                       free(temp_app->appid);
+                                                       temp_app->appid = NULL;
+                                                       free(temp_app);
+                                                       temp_app = NULL;
+                                                       return ret;
+                                               }
+                                               SLOG(LOG_ERROR, TAG_VCD, "Resume app: appid(%s) result(%s)", temp_app->appid, result);
+                                       }
+                                       free(temp_app->appid);
+                                       temp_app->appid = NULL;
+                               }
+                               free(temp_app);
+                               temp_app = NULL;
+                       }
+                       iter = g_slist_next(iter);
+               }
+               app_list = NULL;
+       }
+
+       return VCD_ERROR_NONE;
+}
+
 static Eina_Bool __vcd_send_selected_result(void *data)
 {
        GSList* pid_list = NULL;
-       if (0 != vc_info_parser_get_result_pid_list(&pid_list)) {
+       const char* result = vcd_client_manager_get_result_text();
+
+       if (0 != vc_info_parser_get_result_pid_list(&pid_list, result)) {
                SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Fail to get pid list. No result");
-       }
-       else {
-               if (0 < g_slist_length(pid_list)){
+       } else {
+               if (0 < g_slist_length(pid_list)) {
                        GSList* iter = NULL;
                        vc_cmd_s* temp_cmd = NULL;
                        int ret = 0;
-                       int count = 0;
+                       int pre_pid = -1;
+                       int pre_type = -1;
 
                        iter = g_slist_nth(pid_list, 0);
                        while (NULL != iter) {
                                temp_cmd = iter->data;
 
-                               if (NULL != temp_cmd) {
-                                       count = 0;
-                                       do {
+                               if (NULL != temp_cmd && (pre_pid != temp_cmd->pid || pre_type == VC_COMMAND_TYPE_WIDGET || temp_cmd->type == VC_COMMAND_TYPE_WIDGET)) {
+                                       /* Launch deactivated several apps that is matched with result */
+                                       ret = __vcd_launch_app(result);
+                                       if (0 != ret) {
+                                               SLOG(LOG_ERROR, TAG_VCD, "Fail to launch or resume app, ret(%d) result(%s)", ret, result);
+                                       } else {
                                                /* send result noti */
-                                               ret = vcdc_send_result(temp_cmd->pid, temp_cmd->type);
+                                               ret = vcdc_send_result(temp_cmd->pid, vcd_client_manager_get_pid(), temp_cmd->type);
                                                if (0 != ret) {
-                                                       SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Fail to send result");
-                                                       if (VCD_ERROR_TIMED_OUT != ret) {
-                                                               break;
-                                                       }
+                                                       SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Fail to send result, ret(%d)", ret);
+                                                       break;
                                                } else {
-                                                       SLOG(LOG_DEBUG, TAG_VCD, "[Server] Send result : pid(%d) type(%d)", temp_cmd->pid, temp_cmd->type);
+                                                       SLOG(LOG_ERROR, TAG_VCD, "[Server] Send result : pid(%d) type(%d)", temp_cmd->pid, temp_cmd->type);
+                                                       pre_pid = temp_cmd->pid;
+                                                       pre_type = temp_cmd->type;
                                                }
-                                               count++;
-
-                                               if (100 == count)       break;
-                                               /* While is retry code */
-                                       } while (0 != ret);
+                                       }
                                        free(temp_cmd);
+                                       temp_cmd = NULL;
                                }
-
                                pid_list = g_slist_remove_link(pid_list, iter);
                                iter = g_slist_nth(pid_list, 0);
                        }
                }
        }
 
-       vcd_config_set_service_state(VCD_STATE_READY);
+       if (VCD_RECOGNITION_MODE_RESTART_CONTINUOUSLY != vcd_client_get_recognition_mode()) {
+               vcd_config_set_service_state(VCD_STATE_READY);
+               vcdc_send_service_state(VCD_STATE_READY);
+       }
 
        return EINA_FALSE;
 }
 
-static void __vcd_server_result_cb(vcp_result_event_e event, int* result_id, int count, 
-                                  const char* all_result, const char* non_fixed_result, const char* msg, void *user_data)
+int vcd_send_asr_result(vce_asr_result_event_e event, const char* asr_result, void *user_data)
 {
+       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);
+       }
+
+       return VCD_ERROR_NONE;
+}
+
+int vcd_send_nlg_result(const char* nlg_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 dialog : mgr_pid(%d), nlg_result(%s)", vcd_client_manager_get_pid(), nlg_result);
+               return ret;
+       }
+
+       SLOG(LOG_ERROR, TAG_VCD, "[Server] send dialog : mgr_pid(%d), nlg_result(%s)", vcd_client_manager_get_pid(), nlg_result);
+       ret = vcdc_send_dialog(vcd_client_manager_get_pid(), -1, nlg_result, NULL, 0); //0: VC_DIALOG_END
+       if (0 != ret)
+               SECURE_SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to send dialog : mgr_pid(%d), nlg_result(%s)", vcd_client_manager_get_pid(), nlg_result);
+       return ret;
+}
+
+static void* __recorder_stop(void *data)
+{
+       vcd_recorder_stop();
+       return NULL;
+}
+
+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;
+
        if (VCD_STATE_PROCESSING != vcd_config_get_service_state()) {
-               SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Current state is not 'Processing'");
-               return;
+               if (VCD_RECOGNITION_MODE_RESTART_CONTINUOUSLY != vcd_client_get_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;
+               }
        }
 
        vc_info_parser_unset_result(vcd_client_manager_get_exclusive());
+       vcd_client_manager_set_result_text(all_result);
 
-       SLOG(LOG_DEBUG, TAG_VCD, "[Server] Event(%d), Text(%s) Nonfixed(%s) Msg(%s) Result count(%d)", event, all_result, non_fixed_result, msg, count);
+       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");
+                       }
+
+                       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 */
+       SLOG(LOG_DEBUG, TAG_VCD, "[Server] @ Get engine result @");
+
+       vc_cmd_s* temp_cmd = NULL;
+       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");
+               vcd_client_manager_set_exclusive(false);
+               vcd_config_set_service_state(VCD_STATE_READY);
+               vcdc_send_service_state(VCD_STATE_READY);
+               return VCD_ERROR_NONE;
+       }
+
+       /* priority filter */
+       /* system > exclusive > widget > foreground > system_background > 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");
+               return VCD_ERROR_OUT_OF_MEMORY;
+       }
+       int filtered_count = 0;
+       int top_priority = VC_COMMAND_PRIORITY_BACKGROUND;
+       for (i = 0; i < count; i++) {
+               SLOG(LOG_INFO, TAG_VCD, "[Server]   [%d] Result id(%d)", i, result_id[i]);
+
+               if (0 > result_id[i]) {
+                       SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Result ID(%d) is NOT valid", result_id[i]);
+                       continue;
+               }
+
+               ret = vcd_client_get_cmd_from_result_id(result_id[i], &temp_cmd);
+               if (0 == ret && NULL != temp_cmd) {
+                       if (top_priority == temp_cmd->priority) {
+                               filtered_id[filtered_count] = result_id[i];
+                               filtered_count++;
+                       } else if (top_priority > temp_cmd->priority) {
+                               filtered_id[0] = result_id[i];
+                               filtered_count = 1;
+                               top_priority = temp_cmd->priority;
+                       }
+
+                       vc_cmd_destroy((vc_cmd_h)temp_cmd);
+                       temp_cmd = NULL;
+               }
+       }
+
+       // ASR consume
+       if (top_priority >= VC_COMMAND_PRIORITY_WIDGET) {
+               int pid = vcd_client_widget_get_foreground_pid();
+               if (-1 != pid) {
+                       if (NULL != all_result) {
+                               vc_info_parser_set_result(all_result, event, msg, NULL, false);
+                               bool enable = false;
+                               vcd_client_widget_get_asr_result_enabled(pid, &enable);
+                               if (true == enable) {
+                                       SLOG(LOG_DEBUG, TAG_VCD, "[Server] Send ASR result to Widget client");
+                                       bool is_consumed = false;
+                                       if (NULL != user_info) {
+                                               *user_info = 0x00;
+                                       }
+                                       if (0 != vcdc_send_asr_result(pid, event, all_result, VC_COMMAND_TYPE_WIDGET, &is_consumed)) {
+                                               SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to send asr result");
+                                       } else {
+                                               SLOG(LOG_DEBUG, TAG_VCD, "[Server] ASR result is consumed(%d)", is_consumed);
+                                               if (true == is_consumed) {
+                                                       if (NULL != user_info) {
+                                                               *user_info = 0x01;
+                                                               SLOG(LOG_ERROR, TAG_VCD, "[Server] Send whether ASR result is consumed or not (%d)", *user_info);
+                                                       }
+                                                       vcdc_send_show_tooltip(pid, false);
+                                                       if (-1 != vcd_client_manager_get_pid()) {
+                                                               /* Manager client is available */
+                                                               vc_info_parser_unset_result(false);
+                                                               vc_info_parser_set_result(all_result, VC_RESULT_EVENT_RESULT_SUCCESS, msg, NULL, false);
+                                                               if (0 != vcdc_send_result_to_manager(vcd_client_manager_get_pid(), VC_RESULT_TYPE_NOTIFICATION)) {
+                                                                       SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Fail to send result");
+                                                               }
+                                                       }
+
+                                                       vcd_client_manager_set_exclusive(false);
+
+                                                       vcd_config_set_service_state(VCD_STATE_READY);
+                                                       vcdc_send_service_state(VCD_STATE_READY);
+                                                       vc_cmd_list_destroy(vc_cmd_list, true);
+                                                       if (NULL != filtered_id) {
+                                                               free(filtered_id);
+                                                               filtered_id = NULL;
+                                                       }
+                                                       return VCD_ERROR_NONE;
+                                               }
+                                       }
+                               }
+                       }
+               }
+       }
+
+       int is_action = 0;
+       for (i = 0; i < filtered_count; i++) {
+               SLOG(LOG_INFO, TAG_VCD, "[Server]   [%d] Filtered Result id(%d)", i, filtered_id[i]);
+
+               if (filtered_id[i] < 0) {
+                       SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Filtered ID(%d) is NOT valid", filtered_id[i]);
+                       continue;
+               }
+
+               ret = vcd_client_get_cmd_from_result_id(filtered_id[i], &temp_cmd);
+               if (0 == ret && NULL != temp_cmd) {
+                       switch (temp_cmd->format) {
+                       case VC_CMD_FORMAT_FIXED:
+                       case VC_CMD_FORMAT_FIXED_AND_VFIXED:
+                       case VC_CMD_FORMAT_VFIXED_AND_FIXED:
+                       case VC_CMD_FORMAT_PARTIAL:
+                       case VC_CMD_FORMAT_FIXED_AND_NONFIXED:
+                       case VC_CMD_FORMAT_NONFIXED_AND_FIXED:
+                               break;
+                       case VC_CMD_FORMAT_ACTION:
+                               is_action = 1;
+                               break;
+                       default:
+                               SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Unknown command type : %d", temp_cmd->type);
+                       }
+
+                       temp_cmd->id = i;
+                       if (0 != vc_cmd_list_add(vc_cmd_list, (vc_cmd_h)temp_cmd)) {
+                               SLOG(LOG_DEBUG, TAG_VCD, "Fail to add command to list");
+                               vc_cmd_destroy((vc_cmd_h)temp_cmd);
+                               temp_cmd = NULL;
+                       }
+               } else {
+                       SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] NOT found matached result(%d)", filtered_id[i]);
+               }
+       }
+
+       if (NULL != filtered_id) {
+               free(filtered_id);
+               filtered_id = NULL;
+       }
+
+       if (NULL != nlu_result) {
+               SECURE_SLOG(LOG_INFO, TAG_VCD, "[Server] NLU (%s)", nlu_result);
+               vc_info_parser_set_nlu_result(nlu_result);
+               if (0 == is_action) {
+                       vc_cmd_h nlu_cmd;
+                       if (0 != vc_cmd_create(&nlu_cmd)) {
+                               SLOG(LOG_ERROR, TAG_VCD, "Fail to nlu cmd create");
+                       } else {
+                               if (0 != vc_cmd_set_type(nlu_cmd, VC_COMMAND_TYPE_SYSTEM)) {
+                                       SLOG(LOG_ERROR, TAG_VCD, "Fail to set type");
+                               }
+                               if (0 != vc_cmd_set_pid(nlu_cmd, vcd_client_manager_get_pid())) {
+                                       SLOG(LOG_ERROR, TAG_VCD, "Fail to set pid");
+                               }
+                               if (0 != vc_cmd_set_format(nlu_cmd, VC_CMD_FORMAT_ACTION)) {
+                                       SLOG(LOG_ERROR, TAG_VCD, "Fail to set format");
+                               }
+                               if (0 != vc_cmd_list_add(vc_cmd_list, nlu_cmd)) {
+                                       SLOG(LOG_ERROR, TAG_VCD, "Fail to add nlu cmd to list");
+                                       vc_cmd_destroy(nlu_cmd);
+                               }
+                       }
+               }
+       }
+
+       vc_cmd_print_list(vc_cmd_list);
+
+       SLOG(LOG_DEBUG, TAG_VCD, "[Server] @@@@");
+
+       int result_count = 0;
+       vc_cmd_list_get_count(vc_cmd_list, &result_count);
+
+       if (0 == result_count) {
+               /* No result */
+               if (NULL != all_result) {
+                       SECURE_SLOG(LOG_DEBUG, TAG_VCD, "[Server] Engine result is no command : %s", all_result);
+               } 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);
+               }
+
+               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);
+
+               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");
+                               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");
+                               }
+                       } 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);
+
+       return VCD_ERROR_NONE;
+
+#else
        /* No result */
        if (NULL == result_id) {
                /* No result */
@@ -221,7 +760,7 @@ static void __vcd_server_result_cb(vcp_result_event_e event, int* result_id, int
                if (-1 != pid) {
                        if (NULL != all_result) {
                                /* Send result text to widget */
-                               vcdc_send_result(pid, VC_COMMAND_TYPE_WIDGET);
+                               vcdc_send_result(pid, vcd_client_manager_get_pid(), VC_COMMAND_TYPE_WIDGET);
                        }
 
                        SLOG(LOG_DEBUG, TAG_VCD, "[Server] Request tooltip hide");
@@ -231,7 +770,7 @@ static void __vcd_server_result_cb(vcp_result_event_e event, int* result_id, int
 
                if (-1 != vcd_client_manager_get_pid()) {
                        /* Manager client is available */
-                       if (0 != vcdc_send_result_to_manager(vcd_client_manager_get_pid())) {
+                       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");
                        }
                }
@@ -242,21 +781,22 @@ static void __vcd_server_result_cb(vcp_result_event_e event, int* result_id, int
        }
 
        /* Normal result */
-       SLOG(LOG_DEBUG, TAG_VCD, "[Server] === Get engine result ===");
+       SLOG(LOG_DEBUG, TAG_VCD, "[Server] @ Get engine result @");
 
        int ret = -1;
        vc_cmd_s* temp_cmd = NULL;
        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_ERROR, 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);
                return;
        }
 
        int i = 0;
-       for (i = 0;i < count;i++) {
+       for (i = 0; i < count; i++) {
                SLOG(LOG_DEBUG, TAG_VCD, "[Server]   [%d] Result ID(%d)", i, result_id[i]);
 
                if (result_id[i] < 0) {
@@ -268,9 +808,12 @@ static void __vcd_server_result_cb(vcp_result_event_e event, int* result_id, int
                if (0 == ret && NULL != temp_cmd) {
                        switch (temp_cmd->format) {
                        case VC_CMD_FORMAT_FIXED:
+                       case VC_CMD_FORMAT_FIXED_AND_VFIXED:
+                       case VC_CMD_FORMAT_VFIXED_AND_FIXED:
+                       case VC_CMD_FORMAT_PARTIAL:
                                /* Nonfixed result is NOT valid */
                                break;
-                       case VC_CMD_FORMAT_FIXED_AND_EXTRA:
+                       case VC_CMD_FORMAT_FIXED_AND_NONFIXED:
                                if (NULL == temp_cmd->parameter) {
                                        if (NULL != non_fixed_result) {
                                                temp_cmd->parameter = strdup(non_fixed_result);
@@ -279,7 +822,7 @@ static void __vcd_server_result_cb(vcp_result_event_e event, int* result_id, int
                                        SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Command type is NOT vaild. Parameter (%s)", temp_cmd->parameter);
                                }
                                break;
-                       case VC_CMD_FORMAT_EXTRA_AND_FIXED:
+                       case VC_CMD_FORMAT_NONFIXED_AND_FIXED:
                                if (NULL == temp_cmd->command) {
                                        if (NULL != non_fixed_result) {
                                                temp_cmd->command = strdup(non_fixed_result);
@@ -305,7 +848,7 @@ static void __vcd_server_result_cb(vcp_result_event_e event, int* result_id, int
 
        vc_cmd_print_list(vc_cmd_list);
 
-       SLOG(LOG_DEBUG, TAG_VCD, "[Server] =========================");
+       SLOG(LOG_DEBUG, TAG_VCD, "[Server] @@@@");
 
        int result_count = 0;
        vc_cmd_list_get_count(vc_cmd_list, &result_count);
@@ -321,7 +864,7 @@ static void __vcd_server_result_cb(vcp_result_event_e event, int* result_id, int
 
                if (-1 != vcd_client_manager_get_pid()) {
                        /* Manager client is available */
-                       if (0 != vcdc_send_result_to_manager(vcd_client_manager_get_pid())) {
+                       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 {
@@ -335,7 +878,7 @@ static void __vcd_server_result_cb(vcp_result_event_e event, int* result_id, int
 
                if (-1 != vcd_client_manager_get_pid()) {
                        /* Manager client is available */
-                       if (0 != vcdc_send_result_to_manager(vcd_client_manager_get_pid())) {
+                       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 {
@@ -347,7 +890,45 @@ static void __vcd_server_result_cb(vcp_result_event_e event, int* result_id, int
 
        vc_cmd_list_destroy(vc_cmd_list, true);
 
-       return;
+       return;
+#endif
+}
+
+#if 0
+static void __vcd_server_nlu_result_cb(vce_result_event_e event, const char* nlu_result, void *user_data)
+{
+       SECURE_SLOG(LOG_DEBUG, TAG_VCD, "[Server] NLU result cb - event(%d)", event);
+       SECURE_SLOG(LOG_DEBUG, TAG_VCD, "[Server] result (%s)", nlu_result);
+
+       int ret = vc_info_parser_set_nlu_result(nlu_result);
+       if (0 != ret) {
+               SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to set nlu result (%d)", ret);
+       }
+
+       return;
+}
+#endif
+
+int vcd_send_error(vce_error_e error, const char* msg, void *user_data)
+{
+       SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Engine Error cb - reason(%d), msg(%s)", error, msg);
+       ecore_main_loop_thread_safe_call_async(__cancel_by_error, NULL);
+
+       char* error_msg = NULL;
+       if (NULL != msg) {
+               error_msg = strdup(msg);
+       }
+
+       if (0 != vcdc_send_error_signal_to_manager(vcd_client_manager_get_pid(), error, error_msg)) {
+               SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to send error signal");
+       }
+
+       if (NULL != error_msg) {
+               free(error_msg);
+               error_msg = NULL;
+       }
+
+       return VCD_ERROR_NONE;
 }
 
 /*
@@ -358,8 +939,6 @@ static void __vcd_file_clean_up()
        SLOG(LOG_DEBUG, TAG_VCD, "== Old file clean up == ");
 
        DIR *dp = NULL;
-       int ret = -1;
-       struct dirent entry;
        struct dirent *dirp = NULL;
 
        dp = opendir(VC_RUNTIME_INFO_ROOT);
@@ -370,11 +949,7 @@ static void __vcd_file_clean_up()
 
        char remove_path[256] = {0, };
        do {
-               ret = readdir_r(dp, &entry, &dirp);
-               if (0 != ret) {
-                       SLOG(LOG_ERROR, TAG_VCD, "[File ERROR] Fail to read directory");
-                       break;
-               }
+               dirp = readdir(dp);
 
                if (NULL != dirp) {
                        if (!strncmp("vc_", dirp->d_name, strlen("vc_"))) {
@@ -396,7 +971,19 @@ static void __vcd_file_clean_up()
        return;
 }
 
-int vcd_initialize()
+static int __vcd_db_clean_up()
+{
+       int ret = 0;
+       int cnt = VC_COMMAND_TYPE_FOREGROUND;
+       do {
+               if (VC_COMMAND_TYPE_BACKGROUND != cnt)
+                       ret = vc_db_delete_commands(-1, cnt, NULL);
+       } while (VC_COMMAND_TYPE_EXCLUSIVE >= ++cnt);
+
+       return ret;
+}
+
+int vcd_initialize(vce_request_callback_s *callback)
 {
        int ret = 0;
 
@@ -409,9 +996,15 @@ int vcd_initialize()
                SLOG(LOG_ERROR, TAG_VCD, "[Server WARNING] Fail to initialize config.");
        }
 
+       /* Remove db data */
+       ret = __vcd_db_clean_up();
+       if (0 != ret) {
+               SLOG(LOG_ERROR, TAG_VCD, "[Server WARNING] Fail to remove db data");
+       }
+
        vcd_config_set_service_state(VCD_STATE_NONE);
 
-       ret = vcd_engine_agent_init(__vcd_server_result_cb);
+       ret = vcd_engine_agent_init();
        if (0 != ret) {
                SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to engine agent initialize : result(%d)", ret);
                return ret;
@@ -422,21 +1015,8 @@ int vcd_initialize()
                return VCD_ERROR_OPERATION_FAILED;
        }
 
-       /* Find engine */
-       ret = vcd_engine_agent_initialize_current_engine();
-       if (0 != ret) {
-               if (VCD_ERROR_ENGINE_NOT_FOUND == ret)
-                       SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] There is No Voice control engine");
-               else
-                       SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to init engine");
-
-               g_is_engine = false;
-       } else {
-               g_is_engine = true;
-       }
-
        /* Load engine */
-       if (0 != vcd_engine_agent_load_current_engine()) {
+       if (0 != vcd_engine_agent_load_current_engine(callback)) {
                SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to load current engine");
                return VCD_ERROR_OPERATION_FAILED;
        }
@@ -445,14 +1025,29 @@ int vcd_initialize()
        vcd_client_manager_unset();
 
        vcd_config_set_service_state(VCD_STATE_READY);
+       vcdc_send_service_state(VCD_STATE_READY);
 
-       SLOG(LOG_DEBUG, TAG_VCD, "[Server SUCCESS] initialize");
+       SLOG(LOG_ERROR, TAG_VCD, "[Server SUCCESS] initialize");
 
        return 0;
 }
 
 void vcd_finalize()
 {
+       GList *iter = NULL;
+       if (0 < g_list_length(g_proc_list)) {
+               iter = g_list_first(g_proc_list);
+               while (NULL != iter) {
+                       g_proc_list = g_list_remove_link(g_proc_list, iter);
+                       iter = g_list_first(g_proc_list);
+               }
+       }
+
+       if (g_restart_timer != NULL) {
+               ecore_timer_del(g_restart_timer);
+               g_restart_timer = NULL;
+       }
+
        vcd_state_e state = vcd_config_get_service_state();
        if (VCD_STATE_READY != state) {
                if (VCD_STATE_RECORDING == state) {
@@ -472,31 +1067,148 @@ void vcd_finalize()
                SLOG(LOG_DEBUG, TAG_VCD, "[Server] release engine");
        }
 
+       vcd_client_manager_unset_appid();
+
        vcd_config_set_service_state(VCD_STATE_NONE);
+       vcdc_send_service_state(VCD_STATE_NONE);
 
-       SLOG(LOG_DEBUG, TAG_VCD, "[Server] mode finalize");
+       SLOG(LOG_ERROR, TAG_VCD, "[Server] mode finalize");
 
        return;
 }
 
 static Eina_Bool __finalize_quit_ecore_loop(void *data)
 {
-       SLOG(LOG_DEBUG, TAG_VCD, "[Server] quit ecore main loop");
+       SLOG(LOG_ERROR, TAG_VCD, "[Server] quit ecore main loop");
        ecore_main_loop_quit();
        return EINA_FALSE;
 }
 
-Eina_Bool vcd_cleanup_client(void *data)
+static void __read_proc()
+{
+       DIR *dp = NULL;
+       struct dirent *dirp = NULL;
+       int tmp;
+
+       GList *iter = NULL;
+       if (0 < g_list_length(g_proc_list)) {
+               iter = g_list_first(g_proc_list);
+               while (NULL != iter) {
+                       g_proc_list = g_list_remove_link(g_proc_list, iter);
+                       iter = g_list_first(g_proc_list);
+               }
+       }
+
+       dp = opendir("/proc");
+       if (NULL == dp) {
+               SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to open proc");
+       } else {
+               do {
+                       dirp = readdir(dp);
+
+                       if (NULL != dirp) {
+                               tmp = atoi(dirp->d_name);
+                               if (0 >= tmp)   continue;
+                               g_proc_list = g_list_append(g_proc_list, GINT_TO_POINTER(tmp));
+                       }
+               } while (NULL != dirp);
+               closedir(dp);
+       }
+       return;
+}
+
+static void __vcd_cleanup_client(vcd_client_type_e type)
 {
        int* client_list = NULL;
        int client_count = 0;
-       int result;
        int i = 0;
+       int j = 0;
+       bool exist = false;
+       int mgr_pid = -1;
+       int ret = -1;
+
+       if (VCD_CLIENT_TYPE_NORMAL == type) {
+               ret = vcd_client_get_list(&client_list, &client_count);
+       } else if (VCD_CLIENT_TYPE_WIDGET == type) {
+               ret = vcd_client_widget_get_list(&client_list, &client_count);
+       } else if (VCD_CLIENT_TYPE_MANAGER == type) {
+               mgr_pid = vcd_client_manager_get_pid();
+               client_list = &mgr_pid;
+               client_count = 1;
+               if (-1 == mgr_pid) {
+                       SLOG(LOG_WARN, TAG_VCD, "[WARNING] Invalid Manager pid");
+                       return;
+               }
+       }
+
+       if (0 == ret || mgr_pid > 0) {
+               SLOG(LOG_DEBUG, TAG_VCD, "@@@ Clean up %s client ", type ? (type == 1) ? "Widget" : "Manager" : "Normal");
+               if (NULL != client_list && client_count > 0) {
+                       for (i = 0; i < client_count; i++) {
+                               exist = false;
+                               GList *iter = NULL;
+                               for (j = 0; j < g_list_length(g_proc_list); j++) {
+                                       iter = g_list_nth(g_proc_list, j);
+                                       if (NULL != iter) {
+                                               if (*(client_list + i) == GPOINTER_TO_INT(iter->data)) {
+                                                       SLOG(LOG_DEBUG, TAG_VCD, "%s pid(%d) is running", type ? (type == 1) ? "Widget" : "Manager" : "Normal", *(client_list + i));
+                                                       exist = true;
+                                                       break;
+                                               }
+                                       }
+                               }
+
+                               if (false == exist) {
+                                       SLOG(LOG_ERROR, TAG_VCD, "%s pid(%d) should be removed", type ? (type == 1) ? "Widget" : "Manager" : "Normal", *(client_list + i));
+                                       if (VCD_CLIENT_TYPE_NORMAL == type)
+                                               vcd_server_finalize(*(client_list + i));
+                                       else if (VCD_CLIENT_TYPE_WIDGET == type)
+                                               vcd_server_widget_finalize(*(client_list + i));
+                                       else
+                                               vcd_server_mgr_finalize(mgr_pid);
+                               }
+                       }
+               }
+               SLOG(LOG_DEBUG, TAG_VCD, "@@@");
+       }
+       if (NULL != client_list && -1 == mgr_pid) {
+               free(client_list);
+               client_list = NULL;
+       }
+       return;
+}
+
+Eina_Bool vcd_cleanup_client_all(void *data)
+{
+       __read_proc();
+
+       __vcd_cleanup_client(VCD_CLIENT_TYPE_NORMAL);
+       __vcd_cleanup_client(VCD_CLIENT_TYPE_WIDGET);
+       __vcd_cleanup_client(VCD_CLIENT_TYPE_MANAGER);
 
+#if 0
        if (0 == vcd_client_get_list(&client_list, &client_count)) {
-               SLOG(LOG_DEBUG, TAG_VCD, "===== Clean up client ");
+               SLOG(LOG_DEBUG, TAG_VCD, "@@@ Clean up client ");
                if (NULL != client_list && client_count > 0) {
-                       for (i = 0;i < client_count;i++) {
+                       for (i = 0; i < client_count; i++) {
+                               exist = false;
+                               GList *iter = NULL;
+                               for (j = 0; j < g_list_length(g_proc_list); j++) {
+                                       iter = g_list_nth(g_proc_list, j);
+                                       if (NULL != iter) {
+                                               if (client_list[i] == GPOINTER_TO_INT(iter->data)) {
+                                                       SLOG(LOG_DEBUG, TAG_VCD, "pid(%d) is running", client_list[i]);
+                                                       exist = true;
+                                                       break;
+                                               }
+                                       }
+                               }
+
+                               if (false == exist) {
+                                       SLOG(LOG_ERROR, TAG_VCD, "pid(%d) should be removed", client_list[i]);
+                                       vcd_server_finalize(client_list[i]);
+                               }
+#if 0
                                result = vcdc_send_hello(client_list[i], VCD_CLIENT_TYPE_NORMAL);
 
                                if (0 == result) {
@@ -505,20 +1217,39 @@ Eina_Bool vcd_cleanup_client(void *data)
                                } else if (-1 == result) {
                                        SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Hello result has error");
                                }
+#endif
                        }
                }
-               SLOG(LOG_DEBUG, TAG_VCD, "=====");
-               SLOG(LOG_DEBUG, TAG_VCD, "  ");
+               SLOG(LOG_DEBUG, TAG_VCD, "@@@");
        }
        if (NULL != client_list) {
                free(client_list);
                client_list = NULL;
        }
 
+       /* If app is in background state, app cannot response message. */
        if (0 == vcd_client_widget_get_list(&client_list, &client_count)) {
-               SLOG(LOG_DEBUG, TAG_VCD, "===== Clean up widget");
+               SLOG(LOG_DEBUG, TAG_VCD, "@@@ Clean up widget");
                if (NULL != client_list && client_count > 0) {
-                       for (i = 0;i < client_count;i++) {
+                       for (i = 0; i < client_count; i++) {
+                               exist = false;
+                               GList *iter = NULL;
+                               for (j = 0; j < g_list_length(g_proc_list); j++) {
+                                       iter = g_list_nth(g_proc_list, j);
+                                       if (NULL != iter) {
+                                               if (client_list[i] == GPOINTER_TO_INT(iter->data)) {
+                                                       SLOG(LOG_DEBUG, TAG_VCD, "widget pid(%d) is running", client_list[i]);
+                                                       exist = true;
+                                                       break;
+                                               }
+                                       }
+                               }
+
+                               if (false == exist) {
+                                       SLOG(LOG_ERROR, TAG_VCD, "widget pid(%d) should be removed", client_list[i]);
+                                       vcd_server_widget_finalize(client_list[i]);
+                               }
+#if 0
                                result = vcdc_send_hello(client_list[i], VCD_CLIENT_TYPE_WIDGET);
 
                                if (0 == result) {
@@ -527,40 +1258,65 @@ Eina_Bool vcd_cleanup_client(void *data)
                                } else if (-1 == result) {
                                        SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Hello result has error");
                                }
+#endif
                        }
                }
-               SLOG(LOG_DEBUG, TAG_VCD, "=====");
-               SLOG(LOG_DEBUG, TAG_VCD, "  ");
+               SLOG(LOG_DEBUG, TAG_VCD, "@@@");
        }
+
        if (NULL != client_list) {
                free(client_list);
                client_list = NULL;
        }
 
        /* manager */
+       exist = false;
+       GList *iter = NULL;
+       int mgr_pid = vcd_client_manager_get_pid();
+       if (0 < mgr_pid) {
+               for (j = 0; j < g_list_length(g_proc_list); j++) {
+                       iter = g_list_nth(g_proc_list, j);
+                       if (NULL != iter) {
+                               if (mgr_pid == GPOINTER_TO_INT(iter->data)) {
+                                       SLOG(LOG_DEBUG, TAG_VCD, "manager pid(%d) is running", mgr_pid);
+                                       exist = true;
+                                       break;
+                               }
+                       }
+               }
 
+               if (false == exist) {
+                       SLOG(LOG_ERROR, TAG_VCD, "manager pid (%d) should be removed", mgr_pid);
+                       vcd_server_mgr_finalize(mgr_pid);
+               }
+       }
+#endif
        return EINA_TRUE;
 }
 
+int vcd_server_get_service_state()
+{
+       return vcd_config_get_service_state();
+}
+
+int vcd_server_get_foreground()
+{
+       int pid;
+       vcd_config_get_foreground(&pid);
+       return pid;
+}
+
+
 /*
 * API for manager
 */
 int vcd_server_mgr_initialize(int pid)
 {
-       if (false == g_is_engine) {
-               if (0 != vcd_engine_agent_initialize_current_engine()) {
-                       SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] No Engine");
-                       g_is_engine = false;
-                       return VCD_ERROR_ENGINE_NOT_FOUND;
-               } else {
-                       g_is_engine = true;
-               }
-       }
-
        /* check if pid is valid */
        if (false == vcd_client_manager_is_valid(pid)) {
-               SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] The pid(%d) is already exist", pid);
-               return VCD_ERROR_INVALID_PARAMETER;
+               SLOG(LOG_ERROR, TAG_VCD, "[Server] old manager pid(%d) be removed", vcd_client_manager_get_pid());
+               vcd_server_mgr_cancel();
+               vcd_client_manager_unset();
        }
 
        /* Add client information to client manager */
@@ -569,7 +1325,10 @@ int vcd_server_mgr_initialize(int pid)
                return VCD_ERROR_OPERATION_FAILED;
        }
 
-       SLOG(LOG_DEBUG, TAG_VCD, "[Server Success] Manager initialize : pid(%d)", pid);
+       if (0 != vcdc_send_manager_pid(pid))
+               SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Fail to send manager pid");
+
+       SLOG(LOG_ERROR, TAG_VCD, "[Server Success] Manager initialize : pid(%d)", pid);
 
        return VCD_ERROR_NONE;
 }
@@ -582,6 +1341,12 @@ int vcd_server_mgr_finalize(int pid)
                return VCD_ERROR_INVALID_PARAMETER;
        }
 
+       /* Cancel recognition */
+       vcd_server_mgr_cancel();
+
+       if (0 != vcdc_send_manager_pid(-1))
+               SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Fail to send manager pid");
+
        /* Remove manager information */
        if (0 != vcd_client_manager_unset()) {
                SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Fail to delete client");
@@ -592,7 +1357,7 @@ int vcd_server_mgr_finalize(int pid)
                ecore_timer_add(0, __finalize_quit_ecore_loop, NULL);
        }
 
-       SLOG(LOG_DEBUG, TAG_VCD, "[Server Success] Manager Finalize : pid(%d)", pid);
+       SLOG(LOG_ERROR, TAG_VCD, "[Server Success] Manager Finalize : pid(%d)", pid);
 
        return VCD_ERROR_NONE;
 }
@@ -645,9 +1410,9 @@ int vcd_server_mgr_set_audio_type(int pid, const char* audio_type)
                SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] The manager pid(%d) is NOT valid", pid);
                return VCD_ERROR_INVALID_PARAMETER;
        }
-       
+
        int ret = 0;
-       vcp_audio_type_e type = VCP_AUDIO_TYPE_PCM_S16_LE;
+       vce_audio_type_e type = VCE_AUDIO_TYPE_PCM_S16_LE;
        int rate = 16000;
        int channel = 1;
 
@@ -673,7 +1438,7 @@ int vcd_server_mgr_get_audio_type(int pid, char** audio_type)
                SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] The manager pid(%d) is NOT valid", pid);
                return VCD_ERROR_INVALID_PARAMETER;
        }
-       
+
        int ret = vcd_recorder_get(audio_type);
        if (0 != ret) {
                SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to get audio in type : %d", ret);
@@ -703,49 +1468,68 @@ int vcd_server_mgr_set_client_info(int pid)
 static int __start_internal_recognition()
 {
        int ret;
+       vcd_client_widget_set_waiting_for_recording(-1, false);
 
-       /* 2. Get commands */
-       ret = vcd_client_command_collect_command();
-       if (0 != ret) {
-               SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to collect command : %d", ret);
-               return VCD_ERROR_OPERATION_FAILED;
-       }
-
-       ret = vcd_client_get_length();
-       if (0 == ret) {
-               SLOG(LOG_WARN, TAG_VCD, "[Server WARNIING] No current command : %d", ret);
+       if (0 != vcd_client_command_collect_command()) {
+               SLOG(LOG_ERROR, TAG_VCD, "[Client Data ERROR] Fail to collect command");
+               /* 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");
                return VCD_ERROR_OPERATION_FAILED;
        }
 
        /* 3. Set command to engine */
        ret = vcd_engine_set_commands();
        if (0 != ret) {
-               SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to collect command : %d", ret);
+               SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to set commands : %d", ret);
+               /* 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");
                return VCD_ERROR_OPERATION_FAILED;
        }
 
-       SLOG(LOG_DEBUG, TAG_VCD, "[Server Success] Set command");
+       SLOG(LOG_ERROR, TAG_VCD, "[Server Success] Set command");
+
+       bool stop_by_silence = true;
+       if (VCD_RECOGNITION_MODE_MANUAL == vcd_client_get_recognition_mode()) {
+               stop_by_silence = false;
+       }
+
+       vcd_client_manager_set_result_text(NULL);
 
        /* 4. start recognition */
-       ret = vcd_engine_recognize_start(true);
+       ret = vcd_engine_recognize_start(stop_by_silence);
        if (0 != ret) {
                SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to start recognition : result(%d)", ret);
+               /* 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");
                return VCD_ERROR_OPERATION_FAILED;
        }
 
-       SLOG(LOG_DEBUG, TAG_VCD, "[Server Success] Start engine");
+       SLOG(LOG_ERROR, TAG_VCD, "[Server Success] Start engine");
 
+#if 1
        /* 5. recorder start */
        ret = vcd_recorder_start();
        if (0 != ret) {
                SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to start recorder : result(%d)", ret);
                vcd_engine_recognize_cancel();
+               /* 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");
                return ret;
        }
+#endif
 
        vcd_config_set_service_state(VCD_STATE_RECORDING);
+       vcdc_send_service_state(VCD_STATE_RECORDING);
 
-       SLOG(LOG_DEBUG, TAG_VCD, "[Server Success] Start recognition");
+       SLOG(LOG_ERROR, TAG_VCD, "[Server Success] Start recognition(%d)", stop_by_silence);
 
        return 0;
 }
@@ -754,32 +1538,42 @@ static Eina_Bool __vcd_request_show_tooltip(void *data)
 {
        int pid = vcd_client_widget_get_foreground_pid();
        if (-1 != pid) {
-               SLOG(LOG_DEBUG, TAG_VCD, "[Server] Request tooltip show and widget command");
+               SLOG(LOG_ERROR, TAG_VCD, "[Server] Request tooltip show and widget command, show(%d)", (bool)data);
                vcdc_send_show_tooltip(pid, (bool)data);
        }
 
        return EINA_FALSE;
 }
 
-int vcd_server_mgr_start(bool stop_by_silence, bool exclusive_cmd, bool start_by_client)
+int vcd_server_mgr_start(vcd_recognition_mode_e recognition_mode, bool exclusive_cmd, bool start_by_client)
 {
        /* 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");
                return VCD_ERROR_INVALID_STATE;
        }
+       if (-1 == vcd_client_manager_get_pid()) {
+               SLOG(LOG_DEBUG, TAG_VCD, "[Server] Manager is NOT available.");
+               return VCD_ERROR_OPERATION_FAILED;
+       }
+       vcd_client_widget_set_waiting_for_recording(-1, false);
 
-       vcd_client_set_slience_detection(stop_by_silence);
+       SLOG(LOG_ERROR, TAG_VCD, "[Server] set recognition mode = %d", recognition_mode);
+       vcd_client_set_recognition_mode(recognition_mode);
 
        if (false == exclusive_cmd) {
+               vcd_client_update_foreground_pid();
                /* Notify show tooltip */
-               int pid = vcd_client_widget_get_foreground_pid();
-               if (-1 != pid) {
-                       SLOG(LOG_DEBUG, TAG_VCD, "[Server] Request tooltip show and widget command");
-                       ecore_timer_add(0, __vcd_request_show_tooltip, (void*)true);
-                       return 0;
+               if (1 == vcd_config_get_command_type_enabled(VC_COMMAND_TYPE_WIDGET)) {
+                       int pid = vcd_client_widget_get_foreground_pid();
+                       if (-1 != pid) {
+                               SLOG(LOG_ERROR, TAG_VCD, "[Server] Request tooltip show and widget command");
+                               ecore_timer_add(0, __vcd_request_show_tooltip, (void*)true);
+                               vcd_client_widget_set_waiting_for_recording(pid, true);
+                               return 0;
+                       }
                }
        } else {
                vcd_client_manager_set_exclusive(exclusive_cmd);
@@ -791,13 +1585,15 @@ int vcd_server_mgr_start(bool stop_by_silence, bool exclusive_cmd, bool start_by
                if (0 != vcd_config_get_foreground(&fg_pid)) {
                        SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to get foreground");
                }
-               
+
                /* Set client exclusive option */
                if (0 != vcd_client_set_exclusive_command(fg_pid)) {
                        SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to set exclusive command");
                }
        }
 
+       SLOG(LOG_ERROR, TAG_VCD, "[Server] start internal recognition");
+
        int ret = __start_internal_recognition();
        if (0 != ret) {
                SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to start recongition : %d", ret);
@@ -808,6 +1604,7 @@ int vcd_server_mgr_start(bool stop_by_silence, bool exclusive_cmd, bool start_by
                vcd_client_unset_exclusive_command(fg_pid);
        }
 
+       SLOG(LOG_ERROR, TAG_VCD, "[Server Success] start internal recognition");
        return VCD_ERROR_NONE;
 }
 
@@ -818,61 +1615,263 @@ int vcd_server_mgr_stop()
                SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Current state is not recording");
                return VCD_ERROR_INVALID_STATE;
        }
+       if (-1 == vcd_client_manager_get_pid()) {
+               SLOG(LOG_DEBUG, TAG_VCD, "[Server] Manager is NOT available.");
+               return VCD_ERROR_OPERATION_FAILED;
+       }
+       SLOG(LOG_ERROR, TAG_VCD, "[Server] stop internal recognition");
+
+#if 1
+       /* 2. Stop recorder */
+       vcd_recorder_stop();
+#endif
+
+       /* 3. Stop engine recognition */
+       int ret = vcd_engine_recognize_stop();
+       if (0 != ret) {
+               SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to stop recognition : %d", ret);
+       }
+
+       /* 4. Set original mode */
+       vcd_config_set_service_state(VCD_STATE_PROCESSING);
+       vcdc_send_service_state(VCD_STATE_PROCESSING);
+
+       SLOG(LOG_ERROR, TAG_VCD, "[Server Success] stop internal recognition");
+       return VCD_ERROR_NONE;
+}
+
+int vcd_server_mgr_cancel()
+{
+       if (-1 == vcd_client_manager_get_pid()) {
+               SLOG(LOG_DEBUG, TAG_VCD, "[Server] Manager is NOT available.");
+               return VCD_ERROR_OPERATION_FAILED;
+       }
+
+       if (g_restart_timer != NULL) {
+               SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Delete restart engine timer");
+               ecore_timer_del(g_restart_timer);
+               g_restart_timer = NULL;
+       }
+
+       /* 1. Check current state */
+       vcd_state_e state = vcd_config_get_service_state();
+       if (VCD_STATE_READY == state) {
+               SLOG(LOG_DEBUG, TAG_VCD, "[Server] Current state is READY");
+               vcd_recorder_stop();
+
+               if (false == vcd_client_manager_get_exclusive()) {
+                       if (1 == vcd_config_get_command_type_enabled(VC_COMMAND_TYPE_WIDGET)) {
+                               int pid = vcd_client_widget_get_foreground_pid();
+                               if (-1 != pid) {
+                                       SLOG(LOG_DEBUG, TAG_VCD, "[Server] Request tooltip hide");
+                                       ecore_timer_add(0, __vcd_request_show_tooltip, (void*)false);
+                               }
+                       }
+               }
+
+               vcdc_send_service_state(VCD_STATE_READY);
+               return VCD_ERROR_NONE;
+       }
+       SLOG(LOG_ERROR, TAG_VCD, "[Server] cancel internal recognition");
 
+#if 1
        /* 2. Stop recorder */
        vcd_recorder_stop();
+#endif
+
+       /* 3. Cancel engine */
+       int ret = vcd_engine_recognize_cancel();
+       if (0 != ret) {
+               SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Fail to cancel : %d", ret);
+       }
+
+       if (false == vcd_client_manager_get_exclusive()) {
+               if (1 == vcd_config_get_command_type_enabled(VC_COMMAND_TYPE_WIDGET)) {
+                       int pid = vcd_client_widget_get_foreground_pid();
+                       if (-1 != pid) {
+                               SLOG(LOG_DEBUG, TAG_VCD, "[Server] Request tooltip hide");
+                               ecore_timer_add(0, __vcd_request_show_tooltip, (void*)false);
+                       }
+               }
+       } else {
+               vcd_client_manager_set_exclusive(false);
+       }
+
+       /* 4. Set state */
+       vcd_config_set_service_state(VCD_STATE_READY);
+       vcdc_send_service_state(VCD_STATE_READY);
+
+       SLOG(LOG_ERROR, TAG_VCD, "[Server Success] cancel internal recognition");
+       return VCD_ERROR_NONE;
+}
+
+
+int vcd_server_mgr_result_select()
+{
+       __vcd_send_selected_result(NULL);
+
+       return VCD_ERROR_NONE;
+}
+
+int vcd_server_mgr_set_domain(int pid, const char* domain)
+{
+       /* 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) {
+               SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Current state is not ready");
+               return VCD_ERROR_INVALID_STATE;
+       }
+
+       /* Set domain to engine */
+       int ret = vcd_engine_set_domain(pid, domain);
+       if (0 != ret) {
+               SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to set domain : %d", ret);
+       } else {
+               SLOG(LOG_DEBUG, TAG_VCD, "[Server SUCCESS] Set domain");
+       }
+
+       return ret;
+}
+
+int vcd_server_mgr_set_private_data(int pid, const char* key, const char* data)
+{
+       /* 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) {
+               SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Current state is not ready");
+               return VCD_ERROR_INVALID_STATE;
+       }
+
+       /* Set private data to engine */
+       int ret = vcd_engine_set_private_data(pid, key, data);
+       if (0 != ret) {
+               SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to set private data : %d", ret);
+       } else {
+               SLOG(LOG_DEBUG, TAG_VCD, "[Server SUCCESS] Set private data");
+       }
+
+       return ret;
+}
+
+int vcd_server_mgr_get_private_data(int pid, const char* key, char** data)
+{
+       /* 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) {
+               SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Current state is not ready");
+               return VCD_ERROR_INVALID_STATE;
+       }
+
+       /* Get private data to engine */
+       int ret = vcd_engine_get_private_data(pid, key, data);
+       if (0 != ret) {
+               SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to get private data : %d", ret);
+       } else {
+               SLOG(LOG_DEBUG, TAG_VCD, "[Server SUCCESS] Set private data");
+       }
+
+       return ret;
+}
+
+int vcd_server_mgr_do_action(int pid, int type, const char* action)
+{
+       int ret = -1;
+
+       /* 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) {
+               SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Current state is not ready");
+               return VCD_ERROR_INVALID_STATE;
+       }
+
+       /* Reqeust 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)
+               ret = vcd_engine_process_list_event(pid, action);
+       else if (VCD_SEND_EVENT_TYPE_HAPTIC_EVENT == type)
+               ret = vcd_engine_process_haptic_event(pid, action);
 
-       /* 3. Stop engine recognition */
-       int ret = vcd_engine_recognize_stop();
        if (0 != ret) {
-               SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to stop recognition : %d", ret);
+               SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to process do action : %d", ret);
+       } else {
+               vcd_config_set_service_state(VCD_STATE_PROCESSING);
+               vcdc_send_service_state(VCD_STATE_PROCESSING);
+               SLOG(LOG_DEBUG, TAG_VCD, "[Server SUCCESS] Process do action");
        }
 
-       /* 4. Set original mode */
-       vcd_config_set_service_state(VCD_STATE_PROCESSING);
-
-       return VCD_ERROR_NONE;
+       return ret;
 }
 
-int vcd_server_mgr_cancel()
+int vcd_server_mgr_enable_command_type(int pid, int cmd_type)
 {
-       /* 1. Check current state */
+       int ret = -1;
+
+       /* 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_RECORDING != state && VCD_STATE_PROCESSING != state) {
-               SLOG(LOG_WARN, TAG_VCD, "[Server ERROR] Current state is not recording or processing");
+       if (VCD_STATE_READY != state) {
+               SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Current state is not ready");
                return VCD_ERROR_INVALID_STATE;
        }
 
-       /* 2. Stop recorder */
-       vcd_recorder_stop();
-       /* 3. Cancel engine */
-       int ret = vcd_engine_recognize_cancel();
+       ret = vcd_config_enable_command_type(cmd_type);
        if (0 != ret) {
-               SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Fail to cancel : %d", ret);
-       }
-
-       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");
-                       ecore_timer_add(0, __vcd_request_show_tooltip, (void*)false);
-               }
+               SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to enable command type");
        } else {
-               vcd_client_manager_set_exclusive(false);
+               SLOG(LOG_ERROR, TAG_VCD, "[Server] Enable command type(%d)", cmd_type);
        }
 
-       /* 4. Set state */
-       vcd_config_set_service_state(VCD_STATE_READY);
-
-       return VCD_ERROR_NONE;
+       return ret;
 }
 
-
-int vcd_server_mgr_result_select()
+int vcd_server_mgr_disable_command_type(int pid, int cmd_type)
 {
-       ecore_timer_add(0.01, __vcd_send_selected_result, NULL);
+       int ret = -1;
 
-       return VCD_ERROR_NONE;
+       /* 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) {
+               SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Current state is not ready");
+               return VCD_ERROR_INVALID_STATE;
+       }
+
+       ret = vcd_config_disable_command_type(cmd_type);
+       if (0 != ret) {
+               SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to disable command type");
+       } else {
+               SLOG(LOG_ERROR, TAG_VCD, "[Server] Disable command type(%d)", cmd_type);
+       }
+
+       return ret;
 }
 
 /*
@@ -880,21 +1879,9 @@ int vcd_server_mgr_result_select()
 */
 int vcd_server_initialize(int pid)
 {
-       if (false == g_is_engine) {
-               if (0 != vcd_engine_agent_initialize_current_engine()) {
-                       SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] No Engine");
-                       g_is_engine = false;
-                       return VCD_ERROR_ENGINE_NOT_FOUND;
-               } else {
-                       g_is_engine = true;
-               }
-       }
-
        if (false == vcd_engine_is_available_engine()) {
-               if (0 != vcd_engine_agent_initialize_current_engine()) {
-                       SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] No Engine");
-                       return VCD_ERROR_ENGINE_NOT_FOUND;
-               }
+               SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] No Engine");
+               return VCD_ERROR_ENGINE_NOT_FOUND;
        }
 
        /* check if pid is valid */
@@ -965,7 +1952,112 @@ int vcd_server_unset_command(int pid, vc_cmd_type_e cmd_type)
                SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to unset command type : pid(%d), cmd_type(%d)", pid, cmd_type);
                return VCD_ERROR_OPERATION_FAILED;
        }
-       
+
+       return 0;
+}
+
+int vcd_server_set_foreground(int pid, bool value)
+{
+       /* 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;
+       }
+
+       if (0 != vcd_config_set_foreground(pid, value)) {
+               SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to set foreground : pid(%d), value(%d)", pid, value);
+               return VCD_ERROR_OPERATION_FAILED;
+       }
+
+       return 0;
+}
+
+static int __vcd_server_launch_manager_app()
+{
+       int ret = -1;
+       bool running = false;
+       char* appid = NULL;
+
+       ret = vcd_client_manager_get_appid(&appid);
+       if (0 != ret || NULL == appid) {
+               SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to get manager appid");
+               return VCD_ERROR_OPERATION_FAILED;
+       }
+       ret = app_manager_is_running(appid, &running);
+       if (0 != ret) {
+               SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to check running with appid(%s)", appid);
+               free(appid);
+               appid = NULL;
+               return VCD_ERROR_OPERATION_FAILED;
+       }
+       if (false == running) {
+               int tmp_ret = __vcd_is_package_installed(appid);
+               if (false == tmp_ret) {
+                       SLOG(LOG_ERROR, TAG_VCD, "[ERROR] manager app is not installed, appid(%s)", appid);
+               } else {
+                       ret = __vcd_activate_app_by_appcontrol(appid);
+                       if (0 != ret) {
+                               SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to activate app");
+                               free(appid);
+                               appid = NULL;
+                               return ret;
+                       }
+                       SLOG(LOG_ERROR, TAG_VCD, "Launch vc manager app: appid(%s)", appid);
+               }
+       } else {
+               ret = __vcd_resume_app(appid);
+               if (0 != ret) {
+                       SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to resume app");
+                       free(appid);
+                       appid = NULL;
+                       return ret;
+               }
+               SLOG(LOG_ERROR, TAG_VCD, "Resume vc manager app: appid(%s)", appid);
+       }
+
+       free(appid);
+       appid = NULL;
+
+       return VCD_ERROR_NONE;
+}
+
+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;
+       }
+
+       int 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;
+}
+
+int vcd_server_is_system_command_valid(int pid, int* is_sys_cmd_valid)
+{
+       /* 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;
+       }
+
+       /* check if system command is valid */
+       if (true == vcd_client_manager_is_system_command_valid(vcd_client_manager_get_pid()))
+               *is_sys_cmd_valid = true;
+       else
+               *is_sys_cmd_valid = false;
+
        return 0;
 }
 
@@ -989,7 +2081,7 @@ int vcd_server_set_exclusive_command(int pid, bool value)
                        return VCD_ERROR_OPERATION_FAILED;
                }
        }
-       
+
        return 0;
 }
 
@@ -1092,27 +2184,15 @@ int vcd_server_request_cancel(int pid)
 */
 int vcd_server_widget_initialize(int pid)
 {
-       if (false == g_is_engine) {
-               if (0 != vcd_engine_agent_initialize_current_engine()) {
-                       SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] No Engine");
-                       g_is_engine = false;
-                       return VCD_ERROR_ENGINE_NOT_FOUND;
-               } else {
-                       g_is_engine = true;
-               }
-       }
-
        if (false == vcd_engine_is_available_engine()) {
-               if (0 != vcd_engine_agent_initialize_current_engine()) {
-                       SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] No Engine");
-                       return VCD_ERROR_ENGINE_NOT_FOUND;
-               }
+               SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] No Engine");
+               return VCD_ERROR_ENGINE_NOT_FOUND;
        }
 
        /* check if pid is valid */
        if (true == vcd_client_widget_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 */
@@ -1126,6 +2206,14 @@ int vcd_server_widget_initialize(int pid)
        return VCD_ERROR_NONE;
 }
 
+static void __vcd_server_widget_start_recording(void *data)
+{
+       if (0 != __start_internal_recognition()) {
+               SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to start recongition");
+       }
+       vcd_client_widget_set_waiting_for_recording(-1, false);
+}
+
 int vcd_server_widget_finalize(int pid)
 {
        /* check if pid is valid */
@@ -1140,10 +2228,20 @@ int vcd_server_widget_finalize(int pid)
        }
 
        if (0 == vcd_client_get_ref_count()) {
-               SLOG(LOG_DEBUG, TAG_VCD, "[Server] connected client list is empty");
+               SLOG(LOG_ERROR, TAG_VCD, "[Server] connected client list is empty");
                ecore_timer_add(0, __finalize_quit_ecore_loop, NULL);
+               return 0;
+       }
+
+       bool is_waiting = false;
+       if (0 != vcd_client_widget_get_waiting_for_recording(pid, &is_waiting)) {
+               SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Fail to get waiting to recording");
        }
 
+       if (true == is_waiting) {
+               SLOG(LOG_INFO, TAG_VCD, "[Server INFO] invoke to start recording");
+               ecore_main_loop_thread_safe_call_async(__vcd_server_widget_start_recording, NULL);
+       }
        return VCD_ERROR_NONE;
 }
 
@@ -1160,9 +2258,10 @@ int vcd_server_widget_start_recording(int pid, bool widget_command)
                SLOG(LOG_DEBUG, TAG_VCD, "[Server] widget command is available");
        } else {
                vcd_client_widget_unset_command(pid);
-               SLOG(LOG_DEBUG, TAG_VCD, "[Server] widget command is NOT available");
+               SLOG(LOG_WARN, TAG_VCD, "[Server] widget command is NOT available");
        }
 
+       SLOG(LOG_ERROR, TAG_VCD, "[Server] start internal recongition : %d", widget_command);
        int ret = __start_internal_recognition();
        if (0 != ret) {
                SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to start recongition : %d", ret);
@@ -1247,10 +2346,189 @@ int vcd_server_widget_cancel(int pid)
 
        ret = vcd_server_mgr_cancel();
        if (0 != ret) {
-               SLOG(LOG_DEBUG, TAG_VCD, "[Server] Fail to start recognition");
-               return VCD_ERROR_OPERATION_FAILED;
+               SLOG(LOG_DEBUG, TAG_VCD, "[Server] Fail to cancel recognition : %d", ret);
+               return ret;
        }
 
        return VCD_ERROR_NONE;
 }
 
+int vcd_server_widget_enable_asr_result(int pid, bool enable)
+{
+       int ret;
+       ret = vcd_client_widget_set_asr_result_enabled(pid, enable);
+       if (0 != ret) {
+               SLOG(LOG_DEBUG, TAG_VCD, "[Server] Fail to enable asr result : %d", ret);
+       }
+
+       return ret;
+}
+
+int vcd_server_set_language(const char* language)
+{
+       int ret = VCD_ERROR_NONE;
+
+       ret = vcd_config_set_default_language(language);
+       if (0 != ret) {
+               SLOG(LOG_DEBUG, TAG_VCD, "[Server] Fail to set language : %d", ret);
+               return ret;
+       }
+
+       ret = vcd_engine_set_current_language(language);
+       if (0 != ret) {
+               SLOG(LOG_DEBUG, TAG_VCD, "[Server] Fail to set language : %d", ret);
+               return ret;
+       }
+
+       return ret;
+}
+/*
+* For engine service
+*/
+int vcd_get_foreach_command(vce_cmd_h vce_command, vce_command_cb callback, void* user_data)
+{
+       SLOG(LOG_DEBUG, TAG_VCD, "[Server] Get foreach command");
+
+       if (NULL == callback) {
+               SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] input parameter is NULL");
+               return VCD_ERROR_INVALID_PARAMETER;
+       }
+
+       int ret = 0;
+       ret = vcd_engine_agent_get_foreach_command(vce_command, callback, user_data);
+       if (0 != ret) {
+               SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to get foreach command : ret(%d)", ret);
+       }
+
+       return ret;
+}
+
+int vcd_get_command_count(vce_cmd_h vce_command)
+{
+       SLOG(LOG_DEBUG, TAG_VCD, "[Server] Get command count");
+
+       int ret = 0;
+       ret = vcd_engine_agent_get_command_count(vce_command);
+       if (0 > ret) {
+               SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to get command count : ret(%d)", ret);
+       }
+
+       return ret;
+}
+
+int vcd_get_audio_type(char** audio_type)
+{
+       SLOG(LOG_DEBUG, TAG_VCD, "[Server] Get audio type");
+
+       int ret = 0;
+       ret = vcd_engine_agent_get_audio_type(audio_type);
+       if (0 != ret) {
+               SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to get audio type : ret(%d)", ret);
+       }
+
+       return ret;
+}
+
+int vcd_set_private_data(const char* key, const char* data)
+{
+       vcd_state_e state = vcd_config_get_service_state();
+
+       if (VCD_STATE_READY != state) {
+               SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Current state(%d) is NOT 'READY'", state);
+               return VCD_ERROR_INVALID_STATE;
+       }
+
+       int ret = vcd_engine_agent_set_private_data(key, data);
+       if (0 != ret) {
+               SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to set private data to the manager client : ret(%d)", ret);
+       } else {
+               SLOG(LOG_DEBUG, TAG_VCD, "[Server] Set private data to the manager client, key(%s), data(%s)", key, data);
+       }
+
+       return ret;
+}
+
+int vcd_get_private_data(const char* key, char** data)
+{
+       vcd_state_e state = vcd_config_get_service_state();
+
+       if (VCD_STATE_READY != state) {
+               SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Current state(%d) is NOT 'READY'", state);
+               return VCD_ERROR_INVALID_STATE;
+       }
+
+       int ret = vcd_engine_agent_get_private_data(key, 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);
+       }
+
+       return ret;
+}
+
+int vcd_start_recording()
+{
+       SLOG(LOG_DEBUG, TAG_VCD, "[Server] Start recording");
+
+       int ret = 0;
+       ret = vcd_engine_agent_start_recording();
+       if (0 != ret) {
+               SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to start recording : ret(%d)", ret);
+       }
+
+       return ret;
+}
+
+int vcd_stop_recording()
+{
+       SLOG(LOG_DEBUG, TAG_VCD, "[Server] Stop recording");
+
+       int ret = 0;
+       ret = vcd_engine_agent_stop_recording();
+       if (0 != ret) {
+               SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to stop recording : ret(%d)", ret);
+       }
+
+       return ret;
+}
+
+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");
+
+       int ret = 0;
+       ret = vcd_engine_agent_set_private_data_set_cb(callback_func);
+       if (0 != ret) {
+               SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to set private data set cb : ret(%d)", ret);
+       }
+
+       return ret;
+}
+
+int vcd_set_private_data_requested_cb(vce_private_data_requested_cb callback_func)
+{
+       SLOG(LOG_DEBUG, TAG_VCD, "[Server] Set private data requested cb");
+
+       int ret = 0;
+       ret = vcd_engine_agent_set_private_data_requested_cb(callback_func);
+       if (0 != ret) {
+               SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to set private data requested cb : ret(%d)", ret);
+       }
+
+       return ret;
+}
+
+int vcd_set_nlu_base_info_requested_cb(vce_nlu_base_info_requested_cb callback_func)
+{
+       SLOG(LOG_DEBUG, TAG_VCD, "[Server] Set nlu base info requested cb");
+
+       int ret = 0;
+       ret = vcd_engine_agent_set_nlu_base_info_requested_cb(callback_func);
+       if (0 != ret) {
+               SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to set nlu base info requested cb : ret(%d)", ret);
+       }
+
+       return ret;
+}
+