/*
* VC Server static variable
*/
-static bool g_is_engine;
-
static GList *g_proc_list = NULL;
static Ecore_Timer *g_restart_timer = NULL;
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);
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");
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);
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) {
SECURE_SLOG(LOG_DEBUG, TAG_VCD, "[Server] ASR result - Event(%d), Text(%s)", event, asr_result);
- vcdc_send_pre_result_to_manager(vcd_client_manager_get_pid(), event, asr_result);
+ ret = vcdc_send_pre_result_to_manager(vcd_client_manager_get_pid(), event, asr_result);
+ if (0 != ret) {
+ SECURE_SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to send ASR result : mgr_pid(%d), asr_result(%s)", vcd_client_manager_get_pid(), asr_result);
+ }
}
- return;
+ return ret;
}
-static void __vcd_server_nlg_result_cb(const char* nlg_result, void *user_data)
+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;
+ return ret;
}
- SECURE_SLOG(LOG_ERROR, TAG_VCD, "[Server] send dialog : mgr_pid(%d), nlg_result(%s)", vcd_client_manager_get_pid(), nlg_result);
+ 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;
+ return ret;
}
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, int* user_info, 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 VCD_ERROR_INVALID_STATE;
+ }
+ }
+
vc_info_parser_unset_result(vcd_client_manager_get_exclusive());
vcd_client_manager_set_result_text(all_result);
- SECURE_SLOG(LOG_ERROR, 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);
- SECURE_SLOG(LOG_ERROR, TAG_VCD, "[Server] NLU result(%s)", nlu_result);
+ 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();
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
/* Normal 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;
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 */
int* filtered_id = (int*)calloc(count, sizeof(int));
if (!filtered_id) {
SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to allocate memory");
- return;
+ return VCD_ERROR_OUT_OF_MEMORY;
}
int filtered_count = 0;
int top_priority = VC_COMMAND_PRIORITY_BACKGROUND;
free(filtered_id);
filtered_id = NULL;
}
- return;
+ return VCD_ERROR_NONE;
}
}
}
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();
vc_cmd_list_destroy(vc_cmd_list, true);
- return;
+ return VCD_ERROR_NONE;
#else
/* No result */
}
#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)
{
SECURE_SLOG(LOG_DEBUG, TAG_VCD, "[Server] NLU result cb - event(%d)", event);
SECURE_SLOG(LOG_DEBUG, TAG_VCD, "[Server] result (%s)", nlu_result);
}
#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;
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");
}
error_msg = NULL;
}
- return;
+ return ret;
}
/*
- * vcd server Interfaces
- */
+* vcd server Interfaces
+*/
static void __vcd_file_clean_up()
{
SLOG(LOG_DEBUG, TAG_VCD, "== Old file clean up == ");
return ret;
}
-int vcd_initialize()
+int vcd_initialize(vce_request_callback_s *callback)
{
int ret = 0;
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_nlg_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;
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;
}
return 0;
}
-void vcd_finalize()
+bool vcd_finalize()
{
GList *iter = NULL;
if (0 < g_list_length(g_proc_list)) {
}
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");
}
SLOG(LOG_ERROR, TAG_VCD, "[Server] mode finalize");
- return;
+ return true;
}
static Eina_Bool __finalize_quit_ecore_loop(void *data)
{
- SLOG(LOG_ERROR, TAG_VCD, "[Server] quit ecore main loop");
- ecore_main_loop_quit();
- return EINA_FALSE;
+ bool ret = vcd_finalize();
+ if (false == ret) {
+ return EINA_TRUE;
+ } else {
+ ecore_main_loop_quit();
+ return EINA_FALSE;
+ }
}
static void __read_proc()
/*
- * API for manager
- */
+* 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] old manager pid(%d) be removed", vcd_client_manager_get_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_ERROR, TAG_VCD, "[Server Success] Manager Finalize : pid(%d)", pid);
}
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;
}
/*
- * VC Server Functions for Client
- */
+* 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 */
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);
#endif
/*
- * VC Server Functions for Widget lib
- */
+* VC Server Functions for Widget lib
+*/
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 (0 == vcd_client_get_ref_count()) {
SLOG(LOG_ERROR, 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);
return 0;
}
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;
+}
+