* limitations under the License.
*/
+#include <app_control.h>
+#include <app_manager.h>
#include <dirent.h>
#include <sound_manager.h>
+#include "vc_cmd_db.h"
#include "vc_info_parser.h"
#include "vcd_main.h"
#include "vcd_server.h"
#include "vcd_dbus.h"
#include "voice_control_command_expand.h"
+#include "voice_control_common.h"
/*
* VC Server static variable
*/
-static bool g_is_engine;
-
static GList *g_proc_list = NULL;
static Ecore_Timer *g_restart_timer = NULL;
+static Ecore_Timer *g_check_widget_client_timer = NULL;
+
+/**
+* @brief Enumerations of send event type.
+*/
+typedef enum {
+ VCD_SEND_EVENT_TYPE_TEXT, /**< send text event to vc engine*/
+ VCD_SEND_EVENT_TYPE_LIST_EVENT, /**< send list event to vc engine */
+ VCD_SEND_EVENT_TYPE_HAPTIC_EVENT /**< send haptic event to vc engine */
+} vcd_send_event_type_e;
+
+static int __vcd_server_launch_manager_app();
/*
* VC Server Internal Functions
*/
static Eina_Bool __stop_by_silence(void *data)
{
- SLOG(LOG_DEBUG, TAG_VCD, "===== Silence Detected ");
+ SLOG(LOG_DEBUG, TAG_VCD, "@@@ Silence Detected ");
vcd_server_mgr_stop();
- SLOG(LOG_DEBUG, TAG_VCD, "=====");
- SLOG(LOG_DEBUG, TAG_VCD, " ");
+ SLOG(LOG_DEBUG, TAG_VCD, "@@@");
return EINA_FALSE;
}
static Eina_Bool __cancel_by_interrupt(void *data)
{
- SLOG(LOG_DEBUG, TAG_VCD, "===== Cancel by interrupt");
+ SLOG(LOG_DEBUG, TAG_VCD, "@@@ Cancel by interrupt");
vcd_server_mgr_cancel();
- SLOG(LOG_DEBUG, TAG_VCD, "=====");
- SLOG(LOG_DEBUG, TAG_VCD, " ");
+ SLOG(LOG_DEBUG, TAG_VCD, "@@@");
return EINA_FALSE;
}
+static void __cancel_by_error(void *data)
+{
+ SLOG(LOG_DEBUG, TAG_VCD, "@@@ Cancel by error");
+
+ vcd_server_mgr_cancel();
+
+ SLOG(LOG_DEBUG, TAG_VCD, "@@@");
+ return;
+}
+
static Eina_Bool __restart_engine(void *data)
{
- SLOG(LOG_DEBUG, TAG_VCD, "===== Restart by no result");
+ SLOG(LOG_DEBUG, TAG_VCD, "@@@ Restart by no result");
g_restart_timer = NULL;
SLOG(LOG_DEBUG, TAG_VCD, "[Server Success] Restart recognition");
- SLOG(LOG_DEBUG, TAG_VCD, "=====");
- SLOG(LOG_DEBUG, TAG_VCD, " ");
+ SLOG(LOG_DEBUG, TAG_VCD, "@@@");
return EINA_FALSE;
}
static int __server_recorder_callback(const void* data, const unsigned int length)
{
vcd_state_e state = vcd_config_get_service_state();
- if (VCD_STATE_RECORDING != state) {
- SLOG(LOG_DEBUG, TAG_VCD, "[Server] Not recording state, but recording");
-// return 0;
+ if (VCD_STATE_READY == state) {
+ SLOG(LOG_DEBUG, TAG_VCD, "[Server] Ready state, but recording");
+ } else if (VCD_STATE_PROCESSING == state) {
+ return 0;
}
- vcp_speech_detect_e speech_detected = VCP_SPEECH_DETECT_NONE;
+ vce_speech_detect_e speech_detected = VCE_SPEECH_DETECT_NONE;
int ret;
ret = vcd_engine_recognize_audio(data, length, &speech_detected);
SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to set recording data to engine(%d)", ret);
ecore_timer_add(0, __cancel_by_interrupt, NULL);
/* Send error cb to manager */
- if (VCP_ERROR_OUT_OF_NETWORK == ret) {
+ if (VCE_ERROR_OUT_OF_NETWORK == ret) {
vcdc_send_error_signal_to_manager(vcd_client_manager_get_pid(), VCD_ERROR_TIMED_OUT, "Engine connection failed");
} else {
vcdc_send_error_signal_to_manager(vcd_client_manager_get_pid(), VCD_ERROR_OPERATION_FAILED, "Engine recognition failed");
return 0;
}
- if (VCP_SPEECH_DETECT_BEGIN == speech_detected) {
+ if (VCE_SPEECH_DETECT_BEGIN == speech_detected) {
if (-1 != vcd_client_manager_get_pid()) {
/* Manager client is available */
if (0 != vcdc_send_speech_detected(vcd_client_manager_get_pid())) {
SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Fail to send speech detected");
}
}
- } else if (VCP_SPEECH_DETECT_END == speech_detected) {
+ } else if (VCE_SPEECH_DETECT_END == speech_detected) {
if (VCD_RECOGNITION_MODE_STOP_BY_SILENCE == vcd_client_get_recognition_mode()) {
/* silence detected */
ecore_timer_add(0, __stop_by_silence, NULL);
void __server_recorder_interrupt_callback()
{
- SLOG(LOG_DEBUG, TAG_VCD, "===== Cancel by sound interrupt");
+ SLOG(LOG_DEBUG, TAG_VCD, "@@@ Cancel by sound interrupt");
ecore_timer_add(0, __cancel_by_interrupt, NULL);
- SLOG(LOG_DEBUG, TAG_VCD, "=====");
- SLOG(LOG_DEBUG, TAG_VCD, " ");
+ SLOG(LOG_DEBUG, TAG_VCD, "@@@");
}
static void __config_lang_changed_cb(const char* current_lang, void* user_data)
{
- SLOG(LOG_DEBUG, TAG_VCD, "===== Change language ");
+ SLOG(LOG_DEBUG, TAG_VCD, "@@@ Change language ");
/* Current state is recording */
vcd_state_e state = vcd_config_get_service_state();
SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to set language of engine : %d", ret);
}
- SLOG(LOG_DEBUG, TAG_VCD, "=====");
- SLOG(LOG_DEBUG, TAG_VCD, " ");
+ SLOG(LOG_DEBUG, TAG_VCD, "@@@");
return;
}
static void __config_foreground_changed_cb(int previous, int current, void* user_data)
{
- SLOG(LOG_DEBUG, TAG_VCD, "===== Change foreground");
+ SLOG(LOG_DEBUG, TAG_VCD, "@@@ Change foreground");
SLOG(LOG_DEBUG, TAG_VCD, "Foreground pid(%d)", current);
}
}
- SLOG(LOG_DEBUG, TAG_VCD, "=====");
- SLOG(LOG_DEBUG, TAG_VCD, " ");
+ SLOG(LOG_DEBUG, TAG_VCD, "@@@");
return;
}
+static int __vcd_activate_app_by_appcontrol(const char* appid)
+{
+ if (NULL == appid) {
+ SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Invalid parameter");
+ return VCD_ERROR_INVALID_PARAMETER;
+ }
+
+ int ret = -1;
+ app_control_h app_control = NULL;
+ ret = app_control_create(&app_control);
+ if (APP_CONTROL_ERROR_NONE == ret) {
+ // Set extra data
+ ret = app_control_add_extra_data(app_control, "voice_launch", "get_result");
+ if (APP_CONTROL_ERROR_NONE != ret) {
+ SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to add extra data, ret(%d)", ret);
+ app_control_destroy(app_control);
+ return VCD_ERROR_OPERATION_FAILED;
+ }
+ // Set an app ID.
+ ret = app_control_set_app_id(app_control, appid);
+ if (APP_CONTROL_ERROR_NONE != ret) {
+ SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to set app id, ret(%d)", ret);
+ app_control_destroy(app_control);
+ return VCD_ERROR_OPERATION_FAILED;
+ }
+ // Sent launch request
+ ret = app_control_send_launch_request(app_control, NULL, NULL);
+ if (APP_CONTROL_ERROR_NONE != ret) {
+ SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to send launch request, ret(%d)", ret);
+ app_control_destroy(app_control);
+ return VCD_ERROR_OPERATION_FAILED;
+ }
+ // Destroy app control
+ ret = app_control_destroy(app_control);
+ if (APP_CONTROL_ERROR_NONE != ret) {
+ SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to destroy, ret(%d)", ret);
+ return VCD_ERROR_OPERATION_FAILED;
+ }
+ }
+ return VCD_ERROR_NONE;
+}
+
+static int __vcd_resume_app(const char* appid)
+{
+ app_context_h app_context = NULL;
+ int ret = app_manager_get_app_context(appid, &app_context);
+ if (APP_MANAGER_ERROR_NONE != ret) {
+ SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to get app_context, ret(%d), appid(%s)", ret, appid);
+ return VCD_ERROR_OPERATION_FAILED;
+ }
+
+ ret = app_manager_resume_app(app_context);
+ if (APP_MANAGER_ERROR_NONE != ret) {
+ SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to resume app, ret(%d), appid(%s)", ret, appid);
+ return VCD_ERROR_OPERATION_FAILED;
+ }
+ return VCD_ERROR_NONE;
+}
+
+static bool __vcd_is_package_installed(const char* appid)
+{
+ app_info_h app_info = NULL;
+ int ret = app_manager_get_app_info(appid, &app_info);
+ if (APP_MANAGER_ERROR_NONE != ret || NULL == app_info)
+ return false;
+ ret = app_info_destroy(app_info);
+ if (APP_MANAGER_ERROR_NONE != ret)
+ SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to destroy app_info, ret(%d)", ret);
+ return true;
+}
+
+static bool __vcd_launch_app(const char* result)
+{
+ if (NULL == result) {
+ SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Invalid parameter");
+ return VCD_ERROR_INVALID_PARAMETER;
+ }
+
+ GSList* app_list = NULL;
+ if (0 != vc_db_get_appid_list(result, &app_list)) {
+ SLOG(LOG_ERROR, TAG_VCD, "[ERROR] result text is NULL");
+ return VCD_ERROR_INVALID_PARAMETER;
+ }
+
+ if (0 != g_slist_length(app_list)) {
+ /* releaes data */
+ GSList *iter = NULL;
+ vc_deactivated_app_s* temp_app = NULL;
+ iter = g_slist_nth(app_list, 0);
+
+ while (NULL != iter) {
+ temp_app = iter->data;
+
+ if (NULL != temp_app) {
+ if (NULL != temp_app->appid) {
+ int ret = -1;
+ bool running = false;
+ ret = app_manager_is_running(temp_app->appid, &running);
+ if (APP_MANAGER_ERROR_NONE != ret) {
+ SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to check running with appid(%s)", temp_app->appid);
+ free(temp_app->appid);
+ temp_app->appid = NULL;
+ free(temp_app);
+ temp_app = NULL;
+ return VCD_ERROR_OPERATION_FAILED;
+ }
+ if (false == running) {
+ int tmp_ret = __vcd_is_package_installed(temp_app->appid);
+ if (false == tmp_ret) {
+ SLOG(LOG_WARN, TAG_VCD, "[WARNING] app is not installed, appid(%s)", temp_app->appid);
+ } else {
+ ret = __vcd_activate_app_by_appcontrol(temp_app->appid);
+ if (0 != ret) {
+ SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to activate app");
+ free(temp_app->appid);
+ temp_app->appid = NULL;
+ free(temp_app);
+ temp_app = NULL;
+ return ret;
+ }
+ SLOG(LOG_ERROR, TAG_VCD, "Launch app: appid(%s) result(%s)", temp_app->appid, result);
+ }
+ } else {
+ ret = __vcd_resume_app(temp_app->appid);
+ if (0 != ret) {
+ SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to resume app");
+ free(temp_app->appid);
+ temp_app->appid = NULL;
+ free(temp_app);
+ temp_app = NULL;
+ return ret;
+ }
+ SLOG(LOG_ERROR, TAG_VCD, "Resume app: appid(%s) result(%s)", temp_app->appid, result);
+ }
+ free(temp_app->appid);
+ temp_app->appid = NULL;
+ }
+ free(temp_app);
+ temp_app = NULL;
+ }
+ iter = g_slist_next(iter);
+ }
+ app_list = NULL;
+ }
+
+ return VCD_ERROR_NONE;
+}
+
static Eina_Bool __vcd_send_selected_result(void *data)
{
GSList* pid_list = NULL;
- if (0 != vc_info_parser_get_result_pid_list(&pid_list)) {
+ const char* result = vcd_client_manager_get_result_text();
+
+ if (0 != vc_info_parser_get_result_pid_list(&pid_list, result)) {
SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Fail to get pid list. No result");
} else {
if (0 < g_slist_length(pid_list)) {
GSList* iter = NULL;
vc_cmd_s* temp_cmd = NULL;
int ret = 0;
- int count = 0;
+ int pre_pid = -1;
+ int pre_type = -1;
iter = g_slist_nth(pid_list, 0);
while (NULL != iter) {
temp_cmd = iter->data;
- if (NULL != temp_cmd) {
- count = 0;
- do {
+ if (NULL != temp_cmd && (pre_pid != temp_cmd->pid || pre_type == VC_COMMAND_TYPE_WIDGET || temp_cmd->type == VC_COMMAND_TYPE_WIDGET)) {
+ /* Launch deactivated several apps that is matched with result */
+ ret = __vcd_launch_app(result);
+ if (0 != ret) {
+ SLOG(LOG_ERROR, TAG_VCD, "Fail to launch or resume app, ret(%d) result(%s)", ret, result);
+ } else {
/* send result noti */
- ret = vcdc_send_result(temp_cmd->pid, temp_cmd->type);
+ ret = vcdc_send_result(temp_cmd->pid, vcd_client_manager_get_pid(), temp_cmd->type);
if (0 != ret) {
- SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Fail to send result");
- if (VCD_ERROR_TIMED_OUT != ret) {
- break;
- }
+ SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Fail to send result, ret(%d)", ret);
+ break;
} else {
- SLOG(LOG_DEBUG, TAG_VCD, "[Server] Send result : pid(%d) type(%d)", temp_cmd->pid, temp_cmd->type);
+ SLOG(LOG_ERROR, TAG_VCD, "[Server] Send result : pid(%d) type(%d)", temp_cmd->pid, temp_cmd->type);
+ pre_pid = temp_cmd->pid;
+ pre_type = temp_cmd->type;
}
- count++;
-
- if (100 == count) break;
- /* While is retry code */
- } while (0 != ret);
+ }
free(temp_cmd);
+ temp_cmd = NULL;
}
-
pid_list = g_slist_remove_link(pid_list, iter);
iter = g_slist_nth(pid_list, 0);
}
return EINA_FALSE;
}
-static int __convert_type_to_priority(vc_cmd_type_e type)
+int vcd_send_asr_result(vce_asr_result_event_e event, const char* asr_result, void *user_data)
{
- switch (type) {
- case VC_COMMAND_TYPE_NONE: return 0;
- case VC_COMMAND_TYPE_BACKGROUND: return 1;
- case VC_COMMAND_TYPE_FOREGROUND: return 2;
- case VC_COMMAND_TYPE_WIDGET: return 2;
- case VC_COMMAND_TYPE_SYSTEM: return 3;
- case VC_COMMAND_TYPE_EXCLUSIVE: return 3;
- default: return 0;
+ int ret = __vcd_server_launch_manager_app();
+ if (0 != ret) {
+ SECURE_SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to send ASR result : mgr_pid(%d), asr_result(%s)", vcd_client_manager_get_pid(), asr_result);
+ return ret;
+ }
+
+ if (NULL != asr_result) {
+ SECURE_SLOG(LOG_DEBUG, TAG_VCD, "[Server] ASR result - Event(%d), Text(%s)", event, asr_result);
+ ret = vcdc_send_pre_result_to_manager(vcd_client_manager_get_pid(), event, asr_result);
+ if (0 != ret) {
+ SECURE_SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to send ASR result : mgr_pid(%d), asr_result(%s)", vcd_client_manager_get_pid(), asr_result);
+ }
}
+
+ return ret;
}
-static void __vcd_server_pre_result_cb(vcp_pre_result_event_e event, const char* pre_result, void* user_data)
+int vcd_send_nlg_result(const char* nlg_result, void *user_data)
{
- if (NULL != pre_result) {
- vcdc_send_pre_result_to_manager(vcd_client_manager_get_pid(), event, pre_result);
+ int ret = __vcd_server_launch_manager_app();
+ if (0 != ret) {
+ SECURE_SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to send dialog : mgr_pid(%d), nlg_result(%s)", vcd_client_manager_get_pid(), nlg_result);
+ return ret;
}
+
+ SLOG(LOG_ERROR, TAG_VCD, "[Server] send dialog : mgr_pid(%d), nlg_result(%s)", vcd_client_manager_get_pid(), nlg_result);
+ ret = vcdc_send_dialog(vcd_client_manager_get_pid(), -1, nlg_result, NULL, 0); //0: VC_DIALOG_END
+ if (0 != ret)
+ SECURE_SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to send dialog : mgr_pid(%d), nlg_result(%s)", vcd_client_manager_get_pid(), nlg_result);
+ return ret;
+}
+
+static void* __recorder_stop(void *data)
+{
+ vcd_recorder_stop();
+ return NULL;
}
-static void __vcd_server_result_cb(vcp_result_event_e event, int* result_id, int count, const char* all_result,
- const char* non_fixed_result, const char* msg, const char* nlp_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;
- }
- }
-
- // temp
- if (NULL != nlp_info) {
- if (0 != vc_info_parser_set_nlp_info(nlp_info)) {
- SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to save nlp info");
+ return VCD_ERROR_INVALID_STATE;
}
}
vc_info_parser_unset_result(vcd_client_manager_get_exclusive());
+ vcd_client_manager_set_result_text(all_result);
- SLOG(LOG_DEBUG, TAG_VCD, "[Server] Event(%d), Text(%s) Nonfixed(%s) Msg(%s) Result count(%d)",
+ SECURE_SLOG(LOG_INFO, TAG_VCD, "[Server] Event(%d), Text(%s) Nonfixed(%s) Msg(%s) Result count(%d)",
event, all_result, non_fixed_result, msg, count);
+ SLOG(LOG_ERROR, TAG_VCD, "[Server] NLU result(%s)", nlu_result);
+
if (VCD_RECOGNITION_MODE_RESTART_AFTER_REJECT == vcd_client_get_recognition_mode()) {
- if (VCP_RESULT_EVENT_REJECTED == event) {
+ if (VCE_RESULT_EVENT_REJECTED == event) {
SLOG(LOG_DEBUG, TAG_VCD, "[Server] Restart by no or rejected result");
/* If no result and restart option is ON */
/* Send reject message */
bool temp = vcd_client_manager_get_exclusive();
vc_info_parser_set_result(all_result, event, msg, NULL, temp);
- if (0 != vcdc_send_result_to_manager(vcd_client_manager_get_pid(), VC_RESULT_TYPE_NOTIFICATION)) {
+ ret = vcdc_send_result_to_manager(vcd_client_manager_get_pid(), VC_RESULT_TYPE_NOTIFICATION);
+ if (0 != ret) {
SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Fail to send result");
}
g_restart_timer = ecore_timer_add(0, __restart_engine, NULL);
- return;
+ return ret;
}
SLOG(LOG_DEBUG, TAG_VCD, "[Server] Stop recorder due to success");
- vcd_recorder_stop();
+ //vcd_recorder_stop();
+ ecore_main_loop_thread_safe_call_sync(__recorder_stop, NULL);
} else if (VCD_RECOGNITION_MODE_RESTART_CONTINUOUSLY == vcd_client_get_recognition_mode()) {
SLOG(LOG_DEBUG, TAG_VCD, "[Server] Restart continuously");
/* Restart option is ON */
g_restart_timer = ecore_timer_add(0, __restart_engine, NULL);
- if (VCP_RESULT_EVENT_REJECTED == event) {
+ if (VCE_RESULT_EVENT_REJECTED == event) {
bool temp = vcd_client_manager_get_exclusive();
vc_info_parser_set_result(all_result, event, msg, NULL, temp);
- if (0 != vcdc_send_result_to_manager(vcd_client_manager_get_pid(), VC_RESULT_TYPE_NOTIFICATION)) {
+ ret = vcdc_send_result_to_manager(vcd_client_manager_get_pid(), VC_RESULT_TYPE_NOTIFICATION);
+ if (0 != ret) {
SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Fail to send result");
}
- return;
+ return ret;
+ }
+ }
+#if 1
+ /* if nlu_result is exist, Add command handle(is_action) into result list */
+ /* Normal result */
+ SLOG(LOG_DEBUG, TAG_VCD, "[Server] @ Get engine result @");
+
+ vc_cmd_s* temp_cmd = NULL;
+ vc_cmd_list_h vc_cmd_list = NULL;
+
+ if (0 != vc_cmd_list_create(&vc_cmd_list)) {
+ SLOG(LOG_DEBUG, TAG_VCD, "[Server] Fail to create command list");
+ vcd_client_manager_set_exclusive(false);
+ vcd_config_set_service_state(VCD_STATE_READY);
+ vcdc_send_service_state(VCD_STATE_READY);
+ return VCD_ERROR_NONE;
+ }
+
+ /* priority filter */
+ /* system > exclusive > widget > foreground > system_background > background */
+ int i = 0;
+ int* filtered_id = (int*)calloc(count, sizeof(int));
+ if (!filtered_id) {
+ SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to allocate memory");
+ return VCD_ERROR_OUT_OF_MEMORY;
+ }
+ int filtered_count = 0;
+ int top_priority = VC_COMMAND_PRIORITY_BACKGROUND;
+ for (i = 0; i < count; i++) {
+ SLOG(LOG_INFO, TAG_VCD, "[Server] [%d] Result id(%d)", i, result_id[i]);
+
+ if (0 > result_id[i]) {
+ SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Result ID(%d) is NOT valid", result_id[i]);
+ continue;
+ }
+
+ ret = vcd_client_get_cmd_from_result_id(result_id[i], &temp_cmd);
+ if (0 == ret && NULL != temp_cmd) {
+ if (top_priority == temp_cmd->priority) {
+ filtered_id[filtered_count] = result_id[i];
+ filtered_count++;
+ } else if (top_priority > temp_cmd->priority) {
+ filtered_id[0] = result_id[i];
+ filtered_count = 1;
+ top_priority = temp_cmd->priority;
+ }
+
+ vc_cmd_destroy((vc_cmd_h)temp_cmd);
+ temp_cmd = NULL;
+ }
+ }
+
+ // ASR consume
+ if (top_priority >= VC_COMMAND_PRIORITY_WIDGET) {
+ int pid = vcd_client_widget_get_foreground_pid();
+ if (-1 != pid) {
+ if (NULL != all_result) {
+ vc_info_parser_set_result(all_result, event, msg, NULL, false);
+ bool enable = false;
+ vcd_client_widget_get_asr_result_enabled(pid, &enable);
+ if (true == enable) {
+ SLOG(LOG_DEBUG, TAG_VCD, "[Server] Send ASR result to Widget client");
+ bool is_consumed = false;
+ if (NULL != user_info) {
+ *user_info = 0x00;
+ }
+ if (0 != vcdc_send_asr_result(pid, event, all_result, VC_COMMAND_TYPE_WIDGET, &is_consumed)) {
+ SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to send asr result");
+ } else {
+ SLOG(LOG_DEBUG, TAG_VCD, "[Server] ASR result is consumed(%d)", is_consumed);
+ if (true == is_consumed) {
+ if (NULL != user_info) {
+ *user_info = 0x01;
+ SLOG(LOG_ERROR, TAG_VCD, "[Server] Send whether ASR result is consumed or not (%d)", *user_info);
+ }
+ vcdc_send_show_tooltip(pid, false);
+ if (-1 != vcd_client_manager_get_pid()) {
+ /* Manager client is available */
+ vc_info_parser_unset_result(false);
+ vc_info_parser_set_result(all_result, VC_RESULT_EVENT_RESULT_SUCCESS, msg, NULL, false);
+ if (0 != vcdc_send_result_to_manager(vcd_client_manager_get_pid(), VC_RESULT_TYPE_NOTIFICATION)) {
+ SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Fail to send result");
+ }
+ }
+
+ vcd_client_manager_set_exclusive(false);
+
+ vcd_config_set_service_state(VCD_STATE_READY);
+ vcdc_send_service_state(VCD_STATE_READY);
+ vc_cmd_list_destroy(vc_cmd_list, true);
+ if (NULL != filtered_id) {
+ free(filtered_id);
+ filtered_id = NULL;
+ }
+ return VCD_ERROR_NONE;
+ }
+ }
+ }
+ }
+ }
+ }
+
+ int is_action = 0;
+ for (i = 0; i < filtered_count; i++) {
+ SLOG(LOG_INFO, TAG_VCD, "[Server] [%d] Filtered Result id(%d)", i, filtered_id[i]);
+
+ if (filtered_id[i] < 0) {
+ SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Filtered ID(%d) is NOT valid", filtered_id[i]);
+ continue;
+ }
+
+ ret = vcd_client_get_cmd_from_result_id(filtered_id[i], &temp_cmd);
+ if (0 == ret && NULL != temp_cmd) {
+ switch (temp_cmd->format) {
+ case VC_CMD_FORMAT_FIXED:
+ case VC_CMD_FORMAT_FIXED_AND_VFIXED:
+ case VC_CMD_FORMAT_VFIXED_AND_FIXED:
+ case VC_CMD_FORMAT_PARTIAL:
+ case VC_CMD_FORMAT_FIXED_AND_NONFIXED:
+ case VC_CMD_FORMAT_NONFIXED_AND_FIXED:
+ break;
+ case VC_CMD_FORMAT_ACTION:
+ is_action = 1;
+ break;
+ default:
+ SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Unknown command type : %d", temp_cmd->type);
+ }
+
+ temp_cmd->id = i;
+ if (0 != vc_cmd_list_add(vc_cmd_list, (vc_cmd_h)temp_cmd)) {
+ SLOG(LOG_DEBUG, TAG_VCD, "Fail to add command to list");
+ vc_cmd_destroy((vc_cmd_h)temp_cmd);
+ temp_cmd = NULL;
+ }
+ } else {
+ SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] NOT found matached result(%d)", filtered_id[i]);
+ }
+ }
+
+ if (NULL != filtered_id) {
+ free(filtered_id);
+ filtered_id = NULL;
+ }
+
+ if (NULL != nlu_result) {
+ SECURE_SLOG(LOG_INFO, TAG_VCD, "[Server] NLU (%s)", nlu_result);
+ vc_info_parser_set_nlu_result(nlu_result);
+ if (0 == is_action) {
+ vc_cmd_h nlu_cmd;
+ if (0 != vc_cmd_create(&nlu_cmd)) {
+ SLOG(LOG_ERROR, TAG_VCD, "Fail to nlu cmd create");
+ } else {
+ if (0 != vc_cmd_set_type(nlu_cmd, VC_COMMAND_TYPE_SYSTEM)) {
+ SLOG(LOG_ERROR, TAG_VCD, "Fail to set type");
+ }
+ if (0 != vc_cmd_set_pid(nlu_cmd, vcd_client_manager_get_pid())) {
+ SLOG(LOG_ERROR, TAG_VCD, "Fail to set pid");
+ }
+ if (0 != vc_cmd_set_format(nlu_cmd, VC_CMD_FORMAT_ACTION)) {
+ SLOG(LOG_ERROR, TAG_VCD, "Fail to set format");
+ }
+ if (0 != vc_cmd_list_add(vc_cmd_list, nlu_cmd)) {
+ SLOG(LOG_ERROR, TAG_VCD, "Fail to add nlu cmd to list");
+ vc_cmd_destroy(nlu_cmd);
+ }
+ }
+ }
+ }
+
+ vc_cmd_print_list(vc_cmd_list);
+
+ SLOG(LOG_DEBUG, TAG_VCD, "[Server] @@@@");
+
+ int result_count = 0;
+ vc_cmd_list_get_count(vc_cmd_list, &result_count);
+
+ if (0 == result_count) {
+ /* No result */
+ if (NULL != all_result) {
+ SECURE_SLOG(LOG_DEBUG, TAG_VCD, "[Server] Engine result is no command : %s", all_result);
+ } else {
+ SLOG(LOG_DEBUG, TAG_VCD, "[Server] Engine result is NULL");
+ }
+ bool temp = vcd_client_manager_get_exclusive();
+ vc_info_parser_set_result(all_result, event, msg, NULL, temp);
+
+ int pid = vcd_client_widget_get_foreground_pid();
+ if (-1 != pid) {
+ SLOG(LOG_DEBUG, TAG_VCD, "[Server] Request tooltip hide");
+ /* Send to hide tooltip */
+ vcdc_send_show_tooltip(pid, false);
+ }
+
+ if (-1 != vcd_client_manager_get_pid()) {
+ /* Manager client is available */
+ if (0 != vcdc_send_result_to_manager(vcd_client_manager_get_pid(), VC_RESULT_TYPE_NORMAL)) {
+ SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Fail to send result");
+ }
+ }
+
+ vcd_client_manager_set_exclusive(false);
+
+ return VCD_ERROR_NONE;
+ } else {
+ if (false == vcd_client_manager_get_exclusive()) {
+ int pid = vcd_client_widget_get_foreground_pid();
+ if (-1 != pid) {
+ SLOG(LOG_DEBUG, TAG_VCD, "[Server] Request tooltip hide");
+ vcdc_send_show_tooltip(pid, false);
+ }
+
+ vc_info_parser_set_result(all_result, event, msg, vc_cmd_list, false);
+
+ if (-1 != vcd_client_manager_get_pid()) {
+ /* Manager client is available */
+ if (0 != vcdc_send_result_to_manager(vcd_client_manager_get_pid(), VC_RESULT_TYPE_NORMAL)) {
+ SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Fail to send result");
+ }
+ } else {
+ SLOG(LOG_DEBUG, TAG_VCD, "[Server] Manager is NOT available. Send result to client directly");
+ /* Send result to client */
+ ecore_timer_add(0, __vcd_send_selected_result, NULL);
+ }
+ } else {
+ /* exclusive command */
+ vc_info_parser_set_result(all_result, event, msg, vc_cmd_list, true);
+
+ if (-1 != vcd_client_manager_get_pid()) {
+ /* Manager client is available */
+ if (0 != vcdc_send_result_to_manager(vcd_client_manager_get_pid(), VC_RESULT_TYPE_NORMAL)) {
+ SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Fail to send result");
+ }
+ } else {
+ SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Manager is NOT available");
+ }
+
+ vcd_client_manager_set_exclusive(false);
}
}
+ vc_cmd_list_destroy(vc_cmd_list, true);
+
+ return VCD_ERROR_NONE;
+
+#else
/* No result */
if (NULL == result_id) {
/* No result */
if (-1 != pid) {
if (NULL != all_result) {
/* Send result text to widget */
- vcdc_send_result(pid, VC_COMMAND_TYPE_WIDGET);
+ vcdc_send_result(pid, vcd_client_manager_get_pid(), VC_COMMAND_TYPE_WIDGET);
}
SLOG(LOG_DEBUG, TAG_VCD, "[Server] Request tooltip hide");
}
/* Normal result */
- SLOG(LOG_DEBUG, TAG_VCD, "[Server] === Get engine result ===");
+ SLOG(LOG_DEBUG, TAG_VCD, "[Server] @ Get engine result @");
int ret = -1;
vc_cmd_s* temp_cmd = NULL;
}
int i = 0;
- int priority = 0;
for (i = 0; i < count; i++) {
SLOG(LOG_DEBUG, TAG_VCD, "[Server] [%d] Result ID(%d)", i, result_id[i]);
ret = vcd_client_get_cmd_from_result_id(result_id[i], &temp_cmd);
if (0 == ret && NULL != temp_cmd) {
- /* Add priority filter */
- int temp_priority = __convert_type_to_priority(temp_cmd->type);
- if (priority > temp_priority) {
- SLOG(LOG_DEBUG, TAG_VCD, "[Server] Ignore result by priority");
- continue;
- } else if (priority < temp_priority) {
- SLOG(LOG_DEBUG, TAG_VCD, "[Server] High priority result!!");
- priority = temp_priority;
-
- if (0 != vc_cmd_list_remove_all(vc_cmd_list, true)) {
- SLOG(LOG_ERROR, TAG_VCD, "[Server] Fail to list remove all");
- }
- }
-
switch (temp_cmd->format) {
case VC_CMD_FORMAT_FIXED:
+ case VC_CMD_FORMAT_FIXED_AND_VFIXED:
+ case VC_CMD_FORMAT_VFIXED_AND_FIXED:
+ case VC_CMD_FORMAT_PARTIAL:
/* Nonfixed result is NOT valid */
break;
- case VC_CMD_FORMAT_FIXED_AND_EXTRA:
+ case VC_CMD_FORMAT_FIXED_AND_NONFIXED:
if (NULL == temp_cmd->parameter) {
if (NULL != non_fixed_result) {
temp_cmd->parameter = strdup(non_fixed_result);
SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Command type is NOT vaild. Parameter (%s)", temp_cmd->parameter);
}
break;
- case VC_CMD_FORMAT_EXTRA_AND_FIXED:
+ case VC_CMD_FORMAT_NONFIXED_AND_FIXED:
if (NULL == temp_cmd->command) {
if (NULL != non_fixed_result) {
temp_cmd->command = strdup(non_fixed_result);
vc_cmd_print_list(vc_cmd_list);
- SLOG(LOG_DEBUG, TAG_VCD, "[Server] =========================");
+ SLOG(LOG_DEBUG, TAG_VCD, "[Server] @@@@");
int result_count = 0;
vc_cmd_list_get_count(vc_cmd_list, &result_count);
vc_cmd_list_destroy(vc_cmd_list, true);
return;
+#endif
+}
+
+#if 0
+static void __vcd_server_nlu_result_cb(vce_result_event_e event, const char* nlu_result, void *user_data)
+{
+ SECURE_SLOG(LOG_DEBUG, TAG_VCD, "[Server] NLU result cb - event(%d)", event);
+ SECURE_SLOG(LOG_DEBUG, TAG_VCD, "[Server] result (%s)", nlu_result);
+
+ int ret = vc_info_parser_set_nlu_result(nlu_result);
+ if (0 != ret) {
+ SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to set nlu result (%d)", ret);
+ }
+
+ return;
+}
+#endif
+
+int vcd_send_error(vce_error_e error, const char* msg, void *user_data)
+{
+ SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Engine Error cb - reason(%d), msg(%s)", error, msg);
+ ecore_main_loop_thread_safe_call_async(__cancel_by_error, NULL);
+
+ char* error_msg = NULL;
+ if (NULL != msg) {
+ error_msg = strdup(msg);
+ if (NULL == error_msg) {
+ return VCD_ERROR_OUT_OF_MEMORY;
+ }
+ }
+
+ int ret = VCD_ERROR_NONE;
+ ret = vcdc_send_error_signal_to_manager(vcd_client_manager_get_pid(), error, error_msg);
+ if (VCD_ERROR_NONE != ret) {
+ SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to send error signal");
+ }
+
+ if (NULL != error_msg) {
+ free(error_msg);
+ error_msg = NULL;
+ }
+
+ return ret;
}
/*
SLOG(LOG_DEBUG, TAG_VCD, "== Old file clean up == ");
DIR *dp = NULL;
- int ret = -1;
- struct dirent entry;
struct dirent *dirp = NULL;
dp = opendir(VC_RUNTIME_INFO_ROOT);
char remove_path[256] = {0, };
do {
- ret = readdir_r(dp, &entry, &dirp);
- if (0 != ret) {
- SLOG(LOG_ERROR, TAG_VCD, "[File ERROR] Fail to read directory");
- break;
- }
+ dirp = readdir(dp);
if (NULL != dirp) {
if (!strncmp("vc_", dirp->d_name, strlen("vc_"))) {
return;
}
-int vcd_initialize()
+static int __vcd_db_clean_up()
+{
+ int ret = 0;
+ int cnt = VC_COMMAND_TYPE_FOREGROUND;
+ do {
+ if (VC_COMMAND_TYPE_BACKGROUND != cnt)
+ ret = vc_db_delete_commands(-1, cnt, NULL);
+ } while (VC_COMMAND_TYPE_EXCLUSIVE >= ++cnt);
+
+ return ret;
+}
+
+int vcd_initialize(vce_request_callback_s *callback)
{
int ret = 0;
/* Remove old file */
__vcd_file_clean_up();
- /* Send error signal for notifying that daemon is reset*/
- vcdc_send_error_signal(VCD_ERROR_SERVICE_RESET, "Daemon reset");
/* initialize modules */
ret = vcd_config_initialize(__config_lang_changed_cb, __config_foreground_changed_cb, NULL);
SLOG(LOG_ERROR, TAG_VCD, "[Server WARNING] Fail to initialize config.");
}
+ /* Remove db data */
+ ret = __vcd_db_clean_up();
+ if (0 != ret) {
+ SLOG(LOG_ERROR, TAG_VCD, "[Server WARNING] Fail to remove db data");
+ }
+
vcd_config_set_service_state(VCD_STATE_NONE);
- ret = vcd_engine_agent_init(__vcd_server_pre_result_cb, __vcd_server_result_cb);
+ ret = vcd_engine_agent_init();
if (0 != ret) {
SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to engine agent initialize : result(%d)", ret);
return ret;
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;
}
vcd_config_set_service_state(VCD_STATE_READY);
vcdc_send_service_state(VCD_STATE_READY);
- SLOG(LOG_DEBUG, TAG_VCD, "[Server SUCCESS] initialize");
+ SLOG(LOG_ERROR, TAG_VCD, "[Server SUCCESS] initialize");
return 0;
}
-void vcd_finalize()
+bool vcd_finalize()
{
GList *iter = NULL;
if (0 < g_list_length(g_proc_list)) {
}
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");
}
+ vcd_client_manager_unset_appid();
+
vcd_config_set_service_state(VCD_STATE_NONE);
vcdc_send_service_state(VCD_STATE_NONE);
- SLOG(LOG_DEBUG, TAG_VCD, "[Server] mode finalize");
+ SLOG(LOG_ERROR, TAG_VCD, "[Server] mode finalize");
- return;
+ return true;
}
static Eina_Bool __finalize_quit_ecore_loop(void *data)
{
- SLOG(LOG_DEBUG, TAG_VCD, "[Server] quit ecore main loop");
- ecore_main_loop_quit();
- return EINA_FALSE;
+ bool ret = vcd_finalize();
+ if (false == ret) {
+ return EINA_TRUE;
+ } else {
+ ecore_main_loop_quit();
+ return EINA_FALSE;
+ }
}
static void __read_proc()
{
DIR *dp = NULL;
- struct dirent entry;
struct dirent *dirp = NULL;
- int ret = -1;
int tmp;
GList *iter = NULL;
SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to open proc");
} else {
do {
- ret = readdir_r(dp, &entry, &dirp);
- if (0 != ret) {
- SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to readdir");
- break;
- }
+ dirp = readdir(dp);
if (NULL != dirp) {
tmp = atoi(dirp->d_name);
}
if (0 == ret || mgr_pid > 0) {
- SLOG(LOG_DEBUG, TAG_VCD, "===== Clean up %s client ", type ? (type == 1) ? "Widget" : "Manager" : "Normal");
+ SLOG(LOG_DEBUG, TAG_VCD, "@@@ Clean up %s client ", type ? (type == 1) ? "Widget" : "Manager" : "Normal");
if (NULL != client_list && client_count > 0) {
for (i = 0; i < client_count; i++) {
exist = false;
for (j = 0; j < g_list_length(g_proc_list); j++) {
iter = g_list_nth(g_proc_list, j);
if (NULL != iter) {
- if (client_list[i] == GPOINTER_TO_INT(iter->data)) {
- SLOG(LOG_DEBUG, TAG_VCD, "%s pid(%d) is running", type ? (type == 1) ? "Widget" : "Manager" : "Normal", client_list[i]);
+ if (*(client_list + i) == GPOINTER_TO_INT(iter->data)) {
+ SLOG(LOG_DEBUG, TAG_VCD, "%s pid(%d) is running", type ? (type == 1) ? "Widget" : "Manager" : "Normal", *(client_list + i));
exist = true;
break;
}
}
if (false == exist) {
- SLOG(LOG_ERROR, TAG_VCD, "%s pid(%d) should be removed", type ? (type == 1) ? "Widget" : "Manager" : "Normal", client_list[i]);
+ SLOG(LOG_ERROR, TAG_VCD, "%s pid(%d) should be removed", type ? (type == 1) ? "Widget" : "Manager" : "Normal", *(client_list + i));
if (VCD_CLIENT_TYPE_NORMAL == type)
- vcd_server_finalize(client_list[i]);
+ vcd_server_finalize(*(client_list + i));
else if (VCD_CLIENT_TYPE_WIDGET == type)
- vcd_server_widget_finalize(client_list[i]);
+ vcd_server_widget_finalize(*(client_list + i));
else
vcd_server_mgr_finalize(mgr_pid);
}
}
}
- SLOG(LOG_DEBUG, TAG_VCD, "=====");
- SLOG(LOG_DEBUG, TAG_VCD, " ");
+ SLOG(LOG_DEBUG, TAG_VCD, "@@@");
}
if (NULL != client_list && -1 == mgr_pid) {
free(client_list);
Eina_Bool vcd_cleanup_client_all(void *data)
{
__read_proc();
-
+
__vcd_cleanup_client(VCD_CLIENT_TYPE_NORMAL);
__vcd_cleanup_client(VCD_CLIENT_TYPE_WIDGET);
__vcd_cleanup_client(VCD_CLIENT_TYPE_MANAGER);
#if 0
if (0 == vcd_client_get_list(&client_list, &client_count)) {
- SLOG(LOG_DEBUG, TAG_VCD, "===== Clean up client ");
+ SLOG(LOG_DEBUG, TAG_VCD, "@@@ Clean up client ");
if (NULL != client_list && client_count > 0) {
for (i = 0; i < client_count; i++) {
exist = false;
#endif
}
}
- SLOG(LOG_DEBUG, TAG_VCD, "=====");
- SLOG(LOG_DEBUG, TAG_VCD, " ");
+ SLOG(LOG_DEBUG, TAG_VCD, "@@@");
}
if (NULL != client_list) {
free(client_list);
/* If app is in background state, app cannot response message. */
if (0 == vcd_client_widget_get_list(&client_list, &client_count)) {
- SLOG(LOG_DEBUG, TAG_VCD, "===== Clean up widget");
+ SLOG(LOG_DEBUG, TAG_VCD, "@@@ Clean up widget");
if (NULL != client_list && client_count > 0) {
for (i = 0; i < client_count; i++) {
exist = false;
#endif
}
}
- SLOG(LOG_DEBUG, TAG_VCD, "=====");
- SLOG(LOG_DEBUG, TAG_VCD, " ");
+ SLOG(LOG_DEBUG, TAG_VCD, "@@@");
}
if (NULL != client_list) {
*/
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());
return VCD_ERROR_OPERATION_FAILED;
}
- SLOG(LOG_DEBUG, TAG_VCD, "[Server Success] Manager initialize : pid(%d)", pid);
+ if (0 != vcdc_send_manager_pid(pid))
+ SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Fail to send manager pid");
+
+ SLOG(LOG_ERROR, TAG_VCD, "[Server Success] Manager initialize : pid(%d)", pid);
return VCD_ERROR_NONE;
}
/* Cancel recognition */
vcd_server_mgr_cancel();
+ if (0 != vcdc_send_manager_pid(-1))
+ SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Fail to send manager pid");
+
/* Remove manager information */
if (0 != vcd_client_manager_unset()) {
SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Fail to delete client");
if (0 == vcd_client_get_ref_count()) {
SLOG(LOG_DEBUG, TAG_VCD, "[Server] Connected client list is empty");
- ecore_timer_add(0, __finalize_quit_ecore_loop, NULL);
+ ecore_timer_add(0.5, __finalize_quit_ecore_loop, NULL);
}
- SLOG(LOG_DEBUG, TAG_VCD, "[Server Success] Manager Finalize : pid(%d)", pid);
+ SLOG(LOG_ERROR, TAG_VCD, "[Server Success] Manager Finalize : pid(%d)", pid);
return VCD_ERROR_NONE;
}
}
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;
return VCD_ERROR_NONE;
}
+static int __reset_waiting_for_widget_recording(void)
+{
+ SLOG(LOG_ERROR, TAG_VCD, "[Server] Reet waiting for widget recording");
+ // Delete timer to check that widget client is terminated
+ if (g_check_widget_client_timer) {
+ ecore_timer_del(g_check_widget_client_timer);
+ g_check_widget_client_timer = NULL;
+ }
+ // Reset flag to wait for recording from widget client
+ vcd_client_widget_set_waiting_for_recording(-1, false);
+ return 0;
+}
+
+static Eina_Bool __send_waiting_timeout_error_to_manager(void* data)
+{
+ intptr_t ppid = (intptr_t)data;
+ int pid = (int)ppid;
+ SLOG(LOG_ERROR, TAG_VCD, "Widget client didn't send to start recording, pid(%d)", pid);
+ __reset_waiting_for_widget_recording();
+
+ vcdc_send_error_signal_to_manager(vcd_client_manager_get_pid(), VCD_ERROR_OPERATION_FAILED, "voice_engine.error.proc_fail");
+ return EINA_FALSE;
+}
+
+static int __set_waiting_for_widget_recording(int pid)
+{
+ SLOG(LOG_ERROR, TAG_VCD, "[Server] Set waiting for widget recording, pid(%d)", pid);
+
+ // Check if the app included widget client is terminated or not. If it is terminated, vcd_server_widget_finalize() function will be called
+ // In that function, it will start recording
+ intptr_t ppid = (intptr_t)pid;
+ g_check_widget_client_timer = ecore_timer_add(2.0, __send_waiting_timeout_error_to_manager, (void*)ppid);
+
+ // Set flag to wait for recording from widget client
+ vcd_client_widget_set_waiting_for_recording(pid, true);
+ return 0;
+}
+
static int __start_internal_recognition()
{
int ret;
+ __reset_waiting_for_widget_recording();
- /* 2. Get commands */
- ret = vcd_client_command_collect_command();
- if (0 != ret) {
- SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to collect command : %d", ret);
- return VCD_ERROR_OPERATION_FAILED;
- }
-
- ret = vcd_client_get_length();
- if (0 == ret) {
- SLOG(LOG_WARN, TAG_VCD, "[Server WARNIING] No current command : %d", ret);
+ if (0 != vcd_client_command_collect_command()) {
+ SLOG(LOG_ERROR, TAG_VCD, "[Client Data ERROR] Fail to collect command");
+ /* Send error cb to manager */
+ int pid = vcd_client_widget_get_foreground_pid();
+ if (-1 != pid)
+ vcdc_send_error_signal_to_manager(vcd_client_manager_get_pid(), VCD_ERROR_OPERATION_FAILED, "voice_engine.error.proc_fail");
return VCD_ERROR_OPERATION_FAILED;
}
/* 3. Set command to engine */
ret = vcd_engine_set_commands();
if (0 != ret) {
- SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to collect command : %d", ret);
+ SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to set commands : %d", ret);
+ /* Send error cb to manager */
+ int pid = vcd_client_widget_get_foreground_pid();
+ if (-1 != pid)
+ vcdc_send_error_signal_to_manager(vcd_client_manager_get_pid(), VCD_ERROR_OPERATION_FAILED, "voice_engine.error.proc_fail");
return VCD_ERROR_OPERATION_FAILED;
}
- SLOG(LOG_DEBUG, TAG_VCD, "[Server Success] Set command");
+ SLOG(LOG_ERROR, TAG_VCD, "[Server Success] Set command");
bool stop_by_silence = true;
if (VCD_RECOGNITION_MODE_MANUAL == vcd_client_get_recognition_mode()) {
stop_by_silence = false;
}
+ vcd_client_manager_set_result_text(NULL);
+
/* 4. start recognition */
ret = vcd_engine_recognize_start(stop_by_silence);
if (0 != ret) {
SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to start recognition : result(%d)", ret);
+ /* Send error cb to manager */
+ int pid = vcd_client_widget_get_foreground_pid();
+ if (-1 != pid)
+ vcdc_send_error_signal_to_manager(vcd_client_manager_get_pid(), VCD_ERROR_OPERATION_FAILED, "voice_engine.error.proc_fail");
return VCD_ERROR_OPERATION_FAILED;
}
- SLOG(LOG_DEBUG, TAG_VCD, "[Server Success] Start engine");
+ SLOG(LOG_ERROR, TAG_VCD, "[Server Success] Start engine");
+#if 1
/* 5. recorder start */
ret = vcd_recorder_start();
if (0 != ret) {
SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to start recorder : result(%d)", ret);
vcd_engine_recognize_cancel();
+ /* Send error cb to manager */
+ int pid = vcd_client_widget_get_foreground_pid();
+ if (-1 != pid)
+ vcdc_send_error_signal_to_manager(vcd_client_manager_get_pid(), VCD_ERROR_OPERATION_FAILED, "voice_engine.error.proc_fail");
return ret;
}
+#endif
vcd_config_set_service_state(VCD_STATE_RECORDING);
vcdc_send_service_state(VCD_STATE_RECORDING);
- SLOG(LOG_DEBUG, TAG_VCD, "[Server Success] Start recognition(%d)", stop_by_silence);
+ SLOG(LOG_ERROR, TAG_VCD, "[Server Success] Start recognition(%d)", stop_by_silence);
return 0;
}
{
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);
}
SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Current state is not ready");
return VCD_ERROR_INVALID_STATE;
}
+ if (-1 == vcd_client_manager_get_pid()) {
+ SLOG(LOG_DEBUG, TAG_VCD, "[Server] Manager is NOT available.");
+ return VCD_ERROR_OPERATION_FAILED;
+ }
+ __reset_waiting_for_widget_recording();
- SLOG(LOG_DEBUG, TAG_VCD, "[Server] set recognition mode = %d", recognition_mode);
+ SLOG(LOG_ERROR, TAG_VCD, "[Server] set recognition mode = %d", recognition_mode);
vcd_client_set_recognition_mode(recognition_mode);
if (false == exclusive_cmd) {
+ vcd_client_update_foreground_pid();
/* Notify show tooltip */
- int pid = vcd_client_widget_get_foreground_pid();
- if (-1 != pid) {
- SLOG(LOG_DEBUG, TAG_VCD, "[Server] Request tooltip show and widget command");
- ecore_timer_add(0, __vcd_request_show_tooltip, (void*)true);
- return 0;
+ if (1 == vcd_config_get_command_type_enabled(VC_COMMAND_TYPE_WIDGET)) {
+ int pid = vcd_client_widget_get_foreground_pid();
+ if (-1 != pid) {
+ SLOG(LOG_ERROR, TAG_VCD, "[Server] Request tooltip show and widget command");
+ ecore_timer_add(0, __vcd_request_show_tooltip, (void*)true);
+
+ __set_waiting_for_widget_recording(pid);
+ return 0;
+ }
}
} else {
vcd_client_manager_set_exclusive(exclusive_cmd);
}
}
+ 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);
vcd_client_unset_exclusive_command(fg_pid);
}
+ SLOG(LOG_ERROR, TAG_VCD, "[Server Success] start internal recognition");
return VCD_ERROR_NONE;
}
SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Current state is not recording");
return VCD_ERROR_INVALID_STATE;
}
+ if (-1 == vcd_client_manager_get_pid()) {
+ SLOG(LOG_DEBUG, TAG_VCD, "[Server] Manager is NOT available.");
+ return VCD_ERROR_OPERATION_FAILED;
+ }
+ SLOG(LOG_ERROR, TAG_VCD, "[Server] stop internal recognition");
+#if 1
/* 2. Stop recorder */
vcd_recorder_stop();
+#endif
/* 3. Stop engine recognition */
int ret = vcd_engine_recognize_stop();
vcd_config_set_service_state(VCD_STATE_PROCESSING);
vcdc_send_service_state(VCD_STATE_PROCESSING);
+ SLOG(LOG_ERROR, TAG_VCD, "[Server Success] stop internal recognition");
return VCD_ERROR_NONE;
}
int vcd_server_mgr_cancel()
{
- /* 1. Check current state */
- vcd_state_e state = vcd_config_get_service_state();
- if (VCD_STATE_RECORDING != state && VCD_STATE_PROCESSING != state) {
- SLOG(LOG_WARN, TAG_VCD, "[Server ERROR] Current state is not recording or processing");
- return VCD_ERROR_INVALID_STATE;
+ if (-1 == vcd_client_manager_get_pid()) {
+ SLOG(LOG_DEBUG, TAG_VCD, "[Server] Manager is NOT available.");
+ return VCD_ERROR_OPERATION_FAILED;
}
if (g_restart_timer != NULL) {
g_restart_timer = NULL;
}
+ /* 1. Check current state */
+ vcd_state_e state = vcd_config_get_service_state();
+ if (VCD_STATE_READY == state) {
+ SLOG(LOG_DEBUG, TAG_VCD, "[Server] Current state is READY");
+ vcd_recorder_stop();
+
+ if (false == vcd_client_manager_get_exclusive()) {
+ if (1 == vcd_config_get_command_type_enabled(VC_COMMAND_TYPE_WIDGET)) {
+ int pid = vcd_client_widget_get_foreground_pid();
+ if (-1 != pid) {
+ SLOG(LOG_DEBUG, TAG_VCD, "[Server] Request tooltip hide");
+ ecore_timer_add(0, __vcd_request_show_tooltip, (void*)false);
+ }
+ }
+ }
+
+ vcdc_send_service_state(VCD_STATE_READY);
+ return VCD_ERROR_NONE;
+ }
+ SLOG(LOG_ERROR, TAG_VCD, "[Server] cancel internal recognition");
+
+#if 1
/* 2. Stop recorder */
vcd_recorder_stop();
+#endif
+
/* 3. Cancel engine */
int ret = vcd_engine_recognize_cancel();
if (0 != ret) {
}
if (false == vcd_client_manager_get_exclusive()) {
- int pid = vcd_client_widget_get_foreground_pid();
- if (-1 != pid) {
- SLOG(LOG_DEBUG, TAG_VCD, "[Server] Request tooltip hide");
- ecore_timer_add(0, __vcd_request_show_tooltip, (void*)false);
+ if (1 == vcd_config_get_command_type_enabled(VC_COMMAND_TYPE_WIDGET)) {
+ int pid = vcd_client_widget_get_foreground_pid();
+ if (-1 != pid) {
+ SLOG(LOG_DEBUG, TAG_VCD, "[Server] Request tooltip hide");
+ ecore_timer_add(0, __vcd_request_show_tooltip, (void*)false);
+ }
}
} else {
vcd_client_manager_set_exclusive(false);
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;
}
return VCD_ERROR_NONE;
}
+int vcd_server_mgr_set_domain(int pid, const char* domain)
+{
+ /* check if pid is valid */
+ if (false == vcd_client_manager_is_valid(pid)) {
+ SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] The manager pid(%d) is NOT valid", pid);
+ return VCD_ERROR_INVALID_PARAMETER;
+ }
+
+ vcd_state_e state = vcd_config_get_service_state();
+ if (VCD_STATE_READY != state) {
+ SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Current state is not ready");
+ return VCD_ERROR_INVALID_STATE;
+ }
+
+ /* Set domain to engine */
+ int ret = vcd_engine_set_domain(pid, domain);
+ if (0 != ret) {
+ SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to set domain : %d", ret);
+ } else {
+ SLOG(LOG_DEBUG, TAG_VCD, "[Server SUCCESS] Set domain");
+ }
+
+ return ret;
+}
+
+int vcd_server_mgr_set_private_data(int pid, const char* key, const char* data)
+{
+ /* check if pid is valid */
+ if (false == vcd_client_manager_is_valid(pid)) {
+ SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] The manager pid(%d) is NOT valid", pid);
+ return VCD_ERROR_INVALID_PARAMETER;
+ }
+
+ vcd_state_e state = vcd_config_get_service_state();
+ if (VCD_STATE_READY != state) {
+ SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Current state is not ready");
+ return VCD_ERROR_INVALID_STATE;
+ }
+
+ /* Set private data to engine */
+ int ret = vcd_engine_set_private_data(pid, key, data);
+ if (0 != ret) {
+ SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to set private data : %d", ret);
+ } else {
+ SLOG(LOG_DEBUG, TAG_VCD, "[Server SUCCESS] Set private data");
+ }
+
+ return ret;
+}
+
+int vcd_server_mgr_get_private_data(int pid, const char* key, char** data)
+{
+ /* check if pid is valid */
+ if (false == vcd_client_manager_is_valid(pid)) {
+ SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] The manager pid(%d) is NOT valid", pid);
+ return VCD_ERROR_INVALID_PARAMETER;
+ }
+ vcd_state_e state = vcd_config_get_service_state();
+ if (VCD_STATE_READY != state) {
+ SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Current state is not ready");
+ return VCD_ERROR_INVALID_STATE;
+ }
+
+ /* Get private data to engine */
+ int ret = vcd_engine_get_private_data(pid, key, data);
+ if (0 != ret) {
+ SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to get private data : %d", ret);
+ } else {
+ SLOG(LOG_DEBUG, TAG_VCD, "[Server SUCCESS] Set private data");
+ }
+
+ return ret;
+}
+
+int vcd_server_mgr_do_action(int pid, int type, const char* action)
+{
+ int ret = -1;
+
+ /* check if pid is valid */
+ if (false == vcd_client_manager_is_valid(pid)) {
+ SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] The manager pid(%d) is NOT valid", pid);
+ return VCD_ERROR_INVALID_PARAMETER;
+ }
+
+ vcd_state_e state = vcd_config_get_service_state();
+ if (VCD_STATE_READY != state) {
+ SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Current state is not ready");
+ return VCD_ERROR_INVALID_STATE;
+ }
+
+ /* Reqeust do action to engine */
+ if (VCD_SEND_EVENT_TYPE_TEXT == type)
+ ret = vcd_engine_process_text(pid, action);
+ else if (VCD_SEND_EVENT_TYPE_LIST_EVENT == type)
+ ret = vcd_engine_process_list_event(pid, action);
+ else if (VCD_SEND_EVENT_TYPE_HAPTIC_EVENT == type)
+ ret = vcd_engine_process_haptic_event(pid, action);
+
+ if (0 != ret) {
+ SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to process do action : %d", ret);
+ } else {
+ vcd_config_set_service_state(VCD_STATE_PROCESSING);
+ vcdc_send_service_state(VCD_STATE_PROCESSING);
+ SLOG(LOG_DEBUG, TAG_VCD, "[Server SUCCESS] Process do action");
+ }
+
+ return ret;
+}
+
+int vcd_server_mgr_enable_command_type(int pid, int cmd_type)
+{
+ int ret = -1;
+
+ /* check if pid is valid */
+ if (false == vcd_client_manager_is_valid(pid)) {
+ SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] The manager pid(%d) is NOT valid", pid);
+ return VCD_ERROR_INVALID_PARAMETER;
+ }
+
+ vcd_state_e state = vcd_config_get_service_state();
+ if (VCD_STATE_READY != state) {
+ SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Current state is not ready");
+ return VCD_ERROR_INVALID_STATE;
+ }
+
+ ret = vcd_config_enable_command_type(cmd_type);
+ if (0 != ret) {
+ SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to enable command type");
+ } else {
+ SLOG(LOG_ERROR, TAG_VCD, "[Server] Enable command type(%d)", cmd_type);
+ }
+
+ return ret;
+}
+
+int vcd_server_mgr_disable_command_type(int pid, int cmd_type)
+{
+ int ret = -1;
+
+ /* check if pid is valid */
+ if (false == vcd_client_manager_is_valid(pid)) {
+ SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] The manager pid(%d) is NOT valid", pid);
+ return VCD_ERROR_INVALID_PARAMETER;
+ }
+
+ vcd_state_e state = vcd_config_get_service_state();
+ if (VCD_STATE_READY != state) {
+ SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Current state is not ready");
+ return VCD_ERROR_INVALID_STATE;
+ }
+
+ ret = vcd_config_disable_command_type(cmd_type);
+ if (0 != ret) {
+ SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to disable command type");
+ } else {
+ SLOG(LOG_ERROR, TAG_VCD, "[Server] Disable command type(%d)", cmd_type);
+ }
+
+ return ret;
+}
+
/*
* VC Server Functions for Client
*/
int vcd_server_initialize(int pid)
{
- if (false == g_is_engine) {
- if (0 != vcd_engine_agent_initialize_current_engine()) {
- SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] No Engine");
- g_is_engine = false;
- return VCD_ERROR_ENGINE_NOT_FOUND;
- } else {
- g_is_engine = true;
- }
- }
-
if (false == vcd_engine_is_available_engine()) {
- if (0 != vcd_engine_agent_initialize_current_engine()) {
- SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] No Engine");
- return VCD_ERROR_ENGINE_NOT_FOUND;
- }
+ SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] No Engine");
+ return VCD_ERROR_ENGINE_NOT_FOUND;
}
/* check if pid is valid */
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);
return 0;
}
+static int __vcd_server_launch_manager_app()
+{
+ int ret = -1;
+ bool running = false;
+ char* appid = NULL;
+
+ ret = vcd_client_manager_get_appid(&appid);
+ if (0 != ret || NULL == appid) {
+ SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to get manager appid");
+ return VCD_ERROR_OPERATION_FAILED;
+ }
+ ret = app_manager_is_running(appid, &running);
+ if (0 != ret) {
+ SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to check running with appid(%s)", appid);
+ free(appid);
+ appid = NULL;
+ return VCD_ERROR_OPERATION_FAILED;
+ }
+ if (false == running) {
+ int tmp_ret = __vcd_is_package_installed(appid);
+ if (false == tmp_ret) {
+ SLOG(LOG_ERROR, TAG_VCD, "[ERROR] manager app is not installed, appid(%s)", appid);
+ } else {
+ ret = __vcd_activate_app_by_appcontrol(appid);
+ if (0 != ret) {
+ SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to activate app");
+ free(appid);
+ appid = NULL;
+ return ret;
+ }
+ SLOG(LOG_ERROR, TAG_VCD, "Launch vc manager app: appid(%s)", appid);
+ }
+ } else {
+ ret = __vcd_resume_app(appid);
+ if (0 != ret) {
+ SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to resume app");
+ free(appid);
+ appid = NULL;
+ return ret;
+ }
+ SLOG(LOG_ERROR, TAG_VCD, "Resume vc manager app: appid(%s)", appid);
+ }
+
+ free(appid);
+ appid = NULL;
+
+ return VCD_ERROR_NONE;
+}
+
+int vcd_server_dialog(int pid, const char* disp_text, const char* utt_text, int continuous)
+{
+ /* check if pid is valid */
+ if (false == vcd_client_is_available(pid) && false == vcd_client_widget_is_available(pid)) {
+ SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] pid is NOT valid ");
+ return VCD_ERROR_INVALID_PARAMETER;
+ }
+
+ int ret = __vcd_server_launch_manager_app();
+ if (0 != ret) {
+ SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to send dialog : mgr_pid(%d), pid(%d), disp_text(%s), utt_text(%s), continue(%d)", vcd_client_manager_get_pid(), pid, disp_text, utt_text, continuous);
+ return ret;
+ }
+
+ ret = vcdc_send_dialog(vcd_client_manager_get_pid(), pid, disp_text, utt_text, continuous);
+ if (0 != ret) {
+ SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to send dialog : mgr_pid(%d), pid(%d), disp_text(%s), utt_text(%s), continue(%d)", vcd_client_manager_get_pid(), pid, disp_text, utt_text, continuous);
+ return ret;
+ }
+
+ return 0;
+}
+
+int vcd_server_is_system_command_valid(int pid, int* is_sys_cmd_valid)
+{
+ /* check if pid is valid */
+ if (false == vcd_client_is_available(pid) && false == vcd_client_widget_is_available(pid)) {
+ SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] pid is NOT valid ");
+ return VCD_ERROR_INVALID_PARAMETER;
+ }
+
+ /* check if system command is valid */
+ if (true == vcd_client_manager_is_system_command_valid(vcd_client_manager_get_pid()))
+ *is_sys_cmd_valid = true;
+ else
+ *is_sys_cmd_valid = false;
+
+ return 0;
+}
+
#if 0
int vcd_server_set_exclusive_command(int pid, bool value)
{
*/
int vcd_server_widget_initialize(int pid)
{
- if (false == g_is_engine) {
- if (0 != vcd_engine_agent_initialize_current_engine()) {
- SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] No Engine");
- g_is_engine = false;
- return VCD_ERROR_ENGINE_NOT_FOUND;
- } else {
- g_is_engine = true;
- }
- }
-
if (false == vcd_engine_is_available_engine()) {
- if (0 != vcd_engine_agent_initialize_current_engine()) {
- SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] No Engine");
- return VCD_ERROR_ENGINE_NOT_FOUND;
- }
+ SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] No Engine");
+ return VCD_ERROR_ENGINE_NOT_FOUND;
}
/* check if pid is valid */
if (true == vcd_client_widget_is_available(pid)) {
- SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] The pid is already exist");
- return VCD_ERROR_INVALID_PARAMETER;
+ SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] The pid is already exist");
+ return VCD_ERROR_NONE;
}
/* Add client information to client manager */
return VCD_ERROR_NONE;
}
+static void __vcd_server_widget_start_recording(void *data)
+{
+ SLOG(LOG_ERROR, TAG_VCD, "[Server INFO] start recording");
+
+ if (0 != __start_internal_recognition()) {
+ SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to start recongition");
+ }
+}
+
int vcd_server_widget_finalize(int pid)
{
/* check if pid is valid */
}
if (0 == vcd_client_get_ref_count()) {
- SLOG(LOG_DEBUG, TAG_VCD, "[Server] connected client list is empty");
- ecore_timer_add(0, __finalize_quit_ecore_loop, NULL);
+ SLOG(LOG_ERROR, TAG_VCD, "[Server] connected client list is empty");
+ ecore_timer_add(0.5, __finalize_quit_ecore_loop, NULL);
+ return 0;
+ }
+
+ bool is_waiting = false;
+ if (0 != vcd_client_widget_get_waiting_for_recording(pid, &is_waiting)) {
+ SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Fail to get waiting to recording");
}
+ if (true == is_waiting) {
+ SLOG(LOG_ERROR, TAG_VCD, "[Server INFO] invoke to start recording");
+ ecore_main_loop_thread_safe_call_async(__vcd_server_widget_start_recording, NULL);
+ }
return VCD_ERROR_NONE;
}
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");
} else {
vcd_client_widget_unset_command(pid);
- SLOG(LOG_DEBUG, TAG_VCD, "[Server] widget command is NOT available");
+ SLOG(LOG_WARN, TAG_VCD, "[Server] widget command is NOT available");
}
+ SLOG(LOG_ERROR, TAG_VCD, "[Server] start internal recongition : %d", widget_command);
int ret = __start_internal_recognition();
if (0 != ret) {
SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to start recongition : %d", ret);
return VCD_ERROR_NONE;
}
+int vcd_server_widget_enable_asr_result(int pid, bool enable)
+{
+ int ret;
+ ret = vcd_client_widget_set_asr_result_enabled(pid, enable);
+ if (0 != ret) {
+ SLOG(LOG_DEBUG, TAG_VCD, "[Server] Fail to enable asr result : %d", ret);
+ }
+
+ return ret;
+}
+
+int vcd_server_set_language(const char* language)
+{
+ int ret = VCD_ERROR_NONE;
+
+ ret = vcd_config_set_default_language(language);
+ if (0 != ret) {
+ SLOG(LOG_DEBUG, TAG_VCD, "[Server] Fail to set language : %d", ret);
+ return ret;
+ }
+
+ ret = vcd_engine_set_current_language(language);
+ if (0 != ret) {
+ SLOG(LOG_DEBUG, TAG_VCD, "[Server] Fail to set language : %d", ret);
+ return ret;
+ }
+
+ return ret;
+}
+/*
+* For engine service
+*/
+int vcd_get_foreach_command(vce_cmd_h vce_command, vce_command_cb callback, void* user_data)
+{
+ SLOG(LOG_DEBUG, TAG_VCD, "[Server] Get foreach command");
+
+ if (NULL == callback) {
+ SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] input parameter is NULL");
+ return VCD_ERROR_INVALID_PARAMETER;
+ }
+
+ int ret = 0;
+ ret = vcd_engine_agent_get_foreach_command(vce_command, callback, user_data);
+ if (0 != ret) {
+ SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to get foreach command : ret(%d)", ret);
+ }
+
+ return ret;
+}
+
+int vcd_get_command_count(vce_cmd_h vce_command)
+{
+ SLOG(LOG_DEBUG, TAG_VCD, "[Server] Get command count");
+
+ int ret = 0;
+ ret = vcd_engine_agent_get_command_count(vce_command);
+ if (0 > ret) {
+ SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to get command count : ret(%d)", ret);
+ }
+
+ return ret;
+}
+
+int vcd_get_audio_type(char** audio_type)
+{
+ SLOG(LOG_DEBUG, TAG_VCD, "[Server] Get audio type");
+
+ int ret = 0;
+ ret = vcd_engine_agent_get_audio_type(audio_type);
+ if (0 != ret) {
+ SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to get audio type : ret(%d)", ret);
+ }
+
+ return ret;
+}
+
+int vcd_set_private_data(const char* key, const char* data)
+{
+ vcd_state_e state = vcd_config_get_service_state();
+
+ if (VCD_STATE_READY != state) {
+ SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Current state(%d) is NOT 'READY'", state);
+ return VCD_ERROR_INVALID_STATE;
+ }
+
+ int ret = vcd_engine_agent_set_private_data(key, data);
+ if (0 != ret) {
+ SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to set private data to the manager client : ret(%d)", ret);
+ } else {
+ SLOG(LOG_DEBUG, TAG_VCD, "[Server] Set private data to the manager client, key(%s), data(%s)", key, data);
+ }
+
+ return ret;
+}
+
+int vcd_get_private_data(const char* key, char** data)
+{
+ vcd_state_e state = vcd_config_get_service_state();
+
+ if (VCD_STATE_READY != state) {
+ SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Current state(%d) is NOT 'READY'", state);
+ return VCD_ERROR_INVALID_STATE;
+ }
+
+ int ret = vcd_engine_agent_get_private_data(key, data);
+ if (0 != ret) {
+ SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to get private data from the manager client : ret(%d)", ret);
+ } else {
+ SLOG(LOG_DEBUG, TAG_VCD, "[Server] Get private data from the manager client, key(%s), data(%s)", key, data);
+ }
+
+ return ret;
+}
+
+int vcd_start_recording()
+{
+ SLOG(LOG_DEBUG, TAG_VCD, "[Server] Start recording");
+
+ int ret = 0;
+ ret = vcd_engine_agent_start_recording();
+ if (0 != ret) {
+ SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to start recording : ret(%d)", ret);
+ }
+
+ return ret;
+}
+
+int vcd_stop_recording()
+{
+ SLOG(LOG_DEBUG, TAG_VCD, "[Server] Stop recording");
+
+ int ret = 0;
+ ret = vcd_engine_agent_stop_recording();
+ if (0 != ret) {
+ SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to stop recording : ret(%d)", ret);
+ }
+
+ return ret;
+}
+
+int vcd_set_private_data_set_cb(vce_private_data_set_cb callback_func)
+{
+ SLOG(LOG_DEBUG, TAG_VCD, "[Server] Set private data set cb");
+
+ int ret = 0;
+ ret = vcd_engine_agent_set_private_data_set_cb(callback_func);
+ if (0 != ret) {
+ SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to set private data set cb : ret(%d)", ret);
+ }
+
+ return ret;
+}
+
+int vcd_set_private_data_requested_cb(vce_private_data_requested_cb callback_func)
+{
+ SLOG(LOG_DEBUG, TAG_VCD, "[Server] Set private data requested cb");
+
+ int ret = 0;
+ ret = vcd_engine_agent_set_private_data_requested_cb(callback_func);
+ if (0 != ret) {
+ SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to set private data requested cb : ret(%d)", ret);
+ }
+
+ return ret;
+}
+
+int vcd_set_nlu_base_info_requested_cb(vce_nlu_base_info_requested_cb callback_func)
+{
+ SLOG(LOG_DEBUG, TAG_VCD, "[Server] Set nlu base info requested cb");
+
+ int ret = 0;
+ ret = vcd_engine_agent_set_nlu_base_info_requested_cb(callback_func);
+ if (0 != ret) {
+ SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to set nlu base info requested cb : ret(%d)", ret);
+ }
+
+ return ret;
+}
+