X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=server%2Fvcd_server.c;h=a5256629b4ff4a65517189877dc4afbb0292ae29;hb=8a3433127b6f72a9f7e1e21b5a34c244b7837b33;hp=7787e21ab46a74880eb2c261477f2973cc63c887;hpb=6420f09e0bcfd4600836a83b527fa4e72f831fcd;p=platform%2Fcore%2Fuifw%2Fvoice-control.git diff --git a/server/vcd_server.c b/server/vcd_server.c old mode 100644 new mode 100755 index 7787e21..a525662 --- a/server/vcd_server.c +++ b/server/vcd_server.c @@ -14,7 +14,7 @@ * limitations under the License. */ -#include +#include #include #include #include @@ -31,15 +31,15 @@ #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; +static Ecore_Timer *g_check_widget_client_timer = NULL; /** * @brief Enumerations of send event type. @@ -50,45 +50,44 @@ typedef enum { 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"); + SLOG(LOG_DEBUG, TAG_VCD, "@@@ Cancel by error"); vcd_server_mgr_cancel(); - SLOG(LOG_DEBUG, TAG_VCD, "====="); - SLOG(LOG_DEBUG, TAG_VCD, " "); + SLOG(LOG_DEBUG, TAG_VCD, "@@@"); return; } static Eina_Bool __restart_engine(void *data) { - SLOG(LOG_DEBUG, TAG_VCD, "===== Restart by no result"); + SLOG(LOG_DEBUG, TAG_VCD, "@@@ Restart by no result"); g_restart_timer = NULL; @@ -108,8 +107,7 @@ static Eina_Bool __restart_engine(void *data) SLOG(LOG_DEBUG, TAG_VCD, "[Server Success] Restart recognition"); - SLOG(LOG_DEBUG, TAG_VCD, "====="); - SLOG(LOG_DEBUG, TAG_VCD, " "); + SLOG(LOG_DEBUG, TAG_VCD, "@@@"); return EINA_FALSE; } @@ -122,7 +120,7 @@ static int __server_recorder_callback(const void* data, const unsigned int lengt 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); @@ -132,7 +130,7 @@ static int __server_recorder_callback(const void* data, const unsigned int lengt 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 (VCP_ERROR_OUT_OF_NETWORK == ret) { + 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"); @@ -140,14 +138,14 @@ static int __server_recorder_callback(const void* data, const unsigned int lengt 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) { + } 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); @@ -175,17 +173,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(); @@ -200,15 +197,14 @@ 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); @@ -221,8 +217,7 @@ 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; } @@ -242,18 +237,21 @@ static int __vcd_activate_app_by_appcontrol(const char* appid) 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 @@ -384,12 +382,14 @@ static Eina_Bool __vcd_send_selected_result(void *data) GSList* iter = NULL; vc_cmd_s* temp_cmd = NULL; int ret = 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) { + 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) { @@ -401,7 +401,9 @@ static Eina_Bool __vcd_send_selected_result(void *data) 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; } } free(temp_cmd); @@ -421,15 +423,38 @@ static Eina_Bool __vcd_send_selected_result(void *data) return EINA_FALSE; } -//static void __vcd_server_pre_result_cb(vcp_pre_result_event_e event, const char* pre_result, void *user_data) -static void __vcd_server_asr_result_cb(vcp_asr_result_event_e event, const char* asr_result, void *user_data) +int vcd_send_asr_result(vce_asr_result_event_e event, const char* asr_result, void *user_data) { + int ret = __vcd_server_launch_manager_app(); + if (0 != ret) { + SECURE_SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to send ASR result : mgr_pid(%d), asr_result(%s)", vcd_client_manager_get_pid(), asr_result); + return ret; + } + if (NULL != asr_result) { - 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); + SECURE_SLOG(LOG_DEBUG, TAG_VCD, "[Server] ASR result - Event(%d), Text(%s)", event, asr_result); + ret = vcdc_send_pre_result_to_manager(vcd_client_manager_get_pid(), event, asr_result); + if (0 != ret) { + SECURE_SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to send ASR result : mgr_pid(%d), asr_result(%s)", vcd_client_manager_get_pid(), asr_result); + } } - return; + return ret; +} + +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) @@ -438,35 +463,39 @@ static void* __recorder_stop(void *data) return NULL; } -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* nlu_result, const char* msg, void *user_data) +int vcd_send_result(vce_result_event_e event, int* result_id, int count, const char* all_result, const char* non_fixed_result, const char* nlu_result, const char* msg, int* user_info, void *user_data) { + int ret = 0; + if (VCD_STATE_PROCESSING != vcd_config_get_service_state()) { 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; + 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_INFO, TAG_VCD, "[Server] Event(%d), Text(%s) Nonfixed(%s) Msg(%s) Result count(%d)", + 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 (VCP_RESULT_EVENT_REJECTED == event) { + 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); - if (0 != vcdc_send_result_to_manager(vcd_client_manager_get_pid(), VC_RESULT_TYPE_NOTIFICATION)) { + 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; + return ret; } SLOG(LOG_DEBUG, TAG_VCD, "[Server] Stop recorder due to success"); //vcd_recorder_stop(); @@ -475,21 +504,21 @@ static void __vcd_server_result_cb(vcp_result_event_e event, int* result_id, int SLOG(LOG_DEBUG, TAG_VCD, "[Server] Restart continuously"); /* Restart option is ON */ g_restart_timer = ecore_timer_add(0, __restart_engine, NULL); - if (VCP_RESULT_EVENT_REJECTED == event) { + if (VCE_RESULT_EVENT_REJECTED == event) { bool temp = vcd_client_manager_get_exclusive(); vc_info_parser_set_result(all_result, event, msg, NULL, temp); - if (0 != vcdc_send_result_to_manager(vcd_client_manager_get_pid(), VC_RESULT_TYPE_NOTIFICATION)) { + 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; + 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 ==="); + 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; @@ -498,13 +527,17 @@ static void __vcd_server_result_cb(vcp_result_event_e event, int* result_id, int vcd_client_manager_set_exclusive(false); vcd_config_set_service_state(VCD_STATE_READY); vcdc_send_service_state(VCD_STATE_READY); - return; + return VCD_ERROR_NONE; } /* priority filter */ - /* system > exclusive > foreground = widget > system_background > background */ + /* 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++) { @@ -520,13 +553,64 @@ static void __vcd_server_result_cb(vcp_result_event_e event, int* result_id, int if (top_priority == temp_cmd->priority) { filtered_id[filtered_count] = result_id[i]; filtered_count++; - } else if (top_priority < temp_cmd->priority) { - continue; - } else { + } 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; + } + } + } + } } } @@ -560,6 +644,7 @@ static void __vcd_server_result_cb(vcp_result_event_e event, int* result_id, int 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]); @@ -572,7 +657,7 @@ static void __vcd_server_result_cb(vcp_result_event_e event, int* result_id, int } if (NULL != nlu_result) { - SLOG(LOG_INFO, TAG_VCD, "[Server] NLU (%s)", 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; @@ -598,7 +683,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); @@ -606,18 +691,15 @@ static void __vcd_server_result_cb(vcp_result_event_e event, int* result_id, int if (0 == result_count) { /* No result */ if (NULL != all_result) { - SLOG(LOG_DEBUG, TAG_VCD, "[Server] Engine result is no command : %s", all_result); - bool temp = vcd_client_manager_get_exclusive(); - vc_info_parser_set_result(all_result, event, msg, NULL, temp); + 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) { - if (NULL != all_result) { - /* Send result text to widget */ - vcdc_send_result(pid, vcd_client_manager_get_pid(), VC_COMMAND_TYPE_WIDGET); - } - SLOG(LOG_DEBUG, TAG_VCD, "[Server] Request tooltip hide"); /* Send to hide tooltip */ vcdc_send_show_tooltip(pid, false); @@ -632,7 +714,7 @@ static void __vcd_server_result_cb(vcp_result_event_e event, int* result_id, int vcd_client_manager_set_exclusive(false); - return; + return VCD_ERROR_NONE; } else { if (false == vcd_client_manager_get_exclusive()) { int pid = vcd_client_widget_get_foreground_pid(); @@ -672,7 +754,7 @@ 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 VCD_ERROR_NONE; #else /* No result */ @@ -709,7 +791,7 @@ 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; @@ -776,7 +858,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); @@ -823,10 +905,10 @@ static void __vcd_server_result_cb(vcp_result_event_e event, int* result_id, int } #if 0 -static void __vcd_server_nlu_result_cb(vcp_result_event_e event, const char* nlu_result, void *user_data) +static void __vcd_server_nlu_result_cb(vce_result_event_e event, const char* nlu_result, void *user_data) { - SLOG(LOG_DEBUG, TAG_VCD, "[Server] NLU result cb - event(%d)", event); - SLOG(LOG_DEBUG, TAG_VCD, "[Server] result (%s)", nlu_result); + 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) { @@ -837,15 +919,22 @@ static void __vcd_server_nlu_result_cb(vcp_result_event_e event, const char* nlu } #endif -static void __vcd_server_error_cb(vcp_error_e error, const char* msg, void *user_data) +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; - error_msg = strdup(msg); + if (NULL != msg) { + error_msg = strdup(msg); + if (NULL == error_msg) { + return VCD_ERROR_OUT_OF_MEMORY; + } + } - if (0 != vcdc_send_error_signal_to_manager(vcd_client_manager_get_pid(), error, error_msg)) { + int ret = VCD_ERROR_NONE; + ret = vcdc_send_error_signal_to_manager(vcd_client_manager_get_pid(), error, error_msg); + if (VCD_ERROR_NONE != ret) { SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to send error signal"); } @@ -854,7 +943,7 @@ static void __vcd_server_error_cb(vcp_error_e error, const char* msg, void *user error_msg = NULL; } - return; + return ret; } /* @@ -865,8 +954,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); @@ -877,11 +964,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_"))) { @@ -915,7 +998,7 @@ static int __vcd_db_clean_up() return ret; } -int vcd_initialize() +int vcd_initialize(vce_request_callback_s *callback) { int ret = 0; @@ -936,8 +1019,7 @@ int vcd_initialize() vcd_config_set_service_state(VCD_STATE_NONE); - //ret = vcd_engine_agent_init(__vcd_server_pre_result_cb, __vcd_server_result_cb, __vcd_server_nlu_result_cb, __vcd_server_error_cb); - ret = vcd_engine_agent_init(__vcd_server_asr_result_cb, __vcd_server_result_cb, __vcd_server_error_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; @@ -948,21 +1030,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; } @@ -973,12 +1042,12 @@ int vcd_initialize() 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() +bool vcd_finalize() { GList *iter = NULL; if (0 < g_list_length(g_proc_list)) { @@ -1001,14 +1070,17 @@ void vcd_finalize() } vcd_engine_recognize_cancel(); } + if (0 != vcd_recorder_destroy()) { SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to destroy recorder"); + return false; } else { SLOG(LOG_DEBUG, TAG_VCD, "[Server] destroy recorder"); } if (0 != vcd_engine_agent_release()) { SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to release engine"); + return false; } else { SLOG(LOG_DEBUG, TAG_VCD, "[Server] release engine"); } @@ -1018,24 +1090,26 @@ void vcd_finalize() 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; + return true; } static Eina_Bool __finalize_quit_ecore_loop(void *data) { - SLOG(LOG_DEBUG, TAG_VCD, "[Server] quit ecore main loop"); - ecore_main_loop_quit(); - return EINA_FALSE; + bool ret = vcd_finalize(); + if (false == ret) { + return EINA_TRUE; + } else { + ecore_main_loop_quit(); + return EINA_FALSE; + } } static void __read_proc() { DIR *dp = NULL; - struct dirent entry; struct dirent *dirp = NULL; - int ret = -1; int tmp; GList *iter = NULL; @@ -1052,11 +1126,7 @@ static void __read_proc() SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to open proc"); } else { do { - ret = readdir_r(dp, &entry, &dirp); - if (0 != ret) { - SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to readdir"); - break; - } + dirp = readdir(dp); if (NULL != dirp) { tmp = atoi(dirp->d_name); @@ -1094,7 +1164,7 @@ static void __vcd_cleanup_client(vcd_client_type_e type) } if (0 == ret || mgr_pid > 0) { - SLOG(LOG_DEBUG, TAG_VCD, "===== Clean up %s client ", type ? (type == 1) ? "Widget" : "Manager" : "Normal"); + 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; @@ -1102,8 +1172,8 @@ static void __vcd_cleanup_client(vcd_client_type_e type) 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]); + 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; } @@ -1111,18 +1181,17 @@ static void __vcd_cleanup_client(vcd_client_type_e type) } if (false == exist) { - SLOG(LOG_ERROR, TAG_VCD, "%s pid(%d) should be removed", type ? (type == 1) ? "Widget" : "Manager" : "Normal", client_list[i]); + 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]); + vcd_server_finalize(*(client_list + i)); else if (VCD_CLIENT_TYPE_WIDGET == type) - vcd_server_widget_finalize(client_list[i]); + vcd_server_widget_finalize(*(client_list + i)); else vcd_server_mgr_finalize(mgr_pid); } } } - SLOG(LOG_DEBUG, TAG_VCD, "====="); - SLOG(LOG_DEBUG, TAG_VCD, " "); + SLOG(LOG_DEBUG, TAG_VCD, "@@@"); } if (NULL != client_list && -1 == mgr_pid) { free(client_list); @@ -1134,14 +1203,14 @@ static void __vcd_cleanup_client(vcd_client_type_e type) 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++) { exist = false; @@ -1173,8 +1242,7 @@ Eina_Bool vcd_cleanup_client_all(void *data) #endif } } - SLOG(LOG_DEBUG, TAG_VCD, "====="); - SLOG(LOG_DEBUG, TAG_VCD, " "); + SLOG(LOG_DEBUG, TAG_VCD, "@@@"); } if (NULL != client_list) { free(client_list); @@ -1183,7 +1251,7 @@ Eina_Bool vcd_cleanup_client_all(void *data) /* 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++) { exist = false; @@ -1215,8 +1283,7 @@ Eina_Bool vcd_cleanup_client_all(void *data) #endif } } - SLOG(LOG_DEBUG, TAG_VCD, "====="); - SLOG(LOG_DEBUG, TAG_VCD, " "); + SLOG(LOG_DEBUG, TAG_VCD, "@@@"); } if (NULL != client_list) { @@ -1267,16 +1334,6 @@ int vcd_server_get_foreground() */ 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] old manager pid(%d) be removed", vcd_client_manager_get_pid()); @@ -1293,7 +1350,7 @@ int vcd_server_mgr_initialize(int pid) if (0 != vcdc_send_manager_pid(pid)) SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Fail to send manager pid"); - SLOG(LOG_DEBUG, TAG_VCD, "[Server Success] Manager initialize : pid(%d)", pid); + SLOG(LOG_ERROR, TAG_VCD, "[Server Success] Manager initialize : pid(%d)", pid); return VCD_ERROR_NONE; } @@ -1319,10 +1376,10 @@ int vcd_server_mgr_finalize(int pid) if (0 == vcd_client_get_ref_count()) { SLOG(LOG_DEBUG, TAG_VCD, "[Server] Connected client list is empty"); - ecore_timer_add(0, __finalize_quit_ecore_loop, NULL); + ecore_timer_add(0.5, __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; } @@ -1377,7 +1434,7 @@ int vcd_server_mgr_set_audio_type(int pid, const char* audio_type) } 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; @@ -1430,31 +1487,70 @@ int vcd_server_mgr_set_client_info(int pid) return VCD_ERROR_NONE; } +static int __reset_waiting_for_widget_recording(void) +{ + SLOG(LOG_ERROR, TAG_VCD, "[Server] Reet waiting for widget recording"); + // Delete timer to check that widget client is terminated + if (g_check_widget_client_timer) { + ecore_timer_del(g_check_widget_client_timer); + g_check_widget_client_timer = NULL; + } + // Reset flag to wait for recording from widget client + vcd_client_widget_set_waiting_for_recording(-1, false); + return 0; +} + +static Eina_Bool __send_waiting_timeout_error_to_manager(void* data) +{ + intptr_t ppid = (intptr_t)data; + int pid = (int)ppid; + SLOG(LOG_ERROR, TAG_VCD, "Widget client didn't send to start recording, pid(%d)", pid); + __reset_waiting_for_widget_recording(); + + vcdc_send_error_signal_to_manager(vcd_client_manager_get_pid(), VCD_ERROR_OPERATION_FAILED, "voice_engine.error.proc_fail"); + return EINA_FALSE; +} + +static int __set_waiting_for_widget_recording(int pid) +{ + SLOG(LOG_ERROR, TAG_VCD, "[Server] Set waiting for widget recording, pid(%d)", pid); + + // Check if the app included widget client is terminated or not. If it is terminated, vcd_server_widget_finalize() function will be called + // In that function, it will start recording + intptr_t ppid = (intptr_t)pid; + g_check_widget_client_timer = ecore_timer_add(2.0, __send_waiting_timeout_error_to_manager, (void*)ppid); + + // Set flag to wait for recording from widget client + vcd_client_widget_set_waiting_for_recording(pid, true); + return 0; +} + static int __start_internal_recognition() { int ret; + __reset_waiting_for_widget_recording(); - /* 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()) { @@ -1467,23 +1563,33 @@ static int __start_internal_recognition() 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(%d)", stop_by_silence); + SLOG(LOG_ERROR, TAG_VCD, "[Server Success] Start recognition(%d)", stop_by_silence); return 0; } @@ -1492,7 +1598,7 @@ 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); } @@ -1512,17 +1618,23 @@ int vcd_server_mgr_start(vcd_recognition_mode_e recognition_mode, bool exclusive SLOG(LOG_DEBUG, TAG_VCD, "[Server] Manager is NOT available."); return VCD_ERROR_OPERATION_FAILED; } + __reset_waiting_for_widget_recording(); - SLOG(LOG_DEBUG, TAG_VCD, "[Server] set recognition mode = %d", recognition_mode); + 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); + + __set_waiting_for_widget_recording(pid); + return 0; + } } } else { vcd_client_manager_set_exclusive(exclusive_cmd); @@ -1541,6 +1653,8 @@ int vcd_server_mgr_start(vcd_recognition_mode_e recognition_mode, bool exclusive } } + 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); @@ -1551,6 +1665,7 @@ int vcd_server_mgr_start(vcd_recognition_mode_e recognition_mode, bool exclusive vcd_client_unset_exclusive_command(fg_pid); } + SLOG(LOG_ERROR, TAG_VCD, "[Server Success] start internal recognition"); return VCD_ERROR_NONE; } @@ -1565,9 +1680,12 @@ int vcd_server_mgr_stop() 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(); @@ -1579,17 +1697,12 @@ int vcd_server_mgr_stop() 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() { - /* 1. Check current state */ - 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"); - 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; @@ -1601,8 +1714,32 @@ int vcd_server_mgr_cancel() 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) { @@ -1610,10 +1747,12 @@ int vcd_server_mgr_cancel() } 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); + 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); @@ -1623,6 +1762,7 @@ int vcd_server_mgr_cancel() 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; } @@ -1735,32 +1875,74 @@ int vcd_server_mgr_do_action(int pid, int type, const char* action) if (0 != 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"); } return ret; } +int vcd_server_mgr_enable_command_type(int pid, int cmd_type) +{ + 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; + } + + ret = vcd_config_enable_command_type(cmd_type); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to enable command type"); + } else { + SLOG(LOG_ERROR, TAG_VCD, "[Server] Enable command type(%d)", cmd_type); + } + + return ret; +} + +int vcd_server_mgr_disable_command_type(int pid, int cmd_type) +{ + 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; + } + + 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; +} + /* * VC Server Functions for Client */ 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 */ @@ -1795,7 +1977,7 @@ int vcd_server_finalize(int pid) if (0 == vcd_client_get_ref_count()) { SLOG(LOG_DEBUG, TAG_VCD, "[Server] Connected client list is empty"); - ecore_timer_add(0, __finalize_quit_ecore_loop, NULL); + ecore_timer_add(0.5, __finalize_quit_ecore_loop, NULL); } SLOG(LOG_DEBUG, TAG_VCD, "[Server Success] Client Finalize : pid(%d)", pid); @@ -2063,27 +2245,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 */ @@ -2097,6 +2267,15 @@ int vcd_server_widget_initialize(int pid) return VCD_ERROR_NONE; } +static void __vcd_server_widget_start_recording(void *data) +{ + SLOG(LOG_ERROR, TAG_VCD, "[Server INFO] start recording"); + + if (0 != __start_internal_recognition()) { + SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to start recongition"); + } +} + int vcd_server_widget_finalize(int pid) { /* check if pid is valid */ @@ -2111,10 +2290,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"); - ecore_timer_add(0, __finalize_quit_ecore_loop, NULL); + SLOG(LOG_ERROR, TAG_VCD, "[Server] connected client list is empty"); + ecore_timer_add(0.5, __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_ERROR, 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; } @@ -2126,6 +2315,12 @@ int vcd_server_widget_start_recording(int pid, bool widget_command) return VCD_ERROR_INVALID_PARAMETER; } + bool waiting; + if (0 != vcd_client_widget_get_waiting_for_recording(pid, &waiting) || false == waiting) { + SLOG(LOG_ERROR, TAG_VCD, "[Server] Server is not waiting for recording, pid(%d), waiting(%d)", pid, waiting); + return 0; + } + if (true == widget_command) { vcd_client_widget_set_command(pid); SLOG(LOG_DEBUG, TAG_VCD, "[Server] widget command is available"); @@ -2134,6 +2329,7 @@ int vcd_server_widget_start_recording(int pid, bool widget_command) SLOG(LOG_WARN, TAG_VCD, "[Server] widget command is NOT available"); } + SLOG(LOG_ERROR, TAG_VCD, "[Server] start internal recongition : %d", widget_command); int ret = __start_internal_recognition(); if (0 != ret) { SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to start recongition : %d", ret); @@ -2225,3 +2421,182 @@ int vcd_server_widget_cancel(int pid) 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; +} +