SLOG(LOG_DEBUG, TAG_VCD, "[Server Success] Start engine");
- if (VCD_RECOGNITION_MODE_RESTART_AFTER_REJECT == vcd_client_get_recognition_mode()) {
+ vcd_recognition_mode_e mode = vcd_client_get_recognition_mode();
+ if (VCD_RECOGNITION_MODE_RESTART_AFTER_REJECT == mode || VCD_RECOGNITION_MODE_RESTART_CONTINUOUSLY == mode) {
vcd_config_set_service_state(VCD_STATE_RECORDING);
vcdc_send_service_state(VCD_STATE_RECORDING);
}
int vcd_send_result(vce_result_event_e event, int* result_id, int count, const char* all_result, const char* non_fixed_result, const char* nlu_result, const char* msg, int* user_info, void *user_data)
{
int ret = 0;
+ vcd_recognition_mode_e recognition_mode = vcd_client_get_recognition_mode();
if (VCD_STATE_PROCESSING != vcd_config_get_service_state()) {
- if (VCD_RECOGNITION_MODE_RESTART_CONTINUOUSLY != vcd_client_get_recognition_mode()) {
+ if (VCD_RECOGNITION_MODE_RESTART_CONTINUOUSLY != recognition_mode) {
SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Current state is not 'Processing' and mode is not 'Restart continuously'");
return VCD_ERROR_INVALID_STATE;
}
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);
+ SECURE_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 */
vc_cmd_list_h vc_cmd_list = NULL;
if (0 != vc_cmd_list_create(&vc_cmd_list)) {
- SLOG(LOG_DEBUG, TAG_VCD, "[Server] Fail to create command list");
+ SLOG(LOG_INFO, TAG_VCD, "[Server] Fail to create command list");
vcd_client_manager_set_exclusive(false);
vcd_config_set_service_state(VCD_STATE_READY);
vcdc_send_service_state(VCD_STATE_READY);
int* filtered_id = (int*)calloc(count, sizeof(int));
if (!filtered_id) {
SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to allocate memory");
+ vc_cmd_list_destroy(vc_cmd_list, true);
return VCD_ERROR_OUT_OF_MEMORY;
}
int filtered_count = 0;
}
}
+ // Set state manually, because the result is already handled in ASR result by client.
+ // So, the daemon does not need to send the result to client.
vcd_client_manager_set_exclusive(false);
vcd_config_set_service_state(VCD_STATE_READY);
int result_count = 0;
vc_cmd_list_get_count(vc_cmd_list, &result_count);
+ /* Handle the result list */
if (0 == result_count) {
/* No result */
if (NULL != all_result) {
+ vc_cmd_list_h fg_priority_cmd_list = NULL;
SECURE_SLOG(LOG_DEBUG, TAG_VCD, "[Server] Engine result is no command : %s", all_result);
+
+ if (0 != vc_cmd_list_create(&fg_priority_cmd_list)) {
+ SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to create command list handle");
+ vc_cmd_list_destroy(vc_cmd_list, true);
+ return VCD_ERROR_OUT_OF_MEMORY;
+ }
+
+ /* Get the list of foreground and widget type commands */
+ vcd_client_append_cmd_from_type(VC_COMMAND_TYPE_FOREGROUND, fg_priority_cmd_list);
+ vcd_client_append_cmd_from_type(VC_COMMAND_TYPE_WIDGET, fg_priority_cmd_list);
+
+ /* Matching algorithm */
+ vc_cmd_get_partially_matched_cmd_list(all_result, fg_priority_cmd_list, vc_cmd_list, VC_SEARCH_CHAR_LEVEL);
+
+ vc_cmd_list_destroy(fg_priority_cmd_list, true);
} else {
SLOG(LOG_DEBUG, TAG_VCD, "[Server] Engine result is NULL");
}
- bool temp = vcd_client_manager_get_exclusive();
- vc_info_parser_set_result(all_result, event, msg, NULL, temp);
- int pid = vcd_client_widget_get_foreground_pid();
- if (-1 != pid) {
- SLOG(LOG_DEBUG, TAG_VCD, "[Server] Request tooltip hide");
- /* Send to hide tooltip */
- vcdc_send_show_tooltip(pid, false);
- }
-
- 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");
- }
- }
+ vc_cmd_list_get_count(vc_cmd_list, &result_count);
- vcd_client_manager_set_exclusive(false);
+ // After running partial matching algorithm, if there is no result.
+ if (0 == result_count) {
+ bool temp = vcd_client_manager_get_exclusive();
+ vc_info_parser_set_result(all_result, event, msg, NULL, temp);
- return VCD_ERROR_NONE;
- } else {
- if (false == vcd_client_manager_get_exclusive()) {
int pid = vcd_client_widget_get_foreground_pid();
if (-1 != pid) {
SLOG(LOG_DEBUG, TAG_VCD, "[Server] Request tooltip hide");
+ /* Send to hide tooltip */
vcdc_send_show_tooltip(pid, false);
}
- vc_info_parser_set_result(all_result, event, msg, vc_cmd_list, false);
-
if (-1 != vcd_client_manager_get_pid()) {
/* Manager client is available */
if (0 != vcdc_send_result_to_manager(vcd_client_manager_get_pid(), VC_RESULT_TYPE_NORMAL)) {
SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Fail to send result");
}
- } else {
- SLOG(LOG_DEBUG, TAG_VCD, "[Server] Manager is NOT available. Send result to client directly");
- /* Send result to client */
- ecore_timer_add(0, __vcd_send_selected_result, NULL);
}
- } else {
- /* exclusive command */
- vc_info_parser_set_result(all_result, event, msg, vc_cmd_list, true);
- if (-1 != vcd_client_manager_get_pid()) {
- /* Manager client is available */
- if (0 != vcdc_send_result_to_manager(vcd_client_manager_get_pid(), VC_RESULT_TYPE_NORMAL)) {
- SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Fail to send result");
+ vcd_client_manager_set_exclusive(false);
+ vc_cmd_list_destroy(vc_cmd_list, true);
+
+ return VCD_ERROR_NONE;
+ }
+
+ // Partial matching algorithm find some commands
+ top_priority = VC_COMMAND_PRIORITY_FOREGROUND;
+ event = VC_RESULT_EVENT_RESULT_SUCCESS;
+ }
+
+ // There are more than one result.
+ if (false == vcd_client_manager_get_exclusive()) {
+ /* Foreground, Widget, Background, System, System-Background */
+ if (top_priority >= VC_COMMAND_PRIORITY_BACKGROUND) {
+ vc_cmd_list_h fg_priority_cmd_list = NULL;
+ vc_cmd_list_h temp_list = NULL;
+
+ if (0 != vc_cmd_list_create(&fg_priority_cmd_list)) {
+ SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to create command list handle");
+ vc_cmd_list_destroy(vc_cmd_list, true);
+ return VCD_ERROR_OUT_OF_MEMORY;
+ }
+
+ if (0 != vc_cmd_list_create(&temp_list)) {
+ SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to create command list handle");
+ vc_cmd_list_destroy(fg_priority_cmd_list, true);
+ vc_cmd_list_destroy(vc_cmd_list, true);
+ return VCD_ERROR_OUT_OF_MEMORY;
+ }
+
+ /* Get the list of foreground and widget type commands */
+ vcd_client_append_cmd_from_type(VC_COMMAND_TYPE_FOREGROUND, fg_priority_cmd_list);
+ vcd_client_append_cmd_from_type(VC_COMMAND_TYPE_WIDGET, fg_priority_cmd_list);
+
+ /* Matching algorithm */
+ vc_cmd_get_partially_matched_cmd_list(all_result, fg_priority_cmd_list, temp_list, VC_SEARCH_CHAR_LEVEL);
+ vc_cmd_list_destroy(fg_priority_cmd_list, true);
+
+ vc_cmd_list_get_count(temp_list, &result_count);
+
+ if (0 < result_count) {
+ if (0 != vc_cmd_list_destroy(vc_cmd_list, true)) {
+ SLOG(LOG_WARN, TAG_VCD, "[WARNING] Fail to destroy list");
}
- } else {
- SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Manager is NOT available");
+ vc_cmd_list = temp_list;
+ event = VC_RESULT_EVENT_RESULT_SUCCESS;
}
+ }
- vcd_client_manager_set_exclusive(false);
+ int pid = vcd_client_widget_get_foreground_pid();
+ if (-1 != pid) {
+ SLOG(LOG_DEBUG, TAG_VCD, "[Server] Request tooltip hide");
+ vcdc_send_show_tooltip(pid, false);
+ }
+
+ vc_info_parser_set_result(all_result, event, msg, vc_cmd_list, false);
+
+ if (-1 != vcd_client_manager_get_pid()) {
+ /* Manager client is available */
+ if (0 != vcdc_send_result_to_manager(vcd_client_manager_get_pid(), VC_RESULT_TYPE_NORMAL)) {
+ SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Fail to send result");
+ }
+ } else {
+ SLOG(LOG_DEBUG, TAG_VCD, "[Server] Manager is NOT available. Send result to client directly");
+ ecore_timer_add(0, __vcd_send_selected_result, NULL);
+ }
+ } else {
+ /* exclusive command */
+ vc_info_parser_set_result(all_result, event, msg, vc_cmd_list, true);
+
+ if (-1 != vcd_client_manager_get_pid()) {
+ /* Manager client is available */
+ if (0 != vcdc_send_result_to_manager(vcd_client_manager_get_pid(), VC_RESULT_TYPE_NORMAL)) {
+ SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Fail to send result");
+ }
+ } else {
+ SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Manager is NOT available");
}
+
+ vcd_client_manager_set_exclusive(false);
}
vc_cmd_list_destroy(vc_cmd_list, true);
+ if (VCD_RECOGNITION_MODE_RESTART_AFTER_REJECT == recognition_mode) {
+ if (VCE_RESULT_EVENT_REJECTED == event) {
+ SLOG(LOG_DEBUG, TAG_VCD, "[Server] Restart by no or rejected result");
+ /* If no result and restart option is ON */
+ /* Send reject message */
+ bool temp = vcd_client_manager_get_exclusive();
+ vc_info_parser_set_result(all_result, event, msg, NULL, temp);
+ ret = vcdc_send_result_to_manager(vcd_client_manager_get_pid(), VC_RESULT_TYPE_NOTIFICATION);
+ if (0 != ret) {
+ SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Fail to send result");
+ }
+
+ g_restart_timer = ecore_timer_add(0, __restart_engine, NULL);
+ return ret;
+ }
+ SLOG(LOG_DEBUG, TAG_VCD, "[Server] Stop recorder due to success");
+ //vcd_recorder_stop();
+ ecore_main_loop_thread_safe_call_sync(__recorder_stop, NULL);
+ } else if (VCD_RECOGNITION_MODE_RESTART_CONTINUOUSLY == recognition_mode) {
+ SLOG(LOG_DEBUG, TAG_VCD, "[Server] Restart continuously");
+ /* Restart option is ON */
+ g_restart_timer = ecore_timer_add(0, __restart_engine, NULL);
+ if (VCE_RESULT_EVENT_REJECTED == event) {
+ bool temp = vcd_client_manager_get_exclusive();
+ vc_info_parser_set_result(all_result, event, msg, NULL, temp);
+ ret = vcdc_send_result_to_manager(vcd_client_manager_get_pid(), VC_RESULT_TYPE_NOTIFICATION);
+ if (0 != ret) {
+ SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Fail to send result");
+ }
+ return ret;
+ }
+ }
+
return VCD_ERROR_NONE;
#else
return ret;
}
-