From 2cdea0cceffe58976806a8e4a252647a386262aa Mon Sep 17 00:00:00 2001 From: Wonnam Jang Date: Mon, 15 Jan 2018 20:22:36 +0900 Subject: [PATCH 01/16] Load default config file when user config is invalid Change-Id: I0021fefc33e167a256c6ad3f52f0854b4c60987a Signed-off-by: Wonnam Jang (cherry picked from commit bc058016cd72cb627aa9a6d3f51f4c7d3aed8dc2) --- common/vc_config_parser.c | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/common/vc_config_parser.c b/common/vc_config_parser.c index 0048a05..ac89c5a 100644 --- a/common/vc_config_parser.c +++ b/common/vc_config_parser.c @@ -322,7 +322,14 @@ int vc_parser_load_config(vc_config_s** config_info) if (VC_RETRY_COUNT == retry_count) { SLOG(LOG_ERROR, vc_config_tag(), "[ERROR] Fail to parse file error : %s", VC_CONFIG); - return -1; + doc = xmlParseFile(VC_CONFIG_DEFAULT); + if (NULL == doc) { + SLOG(LOG_ERROR, vc_config_tag(), "[ERROR] Fail to parse file error : %s", VC_CONFIG_DEFAULT); + xmlCleanupParser(); + return -1; + } + is_default_open = true; + break; } } } @@ -426,9 +433,25 @@ int vc_parser_load_config(vc_config_s** config_info) g_config_doc = doc; if (is_default_open) { - xmlSaveFile(VC_CONFIG, g_config_doc); + int retry_count = 0; + int ret = -1; + do { + ret = xmlSaveFile(VC_CONFIG, g_config_doc); + if (0 < ret) + break; + retry_count++; + usleep(10000); + + if (VC_RETRY_COUNT == retry_count) { + SLOG(LOG_ERROR, vc_config_tag(), "[ERROR] Fail to save config file: %d", ret); + return -1; + } + } while (0 != ret); + if (0 != __vc_config_parser_set_file_mode(VC_CONFIG)) SLOG(LOG_ERROR, vc_config_tag(), "[ERROR] Fail to set file mode - %s", VC_CONFIG); + + SLOG(LOG_ERROR, vc_config_tag(), "Default config is changed : pid(%d)", getpid()); } return 0; -- 2.7.4 From 8b68b96409cbe2e0929f693b555079a40c694573 Mon Sep 17 00:00:00 2001 From: Wonnam Jang Date: Tue, 16 Jan 2018 14:50:41 +0900 Subject: [PATCH 02/16] Add log for debugging Change-Id: I80ffb9f2238c273119373f39b0b054f8c3ce253d Signed-off-by: Wonnam Jang --- client/vc_mgr.c | 60 ++++++++++++++++++++++++++--------------------------- server/vcd_server.c | 39 +++++++++++++++++++++------------- 2 files changed, 55 insertions(+), 44 deletions(-) diff --git a/client/vc_mgr.c b/client/vc_mgr.c index 5e33f6a..2ed9ab5 100644 --- a/client/vc_mgr.c +++ b/client/vc_mgr.c @@ -123,7 +123,7 @@ static int __vc_mgr_get_feature_enabled() int vc_mgr_initialize() { - SLOG(LOG_DEBUG, TAG_VCM, "@@@ [Manager] Initialize"); + SLOG(LOG_ERROR, TAG_VCM, "@@@ [Manager] Initialize"); if (0 != __vc_mgr_get_feature_enabled()) { @@ -170,7 +170,7 @@ int vc_mgr_initialize() return ret; } - SLOG(LOG_DEBUG, TAG_VCM, "[Success] pid(%d)", g_vc_m->handle); + SLOG(LOG_ERROR, TAG_VCM, "[Success] pid(%d)", g_vc_m->handle); SLOG(LOG_DEBUG, TAG_VCM, "@@@"); @@ -190,7 +190,7 @@ static void __vc_mgr_internal_unprepare() int vc_mgr_deinitialize() { - SLOG(LOG_DEBUG, TAG_VCM, "@@@ [Manager] Deinitialize"); + SLOG(LOG_ERROR, TAG_VCM, "@@@ [Manager] Deinitialize"); if (false == vc_mgr_client_is_valid(g_vc_m)) { SLOG(LOG_ERROR, TAG_VCM, "[ERROR] NOT initialized"); @@ -242,7 +242,7 @@ int vc_mgr_deinitialize() SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to close connection"); } - SLOG(LOG_DEBUG, TAG_VCM, "@@@"); + SLOG(LOG_ERROR, TAG_VCM, "@@@"); return VC_ERROR_NONE; } @@ -280,7 +280,7 @@ static Eina_Bool __vc_mgr_connect_daemon(void *data) /* Set foreground */ vc_mgr_client_set_foreground(g_vc_m, foreground, true); - SLOG(LOG_DEBUG, TAG_VCM, "[SUCCESS] Connected daemon"); + SLOG(LOG_ERROR, TAG_VCM, "[SUCCESS] Connected daemon"); vc_mgr_client_set_client_state(g_vc_m, VC_STATE_READY); @@ -354,7 +354,7 @@ static void __end_prepare_thread(void *data, Ecore_Thread *thread) int vc_mgr_prepare() { - SLOG(LOG_DEBUG, TAG_VCM, "@@@ [Manager] Prepare"); + SLOG(LOG_ERROR, TAG_VCM, "@@@ [Manager] Prepare"); vc_state_e state; if (0 != vc_mgr_client_get_client_state(g_vc_m, &state)) { @@ -379,7 +379,7 @@ int vc_mgr_prepare() int vc_mgr_unprepare() { - SLOG(LOG_DEBUG, TAG_VCM, "@@@ [Manager] Unprepare"); + SLOG(LOG_ERROR, TAG_VCM, "@@@ [Manager] Unprepare"); vc_state_e state; if (0 != vc_mgr_client_get_client_state(g_vc_m, &state)) { @@ -453,7 +453,7 @@ int vc_mgr_get_current_language(char** language) ret = vc_config_convert_error_code((vc_config_error_e)ret); SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to get current languages : %s", __vc_mgr_get_error_code(ret)); } else { - SLOG(LOG_DEBUG, TAG_VCM, "[Get current language] language : %s", *language); + SLOG(LOG_ERROR, TAG_VCM, "[Get current language] language : %s", *language); } return ret; @@ -597,7 +597,7 @@ int vc_mgr_unset_demandable_client_rule() int vc_mgr_is_command_format_supported(vc_cmd_format_e format, bool* support) { - SLOG(LOG_DEBUG, TAG_VCM, "@@@ [Manager] Is command type supported"); + SLOG(LOG_ERROR, TAG_VCM, "@@@ [Manager] Is command type supported"); vc_state_e state; if (0 != vc_mgr_client_get_client_state(g_vc_m, &state)) { @@ -630,7 +630,7 @@ int vc_mgr_is_command_format_supported(vc_cmd_format_e format, bool* support) int vc_mgr_enable_command_type(int cmd_type) { - SLOG(LOG_DEBUG, TAG_VCM, "@@@ [Manager] Enable Command Type"); + SLOG(LOG_ERROR, TAG_VCM, "@@@ [Manager] Enable Command Type, cmd_type(%d)", cmd_type); vc_state_e state; if (0 != vc_mgr_client_get_client_state(g_vc_m, &state)) { @@ -675,14 +675,14 @@ int vc_mgr_enable_command_type(int cmd_type) } } while (0 != ret); - SLOG(LOG_DEBUG, TAG_VCM, "@@@"); + SLOG(LOG_ERROR, TAG_VCM, "@@@, ret(%d)", ret); return ret; } int vc_mgr_disable_command_type(int cmd_type) { - SLOG(LOG_DEBUG, TAG_VCM, "@@@ [Manager] Disable Command Type"); + SLOG(LOG_ERROR, TAG_VCM, "@@@ [Manager] Disable Command Type, cmd_type(%d)", cmd_type); vc_state_e state; if (0 != vc_mgr_client_get_client_state(g_vc_m, &state)) { @@ -727,14 +727,14 @@ int vc_mgr_disable_command_type(int cmd_type) } } while (0 != ret); - SLOG(LOG_DEBUG, TAG_VCM, "@@@"); + SLOG(LOG_ERROR, TAG_VCM, "@@@, ret(%d)", ret); return ret; } int vc_mgr_set_command_list(vc_cmd_list_h vc_cmd_list) { - SLOG(LOG_DEBUG, TAG_VCM, "@@@ [Manager] Set Command list"); + SLOG(LOG_ERROR, TAG_VCM, "@@@ [Manager] Set Command list"); vc_state_e state; if (0 != vc_mgr_client_get_client_state(g_vc_m, &state)) { @@ -814,14 +814,14 @@ int vc_mgr_set_command_list(vc_cmd_list_h vc_cmd_list) } while (0 != ret); } - SLOG(LOG_DEBUG, TAG_VCM, "@@@"); + SLOG(LOG_ERROR, TAG_VCM, "@@@, ret(%d)", ret); return ret; } int vc_mgr_unset_command_list() { - SLOG(LOG_DEBUG, TAG_VCM, "@@@ [Manager] Unset Command list"); + SLOG(LOG_ERROR, TAG_VCM, "@@@ [Manager] Unset Command list"); vc_state_e state; if (0 != vc_mgr_client_get_client_state(g_vc_m, &state)) { @@ -862,14 +862,14 @@ int vc_mgr_unset_command_list() SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to delete file, type(%d), ret(%d)", i, ret); } - SLOG(LOG_DEBUG, TAG_VCM, "@@@"); + SLOG(LOG_ERROR, TAG_VCM, "@@@"); return 0; } int vc_mgr_set_command_list_from_file(const char* file_path, int type) { - SLOG(LOG_DEBUG, TAG_VCM, "@@@ [Manager] Set Command list from file"); + SLOG(LOG_ERROR, TAG_VCM, "@@@ [Manager] Set Command list from file, type(%d)", type); if (NULL == file_path) { SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Invalid parameter!!"); @@ -933,14 +933,14 @@ int vc_mgr_set_command_list_from_file(const char* file_path, int type) } while (0 != ret); } - SLOG(LOG_DEBUG, TAG_VCM, "@@@"); + SLOG(LOG_ERROR, TAG_VCM, "@@@, ret(%d)", ret); return ret; } int vc_mgr_set_preloaded_commands_from_file(const char* file_path) { - SLOG(LOG_DEBUG, TAG_VCM, "@@@ [Manager] Set preloaded command list"); + SLOG(LOG_ERROR, TAG_VCM, "@@@ [Manager] Set preloaded command list"); vc_state_e state; if (0 != vc_mgr_client_get_client_state(g_vc_m, &state)) { @@ -967,13 +967,13 @@ int vc_mgr_set_preloaded_commands_from_file(const char* file_path) if (0 != ret) SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to insert preloaded commands into db"); - SLOG(LOG_DEBUG, TAG_VCM, "@@@"); + SLOG(LOG_ERROR, TAG_VCM, "@@@, ret(%d)", ret); return ret; } int vc_mgr_set_audio_type(const char* audio_id) { - SLOG(LOG_DEBUG, TAG_VCM, "@@@ [Manager] Set audio type"); + SLOG(LOG_ERROR, TAG_VCM, "@@@ [Manager] Set audio type, audio_id(%s)", audio_id); if (NULL == audio_id) { SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Input parameter is NULL"); @@ -1029,14 +1029,14 @@ int vc_mgr_set_audio_type(const char* audio_id) } } - SLOG(LOG_DEBUG, TAG_VCM, "@@@"); + SLOG(LOG_ERROR, TAG_VCM, "@@@, ret(%d)", ret); return ret; } int vc_mgr_get_audio_type(char** audio_id) { - SLOG(LOG_DEBUG, TAG_VCM, "@@@ [Manager] Get audio type"); + SLOG(LOG_ERROR, TAG_VCM, "@@@ [Manager] Get audio type"); if (NULL == audio_id) { SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Input parameter is NULL"); @@ -1090,7 +1090,7 @@ int vc_mgr_get_audio_type(char** audio_id) } } } else { - SLOG(LOG_DEBUG, TAG_VCM, "[SUCCESS] Get audio type : %s", temp); + SLOG(LOG_ERROR, TAG_VCM, "[SUCCESS] Get audio type : %s", temp); /* Save */ vc_mgr_client_set_audio_type(g_vc_m, temp); } @@ -1108,7 +1108,7 @@ int vc_mgr_get_audio_type(char** audio_id) int vc_mgr_get_current_commands(vc_cmd_list_h* vc_cmd_list) { - SLOG(LOG_DEBUG, TAG_VCM, "@@@ [Manager] Foreach current commands"); + SLOG(LOG_ERROR, TAG_VCM, "@@@ [Manager] Foreach current commands"); vc_state_e state; if (0 != vc_mgr_client_get_client_state(g_vc_m, &state)) { @@ -1294,7 +1294,7 @@ int vc_mgr_get_current_commands(vc_cmd_list_h* vc_cmd_list) SLOG(LOG_DEBUG, TAG_VCM, "[Manager] No background commands"); } - SLOG(LOG_DEBUG, TAG_VCM, "@@@"); + SLOG(LOG_ERROR, TAG_VCM, "@@@"); return 0; } @@ -1587,7 +1587,7 @@ int vc_mgr_do_action(vc_send_event_type_e type, char* send_event) int vc_mgr_start(bool exclusive_command_option) { - SLOG(LOG_DEBUG, TAG_VCM, "@@@ [Manager] Request start"); + SLOG(LOG_ERROR, TAG_VCM, "@@@ [Manager] Request start"); vc_state_e state; if (0 != vc_mgr_client_get_client_state(g_vc_m, &state)) { @@ -1665,14 +1665,14 @@ int vc_mgr_start(bool exclusive_command_option) g_prev_volume_db = 0; g_cur_volume_db = 0; - SLOG(LOG_DEBUG, TAG_VCM, "@@@"); + SLOG(LOG_ERROR, TAG_VCM, "@@@, ret(%d)", ret); return ret; } int vc_mgr_stop() { - SLOG(LOG_DEBUG, TAG_VCM, "@@@ [Manager] Request stop"); + SLOG(LOG_ERROR, TAG_VCM, "@@@ [Manager] Request stop"); vc_state_e state; if (0 != vc_mgr_client_get_client_state(g_vc_m, &state)) { diff --git a/server/vcd_server.c b/server/vcd_server.c index 6cbc2b9..6b13ed0 100755 --- a/server/vcd_server.c +++ b/server/vcd_server.c @@ -400,7 +400,7 @@ 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; } @@ -440,6 +440,7 @@ int vcd_send_nlg_result(const char* nlg_result, void *user_data) 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); @@ -469,6 +470,8 @@ int vcd_send_result(vce_result_event_e event, int* result_id, int count, const c SECURE_SLOG(LOG_INFO, TAG_VCD, "[Server] Event(%d), Text(%s) Nonfixed(%s) Msg(%s) Result count(%d)", event, all_result, non_fixed_result, msg, count); + SLOG(LOG_ERROR, TAG_VCD, "[Server] NLU result(%s)", nlu_result); + if (VCD_RECOGNITION_MODE_RESTART_AFTER_REJECT == vcd_client_get_recognition_mode()) { if (VCE_RESULT_EVENT_REJECTED == event) { SLOG(LOG_DEBUG, TAG_VCD, "[Server] Restart by no or rejected result"); @@ -572,7 +575,7 @@ int vcd_send_result(vce_result_event_e event, int* result_id, int count, const c if (true == is_consumed) { if (NULL != user_info) { *user_info = 0x01; - SLOG(LOG_DEBUG, TAG_VCD, "[Server] Send whether ASR result is consumed or not (%d)", *user_info); + 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()) { @@ -1024,7 +1027,7 @@ int vcd_initialize(vce_request_callback_s *callback) 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; } @@ -1069,7 +1072,7 @@ 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; } @@ -1325,7 +1328,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; } @@ -1354,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; } @@ -1486,7 +1489,7 @@ static int __start_internal_recognition() 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()) { @@ -1506,7 +1509,7 @@ static int __start_internal_recognition() 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 */ @@ -1525,7 +1528,7 @@ static int __start_internal_recognition() 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; } @@ -1534,7 +1537,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); } @@ -1556,7 +1559,7 @@ int vcd_server_mgr_start(vcd_recognition_mode_e recognition_mode, bool exclusive } vcd_client_widget_set_waiting_for_recording(-1, false); - 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) { @@ -1565,7 +1568,7 @@ int vcd_server_mgr_start(vcd_recognition_mode_e recognition_mode, bool 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_INFO, TAG_VCD, "[Server] Request tooltip show and widget command"); + 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; @@ -1588,6 +1591,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); @@ -1598,6 +1603,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; } @@ -1612,6 +1618,7 @@ 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 */ @@ -1628,6 +1635,7 @@ 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; } @@ -1663,6 +1671,7 @@ int vcd_server_mgr_cancel() 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 */ @@ -1691,6 +1700,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; } @@ -1831,7 +1841,7 @@ int vcd_server_mgr_enable_command_type(int pid, int cmd_type) if (0 != ret) { SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to enable command type"); } else { - SLOG(LOG_DEBUG, TAG_VCD, "[Server] Enable command type(%d)", cmd_type); + SLOG(LOG_ERROR, TAG_VCD, "[Server] Enable command type(%d)", cmd_type); } return ret; @@ -1857,7 +1867,7 @@ int vcd_server_mgr_disable_command_type(int pid, int cmd_type) if (0 != ret) { SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to disable command type"); } else { - SLOG(LOG_DEBUG, TAG_VCD, "[Server] Disable command type(%d)", cmd_type); + SLOG(LOG_ERROR, TAG_VCD, "[Server] Disable command type(%d)", cmd_type); } return ret; @@ -2250,6 +2260,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); -- 2.7.4 From b6bd8182b5ef14425febae7684d39fb1e825da81 Mon Sep 17 00:00:00 2001 From: Wonnam Jang Date: Tue, 16 Jan 2018 20:13:28 +0900 Subject: [PATCH 03/16] Reset waiting flag when recognition starts by widget Change-Id: I3bbfbaa4d8bfee09563ec0ecccfdca2e167e06af Signed-off-by: Wonnam Jang (cherry picked from commit 2f1663d67c69531413405f80bdca4b47b5322305) --- server/vcd_server.c | 1 + 1 file changed, 1 insertion(+) diff --git a/server/vcd_server.c b/server/vcd_server.c index 6cbc2b9..d6646f2 100755 --- a/server/vcd_server.c +++ b/server/vcd_server.c @@ -1465,6 +1465,7 @@ 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); if (0 != vcd_client_command_collect_command()) { SLOG(LOG_ERROR, TAG_VCD, "[Client Data ERROR] Fail to collect command"); -- 2.7.4 From e5aa26e2ab9eb8fc4bbff513a5d2af93c865433b Mon Sep 17 00:00:00 2001 From: sungrae jo Date: Wed, 24 Jan 2018 15:08:53 +0900 Subject: [PATCH 04/16] Fixed logic for stt unprepare Change-Id: Icd0b56cda3d049fea008e72dec7127332fd3002e Signed-off-by: sungrae jo --- server/vcd_engine_agent.c | 8 ++++++-- server/vcd_recorder.c | 4 +++- server/vcd_server.c | 22 ++++++++++++++-------- server/vcd_server.h | 2 +- 4 files changed, 24 insertions(+), 12 deletions(-) diff --git a/server/vcd_engine_agent.c b/server/vcd_engine_agent.c index 1f4c585..28748fd 100644 --- a/server/vcd_engine_agent.c +++ b/server/vcd_engine_agent.c @@ -120,7 +120,10 @@ int vcd_engine_agent_release() } /* unload current engine */ - vcd_engine_agent_unload_current_engine(); + if (0 != vcd_engine_agent_unload_current_engine()) { + SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Fail to deinitialize"); + return VCD_ERROR_OPERATION_FAILED; + } /* release current engine data */ if (NULL != g_dynamic_engine.callbacks) { @@ -298,12 +301,13 @@ int vcd_engine_agent_unload_current_engine() ret = g_dynamic_engine.callbacks->deinitialize(); if (0 != ret) { SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Fail to deinitialize"); + return VCD_ERROR_OPERATION_FAILED; } /* reset current engine data */ g_dynamic_engine.is_loaded = false; - return 0; + return VCD_ERROR_NONE; } diff --git a/server/vcd_recorder.c b/server/vcd_recorder.c index f3194d4..eea8f50 100644 --- a/server/vcd_recorder.c +++ b/server/vcd_recorder.c @@ -483,7 +483,9 @@ int vcd_recorder_destroy() if (0 != ret) SLOG(LOG_ERROR, TAG_VCD, "[Recorder ERROR] Fail to destroy stream info, ret(%d)", ret); - audio_in_destroy(g_audio_h); + ret = audio_in_destroy(g_audio_h); + if (0 != ret) + SLOG(LOG_ERROR, TAG_VCD, "[Recorder ERROR] Fail to audio in destroy, ret(%d)", ret); #ifdef TV_BT_MODE bt_hid_unset_audio_data_receive_cb(); diff --git a/server/vcd_server.c b/server/vcd_server.c index 6cbc2b9..9c28722 100755 --- a/server/vcd_server.c +++ b/server/vcd_server.c @@ -1029,7 +1029,7 @@ int vcd_initialize(vce_request_callback_s *callback) return 0; } -void vcd_finalize() +bool vcd_finalize() { GList *iter = NULL; if (0 < g_list_length(g_proc_list)) { @@ -1054,12 +1054,14 @@ void vcd_finalize() } 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"); } @@ -1071,14 +1073,18 @@ void vcd_finalize() SLOG(LOG_DEBUG, 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() @@ -1351,7 +1357,7 @@ 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); @@ -1905,7 +1911,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); @@ -2218,7 +2224,7 @@ int vcd_server_widget_finalize(int pid) 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; } diff --git a/server/vcd_server.h b/server/vcd_server.h index b328a7e..6df0154 100644 --- a/server/vcd_server.h +++ b/server/vcd_server.h @@ -32,7 +32,7 @@ extern "C" { */ int vcd_initialize(vce_request_callback_s *callback); -void vcd_finalize(); +bool vcd_finalize(); Eina_Bool vcd_cleanup_client_all(void *data); -- 2.7.4 From 07c58373ab34e4992c76f5575737a082af12326a Mon Sep 17 00:00:00 2001 From: Jihoon Kim Date: Thu, 8 Feb 2018 14:14:13 +0900 Subject: [PATCH 05/16] Fix typo in log Change-Id: I75166ed67d73e2a7cc3d3351adc985a85630697f Signed-off-by: Jihoon Kim --- server/vcd_dbus.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/server/vcd_dbus.c b/server/vcd_dbus.c index 325aaf3..a60006a 100755 --- a/server/vcd_dbus.c +++ b/server/vcd_dbus.c @@ -502,7 +502,7 @@ int vcdc_send_service_state(vcd_state_e state) SLOG(LOG_ERROR, TAG_VCD, "[Dbus ERROR] Fail to Send"); return VCD_ERROR_OPERATION_FAILED; } else { - SLOG(LOG_DEBUG, TAG_VCD, "@@ Send serive state message to manager : state(%d)", state); + SLOG(LOG_DEBUG, TAG_VCD, "@@ Send service state message to manager : state(%d)", state); dbus_connection_flush(g_conn_sender); } @@ -527,7 +527,7 @@ int vcdc_send_service_state(vcd_state_e state) SLOG(LOG_ERROR, TAG_VCD, "[Dbus ERROR] Fail to Send"); return VCD_ERROR_OPERATION_FAILED; } else { - SLOG(LOG_DEBUG, TAG_VCD, "@@ Send serive state message to client : state(%d)", state); + SLOG(LOG_DEBUG, TAG_VCD, "@@ Send service state message to client : state(%d)", state); dbus_connection_flush(g_conn_sender); } @@ -552,7 +552,7 @@ int vcdc_send_service_state(vcd_state_e state) SLOG(LOG_ERROR, TAG_VCD, "[Dbus ERROR] Fail to Send"); return VCD_ERROR_OPERATION_FAILED; } else { - SLOG(LOG_DEBUG, TAG_VCD, "@@ Send serive state message to widget client : state(%d)", state); + SLOG(LOG_DEBUG, TAG_VCD, "@@ Send service state message to widget client : state(%d)", state); dbus_connection_flush(g_conn_sender); } -- 2.7.4 From d663fe04dceec46a9b1893a813eab766535d1917 Mon Sep 17 00:00:00 2001 From: Wonnam Jang Date: Mon, 19 Feb 2018 11:43:12 +0900 Subject: [PATCH 06/16] Fix memory leak when engine is not found Change-Id: I3bb6c64cb76eb6a646c2ad747e50937921b35e4f Signed-off-by: Wonnam Jang --- common/vc_config_mgr.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/common/vc_config_mgr.c b/common/vc_config_mgr.c index 77bd3a2..296e88a 100755 --- a/common/vc_config_mgr.c +++ b/common/vc_config_mgr.c @@ -602,6 +602,7 @@ int vc_config_mgr_initialize(int uid) if (0 != __vc_config_mgr_check_engine_is_valid(g_config_info->engine_id)) { SLOG(LOG_ERROR, vc_config_tag(), "[ERROR] Fail to get default engine"); + vc_parser_unload_config(g_config_info); pthread_mutex_unlock(&vc_config_mgr_mutex); return VC_CONFIG_ERROR_ENGINE_NOT_FOUND; } @@ -615,6 +616,7 @@ int vc_config_mgr_initialize(int uid) char* tmp_language; if (0 != __vc_config_mgr_select_lang(g_config_info->engine_id, &tmp_language)) { SLOG(LOG_ERROR, vc_config_tag(), "[ERROR] Fail to select language"); + vc_parser_unload_config(g_config_info); pthread_mutex_unlock(&vc_config_mgr_mutex); return -1; } @@ -628,6 +630,7 @@ int vc_config_mgr_initialize(int uid) if (0 != vc_parser_set_language(tmp_language)) { free(tmp_language); SLOG(LOG_ERROR, vc_config_tag(), "[ERROR] Fail to save config"); + vc_parser_unload_config(g_config_info); pthread_mutex_unlock(&vc_config_mgr_mutex); return -1; } @@ -652,6 +655,7 @@ int vc_config_mgr_initialize(int uid) temp_client = (vc_config_client_s*)calloc(1, sizeof(vc_config_client_s)); if (NULL == temp_client) { SLOG(LOG_ERROR, vc_config_tag(), "[ERROR] Fail to allocate memory"); + vc_parser_unload_config(g_config_info); pthread_mutex_unlock(&vc_config_mgr_mutex); return VC_ERROR_OUT_OF_MEMORY; } -- 2.7.4 From 6e35a7628707b49ded839c966a15247bf524736e Mon Sep 17 00:00:00 2001 From: Wonnam Jang Date: Fri, 23 Feb 2018 07:03:30 +0000 Subject: [PATCH 07/16] Revert "Fixed logic for stt unprepare" This reverts commit e5aa26e2ab9eb8fc4bbff513a5d2af93c865433b. Change-Id: I9b3ad6918c8db94babc641d003da84456de91b6a --- server/vcd_engine_agent.c | 8 ++------ server/vcd_recorder.c | 4 +--- server/vcd_server.c | 22 ++++++++-------------- server/vcd_server.h | 2 +- 4 files changed, 12 insertions(+), 24 deletions(-) diff --git a/server/vcd_engine_agent.c b/server/vcd_engine_agent.c index 28748fd..1f4c585 100644 --- a/server/vcd_engine_agent.c +++ b/server/vcd_engine_agent.c @@ -120,10 +120,7 @@ int vcd_engine_agent_release() } /* unload current engine */ - if (0 != vcd_engine_agent_unload_current_engine()) { - SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Fail to deinitialize"); - return VCD_ERROR_OPERATION_FAILED; - } + vcd_engine_agent_unload_current_engine(); /* release current engine data */ if (NULL != g_dynamic_engine.callbacks) { @@ -301,13 +298,12 @@ int vcd_engine_agent_unload_current_engine() ret = g_dynamic_engine.callbacks->deinitialize(); if (0 != ret) { SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Fail to deinitialize"); - return VCD_ERROR_OPERATION_FAILED; } /* reset current engine data */ g_dynamic_engine.is_loaded = false; - return VCD_ERROR_NONE; + return 0; } diff --git a/server/vcd_recorder.c b/server/vcd_recorder.c index eea8f50..f3194d4 100644 --- a/server/vcd_recorder.c +++ b/server/vcd_recorder.c @@ -483,9 +483,7 @@ int vcd_recorder_destroy() if (0 != ret) SLOG(LOG_ERROR, TAG_VCD, "[Recorder ERROR] Fail to destroy stream info, ret(%d)", ret); - ret = audio_in_destroy(g_audio_h); - if (0 != ret) - SLOG(LOG_ERROR, TAG_VCD, "[Recorder ERROR] Fail to audio in destroy, ret(%d)", ret); + audio_in_destroy(g_audio_h); #ifdef TV_BT_MODE bt_hid_unset_audio_data_receive_cb(); diff --git a/server/vcd_server.c b/server/vcd_server.c index 9c28722..6cbc2b9 100755 --- a/server/vcd_server.c +++ b/server/vcd_server.c @@ -1029,7 +1029,7 @@ int vcd_initialize(vce_request_callback_s *callback) return 0; } -bool vcd_finalize() +void vcd_finalize() { GList *iter = NULL; if (0 < g_list_length(g_proc_list)) { @@ -1054,14 +1054,12 @@ bool vcd_finalize() } 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"); } @@ -1073,18 +1071,14 @@ bool vcd_finalize() SLOG(LOG_DEBUG, TAG_VCD, "[Server] mode finalize"); - return true; + return; } static Eina_Bool __finalize_quit_ecore_loop(void *data) { - bool ret = vcd_finalize(); - if (false == ret) { - return EINA_TRUE; - } else { - ecore_main_loop_quit(); - return EINA_FALSE; - } + SLOG(LOG_ERROR, TAG_VCD, "[Server] quit ecore main loop"); + ecore_main_loop_quit(); + return EINA_FALSE; } static void __read_proc() @@ -1357,7 +1351,7 @@ 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.5, __finalize_quit_ecore_loop, NULL); + ecore_timer_add(0, __finalize_quit_ecore_loop, NULL); } SLOG(LOG_DEBUG, TAG_VCD, "[Server Success] Manager Finalize : pid(%d)", pid); @@ -1911,7 +1905,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.5, __finalize_quit_ecore_loop, NULL); + ecore_timer_add(0, __finalize_quit_ecore_loop, NULL); } SLOG(LOG_DEBUG, TAG_VCD, "[Server Success] Client Finalize : pid(%d)", pid); @@ -2224,7 +2218,7 @@ int vcd_server_widget_finalize(int pid) if (0 == vcd_client_get_ref_count()) { SLOG(LOG_ERROR, TAG_VCD, "[Server] connected client list is empty"); - ecore_timer_add(0.5, __finalize_quit_ecore_loop, NULL); + ecore_timer_add(0, __finalize_quit_ecore_loop, NULL); return 0; } diff --git a/server/vcd_server.h b/server/vcd_server.h index 6df0154..b328a7e 100644 --- a/server/vcd_server.h +++ b/server/vcd_server.h @@ -32,7 +32,7 @@ extern "C" { */ int vcd_initialize(vce_request_callback_s *callback); -bool vcd_finalize(); +void vcd_finalize(); Eina_Bool vcd_cleanup_client_all(void *data); -- 2.7.4 From 978089d3660047ebcca2be26f39d8c5e2bfba5d3 Mon Sep 17 00:00:00 2001 From: Wonnam Jang Date: Wed, 17 Jan 2018 19:41:29 +0900 Subject: [PATCH 08/16] Send error signal to manager client when widget doesn't start recording Change-Id: Id9adae3e2a86f5eb8f7433a103c586bce0d05270 Signed-off-by: Wonnam Jang (cherry picked from commit 58d8c3f96d0da340dd31c9f7ecb76e82a5c6c6c1) --- server/vcd_client_data.c | 4 ++-- server/vcd_server.c | 54 +++++++++++++++++++++++++++++++++++++++++++----- 2 files changed, 51 insertions(+), 7 deletions(-) diff --git a/server/vcd_client_data.c b/server/vcd_client_data.c index c18b8b2..358ddb7 100644 --- a/server/vcd_client_data.c +++ b/server/vcd_client_data.c @@ -1413,7 +1413,7 @@ int vcd_client_widget_set_waiting_for_recording(int pid, bool waiting) g_is_waiting_recording = waiting; g_waiting_recording_pid = pid; - SLOG(LOG_INFO, TAG_VCD, "[INFO] Success to set waiting for recording, pid(%d), waiting(%d)", pid, waiting); + SLOG(LOG_ERROR, TAG_VCD, "[INFO] Success to set waiting for recording, pid(%d), waiting(%d)", pid, waiting); return 0; } @@ -1425,7 +1425,7 @@ int vcd_client_widget_get_waiting_for_recording(int pid, bool* waiting) } *waiting = g_is_waiting_recording; - SLOG(LOG_INFO, TAG_VCD, "[INFO] Success to get waiting for recording, waiting(%d)", *waiting); + SLOG(LOG_ERROR, TAG_VCD, "[INFO] Success to get waiting for recording, waiting(%d)", *waiting); return 0; } diff --git a/server/vcd_server.c b/server/vcd_server.c index 65fb25b..ecdd61c 100755 --- a/server/vcd_server.c +++ b/server/vcd_server.c @@ -39,6 +39,7 @@ 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. @@ -1465,10 +1466,45 @@ 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) +{ + SLOG(LOG_ERROR, TAG_VCD, "Widget client didn't send to start recording, pid(%d)", (int)data); + __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 + g_check_widget_client_timer = ecore_timer_add(2.0, __send_waiting_timeout_error_to_manager, (void*)pid); + + // 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; - vcd_client_widget_set_waiting_for_recording(-1, false); + __reset_waiting_for_widget_recording(); if (0 != vcd_client_command_collect_command()) { SLOG(LOG_ERROR, TAG_VCD, "[Client Data ERROR] Fail to collect command"); @@ -1558,7 +1594,7 @@ 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; } - vcd_client_widget_set_waiting_for_recording(-1, false); + __reset_waiting_for_widget_recording(); SLOG(LOG_ERROR, TAG_VCD, "[Server] set recognition mode = %d", recognition_mode); vcd_client_set_recognition_mode(recognition_mode); @@ -1571,7 +1607,8 @@ int vcd_server_mgr_start(vcd_recognition_mode_e recognition_mode, bool exclusive 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); + + __set_waiting_for_widget_recording(pid); return 0; } } @@ -2208,10 +2245,11 @@ int vcd_server_widget_initialize(int pid) 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"); } - vcd_client_widget_set_waiting_for_recording(-1, false); } int vcd_server_widget_finalize(int pid) @@ -2239,7 +2277,7 @@ int vcd_server_widget_finalize(int pid) } if (true == is_waiting) { - SLOG(LOG_INFO, TAG_VCD, "[Server INFO] invoke to start recording"); + 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; @@ -2253,6 +2291,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"); -- 2.7.4 From 3d18b21c01b9a1158645f76895e4259e98a4d977 Mon Sep 17 00:00:00 2001 From: Suyeon Hwang Date: Mon, 22 Jan 2018 20:35:42 +0900 Subject: [PATCH 09/16] Move adding match rule code Change-Id: I56713583b07392fbdcb5926f0a805c21a4fd736e Signed-off-by: Suyeon Hwang (cherry picked from commit 4890129b35545db17e2ebf5e84490d8248a21e09) --- client/vc.c | 7 +++++-- client/vc_dbus.c | 28 ++++++++++++++-------------- 2 files changed, 19 insertions(+), 16 deletions(-) diff --git a/client/vc.c b/client/vc.c index da52879..9cfc04b 100644 --- a/client/vc.c +++ b/client/vc.c @@ -1631,8 +1631,11 @@ int __vc_cb_error(int reason, int daemon_pid, char* msg) /* check state */ if (state != VC_STATE_READY) { - SLOG(LOG_ERROR, TAG_VCC, "[ERROR] not connected client yet"); - return -1; + if (VC_ERROR_SERVICE_RESET != reason) { + SLOG(LOG_ERROR, TAG_VCC, "[ERROR] not connected client yet"); + return -1; + } + return 0; } if (VC_ERROR_SERVICE_RESET == reason) { diff --git a/client/vc_dbus.c b/client/vc_dbus.c index c8d3937..7bc8cef 100644 --- a/client/vc_dbus.c +++ b/client/vc_dbus.c @@ -272,8 +272,8 @@ int vc_dbus_open_connection() return 0; } - char rule[128] = {0, }; - snprintf(rule, 128, "type='signal',interface='%s'", VC_CLIENT_SERVICE_INTERFACE); + char rule[256] = {0, }; + snprintf(rule, 256, "type='signal',interface='%s'", VC_CLIENT_SERVICE_INTERFACE); /* add a rule for which messages we want to see */ dbus_bus_add_match(g_conn_listener, rule, &err); @@ -286,6 +286,18 @@ int vc_dbus_open_connection() return VC_ERROR_OPERATION_FAILED; } + /* add a rule for daemon error */ + snprintf(rule, 256, "sender='org.freedesktop.DBus',path='/org/freedesktop/DBus',interface='org.freedesktop.DBus',member='NameOwnerChanged',type='signal',arg0='%s'", VC_SERVER_SERVICE_INTERFACE); + dbus_bus_add_match(g_conn_listener, rule, &err); + dbus_connection_flush(g_conn_listener); + + if (dbus_error_is_set(&err)) { + SLOG(LOG_ERROR, TAG_VCC, "Match Error (%s)", err.message); + dbus_error_free(&err); + __vc_dbus_connection_free(); + return VC_ERROR_OPERATION_FAILED; + } + int fd = 0; if (1 != dbus_connection_get_unix_fd(g_conn_listener, &fd)) { SLOG(LOG_ERROR, TAG_VCC, "fail to get fd from dbus "); @@ -485,18 +497,6 @@ int vc_dbus_request_initialize(int pid, int* mgr_pid, int* service_state, int* d *service_state = tmp_service_state; *daemon_pid = tmp_daemon_pid; - /* add a rule for daemon error */ - char rule_err[256] = {0, }; - snprintf(rule_err, 256, "sender='org.freedesktop.DBus',path='/org/freedesktop/DBus',interface='org.freedesktop.DBus',member='NameOwnerChanged',type='signal',arg0='%s'", VC_SERVER_SERVICE_INTERFACE); - dbus_bus_add_match(g_conn_listener, rule_err, &err); - dbus_connection_flush(g_conn_listener); - - if (dbus_error_is_set(&err)) { - SLOG(LOG_ERROR, TAG_VCC, "Match Error (%s)", err.message); - dbus_error_free(&err); - return VC_ERROR_OPERATION_FAILED; - } - SLOG(LOG_DEBUG, TAG_VCC, "@@ vc initialize : result = %d mgr = %d service = %d daemon_pid = %d", result, *mgr_pid, *service_state, *daemon_pid); } else { SLOG(LOG_ERROR, TAG_VCC, "@@ vc initialize : result = %d", result); -- 2.7.4 From fa3089e4118336be8fe7097fd9d32988c71edafd Mon Sep 17 00:00:00 2001 From: Suyeon Hwang Date: Mon, 22 Jan 2018 22:03:17 +0900 Subject: [PATCH 10/16] Fix invalid casting Change-Id: Ibe0efb537deadc999f67b5ab9b94f3a789c43c0b Signed-off-by: Suyeon Hwang (cherry picked from commit d73a148aca19b5423df39706b304b807421e98c5) --- server/vcd_server.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/server/vcd_server.c b/server/vcd_server.c index ecdd61c..58d6d7d 100755 --- a/server/vcd_server.c +++ b/server/vcd_server.c @@ -1481,7 +1481,9 @@ static int __reset_waiting_for_widget_recording(void) static Eina_Bool __send_waiting_timeout_error_to_manager(void* data) { - SLOG(LOG_ERROR, TAG_VCD, "Widget client didn't send to start recording, pid(%d)", (int)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"); @@ -1494,7 +1496,8 @@ static int __set_waiting_for_widget_recording(int pid) // Check if the app included widget client is terminated or not. If it is terminated, vcd_server_widget_finalize() function will be called // In that function, it will start recording - g_check_widget_client_timer = ecore_timer_add(2.0, __send_waiting_timeout_error_to_manager, (void*)pid); + 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); -- 2.7.4 From 97559bed8a6dfe158a26f7dc14dc6a3089d2a9fe Mon Sep 17 00:00:00 2001 From: Wonnam Jang Date: Wed, 24 Jan 2018 17:16:20 +0900 Subject: [PATCH 11/16] Change to connect daemon from timer to thread Change-Id: Id7f2e5d38eabbb3880cad5a98f0bb3855d21eff0 Signed-off-by: Wonnam Jang (cherry picked from commit fe930a534021d4f59153c6d7428bcbb3344309eb) --- client/vc_widget.c | 99 ++++++++++++++++++++++++++++++++++++------------- client/vc_widget_dbus.c | 2 + 2 files changed, 75 insertions(+), 26 deletions(-) diff --git a/client/vc_widget.c b/client/vc_widget.c index 89426e1..afe19f0 100644 --- a/client/vc_widget.c +++ b/client/vc_widget.c @@ -36,7 +36,6 @@ static Ecore_Event_Handler* g_focus_in_handler = NULL; static Ecore_Event_Handler* g_focus_out_handler = NULL; static Ecore_Timer* g_w_start_timer = NULL; -static Ecore_Timer* g_w_notify_error_timer = NULL; static Ecore_Timer* g_w_notify_state_timer = NULL; static Ecore_Timer* g_w_notify_result_timer = NULL; @@ -45,7 +44,7 @@ static int g_daemon_pid = 0; static int g_feature_enabled = -1; static Eina_Bool __vc_widget_notify_state_changed(void *data); -static Eina_Bool __vc_widget_notify_error(void *data); +static void __vc_widget_notify_error(void *data); static int __vc_widget_get_feature_enabled() { @@ -237,10 +236,6 @@ static void __vc_widget_delete_timer() ecore_timer_del(g_w_start_timer); g_w_start_timer = NULL; } - if (NULL != g_w_notify_error_timer) { - ecore_timer_del(g_w_notify_error_timer); - g_w_notify_error_timer = NULL; - } if (NULL != g_w_notify_state_timer) { ecore_timer_del(g_w_notify_state_timer); g_w_notify_state_timer = NULL; @@ -347,13 +342,6 @@ static Eina_Bool __vc_widget_connect_daemon(void *data) { vc_h vc_w = (vc_h)data; - /* Send hello */ - if (0 != vc_widget_dbus_request_hello()) { - return EINA_TRUE; - } - - SLOG(LOG_DEBUG, TAG_VCW, "@@@ [Widget] Connect daemon"); - vc_widget_s* widget = widget_get(vc_w); if (NULL != widget) { widget->conn_timer = NULL; @@ -368,7 +356,7 @@ static Eina_Bool __vc_widget_connect_daemon(void *data) SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Fail to initialize : %s", __vc_widget_get_error_code(ret)); vc_widget_client_set_error(vc_w, VC_ERROR_ENGINE_NOT_FOUND); - g_w_notify_error_timer = ecore_timer_add(0, __vc_widget_notify_error, vc_w); + ecore_main_loop_thread_safe_call_async(__vc_widget_notify_error, vc_w); SLOG(LOG_DEBUG, TAG_VCW, "@@@"); return EINA_FALSE; @@ -379,7 +367,7 @@ static Eina_Bool __vc_widget_connect_daemon(void *data) SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Fail to initialize : %s", __vc_widget_get_error_code(ret)); vc_widget_client_set_error(vc_w, VC_ERROR_TIMED_OUT); - g_w_notify_error_timer = ecore_timer_add(0, __vc_widget_notify_error, vc_w); + ecore_main_loop_thread_safe_call_async(__vc_widget_notify_error, vc_w); SLOG(LOG_DEBUG, TAG_VCW, "@@@"); return EINA_FALSE; @@ -387,6 +375,8 @@ static Eina_Bool __vc_widget_connect_daemon(void *data) vc_widget_client_set_service_state(vc_w, (vc_service_state_e)service_state); + SLOG(LOG_INFO, TAG_VCW, "@@@ [Widget] Connect daemon"); + if (NULL == g_focus_in_handler) g_focus_in_handler = ecore_event_handler_add(ECORE_WL_EVENT_FOCUS_IN, __focus_changed_cb, NULL); if (NULL == g_focus_out_handler) @@ -405,22 +395,79 @@ static Eina_Bool __vc_widget_connect_daemon(void *data) } vc_widget_client_set_state(vc_w, VC_STATE_READY); - g_w_notify_state_timer = ecore_timer_add(0, __vc_widget_notify_state_changed, vc_w); + + vc_state_changed_cb changed_callback = NULL; + void* user_data; + + vc_widget_client_get_state_changed_cb(vc_w, &changed_callback, &user_data); + + vc_state_e current_state; + vc_state_e before_state; + + vc_widget_client_get_before_state(vc_w, ¤t_state, &before_state); + + if (NULL != changed_callback) { + vc_widget_client_use_callback(vc_w); + changed_callback(before_state, current_state, user_data); + vc_widget_client_not_use_callback(vc_w); + SLOG(LOG_DEBUG, TAG_VCW, "State changed callback is called"); + } else { + SLOG(LOG_WARN, TAG_VCW, "[WARNING] State changed callback is null"); + } SLOG(LOG_DEBUG, TAG_VCW, "@@@"); return EINA_FALSE; } -int vc_widget_prepare(vc_h vc_w) +static void __start_prepare_thread(void *data, Ecore_Thread *thread) { - SLOG(LOG_DEBUG, TAG_VCW, "@@@ [Widget] Prepare"); + SLOG(LOG_INFO, TAG_VCW, "@@@ Start prepare thread"); + int ret = -1, retry_count = 0; + vc_h vc_w = (vc_h)data; - if (0 != __vc_widget_get_feature_enabled()) { - SLOG(LOG_INFO, TAG_VCW, "@@@ [Widget] not supported"); - return VC_ERROR_NONE; + /* Send hello */ + while (0 != ret) { + if (retry_count == 30) { + SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Fail to request hello !!"); + return; + } + + ret = vc_widget_dbus_request_hello(); + if (ret == 0) { + SLOG(LOG_DEBUG, TAG_VCW, "Success to request hello. retry count(%d)", retry_count); + break; + } else { + retry_count++; + } + } + + ret = -1; + retry_count = 0; + while (0 != ret) { + if (retry_count == 10) { + SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Fail to connect daemon !!"); + return; + } + ret = __vc_widget_connect_daemon((void*)vc_w); + if (ret == 0) + break; + else + retry_count++; } + return; +} + +static void __end_prepare_thread(void *data, Ecore_Thread *thread) +{ + SLOG(LOG_DEBUG, TAG_VCW, "@@@ End prepare thread"); +} + +int vc_widget_prepare(vc_h vc_w) +{ + SLOG(LOG_DEBUG, TAG_VCW, "@@@ [Widget] Prepare"); + vc_state_e state; if (0 != vc_widget_client_get_state(vc_w, &state)) { SLOG(LOG_ERROR, TAG_VCW, "[ERROR] A handle is not available"); @@ -442,7 +489,7 @@ int vc_widget_prepare(vc_h vc_w) return VC_ERROR_INVALID_STATE; } - widget->conn_timer = ecore_timer_add(0, __vc_widget_connect_daemon, (void*)vc_w); + ecore_thread_run(__start_prepare_thread, __end_prepare_thread, NULL, (void*)vc_w); SLOG(LOG_DEBUG, TAG_VCW, "@@@"); @@ -980,7 +1027,7 @@ int vc_widget_cancel(vc_h vc_w) return 0; } -static Eina_Bool __vc_widget_notify_error(void *data) +static void __vc_widget_notify_error(void *data) { vc_h vc_w = (vc_h)data; vc_error_cb callback = NULL; @@ -988,7 +1035,7 @@ static Eina_Bool __vc_widget_notify_error(void *data) int reason; if (NULL == vc_w) { SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Input parameter is NULL"); - return VC_ERROR_INVALID_PARAMETER; + return; } vc_widget_client_get_error_cb(vc_w, &callback, &user_data); @@ -1003,7 +1050,7 @@ static Eina_Bool __vc_widget_notify_error(void *data) SLOG(LOG_WARN, TAG_VCW, "[WARNING] Error callback is null"); } - return EINA_FALSE; + return; } int __vc_widget_cb_error(int reason, int daemon_pid, char* msg) @@ -1047,7 +1094,7 @@ int __vc_widget_cb_error(int reason, int daemon_pid, char* msg) SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Error reason(%d), msg(%s)", reason, msg); vc_widget_client_set_error(vc_w, reason); - g_w_notify_error_timer = ecore_timer_add(0, __vc_widget_notify_error, vc_w); + ecore_main_loop_thread_safe_call_async(__vc_widget_notify_error, vc_w); } } diff --git a/client/vc_widget_dbus.c b/client/vc_widget_dbus.c index 14d3f4d..db68c92 100644 --- a/client/vc_widget_dbus.c +++ b/client/vc_widget_dbus.c @@ -489,6 +489,8 @@ int vc_widget_dbus_request_hello() result_msg = dbus_connection_send_with_reply_and_block(g_w_conn_sender, msg, 500, &err); if (dbus_error_is_set(&err)) { + if (!strncmp(err.name, DBUS_ERROR_SERVICE_UNKNOWN, strlen(err.name))) + usleep(500000); dbus_error_free(&err); } -- 2.7.4 From d1eb9cde65ace873a5bf51568eb72124b47510c6 Mon Sep 17 00:00:00 2001 From: Suyeon Hwang Date: Thu, 1 Feb 2018 21:08:52 +0900 Subject: [PATCH 12/16] Fix thread safety issue of ecore API Change-Id: Ia244d747b595c6d610d84d4ebc44a85a0f95ca30 Signed-off-by: Suyeon Hwang (cherry picked from commit 45d48cfa36cb7dc5da5fd26a4d5b127525e580db) --- client/vc_widget.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/client/vc_widget.c b/client/vc_widget.c index afe19f0..ad6908d 100644 --- a/client/vc_widget.c +++ b/client/vc_widget.c @@ -377,10 +377,12 @@ static Eina_Bool __vc_widget_connect_daemon(void *data) SLOG(LOG_INFO, TAG_VCW, "@@@ [Widget] Connect daemon"); + ecore_thread_main_loop_begin(); if (NULL == g_focus_in_handler) g_focus_in_handler = ecore_event_handler_add(ECORE_WL_EVENT_FOCUS_IN, __focus_changed_cb, NULL); if (NULL == g_focus_out_handler) g_focus_out_handler = ecore_event_handler_add(ECORE_WL_EVENT_FOCUS_OUT, __focus_changed_cb, NULL); + ecore_thread_main_loop_end(); char appid[1024] = {'\0',}; aul_app_get_appid_bypid(getpid(), appid, sizeof(appid) - 1); -- 2.7.4 From 133183771a9c64d99098efec3162a3408dca0d50 Mon Sep 17 00:00:00 2001 From: "sooyeon.kim" Date: Thu, 8 Feb 2018 16:56:00 +0900 Subject: [PATCH 13/16] Add feature checker in vc_widget_prepare Change-Id: Ide8a8eeb5826947839578de69d634d3420e5d041 Signed-off-by: sooyeon.kim (cherry picked from commit fd9419d346f53861f55ed56c6c52efa0b24806c9) --- client/vc_widget.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/client/vc_widget.c b/client/vc_widget.c index ad6908d..46d68ac 100644 --- a/client/vc_widget.c +++ b/client/vc_widget.c @@ -470,6 +470,11 @@ int vc_widget_prepare(vc_h vc_w) { SLOG(LOG_DEBUG, TAG_VCW, "@@@ [Widget] Prepare"); + if (0 != __vc_widget_get_feature_enabled()) { + SLOG(LOG_INFO, TAG_VCW, "@@@ [Widget] not supported"); + return VC_ERROR_NONE; + } + vc_state_e state; if (0 != vc_widget_client_get_state(vc_w, &state)) { SLOG(LOG_ERROR, TAG_VCW, "[ERROR] A handle is not available"); -- 2.7.4 From f09f22e095ad108d2084e02c511ad5afc3b06369 Mon Sep 17 00:00:00 2001 From: "sooyeon.kim" Date: Wed, 28 Feb 2018 10:59:31 +0900 Subject: [PATCH 14/16] Revert 'Change to support VC downloadable engine (hybrid)' temporarily Change-Id: Ia44e65e5d566a2c501ba2abd6d4031746a21eb5e Signed-off-by: sooyeon.kim --- include/CMakeLists.txt | 2 +- include/vce.h | 746 --------------------------- include/voice-control-engine.pc.in | 1 - include/voice_control_manager.h | 2 +- include/voice_control_plugin_engine.h | 800 +++++++++++++++++++++++++++++ org.tizen.voice.vcserver.service | 3 +- packaging/voice-control.spec | 5 +- server/CMakeLists.txt | 17 +- server/vcd_client_data.c | 14 +- server/vcd_engine_agent.c | 919 +++++++++++++++++++++++++--------- server/vcd_engine_agent.h | 58 ++- server/vcd_main.c | 75 +++ server/vcd_main.h | 39 -- server/vcd_recorder.c | 95 ++-- server/vcd_recorder.h | 3 +- server/vcd_server.c | 302 ++++------- server/vcd_server.h | 36 +- server/vce.c | 262 ---------- 18 files changed, 1750 insertions(+), 1629 deletions(-) delete mode 100755 include/vce.h create mode 100755 include/voice_control_plugin_engine.h create mode 100755 server/vcd_main.c delete mode 100755 server/vce.c diff --git a/include/CMakeLists.txt b/include/CMakeLists.txt index 84fd0df..7d0db51 100644 --- a/include/CMakeLists.txt +++ b/include/CMakeLists.txt @@ -21,6 +21,6 @@ INSTALL(FILES ${CMAKE_BINARY_DIR}/include/voice_control_command_expand.h DESTINA INSTALL(FILES ${CMAKE_BINARY_DIR}/include/voice_control_common.h DESTINATION ${INCLUDEDIR}) INSTALL(FILES ${CMAKE_BINARY_DIR}/include/voice_control_key_defines.h DESTINATION ${INCLUDEDIR}) INSTALL(FILES ${CMAKE_BINARY_DIR}/include/voice_control_manager.h DESTINATION ${INCLUDEDIR}) +INSTALL(FILES ${CMAKE_BINARY_DIR}/include/voice_control_plugin_engine.h DESTINATION ${INCLUDEDIR}) INSTALL(FILES ${CMAKE_BINARY_DIR}/include/voice_control_setting.h DESTINATION ${INCLUDEDIR}) INSTALL(FILES ${CMAKE_BINARY_DIR}/include/voice_control_widget.h DESTINATION ${INCLUDEDIR}) -INSTALL(FILES ${CMAKE_BINARY_DIR}/include/vce.h DESTINATION ${INCLUDEDIR}) diff --git a/include/vce.h b/include/vce.h deleted file mode 100755 index a921cd1..0000000 --- a/include/vce.h +++ /dev/null @@ -1,746 +0,0 @@ -/* -* Copyright (c) 2011-2017 Samsung Electronics Co., Ltd All Rights Reserved -* -* Licensed under the Apache License, Version 2.0 (the License); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an AS IS BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - - -#ifndef __VCE_H__ -#define __VCE_H__ - -#include - -/** -* @addtogroup CAPI_UIX_VCE_MODULE -* @{ -*/ - -#ifdef __cplusplus -extern "C" { -#endif - -/** -* @brief Enumerations of error codes. -* @since_tizen 5.0 -*/ -typedef enum { - VCE_ERROR_NONE = TIZEN_ERROR_NONE, /**< Successful */ - VCE_ERROR_OUT_OF_MEMORY = TIZEN_ERROR_OUT_OF_MEMORY, /**< Out of Memory */ - VCE_ERROR_IO_ERROR = TIZEN_ERROR_IO_ERROR, /**< I/O error */ - VCE_ERROR_INVALID_PARAMETER = TIZEN_ERROR_INVALID_PARAMETER,/**< Invalid parameter */ - VCE_ERROR_OUT_OF_NETWORK = TIZEN_ERROR_NETWORK_DOWN, /**< Out of network */ - VCE_ERROR_INVALID_STATE = TIZEN_ERROR_VOICE_CONTROL | 0x011, /**< Invalid state */ - VCE_ERROR_INVALID_LANGUAGE = TIZEN_ERROR_VOICE_CONTROL | 0x012, /**< Invalid language */ - VCE_ERROR_OPERATION_FAILED = TIZEN_ERROR_VOICE_CONTROL | 0x014, /**< Operation failed */ - VCE_ERROR_NOT_SUPPORTED_FEATURE = TIZEN_ERROR_VOICE_CONTROL | 0x022 /**< Not supported feature of current engine */ -} vce_error_e; - -/** -* @brief Enumerations of audio type. -* @since_tizen 5.0 -*/ -typedef enum { - VCE_AUDIO_TYPE_PCM_S16_LE = 0, /**< Signed 16bit audio type, Little endian */ - VCE_AUDIO_TYPE_PCM_U8 /**< Unsigned 8bit audio type */ -} vce_audio_type_e; - -/** -* @brief Enumerations of callback event. -* @since_tizen 5.0 -*/ -typedef enum { - VCE_RESULT_EVENT_SUCCESS = 0, /**< Event when the recognition full result is ready */ - VCE_RESULT_EVENT_REJECTED, /**< Event when the recognition result is rejected */ - VCE_RESULT_EVENT_ERROR /**< Event when the recognition has failed */ -} vce_result_event_e; - -/** -* @brief Enumerations of command type. -* @since_tizen 5.0 -*/ -typedef enum { - VCE_COMMAND_FORMAT_FIXED = 0, /**< Fixed command */ - VCE_COMMAND_FORMAT_FIXED_AND_VFIXED, /**< Fixed command + variable-fixed command */ - VCE_COMMAND_FORMAT_VFIXED_AND_FIXED, /**< variable-fixed command + Fixed command */ - VCE_COMMAND_FORMAT_FIXED_AND_NONFIXED, /**< Fixed command + Non-fixed command */ - VCE_COMMAND_FORMAT_NONFIXED_AND_FIXED, /**< Non-fixed command + Fixed command */ - VCE_COMMAND_FORMAT_ACTION, - VCE_COMMAND_FORMAT_PARTIAL -} vce_command_format_e; - -/** -* @brief Definition for foreground command type. -* @since_tizen 5.0 -*/ -#define VCE_COMMAND_TYPE_FOREGROUND 1 - -/** -* @brief Definition for background command type. -* @since_tizen 5.0 -*/ -#define VCE_COMMAND_TYPE_BACKGROUND 2 - -/** -* @brief Definition for widget command type. -* @since_tizen 5.0 -*/ -#define VCE_COMMAND_TYPE_WIDGET 3 - -/** -* @brief Definition for system command type. -* @since_tizen 5.0 -*/ -#define VCE_COMMAND_TYPE_SYSTEM 4 - -/** -* @brief Definition for system background command type. -* @since_tizen 5.0 -*/ -#define VCE_COMMAND_TYPE_SYSTEM_BACKGROUND 5 - -/** -* @brief Definitions for exclusive command type. -* @since_tizen 5.0 -*/ -#define VCE_COMMAND_TYPE_EXCLUSIVE 6 - - -/** -* @brief Enumerations of speech detect. -* @since_tizen 5.0 -*/ -typedef enum { - VCE_SPEECH_DETECT_NONE = 0, /**< No event */ - VCE_SPEECH_DETECT_BEGIN, /**< Begin of speech detected */ - VCE_SPEECH_DETECT_END, /**< End of speech detected */ -} vce_speech_detect_e; - -/** -* @brief Enumerations of ASR result events -* @since_tizen 5.0 -*/ -typedef enum { - VCE_ASR_RESULT_EVENT_FINAL_RESULT = 0, - VCE_ASR_RESULT_EVENT_PARTIAL_RESULT, - VCE_ASR_RESULT_EVENT_ERROR -} vce_asr_result_event_e; - -/** -* @brief A structure of handle for VC command -* @since_tizen 5.0 -*/ -typedef int vce_cmd_h; - -/** -* @brief Definition of bluetooth audio id. -* @since_tizen 5.0 -*/ -#define VCE_AUDIO_ID_BLUETOOTH "VC_AUDIO_ID_BLUETOOTH" /**< Bluetooth audio id */ - -/** -* @brief Definition of Wi-Fi audio id. -* @since_tizen 5.0 -*/ -#define VCE_AUDIO_ID_WIFI "VC_AUDIO_ID_WIFI" /**< Wi-Fi audio id */ - -/** -* @brief Definition for none message. -*/ -#define VC_RESULT_MESSAGE_NONE "vc.result.message.none" - -/** -* @brief Definition for failed recognition because the speech is too loud to listen. -*/ -#define VC_RESULT_MESSAGE_ERROR_TOO_LOUD "vc.result.message.error.too.loud" - - - -/** -* @brief Called when VC engine informs the engine service user about whole supported languages. -* @details This callback function is implemented by the engine service user. Therefore, the engine developer does NOT have to implement this callback function. -* @since_tizen 5.0 -* @remarks This callback function is called by vce_foreach_supported_languages_cb() to retrieve the whole supported language list. -* @a user_data must be transferred from vce_foreach_supported_languages_cb(). -* -* @param[in] language A language is specified as an ISO 3166 alpha-2 two letter country-code -* followed by ISO 639-1 for the two-letter language code \n -* For example, "ko_KR" for Korean, "en_US" for American English -* @param[in] user_data The user data passed from the foreach function -* -* @return @c true to continue with the next iteration of the loop \n @c false to break out of the loop -* -* @pre vce_foreach_supported_languages() will invoke this callback. -* -* @see vce_foreach_supported_languages() -*/ -typedef bool (*vce_supported_language_cb)(const char* language, void* user_data); - -/** -* @brief Called when the engine service user initializes VC engine. -* @since_tizen 5.0 -* @remarks This callback function is mandatory and must be registered using vce_main(). -* -* @return 0 on success, otherwise a negative error value -* @retval #VCE_ERROR_NONE Successful -* @retval #VCE_ERROR_INVALID_PARAMETER Invalid parameter -* @retval #VCE_ERROR_INVALID_STATE Already initialized -* @retval #VCE_ERROR_OPERATION_FAILED Operation failed -* -* @see vce_deinitialize_cb() -*/ -typedef int (*vce_initialize_cb)(void); - -/** -* @brief Called when the engine service user deinitializes VC engine -* @since_tizen 5.0 -* @remarks This callback function is mandatory and must be registered using vce_main(). -* -* @return 0 on success, otherwise a negative error value -* @retval #VCE_ERROR_NONE Successful -* @retval #VCE_ERROR_INVALID_STATE Not initialized -* -* @see vce_initialize_cb() -*/ -typedef int (*vce_deinitialize_cb)(void); - -/** -* @brief Called when the engine service user requests the recording format of VC engine. -* -* @param[in] audio_id The audio device id. -* @param[out] types The format used by the recorder. -* @param[out] rate The sample rate used by the recorder. -* @param[out] channels The number of channels used by the recorder. -* -* @return 0 on success, otherwise a negative error value -* @retval #VCE_ERROR_NONE Successful -* @retval #VCE_ERROR_INVALID_PARAMETER Not initialized -*/ -typedef int (*vce_get_recording_format_cb)(const char* audio_id, vce_audio_type_e* types, int* rate, int* channels); - -/** -* @brief Called when the engine service user retrieves all supported languages of VC engine. -* -* @param[in] callback a callback function -* @param[in] user_data The user data to be passed to the callback function -* -* @return 0 on success, otherwise a negative error value -* @retval #VCE_ERROR_NONE Successful -* @retval #VCE_ERROR_INVALID_PARAMETER Invalid parameter -* @retval #VCE_ERROR_INVALID_STATE Not initialized -* -* @post This function invokes vce_supported_language_cb() repeatedly for getting supported languages. -* -* @see vce_supported_language_cb() -*/ -typedef int (*vce_foreach_supported_languages_cb)(vce_supported_language_cb callback, void* user_data); - -/** -* @brief Called when the engine service user checks whether a language is supported or not. -* -* @param[in] language A language -* -* @return @c true = supported, \n @c false = not supported. -*/ -typedef bool (*vce_is_language_supported_cb)(const char* language); - -/** -* @brief Called when the engine service user sets language. -* -* @param[in] language A language. -* -* @return 0 on success, otherwise a negative error value -* @retval #VCE_ERROR_NONE Successful -* @retval #VCE_ERROR_INVALID_LANGUAGE Invalid language -* @retval #VCE_ERROR_INVALID_STATE Not initialized -*/ -typedef int (*vce_set_language_cb)(const char* language); - -/** -* @brief Called when the engine service user sets command list before recognition. -* -* @remark This function should set commands via vcd_foreach_command(). -* -* @param[in] vc_command command handle. -* -* @return 0 on success, otherwise a negative error value -* @retval #VCE_ERROR_NONE Successful -* @retval #VCE_ERROR_INVALID_PARAMETER Invalid parameter -* @retval #VCE_ERROR_INVALID_STATE Invalid state -* @retval #VCE_ERROR_OPERATION_FAILED Operation failed -* @retval #VCE_ERROR_NOT_SUPPORTED_FEATURE Not supported command type -* -* @post vce_start() is called after this function is successful. -* -* @see vce_start() -* @see vcd_foreach_command() -* @see vce_unset_commands() -*/ -typedef int (*vce_set_commands_cb)(vce_cmd_h vc_command); - -/** -* @brief Called when the engine service user unsets command list for reset. -* -* @return 0 on success, otherwise a negative error value -* @retval #VCE_ERROR_NONE Successful -* @retval #VCE_ERROR_INVALID_PARAMETER Invalid parameter -* @retval #VCE_ERROR_INVALID_STATE Invalid state -* @retval #VCE_ERROR_OPERATION_FAILED Operation failed -* -* @see vce_set_commands() -*/ -typedef int (*vce_unset_commands_cb)(); - -/** -* @brief Called when the engine service user starts recognition. -* -* @return 0 on success, otherwise a negative error value -* @retval #VCE_ERROR_NONE Successful -* @retval #VCE_ERROR_INVALID_PARAMETER Invalid parameter -* @retval #VCE_ERROR_INVALID_STATE Invalid state -* @retval #VCE_ERROR_INVALID_LANGUAGE Invalid language -* @retval #VCE_ERROR_OUT_OF_NETWORK Out of network -* @retval #VCE_ERROR_OPERATION_FAILED Operation failed -* -* @pre vcd_foreach_command() is successful. -* -* @see vce_set_recording_data() -* @see vce_stop() -* @see vce_cancel() -*/ -typedef int (*vce_start_cb)(bool stop_by_silence); - -/** -* @brief Called when the engine service user sets recording data for speech recognition from recorder. -* -* @remark This function should be returned immediately after recording data copy. -* -* @param[in] data A recording data -* @param[in] length A length of recording data -* @param[out] silence_detected @c true Silence detected \n @c false No silence detected -* -* @return 0 on success, otherwise a negative error value -* @retval #VCE_ERROR_NONE Successful -* @retval #VCE_ERROR_INVALID_PARAMETER Invalid parameter -* @retval #VCE_ERROR_INVALID_STATE Invalid state -* @retval #VCE_ERROR_OPERATION_FAILED Operation failed -* -* @pre vce_start() is successful. -* -* @see vce_start() -* @see vce_cancel() -* @see vce_stop() -*/ -typedef int(*vce_set_recording_data_cb)(const void* data, unsigned int length, vce_speech_detect_e* speech_detected); - -/** -* @brief Called when the engine service user stops to get the result of recognition. -* -* @return 0 on success, otherwise a negative error value -* @retval #VCE_ERROR_NONE Successful -* @retval #VCE_ERROR_INVALID_STATE Invalid state -* @retval #VCE_ERROR_OPERATION_FAILED Operation failed -* @retval #VCE_ERROR_OUT_OF_NETWORK Out of network -* -* @pre vce_set_recording_data() is successful. -* -* @see vce_start() -* @see vce_set_recording_data() -* @see vce_result_cb() -* @see vce_cancel() -*/ -typedef int (*vce_stop_cb)(void); - -/** -* @brief Called when the engine service user cancels the recognition process. -* -* @return 0 on success, otherwise a negative error value. -* @retval #VCE_ERROR_NONE Successful. -* @retval #VCE_ERROR_INVALID_STATE Invalid state. -* -* @pre vce_start() is successful. -* -* @see vce_start() -* @see vce_stop() -*/ -typedef int (*vce_cancel_cb)(void); - -/** -* @brief Set audio recording type. -* -* @return 0 on success, otherwise a negative error value. -* @retval #VCE_ERROR_NONE Successful. -* -*/ -typedef int (*vce_set_audio_type)(const char* audio); - - -/** -* @brief Called when the engine service user sets domain (Agent or device type) -* -* @param[in] domain Available agent or device type -* -* @return 0 on success, otherwise a negative error value. -* -*/ -typedef int (*vce_set_domain_cb)(const char* domain); - -/** -* @brief Called when the engine service user requests essential value from nlu result. -* @since_tizen 5.0 -* @remarks This function is available inside vce_nlu_result_cb() -* -* @param[in] key NLU base info key -* @parma[out] value NLU base info value -* -* @return 0 on success, otherwise a negative error value. -* -*/ -typedef int (*vce_nlu_base_info_requested_cb)(const char* key, char** value); - -/** -* @brief Called when the engine service user sets private data between app and engine. -* -* @param[in] key Private key -* @param[in] data Private data -* -* @return 0 on success, otherwise a negative error value. -* -*/ -typedef int (*vce_private_data_set_cb)(const char* key, const char* data); - -/** -* @brief Called when the engine service user requests private data between app and engine. -* -* @param[in] key Private key -* @param[out] data Private data -* -* @return 0 on success, otherwise a negative error value. -* -*/ -typedef int (*vce_private_data_requested_cb)(const char* key, char** data); - -/** -* @brief Called when the engine service user requests process text. -* -* @param[in] text Requested text -* -* @return 0 on success, otherwise a negative error value. -* -*/ -typedef int (*vce_process_text_cb)(const char* text); - -/** -* @brief Called when the engine service user requests list event. -* -* @param[in] event Requested list event -* -* @return 0 on success, otherwise a negative error value. -* -*/ -typedef int (*vce_process_list_event_cb)(const char* event); - -/** -* @brief Called when the engine service user requests haptic event. -* -* @param[in] event Requested haptic event -* -* @return 0 on success, otherwise a negative error value. -* -*/ -typedef int (*vce_process_haptic_event_cb)(const char* event); - -/** -* @brief Called when the engine service user requests the base information of VC engine. -* @since_tizen 5.0 -* -* @param[out] engine_uuid The engine id -* @param[out] engine_name The engine name -* @param[out] engine_setting The setting path name -* @param[out] use_network @c true to need network @c false not to need network. -*/ -typedef int (*vce_get_info_cb)(char** engine_uuid, char** engine_name, char** engine_setting, bool* use_network); - - -/** -* Daemon API. -*/ - -/** -* @brief Called to retrieve the commands. -* -* @param[in] id command id -* @param[in] type command type -* @param[in] format command format -* @param[in] command command text -* @param[in] param parameter text -* @param[in] domain command domain -* @param[in] user_data The user data passed from the foreach function -* -* @return @c true to continue with the next iteration of the loop, \n @c false to break out of the loop. -* @pre vce_get_foreach_command() will invoke this callback. -* -* @see vce_get_foreach_command() -*/ -typedef bool (*vce_command_cb)(int id, int type, int format, const char* command, const char* param, int domain, void* user_data); - -/** -* @brief Retrieves all commands using callback function. -* -* @param[in] vce_command The handle to be passed to the vce_set_commands() function -* @param[in] callback The callback function to invoke -* @param[in] user_data The user data to be passed to the callback function -* -* @return 0 on success, otherwise a negative error value -* @retval #VCE_ERROR_NONE Successful -* @retval #VCE_ERROR_INVALID_PARAMETER Invalid parameter -* @retval #VCE_ERROR_OPERATION_FAILED Operation failure -* @retval #VCE_ERROR_INVALID_STATE Invalid state -* -* @post This function invokes vce_command_cb() repeatedly for getting commands. -* -* @see vce_foreach_command_cb() -* @see vce_set_commands() -*/ -int vce_get_foreach_command(vce_cmd_h vce_command, vce_command_cb callback, void* user_data); - -/** -* @brief Gets command length. -* -* @param[in] vce_command The handle to be passed to the vce_set_commands() function -* -* @return the value greater than 0 on success, otherwise a negative error value -* -* @see vce_set_commands() -*/ -int vce_get_command_count(vce_cmd_h vce_command); - -/** -* @brief Gets current audio type. -* -* @remarks audio_type must be released using free() when it is no longer required. -* -* @param[in] audio_type Current audio type (e.g. #VCE_AUDIO_ID_BLUETOOTH or usb device id) -* -* @return the value greater than 0 on success, otherwise a negative error value -* -*/ -int vce_get_audio_type(char** audio_type); - -/** -* @brief Sets private data to Manager client. -* -* @param[in] key Private key -* @param[in] data Private data -* -* @return 0 on success, otherwise a negative error value. -* -*/ -int vce_set_private_data(const char* key, const char* data); - -/** -* @brief Gets private data from Manager client. -* -* @param[in] key Private key -* @param[out] data Private data -* -* @return 0 on success, otherwise a negative error value. -* -*/ -int vce_get_private_data(const char* key, char** data); - -/** -* @brief Request start recording. -* -* @return 0 on success, otherwise a negative error value. -* -*/ -int vce_start_recording(); - -/** -* @brief Request stop recording. -* -* @return 0 on success, otherwise a negative error value. -* -*/ -int vce_stop_recording(); - - -/** -* @brief A structure for the VC engine functions. -* @details This structure contains essential callback functions for operating VC engine. -* @since_tizen 5.0 -* @remarks These functions ar mandatory for operating VC engine. Therefore, all functions MUST be implemented. -*/ -typedef struct { - int version; /**< Version */ - - /* Get engine information */ - vce_get_info_cb get_info; /**< Called when the engine service user requests the basic information of VC engine */ - vce_get_recording_format_cb get_recording_format; /**< Get recording format */ - vce_foreach_supported_languages_cb foreach_langs; /**< Foreach language list */ - vce_is_language_supported_cb is_lang_supported; /**< Check language */ - - vce_initialize_cb initialize; /**< Initialize engine */ - vce_deinitialize_cb deinitialize; /**< Shutdown engine */ - - /* Set info */ - vce_set_language_cb set_language; /**< Set language */ - vce_set_commands_cb set_commands; /**< Request to set current commands */ - vce_unset_commands_cb unset_commands; /**< Request to unset current commands */ - - /* Control recognition */ - vce_start_cb start; /**< Start recognition */ - vce_set_recording_data_cb set_recording; /**< Set recording data */ - vce_stop_cb stop; /**< Stop recording for getting result */ - vce_cancel_cb cancel; /**< Cancel recording and processing */ - - vce_set_audio_type set_audio_type; /**< Set audio type */ - - vce_set_domain_cb set_domain; /**< Set domain */ - vce_process_text_cb process_text; /**< Request to process text */ - vce_process_list_event_cb process_list_event; /**< Request to process list event */ - vce_process_haptic_event_cb process_haptic_event; /**< Request to process haptic event */ -} vce_request_callback_s; - -/** -* @brief Loads the engine. -* -* @param[in] argc The argument count(original) -* @param[in] argv The argument(original) -* @param[in] callback The structure of engine request callback function -* -* @return This function returns zero on success, or negative with error code on failure -* @retval #VCE_ERROR_NONE Successful -* @retval #VCE_ERROR_INVALID_PARAMETER Invalid parameter -* @retval #VCE_ERROR_OPERATION_FAILED Operation failed -* -* @pre The vce_get_engine_info() should be successful. -* @post The daemon calls engine functions of vce_funcs_s. -* -* @see vce_get_engine_info() -* @see vce_unload_engine() -*/ -int vce_main(int argc, char** argv, vce_request_callback_s *callback); - - -/** -* @brief Sends the results to the engine service user. -* @since_tizen 5.0 -* -* @param[in] event A result event -* @param[in] result_id Result ids -* @param[in] count Result count -* @param[in] all_result All result text -* @param[in] non_fixed_result Non-fixed command result text -* @param[in] nlu_result NLU result text -* @param[in] msg Engine message (e.g. #VC_RESULT_MESSAGE_NONE, #VC_RESULT_MESSAGE_ERROR_TOO_LOUD) -* @param[out] user_info A user info (e.g. If ASR result is consumed, the value is 0x01. If not, the value is 0x00.) -* @param[in] user_data The user data passed from set callback function -* -* @pre The vce_main() function should be invoked before this function is called. -* vce_stop_cb() will invoke this callback. -* -* @see vce_stop_cb() -*/ -int vce_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); - -/** -* @brief Sends the ASR result to the engine service user. -* @since_tizen 5.0 -* -* @param[in] event A asr result event -* @param[in] asr_result A asr result text -* @param[in] user_data The user data passed from the start -* -* @pre The vce_main() function should be invoked before this function is called. -*/ -int vce_send_asr_result(vce_asr_result_event_e event, const char* asr_result, void *user_data); - -/** -* @brief Called when the daemon gets nlg(natural language generation) result. -* -* @param[in] nlg_result A nlg result -* @param[in] user_data The user data passed from the start -*/ -int vce_send_nlg_result(const char* nlg_result, void *user_data); - -/** -* @brief Sends the error to the engine service user. -* @details The following error codes can be delivered. -* #VCE_ERROR_NONE, -* #VCE_ERROR_OUT_OF_MEMORY, -* #VCE_ERROR_IO_ERROR, -* #VCE_ERROR_INVALID_PARAMETER, -* #VCE_ERROR_OUT_OF_NETWORK, -* #VCE_ERROR_INVALID_STATE, -* #VCE_ERROR_INVALID_LANGUAGE, -* #VCE_ERROR_OPERATION_FAILED, -* #VCE_ERROR_NOT_SUPPORTED_FEATURE. -* @since_tizen 5.0 -* -* @param[in] error Error type -* @param[in] msg Error message -* @param[in] user_data The user data passed from set callback function -* -* @pre The vce_main() function should be invoked before this function is called. -*/ -int vce_send_error(vce_error_e error, const char* msg, void *user_data); - -/** -* @brief Sets a callback function for setting the private data to the engine service. -* @since_tizen 5.0 -* @remarks The vce_private_data_set_cb() function is called when the engine service user sets the private data to the engine service. -* -* @param[in] callback_func vce_private_data_set event callback function -* @return -* -* @see vce_private_data_set_cb() -*/ -int vce_set_private_data_set_cb(vce_private_data_set_cb callback_func); - -/** -* @brief Sets a callback function for requesting the private data to the engine service. -* @since_tizen 5.0 -* @remarks The vce_private_data_requested_cb() function is called when the engine service user requests the private data to the engine service. -* -* @param[in] callback_func vce_private_data_requested event callback function -* @return -* -* @see vce_private_data_requested_cb() -*/ -int vce_set_private_data_requested_cb(vce_private_data_requested_cb callback_func); - -/** -* @brief Sets a callback function for requesting the NLU base information to the engine service. -* @since_tizen 5.0 -* @remarks The vce_nlu_base_info_requested_cb() function is called when the engine service user requests the NLU base information to the engine service. -* -* @param[in] callback_func vce_nlu_base_info_requested event callback function -* @return -* -* @see vce_nlu_base_info_requested_cb() -*/ -int vce_set_nlu_base_info_requested_cb(vce_nlu_base_info_requested_cb callback_func); - - -#ifdef __cplusplus -} -#endif - -/** -* @}@} -*/ - -#endif /* __VCE_H__ */ - - diff --git a/include/voice-control-engine.pc.in b/include/voice-control-engine.pc.in index d089851..7808dfb 100644 --- a/include/voice-control-engine.pc.in +++ b/include/voice-control-engine.pc.in @@ -7,5 +7,4 @@ Name: lib@PROJECT_NAME@_engine Description: Voice control engine header Requires: glib-2.0 dbus-1 capi-base-common Version: @VERSION@ -Libs: -L${libdir} -l@PROJECT_NAME@_engine Cflags: -I${includedir} diff --git a/include/voice_control_manager.h b/include/voice_control_manager.h index eb0055b..92701b9 100644 --- a/include/voice_control_manager.h +++ b/include/voice_control_manager.h @@ -41,7 +41,7 @@ extern "C" /** * @brief Definition of Wi-Fi audio-in type. */ -#define VC_AUDIO_TYPE_WIFI "VC_AUDIO_ID_WIFI" /**< Wi-Fi audio type */ +#define VC_AUDIO_TYPE_MSF "VC_AUDIO_ID_MSF" /**< MSF (wifi) audio type */ /** * @brief Definition for foreground command type. diff --git a/include/voice_control_plugin_engine.h b/include/voice_control_plugin_engine.h new file mode 100755 index 0000000..8b13471 --- /dev/null +++ b/include/voice_control_plugin_engine.h @@ -0,0 +1,800 @@ +/* +* Copyright (c) 2011-2015 Samsung Electronics Co., Ltd All Rights Reserved +* +* Licensed under the Apache License, Version 2.0 (the License); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an AS IS BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + + +#ifndef __VOICE_CONTROL_PLUGIN_ENGINE_H__ +#define __VOICE_CONTROL_PLUGIN_ENGINE_H__ + +#include + +/** +* @addtogroup VOICE_CONTROL_PLUGIN_ENGINE +* @{ +*/ + +#ifdef __cplusplus +extern "C" { +#endif + +/** +* @brief Enumerations of error codes. +*/ +typedef enum { + VCP_ERROR_NONE = TIZEN_ERROR_NONE, /**< Successful */ + VCP_ERROR_OUT_OF_MEMORY = TIZEN_ERROR_OUT_OF_MEMORY, /**< Out of Memory */ + VCP_ERROR_IO_ERROR = TIZEN_ERROR_IO_ERROR, /**< I/O error */ + VCP_ERROR_INVALID_PARAMETER = TIZEN_ERROR_INVALID_PARAMETER,/**< Invalid parameter */ + VCP_ERROR_OUT_OF_NETWORK = TIZEN_ERROR_NETWORK_DOWN, /**< Out of network */ + VCP_ERROR_INVALID_STATE = -0x0100031, /**< Invalid state */ + VCP_ERROR_INVALID_LANGUAGE = -0x0100032, /**< Invalid language */ + VCP_ERROR_OPERATION_FAILED = -0x0100034, /**< Operation failed */ + VCP_ERROR_NOT_SUPPORTED_FEATURE = -0x0100035 /**< Not supported feature */ +} vcp_error_e; + +/** +* @brief Enumerations of audio type. +*/ +typedef enum { + VCP_AUDIO_TYPE_PCM_S16_LE = 0, /**< Signed 16bit audio type, Little endian */ + VCP_AUDIO_TYPE_PCM_U8 /**< Unsigned 8bit audio type */ +} vcp_audio_type_e; + +/** +* @brief Enumerations of callback event. +*/ +typedef enum { + VCP_RESULT_EVENT_SUCCESS = 0, /**< Event when the recognition full result is ready */ + VCP_RESULT_EVENT_REJECTED, /**< Event when the recognition result is rejected */ + VCP_RESULT_EVENT_ERROR /**< Event when the recognition has failed */ +} vcp_result_event_e; + +/** +* @brief Enumerations of command type. +*/ +typedef enum { + VCP_COMMAND_FORMAT_FIXED = 0, /**< Fixed command */ + VCP_COMMAND_FORMAT_FIXED_AND_VFIXED, /**< Fixed command + variable-fixed command */ + VCP_COMMAND_FORMAT_VFIXED_AND_FIXED, /**< variable-fixed command + Fixed command */ + VCP_COMMAND_FORMAT_FIXED_AND_NONFIXED, /**< Fixed command + Non-fixed command */ + VCP_COMMAND_FORMAT_NONFIXED_AND_FIXED, /**< Non-fixed command + Fixed command */ + VCP_COMMAND_FORMAT_ACTION, + VCP_COMMAND_FORMAT_PARTIAL +} vcp_command_format_e; + +/** +* @brief Definition for foreground command type. +* @since_tizen @if MOBILE 2.4 @elseif WEARABLE 3.0 @endif +*/ +#define VCP_COMMAND_TYPE_FOREGROUND 1 + +/** +* @brief Definition for background command type. +* @since_tizen @if MOBILE 2.4 @elseif WEARABLE 3.0 @endif +*/ +#define VCP_COMMAND_TYPE_BACKGROUND 2 + +/** +* @brief Definition for widget command type. +* @since_tizen @if MOBILE 2.4 @elseif WEARABLE 3.0 @endif +*/ +#define VCP_COMMAND_TYPE_WIDGET 3 + +/** +* @brief Definition for system command type. +* @since_tizen @if MOBILE 2.4 @elseif WEARABLE 3.0 @endif +*/ +#define VCP_COMMAND_TYPE_SYSTEM 4 + +/** +* @brief Definition for exclusive command type. +* @since_tizen @if MOBILE 2.4 @elseif WEARABLE 3.0 @endif +*/ +#define VCP_COMMAND_TYPE_SYSTEM_BACKGROUND 5 + +/** +* @brief Definitions for exclusive command type. +* @since_tizen 2.4 +*/ +#define VCP_COMMAND_TYPE_EXCLUSIVE 6 + + +/** +* @brief Enumerations of speech detect. +*/ +typedef enum { + VCP_SPEECH_DETECT_NONE = 0, /**< No event */ + VCP_SPEECH_DETECT_BEGIN, /**< Begin of speech detected */ + VCP_SPEECH_DETECT_END, /**< End of speech detected */ +} vcp_speech_detect_e; + +typedef enum { + VCP_ASR_RESULT_EVENT_FINAL_RESULT = 0, + VCP_ASR_RESULT_EVENT_PARTIAL_RESULT, + VCP_ASR_RESULT_EVENT_ERROR +} vcp_asr_result_event_e; + +/** +* @brief A structure of handle for VC command +*/ +typedef int vcp_cmd_h; + +/** + * @brief Definition of bluetooth audio id. +*/ +#define VCP_AUDIO_ID_BLUETOOTH "VC_AUDIO_ID_BLUETOOTH" /**< Bluetooth audio id */ + +/** + * @brief Definition of MSF(wifi) audio id. +*/ +#define VCP_AUDIO_ID_MSF "VC_AUDIO_ID_MSF" /**< MSF (wifi) audio id */ + +/** +* @brief Definition for none message. +*/ +#define VC_RESULT_MESSAGE_NONE "vc.result.message.none" + +/** +* @brief Definition for failed recognition because the speech is too loud to listen. +*/ +#define VC_RESULT_MESSAGE_ERROR_TOO_LOUD "vc.result.message.error.too.loud" + + +/** +* @brief Called when the daemon gets synthesized result. +* +* @param[in] event A result event +* @param[in] result_id Result ids +* @param[in] count Result count +* @param[in] all_result All result text +* @param[in] non_fixed_result Non-fixed command result text +* @param[in] nlu_result NLU result text +* @param[in] msg Engine message (e.g. #VC_RESULT_MESSAGE_NONE, #VC_RESULT_MESSAGE_ERROR_TOO_LOUD) +* @param[out] user_info A user info (e.g. If ASR result is consumed, the value is 0x01. If not, the value is 0x00.) +* @param[in] user_data The user data passed from set callback function +* +* @pre vcpe_stop() will invoke this callback. +* +* @see vcpe_stop() +*/ +typedef void (*vcpe_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); + + +/** +* @brief Called when the daemon gets ASR result. +* +* @param[in] event A asr result event +* @param[in] pre_result result text +* @param[in] user_data The user data passed from the start +*/ +typedef void (*vcpe_asr_result_cb)(vcp_asr_result_event_e event, const char* asr_result, void *user_data); + +/** +* @brief Called when the daemon gets nlg result. +* +* @param[in] nlg_result Nlg result +* @param[in] user_data The user data passed from the start +*/ +typedef void (*vcpe_nlg_result_cb)(const char* nlg_result, void *user_data); + +/** +* @brief Called when the daemon gets error. +* +* @param[in] error Error type +* @param[in] msg Error message +* @param[in] user_data The user data passed from set callback function +* +*/ +typedef void (*vcpe_error_cb)(vcp_error_e error, const char* msg, void *user_data); + +/** +* @brief Called to retrieve the supported languages. +* +* @param[in] language A language is specified as an ISO 3166 alpha-2 two letter country-code +* followed by ISO 639-1 for the two-letter language code \n +* For example, "ko_KR" for Korean, "en_US" for American English +* @param[in] user_data The user data passed from the foreach function +* +* @return @c true to continue with the next iteration of the loop \n @c false to break out of the loop +* +* @pre vcpe_foreach_supported_languages() will invoke this callback. +* +* @see vcpe_foreach_supported_languages() +*/ +typedef bool (*vcpe_supported_language_cb)(const char* language, void* user_data); + +/** +* @brief Initializes the engine. +* +* @param[in] result_cb A callback function for recognition result +* @param[in] silence_cb A callback function for silence detection +* +* @return 0 on success, otherwise a negative error value +* @retval #VCP_ERROR_NONE Successful +* @retval #VCP_ERROR_INVALID_PARAMETER Invalid parameter +* @retval #VCP_ERROR_INVALID_STATE Already initialized +* @retval #VCP_ERROR_OPERATION_FAILED Operation failed +* +* @see vcpe_deinitialize() +*/ +typedef int (*vcpe_initialize)(void); + +/** +* @brief Deinitializes the engine +* +* @return 0 on success, otherwise a negative error value +* @retval #VCP_ERROR_NONE Successful +* @retval #VCP_ERROR_INVALID_STATE Not initialized +* +* @see vcpe_initialize() +*/ +typedef void (*vcpe_deinitialize)(void); + +/** +* @brief Registers a callback function for getting recognition result. +* +* @param[in] callback Callback function to register +* @param[in] user_data The user data to be passed to the callback function +* +* @return 0 on success, otherwise a negative error value +* @retval #VCP_ERROR_NONE Successful +* @retval #VCP_ERROR_INVALID_PARAMETER Invalid parameter +* +* @see vcpe_result_cb() +*/ +typedef int (*vcpe_set_result_cb)(vcpe_result_cb callback, void* user_data); + +/** +* @brief Registers a callback function for getting ASR recognition result. +* +* @param[in] callback Callback function to register +* @param[in] user_data The user data to be passed to the callback function +* +* @return 0 on success, otherwise a negative error value +* +* @see vcpe_asr_result_cb() +*/ +typedef int (*vcpe_set_asr_result_cb)(vcpe_asr_result_cb callback, void* user_data); + +/** +* @brief Registers a callback function for getting nlg result. +* +* @param[in] callback Callback function to register +* @param[in] user_data The user data to be passed to the callback function +* +* @return 0 on success, otherwise a negative error value +* +*/ +typedef int (*vcpe_set_nlg_result_cb)(vcpe_nlg_result_cb, void* user_data); + +#if 0 +/** +* @brief Registers a callback function for getting partial recognition result. +* +* @param[in] callback Callback function to register +* @param[in] user_data The user data to be passed to the callback function +* +* @return 0 on success, otherwise a negative error value +* +* @see vcpe_pre_result_cb() +*/ +typedef int (*vcpe_set_pre_result_cb)(vcpe_pre_result_cb callback, void* user_data); +#endif + +/** +* @brief Registers a callback function for error. +* +* @param[in] callback Callback function to register +* @param[in] user_data The user data to be passed to the callback function +* +* @return 0 on success, otherwise a negative error value +* +*/ +typedef int (*vcpe_set_error_cb)(vcpe_error_cb callback, void* user_data); + +#if 0 +/** +* @brief Registers a callback function for getting NLU result. +* +* @param[in] callback Callback function to register +* @param[in] user_data The user data to be passed to the callback function +* +* @return 0 on success, otherwise a negative error value +* +*/ +typedef int (*vcpe_set_nlu_result_cb)(vcpe_nlu_result_cb, void* user_data); +#endif + +/** +* @brief Gets recording format of the engine. +* +* @param[in] audio_id The audio device id. +* @param[out] types The format used by the recorder. +* @param[out] rate The sample rate used by the recorder. +* @param[out] channels The number of channels used by the recorder. +* +* @return 0 on success, otherwise a negative error value +* @retval #VCP_ERROR_NONE Successful +* @retval #VCP_ERROR_INVALID_PARAMETER Not initialized +*/ +typedef int (*vcpe_get_recording_format)(const char* audio_id, vcp_audio_type_e* types, int* rate, int* channels); + +/** +* @brief Retrieves all supported languages of the engine. +* +* @param[in] callback a callback function +* @param[in] user_data The user data to be passed to the callback function +* +* @return 0 on success, otherwise a negative error value +* @retval #VCP_ERROR_NONE Successful +* @retval #VCP_ERROR_INVALID_PARAMETER Invalid parameter +* @retval #VCP_ERROR_INVALID_STATE Not initialized +* +* @post This function invokes vcpe_supported_language_cb() repeatedly for getting supported languages. +* +* @see vcpe_supported_language_cb() +*/ +typedef int (*vcpe_foreach_supported_languages)(vcpe_supported_language_cb callback, void* user_data); + +/** +* @brief Checks whether a language is supported or not. +* +* @param[in] language A language +* +* @return @c true = supported, \n @c false = not supported. +*/ +typedef bool (*vcpe_is_language_supported)(const char* language); + +/** +* @brief Sets language. +* +* @param[in] language language. +* +* @return 0 on success, otherwise a negative error value +* @retval #VCP_ERROR_NONE Successful +* @retval #VCP_ERROR_INVALID_LANGUAGE Invalid language +* @retval #VCP_ERROR_INVALID_STATE Not initialized +*/ +typedef int (*vcpe_set_language)(const char* language); + +/** +* @brief Sets command list before recognition. +* +* @remark This function should set commands via vcpd_foreach_command(). +* +* @param[in] vcp_command command handle. +* +* @return 0 on success, otherwise a negative error value +* @retval #VCP_ERROR_NONE Successful +* @retval #VCP_ERROR_INVALID_PARAMETER Invalid parameter +* @retval #VCP_ERROR_INVALID_STATE Invalid state +* @retval #VCP_ERROR_OPERATION_FAILED Operation failed +* @retval #VCP_ERROR_NOT_SUPPORTED_FEATURE Not supported command type +* +* @post vcpe_start() is called after this function is successful. +* +* @see vcpe_start() +* @see vcpd_foreach_command() +* @see vcpe_unset_commands() +*/ +typedef int (*vcpe_set_commands)(vcp_cmd_h vcp_command); + +/** +* @brief Unset command list for reset. +* +* @return 0 on success, otherwise a negative error value +* @retval #VCP_ERROR_NONE Successful +* @retval #VCP_ERROR_INVALID_PARAMETER Invalid parameter +* @retval #VCP_ERROR_INVALID_STATE Invalid state +* @retval #VCP_ERROR_OPERATION_FAILED Operation failed +* +* @see vcpe_set_commands() +*/ +typedef int (*vcpe_unset_commands)(); + +/** +* @brief Start recognition. +* +* @return 0 on success, otherwise a negative error value +* @retval #VCP_ERROR_NONE Successful +* @retval #VCP_ERROR_INVALID_PARAMETER Invalid parameter +* @retval #VCP_ERROR_INVALID_STATE Invalid state +* @retval #VCP_ERROR_INVALID_LANGUAGE Invalid language +* @retval #VCP_ERROR_OUT_OF_NETWORK Out of network +* @retval #VCP_ERROR_OPERATION_FAILED Operation failed +* +* @pre vcpd_foreach_command() is successful. +* +* @see vcpe_set_recording_data() +* @see vcpe_stop() +* @see vcpe_cancel() +*/ +typedef int (*vcpe_start)(bool stop_by_silence); + +/** +* @brief Sets recording data for speech recognition from recorder. +* +* @remark This function should be returned immediately after recording data copy. +* +* @param[in] data A recording data +* @param[in] length A length of recording data +* @param[out] silence_detected @c true Silence detected \n @c false No silence detected +* +* @return 0 on success, otherwise a negative error value +* @retval #VCP_ERROR_NONE Successful +* @retval #VCP_ERROR_INVALID_PARAMETER Invalid parameter +* @retval #VCP_ERROR_INVALID_STATE Invalid state +* @retval #VCP_ERROR_OPERATION_FAILED Operation failed +* +* @pre vcpe_start() is successful. +* +* @see vcpe_start() +* @see vcpe_cancel() +* @see vcpe_stop() +*/ +typedef int(*vcpe_set_recording_data)(const void* data, unsigned int length, vcp_speech_detect_e* speech_detected); + +/** +* @brief Stops to get the result of recognition. +* +* @return 0 on success, otherwise a negative error value +* @retval #VCP_ERROR_NONE Successful +* @retval #VCP_ERROR_INVALID_STATE Invalid state +* @retval #VCP_ERROR_OPERATION_FAILED Operation failed +* @retval #VCP_ERROR_OUT_OF_NETWORK Out of network +* +* @pre vcpe_set_recording_data() is successful. +* +* @see vcpe_start() +* @see vcpe_set_recording_data() +* @see vcpe_result_cb() +* @see vcpe_cancel() +*/ +typedef int (*vcpe_stop)(void); + +/** +* @brief Cancels the recognition process. +* +* @return 0 on success, otherwise a negative error value. +* @retval #VCP_ERROR_NONE Successful. +* @retval #VCP_ERROR_INVALID_STATE Invalid state. +* +* @pre vcpe_start() is successful. +* +* @see vcpe_start() +* @see vcpe_stop() +*/ +typedef int (*vcpe_cancel)(void); + +/** +* @brief Set audio recording type. +* +* @return 0 on success, otherwise a negative error value. +* @retval #VCP_ERROR_NONE Successful. +* +*/ +typedef int (*vcpe_set_audio_type)(const char* audio); + +/** +* @brief Sets domain (Agent or device type) +* +* @param[in] domain available Agent or device type +* +* @return 0 on success, otherwise a negative error value. +* +*/ +typedef int (*vcpe_set_domain)(const char* domain); + +/** +* @brief Gets essential value from nlu result. This function is available inside vcpe_nlu_result_cb() +* +* @param[in] key NLU base info key +* @parma[out] value NLU base info value +* +* @return 0 on success, otherwise a negative error value. +* +*/ +typedef int (*vcpe_get_nlu_base_info)(const char* key, char** value); + +/** +* @brief Sets private data between app and engine. +* +* @param[in] key Private key +* @param[in] data Private data +* +* @return 0 on success, otherwise a negative error value. +* +*/ +typedef int (*vcpe_set_private_data)(const char* key, const char* data); + +/** +* @brief Gets private data between app and engine. +* +* @param[in] key Private key +* @param[out] data Private data +* +* @return 0 on success, otherwise a negative error value. +* +*/ +typedef int (*vcpe_get_private_data)(const char* key, char** data); + +/** +* @brief Request process text. +* +* @param[in] text Requested text +* +* @return 0 on success, otherwise a negative error value. +* +*/ +typedef int (*vcpe_process_text)(const char* text); + +/** +* @brief Request list event. +* +* @param[in] event Requested list event +* +* @return 0 on success, otherwise a negative error value. +* +*/ +typedef int (*vcpe_process_list_event)(const char* event); + +/** +* @brief Request haptic event. +* +* @param[in] event Requested haptic event +* +* @return 0 on success, otherwise a negative error value. +* +*/ +typedef int (*vcpe_process_haptic_event)(const char* event); + +/** +* Daemon API. +*/ + +/** +* @brief Called to retrieve the commands. +* +* @param[in] id command id +* @param[in] type command type +* @param[in] format command format +* @param[in] command command text +* @param[in] param parameter text +* @param[in] domain command domain +* @param[in] user_data The user data passed from the foreach function +* +* @return @c true to continue with the next iteration of the loop, \n @c false to break out of the loop. +* @pre vcpd_foreach_command() will invoke this callback. +* +* @see vcpd_foreach_command() +*/ +typedef bool (*vcpd_foreach_command_cb)(int id, int type, int format, const char* command, const char* param, int domain, void* user_data); + +/** +* @brief Retrieves all commands using callback function. +* +* @param[in] vcp_command The handle to be passed to the vcpe_set_commands() function +* @param[in] callback The callback function to invoke +* @param[in] user_data The user data to be passed to the callback function +* +* @return 0 on success, otherwise a negative error value +* @retval #VCP_ERROR_NONE Successful +* @retval #VCP_ERROR_INVALID_PARAMETER Invalid parameter +* @retval #VCP_ERROR_OPERATION_FAILED Operation failure +* @retval #VCP_ERROR_INVALID_STATE Invalid state +* +* @post This function invokes vcpd_foreach_command_cb() repeatedly for getting commands. +* +* @see vcpd_foreach_command_cb() +* @see vcpe_set_commands() +*/ +typedef int (*vcpd_foreach_command)(vcp_cmd_h vcp_command, vcpd_foreach_command_cb callback, void* user_data); + +/** +* @brief Gets command length. +* +* @param[in] vcp_command The handle to be passed to the vcpe_set_commands() function +* +* @return the value greater than 0 on success, otherwise a negative error value +* +* @see vcpe_set_commands() +*/ +typedef int (*vcpd_get_command_count)(vcp_cmd_h vcp_command); + +/** +* @brief Gets current audio type. +* +* @remarks audio_type must be released using free() when it is no longer required. +* +* @param[in] audio_type Current audio type (e.g. #VCP_AUDIO_ID_BLUETOOTH or usb device id) +* +* @return the value greater than 0 on success, otherwise a negative error value +* +*/ +typedef int (*vcpd_get_audio_type)(char** audio_type); + +/** +* @brief Sets private data to Manager client. +* +* @param[in] key Private key +* @param[in] data Private data +* +* @return 0 on success, otherwise a negative error value. +* +*/ +typedef int (*vcpd_set_private_data)(const char* key, const char* data); + +/** +* @brief Gets private data from Manager client. +* +* @param[in] key Private key +* @param[out] data Private data +* +* @return 0 on success, otherwise a negative error value. +* +*/ +typedef int (*vcpd_get_private_data)(const char* key, char** data); + +/** +* @brief Request start recording. +* +* @return 0 on success, otherwise a negative error value. +* +*/ +typedef int (*vcpd_start_recording)(); + +/** +* @brief Request stop recording. +* +* @return 0 on success, otherwise a negative error value. +* +*/ +typedef int (*vcpd_stop_recording)(); + +/** +* @brief A structure of the engine functions. +*/ +typedef struct { + int size; /**< Size of structure */ + int version; /**< Version */ + + vcpe_initialize initialize; /**< Initialize engine */ + vcpe_deinitialize deinitialize; /**< Shutdown engine */ + + /* Get engine information */ + vcpe_get_recording_format get_recording_format; /**< Get recording format */ + vcpe_foreach_supported_languages foreach_langs; /**< Foreach language list */ + vcpe_is_language_supported is_lang_supported; /**< Check language */ + + /* Set info */ + vcpe_set_result_cb set_result_cb; /**< Set result callback */ + vcpe_set_language set_language; /**< Set language */ + vcpe_set_commands set_commands; /**< Request to set current commands */ + vcpe_unset_commands unset_commands; /**< Request to unset current commands */ + + /* Control recognition */ + vcpe_start start; /**< Start recognition */ + vcpe_set_recording_data set_recording; /**< Set recording data */ + vcpe_stop stop; /**< Stop recording for getting result */ + vcpe_cancel cancel; /**< Cancel recording and processing */ + + vcpe_set_audio_type set_audio_type; /**< Set audio type */ + + //vcpe_set_pre_result_cb set_pre_result_cb; /**< Set pre result callback */ + vcpe_set_asr_result_cb set_asr_result_cb; /**< Set asr result callback */ + vcpe_set_nlg_result_cb set_nlg_result_cb; /**< Set nlg result callback */ + vcpe_set_error_cb set_error_cb; /**< Set error callback */ + vcpe_set_domain set_domain; /**< Set domain */ + vcpe_get_nlu_base_info get_nlu_base_info; /**< Get essential info */ + //vcpe_set_nlu_result_cb set_nlu_result_cb; /**< Set nlu result callback */ + vcpe_set_private_data set_private_data; /**< Set private data */ + vcpe_get_private_data get_private_data; /**< Get private data */ + vcpe_process_text process_text; /**< Request to process text */ + vcpe_process_list_event process_list_event; /**< Request to process list event */ + vcpe_process_haptic_event process_haptic_event; /**< Request to process haptic event */ +} vcpe_funcs_s; + +/** +* @brief A structure of the daemon functions. +*/ +typedef struct { + int size; /**< Size of structure */ + int version; /**< Version */ + + vcpd_foreach_command foreach_command; /**< Foreach command */ + vcpd_get_command_count get_command_count; /**< Get command count */ + + vcpd_get_audio_type get_audio_type; /**< Get audio type */ + + vcpd_set_private_data set_private_data; /**< Set private data to Manager */ + vcpd_get_private_data get_private_data; /**< Get private data from Manager */ + + vcpd_start_recording start_recording; /**< Request start recording */ + vcpd_stop_recording stop_recording; /**< Request stop recording */ +} vcpd_funcs_s; + +/** +* @brief Loads the engine. +* +* @param[in] pdfuncs The daemon functions +* @param[out] pefuncs The engine functions +* +* @return This function returns zero on success, or negative with error code on failure +* @retval #VCP_ERROR_NONE Successful +* @retval #VCP_ERROR_INVALID_PARAMETER Invalid parameter +* @retval #VCP_ERROR_OPERATION_FAILED Operation failed +* +* @pre The vcp_get_engine_info() should be successful. +* @post The daemon calls engine functions of vcpe_funcs_s. +* +* @see vcp_get_engine_info() +* @see vcp_unload_engine() +*/ +int vcp_load_engine(vcpd_funcs_s* pdfuncs, vcpe_funcs_s* pefuncs); + +/** +* @brief Unloads this engine by the daemon. +* +* @pre The vcp_load_engine() should be successful. +* +* @see vcp_load_engine() +*/ +void vcp_unload_engine(void); + +/** +* @brief Called to get the engine base information. +* +* @param[in] engine_uuid The engine id +* @param[in] engine_name The engine name +* @param[in] engine_setting The setting ug name +* @param[in] use_network @c true to need network @c false not to need network. +* @param[in] user_data The User data passed from vcp_get_engine_info() +* +* @pre vcp_get_engine_info() will invoke this callback. +* +* @see vcp_get_engine_info() +*/ +typedef void (*vcpe_engine_info_cb)(const char* engine_uuid, const char* engine_name, const char* engine_setting, + bool use_network, void* user_data); + +/** +* @brief Gets the engine base information before the engine is loaded by the daemon. +* +* @param[in] callback Callback function +* @param[in] user_data User data to be passed to the callback function +* +* @return This function returns zero on success, or negative with error code on failure +* @retval #VCP_ERROR_NONE Successful +* @retval #VCP_ERROR_INVALID_PARAMETER Invalid parameter +* @retval #VCP_ERROR_OPERATION_FAILED Operation failed +* +* @post This function invokes vcpe_engine_info_cb() for getting engine information. +* +* @see vcpe_engine_info_cb() +* @see vcp_load_engine() +*/ +int vcp_get_engine_info(vcpe_engine_info_cb callback, void* user_data); + + +#ifdef __cplusplus +} +#endif + +/** +* @}@} +*/ + +#endif /* __VOICE_CONTROL_PLUGIN_ENGINE_H__ */ diff --git a/org.tizen.voice.vcserver.service b/org.tizen.voice.vcserver.service index c5006a2..a6f1e01 100644 --- a/org.tizen.voice.vcserver.service +++ b/org.tizen.voice.vcserver.service @@ -1,4 +1,3 @@ [D-BUS Service] Name=org.tizen.voice.vcserver -#Exec=/usr/bin/vc-daemon -Exec=/bin/sh -c "launch_app org.tizen.vc-engine-default" +Exec=/usr/bin/vc-daemon diff --git a/packaging/voice-control.spec b/packaging/voice-control.spec index 3b585bc..bb50859 100644 --- a/packaging/voice-control.spec +++ b/packaging/voice-control.spec @@ -121,7 +121,7 @@ mkdir -p %{_libdir}/voice/vc %{_libdir}/libvc_setting.so %{_libdir}/libvc_widget.so %{_libdir}/libvc_manager.so -%{_libdir}/libvc_engine.so +%{_bindir}/vc-daemon %{TZ_SYS_RO_SHARE}/voice/vc/1.0/vc-config.xml %{TZ_SYS_RO_SHARE}/dbus-1/services/org.tizen.voice* /etc/dbus-1/session.d/vc-server.conf @@ -165,5 +165,4 @@ mkdir -p %{_libdir}/voice/vc %files engine-devel %defattr(-,root,root,-) %{_libdir}/pkgconfig/voice-control-engine.pc -%{_includedir}/vce.h - +%{_includedir}/voice_control_plugin_engine.h diff --git a/server/CMakeLists.txt b/server/CMakeLists.txt index f9e8d48..d2cf638 100644 --- a/server/CMakeLists.txt +++ b/server/CMakeLists.txt @@ -10,13 +10,11 @@ SET(SRCS vcd_dbus_server.c vcd_dbus.c vcd_engine_agent.c -# vcd_main.c + vcd_main.c vcd_recorder.c vcd_server.c - vce.c ) -INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}) INCLUDE_DIRECTORIES(${CMAKE_BINARY_DIR}/common) INCLUDE_DIRECTORIES(${CMAKE_BINARY_DIR}/include) @@ -30,15 +28,8 @@ SET(CMAKE_C_FLAGS_RELEASE "-O2 -fPIE") SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed -pie") ## Executable ## -#ADD_EXECUTABLE("${PROJECT_NAME}-daemon" ${SRCS}) -#TARGET_LINK_LIBRARIES("${PROJECT_NAME}-daemon" -ldl -lm ${pkgs_LDFLAGS}) +ADD_EXECUTABLE("${PROJECT_NAME}-daemon" ${SRCS}) +TARGET_LINK_LIBRARIES("${PROJECT_NAME}-daemon" -ldl -lm ${pkgs_LDFLAGS}) ## Install -#INSTALL(TARGETS "${PROJECT_NAME}-daemon" DESTINATION bin) - -## Executable ## -ADD_LIBRARY("${PROJECT_NAME}_engine" SHARED ${SRCS}) -TARGET_LINK_LIBRARIES("${PROJECT_NAME}_engine" -ldl ${pkgs_LDFLAGS}) - -## Install -INSTALL(TARGETS "${PROJECT_NAME}_engine" DESTINATION ${LIBDIR} COMPONENT RuntimeLibraries) +INSTALL(TARGETS "${PROJECT_NAME}-daemon" DESTINATION bin) diff --git a/server/vcd_client_data.c b/server/vcd_client_data.c index 358ddb7..22ea990 100644 --- a/server/vcd_client_data.c +++ b/server/vcd_client_data.c @@ -457,7 +457,7 @@ int vcd_client_foreach_command(client_foreach_command_cb callback, void* user_da return VCD_ERROR_OPERATION_FAILED; } -// int id_count = 1; + // int id_count = 1; GSList *iter = NULL; vc_cmd_s* temp_cmd; @@ -467,7 +467,7 @@ int vcd_client_foreach_command(client_foreach_command_cb callback, void* user_da temp_cmd = iter->data; SLOG(LOG_DEBUG, TAG_VCD, "[Client Data] Widget : id(%d) type(%d) format(%d) command(%s) domain(%d)" - , temp_cmd->id, temp_cmd->type, temp_cmd->format, temp_cmd->command, temp_cmd->domain); + , temp_cmd->id, temp_cmd->type, temp_cmd->format, temp_cmd->command, temp_cmd->domain); callback(temp_cmd->id, temp_cmd->type, temp_cmd->format, temp_cmd->command, temp_cmd->parameter, temp_cmd->domain, user_data); @@ -483,7 +483,7 @@ int vcd_client_foreach_command(client_foreach_command_cb callback, void* user_da temp_cmd = iter->data; SLOG(LOG_DEBUG, TAG_VCD, "[Client Data] Fore : id(%d) type(%d) format(%d) command(%s) param(%s) domain(%d) fixed(%s)" - , temp_cmd->id, temp_cmd->type, temp_cmd->format, temp_cmd->command, temp_cmd->parameter, temp_cmd->domain, temp_cmd->fixed); + , temp_cmd->id, temp_cmd->type, temp_cmd->format, temp_cmd->command, temp_cmd->parameter, temp_cmd->domain, temp_cmd->fixed); callback(temp_cmd->id, temp_cmd->type, temp_cmd->format, temp_cmd->command, temp_cmd->parameter, temp_cmd->domain, user_data); @@ -499,7 +499,7 @@ int vcd_client_foreach_command(client_foreach_command_cb callback, void* user_da temp_cmd = iter->data; SLOG(LOG_DEBUG, TAG_VCD, "[Client Data] System : id(%d) type(%d) format(%d) command(%s) param(%s) domain(%d)" - , temp_cmd->id, temp_cmd->type, temp_cmd->format, temp_cmd->command, temp_cmd->parameter, temp_cmd->domain); + , temp_cmd->id, temp_cmd->type, temp_cmd->format, temp_cmd->command, temp_cmd->parameter, temp_cmd->domain); callback(temp_cmd->id, temp_cmd->type, temp_cmd->format, temp_cmd->command, temp_cmd->parameter, temp_cmd->domain, user_data); @@ -515,7 +515,7 @@ int vcd_client_foreach_command(client_foreach_command_cb callback, void* user_da temp_cmd = iter->data; SLOG(LOG_DEBUG, TAG_VCD, "[Client Data] System background : id(%d) type(%d) format(%d) command(%s) param(%s) domain(%d)" - , temp_cmd->id, temp_cmd->type, temp_cmd->format, temp_cmd->command, temp_cmd->parameter, temp_cmd->domain); + , temp_cmd->id, temp_cmd->type, temp_cmd->format, temp_cmd->command, temp_cmd->parameter, temp_cmd->domain); callback(temp_cmd->id, temp_cmd->type, temp_cmd->format, temp_cmd->command, temp_cmd->parameter, temp_cmd->domain, user_data); @@ -531,7 +531,7 @@ int vcd_client_foreach_command(client_foreach_command_cb callback, void* user_da temp_cmd = iter->data; SLOG(LOG_DEBUG, TAG_VCD, "[Client Data] Exclusive system : id(%d) type(%d) format(%d) command(%s) param(%s) domain(%d)" - , temp_cmd->id, temp_cmd->type, temp_cmd->format, temp_cmd->command, temp_cmd->parameter, temp_cmd->domain); + , temp_cmd->id, temp_cmd->type, temp_cmd->format, temp_cmd->command, temp_cmd->parameter, temp_cmd->domain); callback(temp_cmd->id, temp_cmd->type, temp_cmd->format, temp_cmd->command, temp_cmd->parameter, temp_cmd->domain, user_data); @@ -547,7 +547,7 @@ int vcd_client_foreach_command(client_foreach_command_cb callback, void* user_da temp_cmd = iter->data; SLOG(LOG_DEBUG, TAG_VCD, "[Client Data] Back : id(%d) format(%d) type(%d) command(%s) param(%s) domain(%d) appid(%s) invocation(%s) fixed(%s)" - , temp_cmd->id, temp_cmd->type, temp_cmd->format, temp_cmd->command, temp_cmd->parameter, temp_cmd->domain, temp_cmd->appid, temp_cmd->invocation_name, temp_cmd->fixed); + , temp_cmd->id, temp_cmd->type, temp_cmd->format, temp_cmd->command, temp_cmd->parameter, temp_cmd->domain, temp_cmd->appid, temp_cmd->invocation_name, temp_cmd->fixed); callback(temp_cmd->id, temp_cmd->type, temp_cmd->format, temp_cmd->command, temp_cmd->parameter, temp_cmd->domain, user_data); diff --git a/server/vcd_engine_agent.c b/server/vcd_engine_agent.c index 1f4c585..14510fc 100644 --- a/server/vcd_engine_agent.c +++ b/server/vcd_engine_agent.c @@ -42,7 +42,11 @@ typedef struct { bool use_network; void *handle; - vc_engine_callback_s* callbacks; + vcpe_funcs_s* pefuncs; + vcpd_funcs_s* pdfuncs; + + int (*vcp_load_engine)(vcpd_funcs_s* pdfuncs, vcpe_funcs_s* pefuncs); + int (*vcp_unload_engine)(); } vcengine_s; typedef struct _vcengine_info { @@ -59,28 +63,62 @@ typedef struct _vcengine_info { /** vc engine agent init */ static bool g_agent_init; +/** vc engine list */ +static GList *g_engine_list; + /** current engine information */ static vcengine_s g_dynamic_engine; static char* g_default_lang; +/** callback functions */ +static result_callback g_result_cb = NULL; + +static asr_result_callback g_asr_result_cb = NULL; +static nlg_result_callback g_nlg_result_cb = NULL; + +#if 0 +static pre_result_callback g_pre_result_cb = NULL; + +static nlu_result_callback g_nlu_result_cb = NULL; +#endif + +static error_callback g_error_cb = NULL; + bool __supported_language_cb(const char* language, void* user_data); +void __engine_info_cb(const char* engine_uuid, const char* engine_name, const char* engine_setting, bool use_network, void* user_data); + +bool __engine_setting_cb(const char* key, const char* value, void* user_data); + +/** Free voice list */ +void __free_language_list(GList* lang_list); + + /* * Internal Interfaces */ +/** check engine id */ +int __internal_check_engine_id(const char* engine_uuid); + +/** update engine list */ +int __internal_update_engine_list(); + /** get engine info */ -int __internal_get_engine_info(vce_request_callback_s* callback); +int __internal_get_engine_info(const char* filepath, vcengine_info_s** info); + +int __log_enginelist(); /* * VCS Engine Agent Interfaces */ -int vcd_engine_agent_init() +//int vcd_engine_agent_init(pre_result_callback pre_result_cb, result_callback result_cb, nlu_result_callback nlu_result_cb, error_callback error_cb) +int vcd_engine_agent_init(asr_result_callback asr_result_cb, result_callback result_cb, nlg_result_callback nlg_result_cb, error_callback error_cb) { - if (true == g_agent_init) { - SLOG(LOG_DEBUG, TAG_VCD, "[Engine Agent] Already initialized"); - return VCD_ERROR_NONE; + if (/*NULL == pre_result_cb*/ NULL == asr_result_cb || NULL == result_cb /*|| NULL == nlu_result_cb*/ || NULL == error_cb) { + SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Input parameter is NULL"); + return VCD_ERROR_OPERATION_FAILED; } /* init dynamic engine */ @@ -92,15 +130,18 @@ int vcd_engine_agent_init() g_dynamic_engine.is_loaded = false; g_dynamic_engine.handle = NULL; g_dynamic_engine.is_command_ready = false; - - g_dynamic_engine.callbacks = (vc_engine_callback_s*)calloc(1, sizeof(vc_engine_callback_s)); - if (NULL == g_dynamic_engine.callbacks) { - SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent] Fail to allocate memory"); - return VCD_ERROR_OUT_OF_MEMORY; - } + g_dynamic_engine.pefuncs = (vcpe_funcs_s*)calloc(1, sizeof(vcpe_funcs_s)); + g_dynamic_engine.pdfuncs = (vcpd_funcs_s*)calloc(1, sizeof(vcpd_funcs_s)); g_agent_init = true; + //g_pre_result_cb = pre_result_cb; + g_asr_result_cb = asr_result_cb; + g_nlg_result_cb = nlg_result_cb; + g_result_cb = result_cb; + //g_nlu_result_cb = nlu_result_cb; + g_error_cb = error_cb; + if (0 != vcd_config_get_default_language(&g_default_lang)) { SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] There is No default voice in config"); /* Set default voice */ @@ -122,14 +163,61 @@ int vcd_engine_agent_release() /* unload current engine */ vcd_engine_agent_unload_current_engine(); + /* release engine list */ + GList *iter = NULL; + vcengine_s *data = NULL; + + if (g_list_length(g_engine_list) > 0) { + /* Get a first item */ + iter = g_list_first(g_engine_list); + + while (NULL != iter) { + /* Get handle data from list */ + data = iter->data; + iter = g_list_remove(iter, data); + + if (NULL != data) { + if (NULL != data->engine_uuid) { + g_free(data->engine_uuid); + data->engine_uuid = NULL; + } + if (NULL != data->engine_name) { + g_free(data->engine_name); + data->engine_name = NULL; + } + if (NULL != data->engine_path) { + g_free(data->engine_path); + data->engine_path = NULL; + } + + free(data); + data = NULL; + } + } + } + + g_list_free(iter); + g_engine_list = NULL; + /* release current engine data */ - if (NULL != g_dynamic_engine.callbacks) { - free(g_dynamic_engine.callbacks); - g_dynamic_engine.callbacks = NULL; + if (NULL != g_dynamic_engine.pefuncs) { + free(g_dynamic_engine.pefuncs); + g_dynamic_engine.pefuncs = NULL; + } + if (NULL != g_dynamic_engine.pdfuncs) { + free(g_dynamic_engine.pdfuncs); + g_dynamic_engine.pdfuncs = NULL; } g_agent_init = false; + //g_pre_result_cb = NULL; + g_asr_result_cb = NULL; + g_nlg_result_cb = NULL; + g_result_cb = NULL; + //g_nlu_result_cb = NULL; + g_error_cb = NULL; + SLOG(LOG_DEBUG, TAG_VCD, "[Engine Agent SUCCESS] Engine Agent release"); return 0; @@ -143,166 +231,570 @@ bool vcd_engine_is_available_engine() return false; } -int __internal_get_engine_info(vce_request_callback_s* callback) +int vcd_engine_agent_initialize_current_engine() { - SLOG(LOG_DEBUG, TAG_VCD, "[Engine Agent] inside __internal_get_engine_info"); + /* check agent init */ + if (false == g_agent_init) { + SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Not Initialized"); + return VCD_ERROR_OPERATION_FAILED; + } - if (NULL == callback) { - SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Invalid engine"); + /* update engine list */ + if (0 != __internal_update_engine_list()) { + SLOG(LOG_ERROR, TAG_VCD, "[engine agent] vcd_engine_agent_init : __internal_update_engine_list : no engine error"); return VCD_ERROR_ENGINE_NOT_FOUND; } - if (NULL == callback->get_info) { - SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Invalid engine"); + /* check whether engine id is valid or not.*/ + GList *iter = NULL; + vcengine_info_s *dynamic_engine = NULL; + + if (g_list_length(g_engine_list) > 0) { + /*Get a first item*/ + iter = g_list_first(g_engine_list); + + while (NULL != iter) { + /*Get handle data from list*/ + dynamic_engine = iter->data; + if (NULL != dynamic_engine) { + break; + } + + /*Get next item*/ + iter = g_list_next(iter); + } + } else { return VCD_ERROR_ENGINE_NOT_FOUND; } - if (0 != callback->get_info(&(g_dynamic_engine.engine_uuid), &(g_dynamic_engine.engine_name), &(g_dynamic_engine.engine_setting_path), &(g_dynamic_engine.use_network))) { - SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Fail to get engine info"); + if (NULL == dynamic_engine) { return VCD_ERROR_ENGINE_NOT_FOUND; + } else { + if (NULL != g_dynamic_engine.engine_uuid) { + /* set data from g_engine_list */ + if (g_dynamic_engine.engine_uuid != NULL) g_free(g_dynamic_engine.engine_uuid); + if (g_dynamic_engine.engine_name != NULL) g_free(g_dynamic_engine.engine_name); + if (g_dynamic_engine.engine_path != NULL) g_free(g_dynamic_engine.engine_path); + } + + g_dynamic_engine.engine_uuid = g_strdup(dynamic_engine->engine_uuid); + g_dynamic_engine.engine_name = g_strdup(dynamic_engine->engine_name); + g_dynamic_engine.engine_path = g_strdup(dynamic_engine->engine_path); + + g_dynamic_engine.handle = NULL; + g_dynamic_engine.is_loaded = false; + g_dynamic_engine.is_set = true; + + SLOG(LOG_DEBUG, TAG_VCD, "@@@"); + SLOG(LOG_DEBUG, TAG_VCD, " Dynamic engine uuid : %s", g_dynamic_engine.engine_uuid); + SLOG(LOG_DEBUG, TAG_VCD, " Dynamic engine name : %s", g_dynamic_engine.engine_name); + SLOG(LOG_DEBUG, TAG_VCD, " Dynamic engine path : %s", g_dynamic_engine.engine_path); + SLOG(LOG_DEBUG, TAG_VCD, "@@@"); + } - if (NULL != g_dynamic_engine.callbacks) { - free(g_dynamic_engine.callbacks); - g_dynamic_engine.callbacks = NULL; + return 0; +} + +int __internal_check_engine_id(const char* engine_uuid) +{ + if (NULL == engine_uuid) { + SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Invalid Parameter"); + return VCD_ERROR_INVALID_PARAMETER; + } + + GList *iter = NULL; + vcengine_s *data = NULL; + + if (0 < g_list_length(g_engine_list)) { + /*Get a first item*/ + iter = g_list_first(g_engine_list); + + while (NULL != iter) { + data = iter->data; + + if (0 == strncmp(engine_uuid, data->engine_uuid, strlen(data->engine_uuid))) { + return 0; + } + + iter = g_list_next(iter); + } } - g_dynamic_engine.callbacks = (vc_engine_callback_s*)calloc(1, sizeof(vc_engine_callback_s)); - if (NULL == g_dynamic_engine.callbacks) { - SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Fail to allocate memory"); + + return -1; +} + +void __engine_info_cb(const char* engine_uuid, const char* engine_name, const char* engine_setting, bool use_network, void* user_data) +{ + vcengine_info_s* temp = (vcengine_info_s*)user_data; + + temp->engine_uuid = g_strdup(engine_uuid); + temp->engine_name = g_strdup(engine_name); +} + + +int __internal_get_engine_info(const char* filepath, vcengine_info_s** info) +{ + if (NULL == filepath || NULL == info) { + SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Invalid Parameter"); + return VCD_ERROR_INVALID_PARAMETER; + } + + /* load engine */ + char *error; + void* handle; + + if (0 != access(filepath, F_OK)) { + SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Fail to access file (%s)", filepath); + return -1; + } else { + handle = dlopen(filepath, RTLD_LAZY); + if (!handle) { + SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Invalid engine : %s", filepath); + if ((error = dlerror()) != NULL) { + SLOG(LOG_ERROR, TAG_VCD, "[ERROR] %s", error); + } + return -1; + } + } + + /* link engine to daemon */ + dlsym(handle, "vcp_load_engine"); + if ((error = dlerror()) != NULL) { + SLOG(LOG_WARN, TAG_VCD, "[Engine Agent] Invalid engine. Fail to open vcp_load_engine : %s", filepath); + dlclose(handle); + return -1; + } + + dlsym(handle, "vcp_unload_engine"); + if ((error = dlerror()) != NULL) { + SLOG(LOG_WARN, TAG_VCD, "[Engine Agent] Invalid engine. Fail to open vcp_unload_engine : %s", filepath); + dlclose(handle); + return -1; + } + + int (*get_engine_info)(vcpe_engine_info_cb callback, void* user_data); + + get_engine_info = (int (*)(vcpe_engine_info_cb, void*))dlsym(handle, "vcp_get_engine_info"); + if (NULL != (error = dlerror()) || NULL == get_engine_info) { + SLOG(LOG_WARN, TAG_VCD, "[Engine Agent WARNING] Invalid engine. Fail to open vcp_get_engine_info : %s", filepath); + dlclose(handle); + return -1; + } + + vcengine_info_s* temp; + temp = (vcengine_info_s*)calloc(1, sizeof(vcengine_info_s)); + if (NULL == temp) { + SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to allocate memory"); + dlclose(handle); return VCD_ERROR_OUT_OF_MEMORY; } - g_dynamic_engine.callbacks->get_info = callback->get_info; - g_dynamic_engine.callbacks->get_recording_format = callback->get_recording_format; - g_dynamic_engine.callbacks->foreach_langs = callback->foreach_langs; - g_dynamic_engine.callbacks->is_lang_supported = callback->is_lang_supported; - g_dynamic_engine.callbacks->initialize = callback->initialize; - g_dynamic_engine.callbacks->deinitialize = callback->deinitialize; - g_dynamic_engine.callbacks->set_language = callback->set_language; - g_dynamic_engine.callbacks->set_commands = callback->set_commands; - g_dynamic_engine.callbacks->unset_commands = callback->unset_commands; - - g_dynamic_engine.callbacks->start = callback->start; - g_dynamic_engine.callbacks->set_recording = callback->set_recording; - g_dynamic_engine.callbacks->stop = callback->stop; - g_dynamic_engine.callbacks->cancel = callback->cancel; - g_dynamic_engine.callbacks->set_domain = callback->set_domain; - g_dynamic_engine.callbacks->set_audio_type = callback->set_audio_type; - g_dynamic_engine.callbacks->process_text = callback->process_text; - g_dynamic_engine.callbacks->process_list_event = callback->process_list_event; - g_dynamic_engine.callbacks->process_haptic_event = callback->process_haptic_event; - - g_dynamic_engine.callbacks->private_data_set = NULL; - g_dynamic_engine.callbacks->private_data_request = NULL; - g_dynamic_engine.callbacks->nlu_base_info_request = NULL; + /* get engine info */ + if (0 != get_engine_info(__engine_info_cb, (void*)temp)) { + SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Fail to get engine info from engine"); + dlclose(handle); + free(temp); + return -1; + } + + /* close engine */ + dlclose(handle); + + temp->engine_path = g_strdup(filepath); SLOG(LOG_DEBUG, TAG_VCD, "@@@ Valid Engine"); - SLOG(LOG_DEBUG, TAG_VCD, "Engine uuid : %s", g_dynamic_engine.engine_uuid); - SLOG(LOG_DEBUG, TAG_VCD, "Engine name : %s", g_dynamic_engine.engine_name); + SLOG(LOG_DEBUG, TAG_VCD, "Engine uuid : %s", temp->engine_uuid); + SLOG(LOG_DEBUG, TAG_VCD, "Engine name : %s", temp->engine_name); + SLOG(LOG_DEBUG, TAG_VCD, "Engine path : %s", temp->engine_path); SLOG(LOG_DEBUG, TAG_VCD, "@@@"); + *info = temp; + return 0; } -int vcd_engine_agent_load_current_engine(vce_request_callback_s* callback) +int __internal_update_engine_list() { - SLOG(LOG_DEBUG, TAG_VCD, "[Engine Agent] load current engine START"); + /* relsease engine list */ + GList *iter = NULL; + vcengine_info_s *data = NULL; - if (false == g_agent_init) { - SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Not Initialized"); - return VCD_ERROR_OPERATION_FAILED; + if (0 < g_list_length(g_engine_list)) { + /* Get a first item */ + iter = g_list_first(g_engine_list); + + while (NULL != iter) { + /* Get handle data from list */ + data = iter->data; + + if (NULL != data) { + if (NULL != data->engine_uuid) g_free(data->engine_uuid); + if (NULL != data->engine_path) g_free(data->engine_path); + if (NULL != data->engine_name) g_free(data->engine_name); + + data->engine_uuid = NULL; + data->engine_path = NULL; + data->engine_name = NULL; + + free(data); + } + + g_engine_list = g_list_remove_link(g_engine_list, iter); + iter = g_list_first(g_engine_list); + } } - if (true == g_dynamic_engine.is_loaded) { - SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent] Engine has already been loaded"); - return 0; + /* Get file name from default engine directory */ + DIR *dp = NULL; + struct dirent *dirp = NULL; + + dp = opendir(VC_DEFAULT_ENGINE); + if (NULL != dp) { + do { + dirp = readdir(dp); + + if (NULL != dirp) { + if (!strcmp(".", dirp->d_name) || !strcmp("..", dirp->d_name)) + continue; + + vcengine_info_s* info = NULL; + char* filepath = NULL; + int filesize = 0; + + filesize = strlen(VC_DEFAULT_ENGINE) + strlen(dirp->d_name) + 5; + filepath = (char*)calloc(filesize, sizeof(char)); + + if (NULL != filepath) { + snprintf(filepath, filesize, "%s/%s", VC_DEFAULT_ENGINE, dirp->d_name); + } else { + SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Memory not enough!!"); + continue; + } + + /* get its info and update engine list */ + if (0 == __internal_get_engine_info(filepath, &info)) { + /* add engine info to g_engine_list */ + g_engine_list = g_list_append(g_engine_list, info); + } + + if (NULL != filepath) { + free(filepath); + filepath = NULL; + } + } + } while (NULL != dirp); + + closedir(dp); + } else { + SLOG(LOG_WARN, TAG_VCD, "[Engine Agent WARNING] Fail to open default directory"); } - if (NULL == callback) { - SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Invalid engine"); + if (0 >= g_list_length(g_engine_list)) { + SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] No Engine"); return VCD_ERROR_ENGINE_NOT_FOUND; } - /* Get current engine info */ - int ret = __internal_get_engine_info(callback); + __log_enginelist(); + + return 0; +} + + +int __foreach_command(vcp_cmd_h vc_command, vcpd_foreach_command_cb callback, void* user_data) +{ + SLOG(LOG_DEBUG, TAG_VCD, "[Engine Agent] Request foreach command from engine"); + return vcd_client_foreach_command((client_foreach_command_cb)callback, user_data); +} + +int __command_get_length(vcp_cmd_h vc_command) +{ + SLOG(LOG_DEBUG, TAG_VCD, "[Engine Agent] Request command length from engine"); + return vcd_client_get_length(); +} + +int __get_audio_type(char** audio_type) +{ + SLOG(LOG_DEBUG, TAG_VCD, "[Engine Agent] Request audio type"); + + return vcd_recorder_get(audio_type); +} + +int __set_private_data(const char* key, const char* data) +{ + SLOG(LOG_DEBUG, TAG_VCD, "[Engine Agent] Request set private data, key(%s), data(%s)", key, data); + vcdc_send_request_set_private_data(vcd_client_manager_get_pid(), key, data); + + return 0; +} + +int __get_private_data(const char* key, char** data) +{ + SLOG(LOG_DEBUG, TAG_VCD, "[Engine Agent] Request get private data, key(%s)", key); + vcdc_send_request_get_private_data(vcd_client_manager_get_pid(), key, data); + + return 0; +} + +int __start_recording() +{ + SLOG(LOG_DEBUG, TAG_VCD, "[Engine Agent] Request start recording"); + + int ret = vcd_recorder_start(); if (0 != ret) { - SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Fail to get engine info"); + SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to start recorder : result(%d)", ret); + vcd_engine_recognize_cancel(); + /* Send error cb to manager */ + vcdc_send_error_signal_to_manager(vcd_client_manager_get_pid(), VCD_ERROR_OPERATION_FAILED, "voice_engine.error.proc_fail"); return ret; } - /* Check all engine functions */ - if (NULL == g_dynamic_engine.callbacks->get_info || - NULL == g_dynamic_engine.callbacks->get_recording_format || - NULL == g_dynamic_engine.callbacks->foreach_langs || - NULL == g_dynamic_engine.callbacks->is_lang_supported || - NULL == g_dynamic_engine.callbacks->initialize || - NULL == g_dynamic_engine.callbacks->deinitialize || - NULL == g_dynamic_engine.callbacks->set_language || - NULL == g_dynamic_engine.callbacks->set_commands || - NULL == g_dynamic_engine.callbacks->unset_commands || - NULL == g_dynamic_engine.callbacks->start || - NULL == g_dynamic_engine.callbacks->set_recording || - NULL == g_dynamic_engine.callbacks->stop || - NULL == g_dynamic_engine.callbacks->cancel || - NULL == g_dynamic_engine.callbacks->set_audio_type || - NULL == g_dynamic_engine.callbacks->set_domain || - NULL == g_dynamic_engine.callbacks->process_text || - NULL == g_dynamic_engine.callbacks->process_list_event || - NULL == g_dynamic_engine.callbacks->process_haptic_event) { - SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] The current engine is NOT valid"); - return VCD_ERROR_ENGINE_NOT_FOUND; + return 0; +} + +int __stop_recording() +{ + SLOG(LOG_DEBUG, TAG_VCD, "[Engine Agent] Request stop recording"); + + return vcd_recorder_stop(); +} + +void __result_cb(vcp_result_event_e event, int* result_id, int count, const char* all_result, const char* non_fixed, const char* nlu_result, const char* msg, int* user_info, void *user_data) +{ + SECURE_SLOG(LOG_DEBUG, TAG_VCD, "[Engine agent] Event(%d), Count(%d) Text(%s) Nonfixed(%s) NLU result(%s) Msg(%s)", event, count, all_result, non_fixed, nlu_result, msg); + + if (NULL != g_result_cb) { + g_result_cb(event, result_id, count, all_result, non_fixed, nlu_result, msg, user_info, user_data); + } else { + SLOG(LOG_DEBUG, TAG_VCD, "[Engine Agent ERROR] Result callback function is NOT valid"); } - /* initalize engine */ - ret = g_dynamic_engine.callbacks->initialize(); - if (0 != ret) { - SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Fail to initialize vc engine service"); - return ret; + return; +} + +void __asr_result_cb(vcp_asr_result_event_e event, const char* asr_result, void *user_data) +{ + SECURE_SLOG(LOG_DEBUG, TAG_VCD, "[Engine Agent] ASR result - Event(%d), Result(%s)", event, asr_result); + + if (NULL != g_asr_result_cb) { + g_asr_result_cb(event, asr_result, user_data); + } else { + SLOG(LOG_DEBUG, TAG_VCD, "[Engine Agent ERROR] ASR result callback function is NOT valid"); } - /* set the supported language */ - if (true == g_dynamic_engine.callbacks->is_lang_supported(g_default_lang)) { - ret = g_dynamic_engine.callbacks->set_language(g_default_lang); - if (0 != ret) { - SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Fail to set the supported language"); - return ret; - } + return; +} + +void __nlg_result_cb(const char* nlg_result, void *user_data) +{ + SECURE_SLOG(LOG_DEBUG, TAG_VCD, "[Engine Agent] NLG result - Result(%s)", nlg_result); - SLOG(LOG_DEBUG, TAG_VCD, "[Engine Agent SUCCESS] The %s has been loaded!!!", g_dynamic_engine.engine_name); - g_dynamic_engine.is_loaded = true; + if (NULL != g_nlg_result_cb) { + g_nlg_result_cb(nlg_result, user_data); } else { - SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent WARNING] This engine do not support default language : lang(%s)", g_default_lang); - g_dynamic_engine.is_loaded = false; + SLOG(LOG_DEBUG, TAG_VCD, "[Engine Agent ERROR] NLG result callback function is NOT valid"); + } + + return; +} + +void __error_cb(vcp_error_e error, const char* msg, void *user_data) +{ + SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent] ERROR(%d)", error); + + if (NULL != g_error_cb) { + g_error_cb(error, msg, user_data); + } else { + SLOG(LOG_DEBUG, TAG_VCD, "[Engine Agent ERROR] Error callback function is NOT vaild"); + } + + return; +} + +int __load_engine(vcengine_s* engine) +{ + /* check whether engine is NULL or not */ + if (NULL == engine) { + SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] engine is NULL"); + return VCD_ERROR_INVALID_PARAMETER; + } + + /* check whether current engine is loaded or not */ + if (true == engine->is_loaded) { + SLOG(LOG_DEBUG, TAG_VCD, "[Engine Agent] Engine has already been loaded "); + return 0; + } + + SLOG(LOG_DEBUG, TAG_VCD, "[Engine Agent] Current engine path : %s", engine->engine_path); + + /* open engine */ + char *error; + if (0 != access(engine->engine_path, F_OK)) { + SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Fail to access file (%s)", engine->engine_path); + return VCD_ERROR_OPERATION_FAILED; + } else { + engine->handle = dlopen(engine->engine_path, RTLD_LAZY); + + if ((error = dlerror()) != NULL || !engine->handle) { + SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Fail to get engine handle"); + return VCD_ERROR_OPERATION_FAILED; + } + } + + engine->vcp_unload_engine = (int (*)())dlsym(engine->handle, "vcp_unload_engine"); + if ((error = dlerror()) != NULL) { + SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Fail to link daemon to vcp_unload_engine()"); + dlclose(engine->handle); + return VCD_ERROR_OPERATION_FAILED; + } + + engine->vcp_load_engine = (int (*)(vcpd_funcs_s*, vcpe_funcs_s*))dlsym(engine->handle, "vcp_load_engine"); + if (NULL != (error = dlerror()) || NULL == engine->vcp_load_engine) { + SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Fail to link daemon to vcp_load_engine()"); + dlclose(engine->handle); + return VCD_ERROR_OPERATION_FAILED; + } + + /* load engine */ + engine->pdfuncs->version = 1; + engine->pdfuncs->size = sizeof(vcpd_funcs_s); + + engine->pdfuncs->foreach_command = __foreach_command; + engine->pdfuncs->get_command_count = __command_get_length; + engine->pdfuncs->get_audio_type = __get_audio_type; + + engine->pdfuncs->set_private_data = __set_private_data; + engine->pdfuncs->get_private_data = __get_private_data; + + engine->pdfuncs->start_recording = __start_recording; + engine->pdfuncs->stop_recording = __stop_recording; + + if (0 != engine->vcp_load_engine(engine->pdfuncs, engine->pefuncs)) { + SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Fail vcp_load_engine()"); + dlclose(engine->handle); return VCD_ERROR_OPERATION_FAILED; } - SLOG(LOG_DEBUG, TAG_VCD, "[Engine Agent] load current engine FINISH"); + SLOG(LOG_DEBUG, TAG_VCD, "[Engine Agent] engine info : version(%d), size(%d)(%d)", engine->pefuncs->version, engine->pefuncs->size, sizeof(vcpe_funcs_s)); + + /* engine error check */ + if (engine->pefuncs->size != sizeof(vcpe_funcs_s)) { + SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Engine is not valid"); + return VCD_ERROR_OPERATION_FAILED; + } + + /* Check all engine functions */ + if (NULL == engine->pefuncs->initialize || + NULL == engine->pefuncs->deinitialize || + NULL == engine->pefuncs->get_recording_format || + NULL == engine->pefuncs->foreach_langs || + NULL == engine->pefuncs->is_lang_supported || + NULL == engine->pefuncs->set_result_cb || + NULL == engine->pefuncs->set_language || + NULL == engine->pefuncs->set_commands || + NULL == engine->pefuncs->unset_commands || + NULL == engine->pefuncs->start || + NULL == engine->pefuncs->set_recording || + NULL == engine->pefuncs->stop || + NULL == engine->pefuncs->cancel || + NULL == engine->pefuncs->set_audio_type || + NULL == engine->pefuncs->set_asr_result_cb || + NULL == engine->pefuncs->set_nlg_result_cb || + //NULL == engine->pefuncs->set_pre_result_cb || + NULL == engine->pefuncs->set_error_cb || + NULL == engine->pefuncs->set_domain || + NULL == engine->pefuncs->get_nlu_base_info || + //NULL == engine->pefuncs->set_nlu_result_cb || + NULL == engine->pefuncs->set_private_data || + NULL == engine->pefuncs->get_private_data || + NULL == engine->pefuncs->process_text || + NULL == engine->pefuncs->process_list_event || + NULL == engine->pefuncs->process_haptic_event) { + SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] The current engine is NOT valid"); + return VCD_ERROR_OPERATION_FAILED; + } + + /* initalize engine */ + if (0 != engine->pefuncs->initialize()) { + SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Fail to initialize vc-engine"); + return VCD_ERROR_OPERATION_FAILED; + } + + if (0 != engine->pefuncs->set_result_cb(__result_cb, NULL)) { + SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Fail to set result callback of vc-engine"); + return VCD_ERROR_OPERATION_FAILED; + } + + if (0 != engine->pefuncs->set_asr_result_cb(__asr_result_cb, NULL)) { + SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Fail to set asr result callback of vc-engine"); + return VCD_ERROR_OPERATION_FAILED; + } + + if (0 != engine->pefuncs->set_nlg_result_cb(__nlg_result_cb, NULL)) { + SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Fail to set nlg result callback of vc-engine"); + return VCD_ERROR_OPERATION_FAILED; + } + + if (0 != engine->pefuncs->set_error_cb(__error_cb, NULL)) { + SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Fail to set error callback of vc-engine"); + return VCD_ERROR_OPERATION_FAILED; + } + + /* load engine */ + if (true == engine->pefuncs->is_lang_supported(g_default_lang)) { + if (0 != engine->pefuncs->set_language(g_default_lang)) { + SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Fail to load current engine"); + return VCD_ERROR_OPERATION_FAILED; + } + SLOG(LOG_DEBUG, TAG_VCD, "[Engine Agent SUCCESS] The %s has been loaded !!!", engine->engine_name); + engine->is_loaded = true; + } else { + SLOG(LOG_WARN, TAG_VCD, "[Engine Agent WARNING] This engine do not support default language : lang(%s)", g_default_lang); + engine->is_loaded = false; + } return 0; } -int vcd_engine_agent_unload_current_engine() +int vcd_engine_agent_load_current_engine() { if (false == g_agent_init) { SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Not Initialized"); return VCD_ERROR_OPERATION_FAILED; } - if (false == g_dynamic_engine.is_loaded) { - SLOG(LOG_DEBUG, TAG_VCD, "[Engine Agent] Engine has already been unloaded"); - return VCD_ERROR_NONE; - } + if (true == g_dynamic_engine.is_set) { + if (0 != __load_engine(&g_dynamic_engine)) { + SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Fail to load dynamic engine"); - /* shut down engine */ - int ret = 0; - ret = g_dynamic_engine.callbacks->deinitialize(); - if (0 != ret) { - SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Fail to deinitialize"); + /* need to initialize dynamic engine data */ + g_dynamic_engine.is_loaded = false; + } else { + SLOG(LOG_DEBUG, TAG_VCD, "[Engine Agent SUCCESS] Load dynamic engine"); + } } - /* reset current engine data */ - g_dynamic_engine.is_loaded = false; + return 0; +} + +int vcd_engine_agent_unload_current_engine() +{ + if (false == g_agent_init) { + SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Not Initialized "); + return VCD_ERROR_OPERATION_FAILED; + } + if (true == g_dynamic_engine.is_set) { + /* unload dynamic engine */ + if (true == g_dynamic_engine.is_loaded) { + /* shutdown engine */ + g_dynamic_engine.pefuncs->deinitialize(); + g_dynamic_engine.vcp_unload_engine(); + dlclose(g_dynamic_engine.handle); + g_dynamic_engine.handle = NULL; + g_dynamic_engine.is_loaded = false; + } + } return 0; } @@ -322,7 +814,7 @@ int vcd_engine_set_commands() if (true == g_dynamic_engine.is_loaded) { /* Set dynamic command */ - ret = g_dynamic_engine.callbacks->set_commands((vce_cmd_h)0); + ret = g_dynamic_engine.pefuncs->set_commands((vcp_cmd_h)0); if (0 != ret) { SLOG(LOG_WARN, TAG_VCD, "[Engine Agent ERROR] Fail to set command of dynamic engine : error(%d)", ret); g_dynamic_engine.is_command_ready = false; @@ -349,7 +841,7 @@ int vcd_engine_recognize_start(bool silence) SLOG(LOG_DEBUG, TAG_VCD, "[Engine Agent] silence is %s", silence ? "true" : "false"); if (true == g_dynamic_engine.is_loaded && true == g_dynamic_engine.is_command_ready) { - ret = g_dynamic_engine.callbacks->start(silence); + ret = g_dynamic_engine.pefuncs->start(silence); if (0 != ret) { SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent] Fail to start engine error(%d)", ret); return VCD_ERROR_OPERATION_FAILED; @@ -363,7 +855,7 @@ int vcd_engine_recognize_start(bool silence) return 0; } -int vcd_engine_recognize_audio(const void* data, unsigned int length, vce_speech_detect_e* speech_detected) +int vcd_engine_recognize_audio(const void* data, unsigned int length, vcp_speech_detect_e* speech_detected) { if (false == g_agent_init) { SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Not Initialized"); @@ -378,10 +870,10 @@ int vcd_engine_recognize_audio(const void* data, unsigned int length, vce_speech int ret = -1; if (true == g_dynamic_engine.is_loaded) { - ret = g_dynamic_engine.callbacks->set_recording(data, length, speech_detected); + ret = g_dynamic_engine.pefuncs->set_recording(data, length, speech_detected); if (0 != ret) { SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Fail to set recording dynamic engine error(%d)", ret); - if (VCE_ERROR_OUT_OF_NETWORK == ret) { + if (VCP_ERROR_OUT_OF_NETWORK == ret) { return VCD_ERROR_TIMED_OUT; } return VCD_ERROR_OPERATION_FAILED; @@ -400,7 +892,7 @@ int vcd_engine_recognize_stop() if (true == g_dynamic_engine.is_loaded) { int ret = -1; - ret = g_dynamic_engine.callbacks->stop(); + ret = g_dynamic_engine.pefuncs->stop(); if (0 != ret) { SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Fail to stop dynamic engine error(%d)", ret); return VCD_ERROR_OPERATION_FAILED; @@ -422,7 +914,7 @@ int vcd_engine_recognize_cancel() int ret = -1; if (true == g_dynamic_engine.is_loaded) { - ret = g_dynamic_engine.callbacks->cancel(); + ret = g_dynamic_engine.pefuncs->cancel(); if (0 != ret) { SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Fail to cancel dynamic engine error(%d)", ret); return VCD_ERROR_OPERATION_FAILED; @@ -441,7 +933,7 @@ int vcd_engine_set_audio_type(const char* audio) int ret = -1; if (true == g_dynamic_engine.is_loaded) { - ret = g_dynamic_engine.callbacks->set_audio_type(audio); + ret = g_dynamic_engine.pefuncs->set_audio_type(audio); if (0 != ret) { SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Fail to set audio type(%d)", ret); return VCD_ERROR_OPERATION_FAILED; @@ -460,7 +952,7 @@ int vcd_engine_set_domain(int pid, const char* domain) int ret = -1; if (true == g_dynamic_engine.is_loaded) { - ret = g_dynamic_engine.callbacks->set_domain(domain); + ret = g_dynamic_engine.pefuncs->set_domain(domain); if (0 != ret) { SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Fail to set domain (%d)", ret); return VCD_ERROR_OPERATION_FAILED; @@ -483,15 +975,12 @@ int vcd_engine_get_nlu_base_info(int pid, const char* key, char** value) } int ret = -1; - if (true == g_dynamic_engine.is_loaded && NULL != g_dynamic_engine.callbacks->nlu_base_info_request) { - ret = g_dynamic_engine.callbacks->nlu_base_info_request(key, value); + if (true == g_dynamic_engine.is_loaded) { + ret = g_dynamic_engine.pefuncs->get_nlu_base_info(key, value); if (0 != ret) { SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Fail to get nlu base info (%d)", ret); return VCD_ERROR_OPERATION_FAILED; } - } else { - SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Engine is not loaded or There is no nlu_base_info_request callback"); - return VCD_ERROR_OPERATION_FAILED; } return 0; @@ -505,15 +994,12 @@ int vcd_engine_set_private_data(int pid, const char* key, const char* data) } int ret = -1; - if (true == g_dynamic_engine.is_loaded && NULL != g_dynamic_engine.callbacks->private_data_set) { - ret = g_dynamic_engine.callbacks->private_data_set(key, data); + if (true == g_dynamic_engine.is_loaded) { + ret = g_dynamic_engine.pefuncs->set_private_data(key, data); if (0 != ret) { SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Fail to set private data (%d)", ret); return VCD_ERROR_OPERATION_FAILED; } - } else { - SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Engine is not loaded or There is no private_data_set callback"); - return VCD_ERROR_OPERATION_FAILED; } return 0; @@ -532,15 +1018,12 @@ int vcd_engine_get_private_data(int pid, const char* key, char** data) } int ret = -1; - if (true == g_dynamic_engine.is_loaded && NULL != g_dynamic_engine.callbacks->private_data_request) { - ret = g_dynamic_engine.callbacks->private_data_request(key, data); + if (true == g_dynamic_engine.is_loaded) { + ret = g_dynamic_engine.pefuncs->get_private_data(key, data); if (0 != ret) { SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Fail to get private data (%d)", ret); return VCD_ERROR_OPERATION_FAILED; } - } else { - SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Engine is not loaded or There is no private_data_request callback"); - return VCD_ERROR_OPERATION_FAILED; } return 0; @@ -555,7 +1038,7 @@ int vcd_engine_process_text(int pid, const char* text) int ret = -1; if (true == g_dynamic_engine.is_loaded) { - ret = g_dynamic_engine.callbacks->process_text(text); + ret = g_dynamic_engine.pefuncs->process_text(text); if (0 != ret) { SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Fail to process text (%d)", ret); return VCD_ERROR_OPERATION_FAILED; @@ -574,7 +1057,7 @@ int vcd_engine_process_list_event(int pid, const char* event) int ret = -1; if (true == g_dynamic_engine.is_loaded) { - ret = g_dynamic_engine.callbacks->process_list_event(event); + ret = g_dynamic_engine.pefuncs->process_list_event(event); if (0 != ret) { SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Fail to process list event (%d)", ret); return VCD_ERROR_OPERATION_FAILED; @@ -593,7 +1076,7 @@ int vcd_engine_process_haptic_event(int pid, const char* event) int ret = -1; if (true == g_dynamic_engine.is_loaded) { - ret = g_dynamic_engine.callbacks->process_haptic_event(event); + ret = g_dynamic_engine.pefuncs->process_haptic_event(event); if (0 != ret) { SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Fail to process haptic event (%d)", ret); return VCD_ERROR_OPERATION_FAILED; @@ -607,7 +1090,7 @@ int vcd_engine_process_haptic_event(int pid, const char* event) * VCS Engine Interfaces for client and setting */ -int vcd_engine_get_audio_format(const char* audio_id, vce_audio_type_e* types, int* rate, int* channels) +int vcd_engine_get_audio_format(const char* audio_id, vcp_audio_type_e* types, int* rate, int* channels) { if (false == g_agent_init) { SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Not Initialized"); @@ -618,7 +1101,12 @@ int vcd_engine_get_audio_format(const char* audio_id, vce_audio_type_e* types, i SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Engine is not loaded"); } - int ret = g_dynamic_engine.callbacks->get_recording_format(audio_id, types, rate, channels); + if (NULL == g_dynamic_engine.pefuncs->get_recording_format) { + SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] The function of engine is NULL!!"); + return VCD_ERROR_OPERATION_FAILED; + } + + int ret = g_dynamic_engine.pefuncs->get_recording_format(audio_id, types, rate, channels); if (0 != ret) { SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] get recording format(%d)", ret); return VCD_ERROR_OPERATION_FAILED; @@ -656,7 +1144,12 @@ int vcd_engine_supported_langs(GList** lang_list) SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Engine is not loaded"); } - int ret = g_dynamic_engine.callbacks->foreach_langs(__supported_language_cb, (void*)lang_list); + if (NULL == g_dynamic_engine.pefuncs->foreach_langs) { + SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] The function of engine is NULL!!"); + return VCD_ERROR_OPERATION_FAILED; + } + + int ret = g_dynamic_engine.pefuncs->foreach_langs(__supported_language_cb, (void*)lang_list); if (0 != ret) { SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] get language list error(%d)", ret); return VCD_ERROR_OPERATION_FAILED; @@ -701,7 +1194,7 @@ int vcd_engine_set_current_language(const char* language) if (true == g_dynamic_engine.is_loaded) { g_dynamic_engine.is_command_ready = false; - ret = g_dynamic_engine.callbacks->set_language(language); + ret = g_dynamic_engine.pefuncs->set_language(language); if (0 != ret) { SLOG(LOG_WARN, TAG_VCD, "[Engine Agent] Fail to set language of dynamic engine error(%d, %s)", ret, language); } @@ -712,113 +1205,59 @@ int vcd_engine_set_current_language(const char* language) return 0; } -int vcd_engine_agent_get_foreach_command(vce_cmd_h vce_command, vce_command_cb callback, void* user_data) -{ - SLOG(LOG_DEBUG, TAG_VCD, "[Engine Agent] Request foreach command from engine"); - return vcd_client_foreach_command((client_foreach_command_cb)callback, user_data); -} - -int vcd_engine_agent_get_command_count(vce_cmd_h vce_command) -{ - SLOG(LOG_DEBUG, TAG_VCD, "[Engine Agent] Request command length from engine"); - - return vcd_client_get_length(); -} - -int vcd_engine_agent_get_audio_type(char** audio_type) -{ - SLOG(LOG_DEBUG, TAG_VCD, "[Engine Agent] Request audio type"); - - return vcd_recorder_get(audio_type); -} - -int vcd_engine_agent_set_private_data(const char* key, const char* data) -{ - SLOG(LOG_DEBUG, TAG_VCD, "[Engine Agent] Request set private data, key(%s), data(%s)", key, data); - vcdc_send_request_set_private_data(vcd_client_manager_get_pid(), key, data); - - return VCD_ERROR_NONE; -} - -int vcd_engine_agent_get_private_data(const char* key, char** data) -{ - SLOG(LOG_DEBUG, TAG_VCD, "[Engine Agent] Request get private data, key(%s)", key); - vcdc_send_request_get_private_data(vcd_client_manager_get_pid(), key, data); - - return VCD_ERROR_NONE; -} - -int vcd_engine_agent_start_recording() +void __free_language_list(GList* lang_list) { - SLOG(LOG_DEBUG, TAG_VCD, "[Engine Agent] Request start recording"); - - int 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 */ - vcdc_send_error_signal_to_manager(vcd_client_manager_get_pid(), VCD_ERROR_OPERATION_FAILED, "voice_engine.error.proc_fail"); - return ret; - } + GList *iter = NULL; + char* data = NULL; - return VCD_ERROR_NONE; -} + /* if list have item */ + if (g_list_length(lang_list) > 0) { + /* Get a first item */ + iter = g_list_first(lang_list); -int vcd_engine_agent_stop_recording() -{ - SLOG(LOG_DEBUG, TAG_VCD, "[Engine Agent] Request stop recording"); + while (NULL != iter) { + data = iter->data; - return vcd_recorder_stop(); -} + if (NULL != data) + free(data); -int vcd_engine_agent_set_private_data_set_cb(vce_private_data_set_cb callback_func) -{ - if (false == g_agent_init) { - SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Not Initialized"); - return VCD_ERROR_OPERATION_FAILED; - } + lang_list = g_list_remove_link(lang_list, iter); - if (false == g_dynamic_engine.is_loaded) { - SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Not loaded engine"); - return VCD_ERROR_OPERATION_FAILED; + iter = g_list_first(lang_list); + } } - - g_dynamic_engine.callbacks->private_data_set = callback_func; - - return VCD_ERROR_NONE; } -int vcd_engine_agent_set_private_data_requested_cb(vce_private_data_requested_cb callback_func) +int __log_enginelist() { - if (false == g_agent_init) { - SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Not Initialized"); - return VCD_ERROR_OPERATION_FAILED; - } + GList *iter = NULL; + vcengine_info_s *data = NULL; - if (false == g_dynamic_engine.is_loaded) { - SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Not loaded engine"); - return VCD_ERROR_OPERATION_FAILED; - } + if (0 < g_list_length(g_engine_list)) { - g_dynamic_engine.callbacks->private_data_request = callback_func; + /* Get a first item */ + iter = g_list_first(g_engine_list); - return VCD_ERROR_NONE; -} + SLOG(LOG_DEBUG, TAG_VCD, "@ engine list @"); -int vcd_engine_agent_set_nlu_base_info_requested_cb(vce_nlu_base_info_requested_cb callback_func) -{ - if (false == g_agent_init) { - SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Not Initialized"); - return VCD_ERROR_OPERATION_FAILED; - } + int i = 1; + while (NULL != iter) { + /* Get handle data from list */ + data = iter->data; - if (false == g_dynamic_engine.is_loaded) { - SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Not loaded engine"); - return VCD_ERROR_OPERATION_FAILED; + SLOG(LOG_DEBUG, TAG_VCD, "[%dth]", i); + SLOG(LOG_DEBUG, TAG_VCD, " engine uuid : %s", data->engine_uuid); + SLOG(LOG_DEBUG, TAG_VCD, " engine name : %s", data->engine_name); + SLOG(LOG_DEBUG, TAG_VCD, " engine path : %s", data->engine_path); + iter = g_list_next(iter); + i++; + } + SLOG(LOG_DEBUG, TAG_VCD, "@@@@"); + } else { + SLOG(LOG_DEBUG, TAG_VCD, "@ engine list @"); + SLOG(LOG_DEBUG, TAG_VCD, " No Engine in engine directory"); + SLOG(LOG_DEBUG, TAG_VCD, "@@@@"); } - g_dynamic_engine.callbacks->nlu_base_info_request = callback_func; - - return VCD_ERROR_NONE; + return 0; } - diff --git a/server/vcd_engine_agent.h b/server/vcd_engine_agent.h index 4fa59d8..aac4fc8 100644 --- a/server/vcd_engine_agent.h +++ b/server/vcd_engine_agent.h @@ -19,6 +19,7 @@ #define __VCD_ENGINE_AGENT_H_ #include "vcd_main.h" +#include "voice_control_plugin_engine.h" #ifdef __cplusplus extern "C" { @@ -30,22 +31,48 @@ extern "C" { #define ENGINE_PATH_SIZE 256 +typedef void (*result_callback)(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); + +typedef void (*asr_result_callback)(vcp_asr_result_event_e event, const char* asr_result, void *user_data); + +typedef void (*nlg_result_callback)(const char* nlg_result, void *user_data); + +#if 0 +typedef void (*pre_result_callback)(vcp_pre_result_event_e event, const char* pre_result, void *user_data); + +typedef void (*nlu_result_callback)(vcp_result_event_e event, const char* nlu_result, void *user_data); +#endif + +typedef void (*error_callback)(vcp_error_e error, const char* msg, void *user_data); + +typedef void (*silence_dectection_callback)(void *user_data); + + + /** Init engine agent */ -int vcd_engine_agent_init(); +//int vcd_engine_agent_init(pre_result_callback pre_result_cb, result_callback result_cb, nlu_result_callback nlu_result_cb, error_callback error_cb); +int vcd_engine_agent_init(asr_result_callback asr_result_cb, result_callback result_cb, nlg_result_callback nlg_result_cb, error_callback error_cb); /** Release engine agent */ int vcd_engine_agent_release(); bool vcd_engine_is_available_engine(); +/** Set current engine */ +int vcd_engine_agent_initialize_current_engine(); + /** load current engine */ -int vcd_engine_agent_load_current_engine(vce_request_callback_s* callback); +int vcd_engine_agent_load_current_engine(); /** Unload current engine */ int vcd_engine_agent_unload_current_engine(); +/** test for language list */ +int vcd_print_enginelist(); -int vcd_engine_get_audio_format(const char* audio_id, vce_audio_type_e* types, int* rate, int* channels); + +int vcd_engine_get_audio_format(const char* audio_id, vcp_audio_type_e* types, int* rate, int* channels); int vcd_engine_supported_langs(GList** lang_list); @@ -58,7 +85,7 @@ int vcd_engine_set_commands(); /* normal recognition */ int vcd_engine_recognize_start(bool silence); -int vcd_engine_recognize_audio(const void* data, unsigned int length, vce_speech_detect_e* speech_detected); +int vcd_engine_recognize_audio(const void* data, unsigned int length, vcp_speech_detect_e* speech_detected); int vcd_engine_recognize_stop(); @@ -70,8 +97,10 @@ int vcd_engine_set_domain(int pid, const char* domain); int vcd_engine_get_nlu_base_info(int pid, const char* key, char** value); +// int vcd_engine_set_private_data(const char* data); int vcd_engine_set_private_data(int pid, const char* key, const char* data); +// int vcd_engine_get_private_data(char** data); int vcd_engine_get_private_data(int pid, const char* key, char** data); int vcd_engine_process_text(int pid, const char* text); @@ -80,27 +109,6 @@ int vcd_engine_process_list_event(int pid, const char* event); int vcd_engine_process_haptic_event(int pid, const char* event); -/* for engine service */ -int vcd_engine_agent_get_foreach_command(vce_cmd_h vce_command, vce_command_cb callback, void* user_data); - -int vcd_engine_agent_get_command_count(vce_cmd_h vce_command); - -int vcd_engine_agent_get_audio_type(char** audio_type); - -int vcd_engine_agent_set_private_data(const char* key, const char* data); - -int vcd_engine_agent_get_private_data(const char* key, char** data); - -int vcd_engine_agent_start_recording(); - -int vcd_engine_agent_stop_recording(); - -int vcd_engine_agent_set_private_data_set_cb(vce_private_data_set_cb callback_func); - -int vcd_engine_agent_set_private_data_requested_cb(vce_private_data_requested_cb callback_func); - -int vcd_engine_agent_set_nlu_base_info_requested_cb(vce_nlu_base_info_requested_cb callback_func); - #ifdef __cplusplus } diff --git a/server/vcd_main.c b/server/vcd_main.c new file mode 100755 index 0000000..a1b865a --- /dev/null +++ b/server/vcd_main.c @@ -0,0 +1,75 @@ +/* +* Copyright (c) 2011-2015 Samsung Electronics Co., Ltd All Rights Reserved +* +* Licensed under the Apache License, Version 2.0 (the License); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an AS IS BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + + +#include "vcd_dbus.h" +#include "vcd_main.h" +#include "vcd_server.h" + +#define CLIENT_CLEAN_UP_TIME 500 + +static Ecore_Timer* g_check_client_timer = NULL; + +int main(int argc, char** argv) +{ + SLOG(LOG_DEBUG, TAG_VCD, "@@@ VC Daemon Initialize"); + + if (!ecore_init()) { + SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail ecore_init()"); + return -1; + } + + if (0 != vcd_dbus_open_connection()) { + SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to open connection"); + ecore_shutdown(); + return EXIT_FAILURE; + } + + if (0 != vcd_initialize()) { + SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to initialize vc-daemon"); + ecore_shutdown(); + return EXIT_FAILURE; + } + + g_check_client_timer = ecore_timer_add(CLIENT_CLEAN_UP_TIME, vcd_cleanup_client_all, NULL); + if (NULL == g_check_client_timer) { + SLOG(LOG_WARN, TAG_VCD, "[Main Warning] Fail to create timer of client check"); + } + + SLOG(LOG_DEBUG, TAG_VCD, "[Main] vc-daemon start"); + + SLOG(LOG_DEBUG, TAG_VCD, "@@@"); + + ecore_main_loop_begin(); + + SLOG(LOG_DEBUG, TAG_VCD, "@@@ VC Daemon Finalize"); + + if (NULL != g_check_client_timer) { + ecore_timer_del(g_check_client_timer); + } + + vcd_finalize(); + + vcd_dbus_close_connection(); + + ecore_shutdown(); + + SLOG(LOG_DEBUG, TAG_VCD, "@@@"); + + return 0; +} + + diff --git a/server/vcd_main.h b/server/vcd_main.h index a4e5705..1f83fb9 100644 --- a/server/vcd_main.h +++ b/server/vcd_main.h @@ -31,8 +31,6 @@ #include "vc_defs.h" -#include "vce.h" - #ifdef __cplusplus extern "C" { #endif @@ -72,43 +70,6 @@ typedef enum { VCD_STATE_PROCESSING = 3 } vcd_state_e; -typedef struct { - int version; /**< Version */ - - /* Mandatory callbacks */ - /* Get engine information */ - vce_get_info_cb get_info; /**< Called when the engine service user requests the basic information of VC engine */ - vce_get_recording_format_cb get_recording_format; /**< Get recording format */ - vce_foreach_supported_languages_cb foreach_langs; /**< Foreach language list */ - vce_is_language_supported_cb is_lang_supported; /**< Check language */ - - vce_initialize_cb initialize; /**< Initialize engine */ - vce_deinitialize_cb deinitialize; /**< Shutdown engine */ - - /* Set info */ - vce_set_language_cb set_language; /**< Set language */ - vce_set_commands_cb set_commands; /**< Request to set current commands */ - vce_unset_commands_cb unset_commands; /**< Request to unset current commands */ - - /* Control recognition */ - vce_start_cb start; /**< Start recognition */ - vce_set_recording_data_cb set_recording; /**< Set recording data */ - vce_stop_cb stop; /**< Stop recording for getting result */ - vce_cancel_cb cancel; /**< Cancel recording and processing */ - - vce_set_audio_type set_audio_type; /**< Set audio type */ - - vce_set_domain_cb set_domain; /**< Set domain */ - vce_process_text_cb process_text; /**< Request to process text */ - vce_process_list_event_cb process_list_event; /**< Request to process list event */ - vce_process_haptic_event_cb process_haptic_event; /**< Request to process haptic event */ - - /* Optional callbacks */ - vce_private_data_set_cb private_data_set; - vce_private_data_requested_cb private_data_request; - vce_nlu_base_info_requested_cb nlu_base_info_request; -} vc_engine_callback_s; - #ifdef __cplusplus } diff --git a/server/vcd_recorder.c b/server/vcd_recorder.c index f3194d4..e2bee43 100644 --- a/server/vcd_recorder.c +++ b/server/vcd_recorder.c @@ -38,13 +38,14 @@ #include "vcd_engine_agent.h" #include "vcd_recorder.h" #include "vcd_main.h" +#include "voice_control_plugin_engine.h" #define FRAME_LENGTH 160 #define BUFFER_LENGTH FRAME_LENGTH * 2 #define FOCUS_SERVER_READY "/tmp/.focus_server_ready" -#define VCE_AUDIO_ID_NONE "VC_AUDIO_ID_NONE" /**< None audio id */ +#define VCP_AUDIO_ID_NONE "VC_AUDIO_ID_NONE" /**< None audio id */ static vcd_recorder_state_e g_recorder_state = VCD_RECORDER_STATE_READY; @@ -56,7 +57,7 @@ static audio_in_h g_audio_h; static sound_stream_info_h g_stream_info_h; -static vce_audio_type_e g_audio_type; +static vcp_audio_type_e g_audio_type; static int g_audio_rate; @@ -90,10 +91,10 @@ static float get_volume_decibel(char* data, int size); #ifdef TV_MSF_WIFI_MODE static void __msf_wifi_audio_data_receive_cb(msf_wifi_voice_data_s *voice_data, void* user_data) { - if (0 != strncmp(g_current_audio_type, VCE_AUDIO_ID_WIFI, sizeof(VCE_AUDIO_ID_WIFI))) { + if (0 != strncmp(g_current_audio_type, VCP_AUDIO_ID_MSF, sizeof(VCP_AUDIO_ID_MSF))) { vcd_state_e state = vcd_config_get_service_state(); if (VCD_STATE_READY == state) { - vcd_recorder_set(VCE_AUDIO_ID_WIFI, VCE_AUDIO_TYPE_PCM_S16_LE, 16000, 1); + vcd_recorder_set(VCP_AUDIO_ID_MSF, VCP_AUDIO_TYPE_PCM_S16_LE, 16000, 1); } else { SLOG(LOG_ERROR, TAG_VCD, "[Recorder ERROR] current audio type is (%s)", g_current_audio_type); return; @@ -101,7 +102,7 @@ static void __msf_wifi_audio_data_receive_cb(msf_wifi_voice_data_s *voice_data, } if (VCD_RECORDER_STATE_RECORDING != g_recorder_state) { - SLOG(LOG_WARN, TAG_VCD, "[Recorder] Not start yet, but send audio data vi Wi-Fi"); + SLOG(LOG_WARN, TAG_VCD, "[Recorder] Not start yet, but send audio data vi MSF"); vcd_recorder_start(); } @@ -153,10 +154,10 @@ static void _bt_cb_hid_state_changed(int result, bool connected, const char *rem static void _bt_hid_audio_data_receive_cb(bt_hid_voice_data_s *voice_data, void *user_data) { - if (0 != strncmp(g_current_audio_type, VCE_AUDIO_ID_BLUETOOTH, sizeof(VCE_AUDIO_ID_BLUETOOTH))) { + if (0 != strncmp(g_current_audio_type, VCP_AUDIO_ID_BLUETOOTH, sizeof(VCP_AUDIO_ID_BLUETOOTH))) { vcd_state_e state = vcd_config_get_service_state(); if (VCD_STATE_READY == state) { - vcd_recorder_set(VCE_AUDIO_ID_BLUETOOTH, VCE_AUDIO_TYPE_PCM_S16_LE, 16000, 1); + vcd_recorder_set(VCP_AUDIO_ID_BLUETOOTH, VCP_AUDIO_TYPE_PCM_S16_LE, 16000, 1); } else { SLOG(LOG_ERROR, TAG_VCD, "[Recorder ERROR] current audio type is (%s)", g_current_audio_type); return; @@ -362,7 +363,7 @@ int vcd_recorder_create(vcd_recoder_audio_cb audio_cb, vcd_recorder_interrupt_cb g_is_valid_bt_in = false; g_current_audio_type = NULL; - g_audio_type = VCE_AUDIO_TYPE_PCM_S16_LE; + g_audio_type = VCP_AUDIO_TYPE_PCM_S16_LE; g_audio_rate = 16000; g_audio_channel = 1; @@ -381,8 +382,8 @@ int vcd_recorder_create(vcd_recoder_audio_cb audio_cb, vcd_recorder_interrupt_cb } switch (g_audio_type) { - case VCE_AUDIO_TYPE_PCM_S16_LE: audio_type = AUDIO_SAMPLE_TYPE_S16_LE; break; - case VCE_AUDIO_TYPE_PCM_U8: audio_type = AUDIO_SAMPLE_TYPE_U8; break; + case VCP_AUDIO_TYPE_PCM_S16_LE: audio_type = AUDIO_SAMPLE_TYPE_S16_LE; break; + case VCP_AUDIO_TYPE_PCM_U8: audio_type = AUDIO_SAMPLE_TYPE_U8; break; default: SLOG(LOG_ERROR, TAG_VCD, "[Recorder ERROR] Invalid Audio Type"); return VCD_ERROR_OPERATION_FAILED; @@ -443,10 +444,10 @@ int vcd_recorder_create(vcd_recoder_audio_cb audio_cb, vcd_recorder_interrupt_cb #endif /* Select default audio type */ if (true == g_is_valid_audio_in) { - g_current_audio_type = strdup(VCE_AUDIO_ID_NONE); + g_current_audio_type = strdup(VCP_AUDIO_ID_NONE); } else { if (true == g_is_valid_bt_in) { - g_current_audio_type = strdup(VCE_AUDIO_ID_BLUETOOTH); + g_current_audio_type = strdup(VCP_AUDIO_ID_BLUETOOTH); } else { SLOG(LOG_ERROR, TAG_VCD, "[Recorder ERROR] No valid audio"); return -1; @@ -461,11 +462,11 @@ int vcd_recorder_create(vcd_recoder_audio_cb audio_cb, vcd_recorder_interrupt_cb int vcd_recorder_destroy() { if (VCD_RECORDER_STATE_RECORDING == g_recorder_state) { - if (0 == strncmp(VCE_AUDIO_ID_BLUETOOTH, g_current_audio_type, strlen(VCE_AUDIO_ID_BLUETOOTH))) { + if (0 == strncmp(VCP_AUDIO_ID_BLUETOOTH, g_current_audio_type, strlen(VCP_AUDIO_ID_BLUETOOTH))) { #ifdef TV_BT_MODE bt_hid_unset_audio_data_receive_cb(); #endif - } else if (0 == strncmp(VCE_AUDIO_ID_WIFI, g_current_audio_type, strlen(VCE_AUDIO_ID_WIFI))) { + } else if (0 == strncmp(VCP_AUDIO_ID_MSF, g_current_audio_type, strlen(VCP_AUDIO_ID_MSF))) { #ifdef TV_MSF_WIFI_MODE UnRegisterMSFAudioCallback(); #endif @@ -503,7 +504,7 @@ int vcd_recorder_destroy() return 0; } -int vcd_recorder_set(const char* audio_type, vce_audio_type_e type, int rate, int channel) +int vcd_recorder_set(const char* audio_type, vcp_audio_type_e type, int rate, int channel) { if (NULL == audio_type) { return VCD_ERROR_INVALID_PARAMETER; @@ -523,26 +524,24 @@ int vcd_recorder_set(const char* audio_type, vce_audio_type_e type, int rate, in vcd_engine_set_audio_type(audio_type); if (VCD_RECORDER_STATE_READY != g_recorder_state) { - if (NULL != g_current_audio_type) { - if ((!strncmp(g_current_audio_type, VCE_AUDIO_ID_NONE, strlen(g_current_audio_type)) && - strncmp(audio_type, VCE_AUDIO_ID_BLUETOOTH, strlen(audio_type)) && - strncmp(audio_type, VCE_AUDIO_ID_WIFI, strlen(audio_type))) || - (strncmp(g_current_audio_type, VCE_AUDIO_ID_BLUETOOTH, strlen(g_current_audio_type)) && - strncmp(g_current_audio_type, VCE_AUDIO_ID_WIFI, strlen(g_current_audio_type)) && - strncmp(g_current_audio_type, VCE_AUDIO_ID_NONE, strlen(g_current_audio_type)) && - !strncmp(audio_type, VCE_AUDIO_ID_NONE, strlen(audio_type)))) { - SLOG(LOG_DEBUG, TAG_VCD, "[Recorder] Skip stop recording while Recorder is NOT ready"); - } else { - SLOG(LOG_ERROR, TAG_VCD, "[Recorder ERROR] Recorder is NOT ready"); - vcd_recorder_stop(); - //return VCD_ERROR_INVALID_STATE; - } + if ((!strncmp(g_current_audio_type, VCP_AUDIO_ID_NONE, strlen(g_current_audio_type)) && + strncmp(audio_type, VCP_AUDIO_ID_BLUETOOTH, strlen(audio_type)) && + strncmp(audio_type, VCP_AUDIO_ID_MSF, strlen(audio_type))) || + (strncmp(g_current_audio_type, VCP_AUDIO_ID_BLUETOOTH, strlen(g_current_audio_type)) && + strncmp(g_current_audio_type, VCP_AUDIO_ID_MSF, strlen(g_current_audio_type)) && + strncmp(g_current_audio_type, VCP_AUDIO_ID_NONE, strlen(g_current_audio_type)) && + !strncmp(audio_type, VCP_AUDIO_ID_NONE, strlen(audio_type)))) { + SLOG(LOG_DEBUG, TAG_VCD, "[Recorder] Skip stop recording while Recorder is NOT ready"); + } else { + SLOG(LOG_ERROR, TAG_VCD, "[Recorder ERROR] Recorder is NOT ready"); + vcd_recorder_stop(); + //return VCD_ERROR_INVALID_STATE; } } int ret = -1; /* Check BT audio */ - if (0 == strncmp(VCE_AUDIO_ID_BLUETOOTH, audio_type, strlen(VCE_AUDIO_ID_BLUETOOTH))) { + if (0 == strncmp(VCP_AUDIO_ID_BLUETOOTH, audio_type, strlen(VCP_AUDIO_ID_BLUETOOTH))) { if (false == g_is_valid_bt_in) { SLOG(LOG_ERROR, TAG_VCD, "[Recorder] BT audio is NOT valid"); return VCD_ERROR_OPERATION_REJECTED; @@ -554,7 +553,7 @@ int vcd_recorder_set(const char* audio_type, vce_audio_type_e type, int rate, in } g_current_audio_type = strdup(audio_type); - } else if (0 == strncmp(VCE_AUDIO_ID_WIFI, audio_type, strlen(VCE_AUDIO_ID_WIFI))) { + } else if (0 == strncmp(VCP_AUDIO_ID_MSF, audio_type, strlen(VCP_AUDIO_ID_MSF))) { if (NULL != g_current_audio_type) { free(g_current_audio_type); g_current_audio_type = NULL; @@ -584,8 +583,8 @@ int vcd_recorder_set(const char* audio_type, vce_audio_type_e type, int rate, in } switch (type) { - case VCE_AUDIO_TYPE_PCM_S16_LE: audio_type = AUDIO_SAMPLE_TYPE_S16_LE; break; - case VCE_AUDIO_TYPE_PCM_U8: audio_type = AUDIO_SAMPLE_TYPE_U8; break; + case VCP_AUDIO_TYPE_PCM_S16_LE: audio_type = AUDIO_SAMPLE_TYPE_S16_LE; break; + case VCP_AUDIO_TYPE_PCM_U8: audio_type = AUDIO_SAMPLE_TYPE_U8; break; default: SLOG(LOG_ERROR, TAG_VCD, "[Recorder ERROR] Invalid Audio Type"); return VCD_ERROR_OPERATION_FAILED; @@ -732,11 +731,11 @@ static void __timer_read_normal_func(void *data) static void __check_audio_format() { - vce_audio_type_e type; + vcp_audio_type_e type; int rate; int channel; - int ret = vcd_engine_get_audio_format(VCE_AUDIO_ID_NONE, &type, &rate, &channel); + int ret = vcd_engine_get_audio_format(VCP_AUDIO_ID_NONE, &type, &rate, &channel); if (0 != ret) { SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to get audio format : %d", ret); return; @@ -764,8 +763,8 @@ static void __check_audio_format() } switch (type) { - case VCE_AUDIO_TYPE_PCM_S16_LE: audio_type = AUDIO_SAMPLE_TYPE_S16_LE; break; - case VCE_AUDIO_TYPE_PCM_U8: audio_type = AUDIO_SAMPLE_TYPE_U8; break; + case VCP_AUDIO_TYPE_PCM_S16_LE: audio_type = AUDIO_SAMPLE_TYPE_S16_LE; break; + case VCP_AUDIO_TYPE_PCM_U8: audio_type = AUDIO_SAMPLE_TYPE_U8; break; default: SLOG(LOG_ERROR, TAG_VCD, "[Recorder ERROR] Invalid Audio Type"); return; @@ -806,7 +805,7 @@ int vcd_recorder_start() SLOG(LOG_DEBUG, TAG_VCD, "[Recorder] audio type : %s", g_current_audio_type); if (NULL != g_current_audio_type) { - if (0 == strncmp(VCE_AUDIO_ID_BLUETOOTH, g_current_audio_type, strlen(VCE_AUDIO_ID_BLUETOOTH))) { + if (0 == strncmp(VCP_AUDIO_ID_BLUETOOTH, g_current_audio_type, strlen(VCP_AUDIO_ID_BLUETOOTH))) { #ifdef TV_BT_MODE const unsigned char input_data[2] = {SMART_CONTROL_START_CMD, 0x00}; int bt_retry = 0; @@ -831,7 +830,7 @@ int vcd_recorder_start() g_bt_extend_count = 0; #endif - } else if (0 == strncmp(VCE_AUDIO_ID_WIFI, g_current_audio_type, strlen(VCE_AUDIO_ID_WIFI))) { + } else if (0 == strncmp(VCP_AUDIO_ID_MSF, g_current_audio_type, strlen(VCP_AUDIO_ID_MSF))) { SLOG(LOG_DEBUG, TAG_VCD, "[Recorder] call RegisterMSFAudioCallback() function"); #ifdef TV_MSF_WIFI_MODE @@ -840,7 +839,7 @@ int vcd_recorder_start() if (MSFResult_OK == ret) { started = true; } else { - SLOG(LOG_ERROR, TAG_VCD, "[Recorder ERROR] Fail to start Wi-Fi audio"); + SLOG(LOG_ERROR, TAG_VCD, "[Recorder ERROR] Fail to start MSF(wifi) audio"); return VCD_ERROR_OPERATION_FAILED; } #endif @@ -929,7 +928,7 @@ int vcd_recorder_stop() bool stoped = false; if (NULL != g_current_audio_type) { - if (0 == strncmp(VCE_AUDIO_ID_BLUETOOTH, g_current_audio_type, strlen(VCE_AUDIO_ID_BLUETOOTH))) { + if (0 == strncmp(VCP_AUDIO_ID_BLUETOOTH, g_current_audio_type, strlen(VCP_AUDIO_ID_BLUETOOTH))) { #ifdef TV_BT_MODE int bt_retry = 0; while (5 > bt_retry) { @@ -947,10 +946,10 @@ int vcd_recorder_stop() } } if (NULL != g_current_audio_type && - (!strncmp(g_current_audio_type, VCE_AUDIO_ID_BLUETOOTH, sizeof(VCE_AUDIO_ID_BLUETOOTH)) || - !strncmp(g_current_audio_type, VCE_AUDIO_ID_WIFI, sizeof(VCE_AUDIO_ID_WIFI)))) { + (!strncmp(g_current_audio_type, VCP_AUDIO_ID_BLUETOOTH, sizeof(VCP_AUDIO_ID_BLUETOOTH)) || + !strncmp(g_current_audio_type, VCP_AUDIO_ID_MSF, sizeof(VCP_AUDIO_ID_MSF)))) { SLOG(LOG_DEBUG, TAG_VCD, "[DEBUG] Recorder reset to NONE"); - vcd_recorder_set(VCE_AUDIO_ID_NONE, g_audio_type, g_audio_rate, g_audio_channel); + vcd_recorder_set(VCP_AUDIO_ID_NONE, g_audio_type, g_audio_rate, g_audio_channel); } if (false == stoped) { @@ -958,14 +957,14 @@ int vcd_recorder_stop() return VCD_ERROR_OPERATION_FAILED; } #endif - } else if (0 == strncmp(VCE_AUDIO_ID_WIFI, g_current_audio_type, strlen(VCE_AUDIO_ID_WIFI))) { + } else if (0 == strncmp(VCP_AUDIO_ID_MSF, g_current_audio_type, strlen(VCP_AUDIO_ID_MSF))) { #ifdef TV_MSF_WIFI_MODE UnRegisterMSFAudioCallback(); if (NULL != g_current_audio_type && - (!strncmp(g_current_audio_type, VCE_AUDIO_ID_BLUETOOTH, sizeof(VCE_AUDIO_ID_BLUETOOTH)) || - !strncmp(g_current_audio_type, VCE_AUDIO_ID_WIFI, sizeof(VCE_AUDIO_ID_WIFI)))) { + (!strncmp(g_current_audio_type, VCP_AUDIO_ID_BLUETOOTH, sizeof(VCP_AUDIO_ID_BLUETOOTH)) || + !strncmp(g_current_audio_type, VCP_AUDIO_ID_MSF, sizeof(VCP_AUDIO_ID_MSF)))) { SLOG(LOG_DEBUG, TAG_VCD, "[DEBUG] Recorder reset to NONE"); - vcd_recorder_set(VCE_AUDIO_ID_NONE, g_audio_type, g_audio_rate, g_audio_channel); + vcd_recorder_set(VCP_AUDIO_ID_NONE, g_audio_type, g_audio_rate, g_audio_channel); } stoped = true; #endif diff --git a/server/vcd_recorder.h b/server/vcd_recorder.h index a061d2a..dafef24 100644 --- a/server/vcd_recorder.h +++ b/server/vcd_recorder.h @@ -23,6 +23,7 @@ extern "C" { #endif +#include "voice_control_plugin_engine.h" typedef enum { VCD_RECORDER_STATE_READY, /**< Recorder is ready to start */ @@ -39,7 +40,7 @@ int vcd_recorder_create(vcd_recoder_audio_cb audio_cb, vcd_recorder_interrupt_cb int vcd_recorder_destroy(); -int vcd_recorder_set(const char* audio_type, vce_audio_type_e type, int rate, int channel); +int vcd_recorder_set(const char* audio_type, vcp_audio_type_e type, int rate, int channel); int vcd_recorder_get(char** audio_type); diff --git a/server/vcd_server.c b/server/vcd_server.c index 58d6d7d..4eb3db0 100755 --- a/server/vcd_server.c +++ b/server/vcd_server.c @@ -36,6 +36,8 @@ /* * VC Server static variable */ +static bool g_is_engine; + static GList *g_proc_list = NULL; static Ecore_Timer *g_restart_timer = NULL; @@ -120,7 +122,7 @@ static int __server_recorder_callback(const void* data, const unsigned int lengt return 0; } - vce_speech_detect_e speech_detected = VCE_SPEECH_DETECT_NONE; + vcp_speech_detect_e speech_detected = VCP_SPEECH_DETECT_NONE; int ret; ret = vcd_engine_recognize_audio(data, length, &speech_detected); @@ -130,7 +132,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 (VCE_ERROR_OUT_OF_NETWORK == ret) { + if (VCP_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"); @@ -138,14 +140,14 @@ static int __server_recorder_callback(const void* data, const unsigned int lengt return 0; } - if (VCE_SPEECH_DETECT_BEGIN == speech_detected) { + if (VCP_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 (VCE_SPEECH_DETECT_END == speech_detected) { + } else if (VCP_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); @@ -423,29 +425,30 @@ static Eina_Bool __vcd_send_selected_result(void *data) return EINA_FALSE; } -int vcd_send_asr_result(vce_asr_result_event_e event, const char* asr_result, void *user_data) +//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) { 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; + return; } -int vcd_send_nlg_result(const char* nlg_result, void *user_data) +static void __vcd_server_nlg_result_cb(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; + return; } - SLOG(LOG_ERROR, TAG_VCD, "[Server] send dialog : mgr_pid(%d), nlg_result(%s)", vcd_client_manager_get_pid(), nlg_result); + SECURE_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; + return; } static void* __recorder_stop(void *data) @@ -454,39 +457,30 @@ static void* __recorder_stop(void *data) 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) +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 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_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] 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) { + if (VCP_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) { + 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"); } g_restart_timer = ecore_timer_add(0, __restart_engine, NULL); - return ret; + return; } SLOG(LOG_DEBUG, TAG_VCD, "[Server] Stop recorder due to success"); //vcd_recorder_stop(); @@ -495,14 +489,13 @@ int vcd_send_result(vce_result_event_e event, int* result_id, int count, const c 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) { + if (VCP_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) { + 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"); } - return ret; + return; } } #if 1 @@ -510,6 +503,7 @@ int vcd_send_result(vce_result_event_e event, int* result_id, int count, const c /* 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; @@ -518,7 +512,7 @@ int vcd_send_result(vce_result_event_e event, int* result_id, int count, const c 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; + return; } /* priority filter */ @@ -527,7 +521,7 @@ int vcd_send_result(vce_result_event_e event, int* result_id, int count, const c 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; + return; } int filtered_count = 0; int top_priority = VC_COMMAND_PRIORITY_BACKGROUND; @@ -597,7 +591,7 @@ int vcd_send_result(vce_result_event_e event, int* result_id, int count, const c free(filtered_id); filtered_id = NULL; } - return VCD_ERROR_NONE; + return; } } } @@ -705,7 +699,7 @@ int vcd_send_result(vce_result_event_e event, int* result_id, int count, const c vcd_client_manager_set_exclusive(false); - return VCD_ERROR_NONE; + return; } else { if (false == vcd_client_manager_get_exclusive()) { int pid = vcd_client_widget_get_foreground_pid(); @@ -745,7 +739,7 @@ int vcd_send_result(vce_result_event_e event, int* result_id, int count, const c vc_cmd_list_destroy(vc_cmd_list, true); - return VCD_ERROR_NONE; + return; #else /* No result */ @@ -896,7 +890,7 @@ int vcd_send_result(vce_result_event_e event, int* result_id, int count, const c } #if 0 -static void __vcd_server_nlu_result_cb(vce_result_event_e event, const char* nlu_result, void *user_data) +static void __vcd_server_nlu_result_cb(vcp_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); @@ -910,7 +904,7 @@ static void __vcd_server_nlu_result_cb(vce_result_event_e event, const char* nlu } #endif -int vcd_send_error(vce_error_e error, const char* msg, void *user_data) +static void __vcd_server_error_cb(vcp_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); @@ -929,12 +923,12 @@ int vcd_send_error(vce_error_e error, const char* msg, void *user_data) error_msg = NULL; } - return VCD_ERROR_NONE; + return; } /* -* vcd server Interfaces -*/ + * vcd server Interfaces + */ static void __vcd_file_clean_up() { SLOG(LOG_DEBUG, TAG_VCD, "== Old file clean up == "); @@ -984,7 +978,7 @@ static int __vcd_db_clean_up() return ret; } -int vcd_initialize(vce_request_callback_s *callback) +int vcd_initialize() { int ret = 0; @@ -1005,7 +999,8 @@ int vcd_initialize(vce_request_callback_s *callback) vcd_config_set_service_state(VCD_STATE_NONE); - ret = vcd_engine_agent_init(); + //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); if (0 != ret) { SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to engine agent initialize : result(%d)", ret); return ret; @@ -1016,8 +1011,21 @@ int vcd_initialize(vce_request_callback_s *callback) 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(callback)) { + if (0 != vcd_engine_agent_load_current_engine()) { SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to load current engine"); return VCD_ERROR_OPERATION_FAILED; } @@ -1309,10 +1317,20 @@ int vcd_server_get_foreground() /* -* 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()); @@ -1413,7 +1431,7 @@ int vcd_server_mgr_set_audio_type(int pid, const char* audio_type) } int ret = 0; - vce_audio_type_e type = VCE_AUDIO_TYPE_PCM_S16_LE; + vcp_audio_type_e type = VCP_AUDIO_TYPE_PCM_S16_LE; int rate = 16000; int channel = 1; @@ -1915,13 +1933,25 @@ int vcd_server_mgr_disable_command_type(int pid, int cmd_type) } /* -* 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()) { - SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] No Engine"); - return VCD_ERROR_ENGINE_NOT_FOUND; + if (0 != vcd_engine_agent_initialize_current_engine()) { + SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] No Engine"); + return VCD_ERROR_ENGINE_NOT_FOUND; + } } /* check if pid is valid */ @@ -2220,13 +2250,25 @@ int vcd_server_request_cancel(int 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()) { - SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] No Engine"); - return VCD_ERROR_ENGINE_NOT_FOUND; + if (0 != vcd_engine_agent_initialize_current_engine()) { + SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] No Engine"); + return VCD_ERROR_ENGINE_NOT_FOUND; + } } /* check if pid is valid */ @@ -2429,153 +2471,3 @@ int vcd_server_set_language(const char* language) 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; -} - diff --git a/server/vcd_server.h b/server/vcd_server.h index b328a7e..14fcbd2 100644 --- a/server/vcd_server.h +++ b/server/vcd_server.h @@ -21,8 +21,6 @@ #include "vcd_main.h" #include "vcd_client_data.h" -#include "vce.h" - #ifdef __cplusplus extern "C" { #endif @@ -30,7 +28,7 @@ extern "C" { /* * Daemon functions */ -int vcd_initialize(vce_request_callback_s *callback); +int vcd_initialize(); void vcd_finalize(); @@ -126,38 +124,6 @@ int vcd_server_widget_enable_asr_result(int pid, bool enable); int vcd_server_set_language(const char* language); -/* -* For engine service -*/ -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 vcd_send_asr_result(vce_asr_result_event_e event, const char* asr_result, void *user_data); - -int vcd_send_nlg_result(const char* nlg_result, void *user_data); - -int vcd_send_error(vce_error_e error, const char* msg, void *user_data); - -int vcd_get_foreach_command(vce_cmd_h vce_command, vce_command_cb callback, void* user_data); - -int vcd_get_command_count(vce_cmd_h vce_command); - -int vcd_get_audio_type(char** audio_type); - -int vcd_set_private_data(const char* key, const char* data); - -int vcd_get_private_data(const char* key, char** data); - -int vcd_start_recording(); - -int vcd_stop_recording(); - -int vcd_set_private_data_set_cb(vce_private_data_set_cb callback_func); - -int vcd_set_private_data_requested_cb(vce_private_data_requested_cb callback_func); - -int vcd_set_nlu_base_info_requested_cb(vce_nlu_base_info_requested_cb callback_func); - - #ifdef __cplusplus } #endif diff --git a/server/vce.c b/server/vce.c deleted file mode 100755 index b7fb585..0000000 --- a/server/vce.c +++ /dev/null @@ -1,262 +0,0 @@ -/* -* Copyright (c) 2011-2017 Samsung Electronics Co., Ltd All Rights Reserved -* -* Licensed under the Apache License, Version 2.0 (the License); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an AS IS BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - - -#include "vcd_dbus.h" -#include "vcd_main.h" -#include "vcd_server.h" - -#include "vce.h" - - -int vce_main(int argc, char** argv, vce_request_callback_s *callback) -{ - SLOG(LOG_DEBUG, TAG_VCD, " "); - SLOG(LOG_DEBUG, TAG_VCD, " "); - SLOG(LOG_DEBUG, TAG_VCD, "===== VC Engine Service Initialize"); - - int ret = VCE_ERROR_NONE; - - if (!ecore_init()) { - SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail ecore_init()"); - return VCE_ERROR_OPERATION_FAILED; - } - - if (0 != vcd_dbus_open_connection()) { - SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to open connection"); - ecore_shutdown(); - return VCE_ERROR_OPERATION_FAILED; - } - - ret = vcd_initialize(callback); - if (0 != ret) { - SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to initialize"); - vcd_dbus_close_connection(); - ecore_shutdown(); - return ret; - } - - SLOG(LOG_DEBUG, TAG_VCD, "[Main] VC Engine Service start..."); - - SLOG(LOG_DEBUG, TAG_VCD, "====="); - SLOG(LOG_DEBUG, TAG_VCD, " "); - SLOG(LOG_DEBUG, TAG_VCD, " "); - - return 0; -} - -int vce_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 = VCE_ERROR_NONE; - - if (NULL == all_result || NULL == non_fixed_result || NULL == nlu_result) { - SLOG(LOG_ERROR, TAG_VCD, "[INFO] Input parameter is NULL. (no result)"); - } - - ret = vcd_send_result(event, result_id, count, all_result, non_fixed_result, nlu_result, msg, user_info, user_data); - if (0 != ret) { - SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to send result"); - } else { - SLOG(LOG_INFO, TAG_VCD, "[INFO] Success to send result"); - } - - return ret; -} - - -int vce_send_asr_result(vce_asr_result_event_e event, const char* asr_result, void *user_data) -{ - int ret = VCE_ERROR_NONE; - - if (NULL == asr_result) { - SLOG(LOG_ERROR, TAG_VCD, "[INFO] Input parameter is NULL. (no result)"); - } - - ret = vcd_send_asr_result(event, asr_result, user_data); - if (0 != ret) { - SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to send ASR result"); - } else { - SLOG(LOG_INFO, TAG_VCD, "[INFO] Success to send ASR result"); - } - - return ret; -} - -int vce_send_nlg_result(const char* nlg_result, void *user_data) -{ - int ret = VCE_ERROR_NONE; - - if (NULL == nlg_result) { - SLOG(LOG_ERROR, TAG_VCD, "[INFO] Input parameter is NULL. (no result)"); - } - - ret = vcd_send_nlg_result(nlg_result, user_data); - if (0 != ret) { - SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to send NLG result"); - } else { - SLOG(LOG_INFO, TAG_VCD, "[INFO] Success to send NLG result"); - } - - return ret; -} - -int vce_send_error(vce_error_e error, const char* msg, void *user_data) -{ - int ret = VCE_ERROR_NONE; - - if (NULL == msg) { - SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Input parameter is NULL. (no error message)"); - } - - ret = vcd_send_error(error, msg, user_data); - - if (0 != ret) { - SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to send error"); - } - - return ret; -} - - -/* Daemon API */ -int vce_get_foreach_command(vce_cmd_h vce_command, vce_command_cb callback, void* user_data) -{ - int ret = VCE_ERROR_NONE; - - ret = vcd_get_foreach_command(vce_command, callback, user_data); - if (0 != ret) { - SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to get foreach command"); - } - - return ret; -} - -int vce_get_command_count(vce_cmd_h vce_command) -{ - int ret = VCE_ERROR_NONE; - - ret = vcd_get_command_count(vce_command); - if (0 != ret) { - SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to get command count"); - } - - return ret; -} - -int vce_get_audio_type(char** audio_type) -{ - int ret = VCE_ERROR_NONE; - - ret = vcd_get_audio_type(audio_type); - if (0 != ret) { - SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to get audio type"); - } - - return ret; -} - -int vce_set_private_data(const char* key, const char* data) -{ - int ret = VCE_ERROR_NONE; - - ret = vcd_set_private_data(key, data); - if (0 != ret) { - SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to set private data to vc manager"); - } - - return ret; -} - -int vce_get_private_data(const char* key, char** data) -{ - int ret = VCE_ERROR_NONE; - - ret = vcd_get_private_data(key, data); - if (0 != ret) { - SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to get private data from vc manager"); - } - - return ret; -} - -int vce_start_recording() -{ - int ret = VCE_ERROR_NONE; - - ret = vcd_start_recording(); - if (0 != ret) { - SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to start recording"); - } - - return ret; -} - -int vce_stop_recording() -{ - int ret = VCE_ERROR_NONE; - - ret = vcd_stop_recording(); - if (0 != ret) { - SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to stop recording"); - } - - return ret; -} - -int vce_set_private_data_set_cb(vce_private_data_set_cb callback_func) -{ - if (NULL == callback_func) { - SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Invalid parameter"); - return VCE_ERROR_INVALID_PARAMETER; - } - - int ret = vcd_set_private_data_set_cb(callback_func); - if (0 != ret) { - SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to set private data set cb"); - } - - return ret; -} - -int vce_set_private_data_requested_cb(vce_private_data_requested_cb callback_func) -{ - if (NULL == callback_func) { - SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Invalid parameter"); - return VCE_ERROR_INVALID_PARAMETER; - } - - int ret = vcd_set_private_data_requested_cb(callback_func); - if (0 != ret) { - SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to set private data requested cb"); - } - - return ret; -} - -int vce_set_nlu_base_info_requested_cb(vce_nlu_base_info_requested_cb callback_func) -{ - if (NULL == callback_func) { - SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Invalid parameter"); - return VCE_ERROR_INVALID_PARAMETER; - } - - int ret = vcd_set_nlu_base_info_requested_cb(callback_func); - if (0 != ret) { - SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to set nlu-base info requested cb"); - } - - return ret; -} -- 2.7.4 From 880a660e0157cbb4c63706becc8433f5ee83e747 Mon Sep 17 00:00:00 2001 From: Sooyeon Kim Date: Wed, 7 Mar 2018 02:31:45 +0000 Subject: [PATCH 15/16] Revert "Revert 'Change to support VC downloadable engine (hybrid)' temporarily" This reverts commit f09f22e095ad108d2084e02c511ad5afc3b06369. Change-Id: I9789fba7e110a023168a90249d0b9f703fe6c794 --- include/CMakeLists.txt | 2 +- include/vce.h | 746 +++++++++++++++++++++++++++ include/voice-control-engine.pc.in | 1 + include/voice_control_manager.h | 2 +- include/voice_control_plugin_engine.h | 800 ----------------------------- org.tizen.voice.vcserver.service | 3 +- packaging/voice-control.spec | 5 +- server/CMakeLists.txt | 17 +- server/vcd_client_data.c | 14 +- server/vcd_engine_agent.c | 919 +++++++++------------------------- server/vcd_engine_agent.h | 58 +-- server/vcd_main.c | 75 --- server/vcd_main.h | 39 ++ server/vcd_recorder.c | 95 ++-- server/vcd_recorder.h | 3 +- server/vcd_server.c | 302 +++++++---- server/vcd_server.h | 36 +- server/vce.c | 262 ++++++++++ 18 files changed, 1629 insertions(+), 1750 deletions(-) create mode 100755 include/vce.h delete mode 100755 include/voice_control_plugin_engine.h delete mode 100755 server/vcd_main.c create mode 100755 server/vce.c diff --git a/include/CMakeLists.txt b/include/CMakeLists.txt index 7d0db51..84fd0df 100644 --- a/include/CMakeLists.txt +++ b/include/CMakeLists.txt @@ -21,6 +21,6 @@ INSTALL(FILES ${CMAKE_BINARY_DIR}/include/voice_control_command_expand.h DESTINA INSTALL(FILES ${CMAKE_BINARY_DIR}/include/voice_control_common.h DESTINATION ${INCLUDEDIR}) INSTALL(FILES ${CMAKE_BINARY_DIR}/include/voice_control_key_defines.h DESTINATION ${INCLUDEDIR}) INSTALL(FILES ${CMAKE_BINARY_DIR}/include/voice_control_manager.h DESTINATION ${INCLUDEDIR}) -INSTALL(FILES ${CMAKE_BINARY_DIR}/include/voice_control_plugin_engine.h DESTINATION ${INCLUDEDIR}) INSTALL(FILES ${CMAKE_BINARY_DIR}/include/voice_control_setting.h DESTINATION ${INCLUDEDIR}) INSTALL(FILES ${CMAKE_BINARY_DIR}/include/voice_control_widget.h DESTINATION ${INCLUDEDIR}) +INSTALL(FILES ${CMAKE_BINARY_DIR}/include/vce.h DESTINATION ${INCLUDEDIR}) diff --git a/include/vce.h b/include/vce.h new file mode 100755 index 0000000..a921cd1 --- /dev/null +++ b/include/vce.h @@ -0,0 +1,746 @@ +/* +* Copyright (c) 2011-2017 Samsung Electronics Co., Ltd All Rights Reserved +* +* Licensed under the Apache License, Version 2.0 (the License); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an AS IS BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + + +#ifndef __VCE_H__ +#define __VCE_H__ + +#include + +/** +* @addtogroup CAPI_UIX_VCE_MODULE +* @{ +*/ + +#ifdef __cplusplus +extern "C" { +#endif + +/** +* @brief Enumerations of error codes. +* @since_tizen 5.0 +*/ +typedef enum { + VCE_ERROR_NONE = TIZEN_ERROR_NONE, /**< Successful */ + VCE_ERROR_OUT_OF_MEMORY = TIZEN_ERROR_OUT_OF_MEMORY, /**< Out of Memory */ + VCE_ERROR_IO_ERROR = TIZEN_ERROR_IO_ERROR, /**< I/O error */ + VCE_ERROR_INVALID_PARAMETER = TIZEN_ERROR_INVALID_PARAMETER,/**< Invalid parameter */ + VCE_ERROR_OUT_OF_NETWORK = TIZEN_ERROR_NETWORK_DOWN, /**< Out of network */ + VCE_ERROR_INVALID_STATE = TIZEN_ERROR_VOICE_CONTROL | 0x011, /**< Invalid state */ + VCE_ERROR_INVALID_LANGUAGE = TIZEN_ERROR_VOICE_CONTROL | 0x012, /**< Invalid language */ + VCE_ERROR_OPERATION_FAILED = TIZEN_ERROR_VOICE_CONTROL | 0x014, /**< Operation failed */ + VCE_ERROR_NOT_SUPPORTED_FEATURE = TIZEN_ERROR_VOICE_CONTROL | 0x022 /**< Not supported feature of current engine */ +} vce_error_e; + +/** +* @brief Enumerations of audio type. +* @since_tizen 5.0 +*/ +typedef enum { + VCE_AUDIO_TYPE_PCM_S16_LE = 0, /**< Signed 16bit audio type, Little endian */ + VCE_AUDIO_TYPE_PCM_U8 /**< Unsigned 8bit audio type */ +} vce_audio_type_e; + +/** +* @brief Enumerations of callback event. +* @since_tizen 5.0 +*/ +typedef enum { + VCE_RESULT_EVENT_SUCCESS = 0, /**< Event when the recognition full result is ready */ + VCE_RESULT_EVENT_REJECTED, /**< Event when the recognition result is rejected */ + VCE_RESULT_EVENT_ERROR /**< Event when the recognition has failed */ +} vce_result_event_e; + +/** +* @brief Enumerations of command type. +* @since_tizen 5.0 +*/ +typedef enum { + VCE_COMMAND_FORMAT_FIXED = 0, /**< Fixed command */ + VCE_COMMAND_FORMAT_FIXED_AND_VFIXED, /**< Fixed command + variable-fixed command */ + VCE_COMMAND_FORMAT_VFIXED_AND_FIXED, /**< variable-fixed command + Fixed command */ + VCE_COMMAND_FORMAT_FIXED_AND_NONFIXED, /**< Fixed command + Non-fixed command */ + VCE_COMMAND_FORMAT_NONFIXED_AND_FIXED, /**< Non-fixed command + Fixed command */ + VCE_COMMAND_FORMAT_ACTION, + VCE_COMMAND_FORMAT_PARTIAL +} vce_command_format_e; + +/** +* @brief Definition for foreground command type. +* @since_tizen 5.0 +*/ +#define VCE_COMMAND_TYPE_FOREGROUND 1 + +/** +* @brief Definition for background command type. +* @since_tizen 5.0 +*/ +#define VCE_COMMAND_TYPE_BACKGROUND 2 + +/** +* @brief Definition for widget command type. +* @since_tizen 5.0 +*/ +#define VCE_COMMAND_TYPE_WIDGET 3 + +/** +* @brief Definition for system command type. +* @since_tizen 5.0 +*/ +#define VCE_COMMAND_TYPE_SYSTEM 4 + +/** +* @brief Definition for system background command type. +* @since_tizen 5.0 +*/ +#define VCE_COMMAND_TYPE_SYSTEM_BACKGROUND 5 + +/** +* @brief Definitions for exclusive command type. +* @since_tizen 5.0 +*/ +#define VCE_COMMAND_TYPE_EXCLUSIVE 6 + + +/** +* @brief Enumerations of speech detect. +* @since_tizen 5.0 +*/ +typedef enum { + VCE_SPEECH_DETECT_NONE = 0, /**< No event */ + VCE_SPEECH_DETECT_BEGIN, /**< Begin of speech detected */ + VCE_SPEECH_DETECT_END, /**< End of speech detected */ +} vce_speech_detect_e; + +/** +* @brief Enumerations of ASR result events +* @since_tizen 5.0 +*/ +typedef enum { + VCE_ASR_RESULT_EVENT_FINAL_RESULT = 0, + VCE_ASR_RESULT_EVENT_PARTIAL_RESULT, + VCE_ASR_RESULT_EVENT_ERROR +} vce_asr_result_event_e; + +/** +* @brief A structure of handle for VC command +* @since_tizen 5.0 +*/ +typedef int vce_cmd_h; + +/** +* @brief Definition of bluetooth audio id. +* @since_tizen 5.0 +*/ +#define VCE_AUDIO_ID_BLUETOOTH "VC_AUDIO_ID_BLUETOOTH" /**< Bluetooth audio id */ + +/** +* @brief Definition of Wi-Fi audio id. +* @since_tizen 5.0 +*/ +#define VCE_AUDIO_ID_WIFI "VC_AUDIO_ID_WIFI" /**< Wi-Fi audio id */ + +/** +* @brief Definition for none message. +*/ +#define VC_RESULT_MESSAGE_NONE "vc.result.message.none" + +/** +* @brief Definition for failed recognition because the speech is too loud to listen. +*/ +#define VC_RESULT_MESSAGE_ERROR_TOO_LOUD "vc.result.message.error.too.loud" + + + +/** +* @brief Called when VC engine informs the engine service user about whole supported languages. +* @details This callback function is implemented by the engine service user. Therefore, the engine developer does NOT have to implement this callback function. +* @since_tizen 5.0 +* @remarks This callback function is called by vce_foreach_supported_languages_cb() to retrieve the whole supported language list. +* @a user_data must be transferred from vce_foreach_supported_languages_cb(). +* +* @param[in] language A language is specified as an ISO 3166 alpha-2 two letter country-code +* followed by ISO 639-1 for the two-letter language code \n +* For example, "ko_KR" for Korean, "en_US" for American English +* @param[in] user_data The user data passed from the foreach function +* +* @return @c true to continue with the next iteration of the loop \n @c false to break out of the loop +* +* @pre vce_foreach_supported_languages() will invoke this callback. +* +* @see vce_foreach_supported_languages() +*/ +typedef bool (*vce_supported_language_cb)(const char* language, void* user_data); + +/** +* @brief Called when the engine service user initializes VC engine. +* @since_tizen 5.0 +* @remarks This callback function is mandatory and must be registered using vce_main(). +* +* @return 0 on success, otherwise a negative error value +* @retval #VCE_ERROR_NONE Successful +* @retval #VCE_ERROR_INVALID_PARAMETER Invalid parameter +* @retval #VCE_ERROR_INVALID_STATE Already initialized +* @retval #VCE_ERROR_OPERATION_FAILED Operation failed +* +* @see vce_deinitialize_cb() +*/ +typedef int (*vce_initialize_cb)(void); + +/** +* @brief Called when the engine service user deinitializes VC engine +* @since_tizen 5.0 +* @remarks This callback function is mandatory and must be registered using vce_main(). +* +* @return 0 on success, otherwise a negative error value +* @retval #VCE_ERROR_NONE Successful +* @retval #VCE_ERROR_INVALID_STATE Not initialized +* +* @see vce_initialize_cb() +*/ +typedef int (*vce_deinitialize_cb)(void); + +/** +* @brief Called when the engine service user requests the recording format of VC engine. +* +* @param[in] audio_id The audio device id. +* @param[out] types The format used by the recorder. +* @param[out] rate The sample rate used by the recorder. +* @param[out] channels The number of channels used by the recorder. +* +* @return 0 on success, otherwise a negative error value +* @retval #VCE_ERROR_NONE Successful +* @retval #VCE_ERROR_INVALID_PARAMETER Not initialized +*/ +typedef int (*vce_get_recording_format_cb)(const char* audio_id, vce_audio_type_e* types, int* rate, int* channels); + +/** +* @brief Called when the engine service user retrieves all supported languages of VC engine. +* +* @param[in] callback a callback function +* @param[in] user_data The user data to be passed to the callback function +* +* @return 0 on success, otherwise a negative error value +* @retval #VCE_ERROR_NONE Successful +* @retval #VCE_ERROR_INVALID_PARAMETER Invalid parameter +* @retval #VCE_ERROR_INVALID_STATE Not initialized +* +* @post This function invokes vce_supported_language_cb() repeatedly for getting supported languages. +* +* @see vce_supported_language_cb() +*/ +typedef int (*vce_foreach_supported_languages_cb)(vce_supported_language_cb callback, void* user_data); + +/** +* @brief Called when the engine service user checks whether a language is supported or not. +* +* @param[in] language A language +* +* @return @c true = supported, \n @c false = not supported. +*/ +typedef bool (*vce_is_language_supported_cb)(const char* language); + +/** +* @brief Called when the engine service user sets language. +* +* @param[in] language A language. +* +* @return 0 on success, otherwise a negative error value +* @retval #VCE_ERROR_NONE Successful +* @retval #VCE_ERROR_INVALID_LANGUAGE Invalid language +* @retval #VCE_ERROR_INVALID_STATE Not initialized +*/ +typedef int (*vce_set_language_cb)(const char* language); + +/** +* @brief Called when the engine service user sets command list before recognition. +* +* @remark This function should set commands via vcd_foreach_command(). +* +* @param[in] vc_command command handle. +* +* @return 0 on success, otherwise a negative error value +* @retval #VCE_ERROR_NONE Successful +* @retval #VCE_ERROR_INVALID_PARAMETER Invalid parameter +* @retval #VCE_ERROR_INVALID_STATE Invalid state +* @retval #VCE_ERROR_OPERATION_FAILED Operation failed +* @retval #VCE_ERROR_NOT_SUPPORTED_FEATURE Not supported command type +* +* @post vce_start() is called after this function is successful. +* +* @see vce_start() +* @see vcd_foreach_command() +* @see vce_unset_commands() +*/ +typedef int (*vce_set_commands_cb)(vce_cmd_h vc_command); + +/** +* @brief Called when the engine service user unsets command list for reset. +* +* @return 0 on success, otherwise a negative error value +* @retval #VCE_ERROR_NONE Successful +* @retval #VCE_ERROR_INVALID_PARAMETER Invalid parameter +* @retval #VCE_ERROR_INVALID_STATE Invalid state +* @retval #VCE_ERROR_OPERATION_FAILED Operation failed +* +* @see vce_set_commands() +*/ +typedef int (*vce_unset_commands_cb)(); + +/** +* @brief Called when the engine service user starts recognition. +* +* @return 0 on success, otherwise a negative error value +* @retval #VCE_ERROR_NONE Successful +* @retval #VCE_ERROR_INVALID_PARAMETER Invalid parameter +* @retval #VCE_ERROR_INVALID_STATE Invalid state +* @retval #VCE_ERROR_INVALID_LANGUAGE Invalid language +* @retval #VCE_ERROR_OUT_OF_NETWORK Out of network +* @retval #VCE_ERROR_OPERATION_FAILED Operation failed +* +* @pre vcd_foreach_command() is successful. +* +* @see vce_set_recording_data() +* @see vce_stop() +* @see vce_cancel() +*/ +typedef int (*vce_start_cb)(bool stop_by_silence); + +/** +* @brief Called when the engine service user sets recording data for speech recognition from recorder. +* +* @remark This function should be returned immediately after recording data copy. +* +* @param[in] data A recording data +* @param[in] length A length of recording data +* @param[out] silence_detected @c true Silence detected \n @c false No silence detected +* +* @return 0 on success, otherwise a negative error value +* @retval #VCE_ERROR_NONE Successful +* @retval #VCE_ERROR_INVALID_PARAMETER Invalid parameter +* @retval #VCE_ERROR_INVALID_STATE Invalid state +* @retval #VCE_ERROR_OPERATION_FAILED Operation failed +* +* @pre vce_start() is successful. +* +* @see vce_start() +* @see vce_cancel() +* @see vce_stop() +*/ +typedef int(*vce_set_recording_data_cb)(const void* data, unsigned int length, vce_speech_detect_e* speech_detected); + +/** +* @brief Called when the engine service user stops to get the result of recognition. +* +* @return 0 on success, otherwise a negative error value +* @retval #VCE_ERROR_NONE Successful +* @retval #VCE_ERROR_INVALID_STATE Invalid state +* @retval #VCE_ERROR_OPERATION_FAILED Operation failed +* @retval #VCE_ERROR_OUT_OF_NETWORK Out of network +* +* @pre vce_set_recording_data() is successful. +* +* @see vce_start() +* @see vce_set_recording_data() +* @see vce_result_cb() +* @see vce_cancel() +*/ +typedef int (*vce_stop_cb)(void); + +/** +* @brief Called when the engine service user cancels the recognition process. +* +* @return 0 on success, otherwise a negative error value. +* @retval #VCE_ERROR_NONE Successful. +* @retval #VCE_ERROR_INVALID_STATE Invalid state. +* +* @pre vce_start() is successful. +* +* @see vce_start() +* @see vce_stop() +*/ +typedef int (*vce_cancel_cb)(void); + +/** +* @brief Set audio recording type. +* +* @return 0 on success, otherwise a negative error value. +* @retval #VCE_ERROR_NONE Successful. +* +*/ +typedef int (*vce_set_audio_type)(const char* audio); + + +/** +* @brief Called when the engine service user sets domain (Agent or device type) +* +* @param[in] domain Available agent or device type +* +* @return 0 on success, otherwise a negative error value. +* +*/ +typedef int (*vce_set_domain_cb)(const char* domain); + +/** +* @brief Called when the engine service user requests essential value from nlu result. +* @since_tizen 5.0 +* @remarks This function is available inside vce_nlu_result_cb() +* +* @param[in] key NLU base info key +* @parma[out] value NLU base info value +* +* @return 0 on success, otherwise a negative error value. +* +*/ +typedef int (*vce_nlu_base_info_requested_cb)(const char* key, char** value); + +/** +* @brief Called when the engine service user sets private data between app and engine. +* +* @param[in] key Private key +* @param[in] data Private data +* +* @return 0 on success, otherwise a negative error value. +* +*/ +typedef int (*vce_private_data_set_cb)(const char* key, const char* data); + +/** +* @brief Called when the engine service user requests private data between app and engine. +* +* @param[in] key Private key +* @param[out] data Private data +* +* @return 0 on success, otherwise a negative error value. +* +*/ +typedef int (*vce_private_data_requested_cb)(const char* key, char** data); + +/** +* @brief Called when the engine service user requests process text. +* +* @param[in] text Requested text +* +* @return 0 on success, otherwise a negative error value. +* +*/ +typedef int (*vce_process_text_cb)(const char* text); + +/** +* @brief Called when the engine service user requests list event. +* +* @param[in] event Requested list event +* +* @return 0 on success, otherwise a negative error value. +* +*/ +typedef int (*vce_process_list_event_cb)(const char* event); + +/** +* @brief Called when the engine service user requests haptic event. +* +* @param[in] event Requested haptic event +* +* @return 0 on success, otherwise a negative error value. +* +*/ +typedef int (*vce_process_haptic_event_cb)(const char* event); + +/** +* @brief Called when the engine service user requests the base information of VC engine. +* @since_tizen 5.0 +* +* @param[out] engine_uuid The engine id +* @param[out] engine_name The engine name +* @param[out] engine_setting The setting path name +* @param[out] use_network @c true to need network @c false not to need network. +*/ +typedef int (*vce_get_info_cb)(char** engine_uuid, char** engine_name, char** engine_setting, bool* use_network); + + +/** +* Daemon API. +*/ + +/** +* @brief Called to retrieve the commands. +* +* @param[in] id command id +* @param[in] type command type +* @param[in] format command format +* @param[in] command command text +* @param[in] param parameter text +* @param[in] domain command domain +* @param[in] user_data The user data passed from the foreach function +* +* @return @c true to continue with the next iteration of the loop, \n @c false to break out of the loop. +* @pre vce_get_foreach_command() will invoke this callback. +* +* @see vce_get_foreach_command() +*/ +typedef bool (*vce_command_cb)(int id, int type, int format, const char* command, const char* param, int domain, void* user_data); + +/** +* @brief Retrieves all commands using callback function. +* +* @param[in] vce_command The handle to be passed to the vce_set_commands() function +* @param[in] callback The callback function to invoke +* @param[in] user_data The user data to be passed to the callback function +* +* @return 0 on success, otherwise a negative error value +* @retval #VCE_ERROR_NONE Successful +* @retval #VCE_ERROR_INVALID_PARAMETER Invalid parameter +* @retval #VCE_ERROR_OPERATION_FAILED Operation failure +* @retval #VCE_ERROR_INVALID_STATE Invalid state +* +* @post This function invokes vce_command_cb() repeatedly for getting commands. +* +* @see vce_foreach_command_cb() +* @see vce_set_commands() +*/ +int vce_get_foreach_command(vce_cmd_h vce_command, vce_command_cb callback, void* user_data); + +/** +* @brief Gets command length. +* +* @param[in] vce_command The handle to be passed to the vce_set_commands() function +* +* @return the value greater than 0 on success, otherwise a negative error value +* +* @see vce_set_commands() +*/ +int vce_get_command_count(vce_cmd_h vce_command); + +/** +* @brief Gets current audio type. +* +* @remarks audio_type must be released using free() when it is no longer required. +* +* @param[in] audio_type Current audio type (e.g. #VCE_AUDIO_ID_BLUETOOTH or usb device id) +* +* @return the value greater than 0 on success, otherwise a negative error value +* +*/ +int vce_get_audio_type(char** audio_type); + +/** +* @brief Sets private data to Manager client. +* +* @param[in] key Private key +* @param[in] data Private data +* +* @return 0 on success, otherwise a negative error value. +* +*/ +int vce_set_private_data(const char* key, const char* data); + +/** +* @brief Gets private data from Manager client. +* +* @param[in] key Private key +* @param[out] data Private data +* +* @return 0 on success, otherwise a negative error value. +* +*/ +int vce_get_private_data(const char* key, char** data); + +/** +* @brief Request start recording. +* +* @return 0 on success, otherwise a negative error value. +* +*/ +int vce_start_recording(); + +/** +* @brief Request stop recording. +* +* @return 0 on success, otherwise a negative error value. +* +*/ +int vce_stop_recording(); + + +/** +* @brief A structure for the VC engine functions. +* @details This structure contains essential callback functions for operating VC engine. +* @since_tizen 5.0 +* @remarks These functions ar mandatory for operating VC engine. Therefore, all functions MUST be implemented. +*/ +typedef struct { + int version; /**< Version */ + + /* Get engine information */ + vce_get_info_cb get_info; /**< Called when the engine service user requests the basic information of VC engine */ + vce_get_recording_format_cb get_recording_format; /**< Get recording format */ + vce_foreach_supported_languages_cb foreach_langs; /**< Foreach language list */ + vce_is_language_supported_cb is_lang_supported; /**< Check language */ + + vce_initialize_cb initialize; /**< Initialize engine */ + vce_deinitialize_cb deinitialize; /**< Shutdown engine */ + + /* Set info */ + vce_set_language_cb set_language; /**< Set language */ + vce_set_commands_cb set_commands; /**< Request to set current commands */ + vce_unset_commands_cb unset_commands; /**< Request to unset current commands */ + + /* Control recognition */ + vce_start_cb start; /**< Start recognition */ + vce_set_recording_data_cb set_recording; /**< Set recording data */ + vce_stop_cb stop; /**< Stop recording for getting result */ + vce_cancel_cb cancel; /**< Cancel recording and processing */ + + vce_set_audio_type set_audio_type; /**< Set audio type */ + + vce_set_domain_cb set_domain; /**< Set domain */ + vce_process_text_cb process_text; /**< Request to process text */ + vce_process_list_event_cb process_list_event; /**< Request to process list event */ + vce_process_haptic_event_cb process_haptic_event; /**< Request to process haptic event */ +} vce_request_callback_s; + +/** +* @brief Loads the engine. +* +* @param[in] argc The argument count(original) +* @param[in] argv The argument(original) +* @param[in] callback The structure of engine request callback function +* +* @return This function returns zero on success, or negative with error code on failure +* @retval #VCE_ERROR_NONE Successful +* @retval #VCE_ERROR_INVALID_PARAMETER Invalid parameter +* @retval #VCE_ERROR_OPERATION_FAILED Operation failed +* +* @pre The vce_get_engine_info() should be successful. +* @post The daemon calls engine functions of vce_funcs_s. +* +* @see vce_get_engine_info() +* @see vce_unload_engine() +*/ +int vce_main(int argc, char** argv, vce_request_callback_s *callback); + + +/** +* @brief Sends the results to the engine service user. +* @since_tizen 5.0 +* +* @param[in] event A result event +* @param[in] result_id Result ids +* @param[in] count Result count +* @param[in] all_result All result text +* @param[in] non_fixed_result Non-fixed command result text +* @param[in] nlu_result NLU result text +* @param[in] msg Engine message (e.g. #VC_RESULT_MESSAGE_NONE, #VC_RESULT_MESSAGE_ERROR_TOO_LOUD) +* @param[out] user_info A user info (e.g. If ASR result is consumed, the value is 0x01. If not, the value is 0x00.) +* @param[in] user_data The user data passed from set callback function +* +* @pre The vce_main() function should be invoked before this function is called. +* vce_stop_cb() will invoke this callback. +* +* @see vce_stop_cb() +*/ +int vce_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); + +/** +* @brief Sends the ASR result to the engine service user. +* @since_tizen 5.0 +* +* @param[in] event A asr result event +* @param[in] asr_result A asr result text +* @param[in] user_data The user data passed from the start +* +* @pre The vce_main() function should be invoked before this function is called. +*/ +int vce_send_asr_result(vce_asr_result_event_e event, const char* asr_result, void *user_data); + +/** +* @brief Called when the daemon gets nlg(natural language generation) result. +* +* @param[in] nlg_result A nlg result +* @param[in] user_data The user data passed from the start +*/ +int vce_send_nlg_result(const char* nlg_result, void *user_data); + +/** +* @brief Sends the error to the engine service user. +* @details The following error codes can be delivered. +* #VCE_ERROR_NONE, +* #VCE_ERROR_OUT_OF_MEMORY, +* #VCE_ERROR_IO_ERROR, +* #VCE_ERROR_INVALID_PARAMETER, +* #VCE_ERROR_OUT_OF_NETWORK, +* #VCE_ERROR_INVALID_STATE, +* #VCE_ERROR_INVALID_LANGUAGE, +* #VCE_ERROR_OPERATION_FAILED, +* #VCE_ERROR_NOT_SUPPORTED_FEATURE. +* @since_tizen 5.0 +* +* @param[in] error Error type +* @param[in] msg Error message +* @param[in] user_data The user data passed from set callback function +* +* @pre The vce_main() function should be invoked before this function is called. +*/ +int vce_send_error(vce_error_e error, const char* msg, void *user_data); + +/** +* @brief Sets a callback function for setting the private data to the engine service. +* @since_tizen 5.0 +* @remarks The vce_private_data_set_cb() function is called when the engine service user sets the private data to the engine service. +* +* @param[in] callback_func vce_private_data_set event callback function +* @return +* +* @see vce_private_data_set_cb() +*/ +int vce_set_private_data_set_cb(vce_private_data_set_cb callback_func); + +/** +* @brief Sets a callback function for requesting the private data to the engine service. +* @since_tizen 5.0 +* @remarks The vce_private_data_requested_cb() function is called when the engine service user requests the private data to the engine service. +* +* @param[in] callback_func vce_private_data_requested event callback function +* @return +* +* @see vce_private_data_requested_cb() +*/ +int vce_set_private_data_requested_cb(vce_private_data_requested_cb callback_func); + +/** +* @brief Sets a callback function for requesting the NLU base information to the engine service. +* @since_tizen 5.0 +* @remarks The vce_nlu_base_info_requested_cb() function is called when the engine service user requests the NLU base information to the engine service. +* +* @param[in] callback_func vce_nlu_base_info_requested event callback function +* @return +* +* @see vce_nlu_base_info_requested_cb() +*/ +int vce_set_nlu_base_info_requested_cb(vce_nlu_base_info_requested_cb callback_func); + + +#ifdef __cplusplus +} +#endif + +/** +* @}@} +*/ + +#endif /* __VCE_H__ */ + + diff --git a/include/voice-control-engine.pc.in b/include/voice-control-engine.pc.in index 7808dfb..d089851 100644 --- a/include/voice-control-engine.pc.in +++ b/include/voice-control-engine.pc.in @@ -7,4 +7,5 @@ Name: lib@PROJECT_NAME@_engine Description: Voice control engine header Requires: glib-2.0 dbus-1 capi-base-common Version: @VERSION@ +Libs: -L${libdir} -l@PROJECT_NAME@_engine Cflags: -I${includedir} diff --git a/include/voice_control_manager.h b/include/voice_control_manager.h index 92701b9..eb0055b 100644 --- a/include/voice_control_manager.h +++ b/include/voice_control_manager.h @@ -41,7 +41,7 @@ extern "C" /** * @brief Definition of Wi-Fi audio-in type. */ -#define VC_AUDIO_TYPE_MSF "VC_AUDIO_ID_MSF" /**< MSF (wifi) audio type */ +#define VC_AUDIO_TYPE_WIFI "VC_AUDIO_ID_WIFI" /**< Wi-Fi audio type */ /** * @brief Definition for foreground command type. diff --git a/include/voice_control_plugin_engine.h b/include/voice_control_plugin_engine.h deleted file mode 100755 index 8b13471..0000000 --- a/include/voice_control_plugin_engine.h +++ /dev/null @@ -1,800 +0,0 @@ -/* -* Copyright (c) 2011-2015 Samsung Electronics Co., Ltd All Rights Reserved -* -* Licensed under the Apache License, Version 2.0 (the License); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an AS IS BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - - -#ifndef __VOICE_CONTROL_PLUGIN_ENGINE_H__ -#define __VOICE_CONTROL_PLUGIN_ENGINE_H__ - -#include - -/** -* @addtogroup VOICE_CONTROL_PLUGIN_ENGINE -* @{ -*/ - -#ifdef __cplusplus -extern "C" { -#endif - -/** -* @brief Enumerations of error codes. -*/ -typedef enum { - VCP_ERROR_NONE = TIZEN_ERROR_NONE, /**< Successful */ - VCP_ERROR_OUT_OF_MEMORY = TIZEN_ERROR_OUT_OF_MEMORY, /**< Out of Memory */ - VCP_ERROR_IO_ERROR = TIZEN_ERROR_IO_ERROR, /**< I/O error */ - VCP_ERROR_INVALID_PARAMETER = TIZEN_ERROR_INVALID_PARAMETER,/**< Invalid parameter */ - VCP_ERROR_OUT_OF_NETWORK = TIZEN_ERROR_NETWORK_DOWN, /**< Out of network */ - VCP_ERROR_INVALID_STATE = -0x0100031, /**< Invalid state */ - VCP_ERROR_INVALID_LANGUAGE = -0x0100032, /**< Invalid language */ - VCP_ERROR_OPERATION_FAILED = -0x0100034, /**< Operation failed */ - VCP_ERROR_NOT_SUPPORTED_FEATURE = -0x0100035 /**< Not supported feature */ -} vcp_error_e; - -/** -* @brief Enumerations of audio type. -*/ -typedef enum { - VCP_AUDIO_TYPE_PCM_S16_LE = 0, /**< Signed 16bit audio type, Little endian */ - VCP_AUDIO_TYPE_PCM_U8 /**< Unsigned 8bit audio type */ -} vcp_audio_type_e; - -/** -* @brief Enumerations of callback event. -*/ -typedef enum { - VCP_RESULT_EVENT_SUCCESS = 0, /**< Event when the recognition full result is ready */ - VCP_RESULT_EVENT_REJECTED, /**< Event when the recognition result is rejected */ - VCP_RESULT_EVENT_ERROR /**< Event when the recognition has failed */ -} vcp_result_event_e; - -/** -* @brief Enumerations of command type. -*/ -typedef enum { - VCP_COMMAND_FORMAT_FIXED = 0, /**< Fixed command */ - VCP_COMMAND_FORMAT_FIXED_AND_VFIXED, /**< Fixed command + variable-fixed command */ - VCP_COMMAND_FORMAT_VFIXED_AND_FIXED, /**< variable-fixed command + Fixed command */ - VCP_COMMAND_FORMAT_FIXED_AND_NONFIXED, /**< Fixed command + Non-fixed command */ - VCP_COMMAND_FORMAT_NONFIXED_AND_FIXED, /**< Non-fixed command + Fixed command */ - VCP_COMMAND_FORMAT_ACTION, - VCP_COMMAND_FORMAT_PARTIAL -} vcp_command_format_e; - -/** -* @brief Definition for foreground command type. -* @since_tizen @if MOBILE 2.4 @elseif WEARABLE 3.0 @endif -*/ -#define VCP_COMMAND_TYPE_FOREGROUND 1 - -/** -* @brief Definition for background command type. -* @since_tizen @if MOBILE 2.4 @elseif WEARABLE 3.0 @endif -*/ -#define VCP_COMMAND_TYPE_BACKGROUND 2 - -/** -* @brief Definition for widget command type. -* @since_tizen @if MOBILE 2.4 @elseif WEARABLE 3.0 @endif -*/ -#define VCP_COMMAND_TYPE_WIDGET 3 - -/** -* @brief Definition for system command type. -* @since_tizen @if MOBILE 2.4 @elseif WEARABLE 3.0 @endif -*/ -#define VCP_COMMAND_TYPE_SYSTEM 4 - -/** -* @brief Definition for exclusive command type. -* @since_tizen @if MOBILE 2.4 @elseif WEARABLE 3.0 @endif -*/ -#define VCP_COMMAND_TYPE_SYSTEM_BACKGROUND 5 - -/** -* @brief Definitions for exclusive command type. -* @since_tizen 2.4 -*/ -#define VCP_COMMAND_TYPE_EXCLUSIVE 6 - - -/** -* @brief Enumerations of speech detect. -*/ -typedef enum { - VCP_SPEECH_DETECT_NONE = 0, /**< No event */ - VCP_SPEECH_DETECT_BEGIN, /**< Begin of speech detected */ - VCP_SPEECH_DETECT_END, /**< End of speech detected */ -} vcp_speech_detect_e; - -typedef enum { - VCP_ASR_RESULT_EVENT_FINAL_RESULT = 0, - VCP_ASR_RESULT_EVENT_PARTIAL_RESULT, - VCP_ASR_RESULT_EVENT_ERROR -} vcp_asr_result_event_e; - -/** -* @brief A structure of handle for VC command -*/ -typedef int vcp_cmd_h; - -/** - * @brief Definition of bluetooth audio id. -*/ -#define VCP_AUDIO_ID_BLUETOOTH "VC_AUDIO_ID_BLUETOOTH" /**< Bluetooth audio id */ - -/** - * @brief Definition of MSF(wifi) audio id. -*/ -#define VCP_AUDIO_ID_MSF "VC_AUDIO_ID_MSF" /**< MSF (wifi) audio id */ - -/** -* @brief Definition for none message. -*/ -#define VC_RESULT_MESSAGE_NONE "vc.result.message.none" - -/** -* @brief Definition for failed recognition because the speech is too loud to listen. -*/ -#define VC_RESULT_MESSAGE_ERROR_TOO_LOUD "vc.result.message.error.too.loud" - - -/** -* @brief Called when the daemon gets synthesized result. -* -* @param[in] event A result event -* @param[in] result_id Result ids -* @param[in] count Result count -* @param[in] all_result All result text -* @param[in] non_fixed_result Non-fixed command result text -* @param[in] nlu_result NLU result text -* @param[in] msg Engine message (e.g. #VC_RESULT_MESSAGE_NONE, #VC_RESULT_MESSAGE_ERROR_TOO_LOUD) -* @param[out] user_info A user info (e.g. If ASR result is consumed, the value is 0x01. If not, the value is 0x00.) -* @param[in] user_data The user data passed from set callback function -* -* @pre vcpe_stop() will invoke this callback. -* -* @see vcpe_stop() -*/ -typedef void (*vcpe_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); - - -/** -* @brief Called when the daemon gets ASR result. -* -* @param[in] event A asr result event -* @param[in] pre_result result text -* @param[in] user_data The user data passed from the start -*/ -typedef void (*vcpe_asr_result_cb)(vcp_asr_result_event_e event, const char* asr_result, void *user_data); - -/** -* @brief Called when the daemon gets nlg result. -* -* @param[in] nlg_result Nlg result -* @param[in] user_data The user data passed from the start -*/ -typedef void (*vcpe_nlg_result_cb)(const char* nlg_result, void *user_data); - -/** -* @brief Called when the daemon gets error. -* -* @param[in] error Error type -* @param[in] msg Error message -* @param[in] user_data The user data passed from set callback function -* -*/ -typedef void (*vcpe_error_cb)(vcp_error_e error, const char* msg, void *user_data); - -/** -* @brief Called to retrieve the supported languages. -* -* @param[in] language A language is specified as an ISO 3166 alpha-2 two letter country-code -* followed by ISO 639-1 for the two-letter language code \n -* For example, "ko_KR" for Korean, "en_US" for American English -* @param[in] user_data The user data passed from the foreach function -* -* @return @c true to continue with the next iteration of the loop \n @c false to break out of the loop -* -* @pre vcpe_foreach_supported_languages() will invoke this callback. -* -* @see vcpe_foreach_supported_languages() -*/ -typedef bool (*vcpe_supported_language_cb)(const char* language, void* user_data); - -/** -* @brief Initializes the engine. -* -* @param[in] result_cb A callback function for recognition result -* @param[in] silence_cb A callback function for silence detection -* -* @return 0 on success, otherwise a negative error value -* @retval #VCP_ERROR_NONE Successful -* @retval #VCP_ERROR_INVALID_PARAMETER Invalid parameter -* @retval #VCP_ERROR_INVALID_STATE Already initialized -* @retval #VCP_ERROR_OPERATION_FAILED Operation failed -* -* @see vcpe_deinitialize() -*/ -typedef int (*vcpe_initialize)(void); - -/** -* @brief Deinitializes the engine -* -* @return 0 on success, otherwise a negative error value -* @retval #VCP_ERROR_NONE Successful -* @retval #VCP_ERROR_INVALID_STATE Not initialized -* -* @see vcpe_initialize() -*/ -typedef void (*vcpe_deinitialize)(void); - -/** -* @brief Registers a callback function for getting recognition result. -* -* @param[in] callback Callback function to register -* @param[in] user_data The user data to be passed to the callback function -* -* @return 0 on success, otherwise a negative error value -* @retval #VCP_ERROR_NONE Successful -* @retval #VCP_ERROR_INVALID_PARAMETER Invalid parameter -* -* @see vcpe_result_cb() -*/ -typedef int (*vcpe_set_result_cb)(vcpe_result_cb callback, void* user_data); - -/** -* @brief Registers a callback function for getting ASR recognition result. -* -* @param[in] callback Callback function to register -* @param[in] user_data The user data to be passed to the callback function -* -* @return 0 on success, otherwise a negative error value -* -* @see vcpe_asr_result_cb() -*/ -typedef int (*vcpe_set_asr_result_cb)(vcpe_asr_result_cb callback, void* user_data); - -/** -* @brief Registers a callback function for getting nlg result. -* -* @param[in] callback Callback function to register -* @param[in] user_data The user data to be passed to the callback function -* -* @return 0 on success, otherwise a negative error value -* -*/ -typedef int (*vcpe_set_nlg_result_cb)(vcpe_nlg_result_cb, void* user_data); - -#if 0 -/** -* @brief Registers a callback function for getting partial recognition result. -* -* @param[in] callback Callback function to register -* @param[in] user_data The user data to be passed to the callback function -* -* @return 0 on success, otherwise a negative error value -* -* @see vcpe_pre_result_cb() -*/ -typedef int (*vcpe_set_pre_result_cb)(vcpe_pre_result_cb callback, void* user_data); -#endif - -/** -* @brief Registers a callback function for error. -* -* @param[in] callback Callback function to register -* @param[in] user_data The user data to be passed to the callback function -* -* @return 0 on success, otherwise a negative error value -* -*/ -typedef int (*vcpe_set_error_cb)(vcpe_error_cb callback, void* user_data); - -#if 0 -/** -* @brief Registers a callback function for getting NLU result. -* -* @param[in] callback Callback function to register -* @param[in] user_data The user data to be passed to the callback function -* -* @return 0 on success, otherwise a negative error value -* -*/ -typedef int (*vcpe_set_nlu_result_cb)(vcpe_nlu_result_cb, void* user_data); -#endif - -/** -* @brief Gets recording format of the engine. -* -* @param[in] audio_id The audio device id. -* @param[out] types The format used by the recorder. -* @param[out] rate The sample rate used by the recorder. -* @param[out] channels The number of channels used by the recorder. -* -* @return 0 on success, otherwise a negative error value -* @retval #VCP_ERROR_NONE Successful -* @retval #VCP_ERROR_INVALID_PARAMETER Not initialized -*/ -typedef int (*vcpe_get_recording_format)(const char* audio_id, vcp_audio_type_e* types, int* rate, int* channels); - -/** -* @brief Retrieves all supported languages of the engine. -* -* @param[in] callback a callback function -* @param[in] user_data The user data to be passed to the callback function -* -* @return 0 on success, otherwise a negative error value -* @retval #VCP_ERROR_NONE Successful -* @retval #VCP_ERROR_INVALID_PARAMETER Invalid parameter -* @retval #VCP_ERROR_INVALID_STATE Not initialized -* -* @post This function invokes vcpe_supported_language_cb() repeatedly for getting supported languages. -* -* @see vcpe_supported_language_cb() -*/ -typedef int (*vcpe_foreach_supported_languages)(vcpe_supported_language_cb callback, void* user_data); - -/** -* @brief Checks whether a language is supported or not. -* -* @param[in] language A language -* -* @return @c true = supported, \n @c false = not supported. -*/ -typedef bool (*vcpe_is_language_supported)(const char* language); - -/** -* @brief Sets language. -* -* @param[in] language language. -* -* @return 0 on success, otherwise a negative error value -* @retval #VCP_ERROR_NONE Successful -* @retval #VCP_ERROR_INVALID_LANGUAGE Invalid language -* @retval #VCP_ERROR_INVALID_STATE Not initialized -*/ -typedef int (*vcpe_set_language)(const char* language); - -/** -* @brief Sets command list before recognition. -* -* @remark This function should set commands via vcpd_foreach_command(). -* -* @param[in] vcp_command command handle. -* -* @return 0 on success, otherwise a negative error value -* @retval #VCP_ERROR_NONE Successful -* @retval #VCP_ERROR_INVALID_PARAMETER Invalid parameter -* @retval #VCP_ERROR_INVALID_STATE Invalid state -* @retval #VCP_ERROR_OPERATION_FAILED Operation failed -* @retval #VCP_ERROR_NOT_SUPPORTED_FEATURE Not supported command type -* -* @post vcpe_start() is called after this function is successful. -* -* @see vcpe_start() -* @see vcpd_foreach_command() -* @see vcpe_unset_commands() -*/ -typedef int (*vcpe_set_commands)(vcp_cmd_h vcp_command); - -/** -* @brief Unset command list for reset. -* -* @return 0 on success, otherwise a negative error value -* @retval #VCP_ERROR_NONE Successful -* @retval #VCP_ERROR_INVALID_PARAMETER Invalid parameter -* @retval #VCP_ERROR_INVALID_STATE Invalid state -* @retval #VCP_ERROR_OPERATION_FAILED Operation failed -* -* @see vcpe_set_commands() -*/ -typedef int (*vcpe_unset_commands)(); - -/** -* @brief Start recognition. -* -* @return 0 on success, otherwise a negative error value -* @retval #VCP_ERROR_NONE Successful -* @retval #VCP_ERROR_INVALID_PARAMETER Invalid parameter -* @retval #VCP_ERROR_INVALID_STATE Invalid state -* @retval #VCP_ERROR_INVALID_LANGUAGE Invalid language -* @retval #VCP_ERROR_OUT_OF_NETWORK Out of network -* @retval #VCP_ERROR_OPERATION_FAILED Operation failed -* -* @pre vcpd_foreach_command() is successful. -* -* @see vcpe_set_recording_data() -* @see vcpe_stop() -* @see vcpe_cancel() -*/ -typedef int (*vcpe_start)(bool stop_by_silence); - -/** -* @brief Sets recording data for speech recognition from recorder. -* -* @remark This function should be returned immediately after recording data copy. -* -* @param[in] data A recording data -* @param[in] length A length of recording data -* @param[out] silence_detected @c true Silence detected \n @c false No silence detected -* -* @return 0 on success, otherwise a negative error value -* @retval #VCP_ERROR_NONE Successful -* @retval #VCP_ERROR_INVALID_PARAMETER Invalid parameter -* @retval #VCP_ERROR_INVALID_STATE Invalid state -* @retval #VCP_ERROR_OPERATION_FAILED Operation failed -* -* @pre vcpe_start() is successful. -* -* @see vcpe_start() -* @see vcpe_cancel() -* @see vcpe_stop() -*/ -typedef int(*vcpe_set_recording_data)(const void* data, unsigned int length, vcp_speech_detect_e* speech_detected); - -/** -* @brief Stops to get the result of recognition. -* -* @return 0 on success, otherwise a negative error value -* @retval #VCP_ERROR_NONE Successful -* @retval #VCP_ERROR_INVALID_STATE Invalid state -* @retval #VCP_ERROR_OPERATION_FAILED Operation failed -* @retval #VCP_ERROR_OUT_OF_NETWORK Out of network -* -* @pre vcpe_set_recording_data() is successful. -* -* @see vcpe_start() -* @see vcpe_set_recording_data() -* @see vcpe_result_cb() -* @see vcpe_cancel() -*/ -typedef int (*vcpe_stop)(void); - -/** -* @brief Cancels the recognition process. -* -* @return 0 on success, otherwise a negative error value. -* @retval #VCP_ERROR_NONE Successful. -* @retval #VCP_ERROR_INVALID_STATE Invalid state. -* -* @pre vcpe_start() is successful. -* -* @see vcpe_start() -* @see vcpe_stop() -*/ -typedef int (*vcpe_cancel)(void); - -/** -* @brief Set audio recording type. -* -* @return 0 on success, otherwise a negative error value. -* @retval #VCP_ERROR_NONE Successful. -* -*/ -typedef int (*vcpe_set_audio_type)(const char* audio); - -/** -* @brief Sets domain (Agent or device type) -* -* @param[in] domain available Agent or device type -* -* @return 0 on success, otherwise a negative error value. -* -*/ -typedef int (*vcpe_set_domain)(const char* domain); - -/** -* @brief Gets essential value from nlu result. This function is available inside vcpe_nlu_result_cb() -* -* @param[in] key NLU base info key -* @parma[out] value NLU base info value -* -* @return 0 on success, otherwise a negative error value. -* -*/ -typedef int (*vcpe_get_nlu_base_info)(const char* key, char** value); - -/** -* @brief Sets private data between app and engine. -* -* @param[in] key Private key -* @param[in] data Private data -* -* @return 0 on success, otherwise a negative error value. -* -*/ -typedef int (*vcpe_set_private_data)(const char* key, const char* data); - -/** -* @brief Gets private data between app and engine. -* -* @param[in] key Private key -* @param[out] data Private data -* -* @return 0 on success, otherwise a negative error value. -* -*/ -typedef int (*vcpe_get_private_data)(const char* key, char** data); - -/** -* @brief Request process text. -* -* @param[in] text Requested text -* -* @return 0 on success, otherwise a negative error value. -* -*/ -typedef int (*vcpe_process_text)(const char* text); - -/** -* @brief Request list event. -* -* @param[in] event Requested list event -* -* @return 0 on success, otherwise a negative error value. -* -*/ -typedef int (*vcpe_process_list_event)(const char* event); - -/** -* @brief Request haptic event. -* -* @param[in] event Requested haptic event -* -* @return 0 on success, otherwise a negative error value. -* -*/ -typedef int (*vcpe_process_haptic_event)(const char* event); - -/** -* Daemon API. -*/ - -/** -* @brief Called to retrieve the commands. -* -* @param[in] id command id -* @param[in] type command type -* @param[in] format command format -* @param[in] command command text -* @param[in] param parameter text -* @param[in] domain command domain -* @param[in] user_data The user data passed from the foreach function -* -* @return @c true to continue with the next iteration of the loop, \n @c false to break out of the loop. -* @pre vcpd_foreach_command() will invoke this callback. -* -* @see vcpd_foreach_command() -*/ -typedef bool (*vcpd_foreach_command_cb)(int id, int type, int format, const char* command, const char* param, int domain, void* user_data); - -/** -* @brief Retrieves all commands using callback function. -* -* @param[in] vcp_command The handle to be passed to the vcpe_set_commands() function -* @param[in] callback The callback function to invoke -* @param[in] user_data The user data to be passed to the callback function -* -* @return 0 on success, otherwise a negative error value -* @retval #VCP_ERROR_NONE Successful -* @retval #VCP_ERROR_INVALID_PARAMETER Invalid parameter -* @retval #VCP_ERROR_OPERATION_FAILED Operation failure -* @retval #VCP_ERROR_INVALID_STATE Invalid state -* -* @post This function invokes vcpd_foreach_command_cb() repeatedly for getting commands. -* -* @see vcpd_foreach_command_cb() -* @see vcpe_set_commands() -*/ -typedef int (*vcpd_foreach_command)(vcp_cmd_h vcp_command, vcpd_foreach_command_cb callback, void* user_data); - -/** -* @brief Gets command length. -* -* @param[in] vcp_command The handle to be passed to the vcpe_set_commands() function -* -* @return the value greater than 0 on success, otherwise a negative error value -* -* @see vcpe_set_commands() -*/ -typedef int (*vcpd_get_command_count)(vcp_cmd_h vcp_command); - -/** -* @brief Gets current audio type. -* -* @remarks audio_type must be released using free() when it is no longer required. -* -* @param[in] audio_type Current audio type (e.g. #VCP_AUDIO_ID_BLUETOOTH or usb device id) -* -* @return the value greater than 0 on success, otherwise a negative error value -* -*/ -typedef int (*vcpd_get_audio_type)(char** audio_type); - -/** -* @brief Sets private data to Manager client. -* -* @param[in] key Private key -* @param[in] data Private data -* -* @return 0 on success, otherwise a negative error value. -* -*/ -typedef int (*vcpd_set_private_data)(const char* key, const char* data); - -/** -* @brief Gets private data from Manager client. -* -* @param[in] key Private key -* @param[out] data Private data -* -* @return 0 on success, otherwise a negative error value. -* -*/ -typedef int (*vcpd_get_private_data)(const char* key, char** data); - -/** -* @brief Request start recording. -* -* @return 0 on success, otherwise a negative error value. -* -*/ -typedef int (*vcpd_start_recording)(); - -/** -* @brief Request stop recording. -* -* @return 0 on success, otherwise a negative error value. -* -*/ -typedef int (*vcpd_stop_recording)(); - -/** -* @brief A structure of the engine functions. -*/ -typedef struct { - int size; /**< Size of structure */ - int version; /**< Version */ - - vcpe_initialize initialize; /**< Initialize engine */ - vcpe_deinitialize deinitialize; /**< Shutdown engine */ - - /* Get engine information */ - vcpe_get_recording_format get_recording_format; /**< Get recording format */ - vcpe_foreach_supported_languages foreach_langs; /**< Foreach language list */ - vcpe_is_language_supported is_lang_supported; /**< Check language */ - - /* Set info */ - vcpe_set_result_cb set_result_cb; /**< Set result callback */ - vcpe_set_language set_language; /**< Set language */ - vcpe_set_commands set_commands; /**< Request to set current commands */ - vcpe_unset_commands unset_commands; /**< Request to unset current commands */ - - /* Control recognition */ - vcpe_start start; /**< Start recognition */ - vcpe_set_recording_data set_recording; /**< Set recording data */ - vcpe_stop stop; /**< Stop recording for getting result */ - vcpe_cancel cancel; /**< Cancel recording and processing */ - - vcpe_set_audio_type set_audio_type; /**< Set audio type */ - - //vcpe_set_pre_result_cb set_pre_result_cb; /**< Set pre result callback */ - vcpe_set_asr_result_cb set_asr_result_cb; /**< Set asr result callback */ - vcpe_set_nlg_result_cb set_nlg_result_cb; /**< Set nlg result callback */ - vcpe_set_error_cb set_error_cb; /**< Set error callback */ - vcpe_set_domain set_domain; /**< Set domain */ - vcpe_get_nlu_base_info get_nlu_base_info; /**< Get essential info */ - //vcpe_set_nlu_result_cb set_nlu_result_cb; /**< Set nlu result callback */ - vcpe_set_private_data set_private_data; /**< Set private data */ - vcpe_get_private_data get_private_data; /**< Get private data */ - vcpe_process_text process_text; /**< Request to process text */ - vcpe_process_list_event process_list_event; /**< Request to process list event */ - vcpe_process_haptic_event process_haptic_event; /**< Request to process haptic event */ -} vcpe_funcs_s; - -/** -* @brief A structure of the daemon functions. -*/ -typedef struct { - int size; /**< Size of structure */ - int version; /**< Version */ - - vcpd_foreach_command foreach_command; /**< Foreach command */ - vcpd_get_command_count get_command_count; /**< Get command count */ - - vcpd_get_audio_type get_audio_type; /**< Get audio type */ - - vcpd_set_private_data set_private_data; /**< Set private data to Manager */ - vcpd_get_private_data get_private_data; /**< Get private data from Manager */ - - vcpd_start_recording start_recording; /**< Request start recording */ - vcpd_stop_recording stop_recording; /**< Request stop recording */ -} vcpd_funcs_s; - -/** -* @brief Loads the engine. -* -* @param[in] pdfuncs The daemon functions -* @param[out] pefuncs The engine functions -* -* @return This function returns zero on success, or negative with error code on failure -* @retval #VCP_ERROR_NONE Successful -* @retval #VCP_ERROR_INVALID_PARAMETER Invalid parameter -* @retval #VCP_ERROR_OPERATION_FAILED Operation failed -* -* @pre The vcp_get_engine_info() should be successful. -* @post The daemon calls engine functions of vcpe_funcs_s. -* -* @see vcp_get_engine_info() -* @see vcp_unload_engine() -*/ -int vcp_load_engine(vcpd_funcs_s* pdfuncs, vcpe_funcs_s* pefuncs); - -/** -* @brief Unloads this engine by the daemon. -* -* @pre The vcp_load_engine() should be successful. -* -* @see vcp_load_engine() -*/ -void vcp_unload_engine(void); - -/** -* @brief Called to get the engine base information. -* -* @param[in] engine_uuid The engine id -* @param[in] engine_name The engine name -* @param[in] engine_setting The setting ug name -* @param[in] use_network @c true to need network @c false not to need network. -* @param[in] user_data The User data passed from vcp_get_engine_info() -* -* @pre vcp_get_engine_info() will invoke this callback. -* -* @see vcp_get_engine_info() -*/ -typedef void (*vcpe_engine_info_cb)(const char* engine_uuid, const char* engine_name, const char* engine_setting, - bool use_network, void* user_data); - -/** -* @brief Gets the engine base information before the engine is loaded by the daemon. -* -* @param[in] callback Callback function -* @param[in] user_data User data to be passed to the callback function -* -* @return This function returns zero on success, or negative with error code on failure -* @retval #VCP_ERROR_NONE Successful -* @retval #VCP_ERROR_INVALID_PARAMETER Invalid parameter -* @retval #VCP_ERROR_OPERATION_FAILED Operation failed -* -* @post This function invokes vcpe_engine_info_cb() for getting engine information. -* -* @see vcpe_engine_info_cb() -* @see vcp_load_engine() -*/ -int vcp_get_engine_info(vcpe_engine_info_cb callback, void* user_data); - - -#ifdef __cplusplus -} -#endif - -/** -* @}@} -*/ - -#endif /* __VOICE_CONTROL_PLUGIN_ENGINE_H__ */ diff --git a/org.tizen.voice.vcserver.service b/org.tizen.voice.vcserver.service index a6f1e01..c5006a2 100644 --- a/org.tizen.voice.vcserver.service +++ b/org.tizen.voice.vcserver.service @@ -1,3 +1,4 @@ [D-BUS Service] Name=org.tizen.voice.vcserver -Exec=/usr/bin/vc-daemon +#Exec=/usr/bin/vc-daemon +Exec=/bin/sh -c "launch_app org.tizen.vc-engine-default" diff --git a/packaging/voice-control.spec b/packaging/voice-control.spec index bb50859..3b585bc 100644 --- a/packaging/voice-control.spec +++ b/packaging/voice-control.spec @@ -121,7 +121,7 @@ mkdir -p %{_libdir}/voice/vc %{_libdir}/libvc_setting.so %{_libdir}/libvc_widget.so %{_libdir}/libvc_manager.so -%{_bindir}/vc-daemon +%{_libdir}/libvc_engine.so %{TZ_SYS_RO_SHARE}/voice/vc/1.0/vc-config.xml %{TZ_SYS_RO_SHARE}/dbus-1/services/org.tizen.voice* /etc/dbus-1/session.d/vc-server.conf @@ -165,4 +165,5 @@ mkdir -p %{_libdir}/voice/vc %files engine-devel %defattr(-,root,root,-) %{_libdir}/pkgconfig/voice-control-engine.pc -%{_includedir}/voice_control_plugin_engine.h +%{_includedir}/vce.h + diff --git a/server/CMakeLists.txt b/server/CMakeLists.txt index d2cf638..f9e8d48 100644 --- a/server/CMakeLists.txt +++ b/server/CMakeLists.txt @@ -10,11 +10,13 @@ SET(SRCS vcd_dbus_server.c vcd_dbus.c vcd_engine_agent.c - vcd_main.c +# vcd_main.c vcd_recorder.c vcd_server.c + vce.c ) +INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}) INCLUDE_DIRECTORIES(${CMAKE_BINARY_DIR}/common) INCLUDE_DIRECTORIES(${CMAKE_BINARY_DIR}/include) @@ -28,8 +30,15 @@ SET(CMAKE_C_FLAGS_RELEASE "-O2 -fPIE") SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed -pie") ## Executable ## -ADD_EXECUTABLE("${PROJECT_NAME}-daemon" ${SRCS}) -TARGET_LINK_LIBRARIES("${PROJECT_NAME}-daemon" -ldl -lm ${pkgs_LDFLAGS}) +#ADD_EXECUTABLE("${PROJECT_NAME}-daemon" ${SRCS}) +#TARGET_LINK_LIBRARIES("${PROJECT_NAME}-daemon" -ldl -lm ${pkgs_LDFLAGS}) ## Install -INSTALL(TARGETS "${PROJECT_NAME}-daemon" DESTINATION bin) +#INSTALL(TARGETS "${PROJECT_NAME}-daemon" DESTINATION bin) + +## Executable ## +ADD_LIBRARY("${PROJECT_NAME}_engine" SHARED ${SRCS}) +TARGET_LINK_LIBRARIES("${PROJECT_NAME}_engine" -ldl ${pkgs_LDFLAGS}) + +## Install +INSTALL(TARGETS "${PROJECT_NAME}_engine" DESTINATION ${LIBDIR} COMPONENT RuntimeLibraries) diff --git a/server/vcd_client_data.c b/server/vcd_client_data.c index 22ea990..358ddb7 100644 --- a/server/vcd_client_data.c +++ b/server/vcd_client_data.c @@ -457,7 +457,7 @@ int vcd_client_foreach_command(client_foreach_command_cb callback, void* user_da return VCD_ERROR_OPERATION_FAILED; } - // int id_count = 1; +// int id_count = 1; GSList *iter = NULL; vc_cmd_s* temp_cmd; @@ -467,7 +467,7 @@ int vcd_client_foreach_command(client_foreach_command_cb callback, void* user_da temp_cmd = iter->data; SLOG(LOG_DEBUG, TAG_VCD, "[Client Data] Widget : id(%d) type(%d) format(%d) command(%s) domain(%d)" - , temp_cmd->id, temp_cmd->type, temp_cmd->format, temp_cmd->command, temp_cmd->domain); + , temp_cmd->id, temp_cmd->type, temp_cmd->format, temp_cmd->command, temp_cmd->domain); callback(temp_cmd->id, temp_cmd->type, temp_cmd->format, temp_cmd->command, temp_cmd->parameter, temp_cmd->domain, user_data); @@ -483,7 +483,7 @@ int vcd_client_foreach_command(client_foreach_command_cb callback, void* user_da temp_cmd = iter->data; SLOG(LOG_DEBUG, TAG_VCD, "[Client Data] Fore : id(%d) type(%d) format(%d) command(%s) param(%s) domain(%d) fixed(%s)" - , temp_cmd->id, temp_cmd->type, temp_cmd->format, temp_cmd->command, temp_cmd->parameter, temp_cmd->domain, temp_cmd->fixed); + , temp_cmd->id, temp_cmd->type, temp_cmd->format, temp_cmd->command, temp_cmd->parameter, temp_cmd->domain, temp_cmd->fixed); callback(temp_cmd->id, temp_cmd->type, temp_cmd->format, temp_cmd->command, temp_cmd->parameter, temp_cmd->domain, user_data); @@ -499,7 +499,7 @@ int vcd_client_foreach_command(client_foreach_command_cb callback, void* user_da temp_cmd = iter->data; SLOG(LOG_DEBUG, TAG_VCD, "[Client Data] System : id(%d) type(%d) format(%d) command(%s) param(%s) domain(%d)" - , temp_cmd->id, temp_cmd->type, temp_cmd->format, temp_cmd->command, temp_cmd->parameter, temp_cmd->domain); + , temp_cmd->id, temp_cmd->type, temp_cmd->format, temp_cmd->command, temp_cmd->parameter, temp_cmd->domain); callback(temp_cmd->id, temp_cmd->type, temp_cmd->format, temp_cmd->command, temp_cmd->parameter, temp_cmd->domain, user_data); @@ -515,7 +515,7 @@ int vcd_client_foreach_command(client_foreach_command_cb callback, void* user_da temp_cmd = iter->data; SLOG(LOG_DEBUG, TAG_VCD, "[Client Data] System background : id(%d) type(%d) format(%d) command(%s) param(%s) domain(%d)" - , temp_cmd->id, temp_cmd->type, temp_cmd->format, temp_cmd->command, temp_cmd->parameter, temp_cmd->domain); + , temp_cmd->id, temp_cmd->type, temp_cmd->format, temp_cmd->command, temp_cmd->parameter, temp_cmd->domain); callback(temp_cmd->id, temp_cmd->type, temp_cmd->format, temp_cmd->command, temp_cmd->parameter, temp_cmd->domain, user_data); @@ -531,7 +531,7 @@ int vcd_client_foreach_command(client_foreach_command_cb callback, void* user_da temp_cmd = iter->data; SLOG(LOG_DEBUG, TAG_VCD, "[Client Data] Exclusive system : id(%d) type(%d) format(%d) command(%s) param(%s) domain(%d)" - , temp_cmd->id, temp_cmd->type, temp_cmd->format, temp_cmd->command, temp_cmd->parameter, temp_cmd->domain); + , temp_cmd->id, temp_cmd->type, temp_cmd->format, temp_cmd->command, temp_cmd->parameter, temp_cmd->domain); callback(temp_cmd->id, temp_cmd->type, temp_cmd->format, temp_cmd->command, temp_cmd->parameter, temp_cmd->domain, user_data); @@ -547,7 +547,7 @@ int vcd_client_foreach_command(client_foreach_command_cb callback, void* user_da temp_cmd = iter->data; SLOG(LOG_DEBUG, TAG_VCD, "[Client Data] Back : id(%d) format(%d) type(%d) command(%s) param(%s) domain(%d) appid(%s) invocation(%s) fixed(%s)" - , temp_cmd->id, temp_cmd->type, temp_cmd->format, temp_cmd->command, temp_cmd->parameter, temp_cmd->domain, temp_cmd->appid, temp_cmd->invocation_name, temp_cmd->fixed); + , temp_cmd->id, temp_cmd->type, temp_cmd->format, temp_cmd->command, temp_cmd->parameter, temp_cmd->domain, temp_cmd->appid, temp_cmd->invocation_name, temp_cmd->fixed); callback(temp_cmd->id, temp_cmd->type, temp_cmd->format, temp_cmd->command, temp_cmd->parameter, temp_cmd->domain, user_data); diff --git a/server/vcd_engine_agent.c b/server/vcd_engine_agent.c index 14510fc..1f4c585 100644 --- a/server/vcd_engine_agent.c +++ b/server/vcd_engine_agent.c @@ -42,11 +42,7 @@ typedef struct { bool use_network; void *handle; - vcpe_funcs_s* pefuncs; - vcpd_funcs_s* pdfuncs; - - int (*vcp_load_engine)(vcpd_funcs_s* pdfuncs, vcpe_funcs_s* pefuncs); - int (*vcp_unload_engine)(); + vc_engine_callback_s* callbacks; } vcengine_s; typedef struct _vcengine_info { @@ -63,62 +59,28 @@ typedef struct _vcengine_info { /** vc engine agent init */ static bool g_agent_init; -/** vc engine list */ -static GList *g_engine_list; - /** current engine information */ static vcengine_s g_dynamic_engine; static char* g_default_lang; -/** callback functions */ -static result_callback g_result_cb = NULL; - -static asr_result_callback g_asr_result_cb = NULL; -static nlg_result_callback g_nlg_result_cb = NULL; - -#if 0 -static pre_result_callback g_pre_result_cb = NULL; - -static nlu_result_callback g_nlu_result_cb = NULL; -#endif - -static error_callback g_error_cb = NULL; - bool __supported_language_cb(const char* language, void* user_data); -void __engine_info_cb(const char* engine_uuid, const char* engine_name, const char* engine_setting, bool use_network, void* user_data); - -bool __engine_setting_cb(const char* key, const char* value, void* user_data); - -/** Free voice list */ -void __free_language_list(GList* lang_list); - - /* * Internal Interfaces */ -/** check engine id */ -int __internal_check_engine_id(const char* engine_uuid); - -/** update engine list */ -int __internal_update_engine_list(); - /** get engine info */ -int __internal_get_engine_info(const char* filepath, vcengine_info_s** info); - -int __log_enginelist(); +int __internal_get_engine_info(vce_request_callback_s* callback); /* * VCS Engine Agent Interfaces */ -//int vcd_engine_agent_init(pre_result_callback pre_result_cb, result_callback result_cb, nlu_result_callback nlu_result_cb, error_callback error_cb) -int vcd_engine_agent_init(asr_result_callback asr_result_cb, result_callback result_cb, nlg_result_callback nlg_result_cb, error_callback error_cb) +int vcd_engine_agent_init() { - if (/*NULL == pre_result_cb*/ NULL == asr_result_cb || NULL == result_cb /*|| NULL == nlu_result_cb*/ || NULL == error_cb) { - SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Input parameter is NULL"); - return VCD_ERROR_OPERATION_FAILED; + if (true == g_agent_init) { + SLOG(LOG_DEBUG, TAG_VCD, "[Engine Agent] Already initialized"); + return VCD_ERROR_NONE; } /* init dynamic engine */ @@ -130,17 +92,14 @@ int vcd_engine_agent_init(asr_result_callback asr_result_cb, result_callback res g_dynamic_engine.is_loaded = false; g_dynamic_engine.handle = NULL; g_dynamic_engine.is_command_ready = false; - g_dynamic_engine.pefuncs = (vcpe_funcs_s*)calloc(1, sizeof(vcpe_funcs_s)); - g_dynamic_engine.pdfuncs = (vcpd_funcs_s*)calloc(1, sizeof(vcpd_funcs_s)); - g_agent_init = true; + g_dynamic_engine.callbacks = (vc_engine_callback_s*)calloc(1, sizeof(vc_engine_callback_s)); + if (NULL == g_dynamic_engine.callbacks) { + SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent] Fail to allocate memory"); + return VCD_ERROR_OUT_OF_MEMORY; + } - //g_pre_result_cb = pre_result_cb; - g_asr_result_cb = asr_result_cb; - g_nlg_result_cb = nlg_result_cb; - g_result_cb = result_cb; - //g_nlu_result_cb = nlu_result_cb; - g_error_cb = error_cb; + g_agent_init = true; if (0 != vcd_config_get_default_language(&g_default_lang)) { SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] There is No default voice in config"); @@ -163,61 +122,14 @@ int vcd_engine_agent_release() /* unload current engine */ vcd_engine_agent_unload_current_engine(); - /* release engine list */ - GList *iter = NULL; - vcengine_s *data = NULL; - - if (g_list_length(g_engine_list) > 0) { - /* Get a first item */ - iter = g_list_first(g_engine_list); - - while (NULL != iter) { - /* Get handle data from list */ - data = iter->data; - iter = g_list_remove(iter, data); - - if (NULL != data) { - if (NULL != data->engine_uuid) { - g_free(data->engine_uuid); - data->engine_uuid = NULL; - } - if (NULL != data->engine_name) { - g_free(data->engine_name); - data->engine_name = NULL; - } - if (NULL != data->engine_path) { - g_free(data->engine_path); - data->engine_path = NULL; - } - - free(data); - data = NULL; - } - } - } - - g_list_free(iter); - g_engine_list = NULL; - /* release current engine data */ - if (NULL != g_dynamic_engine.pefuncs) { - free(g_dynamic_engine.pefuncs); - g_dynamic_engine.pefuncs = NULL; - } - if (NULL != g_dynamic_engine.pdfuncs) { - free(g_dynamic_engine.pdfuncs); - g_dynamic_engine.pdfuncs = NULL; + if (NULL != g_dynamic_engine.callbacks) { + free(g_dynamic_engine.callbacks); + g_dynamic_engine.callbacks = NULL; } g_agent_init = false; - //g_pre_result_cb = NULL; - g_asr_result_cb = NULL; - g_nlg_result_cb = NULL; - g_result_cb = NULL; - //g_nlu_result_cb = NULL; - g_error_cb = NULL; - SLOG(LOG_DEBUG, TAG_VCD, "[Engine Agent SUCCESS] Engine Agent release"); return 0; @@ -231,570 +143,166 @@ bool vcd_engine_is_available_engine() return false; } -int vcd_engine_agent_initialize_current_engine() +int __internal_get_engine_info(vce_request_callback_s* callback) { - /* check agent init */ - if (false == g_agent_init) { - SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Not Initialized"); - return VCD_ERROR_OPERATION_FAILED; - } + SLOG(LOG_DEBUG, TAG_VCD, "[Engine Agent] inside __internal_get_engine_info"); - /* update engine list */ - if (0 != __internal_update_engine_list()) { - SLOG(LOG_ERROR, TAG_VCD, "[engine agent] vcd_engine_agent_init : __internal_update_engine_list : no engine error"); + if (NULL == callback) { + SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Invalid engine"); return VCD_ERROR_ENGINE_NOT_FOUND; } - /* check whether engine id is valid or not.*/ - GList *iter = NULL; - vcengine_info_s *dynamic_engine = NULL; - - if (g_list_length(g_engine_list) > 0) { - /*Get a first item*/ - iter = g_list_first(g_engine_list); - - while (NULL != iter) { - /*Get handle data from list*/ - dynamic_engine = iter->data; - if (NULL != dynamic_engine) { - break; - } - - /*Get next item*/ - iter = g_list_next(iter); - } - } else { + if (NULL == callback->get_info) { + SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Invalid engine"); return VCD_ERROR_ENGINE_NOT_FOUND; } - if (NULL == dynamic_engine) { + if (0 != callback->get_info(&(g_dynamic_engine.engine_uuid), &(g_dynamic_engine.engine_name), &(g_dynamic_engine.engine_setting_path), &(g_dynamic_engine.use_network))) { + SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Fail to get engine info"); return VCD_ERROR_ENGINE_NOT_FOUND; - } else { - if (NULL != g_dynamic_engine.engine_uuid) { - /* set data from g_engine_list */ - if (g_dynamic_engine.engine_uuid != NULL) g_free(g_dynamic_engine.engine_uuid); - if (g_dynamic_engine.engine_name != NULL) g_free(g_dynamic_engine.engine_name); - if (g_dynamic_engine.engine_path != NULL) g_free(g_dynamic_engine.engine_path); - } - - g_dynamic_engine.engine_uuid = g_strdup(dynamic_engine->engine_uuid); - g_dynamic_engine.engine_name = g_strdup(dynamic_engine->engine_name); - g_dynamic_engine.engine_path = g_strdup(dynamic_engine->engine_path); - - g_dynamic_engine.handle = NULL; - g_dynamic_engine.is_loaded = false; - g_dynamic_engine.is_set = true; - - SLOG(LOG_DEBUG, TAG_VCD, "@@@"); - SLOG(LOG_DEBUG, TAG_VCD, " Dynamic engine uuid : %s", g_dynamic_engine.engine_uuid); - SLOG(LOG_DEBUG, TAG_VCD, " Dynamic engine name : %s", g_dynamic_engine.engine_name); - SLOG(LOG_DEBUG, TAG_VCD, " Dynamic engine path : %s", g_dynamic_engine.engine_path); - SLOG(LOG_DEBUG, TAG_VCD, "@@@"); - } - return 0; -} - -int __internal_check_engine_id(const char* engine_uuid) -{ - if (NULL == engine_uuid) { - SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Invalid Parameter"); - return VCD_ERROR_INVALID_PARAMETER; - } - - GList *iter = NULL; - vcengine_s *data = NULL; - - if (0 < g_list_length(g_engine_list)) { - /*Get a first item*/ - iter = g_list_first(g_engine_list); - - while (NULL != iter) { - data = iter->data; - - if (0 == strncmp(engine_uuid, data->engine_uuid, strlen(data->engine_uuid))) { - return 0; - } - - iter = g_list_next(iter); - } + if (NULL != g_dynamic_engine.callbacks) { + free(g_dynamic_engine.callbacks); + g_dynamic_engine.callbacks = NULL; } - - return -1; -} - -void __engine_info_cb(const char* engine_uuid, const char* engine_name, const char* engine_setting, bool use_network, void* user_data) -{ - vcengine_info_s* temp = (vcengine_info_s*)user_data; - - temp->engine_uuid = g_strdup(engine_uuid); - temp->engine_name = g_strdup(engine_name); -} - - -int __internal_get_engine_info(const char* filepath, vcengine_info_s** info) -{ - if (NULL == filepath || NULL == info) { - SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Invalid Parameter"); - return VCD_ERROR_INVALID_PARAMETER; - } - - /* load engine */ - char *error; - void* handle; - - if (0 != access(filepath, F_OK)) { - SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Fail to access file (%s)", filepath); - return -1; - } else { - handle = dlopen(filepath, RTLD_LAZY); - if (!handle) { - SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Invalid engine : %s", filepath); - if ((error = dlerror()) != NULL) { - SLOG(LOG_ERROR, TAG_VCD, "[ERROR] %s", error); - } - return -1; - } - } - - /* link engine to daemon */ - dlsym(handle, "vcp_load_engine"); - if ((error = dlerror()) != NULL) { - SLOG(LOG_WARN, TAG_VCD, "[Engine Agent] Invalid engine. Fail to open vcp_load_engine : %s", filepath); - dlclose(handle); - return -1; - } - - dlsym(handle, "vcp_unload_engine"); - if ((error = dlerror()) != NULL) { - SLOG(LOG_WARN, TAG_VCD, "[Engine Agent] Invalid engine. Fail to open vcp_unload_engine : %s", filepath); - dlclose(handle); - return -1; - } - - int (*get_engine_info)(vcpe_engine_info_cb callback, void* user_data); - - get_engine_info = (int (*)(vcpe_engine_info_cb, void*))dlsym(handle, "vcp_get_engine_info"); - if (NULL != (error = dlerror()) || NULL == get_engine_info) { - SLOG(LOG_WARN, TAG_VCD, "[Engine Agent WARNING] Invalid engine. Fail to open vcp_get_engine_info : %s", filepath); - dlclose(handle); - return -1; - } - - vcengine_info_s* temp; - temp = (vcengine_info_s*)calloc(1, sizeof(vcengine_info_s)); - if (NULL == temp) { - SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to allocate memory"); - dlclose(handle); + g_dynamic_engine.callbacks = (vc_engine_callback_s*)calloc(1, sizeof(vc_engine_callback_s)); + if (NULL == g_dynamic_engine.callbacks) { + SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Fail to allocate memory"); return VCD_ERROR_OUT_OF_MEMORY; } - /* get engine info */ - if (0 != get_engine_info(__engine_info_cb, (void*)temp)) { - SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Fail to get engine info from engine"); - dlclose(handle); - free(temp); - return -1; - } - - /* close engine */ - dlclose(handle); - - temp->engine_path = g_strdup(filepath); + g_dynamic_engine.callbacks->get_info = callback->get_info; + g_dynamic_engine.callbacks->get_recording_format = callback->get_recording_format; + g_dynamic_engine.callbacks->foreach_langs = callback->foreach_langs; + g_dynamic_engine.callbacks->is_lang_supported = callback->is_lang_supported; + g_dynamic_engine.callbacks->initialize = callback->initialize; + g_dynamic_engine.callbacks->deinitialize = callback->deinitialize; + g_dynamic_engine.callbacks->set_language = callback->set_language; + g_dynamic_engine.callbacks->set_commands = callback->set_commands; + g_dynamic_engine.callbacks->unset_commands = callback->unset_commands; + + g_dynamic_engine.callbacks->start = callback->start; + g_dynamic_engine.callbacks->set_recording = callback->set_recording; + g_dynamic_engine.callbacks->stop = callback->stop; + g_dynamic_engine.callbacks->cancel = callback->cancel; + g_dynamic_engine.callbacks->set_domain = callback->set_domain; + g_dynamic_engine.callbacks->set_audio_type = callback->set_audio_type; + g_dynamic_engine.callbacks->process_text = callback->process_text; + g_dynamic_engine.callbacks->process_list_event = callback->process_list_event; + g_dynamic_engine.callbacks->process_haptic_event = callback->process_haptic_event; + + g_dynamic_engine.callbacks->private_data_set = NULL; + g_dynamic_engine.callbacks->private_data_request = NULL; + g_dynamic_engine.callbacks->nlu_base_info_request = NULL; SLOG(LOG_DEBUG, TAG_VCD, "@@@ Valid Engine"); - SLOG(LOG_DEBUG, TAG_VCD, "Engine uuid : %s", temp->engine_uuid); - SLOG(LOG_DEBUG, TAG_VCD, "Engine name : %s", temp->engine_name); - SLOG(LOG_DEBUG, TAG_VCD, "Engine path : %s", temp->engine_path); + SLOG(LOG_DEBUG, TAG_VCD, "Engine uuid : %s", g_dynamic_engine.engine_uuid); + SLOG(LOG_DEBUG, TAG_VCD, "Engine name : %s", g_dynamic_engine.engine_name); SLOG(LOG_DEBUG, TAG_VCD, "@@@"); - *info = temp; - return 0; } -int __internal_update_engine_list() +int vcd_engine_agent_load_current_engine(vce_request_callback_s* callback) { - /* relsease engine list */ - GList *iter = NULL; - vcengine_info_s *data = NULL; + SLOG(LOG_DEBUG, TAG_VCD, "[Engine Agent] load current engine START"); - if (0 < g_list_length(g_engine_list)) { - /* Get a first item */ - iter = g_list_first(g_engine_list); - - while (NULL != iter) { - /* Get handle data from list */ - data = iter->data; - - if (NULL != data) { - if (NULL != data->engine_uuid) g_free(data->engine_uuid); - if (NULL != data->engine_path) g_free(data->engine_path); - if (NULL != data->engine_name) g_free(data->engine_name); - - data->engine_uuid = NULL; - data->engine_path = NULL; - data->engine_name = NULL; - - free(data); - } - - g_engine_list = g_list_remove_link(g_engine_list, iter); - iter = g_list_first(g_engine_list); - } + if (false == g_agent_init) { + SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Not Initialized"); + return VCD_ERROR_OPERATION_FAILED; } - /* Get file name from default engine directory */ - DIR *dp = NULL; - struct dirent *dirp = NULL; - - dp = opendir(VC_DEFAULT_ENGINE); - if (NULL != dp) { - do { - dirp = readdir(dp); - - if (NULL != dirp) { - if (!strcmp(".", dirp->d_name) || !strcmp("..", dirp->d_name)) - continue; - - vcengine_info_s* info = NULL; - char* filepath = NULL; - int filesize = 0; - - filesize = strlen(VC_DEFAULT_ENGINE) + strlen(dirp->d_name) + 5; - filepath = (char*)calloc(filesize, sizeof(char)); - - if (NULL != filepath) { - snprintf(filepath, filesize, "%s/%s", VC_DEFAULT_ENGINE, dirp->d_name); - } else { - SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Memory not enough!!"); - continue; - } - - /* get its info and update engine list */ - if (0 == __internal_get_engine_info(filepath, &info)) { - /* add engine info to g_engine_list */ - g_engine_list = g_list_append(g_engine_list, info); - } - - if (NULL != filepath) { - free(filepath); - filepath = NULL; - } - } - } while (NULL != dirp); - - closedir(dp); - } else { - SLOG(LOG_WARN, TAG_VCD, "[Engine Agent WARNING] Fail to open default directory"); + if (true == g_dynamic_engine.is_loaded) { + SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent] Engine has already been loaded"); + return 0; } - if (0 >= g_list_length(g_engine_list)) { - SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] No Engine"); + if (NULL == callback) { + SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Invalid engine"); return VCD_ERROR_ENGINE_NOT_FOUND; } - __log_enginelist(); - - return 0; -} - - -int __foreach_command(vcp_cmd_h vc_command, vcpd_foreach_command_cb callback, void* user_data) -{ - SLOG(LOG_DEBUG, TAG_VCD, "[Engine Agent] Request foreach command from engine"); - return vcd_client_foreach_command((client_foreach_command_cb)callback, user_data); -} - -int __command_get_length(vcp_cmd_h vc_command) -{ - SLOG(LOG_DEBUG, TAG_VCD, "[Engine Agent] Request command length from engine"); - return vcd_client_get_length(); -} - -int __get_audio_type(char** audio_type) -{ - SLOG(LOG_DEBUG, TAG_VCD, "[Engine Agent] Request audio type"); - - return vcd_recorder_get(audio_type); -} - -int __set_private_data(const char* key, const char* data) -{ - SLOG(LOG_DEBUG, TAG_VCD, "[Engine Agent] Request set private data, key(%s), data(%s)", key, data); - vcdc_send_request_set_private_data(vcd_client_manager_get_pid(), key, data); - - return 0; -} - -int __get_private_data(const char* key, char** data) -{ - SLOG(LOG_DEBUG, TAG_VCD, "[Engine Agent] Request get private data, key(%s)", key); - vcdc_send_request_get_private_data(vcd_client_manager_get_pid(), key, data); - - return 0; -} - -int __start_recording() -{ - SLOG(LOG_DEBUG, TAG_VCD, "[Engine Agent] Request start recording"); - - int ret = vcd_recorder_start(); + /* Get current engine info */ + int ret = __internal_get_engine_info(callback); 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 */ - vcdc_send_error_signal_to_manager(vcd_client_manager_get_pid(), VCD_ERROR_OPERATION_FAILED, "voice_engine.error.proc_fail"); + SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Fail to get engine info"); return ret; } - return 0; -} - -int __stop_recording() -{ - SLOG(LOG_DEBUG, TAG_VCD, "[Engine Agent] Request stop recording"); - - return vcd_recorder_stop(); -} - -void __result_cb(vcp_result_event_e event, int* result_id, int count, const char* all_result, const char* non_fixed, const char* nlu_result, const char* msg, int* user_info, void *user_data) -{ - SECURE_SLOG(LOG_DEBUG, TAG_VCD, "[Engine agent] Event(%d), Count(%d) Text(%s) Nonfixed(%s) NLU result(%s) Msg(%s)", event, count, all_result, non_fixed, nlu_result, msg); - - if (NULL != g_result_cb) { - g_result_cb(event, result_id, count, all_result, non_fixed, nlu_result, msg, user_info, user_data); - } else { - SLOG(LOG_DEBUG, TAG_VCD, "[Engine Agent ERROR] Result callback function is NOT valid"); - } - - return; -} - -void __asr_result_cb(vcp_asr_result_event_e event, const char* asr_result, void *user_data) -{ - SECURE_SLOG(LOG_DEBUG, TAG_VCD, "[Engine Agent] ASR result - Event(%d), Result(%s)", event, asr_result); - - if (NULL != g_asr_result_cb) { - g_asr_result_cb(event, asr_result, user_data); - } else { - SLOG(LOG_DEBUG, TAG_VCD, "[Engine Agent ERROR] ASR result callback function is NOT valid"); - } - - return; -} - -void __nlg_result_cb(const char* nlg_result, void *user_data) -{ - SECURE_SLOG(LOG_DEBUG, TAG_VCD, "[Engine Agent] NLG result - Result(%s)", nlg_result); - - if (NULL != g_nlg_result_cb) { - g_nlg_result_cb(nlg_result, user_data); - } else { - SLOG(LOG_DEBUG, TAG_VCD, "[Engine Agent ERROR] NLG result callback function is NOT valid"); - } - - return; -} - -void __error_cb(vcp_error_e error, const char* msg, void *user_data) -{ - SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent] ERROR(%d)", error); - - if (NULL != g_error_cb) { - g_error_cb(error, msg, user_data); - } else { - SLOG(LOG_DEBUG, TAG_VCD, "[Engine Agent ERROR] Error callback function is NOT vaild"); - } - - return; -} - -int __load_engine(vcengine_s* engine) -{ - /* check whether engine is NULL or not */ - if (NULL == engine) { - SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] engine is NULL"); - return VCD_ERROR_INVALID_PARAMETER; - } - - /* check whether current engine is loaded or not */ - if (true == engine->is_loaded) { - SLOG(LOG_DEBUG, TAG_VCD, "[Engine Agent] Engine has already been loaded "); - return 0; - } - - SLOG(LOG_DEBUG, TAG_VCD, "[Engine Agent] Current engine path : %s", engine->engine_path); - - /* open engine */ - char *error; - if (0 != access(engine->engine_path, F_OK)) { - SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Fail to access file (%s)", engine->engine_path); - return VCD_ERROR_OPERATION_FAILED; - } else { - engine->handle = dlopen(engine->engine_path, RTLD_LAZY); - - if ((error = dlerror()) != NULL || !engine->handle) { - SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Fail to get engine handle"); - return VCD_ERROR_OPERATION_FAILED; - } - } - - engine->vcp_unload_engine = (int (*)())dlsym(engine->handle, "vcp_unload_engine"); - if ((error = dlerror()) != NULL) { - SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Fail to link daemon to vcp_unload_engine()"); - dlclose(engine->handle); - return VCD_ERROR_OPERATION_FAILED; - } - - engine->vcp_load_engine = (int (*)(vcpd_funcs_s*, vcpe_funcs_s*))dlsym(engine->handle, "vcp_load_engine"); - if (NULL != (error = dlerror()) || NULL == engine->vcp_load_engine) { - SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Fail to link daemon to vcp_load_engine()"); - dlclose(engine->handle); - return VCD_ERROR_OPERATION_FAILED; - } - - /* load engine */ - engine->pdfuncs->version = 1; - engine->pdfuncs->size = sizeof(vcpd_funcs_s); - - engine->pdfuncs->foreach_command = __foreach_command; - engine->pdfuncs->get_command_count = __command_get_length; - engine->pdfuncs->get_audio_type = __get_audio_type; - - engine->pdfuncs->set_private_data = __set_private_data; - engine->pdfuncs->get_private_data = __get_private_data; - - engine->pdfuncs->start_recording = __start_recording; - engine->pdfuncs->stop_recording = __stop_recording; - - if (0 != engine->vcp_load_engine(engine->pdfuncs, engine->pefuncs)) { - SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Fail vcp_load_engine()"); - dlclose(engine->handle); - return VCD_ERROR_OPERATION_FAILED; - } - - SLOG(LOG_DEBUG, TAG_VCD, "[Engine Agent] engine info : version(%d), size(%d)(%d)", engine->pefuncs->version, engine->pefuncs->size, sizeof(vcpe_funcs_s)); - - /* engine error check */ - if (engine->pefuncs->size != sizeof(vcpe_funcs_s)) { - SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Engine is not valid"); - return VCD_ERROR_OPERATION_FAILED; - } - /* Check all engine functions */ - if (NULL == engine->pefuncs->initialize || - NULL == engine->pefuncs->deinitialize || - NULL == engine->pefuncs->get_recording_format || - NULL == engine->pefuncs->foreach_langs || - NULL == engine->pefuncs->is_lang_supported || - NULL == engine->pefuncs->set_result_cb || - NULL == engine->pefuncs->set_language || - NULL == engine->pefuncs->set_commands || - NULL == engine->pefuncs->unset_commands || - NULL == engine->pefuncs->start || - NULL == engine->pefuncs->set_recording || - NULL == engine->pefuncs->stop || - NULL == engine->pefuncs->cancel || - NULL == engine->pefuncs->set_audio_type || - NULL == engine->pefuncs->set_asr_result_cb || - NULL == engine->pefuncs->set_nlg_result_cb || - //NULL == engine->pefuncs->set_pre_result_cb || - NULL == engine->pefuncs->set_error_cb || - NULL == engine->pefuncs->set_domain || - NULL == engine->pefuncs->get_nlu_base_info || - //NULL == engine->pefuncs->set_nlu_result_cb || - NULL == engine->pefuncs->set_private_data || - NULL == engine->pefuncs->get_private_data || - NULL == engine->pefuncs->process_text || - NULL == engine->pefuncs->process_list_event || - NULL == engine->pefuncs->process_haptic_event) { - SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] The current engine is NOT valid"); - return VCD_ERROR_OPERATION_FAILED; - } - - /* initalize engine */ - if (0 != engine->pefuncs->initialize()) { - SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Fail to initialize vc-engine"); - return VCD_ERROR_OPERATION_FAILED; - } - - if (0 != engine->pefuncs->set_result_cb(__result_cb, NULL)) { - SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Fail to set result callback of vc-engine"); - return VCD_ERROR_OPERATION_FAILED; + if (NULL == g_dynamic_engine.callbacks->get_info || + NULL == g_dynamic_engine.callbacks->get_recording_format || + NULL == g_dynamic_engine.callbacks->foreach_langs || + NULL == g_dynamic_engine.callbacks->is_lang_supported || + NULL == g_dynamic_engine.callbacks->initialize || + NULL == g_dynamic_engine.callbacks->deinitialize || + NULL == g_dynamic_engine.callbacks->set_language || + NULL == g_dynamic_engine.callbacks->set_commands || + NULL == g_dynamic_engine.callbacks->unset_commands || + NULL == g_dynamic_engine.callbacks->start || + NULL == g_dynamic_engine.callbacks->set_recording || + NULL == g_dynamic_engine.callbacks->stop || + NULL == g_dynamic_engine.callbacks->cancel || + NULL == g_dynamic_engine.callbacks->set_audio_type || + NULL == g_dynamic_engine.callbacks->set_domain || + NULL == g_dynamic_engine.callbacks->process_text || + NULL == g_dynamic_engine.callbacks->process_list_event || + NULL == g_dynamic_engine.callbacks->process_haptic_event) { + SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] The current engine is NOT valid"); + return VCD_ERROR_ENGINE_NOT_FOUND; } - if (0 != engine->pefuncs->set_asr_result_cb(__asr_result_cb, NULL)) { - SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Fail to set asr result callback of vc-engine"); - return VCD_ERROR_OPERATION_FAILED; + /* initalize engine */ + ret = g_dynamic_engine.callbacks->initialize(); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Fail to initialize vc engine service"); + return ret; } - if (0 != engine->pefuncs->set_nlg_result_cb(__nlg_result_cb, NULL)) { - SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Fail to set nlg result callback of vc-engine"); - return VCD_ERROR_OPERATION_FAILED; - } + /* set the supported language */ + if (true == g_dynamic_engine.callbacks->is_lang_supported(g_default_lang)) { + ret = g_dynamic_engine.callbacks->set_language(g_default_lang); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Fail to set the supported language"); + return ret; + } - if (0 != engine->pefuncs->set_error_cb(__error_cb, NULL)) { - SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Fail to set error callback of vc-engine"); + SLOG(LOG_DEBUG, TAG_VCD, "[Engine Agent SUCCESS] The %s has been loaded!!!", g_dynamic_engine.engine_name); + g_dynamic_engine.is_loaded = true; + } else { + SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent WARNING] This engine do not support default language : lang(%s)", g_default_lang); + g_dynamic_engine.is_loaded = false; return VCD_ERROR_OPERATION_FAILED; } - /* load engine */ - if (true == engine->pefuncs->is_lang_supported(g_default_lang)) { - if (0 != engine->pefuncs->set_language(g_default_lang)) { - SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Fail to load current engine"); - return VCD_ERROR_OPERATION_FAILED; - } - SLOG(LOG_DEBUG, TAG_VCD, "[Engine Agent SUCCESS] The %s has been loaded !!!", engine->engine_name); - engine->is_loaded = true; - } else { - SLOG(LOG_WARN, TAG_VCD, "[Engine Agent WARNING] This engine do not support default language : lang(%s)", g_default_lang); - engine->is_loaded = false; - } + SLOG(LOG_DEBUG, TAG_VCD, "[Engine Agent] load current engine FINISH"); return 0; } -int vcd_engine_agent_load_current_engine() +int vcd_engine_agent_unload_current_engine() { if (false == g_agent_init) { SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Not Initialized"); return VCD_ERROR_OPERATION_FAILED; } - if (true == g_dynamic_engine.is_set) { - if (0 != __load_engine(&g_dynamic_engine)) { - SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Fail to load dynamic engine"); - - /* need to initialize dynamic engine data */ - g_dynamic_engine.is_loaded = false; - } else { - SLOG(LOG_DEBUG, TAG_VCD, "[Engine Agent SUCCESS] Load dynamic engine"); - } + if (false == g_dynamic_engine.is_loaded) { + SLOG(LOG_DEBUG, TAG_VCD, "[Engine Agent] Engine has already been unloaded"); + return VCD_ERROR_NONE; } - return 0; -} - -int vcd_engine_agent_unload_current_engine() -{ - if (false == g_agent_init) { - SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Not Initialized "); - return VCD_ERROR_OPERATION_FAILED; + /* shut down engine */ + int ret = 0; + ret = g_dynamic_engine.callbacks->deinitialize(); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Fail to deinitialize"); } - if (true == g_dynamic_engine.is_set) { - /* unload dynamic engine */ - if (true == g_dynamic_engine.is_loaded) { - /* shutdown engine */ - g_dynamic_engine.pefuncs->deinitialize(); - g_dynamic_engine.vcp_unload_engine(); - dlclose(g_dynamic_engine.handle); - g_dynamic_engine.handle = NULL; - g_dynamic_engine.is_loaded = false; - } - } + /* reset current engine data */ + g_dynamic_engine.is_loaded = false; + return 0; } @@ -814,7 +322,7 @@ int vcd_engine_set_commands() if (true == g_dynamic_engine.is_loaded) { /* Set dynamic command */ - ret = g_dynamic_engine.pefuncs->set_commands((vcp_cmd_h)0); + ret = g_dynamic_engine.callbacks->set_commands((vce_cmd_h)0); if (0 != ret) { SLOG(LOG_WARN, TAG_VCD, "[Engine Agent ERROR] Fail to set command of dynamic engine : error(%d)", ret); g_dynamic_engine.is_command_ready = false; @@ -841,7 +349,7 @@ int vcd_engine_recognize_start(bool silence) SLOG(LOG_DEBUG, TAG_VCD, "[Engine Agent] silence is %s", silence ? "true" : "false"); if (true == g_dynamic_engine.is_loaded && true == g_dynamic_engine.is_command_ready) { - ret = g_dynamic_engine.pefuncs->start(silence); + ret = g_dynamic_engine.callbacks->start(silence); if (0 != ret) { SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent] Fail to start engine error(%d)", ret); return VCD_ERROR_OPERATION_FAILED; @@ -855,7 +363,7 @@ int vcd_engine_recognize_start(bool silence) return 0; } -int vcd_engine_recognize_audio(const void* data, unsigned int length, vcp_speech_detect_e* speech_detected) +int vcd_engine_recognize_audio(const void* data, unsigned int length, vce_speech_detect_e* speech_detected) { if (false == g_agent_init) { SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Not Initialized"); @@ -870,10 +378,10 @@ int vcd_engine_recognize_audio(const void* data, unsigned int length, vcp_speech int ret = -1; if (true == g_dynamic_engine.is_loaded) { - ret = g_dynamic_engine.pefuncs->set_recording(data, length, speech_detected); + ret = g_dynamic_engine.callbacks->set_recording(data, length, speech_detected); if (0 != ret) { SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Fail to set recording dynamic engine error(%d)", ret); - if (VCP_ERROR_OUT_OF_NETWORK == ret) { + if (VCE_ERROR_OUT_OF_NETWORK == ret) { return VCD_ERROR_TIMED_OUT; } return VCD_ERROR_OPERATION_FAILED; @@ -892,7 +400,7 @@ int vcd_engine_recognize_stop() if (true == g_dynamic_engine.is_loaded) { int ret = -1; - ret = g_dynamic_engine.pefuncs->stop(); + ret = g_dynamic_engine.callbacks->stop(); if (0 != ret) { SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Fail to stop dynamic engine error(%d)", ret); return VCD_ERROR_OPERATION_FAILED; @@ -914,7 +422,7 @@ int vcd_engine_recognize_cancel() int ret = -1; if (true == g_dynamic_engine.is_loaded) { - ret = g_dynamic_engine.pefuncs->cancel(); + ret = g_dynamic_engine.callbacks->cancel(); if (0 != ret) { SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Fail to cancel dynamic engine error(%d)", ret); return VCD_ERROR_OPERATION_FAILED; @@ -933,7 +441,7 @@ int vcd_engine_set_audio_type(const char* audio) int ret = -1; if (true == g_dynamic_engine.is_loaded) { - ret = g_dynamic_engine.pefuncs->set_audio_type(audio); + ret = g_dynamic_engine.callbacks->set_audio_type(audio); if (0 != ret) { SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Fail to set audio type(%d)", ret); return VCD_ERROR_OPERATION_FAILED; @@ -952,7 +460,7 @@ int vcd_engine_set_domain(int pid, const char* domain) int ret = -1; if (true == g_dynamic_engine.is_loaded) { - ret = g_dynamic_engine.pefuncs->set_domain(domain); + ret = g_dynamic_engine.callbacks->set_domain(domain); if (0 != ret) { SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Fail to set domain (%d)", ret); return VCD_ERROR_OPERATION_FAILED; @@ -975,12 +483,15 @@ int vcd_engine_get_nlu_base_info(int pid, const char* key, char** value) } int ret = -1; - if (true == g_dynamic_engine.is_loaded) { - ret = g_dynamic_engine.pefuncs->get_nlu_base_info(key, value); + if (true == g_dynamic_engine.is_loaded && NULL != g_dynamic_engine.callbacks->nlu_base_info_request) { + ret = g_dynamic_engine.callbacks->nlu_base_info_request(key, value); if (0 != ret) { SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Fail to get nlu base info (%d)", ret); return VCD_ERROR_OPERATION_FAILED; } + } else { + SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Engine is not loaded or There is no nlu_base_info_request callback"); + return VCD_ERROR_OPERATION_FAILED; } return 0; @@ -994,12 +505,15 @@ int vcd_engine_set_private_data(int pid, const char* key, const char* data) } int ret = -1; - if (true == g_dynamic_engine.is_loaded) { - ret = g_dynamic_engine.pefuncs->set_private_data(key, data); + if (true == g_dynamic_engine.is_loaded && NULL != g_dynamic_engine.callbacks->private_data_set) { + ret = g_dynamic_engine.callbacks->private_data_set(key, data); if (0 != ret) { SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Fail to set private data (%d)", ret); return VCD_ERROR_OPERATION_FAILED; } + } else { + SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Engine is not loaded or There is no private_data_set callback"); + return VCD_ERROR_OPERATION_FAILED; } return 0; @@ -1018,12 +532,15 @@ int vcd_engine_get_private_data(int pid, const char* key, char** data) } int ret = -1; - if (true == g_dynamic_engine.is_loaded) { - ret = g_dynamic_engine.pefuncs->get_private_data(key, data); + if (true == g_dynamic_engine.is_loaded && NULL != g_dynamic_engine.callbacks->private_data_request) { + ret = g_dynamic_engine.callbacks->private_data_request(key, data); if (0 != ret) { SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Fail to get private data (%d)", ret); return VCD_ERROR_OPERATION_FAILED; } + } else { + SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Engine is not loaded or There is no private_data_request callback"); + return VCD_ERROR_OPERATION_FAILED; } return 0; @@ -1038,7 +555,7 @@ int vcd_engine_process_text(int pid, const char* text) int ret = -1; if (true == g_dynamic_engine.is_loaded) { - ret = g_dynamic_engine.pefuncs->process_text(text); + ret = g_dynamic_engine.callbacks->process_text(text); if (0 != ret) { SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Fail to process text (%d)", ret); return VCD_ERROR_OPERATION_FAILED; @@ -1057,7 +574,7 @@ int vcd_engine_process_list_event(int pid, const char* event) int ret = -1; if (true == g_dynamic_engine.is_loaded) { - ret = g_dynamic_engine.pefuncs->process_list_event(event); + ret = g_dynamic_engine.callbacks->process_list_event(event); if (0 != ret) { SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Fail to process list event (%d)", ret); return VCD_ERROR_OPERATION_FAILED; @@ -1076,7 +593,7 @@ int vcd_engine_process_haptic_event(int pid, const char* event) int ret = -1; if (true == g_dynamic_engine.is_loaded) { - ret = g_dynamic_engine.pefuncs->process_haptic_event(event); + ret = g_dynamic_engine.callbacks->process_haptic_event(event); if (0 != ret) { SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Fail to process haptic event (%d)", ret); return VCD_ERROR_OPERATION_FAILED; @@ -1090,7 +607,7 @@ int vcd_engine_process_haptic_event(int pid, const char* event) * VCS Engine Interfaces for client and setting */ -int vcd_engine_get_audio_format(const char* audio_id, vcp_audio_type_e* types, int* rate, int* channels) +int vcd_engine_get_audio_format(const char* audio_id, vce_audio_type_e* types, int* rate, int* channels) { if (false == g_agent_init) { SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Not Initialized"); @@ -1101,12 +618,7 @@ int vcd_engine_get_audio_format(const char* audio_id, vcp_audio_type_e* types, i SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Engine is not loaded"); } - if (NULL == g_dynamic_engine.pefuncs->get_recording_format) { - SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] The function of engine is NULL!!"); - return VCD_ERROR_OPERATION_FAILED; - } - - int ret = g_dynamic_engine.pefuncs->get_recording_format(audio_id, types, rate, channels); + int ret = g_dynamic_engine.callbacks->get_recording_format(audio_id, types, rate, channels); if (0 != ret) { SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] get recording format(%d)", ret); return VCD_ERROR_OPERATION_FAILED; @@ -1144,12 +656,7 @@ int vcd_engine_supported_langs(GList** lang_list) SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Engine is not loaded"); } - if (NULL == g_dynamic_engine.pefuncs->foreach_langs) { - SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] The function of engine is NULL!!"); - return VCD_ERROR_OPERATION_FAILED; - } - - int ret = g_dynamic_engine.pefuncs->foreach_langs(__supported_language_cb, (void*)lang_list); + int ret = g_dynamic_engine.callbacks->foreach_langs(__supported_language_cb, (void*)lang_list); if (0 != ret) { SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] get language list error(%d)", ret); return VCD_ERROR_OPERATION_FAILED; @@ -1194,7 +701,7 @@ int vcd_engine_set_current_language(const char* language) if (true == g_dynamic_engine.is_loaded) { g_dynamic_engine.is_command_ready = false; - ret = g_dynamic_engine.pefuncs->set_language(language); + ret = g_dynamic_engine.callbacks->set_language(language); if (0 != ret) { SLOG(LOG_WARN, TAG_VCD, "[Engine Agent] Fail to set language of dynamic engine error(%d, %s)", ret, language); } @@ -1205,59 +712,113 @@ int vcd_engine_set_current_language(const char* language) return 0; } -void __free_language_list(GList* lang_list) +int vcd_engine_agent_get_foreach_command(vce_cmd_h vce_command, vce_command_cb callback, void* user_data) { - GList *iter = NULL; - char* data = NULL; + SLOG(LOG_DEBUG, TAG_VCD, "[Engine Agent] Request foreach command from engine"); + return vcd_client_foreach_command((client_foreach_command_cb)callback, user_data); +} - /* if list have item */ - if (g_list_length(lang_list) > 0) { - /* Get a first item */ - iter = g_list_first(lang_list); +int vcd_engine_agent_get_command_count(vce_cmd_h vce_command) +{ + SLOG(LOG_DEBUG, TAG_VCD, "[Engine Agent] Request command length from engine"); - while (NULL != iter) { - data = iter->data; + return vcd_client_get_length(); +} - if (NULL != data) - free(data); +int vcd_engine_agent_get_audio_type(char** audio_type) +{ + SLOG(LOG_DEBUG, TAG_VCD, "[Engine Agent] Request audio type"); - lang_list = g_list_remove_link(lang_list, iter); + return vcd_recorder_get(audio_type); +} - iter = g_list_first(lang_list); - } +int vcd_engine_agent_set_private_data(const char* key, const char* data) +{ + SLOG(LOG_DEBUG, TAG_VCD, "[Engine Agent] Request set private data, key(%s), data(%s)", key, data); + vcdc_send_request_set_private_data(vcd_client_manager_get_pid(), key, data); + + return VCD_ERROR_NONE; +} + +int vcd_engine_agent_get_private_data(const char* key, char** data) +{ + SLOG(LOG_DEBUG, TAG_VCD, "[Engine Agent] Request get private data, key(%s)", key); + vcdc_send_request_get_private_data(vcd_client_manager_get_pid(), key, data); + + return VCD_ERROR_NONE; +} + +int vcd_engine_agent_start_recording() +{ + SLOG(LOG_DEBUG, TAG_VCD, "[Engine Agent] Request start recording"); + + int 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 */ + vcdc_send_error_signal_to_manager(vcd_client_manager_get_pid(), VCD_ERROR_OPERATION_FAILED, "voice_engine.error.proc_fail"); + return ret; } + + return VCD_ERROR_NONE; } -int __log_enginelist() +int vcd_engine_agent_stop_recording() { - GList *iter = NULL; - vcengine_info_s *data = NULL; + SLOG(LOG_DEBUG, TAG_VCD, "[Engine Agent] Request stop recording"); + + return vcd_recorder_stop(); +} - if (0 < g_list_length(g_engine_list)) { +int vcd_engine_agent_set_private_data_set_cb(vce_private_data_set_cb callback_func) +{ + if (false == g_agent_init) { + SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Not Initialized"); + return VCD_ERROR_OPERATION_FAILED; + } - /* Get a first item */ - iter = g_list_first(g_engine_list); + if (false == g_dynamic_engine.is_loaded) { + SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Not loaded engine"); + return VCD_ERROR_OPERATION_FAILED; + } - SLOG(LOG_DEBUG, TAG_VCD, "@ engine list @"); + g_dynamic_engine.callbacks->private_data_set = callback_func; - int i = 1; - while (NULL != iter) { - /* Get handle data from list */ - data = iter->data; + return VCD_ERROR_NONE; +} - SLOG(LOG_DEBUG, TAG_VCD, "[%dth]", i); - SLOG(LOG_DEBUG, TAG_VCD, " engine uuid : %s", data->engine_uuid); - SLOG(LOG_DEBUG, TAG_VCD, " engine name : %s", data->engine_name); - SLOG(LOG_DEBUG, TAG_VCD, " engine path : %s", data->engine_path); - iter = g_list_next(iter); - i++; - } - SLOG(LOG_DEBUG, TAG_VCD, "@@@@"); - } else { - SLOG(LOG_DEBUG, TAG_VCD, "@ engine list @"); - SLOG(LOG_DEBUG, TAG_VCD, " No Engine in engine directory"); - SLOG(LOG_DEBUG, TAG_VCD, "@@@@"); +int vcd_engine_agent_set_private_data_requested_cb(vce_private_data_requested_cb callback_func) +{ + if (false == g_agent_init) { + SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Not Initialized"); + return VCD_ERROR_OPERATION_FAILED; } - return 0; + if (false == g_dynamic_engine.is_loaded) { + SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Not loaded engine"); + return VCD_ERROR_OPERATION_FAILED; + } + + g_dynamic_engine.callbacks->private_data_request = callback_func; + + return VCD_ERROR_NONE; } + +int vcd_engine_agent_set_nlu_base_info_requested_cb(vce_nlu_base_info_requested_cb callback_func) +{ + if (false == g_agent_init) { + SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Not Initialized"); + return VCD_ERROR_OPERATION_FAILED; + } + + if (false == g_dynamic_engine.is_loaded) { + SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Not loaded engine"); + return VCD_ERROR_OPERATION_FAILED; + } + + g_dynamic_engine.callbacks->nlu_base_info_request = callback_func; + + return VCD_ERROR_NONE; +} + diff --git a/server/vcd_engine_agent.h b/server/vcd_engine_agent.h index aac4fc8..4fa59d8 100644 --- a/server/vcd_engine_agent.h +++ b/server/vcd_engine_agent.h @@ -19,7 +19,6 @@ #define __VCD_ENGINE_AGENT_H_ #include "vcd_main.h" -#include "voice_control_plugin_engine.h" #ifdef __cplusplus extern "C" { @@ -31,48 +30,22 @@ extern "C" { #define ENGINE_PATH_SIZE 256 -typedef void (*result_callback)(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); - -typedef void (*asr_result_callback)(vcp_asr_result_event_e event, const char* asr_result, void *user_data); - -typedef void (*nlg_result_callback)(const char* nlg_result, void *user_data); - -#if 0 -typedef void (*pre_result_callback)(vcp_pre_result_event_e event, const char* pre_result, void *user_data); - -typedef void (*nlu_result_callback)(vcp_result_event_e event, const char* nlu_result, void *user_data); -#endif - -typedef void (*error_callback)(vcp_error_e error, const char* msg, void *user_data); - -typedef void (*silence_dectection_callback)(void *user_data); - - - /** Init engine agent */ -//int vcd_engine_agent_init(pre_result_callback pre_result_cb, result_callback result_cb, nlu_result_callback nlu_result_cb, error_callback error_cb); -int vcd_engine_agent_init(asr_result_callback asr_result_cb, result_callback result_cb, nlg_result_callback nlg_result_cb, error_callback error_cb); +int vcd_engine_agent_init(); /** Release engine agent */ int vcd_engine_agent_release(); bool vcd_engine_is_available_engine(); -/** Set current engine */ -int vcd_engine_agent_initialize_current_engine(); - /** load current engine */ -int vcd_engine_agent_load_current_engine(); +int vcd_engine_agent_load_current_engine(vce_request_callback_s* callback); /** Unload current engine */ int vcd_engine_agent_unload_current_engine(); -/** test for language list */ -int vcd_print_enginelist(); - -int vcd_engine_get_audio_format(const char* audio_id, vcp_audio_type_e* types, int* rate, int* channels); +int vcd_engine_get_audio_format(const char* audio_id, vce_audio_type_e* types, int* rate, int* channels); int vcd_engine_supported_langs(GList** lang_list); @@ -85,7 +58,7 @@ int vcd_engine_set_commands(); /* normal recognition */ int vcd_engine_recognize_start(bool silence); -int vcd_engine_recognize_audio(const void* data, unsigned int length, vcp_speech_detect_e* speech_detected); +int vcd_engine_recognize_audio(const void* data, unsigned int length, vce_speech_detect_e* speech_detected); int vcd_engine_recognize_stop(); @@ -97,10 +70,8 @@ int vcd_engine_set_domain(int pid, const char* domain); int vcd_engine_get_nlu_base_info(int pid, const char* key, char** value); -// int vcd_engine_set_private_data(const char* data); int vcd_engine_set_private_data(int pid, const char* key, const char* data); -// int vcd_engine_get_private_data(char** data); int vcd_engine_get_private_data(int pid, const char* key, char** data); int vcd_engine_process_text(int pid, const char* text); @@ -109,6 +80,27 @@ int vcd_engine_process_list_event(int pid, const char* event); int vcd_engine_process_haptic_event(int pid, const char* event); +/* for engine service */ +int vcd_engine_agent_get_foreach_command(vce_cmd_h vce_command, vce_command_cb callback, void* user_data); + +int vcd_engine_agent_get_command_count(vce_cmd_h vce_command); + +int vcd_engine_agent_get_audio_type(char** audio_type); + +int vcd_engine_agent_set_private_data(const char* key, const char* data); + +int vcd_engine_agent_get_private_data(const char* key, char** data); + +int vcd_engine_agent_start_recording(); + +int vcd_engine_agent_stop_recording(); + +int vcd_engine_agent_set_private_data_set_cb(vce_private_data_set_cb callback_func); + +int vcd_engine_agent_set_private_data_requested_cb(vce_private_data_requested_cb callback_func); + +int vcd_engine_agent_set_nlu_base_info_requested_cb(vce_nlu_base_info_requested_cb callback_func); + #ifdef __cplusplus } diff --git a/server/vcd_main.c b/server/vcd_main.c deleted file mode 100755 index a1b865a..0000000 --- a/server/vcd_main.c +++ /dev/null @@ -1,75 +0,0 @@ -/* -* Copyright (c) 2011-2015 Samsung Electronics Co., Ltd All Rights Reserved -* -* Licensed under the Apache License, Version 2.0 (the License); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an AS IS BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - - -#include "vcd_dbus.h" -#include "vcd_main.h" -#include "vcd_server.h" - -#define CLIENT_CLEAN_UP_TIME 500 - -static Ecore_Timer* g_check_client_timer = NULL; - -int main(int argc, char** argv) -{ - SLOG(LOG_DEBUG, TAG_VCD, "@@@ VC Daemon Initialize"); - - if (!ecore_init()) { - SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail ecore_init()"); - return -1; - } - - if (0 != vcd_dbus_open_connection()) { - SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to open connection"); - ecore_shutdown(); - return EXIT_FAILURE; - } - - if (0 != vcd_initialize()) { - SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to initialize vc-daemon"); - ecore_shutdown(); - return EXIT_FAILURE; - } - - g_check_client_timer = ecore_timer_add(CLIENT_CLEAN_UP_TIME, vcd_cleanup_client_all, NULL); - if (NULL == g_check_client_timer) { - SLOG(LOG_WARN, TAG_VCD, "[Main Warning] Fail to create timer of client check"); - } - - SLOG(LOG_DEBUG, TAG_VCD, "[Main] vc-daemon start"); - - SLOG(LOG_DEBUG, TAG_VCD, "@@@"); - - ecore_main_loop_begin(); - - SLOG(LOG_DEBUG, TAG_VCD, "@@@ VC Daemon Finalize"); - - if (NULL != g_check_client_timer) { - ecore_timer_del(g_check_client_timer); - } - - vcd_finalize(); - - vcd_dbus_close_connection(); - - ecore_shutdown(); - - SLOG(LOG_DEBUG, TAG_VCD, "@@@"); - - return 0; -} - - diff --git a/server/vcd_main.h b/server/vcd_main.h index 1f83fb9..a4e5705 100644 --- a/server/vcd_main.h +++ b/server/vcd_main.h @@ -31,6 +31,8 @@ #include "vc_defs.h" +#include "vce.h" + #ifdef __cplusplus extern "C" { #endif @@ -70,6 +72,43 @@ typedef enum { VCD_STATE_PROCESSING = 3 } vcd_state_e; +typedef struct { + int version; /**< Version */ + + /* Mandatory callbacks */ + /* Get engine information */ + vce_get_info_cb get_info; /**< Called when the engine service user requests the basic information of VC engine */ + vce_get_recording_format_cb get_recording_format; /**< Get recording format */ + vce_foreach_supported_languages_cb foreach_langs; /**< Foreach language list */ + vce_is_language_supported_cb is_lang_supported; /**< Check language */ + + vce_initialize_cb initialize; /**< Initialize engine */ + vce_deinitialize_cb deinitialize; /**< Shutdown engine */ + + /* Set info */ + vce_set_language_cb set_language; /**< Set language */ + vce_set_commands_cb set_commands; /**< Request to set current commands */ + vce_unset_commands_cb unset_commands; /**< Request to unset current commands */ + + /* Control recognition */ + vce_start_cb start; /**< Start recognition */ + vce_set_recording_data_cb set_recording; /**< Set recording data */ + vce_stop_cb stop; /**< Stop recording for getting result */ + vce_cancel_cb cancel; /**< Cancel recording and processing */ + + vce_set_audio_type set_audio_type; /**< Set audio type */ + + vce_set_domain_cb set_domain; /**< Set domain */ + vce_process_text_cb process_text; /**< Request to process text */ + vce_process_list_event_cb process_list_event; /**< Request to process list event */ + vce_process_haptic_event_cb process_haptic_event; /**< Request to process haptic event */ + + /* Optional callbacks */ + vce_private_data_set_cb private_data_set; + vce_private_data_requested_cb private_data_request; + vce_nlu_base_info_requested_cb nlu_base_info_request; +} vc_engine_callback_s; + #ifdef __cplusplus } diff --git a/server/vcd_recorder.c b/server/vcd_recorder.c index e2bee43..f3194d4 100644 --- a/server/vcd_recorder.c +++ b/server/vcd_recorder.c @@ -38,14 +38,13 @@ #include "vcd_engine_agent.h" #include "vcd_recorder.h" #include "vcd_main.h" -#include "voice_control_plugin_engine.h" #define FRAME_LENGTH 160 #define BUFFER_LENGTH FRAME_LENGTH * 2 #define FOCUS_SERVER_READY "/tmp/.focus_server_ready" -#define VCP_AUDIO_ID_NONE "VC_AUDIO_ID_NONE" /**< None audio id */ +#define VCE_AUDIO_ID_NONE "VC_AUDIO_ID_NONE" /**< None audio id */ static vcd_recorder_state_e g_recorder_state = VCD_RECORDER_STATE_READY; @@ -57,7 +56,7 @@ static audio_in_h g_audio_h; static sound_stream_info_h g_stream_info_h; -static vcp_audio_type_e g_audio_type; +static vce_audio_type_e g_audio_type; static int g_audio_rate; @@ -91,10 +90,10 @@ static float get_volume_decibel(char* data, int size); #ifdef TV_MSF_WIFI_MODE static void __msf_wifi_audio_data_receive_cb(msf_wifi_voice_data_s *voice_data, void* user_data) { - if (0 != strncmp(g_current_audio_type, VCP_AUDIO_ID_MSF, sizeof(VCP_AUDIO_ID_MSF))) { + if (0 != strncmp(g_current_audio_type, VCE_AUDIO_ID_WIFI, sizeof(VCE_AUDIO_ID_WIFI))) { vcd_state_e state = vcd_config_get_service_state(); if (VCD_STATE_READY == state) { - vcd_recorder_set(VCP_AUDIO_ID_MSF, VCP_AUDIO_TYPE_PCM_S16_LE, 16000, 1); + vcd_recorder_set(VCE_AUDIO_ID_WIFI, VCE_AUDIO_TYPE_PCM_S16_LE, 16000, 1); } else { SLOG(LOG_ERROR, TAG_VCD, "[Recorder ERROR] current audio type is (%s)", g_current_audio_type); return; @@ -102,7 +101,7 @@ static void __msf_wifi_audio_data_receive_cb(msf_wifi_voice_data_s *voice_data, } if (VCD_RECORDER_STATE_RECORDING != g_recorder_state) { - SLOG(LOG_WARN, TAG_VCD, "[Recorder] Not start yet, but send audio data vi MSF"); + SLOG(LOG_WARN, TAG_VCD, "[Recorder] Not start yet, but send audio data vi Wi-Fi"); vcd_recorder_start(); } @@ -154,10 +153,10 @@ static void _bt_cb_hid_state_changed(int result, bool connected, const char *rem static void _bt_hid_audio_data_receive_cb(bt_hid_voice_data_s *voice_data, void *user_data) { - if (0 != strncmp(g_current_audio_type, VCP_AUDIO_ID_BLUETOOTH, sizeof(VCP_AUDIO_ID_BLUETOOTH))) { + if (0 != strncmp(g_current_audio_type, VCE_AUDIO_ID_BLUETOOTH, sizeof(VCE_AUDIO_ID_BLUETOOTH))) { vcd_state_e state = vcd_config_get_service_state(); if (VCD_STATE_READY == state) { - vcd_recorder_set(VCP_AUDIO_ID_BLUETOOTH, VCP_AUDIO_TYPE_PCM_S16_LE, 16000, 1); + vcd_recorder_set(VCE_AUDIO_ID_BLUETOOTH, VCE_AUDIO_TYPE_PCM_S16_LE, 16000, 1); } else { SLOG(LOG_ERROR, TAG_VCD, "[Recorder ERROR] current audio type is (%s)", g_current_audio_type); return; @@ -363,7 +362,7 @@ int vcd_recorder_create(vcd_recoder_audio_cb audio_cb, vcd_recorder_interrupt_cb g_is_valid_bt_in = false; g_current_audio_type = NULL; - g_audio_type = VCP_AUDIO_TYPE_PCM_S16_LE; + g_audio_type = VCE_AUDIO_TYPE_PCM_S16_LE; g_audio_rate = 16000; g_audio_channel = 1; @@ -382,8 +381,8 @@ int vcd_recorder_create(vcd_recoder_audio_cb audio_cb, vcd_recorder_interrupt_cb } switch (g_audio_type) { - case VCP_AUDIO_TYPE_PCM_S16_LE: audio_type = AUDIO_SAMPLE_TYPE_S16_LE; break; - case VCP_AUDIO_TYPE_PCM_U8: audio_type = AUDIO_SAMPLE_TYPE_U8; break; + case VCE_AUDIO_TYPE_PCM_S16_LE: audio_type = AUDIO_SAMPLE_TYPE_S16_LE; break; + case VCE_AUDIO_TYPE_PCM_U8: audio_type = AUDIO_SAMPLE_TYPE_U8; break; default: SLOG(LOG_ERROR, TAG_VCD, "[Recorder ERROR] Invalid Audio Type"); return VCD_ERROR_OPERATION_FAILED; @@ -444,10 +443,10 @@ int vcd_recorder_create(vcd_recoder_audio_cb audio_cb, vcd_recorder_interrupt_cb #endif /* Select default audio type */ if (true == g_is_valid_audio_in) { - g_current_audio_type = strdup(VCP_AUDIO_ID_NONE); + g_current_audio_type = strdup(VCE_AUDIO_ID_NONE); } else { if (true == g_is_valid_bt_in) { - g_current_audio_type = strdup(VCP_AUDIO_ID_BLUETOOTH); + g_current_audio_type = strdup(VCE_AUDIO_ID_BLUETOOTH); } else { SLOG(LOG_ERROR, TAG_VCD, "[Recorder ERROR] No valid audio"); return -1; @@ -462,11 +461,11 @@ int vcd_recorder_create(vcd_recoder_audio_cb audio_cb, vcd_recorder_interrupt_cb int vcd_recorder_destroy() { if (VCD_RECORDER_STATE_RECORDING == g_recorder_state) { - if (0 == strncmp(VCP_AUDIO_ID_BLUETOOTH, g_current_audio_type, strlen(VCP_AUDIO_ID_BLUETOOTH))) { + if (0 == strncmp(VCE_AUDIO_ID_BLUETOOTH, g_current_audio_type, strlen(VCE_AUDIO_ID_BLUETOOTH))) { #ifdef TV_BT_MODE bt_hid_unset_audio_data_receive_cb(); #endif - } else if (0 == strncmp(VCP_AUDIO_ID_MSF, g_current_audio_type, strlen(VCP_AUDIO_ID_MSF))) { + } else if (0 == strncmp(VCE_AUDIO_ID_WIFI, g_current_audio_type, strlen(VCE_AUDIO_ID_WIFI))) { #ifdef TV_MSF_WIFI_MODE UnRegisterMSFAudioCallback(); #endif @@ -504,7 +503,7 @@ int vcd_recorder_destroy() return 0; } -int vcd_recorder_set(const char* audio_type, vcp_audio_type_e type, int rate, int channel) +int vcd_recorder_set(const char* audio_type, vce_audio_type_e type, int rate, int channel) { if (NULL == audio_type) { return VCD_ERROR_INVALID_PARAMETER; @@ -524,24 +523,26 @@ int vcd_recorder_set(const char* audio_type, vcp_audio_type_e type, int rate, in vcd_engine_set_audio_type(audio_type); if (VCD_RECORDER_STATE_READY != g_recorder_state) { - if ((!strncmp(g_current_audio_type, VCP_AUDIO_ID_NONE, strlen(g_current_audio_type)) && - strncmp(audio_type, VCP_AUDIO_ID_BLUETOOTH, strlen(audio_type)) && - strncmp(audio_type, VCP_AUDIO_ID_MSF, strlen(audio_type))) || - (strncmp(g_current_audio_type, VCP_AUDIO_ID_BLUETOOTH, strlen(g_current_audio_type)) && - strncmp(g_current_audio_type, VCP_AUDIO_ID_MSF, strlen(g_current_audio_type)) && - strncmp(g_current_audio_type, VCP_AUDIO_ID_NONE, strlen(g_current_audio_type)) && - !strncmp(audio_type, VCP_AUDIO_ID_NONE, strlen(audio_type)))) { - SLOG(LOG_DEBUG, TAG_VCD, "[Recorder] Skip stop recording while Recorder is NOT ready"); - } else { - SLOG(LOG_ERROR, TAG_VCD, "[Recorder ERROR] Recorder is NOT ready"); - vcd_recorder_stop(); - //return VCD_ERROR_INVALID_STATE; + if (NULL != g_current_audio_type) { + if ((!strncmp(g_current_audio_type, VCE_AUDIO_ID_NONE, strlen(g_current_audio_type)) && + strncmp(audio_type, VCE_AUDIO_ID_BLUETOOTH, strlen(audio_type)) && + strncmp(audio_type, VCE_AUDIO_ID_WIFI, strlen(audio_type))) || + (strncmp(g_current_audio_type, VCE_AUDIO_ID_BLUETOOTH, strlen(g_current_audio_type)) && + strncmp(g_current_audio_type, VCE_AUDIO_ID_WIFI, strlen(g_current_audio_type)) && + strncmp(g_current_audio_type, VCE_AUDIO_ID_NONE, strlen(g_current_audio_type)) && + !strncmp(audio_type, VCE_AUDIO_ID_NONE, strlen(audio_type)))) { + SLOG(LOG_DEBUG, TAG_VCD, "[Recorder] Skip stop recording while Recorder is NOT ready"); + } else { + SLOG(LOG_ERROR, TAG_VCD, "[Recorder ERROR] Recorder is NOT ready"); + vcd_recorder_stop(); + //return VCD_ERROR_INVALID_STATE; + } } } int ret = -1; /* Check BT audio */ - if (0 == strncmp(VCP_AUDIO_ID_BLUETOOTH, audio_type, strlen(VCP_AUDIO_ID_BLUETOOTH))) { + if (0 == strncmp(VCE_AUDIO_ID_BLUETOOTH, audio_type, strlen(VCE_AUDIO_ID_BLUETOOTH))) { if (false == g_is_valid_bt_in) { SLOG(LOG_ERROR, TAG_VCD, "[Recorder] BT audio is NOT valid"); return VCD_ERROR_OPERATION_REJECTED; @@ -553,7 +554,7 @@ int vcd_recorder_set(const char* audio_type, vcp_audio_type_e type, int rate, in } g_current_audio_type = strdup(audio_type); - } else if (0 == strncmp(VCP_AUDIO_ID_MSF, audio_type, strlen(VCP_AUDIO_ID_MSF))) { + } else if (0 == strncmp(VCE_AUDIO_ID_WIFI, audio_type, strlen(VCE_AUDIO_ID_WIFI))) { if (NULL != g_current_audio_type) { free(g_current_audio_type); g_current_audio_type = NULL; @@ -583,8 +584,8 @@ int vcd_recorder_set(const char* audio_type, vcp_audio_type_e type, int rate, in } switch (type) { - case VCP_AUDIO_TYPE_PCM_S16_LE: audio_type = AUDIO_SAMPLE_TYPE_S16_LE; break; - case VCP_AUDIO_TYPE_PCM_U8: audio_type = AUDIO_SAMPLE_TYPE_U8; break; + case VCE_AUDIO_TYPE_PCM_S16_LE: audio_type = AUDIO_SAMPLE_TYPE_S16_LE; break; + case VCE_AUDIO_TYPE_PCM_U8: audio_type = AUDIO_SAMPLE_TYPE_U8; break; default: SLOG(LOG_ERROR, TAG_VCD, "[Recorder ERROR] Invalid Audio Type"); return VCD_ERROR_OPERATION_FAILED; @@ -731,11 +732,11 @@ static void __timer_read_normal_func(void *data) static void __check_audio_format() { - vcp_audio_type_e type; + vce_audio_type_e type; int rate; int channel; - int ret = vcd_engine_get_audio_format(VCP_AUDIO_ID_NONE, &type, &rate, &channel); + int ret = vcd_engine_get_audio_format(VCE_AUDIO_ID_NONE, &type, &rate, &channel); if (0 != ret) { SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to get audio format : %d", ret); return; @@ -763,8 +764,8 @@ static void __check_audio_format() } switch (type) { - case VCP_AUDIO_TYPE_PCM_S16_LE: audio_type = AUDIO_SAMPLE_TYPE_S16_LE; break; - case VCP_AUDIO_TYPE_PCM_U8: audio_type = AUDIO_SAMPLE_TYPE_U8; break; + case VCE_AUDIO_TYPE_PCM_S16_LE: audio_type = AUDIO_SAMPLE_TYPE_S16_LE; break; + case VCE_AUDIO_TYPE_PCM_U8: audio_type = AUDIO_SAMPLE_TYPE_U8; break; default: SLOG(LOG_ERROR, TAG_VCD, "[Recorder ERROR] Invalid Audio Type"); return; @@ -805,7 +806,7 @@ int vcd_recorder_start() SLOG(LOG_DEBUG, TAG_VCD, "[Recorder] audio type : %s", g_current_audio_type); if (NULL != g_current_audio_type) { - if (0 == strncmp(VCP_AUDIO_ID_BLUETOOTH, g_current_audio_type, strlen(VCP_AUDIO_ID_BLUETOOTH))) { + if (0 == strncmp(VCE_AUDIO_ID_BLUETOOTH, g_current_audio_type, strlen(VCE_AUDIO_ID_BLUETOOTH))) { #ifdef TV_BT_MODE const unsigned char input_data[2] = {SMART_CONTROL_START_CMD, 0x00}; int bt_retry = 0; @@ -830,7 +831,7 @@ int vcd_recorder_start() g_bt_extend_count = 0; #endif - } else if (0 == strncmp(VCP_AUDIO_ID_MSF, g_current_audio_type, strlen(VCP_AUDIO_ID_MSF))) { + } else if (0 == strncmp(VCE_AUDIO_ID_WIFI, g_current_audio_type, strlen(VCE_AUDIO_ID_WIFI))) { SLOG(LOG_DEBUG, TAG_VCD, "[Recorder] call RegisterMSFAudioCallback() function"); #ifdef TV_MSF_WIFI_MODE @@ -839,7 +840,7 @@ int vcd_recorder_start() if (MSFResult_OK == ret) { started = true; } else { - SLOG(LOG_ERROR, TAG_VCD, "[Recorder ERROR] Fail to start MSF(wifi) audio"); + SLOG(LOG_ERROR, TAG_VCD, "[Recorder ERROR] Fail to start Wi-Fi audio"); return VCD_ERROR_OPERATION_FAILED; } #endif @@ -928,7 +929,7 @@ int vcd_recorder_stop() bool stoped = false; if (NULL != g_current_audio_type) { - if (0 == strncmp(VCP_AUDIO_ID_BLUETOOTH, g_current_audio_type, strlen(VCP_AUDIO_ID_BLUETOOTH))) { + if (0 == strncmp(VCE_AUDIO_ID_BLUETOOTH, g_current_audio_type, strlen(VCE_AUDIO_ID_BLUETOOTH))) { #ifdef TV_BT_MODE int bt_retry = 0; while (5 > bt_retry) { @@ -946,10 +947,10 @@ int vcd_recorder_stop() } } if (NULL != g_current_audio_type && - (!strncmp(g_current_audio_type, VCP_AUDIO_ID_BLUETOOTH, sizeof(VCP_AUDIO_ID_BLUETOOTH)) || - !strncmp(g_current_audio_type, VCP_AUDIO_ID_MSF, sizeof(VCP_AUDIO_ID_MSF)))) { + (!strncmp(g_current_audio_type, VCE_AUDIO_ID_BLUETOOTH, sizeof(VCE_AUDIO_ID_BLUETOOTH)) || + !strncmp(g_current_audio_type, VCE_AUDIO_ID_WIFI, sizeof(VCE_AUDIO_ID_WIFI)))) { SLOG(LOG_DEBUG, TAG_VCD, "[DEBUG] Recorder reset to NONE"); - vcd_recorder_set(VCP_AUDIO_ID_NONE, g_audio_type, g_audio_rate, g_audio_channel); + vcd_recorder_set(VCE_AUDIO_ID_NONE, g_audio_type, g_audio_rate, g_audio_channel); } if (false == stoped) { @@ -957,14 +958,14 @@ int vcd_recorder_stop() return VCD_ERROR_OPERATION_FAILED; } #endif - } else if (0 == strncmp(VCP_AUDIO_ID_MSF, g_current_audio_type, strlen(VCP_AUDIO_ID_MSF))) { + } else if (0 == strncmp(VCE_AUDIO_ID_WIFI, g_current_audio_type, strlen(VCE_AUDIO_ID_WIFI))) { #ifdef TV_MSF_WIFI_MODE UnRegisterMSFAudioCallback(); if (NULL != g_current_audio_type && - (!strncmp(g_current_audio_type, VCP_AUDIO_ID_BLUETOOTH, sizeof(VCP_AUDIO_ID_BLUETOOTH)) || - !strncmp(g_current_audio_type, VCP_AUDIO_ID_MSF, sizeof(VCP_AUDIO_ID_MSF)))) { + (!strncmp(g_current_audio_type, VCE_AUDIO_ID_BLUETOOTH, sizeof(VCE_AUDIO_ID_BLUETOOTH)) || + !strncmp(g_current_audio_type, VCE_AUDIO_ID_WIFI, sizeof(VCE_AUDIO_ID_WIFI)))) { SLOG(LOG_DEBUG, TAG_VCD, "[DEBUG] Recorder reset to NONE"); - vcd_recorder_set(VCP_AUDIO_ID_NONE, g_audio_type, g_audio_rate, g_audio_channel); + vcd_recorder_set(VCE_AUDIO_ID_NONE, g_audio_type, g_audio_rate, g_audio_channel); } stoped = true; #endif diff --git a/server/vcd_recorder.h b/server/vcd_recorder.h index dafef24..a061d2a 100644 --- a/server/vcd_recorder.h +++ b/server/vcd_recorder.h @@ -23,7 +23,6 @@ extern "C" { #endif -#include "voice_control_plugin_engine.h" typedef enum { VCD_RECORDER_STATE_READY, /**< Recorder is ready to start */ @@ -40,7 +39,7 @@ int vcd_recorder_create(vcd_recoder_audio_cb audio_cb, vcd_recorder_interrupt_cb int vcd_recorder_destroy(); -int vcd_recorder_set(const char* audio_type, vcp_audio_type_e type, int rate, int channel); +int vcd_recorder_set(const char* audio_type, vce_audio_type_e type, int rate, int channel); int vcd_recorder_get(char** audio_type); diff --git a/server/vcd_server.c b/server/vcd_server.c index 4eb3db0..58d6d7d 100755 --- a/server/vcd_server.c +++ b/server/vcd_server.c @@ -36,8 +36,6 @@ /* * VC Server static variable */ -static bool g_is_engine; - static GList *g_proc_list = NULL; static Ecore_Timer *g_restart_timer = NULL; @@ -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); @@ -425,30 +423,29 @@ 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) { 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; + return VCD_ERROR_NONE; } -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) @@ -457,30 +454,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, 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(); @@ -489,13 +495,14 @@ 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 @@ -503,7 +510,6 @@ 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 @"); - int ret = -1; vc_cmd_s* temp_cmd = NULL; vc_cmd_list_h vc_cmd_list = NULL; @@ -512,7 +518,7 @@ 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 */ @@ -521,7 +527,7 @@ static void __vcd_server_result_cb(vcp_result_event_e event, int* result_id, int 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; @@ -591,7 +597,7 @@ static void __vcd_server_result_cb(vcp_result_event_e event, int* result_id, int free(filtered_id); filtered_id = NULL; } - return; + return VCD_ERROR_NONE; } } } @@ -699,7 +705,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(); @@ -739,7 +745,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 */ @@ -890,7 +896,7 @@ 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) { SECURE_SLOG(LOG_DEBUG, TAG_VCD, "[Server] NLU result cb - event(%d)", event); SECURE_SLOG(LOG_DEBUG, TAG_VCD, "[Server] result (%s)", nlu_result); @@ -904,7 +910,7 @@ 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); @@ -923,12 +929,12 @@ static void __vcd_server_error_cb(vcp_error_e error, const char* msg, void *user error_msg = NULL; } - return; + return VCD_ERROR_NONE; } /* - * vcd server Interfaces - */ +* vcd server Interfaces +*/ static void __vcd_file_clean_up() { SLOG(LOG_DEBUG, TAG_VCD, "== Old file clean up == "); @@ -978,7 +984,7 @@ static int __vcd_db_clean_up() return ret; } -int vcd_initialize() +int vcd_initialize(vce_request_callback_s *callback) { int ret = 0; @@ -999,8 +1005,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_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; @@ -1011,21 +1016,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; } @@ -1317,20 +1309,10 @@ int vcd_server_get_foreground() /* - * 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()); @@ -1431,7 +1413,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; @@ -1933,25 +1915,13 @@ int vcd_server_mgr_disable_command_type(int pid, int cmd_type) } /* - * 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 */ @@ -2250,25 +2220,13 @@ int vcd_server_request_cancel(int 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 */ @@ -2471,3 +2429,153 @@ int vcd_server_set_language(const char* language) 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; +} + diff --git a/server/vcd_server.h b/server/vcd_server.h index 14fcbd2..b328a7e 100644 --- a/server/vcd_server.h +++ b/server/vcd_server.h @@ -21,6 +21,8 @@ #include "vcd_main.h" #include "vcd_client_data.h" +#include "vce.h" + #ifdef __cplusplus extern "C" { #endif @@ -28,7 +30,7 @@ extern "C" { /* * Daemon functions */ -int vcd_initialize(); +int vcd_initialize(vce_request_callback_s *callback); void vcd_finalize(); @@ -124,6 +126,38 @@ int vcd_server_widget_enable_asr_result(int pid, bool enable); int vcd_server_set_language(const char* language); +/* +* For engine service +*/ +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 vcd_send_asr_result(vce_asr_result_event_e event, const char* asr_result, void *user_data); + +int vcd_send_nlg_result(const char* nlg_result, void *user_data); + +int vcd_send_error(vce_error_e error, const char* msg, void *user_data); + +int vcd_get_foreach_command(vce_cmd_h vce_command, vce_command_cb callback, void* user_data); + +int vcd_get_command_count(vce_cmd_h vce_command); + +int vcd_get_audio_type(char** audio_type); + +int vcd_set_private_data(const char* key, const char* data); + +int vcd_get_private_data(const char* key, char** data); + +int vcd_start_recording(); + +int vcd_stop_recording(); + +int vcd_set_private_data_set_cb(vce_private_data_set_cb callback_func); + +int vcd_set_private_data_requested_cb(vce_private_data_requested_cb callback_func); + +int vcd_set_nlu_base_info_requested_cb(vce_nlu_base_info_requested_cb callback_func); + + #ifdef __cplusplus } #endif diff --git a/server/vce.c b/server/vce.c new file mode 100755 index 0000000..b7fb585 --- /dev/null +++ b/server/vce.c @@ -0,0 +1,262 @@ +/* +* Copyright (c) 2011-2017 Samsung Electronics Co., Ltd All Rights Reserved +* +* Licensed under the Apache License, Version 2.0 (the License); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an AS IS BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + + +#include "vcd_dbus.h" +#include "vcd_main.h" +#include "vcd_server.h" + +#include "vce.h" + + +int vce_main(int argc, char** argv, vce_request_callback_s *callback) +{ + SLOG(LOG_DEBUG, TAG_VCD, " "); + SLOG(LOG_DEBUG, TAG_VCD, " "); + SLOG(LOG_DEBUG, TAG_VCD, "===== VC Engine Service Initialize"); + + int ret = VCE_ERROR_NONE; + + if (!ecore_init()) { + SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail ecore_init()"); + return VCE_ERROR_OPERATION_FAILED; + } + + if (0 != vcd_dbus_open_connection()) { + SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to open connection"); + ecore_shutdown(); + return VCE_ERROR_OPERATION_FAILED; + } + + ret = vcd_initialize(callback); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to initialize"); + vcd_dbus_close_connection(); + ecore_shutdown(); + return ret; + } + + SLOG(LOG_DEBUG, TAG_VCD, "[Main] VC Engine Service start..."); + + SLOG(LOG_DEBUG, TAG_VCD, "====="); + SLOG(LOG_DEBUG, TAG_VCD, " "); + SLOG(LOG_DEBUG, TAG_VCD, " "); + + return 0; +} + +int vce_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 = VCE_ERROR_NONE; + + if (NULL == all_result || NULL == non_fixed_result || NULL == nlu_result) { + SLOG(LOG_ERROR, TAG_VCD, "[INFO] Input parameter is NULL. (no result)"); + } + + ret = vcd_send_result(event, result_id, count, all_result, non_fixed_result, nlu_result, msg, user_info, user_data); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to send result"); + } else { + SLOG(LOG_INFO, TAG_VCD, "[INFO] Success to send result"); + } + + return ret; +} + + +int vce_send_asr_result(vce_asr_result_event_e event, const char* asr_result, void *user_data) +{ + int ret = VCE_ERROR_NONE; + + if (NULL == asr_result) { + SLOG(LOG_ERROR, TAG_VCD, "[INFO] Input parameter is NULL. (no result)"); + } + + ret = vcd_send_asr_result(event, asr_result, user_data); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to send ASR result"); + } else { + SLOG(LOG_INFO, TAG_VCD, "[INFO] Success to send ASR result"); + } + + return ret; +} + +int vce_send_nlg_result(const char* nlg_result, void *user_data) +{ + int ret = VCE_ERROR_NONE; + + if (NULL == nlg_result) { + SLOG(LOG_ERROR, TAG_VCD, "[INFO] Input parameter is NULL. (no result)"); + } + + ret = vcd_send_nlg_result(nlg_result, user_data); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to send NLG result"); + } else { + SLOG(LOG_INFO, TAG_VCD, "[INFO] Success to send NLG result"); + } + + return ret; +} + +int vce_send_error(vce_error_e error, const char* msg, void *user_data) +{ + int ret = VCE_ERROR_NONE; + + if (NULL == msg) { + SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Input parameter is NULL. (no error message)"); + } + + ret = vcd_send_error(error, msg, user_data); + + if (0 != ret) { + SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to send error"); + } + + return ret; +} + + +/* Daemon API */ +int vce_get_foreach_command(vce_cmd_h vce_command, vce_command_cb callback, void* user_data) +{ + int ret = VCE_ERROR_NONE; + + ret = vcd_get_foreach_command(vce_command, callback, user_data); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to get foreach command"); + } + + return ret; +} + +int vce_get_command_count(vce_cmd_h vce_command) +{ + int ret = VCE_ERROR_NONE; + + ret = vcd_get_command_count(vce_command); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to get command count"); + } + + return ret; +} + +int vce_get_audio_type(char** audio_type) +{ + int ret = VCE_ERROR_NONE; + + ret = vcd_get_audio_type(audio_type); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to get audio type"); + } + + return ret; +} + +int vce_set_private_data(const char* key, const char* data) +{ + int ret = VCE_ERROR_NONE; + + ret = vcd_set_private_data(key, data); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to set private data to vc manager"); + } + + return ret; +} + +int vce_get_private_data(const char* key, char** data) +{ + int ret = VCE_ERROR_NONE; + + ret = vcd_get_private_data(key, data); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to get private data from vc manager"); + } + + return ret; +} + +int vce_start_recording() +{ + int ret = VCE_ERROR_NONE; + + ret = vcd_start_recording(); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to start recording"); + } + + return ret; +} + +int vce_stop_recording() +{ + int ret = VCE_ERROR_NONE; + + ret = vcd_stop_recording(); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to stop recording"); + } + + return ret; +} + +int vce_set_private_data_set_cb(vce_private_data_set_cb callback_func) +{ + if (NULL == callback_func) { + SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Invalid parameter"); + return VCE_ERROR_INVALID_PARAMETER; + } + + int ret = vcd_set_private_data_set_cb(callback_func); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to set private data set cb"); + } + + return ret; +} + +int vce_set_private_data_requested_cb(vce_private_data_requested_cb callback_func) +{ + if (NULL == callback_func) { + SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Invalid parameter"); + return VCE_ERROR_INVALID_PARAMETER; + } + + int ret = vcd_set_private_data_requested_cb(callback_func); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to set private data requested cb"); + } + + return ret; +} + +int vce_set_nlu_base_info_requested_cb(vce_nlu_base_info_requested_cb callback_func) +{ + if (NULL == callback_func) { + SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Invalid parameter"); + return VCE_ERROR_INVALID_PARAMETER; + } + + int ret = vcd_set_nlu_base_info_requested_cb(callback_func); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to set nlu-base info requested cb"); + } + + return ret; +} -- 2.7.4 From 9238d18e9839520e511818a977aa59d593e7590c Mon Sep 17 00:00:00 2001 From: sungrae jo Date: Fri, 23 Feb 2018 16:25:29 +0900 Subject: [PATCH 16/16] Fixed terminate issue for voice control engine Change-Id: Ic751d9201a970c8ad9df2de5b2916c39f693b2c4 Signed-off-by: sungrae jo --- server/vcd_engine_agent.c | 5 ++++- server/vcd_recorder.c | 4 +++- server/vcd_server.c | 23 +++++++++++++++-------- server/vcd_server.h | 2 +- 4 files changed, 23 insertions(+), 11 deletions(-) diff --git a/server/vcd_engine_agent.c b/server/vcd_engine_agent.c index 1f4c585..4b562b3 100644 --- a/server/vcd_engine_agent.c +++ b/server/vcd_engine_agent.c @@ -120,7 +120,10 @@ int vcd_engine_agent_release() } /* unload current engine */ - vcd_engine_agent_unload_current_engine(); + if (0 != vcd_engine_agent_unload_current_engine()) { + SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Fail to deinitialize"); + return VCD_ERROR_OPERATION_FAILED; + } /* release current engine data */ if (NULL != g_dynamic_engine.callbacks) { diff --git a/server/vcd_recorder.c b/server/vcd_recorder.c index f3194d4..eea8f50 100644 --- a/server/vcd_recorder.c +++ b/server/vcd_recorder.c @@ -483,7 +483,9 @@ int vcd_recorder_destroy() if (0 != ret) SLOG(LOG_ERROR, TAG_VCD, "[Recorder ERROR] Fail to destroy stream info, ret(%d)", ret); - audio_in_destroy(g_audio_h); + ret = audio_in_destroy(g_audio_h); + if (0 != ret) + SLOG(LOG_ERROR, TAG_VCD, "[Recorder ERROR] Fail to audio in destroy, ret(%d)", ret); #ifdef TV_BT_MODE bt_hid_unset_audio_data_receive_cb(); diff --git a/server/vcd_server.c b/server/vcd_server.c index 58d6d7d..688e21d 100755 --- a/server/vcd_server.c +++ b/server/vcd_server.c @@ -1033,7 +1033,7 @@ int vcd_initialize(vce_request_callback_s *callback) return 0; } -void vcd_finalize() +bool vcd_finalize() { GList *iter = NULL; if (0 < g_list_length(g_proc_list)) { @@ -1056,14 +1056,17 @@ void vcd_finalize() } vcd_engine_recognize_cancel(); } + if (0 != vcd_recorder_destroy()) { SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to destroy recorder"); + return false; } else { SLOG(LOG_DEBUG, TAG_VCD, "[Server] destroy recorder"); } if (0 != vcd_engine_agent_release()) { SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to release engine"); + return false; } else { SLOG(LOG_DEBUG, TAG_VCD, "[Server] release engine"); } @@ -1075,14 +1078,18 @@ void vcd_finalize() SLOG(LOG_ERROR, TAG_VCD, "[Server] mode finalize"); - return; + return true; } static Eina_Bool __finalize_quit_ecore_loop(void *data) { - SLOG(LOG_ERROR, TAG_VCD, "[Server] quit ecore main loop"); - ecore_main_loop_quit(); - return EINA_FALSE; + bool ret = vcd_finalize(); + if (false == ret) { + return EINA_TRUE; + } else { + ecore_main_loop_quit(); + return EINA_FALSE; + } } static void __read_proc() @@ -1355,7 +1362,7 @@ 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_ERROR, TAG_VCD, "[Server Success] Manager Finalize : pid(%d)", pid); @@ -1956,7 +1963,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); @@ -2270,7 +2277,7 @@ int vcd_server_widget_finalize(int pid) 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; } diff --git a/server/vcd_server.h b/server/vcd_server.h index b328a7e..6df0154 100644 --- a/server/vcd_server.h +++ b/server/vcd_server.h @@ -32,7 +32,7 @@ extern "C" { */ int vcd_initialize(vce_request_callback_s *callback); -void vcd_finalize(); +bool vcd_finalize(); Eina_Bool vcd_cleanup_client_all(void *data); -- 2.7.4