2 * Copyright (c) 2011-2015 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the License);
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an AS IS BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #include <app_control.h>
18 #include <app_manager.h>
21 #include "vc_cmd_db.h"
22 #include "vc_info_parser.h"
24 #include "vcd_server.h"
25 #include "vcd_server_data.h"
26 #include "vcd_client_data.h"
28 #include "vcd_engine_agent.h"
29 #include "vcd_config.h"
30 #include "vcd_recorder.h"
32 #include "vce_internal.h"
34 #include "voice_control_command_expand.h"
35 #include "voice_control_common.h"
37 #define CLIENT_CLEAN_UP_TIME 500
39 * VC Server static variable
41 static GList *g_proc_list = NULL;
43 static Ecore_Timer *g_restart_timer = NULL;
44 static Ecore_Timer *g_check_widget_client_timer = NULL;
45 static Ecore_Timer *g_check_client_timer = NULL;
47 static Ecore_Thread* g_tts_thread = NULL;
48 static unsigned int g_current_tts_uid = VC_INVALID_TTS_UID;
49 static int g_current_utt_id = -1;
52 * @brief Enumerations of send event type.
55 VCD_SEND_EVENT_TYPE_TEXT, /**< send text event to vc engine*/
56 VCD_SEND_EVENT_TYPE_LIST_EVENT, /**< send list event to vc engine */
57 VCD_SEND_EVENT_TYPE_HAPTIC_EVENT /**< send haptic event to vc engine */
58 } vcd_send_event_type_e;
60 static int __vcd_server_launch_manager_app();
61 static int __start_internal_recognition();
64 * VC Server Internal Functions
66 static inline int __get_tts_played_pid()
68 return g_current_tts_uid > VC_INVALID_TTS_UID ? g_current_tts_uid / 1000 : VC_INVALID_TTS_UID;
71 static Eina_Bool __stop_by_silence(void *data)
73 SLOG(LOG_INFO, TAG_VCD, "@@@ Silence Detected ");
75 vcd_server_mgr_stop();
77 SLOG(LOG_DEBUG, TAG_VCD, "@@@ Silence Detected DONE");
81 static Eina_Bool __cancel_by_interrupt(void *data)
83 SLOG(LOG_INFO, TAG_VCD, "@@@ Cancel by interrupt");
85 vcd_server_mgr_cancel();
87 SLOG(LOG_DEBUG, TAG_VCD, "@@@ Cancel by interrupt DONE");
91 static void __cancel_by_error(void *data)
93 SLOG(LOG_INFO, TAG_VCD, "@@@ Cancel by error");
95 vcd_server_mgr_cancel();
97 SLOG(LOG_DEBUG, TAG_VCD, "@@@ Cancel by error DONE");
101 static Eina_Bool __restart_engine(void *data)
103 SLOG(LOG_INFO, TAG_VCD, "@@@ Restart by no result");
105 g_restart_timer = NULL;
107 /* Restart recognition */
108 int ret = vcd_engine_recognize_start(true);
110 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to restart recognition : result(%d)", ret);
114 SLOG(LOG_INFO, TAG_VCD, "[Server Success] Start engine");
116 vcd_recognition_mode_e mode = vcd_client_get_recognition_mode();
117 if (VCD_RECOGNITION_MODE_RESTART_AFTER_REJECT == mode || VCD_RECOGNITION_MODE_RESTART_CONTINUOUSLY == mode) {
118 vcd_config_set_service_state(VCD_STATE_RECORDING);
119 vcdc_send_service_state(VCD_STATE_RECORDING);
122 SLOG(LOG_INFO, TAG_VCD, "[Server Success] Restart recognition");
127 static int __server_recorder_callback(const void* data, const unsigned int length)
129 vcd_state_e state = vcd_config_get_service_state();
130 if (VCD_STATE_READY == state) {
131 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Ready state, but recording");
132 } else if (VCD_STATE_PROCESSING == state) {
133 return VCD_ERROR_NONE;
136 vce_speech_detect_e speech_detected = VCE_SPEECH_DETECT_NONE;
139 ret = vcd_engine_recognize_audio(data, length, &speech_detected);
143 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to set recording data to engine(%d)", ret);
144 ecore_timer_add(0, __cancel_by_interrupt, NULL);
145 /* Send error cb to manager */
146 if (VCE_ERROR_OUT_OF_NETWORK == ret) {
147 vcdc_send_error_to_manager(vcd_client_manager_get_pid(), VCD_ERROR_TIMED_OUT, "voice_framework.error.engine.set_recording_fail");
149 vcdc_send_error_to_manager(vcd_client_manager_get_pid(), ret, "voice_framework.error.engine.set_recording_fail");
151 return VCD_ERROR_NONE;
154 if (VCE_SPEECH_DETECT_BEGIN == speech_detected) {
155 if (-1 != vcd_client_manager_get_pid()) {
156 /* Manager client is available */
157 if (0 != vcdc_send_speech_detected(vcd_client_manager_get_pid())) {
158 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Fail to send speech detected");
161 } else if (VCE_SPEECH_DETECT_END == speech_detected) {
162 if (VCD_RECOGNITION_MODE_STOP_BY_SILENCE == vcd_client_get_recognition_mode()) {
163 /* silence detected */
164 ecore_timer_add(0, __stop_by_silence, NULL);
165 } else if (VCD_RECOGNITION_MODE_RESTART_AFTER_REJECT == vcd_client_get_recognition_mode()) {
166 /* Stop engine recognition */
167 int ret = vcd_engine_recognize_stop();
169 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to stop recognition : %d", ret);
171 vcd_config_set_service_state(VCD_STATE_PROCESSING);
172 vcdc_send_service_state(VCD_STATE_PROCESSING);
174 SLOG(LOG_INFO, TAG_VCD, "[Server] Stop engine only by silence");
175 } else if (VCD_RECOGNITION_MODE_RESTART_CONTINUOUSLY == vcd_client_get_recognition_mode()) {
176 /* Stop engine recognition */
177 int ret = vcd_engine_recognize_stop();
179 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to stop recognition : %d", ret);
184 return VCD_ERROR_NONE;
187 void __server_recorder_interrupt_callback()
189 SLOG(LOG_INFO, TAG_VCD, "@@@ Cancel by sound interrupt");
191 ecore_timer_add(0, __cancel_by_interrupt, NULL);
193 SLOG(LOG_DEBUG, TAG_VCD, "@@@ Cancel by sound interrupt DONE");
196 static void __config_lang_changed_cb(const char* current_lang, void* user_data)
198 SLOG(LOG_INFO, TAG_VCD, "@@@ Change language ");
200 /* Current state is recording */
201 vcd_state_e state = vcd_config_get_service_state();
202 if (VCD_STATE_RECORDING == state || VCD_STATE_PROCESSING == state) {
203 SLOG(LOG_INFO, TAG_VCD, "[Server] Current state is 'Recording'. Cancel recognition");
204 vcd_server_mgr_cancel();
208 ret = vcd_engine_set_current_language(current_lang);
210 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to set language of engine : %d", ret);
213 SLOG(LOG_INFO, TAG_VCD, "@@@ Change language DONE");
218 static void __config_foreground_changed_cb(int previous, int current, void* user_data)
220 SLOG(LOG_DEBUG, TAG_VCD, "@@@ Change foreground");
222 SLOG(LOG_INFO, TAG_VCD, "Foreground pid(%d)", current);
224 if (VC_NO_FOREGROUND_PID != current) {
225 /* Foreground app is changed */
226 vcd_state_e state = vcd_config_get_service_state();
227 if (VCD_STATE_RECORDING == state) {
228 SLOG(LOG_INFO, TAG_VCD, "[Server] Foreground pid(%d) is changed. Cancel recognition", current);
229 ecore_timer_add(0, __cancel_by_interrupt, NULL);
233 SLOG(LOG_DEBUG, TAG_VCD, "@@@ Change foreground DONE");
238 static int __vcd_activate_app_by_appcontrol(const char* appid)
241 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Invalid parameter");
242 return VCD_ERROR_INVALID_PARAMETER;
246 app_control_h app_control = NULL;
247 ret = app_control_create(&app_control);
248 if (APP_CONTROL_ERROR_NONE == ret) {
250 ret = app_control_add_extra_data(app_control, "voice_launch", "get_result");
251 if (APP_CONTROL_ERROR_NONE != ret) {
252 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to add extra data, ret(%d)", ret);
253 app_control_destroy(app_control);
254 return VCD_ERROR_OPERATION_FAILED;
257 ret = app_control_set_app_id(app_control, appid);
258 if (APP_CONTROL_ERROR_NONE != ret) {
259 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to set app id, ret(%d)", ret);
260 app_control_destroy(app_control);
261 return VCD_ERROR_OPERATION_FAILED;
263 // Sent launch request
264 ret = app_control_send_launch_request(app_control, NULL, NULL);
265 if (APP_CONTROL_ERROR_NONE != ret) {
266 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to send launch request, ret(%d)", ret);
267 app_control_destroy(app_control);
268 return VCD_ERROR_OPERATION_FAILED;
270 // Destroy app control
271 ret = app_control_destroy(app_control);
272 if (APP_CONTROL_ERROR_NONE != ret) {
273 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to destroy, ret(%d)", ret);
274 return VCD_ERROR_OPERATION_FAILED;
277 return VCD_ERROR_NONE;
280 static int __vcd_resume_app(const char* appid)
282 app_context_h app_context = NULL;
283 int ret = app_manager_get_app_context(appid, &app_context);
284 if (APP_MANAGER_ERROR_NONE != ret) {
285 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to get app_context, ret(%d), appid(%s)", ret, appid);
286 return VCD_ERROR_OPERATION_FAILED;
289 ret = app_manager_resume_app(app_context);
290 int destroy_ret = app_context_destroy(app_context);
291 if (APP_MANAGER_ERROR_NONE != destroy_ret) {
292 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to destroy app_context, ret(%d), appid(%s)", destroy_ret, appid);
295 if (APP_MANAGER_ERROR_NONE != ret) {
296 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to resume app, ret(%d), appid(%s)", ret, appid);
297 return VCD_ERROR_OPERATION_FAILED;
300 return VCD_ERROR_NONE;
303 static bool __vcd_is_package_installed(const char* appid)
305 app_info_h app_info = NULL;
306 int ret = app_manager_get_app_info(appid, &app_info);
307 if (APP_MANAGER_ERROR_NONE != ret || NULL == app_info)
309 ret = app_info_destroy(app_info);
310 if (APP_MANAGER_ERROR_NONE != ret)
311 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to destroy app_info, ret(%d)", ret);
315 void __vc_free_deactivated_app(void* data)
317 vc_deactivated_app_s* d_app = (vc_deactivated_app_s*)data;
320 if (NULL != d_app->appid) {
330 static bool __vcd_launch_app(const char* result)
332 if (NULL == result) {
333 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Invalid parameter");
334 return VCD_ERROR_INVALID_PARAMETER;
337 GSList* app_list = NULL;
338 if (0 != vc_db_get_appid_list(result, &app_list)) {
339 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] result text is NULL");
340 return VCD_ERROR_INVALID_PARAMETER;
343 if (0 != g_slist_length(app_list)) {
345 GSList *iter = g_slist_nth(app_list, 0);
346 while (NULL != iter) {
347 vc_deactivated_app_s *temp_app = iter->data;
349 if (NULL != temp_app && NULL != temp_app->appid) {
351 bool running = false;
352 ret = app_manager_is_running(temp_app->appid, &running);
353 if (APP_MANAGER_ERROR_NONE != ret) {
354 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to check running with appid(%s)", temp_app->appid);
355 g_slist_free_full(iter, __vc_free_deactivated_app);
356 return VCD_ERROR_OPERATION_FAILED;
358 if (false == running) {
359 int tmp_ret = __vcd_is_package_installed(temp_app->appid);
360 if (false == tmp_ret) {
361 SLOG(LOG_WARN, TAG_VCD, "[WARNING] app is not installed, appid(%s)", temp_app->appid);
363 ret = __vcd_activate_app_by_appcontrol(temp_app->appid);
365 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to activate app");
366 g_slist_free_full(iter, __vc_free_deactivated_app);
369 SLOG(LOG_ERROR, TAG_VCD, "Launch app: appid(%s) result(%s)", temp_app->appid, result);
372 ret = __vcd_resume_app(temp_app->appid);
374 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to resume app");
375 g_slist_free_full(iter, __vc_free_deactivated_app);
378 SLOG(LOG_ERROR, TAG_VCD, "Resume app: appid(%s) result(%s)", temp_app->appid, result);
380 __vc_free_deactivated_app((void*)temp_app);
383 app_list = g_slist_remove_link(app_list, iter);
385 iter = g_slist_nth(app_list, 0);
390 return VCD_ERROR_NONE;
393 static Eina_Bool __vcd_send_selected_result(void *data)
395 GSList* pid_list = NULL;
396 const char* result = vcd_client_manager_get_result_text();
398 if (0 != vc_info_parser_get_result_pid_list(&pid_list, result)) {
399 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Fail to get pid list. No result");
401 if (0 < g_slist_length(pid_list)) {
406 GSList *iter = g_slist_nth(pid_list, 0);
407 while (NULL != iter) {
408 vc_cmd_s *temp_cmd = iter->data;
410 if (NULL != temp_cmd && (pre_pid != temp_cmd->pid || pre_type == VC_COMMAND_TYPE_WIDGET || temp_cmd->type == VC_COMMAND_TYPE_WIDGET)) {
411 /* Launch deactivated several apps that is matched with result */
412 ret = __vcd_launch_app(result);
414 SLOG(LOG_ERROR, TAG_VCD, "Fail to launch or resume app, ret(%d) result(%s)", ret, result);
416 /* send result noti */
417 ret = vcdc_send_result(temp_cmd->pid, vcd_client_manager_get_pid(), temp_cmd->type);
419 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Fail to send result, ret(%d)", ret);
420 g_slist_free_full(pid_list, free);
424 SLOG(LOG_ERROR, TAG_VCD, "[Server] Send result : pid(%d) type(%d)", temp_cmd->pid, temp_cmd->type);
425 pre_pid = temp_cmd->pid;
426 pre_type = temp_cmd->type;
432 pid_list = g_slist_remove_link(pid_list, iter);
434 iter = g_slist_nth(pid_list, 0);
439 if (VCD_RECOGNITION_MODE_RESTART_CONTINUOUSLY != vcd_client_get_recognition_mode()) {
440 vcd_config_set_service_state(VCD_STATE_READY);
441 vcdc_send_service_state(VCD_STATE_READY);
447 int vcd_send_asr_result(vce_asr_result_event_e event, const char* asr_result, void *user_data)
449 int ret = __vcd_server_launch_manager_app();
451 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);
455 if (NULL != asr_result) {
456 SECURE_SLOG(LOG_INFO, TAG_VCD, "[Server] ASR result - Event(%d), Text(%s)", event, asr_result);
457 ret = vcdc_send_pre_result_to_manager(vcd_client_manager_get_pid(), event, asr_result);
459 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);
466 int vcd_send_specific_engine_result(const char* engine_app_id, const char* event, const char* result, void *user_info)
468 if (NULL != result) {
469 SLOG(LOG_INFO, TAG_VCD, "[Server] specific engine result - Event(%s), Text(%s)", event, result);
470 vcdc_send_specific_engine_result_to_manager(vcd_client_manager_get_pid(), engine_app_id, event, result);
473 return VCD_ERROR_NONE;
476 int vcd_send_nlg_result(const char* nlg_result, void *user_data)
478 int ret = __vcd_server_launch_manager_app();
480 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);
484 SLOG(LOG_ERROR, TAG_VCD, "[Server] send dialog : mgr_pid(%d), nlg_result(%s)", vcd_client_manager_get_pid(), nlg_result);
485 ret = vcdc_send_dialog(vcd_client_manager_get_pid(), -1, nlg_result, NULL, 0); //0: VC_DIALOG_END
487 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);
491 static void* __recorder_stop(void *data)
497 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)
500 vcd_recognition_mode_e recognition_mode = vcd_client_get_recognition_mode();
502 if (VCD_STATE_PROCESSING != vcd_config_get_service_state()) {
503 if (VCD_RECOGNITION_MODE_RESTART_CONTINUOUSLY != recognition_mode) {
504 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Current state is not 'Processing' and mode is not 'Restart continuously'");
505 return VCD_ERROR_INVALID_STATE;
509 vc_info_parser_unset_result(vcd_client_manager_get_exclusive());
510 vcd_client_manager_set_result_text(all_result);
512 SECURE_SLOG(LOG_INFO, TAG_VCD, "[Server] Event(%d), Text(%s) Nonfixed(%s) Msg(%s) Result count(%d)",
513 event, all_result, non_fixed_result, msg, count);
515 SECURE_SLOG(LOG_ERROR, TAG_VCD, "[Server] NLU result(%s)", nlu_result);
518 /* if nlu_result is exist, Add command handle(is_action) into result list */
520 SLOG(LOG_INFO, TAG_VCD, "[Server] @ Get engine result @");
522 vc_cmd_s* temp_cmd = NULL;
523 vc_cmd_list_h vc_cmd_list = NULL;
525 if (0 != vc_cmd_list_create(&vc_cmd_list)) {
526 SLOG(LOG_INFO, TAG_VCD, "[Server] Fail to create command list");
527 vcd_client_manager_set_exclusive(false);
528 vcd_config_set_service_state(VCD_STATE_READY);
529 vcdc_send_service_state(VCD_STATE_READY);
530 return VCD_ERROR_NONE;
533 /* priority filter */
534 /* system > exclusive > widget > foreground > system_background > widget partial > foreground partial > background */
536 int* filtered_id = (int*)calloc(count, sizeof(int));
538 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to allocate memory");
539 vc_cmd_list_destroy(vc_cmd_list, true);
541 return VCD_ERROR_OUT_OF_MEMORY;
543 int filtered_count = 0;
544 int top_priority = VC_COMMAND_PRIORITY_BACKGROUND;
545 for (i = 0; i < count; i++) {
546 SLOG(LOG_INFO, TAG_VCD, "[Server] [%d] Result id(%d)", i, result_id[i]);
548 if (0 > result_id[i]) {
549 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Result ID(%d) is NOT valid", result_id[i]);
553 ret = vcd_client_get_cmd_from_result_id(result_id[i], &temp_cmd);
554 if (0 == ret && NULL != temp_cmd) {
555 if (top_priority == temp_cmd->priority) {
556 filtered_id[filtered_count] = result_id[i];
558 } else if (top_priority > temp_cmd->priority) {
559 filtered_id[0] = result_id[i];
561 top_priority = temp_cmd->priority;
564 vc_cmd_destroy((vc_cmd_h)temp_cmd);
569 if (top_priority >= VC_COMMAND_PRIORITY_WIDGET) {
570 int pid = vcd_client_widget_get_foreground_pid();
572 if (NULL != all_result) {
573 vc_info_parser_set_result(all_result, event, msg, NULL, false);
575 vcd_client_widget_get_asr_result_enabled(pid, &enable);
576 if (true == enable) {
577 SLOG(LOG_INFO, TAG_VCD, "[Server] Send ASR result to Widget client");
578 bool is_consumed = false;
579 if (NULL != user_info) {
582 if (0 != vcdc_send_asr_result(pid, event, all_result, VC_COMMAND_TYPE_WIDGET, &is_consumed)) {
583 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to send asr result");
585 SLOG(LOG_INFO, TAG_VCD, "[Server] ASR result is consumed(%d)", is_consumed);
586 if (true == is_consumed) {
587 if (NULL != user_info) {
589 SLOG(LOG_ERROR, TAG_VCD, "[Server] Send whether ASR result is consumed or not (%d)", *user_info);
591 vcdc_send_show_tooltip(pid, false);
592 if (-1 != vcd_client_manager_get_pid()) {
593 /* Manager client is available */
594 vc_info_parser_unset_result(false);
595 vc_info_parser_set_result(all_result, VC_RESULT_EVENT_RESULT_SUCCESS, msg, NULL, false);
596 if (0 != vcdc_send_result_to_manager(vcd_client_manager_get_pid(), VC_RESULT_TYPE_NOTIFICATION)) {
597 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Fail to send result");
601 // Set state manually, because the result is already handled in ASR result by client.
602 // So, the daemon does not need to send the result to client.
603 vcd_client_manager_set_exclusive(false);
605 vcd_config_set_service_state(VCD_STATE_READY);
606 vcdc_send_service_state(VCD_STATE_READY);
607 vc_cmd_list_destroy(vc_cmd_list, true);
609 if (NULL != filtered_id) {
613 return VCD_ERROR_NONE;
622 for (i = 0; i < filtered_count; i++) {
623 SLOG(LOG_INFO, TAG_VCD, "[Server] [%d] Filtered Result id(%d)", i, filtered_id[i]);
625 if (filtered_id[i] < 0) {
626 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Filtered ID(%d) is NOT valid", filtered_id[i]);
630 ret = vcd_client_get_cmd_from_result_id(filtered_id[i], &temp_cmd);
631 if (0 == ret && NULL != temp_cmd) {
632 switch (temp_cmd->format) {
633 case VC_CMD_FORMAT_FIXED:
634 case VC_CMD_FORMAT_FIXED_AND_VFIXED:
635 case VC_CMD_FORMAT_VFIXED_AND_FIXED:
636 case VC_CMD_FORMAT_PARTIAL:
637 case VC_CMD_FORMAT_FIXED_AND_NONFIXED:
638 case VC_CMD_FORMAT_NONFIXED_AND_FIXED:
640 case VC_CMD_FORMAT_ACTION:
644 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Unknown command type : %d", temp_cmd->type);
648 if (0 != vc_cmd_list_add(vc_cmd_list, (vc_cmd_h)temp_cmd)) {
649 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Fail to add command to list");
650 vc_cmd_destroy((vc_cmd_h)temp_cmd);
654 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] NOT found matched result(%d)", filtered_id[i]);
658 if (NULL != filtered_id) {
663 if (NULL != nlu_result) {
664 SECURE_SLOG(LOG_INFO, TAG_VCD, "[Server] NLU (%s)", nlu_result);
665 vc_info_parser_set_nlu_result(nlu_result);
666 if (0 == is_action) {
668 if (0 != vc_cmd_create(&nlu_cmd)) {
669 SLOG(LOG_ERROR, TAG_VCD, "Fail to nlu cmd create");
671 if (0 != vc_cmd_set_type(nlu_cmd, VC_COMMAND_TYPE_SYSTEM)) {
672 SLOG(LOG_ERROR, TAG_VCD, "Fail to set type");
674 if (0 != vc_cmd_set_pid(nlu_cmd, vcd_client_manager_get_pid())) {
675 SLOG(LOG_ERROR, TAG_VCD, "Fail to set pid");
677 if (0 != vc_cmd_set_format(nlu_cmd, VC_CMD_FORMAT_ACTION)) {
678 SLOG(LOG_ERROR, TAG_VCD, "Fail to set format");
680 if (0 != vc_cmd_list_add(vc_cmd_list, nlu_cmd)) {
681 SLOG(LOG_ERROR, TAG_VCD, "Fail to add nlu cmd to list");
682 vc_cmd_destroy(nlu_cmd);
688 vc_cmd_print_list(vc_cmd_list);
690 SLOG(LOG_INFO, TAG_VCD, "[Server] @@@@");
692 int result_count = 0;
693 vc_cmd_list_get_count(vc_cmd_list, &result_count);
695 /* Handle the result list */
696 if (0 == result_count) {
698 vc_cmd_list_h widget_cmd_list = NULL;
699 vc_cmd_list_h foreground_cmd_list = NULL;
700 if (NULL != all_result) {
701 SECURE_SLOG(LOG_INFO, TAG_VCD, "[Server] Engine result is no command : %s", all_result);
704 if (0 != vc_cmd_list_create(&widget_cmd_list)) {
705 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to create widget command list handle");
706 vc_cmd_list_destroy(vc_cmd_list, true);
708 return VCD_ERROR_OUT_OF_MEMORY;
711 /* Get the list of widget type commands */
712 vcd_client_append_cmd_from_type(VC_COMMAND_TYPE_WIDGET, widget_cmd_list);
713 vc_cmd_list_get_count(widget_cmd_list, &cnt);
715 /* Matched with widget command partially */
716 vc_cmd_get_partially_matched_cmd_list(all_result, widget_cmd_list, vc_cmd_list, VC_SEARCH_NONE_LEVEL);
717 vc_cmd_list_get_count(vc_cmd_list, &cnt);
719 top_priority = VC_COMMAND_PRIORITY_WIDGET;
720 SLOG(LOG_INFO, TAG_VCD, "[INFO] Partially matched widget command");
723 if (0 != vc_cmd_list_create(&foreground_cmd_list)) {
724 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to create foreground command list handle");
725 vc_cmd_list_destroy(vc_cmd_list, true);
727 vc_cmd_list_destroy(widget_cmd_list, true);
728 widget_cmd_list = NULL;
729 return VCD_ERROR_OUT_OF_MEMORY;
732 /* Get the list of foreground type commands */
733 vcd_client_append_cmd_from_type(VC_COMMAND_TYPE_FOREGROUND, foreground_cmd_list);
734 vc_cmd_list_get_count(foreground_cmd_list, &cnt);
736 /* Matched with foreground command partially */
737 vc_cmd_get_partially_matched_cmd_list(all_result, foreground_cmd_list, vc_cmd_list, VC_SEARCH_NONE_LEVEL);
738 vc_cmd_list_get_count(vc_cmd_list, &cnt);
740 top_priority = VC_COMMAND_PRIORITY_FOREGROUND;
741 SLOG(LOG_INFO, TAG_VCD, "[INFO] Partially matched foreground command");
744 vc_cmd_list_destroy(foreground_cmd_list, true);
745 foreground_cmd_list = NULL;
747 vc_cmd_list_destroy(widget_cmd_list, true);
748 widget_cmd_list = NULL;
750 SLOG(LOG_INFO, TAG_VCD, "[Server] Engine all result is NULL");
753 vc_cmd_list_get_count(vc_cmd_list, &result_count);
755 // After running partial matching algorithm, if there is no result.
756 if (0 == result_count) {
757 SLOG(LOG_INFO, TAG_VCD, "[Server] No commands even after partial matching");
759 bool temp = vcd_client_manager_get_exclusive();
760 vc_info_parser_set_result(all_result, event, msg, NULL, temp);
762 int pid = vcd_client_widget_get_foreground_pid();
764 SLOG(LOG_INFO, TAG_VCD, "[Server] Request tooltip hide");
765 /* Send to hide tooltip */
766 vcdc_send_show_tooltip(pid, false);
769 if (-1 != vcd_client_manager_get_pid()) {
770 /* Manager client is available */
771 if (0 != vcdc_send_result_to_manager(vcd_client_manager_get_pid(), VC_RESULT_TYPE_NORMAL)) {
772 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Fail to send result");
776 /* set service state ready */
777 vcd_config_set_service_state(VCD_STATE_READY);
778 vcdc_send_service_state(VCD_STATE_READY);
780 vcd_client_manager_set_exclusive(false);
781 vc_cmd_list_destroy(vc_cmd_list, true);
784 return VCD_ERROR_NONE;
787 // Partial matching algorithm find some commands
788 event = VC_RESULT_EVENT_RESULT_SUCCESS;
791 // There are more than one result.
792 if (false == vcd_client_manager_get_exclusive()) {
793 vc_cmd_list_h temp_list = NULL;
795 /* Foreground, Widget, Background, System, System-Background */
796 if (top_priority >= VC_COMMAND_PRIORITY_BACKGROUND) {
797 vc_cmd_list_h widget_cmd_list = NULL;
798 vc_cmd_list_h foreground_cmd_list = NULL;
801 if (0 != vc_cmd_list_create(&temp_list)) {
802 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to create widget command list handle");
803 vc_cmd_list_destroy(vc_cmd_list, true);
805 return VCD_ERROR_OUT_OF_MEMORY;
808 if (0 != vc_cmd_list_create(&widget_cmd_list)) {
809 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to create widget command list handle");
810 vc_cmd_list_destroy(vc_cmd_list, true);
812 vc_cmd_list_destroy(temp_list, true);
814 return VCD_ERROR_OUT_OF_MEMORY;
817 /* Get the list of widget type commands */
818 vcd_client_append_cmd_from_type(VC_COMMAND_TYPE_WIDGET, widget_cmd_list);
819 vc_cmd_list_get_count(widget_cmd_list, &cnt);
821 /* Matched with widget command partially */
822 vc_cmd_get_partially_matched_cmd_list(all_result, widget_cmd_list, temp_list, VC_SEARCH_NONE_LEVEL);
823 vc_cmd_list_get_count(temp_list, &cnt);
825 if (0 != vc_cmd_list_destroy(vc_cmd_list, true)) {
826 SLOG(LOG_WARN, TAG_VCD, "[WARNING] Fail to destroy list");
828 vc_cmd_list = temp_list;
829 top_priority = VC_COMMAND_PRIORITY_WIDGET;
830 event = VC_RESULT_EVENT_RESULT_SUCCESS;
831 SLOG(LOG_INFO, TAG_VCD, "[INFO] Partially matched widget command when background cmd exists");
834 if (0 != vc_cmd_list_create(&foreground_cmd_list)) {
835 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to create foreground command list handle");
836 vc_cmd_list_destroy(vc_cmd_list, true);
838 vc_cmd_list_destroy(widget_cmd_list, true);
839 widget_cmd_list = NULL;
840 return VCD_ERROR_OUT_OF_MEMORY;
843 /* Get the list of foreground type commands */
844 vcd_client_append_cmd_from_type(VC_COMMAND_TYPE_FOREGROUND, foreground_cmd_list);
845 vc_cmd_list_get_count(foreground_cmd_list, &cnt);
847 /* Matched with foreground command partially */
848 vc_cmd_get_partially_matched_cmd_list(all_result, foreground_cmd_list, temp_list, VC_SEARCH_NONE_LEVEL);
849 vc_cmd_list_get_count(temp_list, &cnt);
851 if (0 != vc_cmd_list_destroy(vc_cmd_list, true)) {
852 SLOG(LOG_WARN, TAG_VCD, "[WARNING] Fail to destroy list");
854 vc_cmd_list = temp_list;
855 top_priority = VC_COMMAND_PRIORITY_FOREGROUND;
856 event = VC_RESULT_EVENT_RESULT_SUCCESS;
857 SLOG(LOG_INFO, TAG_VCD, "[INFO] Partially matched foreground command when background cmd exists");
860 vc_cmd_list_destroy(foreground_cmd_list, true);
861 foreground_cmd_list = NULL;
863 vc_cmd_list_destroy(widget_cmd_list, true);
864 widget_cmd_list = NULL;
867 int pid = vcd_client_widget_get_foreground_pid();
869 SLOG(LOG_INFO, TAG_VCD, "[Server] Request tooltip hide");
870 vcdc_send_show_tooltip(pid, false);
873 vc_info_parser_set_result(all_result, event, msg, vc_cmd_list, false);
874 vc_cmd_list_destroy(vc_cmd_list, true);
877 if (-1 != vcd_client_manager_get_pid()) {
878 /* Manager client is available */
879 if (0 != vcdc_send_result_to_manager(vcd_client_manager_get_pid(), VC_RESULT_TYPE_NORMAL)) {
880 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Fail to send result");
883 SLOG(LOG_INFO, TAG_VCD, "[Server] Manager is NOT available. Send result to client directly");
884 ecore_timer_add(0, __vcd_send_selected_result, NULL);
887 /* exclusive command */
888 vc_info_parser_set_result(all_result, event, msg, vc_cmd_list, true);
889 vc_cmd_list_destroy(vc_cmd_list, true);
892 if (-1 != vcd_client_manager_get_pid()) {
893 /* Manager client is available */
894 if (0 != vcdc_send_result_to_manager(vcd_client_manager_get_pid(), VC_RESULT_TYPE_NORMAL)) {
895 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Fail to send result");
898 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Manager is NOT available");
901 vcd_client_manager_set_exclusive(false);
904 if (VCD_RECOGNITION_MODE_RESTART_AFTER_REJECT == recognition_mode) {
905 if (VCE_RESULT_EVENT_REJECTED == event) {
906 SLOG(LOG_INFO, TAG_VCD, "[Server] Restart by no or rejected result");
907 /* If no result and restart option is ON */
908 /* Send reject message */
909 bool temp = vcd_client_manager_get_exclusive();
910 vc_info_parser_set_result(all_result, event, msg, NULL, temp);
911 ret = vcdc_send_result_to_manager(vcd_client_manager_get_pid(), VC_RESULT_TYPE_NOTIFICATION);
913 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Fail to send result");
916 g_restart_timer = ecore_timer_add(0, __restart_engine, NULL);
919 SLOG(LOG_INFO, TAG_VCD, "[Server] Stop recorder due to success");
920 //vcd_recorder_stop();
921 ecore_main_loop_thread_safe_call_sync(__recorder_stop, NULL);
922 } else if (VCD_RECOGNITION_MODE_RESTART_CONTINUOUSLY == recognition_mode) {
923 SLOG(LOG_INFO, TAG_VCD, "[Server] Restart continuously");
924 /* Restart option is ON */
925 g_restart_timer = ecore_timer_add(0, __restart_engine, NULL);
926 if (VCE_RESULT_EVENT_REJECTED == event) {
927 bool temp = vcd_client_manager_get_exclusive();
928 vc_info_parser_set_result(all_result, event, msg, NULL, temp);
929 ret = vcdc_send_result_to_manager(vcd_client_manager_get_pid(), VC_RESULT_TYPE_NOTIFICATION);
931 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Fail to send result");
937 return VCD_ERROR_NONE;
941 if (NULL == result_id) {
943 if (NULL != all_result) {
944 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Engine result is no command : %s", all_result);
945 bool temp = vcd_client_manager_get_exclusive();
946 vc_info_parser_set_result(all_result, event, msg, NULL, temp);
949 int pid = vcd_client_widget_get_foreground_pid();
951 if (NULL != all_result) {
952 /* Send result text to widget */
953 vcdc_send_result(pid, vcd_client_manager_get_pid(), VC_COMMAND_TYPE_WIDGET);
956 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Request tooltip hide");
957 /* Send to hide tooltip */
958 vcdc_send_show_tooltip(pid, false);
961 if (-1 != vcd_client_manager_get_pid()) {
962 /* Manager client is available */
963 if (0 != vcdc_send_result_to_manager(vcd_client_manager_get_pid(), VC_RESULT_TYPE_NORMAL)) {
964 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Fail to send result");
968 vcd_client_manager_set_exclusive(false);
974 SLOG(LOG_DEBUG, TAG_VCD, "[Server] @ Get engine result @");
977 vc_cmd_s* temp_cmd = NULL;
978 vc_cmd_list_h vc_cmd_list = NULL;
980 if (0 != vc_cmd_list_create(&vc_cmd_list)) {
981 SLOG(LOG_ERROR, TAG_VCD, "[Server] Fail to create command list");
982 vcd_client_manager_set_exclusive(false);
983 vcd_config_set_service_state(VCD_STATE_READY);
984 vcdc_send_service_state(VCD_STATE_READY);
989 for (i = 0; i < count; i++) {
990 SLOG(LOG_DEBUG, TAG_VCD, "[Server] [%d] Result ID(%d)", i, result_id[i]);
992 if (result_id[i] < 0) {
993 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Result ID(%d) is NOT valid", result_id[i]);
997 ret = vcd_client_get_cmd_from_result_id(result_id[i], &temp_cmd);
998 if (0 == ret && NULL != temp_cmd) {
999 switch (temp_cmd->format) {
1000 case VC_CMD_FORMAT_FIXED:
1001 case VC_CMD_FORMAT_FIXED_AND_VFIXED:
1002 case VC_CMD_FORMAT_VFIXED_AND_FIXED:
1003 case VC_CMD_FORMAT_PARTIAL:
1004 /* Nonfixed result is NOT valid */
1006 case VC_CMD_FORMAT_FIXED_AND_NONFIXED:
1007 if (NULL == temp_cmd->parameter) {
1008 if (NULL != non_fixed_result) {
1009 temp_cmd->parameter = strdup(non_fixed_result);
1012 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Command type is NOT valid. Parameter (%s)", temp_cmd->parameter);
1015 case VC_CMD_FORMAT_NONFIXED_AND_FIXED:
1016 if (NULL == temp_cmd->command) {
1017 if (NULL != non_fixed_result) {
1018 temp_cmd->command = strdup(non_fixed_result);
1021 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Command type is NOT valid. Command (%s)", temp_cmd->command);
1026 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Unknown command type : %d", temp_cmd->type);
1030 if (0 != vc_cmd_list_add(vc_cmd_list, (vc_cmd_h)temp_cmd)) {
1031 SLOG(LOG_DEBUG, TAG_VCD, "Fail to add command to list");
1032 vc_cmd_destroy((vc_cmd_h)temp_cmd);
1035 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] NOT found matched result(%d)", result_id[i]);
1039 vc_cmd_print_list(vc_cmd_list);
1041 SLOG(LOG_DEBUG, TAG_VCD, "[Server] @@@@");
1043 int result_count = 0;
1044 vc_cmd_list_get_count(vc_cmd_list, &result_count);
1046 if (false == vcd_client_manager_get_exclusive()) {
1047 int pid = vcd_client_widget_get_foreground_pid();
1049 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Request tooltip hide");
1050 vcdc_send_show_tooltip(pid, false);
1053 vc_info_parser_set_result(all_result, event, msg, vc_cmd_list, false);
1055 if (-1 != vcd_client_manager_get_pid()) {
1056 /* Manager client is available */
1057 if (0 != vcdc_send_result_to_manager(vcd_client_manager_get_pid(), VC_RESULT_TYPE_NORMAL)) {
1058 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Fail to send result");
1061 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Manager is NOT available. Send result to client directly");
1062 /* Send result to client */
1063 ecore_timer_add(0, __vcd_send_selected_result, NULL);
1066 /* exclusive command */
1067 vc_info_parser_set_result(all_result, event, msg, vc_cmd_list, true);
1069 if (-1 != vcd_client_manager_get_pid()) {
1070 /* Manager client is available */
1071 if (0 != vcdc_send_result_to_manager(vcd_client_manager_get_pid(), VC_RESULT_TYPE_NORMAL)) {
1072 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Fail to send result");
1075 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Manager is NOT available");
1078 vcd_client_manager_set_exclusive(false);
1081 vc_cmd_list_destroy(vc_cmd_list, true);
1089 static void __vcd_server_nlu_result_cb(vce_result_event_e event, const char* nlu_result, void *user_data)
1091 SECURE_SLOG(LOG_DEBUG, TAG_VCD, "[Server] NLU result cb - event(%d)", event);
1092 SECURE_SLOG(LOG_DEBUG, TAG_VCD, "[Server] result (%s)", nlu_result);
1094 int ret = vc_info_parser_set_nlu_result(nlu_result);
1096 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to set nlu result (%d)", ret);
1103 int vcd_send_error(vce_error_e error, const char* msg, void *user_data)
1105 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Engine Error cb - reason(%d), msg(%s)", error, msg);
1107 char* error_msg = NULL;
1109 error_msg = strdup(msg);
1110 if (NULL == error_msg) {
1111 return VCD_ERROR_OUT_OF_MEMORY;
1115 int ret = VCD_ERROR_NONE;
1116 if (VCE_ERROR_TTS_FAILED == error) {
1117 int pid = __get_tts_played_pid();
1118 ret = vcdc_send_error_signal_to_app(pid, error, error_msg);
1120 ret = vcdc_send_error_to_manager(vcd_client_manager_get_pid(), error, error_msg);
1121 ecore_main_loop_thread_safe_call_async(__cancel_by_error, NULL);
1124 if (VCD_ERROR_NONE != ret) {
1125 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to send error signal");
1128 if (NULL != error_msg) {
1136 /* for TTS feedback */
1137 int vcd_send_feedback_audio_format(int rate, vce_audio_channel_e channel, vce_audio_type_e audio_type)
1139 SLOG(LOG_INFO, TAG_VCD, "[Server DEBUG] Engine - Send TTS feedback audio format, g_current_tts_uid(%u)", g_current_tts_uid);
1141 /* send TTS feedback audio format to VC manager */
1142 int ret = VCD_ERROR_NONE;
1143 int pid = __get_tts_played_pid();
1144 if (VC_INVALID_TTS_UID == pid || vcd_client_manager_get_pid() == pid) {
1145 ret = vcdc_send_feedback_audio_format_to_manager(vcd_client_manager_get_pid(), rate, channel, audio_type);
1146 if (VCD_ERROR_NONE != ret) {
1147 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to send TTS feedback audio format to VC manager");
1150 SLOG(LOG_INFO, TAG_VCD, "[Server INFO] Do not send TTS feedback audio format to VC manager");
1156 int vcd_send_feedback_streaming(vce_feedback_event_e event, char* buffer, int len)
1158 if (VC_INVALID_TTS_UID == g_current_tts_uid && VCE_FEEDBACK_EVENT_START == event) {
1159 g_current_utt_id = (g_current_utt_id + 1) % 1000;
1160 g_current_tts_uid = (unsigned int)vcd_client_manager_get_pid() * 1000u + g_current_utt_id;
1161 SLOG(LOG_INFO, TAG_VCD, "[Server info] set current uid and utt_id as manager pid(%d)", vcd_client_manager_get_pid());
1164 int ret = VCD_ERROR_NONE;
1165 int pid = __get_tts_played_pid();
1166 int utt_id = g_current_tts_uid % 1000;
1168 SLOG(LOG_INFO, TAG_VCD, "[Server DEBUG] Engine - Send TTS feedback streaming event(%d), uid(%u), is_mgr_client(%d)", event, g_current_tts_uid, (pid == vcd_client_manager_get_pid() ? true : false));
1170 if (VC_INVALID_TTS_UID == pid || pid == vcd_client_manager_get_pid() || -1 == vcd_client_manager_get_pid()) {
1171 /* send TTS feedback streaming to manager client */
1172 ret = vcdc_send_feedback_streaming_to_manager(vcd_client_manager_get_pid(), pid, utt_id, event, buffer, len);
1173 if (VCD_ERROR_NONE != ret) {
1174 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to send TTS feedback streaming to manager client");
1177 /* send TTS feedback streaming to client */
1178 ret = vcdc_send_feedback_streaming(pid, utt_id, event, buffer, len);
1179 if (VCD_ERROR_NONE != ret) {
1180 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to send TTS feedback streaming to client");
1184 if (VCE_FEEDBACK_EVENT_FINISH == event) {
1185 /* reset current uid */
1186 g_current_tts_uid = VC_INVALID_TTS_UID;
1188 /* Set service state to ready if state is synthesizing */
1189 vcd_state_e state = vcd_config_get_service_state();
1190 if (VCD_STATE_SYNTHESIZING == state) {
1191 vcd_config_set_service_state(VCD_STATE_READY);
1193 SLOG(LOG_INFO, TAG_VCD, "[Server info] feedback streaming finish event, reset current uid & service state(%d)", vcd_config_get_service_state());
1200 * vcd server Interfaces
1202 static void __vcd_file_clean_up()
1204 SLOG(LOG_INFO, TAG_VCD, "== Old file clean up == ");
1207 struct dirent *dirp = NULL;
1209 dp = opendir(VC_RUNTIME_INFO_ROOT);
1211 SLOG(LOG_ERROR, TAG_VCD, "[File message WARN] Fail to open path : %s", VC_RUNTIME_INFO_ROOT);
1215 char remove_path[257] = {0, };
1220 if (!strncmp("vc_", dirp->d_name, strlen("vc_"))) {
1221 memset(remove_path, 0, 257);
1222 snprintf(remove_path, 257, "%s/%s", VC_RUNTIME_INFO_ROOT, dirp->d_name);
1225 if (0 != remove(remove_path)) {
1226 SLOG(LOG_WARN, TAG_VCD, "[File message WARN] Fail to remove file : %s", remove_path);
1228 SLOG(LOG_INFO, TAG_VCD, "[File message] Remove file : %s", remove_path);
1232 } while (NULL != dirp);
1239 static int __vcd_db_clean_up()
1242 int cnt = VC_COMMAND_TYPE_FOREGROUND;
1244 if (VC_COMMAND_TYPE_BACKGROUND != cnt)
1245 ret = vc_db_delete_commands(-1, cnt, NULL);
1246 } while (VC_COMMAND_TYPE_EXCLUSIVE >= ++cnt);
1252 static bool __is_default_engine()
1254 char* engine = NULL;
1255 engine = vconf_get_str(VCONFKEY_VC_ENGINE_DEFAULT);
1256 if (NULL == engine) {
1257 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to get sting for vc engine");
1261 char appid[1024] = {'\0', };
1262 if (0 != aul_app_get_appid_bypid(getpid(), appid, sizeof(appid) - 1)) {
1263 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to get callee appid by pid");
1266 SLOG(LOG_DEBUG, TAG_VCD, "[Server] VC Default Engine(%s), appId(%s)", engine, appid);
1267 if (0 == strncmp(engine, appid, strlen(engine))) {
1276 int vcd_initialize(vce_request_callback_s *callback)
1280 /* Remove old file */
1281 __vcd_file_clean_up();
1283 /* initialize modules */
1284 ret = vcd_config_initialize(__config_lang_changed_cb, __config_foreground_changed_cb, NULL);
1286 SLOG(LOG_ERROR, TAG_VCD, "[Server WARNING] Fail to initialize config.");
1289 ret = vc_db_initialize_for_daemon();
1291 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to initialize DB : %d", ret);
1292 if (TRUE != vcd_finalize()) {
1293 SLOG(LOG_ERROR, TAG_VCD, "[Server Error] Fail to finalize");
1298 /* Remove db data */
1299 ret = __vcd_db_clean_up();
1301 SLOG(LOG_ERROR, TAG_VCD, "[Server WARNING] Fail to remove db data");
1304 vcd_config_set_service_state(VCD_STATE_NONE);
1306 ret = vcd_engine_agent_init();
1308 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to engine agent initialize : result(%d)", ret);
1309 if (TRUE != vcd_finalize()) {
1310 SLOG(LOG_ERROR, TAG_VCD, "[Server Error] Fail to finalize");
1315 if (0 != vcd_recorder_create(__server_recorder_callback, __server_recorder_interrupt_callback)) {
1316 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to create recorder");
1317 if (TRUE != vcd_finalize()) {
1318 SLOG(LOG_ERROR, TAG_VCD, "[Server Error] Fail to finalize");
1320 return VCD_ERROR_OPERATION_FAILED;
1324 if (0 != vcd_engine_agent_load_current_engine(callback)) {
1325 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to load current engine");
1326 if (TRUE != vcd_finalize()) {
1327 SLOG(LOG_ERROR, TAG_VCD, "[Server Error] Fail to finalize");
1329 return VCD_ERROR_OPERATION_FAILED;
1332 /* Initialize manager info */
1333 vcd_client_manager_unset();
1335 // if (TRUE == __is_default_engine()) {
1336 /* Open tidl connection */
1337 if (0 != vcd_tidl_open_connection()) {
1338 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to open tidl connection");
1339 if (TRUE != vcd_finalize()) {
1340 SLOG(LOG_ERROR, TAG_VCD, "[Server Error] Fail to finalize");
1342 return VCD_ERROR_OPERATION_FAILED;
1346 vcd_config_set_service_state(VCD_STATE_READY);
1347 // vcdc_send_service_state(VCD_STATE_READY);
1349 /* Set timer cleanup client all */
1350 g_check_client_timer = ecore_timer_add(CLIENT_CLEAN_UP_TIME, vcd_cleanup_client_all, NULL);
1351 if (NULL == g_check_client_timer) {
1352 SLOG(LOG_WARN, TAG_VCD, "[Server Warning] Fail to create timer of client check");
1355 g_current_tts_uid = VC_INVALID_TTS_UID;
1356 g_current_utt_id = -1;
1358 SLOG(LOG_ERROR, TAG_VCD, "[Server SUCCESS] initialize");
1360 return VCD_ERROR_NONE;
1366 if (0 < g_list_length(g_proc_list)) {
1367 iter = g_list_first(g_proc_list);
1368 while (NULL != iter) {
1369 g_proc_list = g_list_delete_link(g_proc_list, iter);
1370 iter = g_list_first(g_proc_list);
1374 if (NULL != g_restart_timer) {
1375 ecore_timer_del(g_restart_timer);
1376 g_restart_timer = NULL;
1379 if (NULL != g_check_client_timer) {
1380 ecore_timer_del(g_check_client_timer);
1381 g_check_client_timer = NULL;
1384 vcd_state_e state = vcd_config_get_service_state();
1385 if (VCD_STATE_NONE != state && VCD_STATE_READY != state) {
1386 if (VCD_STATE_RECORDING == state) {
1387 vcd_recorder_stop();
1389 vcd_engine_recognize_cancel();
1392 if (0 != vcd_recorder_destroy()) {
1393 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to destroy recorder");
1396 SLOG(LOG_DEBUG, TAG_VCD, "[Server] destroy recorder");
1399 if (0 != vcd_engine_agent_release()) {
1400 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to release engine");
1403 SLOG(LOG_DEBUG, TAG_VCD, "[Server] release engine");
1406 vcd_client_manager_unset_appid();
1408 int ret = vcd_config_finalize();
1410 SLOG(LOG_ERROR, TAG_VCD, "[Server WARNING] Fail to finalize config.");
1413 ret = vc_db_finalize();
1415 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to finalize DB : %d", ret);
1418 if (VCD_STATE_NONE != state) {
1419 vcd_config_set_service_state(VCD_STATE_NONE);
1420 vcdc_send_service_state(VCD_STATE_NONE);
1423 /* Close tidl connection */
1424 if (0 != vcd_tidl_close_connection()) {
1425 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to close connection");
1428 SLOG(LOG_ERROR, TAG_VCD, "[Server] mode finalize");
1433 static Eina_Bool __finalize_quit_ecore_loop(void *data)
1435 bool ret = vcd_finalize();
1439 ecore_main_loop_quit();
1444 static void __read_proc()
1447 struct dirent *dirp = NULL;
1451 if (0 < g_list_length(g_proc_list)) {
1452 iter = g_list_first(g_proc_list);
1453 while (NULL != iter) {
1454 g_proc_list = g_list_delete_link(g_proc_list, iter);
1455 iter = g_list_first(g_proc_list);
1459 dp = opendir("/proc");
1461 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to open proc");
1467 tmp = atoi(dirp->d_name);
1468 if (0 >= tmp) continue;
1469 g_proc_list = g_list_append(g_proc_list, GINT_TO_POINTER(tmp));
1471 } while (NULL != dirp);
1477 static inline const char *__get_client_type(vcd_client_type_e type)
1480 case VCD_CLIENT_TYPE_NORMAL:
1482 case VCD_CLIENT_TYPE_WIDGET:
1484 case VCD_CLIENT_TYPE_MANAGER:
1491 static void __vcd_cleanup_client(vcd_client_type_e type)
1493 int* client_list = NULL;
1494 int client_count = 0;
1501 if (VCD_CLIENT_TYPE_NORMAL == type) {
1502 ret = vcd_client_get_list(&client_list, &client_count);
1503 } else if (VCD_CLIENT_TYPE_WIDGET == type) {
1504 ret = vcd_client_widget_get_list(&client_list, &client_count);
1505 } else if (VCD_CLIENT_TYPE_MANAGER == type) {
1506 mgr_pid = vcd_client_manager_get_pid();
1507 client_list = &mgr_pid;
1509 if (-1 == mgr_pid) {
1510 SLOG(LOG_WARN, TAG_VCD, "[WARNING] Invalid Manager pid");
1515 if (0 == ret || mgr_pid > 0) {
1516 SLOG(LOG_INFO, TAG_VCD, "@@@ Clean up %s client ", __get_client_type(type));
1517 if (NULL != client_list && client_count > 0) {
1518 for (i = 0; i < client_count; i++) {
1521 for (j = 0; j < g_list_length(g_proc_list); j++) {
1522 iter = g_list_nth(g_proc_list, j);
1524 if (*(client_list + i) == GPOINTER_TO_INT(iter->data)) {
1525 SLOG(LOG_INFO, TAG_VCD, "%s pid(%d) is running", __get_client_type(type), *(client_list + i));
1532 if (false == exist) {
1533 SLOG(LOG_ERROR, TAG_VCD, "%s pid(%d) should be removed", __get_client_type(type), *(client_list + i));
1534 if (VCD_CLIENT_TYPE_NORMAL == type)
1535 vcd_server_finalize(*(client_list + i));
1536 else if (VCD_CLIENT_TYPE_WIDGET == type)
1537 vcd_server_widget_finalize(*(client_list + i));
1539 vcd_server_mgr_finalize(mgr_pid);
1543 SLOG(LOG_INFO, TAG_VCD, "@@@");
1545 if (NULL != client_list && -1 == mgr_pid) {
1552 Eina_Bool vcd_cleanup_client_all(void *data)
1556 __vcd_cleanup_client(VCD_CLIENT_TYPE_NORMAL);
1557 __vcd_cleanup_client(VCD_CLIENT_TYPE_WIDGET);
1558 __vcd_cleanup_client(VCD_CLIENT_TYPE_MANAGER);
1560 if (0 == vcd_client_get_ref_count()) {
1561 SLOG(LOG_INFO, TAG_VCD, "[Server] Connected client list is empty");
1562 ecore_timer_add(0, __finalize_quit_ecore_loop, NULL);
1565 if (0 == vcd_client_get_list(&client_list, &client_count)) {
1566 SLOG(LOG_DEBUG, TAG_VCD, "@@@ Clean up client ");
1567 if (NULL != client_list && client_count > 0) {
1568 for (i = 0; i < client_count; i++) {
1571 for (j = 0; j < g_list_length(g_proc_list); j++) {
1572 iter = g_list_nth(g_proc_list, j);
1574 if (client_list[i] == GPOINTER_TO_INT(iter->data)) {
1575 SLOG(LOG_DEBUG, TAG_VCD, "pid(%d) is running", client_list[i]);
1582 if (false == exist) {
1583 SLOG(LOG_ERROR, TAG_VCD, "pid(%d) should be removed", client_list[i]);
1584 vcd_server_finalize(client_list[i]);
1587 result = vcdc_send_hello(client_list[i], VCD_CLIENT_TYPE_NORMAL);
1590 SLOG(LOG_DEBUG, TAG_VCD, "[Server] pid(%d) should be removed.", client_list[i]);
1591 vcd_server_finalize(client_list[i]);
1592 } else if (-1 == result) {
1593 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Hello result has error");
1598 SLOG(LOG_DEBUG, TAG_VCD, "@@@");
1600 if (NULL != client_list) {
1605 /* If app is in background state, app cannot response message. */
1606 if (0 == vcd_client_widget_get_list(&client_list, &client_count)) {
1607 SLOG(LOG_DEBUG, TAG_VCD, "@@@ Clean up widget");
1608 if (NULL != client_list && client_count > 0) {
1609 for (i = 0; i < client_count; i++) {
1612 for (j = 0; j < g_list_length(g_proc_list); j++) {
1613 iter = g_list_nth(g_proc_list, j);
1615 if (client_list[i] == GPOINTER_TO_INT(iter->data)) {
1616 SLOG(LOG_DEBUG, TAG_VCD, "widget pid(%d) is running", client_list[i]);
1623 if (false == exist) {
1624 SLOG(LOG_ERROR, TAG_VCD, "widget pid(%d) should be removed", client_list[i]);
1625 vcd_server_widget_finalize(client_list[i]);
1628 result = vcdc_send_hello(client_list[i], VCD_CLIENT_TYPE_WIDGET);
1631 SLOG(LOG_DEBUG, TAG_VCD, "[Server] widget pid(%d) should be removed.", client_list[i]);
1632 vcd_server_widget_finalize(client_list[i]);
1633 } else if (-1 == result) {
1634 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Hello result has error");
1639 SLOG(LOG_DEBUG, TAG_VCD, "@@@");
1642 if (NULL != client_list) {
1650 int mgr_pid = vcd_client_manager_get_pid();
1652 for (j = 0; j < g_list_length(g_proc_list); j++) {
1653 iter = g_list_nth(g_proc_list, j);
1655 if (mgr_pid == GPOINTER_TO_INT(iter->data)) {
1656 SLOG(LOG_DEBUG, TAG_VCD, "manager pid(%d) is running", mgr_pid);
1663 if (false == exist) {
1664 SLOG(LOG_ERROR, TAG_VCD, "manager pid (%d) should be removed", mgr_pid);
1665 vcd_server_mgr_finalize(mgr_pid);
1672 int vcd_server_get_service_state()
1674 return vcd_config_get_service_state();
1677 int vcd_server_get_foreground()
1680 vcd_config_get_foreground(&pid);
1687 int vcd_server_mgr_initialize(int pid, vcd_audio_streaming_mode_e mode)
1689 /* check if pid is valid */
1690 if (false == vcd_client_manager_is_valid(pid)) {
1691 SLOG(LOG_ERROR, TAG_VCD, "[Server] old manager pid(%d) be removed", vcd_client_manager_get_pid());
1692 vcd_server_mgr_cancel();
1693 vcd_client_manager_unset();
1696 /* Add client information to client manager */
1697 int ret = vcd_client_manager_set(pid);
1699 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to add manager");
1700 return VCD_ERROR_OPERATION_FAILED;
1703 if (0 != vcdc_send_manager_pid(pid))
1704 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Fail to send manager pid");
1706 vcd_recorder_set_audio_streaming_mode(mode);
1708 SLOG(LOG_ERROR, TAG_VCD, "[Server Success] Manager initialize : pid(%d)", pid);
1710 return VCD_ERROR_NONE;
1713 int vcd_server_mgr_finalize(int pid)
1715 /* check if pid is valid */
1716 if (false == vcd_client_manager_is_valid(pid)) {
1717 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] The manager pid(%d) is NOT valid", pid);
1718 return VCD_ERROR_INVALID_PARAMETER;
1721 /* Cancel recognition */
1722 vcd_server_mgr_cancel();
1724 if (0 != vcdc_send_manager_pid(-1))
1725 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Fail to send manager pid");
1727 /* Remove manager information */
1728 if (0 != vcd_client_manager_unset()) {
1729 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Fail to delete client");
1732 if (0 == vcd_client_get_ref_count()) {
1733 SLOG(LOG_INFO, TAG_VCD, "[Server] Connected client list is empty");
1734 ecore_timer_add(0, __finalize_quit_ecore_loop, NULL);
1737 SLOG(LOG_ERROR, TAG_VCD, "[Server Success] Manager Finalize : pid(%d)", pid);
1739 return VCD_ERROR_NONE;
1742 int vcd_server_mgr_set_command(int pid)
1744 if (0 != vcd_client_manager_set_command(pid)) {
1745 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] The manager pid(%d) is NOT valid", pid);
1746 return VCD_ERROR_INVALID_PARAMETER;
1748 return VCD_ERROR_NONE;
1751 int vcd_server_mgr_unset_command(int pid)
1753 if (0 != vcd_client_manager_unset_command(pid)) {
1754 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] The manager pid(%d) is NOT valid", pid);
1755 return VCD_ERROR_INVALID_PARAMETER;
1757 return VCD_ERROR_NONE;
1760 int vcd_server_mgr_set_demandable_client(int pid)
1762 /* check if pid is valid */
1763 if (false == vcd_client_manager_is_valid(pid)) {
1764 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] The manager pid(%d) is NOT valid", pid);
1765 return VCD_ERROR_INVALID_PARAMETER;
1768 GSList* client_list = NULL;
1769 if (0 != vc_info_parser_get_demandable_clients(&client_list)) {
1770 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to get demandable client");
1771 return VCD_ERROR_OPERATION_FAILED;
1774 /* Save client list */
1775 if (0 != vcd_client_manager_set_demandable_client(pid, client_list)) {
1776 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to set demandable client list");
1777 return VCD_ERROR_OPERATION_FAILED;
1780 return VCD_ERROR_NONE;
1783 int vcd_server_mgr_set_audio_type(int pid, const char* audio_type)
1785 /* check if pid is valid */
1786 if (false == vcd_client_manager_is_valid(pid)) {
1787 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] The manager pid(%d) is NOT valid", pid);
1788 return VCD_ERROR_INVALID_PARAMETER;
1792 vce_audio_type_e type = VCE_AUDIO_TYPE_PCM_S16_LE;
1796 ret = vcd_engine_get_audio_format(audio_type, &type, &rate, &channel);
1798 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to get audio format : %d", ret);
1799 return VCD_ERROR_OPERATION_FAILED;
1802 ret = vcd_recorder_set(audio_type, type, rate, channel);
1804 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to set audio in type : %d", ret);
1805 return VCD_ERROR_OPERATION_FAILED;
1808 return VCD_ERROR_NONE;
1811 int vcd_server_mgr_get_audio_type(int pid, char** audio_type)
1813 /* check if pid is valid */
1814 if (false == vcd_client_manager_is_valid(pid)) {
1815 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] The manager pid(%d) is NOT valid", pid);
1816 return VCD_ERROR_INVALID_PARAMETER;
1819 int ret = vcd_recorder_get(audio_type);
1821 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to get audio in type : %d", ret);
1822 return VCD_ERROR_OPERATION_FAILED;
1825 return VCD_ERROR_NONE;
1828 int vcd_server_mgr_set_client_info(int pid)
1830 /* check if pid is valid */
1831 if (false == vcd_client_manager_is_valid(pid)) {
1832 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] The manager pid(%d) is NOT valid", pid);
1833 return VCD_ERROR_INVALID_PARAMETER;
1836 int ret = vcd_client_save_client_info();
1838 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to save client info : %d", ret);
1839 return VCD_ERROR_OPERATION_FAILED;
1842 return VCD_ERROR_NONE;
1845 static int __reset_waiting_for_widget_recording(void)
1847 SLOG(LOG_ERROR, TAG_VCD, "[Server] Reset waiting for widget recording");
1848 // Delete timer to check that widget client is terminated
1849 if (g_check_widget_client_timer) {
1850 ecore_timer_del(g_check_widget_client_timer);
1851 g_check_widget_client_timer = NULL;
1853 // Reset flag to wait for recording from widget client
1854 vcd_client_widget_set_waiting_for_recording(-1, false);
1855 return VCD_ERROR_NONE;
1859 static Eina_Bool __send_waiting_timeout_error_to_manager(void* data)
1861 intptr_t ppid = (intptr_t)data;
1862 int pid = (int)ppid;
1863 SLOG(LOG_ERROR, TAG_VCD, "Widget client didn't send to start recording, pid(%d)", pid);
1864 __reset_waiting_for_widget_recording();
1866 vcdc_send_error_signal_to_manager(vcd_client_manager_get_pid(), VCD_ERROR_OPERATION_FAILED, "voice_engine.error.proc_fail");
1870 static Eina_Bool __send_waiting_timeout_start_recording(void* data)
1872 intptr_t ppid = (intptr_t)data;
1873 int pid = (int)ppid;
1874 SLOG(LOG_ERROR, TAG_VCD, "Widget client didn't send to start recording, pid(%d)", pid);
1876 int ret = __start_internal_recognition();
1878 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to start recognition : %d", ret);
1885 static int __set_waiting_for_widget_recording(int pid)
1887 SLOG(LOG_ERROR, TAG_VCD, "[Server] Set waiting for widget recording, pid(%d)", pid);
1889 // Check if the app included widget client is terminated or not. If it is terminated, vcd_server_widget_finalize() function will be called
1890 // In that function, it will start recording
1891 intptr_t ppid = (intptr_t)pid;
1892 g_check_widget_client_timer = ecore_timer_add(2.0, __send_waiting_timeout_start_recording, (void*)ppid);
1894 // Set flag to wait for recording from widget client
1895 vcd_client_widget_set_waiting_for_recording(pid, true);
1896 return VCD_ERROR_NONE;
1899 static int __start_internal_recognition()
1902 __reset_waiting_for_widget_recording();
1904 if (0 != vcd_client_command_collect_command()) {
1905 SLOG(LOG_ERROR, TAG_VCD, "[Client Data ERROR] Fail to collect command");
1906 /* Send error cb to manager */
1907 int pid = vcd_client_widget_get_foreground_pid();
1909 vcdc_send_error_to_manager(vcd_client_manager_get_pid(), VCD_ERROR_OPERATION_FAILED, "voice_framework.error.vcfw.collect_command_fail");
1910 return VCD_ERROR_OPERATION_FAILED;
1913 /* 3. Set command to engine */
1914 ret = vcd_engine_set_commands();
1916 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to set commands : %d", ret);
1917 /* Send error cb to manager */
1918 int pid = vcd_client_widget_get_foreground_pid();
1920 vcdc_send_error_to_manager(vcd_client_manager_get_pid(), VCD_ERROR_OPERATION_FAILED, "voice_framework.error.engine.set_commands_fail");
1921 return VCD_ERROR_OPERATION_FAILED;
1924 SLOG(LOG_ERROR, TAG_VCD, "[Server Success] Set command");
1926 bool stop_by_silence = true;
1927 if (VCD_RECOGNITION_MODE_MANUAL == vcd_client_get_recognition_mode()) {
1928 stop_by_silence = false;
1931 vcd_client_manager_set_result_text(NULL);
1933 /* 4. start recognition */
1934 ret = vcd_engine_recognize_start(stop_by_silence);
1936 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to start recognition : result(%d)", ret);
1937 /* Send error cb to manager */
1938 int pid = vcd_client_widget_get_foreground_pid();
1940 vcdc_send_error_to_manager(vcd_client_manager_get_pid(), ret, "voice_framework.error.engine.start_fail");
1944 SLOG(LOG_ERROR, TAG_VCD, "[Server Success] Start engine");
1947 /* 5. recorder start */
1948 ret = vcd_recorder_start();
1950 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to start recorder : result(%d)", ret);
1951 vcd_engine_recognize_cancel();
1952 /* Send error cb to manager */
1953 int pid = vcd_client_widget_get_foreground_pid();
1955 vcdc_send_error_to_manager(vcd_client_manager_get_pid(), VCD_ERROR_OPERATION_FAILED, "voice_framework.error.vcfw.send_rc_fail");
1960 vcd_config_set_service_state(VCD_STATE_RECORDING);
1961 vcdc_send_service_state(VCD_STATE_RECORDING);
1963 SLOG(LOG_ERROR, TAG_VCD, "[Server Success] Start recognition(%d)", stop_by_silence);
1965 return VCD_ERROR_NONE;
1968 static Eina_Bool __vcd_request_show_tooltip(void *data)
1970 int pid = vcd_client_widget_get_foreground_pid();
1972 SLOG(LOG_ERROR, TAG_VCD, "[Server] Request tooltip show and widget command, show(%d)", (bool)data);
1973 vcdc_send_show_tooltip(pid, (bool)data);
1979 int vcd_server_mgr_start(vcd_recognition_mode_e recognition_mode, bool exclusive_cmd, bool start_by_client)
1981 /* 1. check current state */
1982 vcd_state_e state = vcd_config_get_service_state();
1984 if (VCD_STATE_READY != state && VCD_STATE_SYNTHESIZING != state) {
1985 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Current state is not ready and not synthesizine, state(%d)", state);
1986 return VCD_ERROR_INVALID_STATE;
1988 if (-1 == vcd_client_manager_get_pid()) {
1989 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Manager is NOT available.");
1990 return VCD_ERROR_OPERATION_FAILED;
1992 __reset_waiting_for_widget_recording();
1994 SLOG(LOG_ERROR, TAG_VCD, "[Server] set recognition mode = %d", recognition_mode);
1995 vcd_client_set_recognition_mode(recognition_mode);
1997 if (false == exclusive_cmd) {
1998 vcd_client_update_foreground_pid();
1999 /* Notify show tooltip */
2000 if (1 == vcd_config_get_command_type_enabled(VC_COMMAND_TYPE_WIDGET)) {
2001 int pid = vcd_client_widget_get_foreground_pid();
2003 SLOG(LOG_ERROR, TAG_VCD, "[Server] Request tooltip show and widget command");
2004 ecore_timer_add(0, __vcd_request_show_tooltip, (void*)true);
2006 __set_waiting_for_widget_recording(pid);
2007 return VCD_ERROR_NONE;
2011 vcd_client_manager_set_exclusive(exclusive_cmd);
2015 if (true == start_by_client) {
2016 /* Get foreground pid */
2017 if (0 != vcd_config_get_foreground(&fg_pid)) {
2018 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to get foreground");
2021 /* Set client exclusive option */
2022 if (0 != vcd_client_set_exclusive_command(fg_pid)) {
2023 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to set exclusive command");
2027 SLOG(LOG_ERROR, TAG_VCD, "[Server] start internal recognition");
2029 int ret = __start_internal_recognition();
2031 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to start recognition : %d", ret);
2035 if (true == start_by_client) {
2036 vcd_client_unset_exclusive_command(fg_pid);
2039 SLOG(LOG_ERROR, TAG_VCD, "[Server Success] start internal recognition");
2040 return VCD_ERROR_NONE;
2043 int vcd_server_mgr_stop()
2045 /* 1. Check current state is recording */
2046 if (VCD_STATE_RECORDING != vcd_config_get_service_state()) {
2047 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Current state is not recording");
2048 return VCD_ERROR_INVALID_STATE;
2050 if (-1 == vcd_client_manager_get_pid()) {
2051 SLOG(LOG_INFO, TAG_VCD, "[Server] Manager is NOT available.");
2052 return VCD_ERROR_OPERATION_FAILED;
2054 SLOG(LOG_ERROR, TAG_VCD, "[Server] stop internal recognition");
2057 /* 2. Stop recorder */
2058 vcd_recorder_stop();
2061 /* 3. Stop engine recognition */
2062 int ret = vcd_engine_recognize_stop();
2064 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to stop recognition : %d", ret);
2067 /* 4. Set original mode */
2068 vcd_config_set_service_state(VCD_STATE_PROCESSING);
2069 vcdc_send_service_state(VCD_STATE_PROCESSING);
2071 SLOG(LOG_ERROR, TAG_VCD, "[Server Success] stop internal recognition");
2072 return VCD_ERROR_NONE;
2075 int vcd_server_mgr_cancel()
2077 if (-1 == vcd_client_manager_get_pid()) {
2078 SLOG(LOG_ERROR, TAG_VCD, "[Server] Manager is NOT available.");
2079 return VCD_ERROR_OPERATION_FAILED;
2082 if (g_restart_timer != NULL) {
2083 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Delete restart engine timer");
2084 ecore_timer_del(g_restart_timer);
2085 g_restart_timer = NULL;
2088 /* 1. Check current state */
2089 vcd_state_e state = vcd_config_get_service_state();
2090 if (VCD_STATE_READY == state) {
2091 SLOG(LOG_INFO, TAG_VCD, "[Server] Current state is READY");
2092 vcd_recorder_stop();
2094 if (false == vcd_client_manager_get_exclusive()) {
2095 if (1 == vcd_config_get_command_type_enabled(VC_COMMAND_TYPE_WIDGET)) {
2096 int pid = vcd_client_widget_get_foreground_pid();
2098 SLOG(LOG_INFO, TAG_VCD, "[Server] Request tooltip hide");
2099 ecore_timer_add(0, __vcd_request_show_tooltip, (void*)false);
2104 vcdc_send_service_state(VCD_STATE_READY);
2105 return VCD_ERROR_NONE;
2107 SLOG(LOG_ERROR, TAG_VCD, "[Server] cancel internal recognition");
2110 /* 2. Stop recorder */
2111 vcd_recorder_stop();
2114 /* 3. Cancel engine */
2115 int ret = vcd_engine_recognize_cancel();
2117 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Fail to cancel : %d", ret);
2120 if (false == vcd_client_manager_get_exclusive()) {
2121 if (1 == vcd_config_get_command_type_enabled(VC_COMMAND_TYPE_WIDGET)) {
2122 int pid = vcd_client_widget_get_foreground_pid();
2124 SLOG(LOG_INFO, TAG_VCD, "[Server] Request tooltip hide");
2125 ecore_timer_add(0, __vcd_request_show_tooltip, (void*)false);
2129 vcd_client_manager_set_exclusive(false);
2133 vcd_config_set_service_state(VCD_STATE_READY);
2134 vcdc_send_service_state(VCD_STATE_READY);
2136 SLOG(LOG_ERROR, TAG_VCD, "[Server Success] cancel internal recognition");
2137 return VCD_ERROR_NONE;
2141 int vcd_server_mgr_result_select()
2143 __vcd_send_selected_result(NULL);
2145 return VCD_ERROR_NONE;
2148 int vcd_server_mgr_set_domain(int pid, const char* domain)
2150 /* check if pid is valid */
2151 if (false == vcd_client_manager_is_valid(pid)) {
2152 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] The manager pid(%d) is NOT valid", pid);
2153 return VCD_ERROR_INVALID_PARAMETER;
2156 vcd_state_e state = vcd_config_get_service_state();
2157 if (VCD_STATE_READY != state) {
2158 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Current state is not ready");
2159 return VCD_ERROR_INVALID_STATE;
2162 /* Set domain to engine */
2163 int ret = vcd_engine_set_domain(pid, domain);
2165 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to set domain : %d", ret);
2167 SLOG(LOG_INFO, TAG_VCD, "[Server SUCCESS] Set domain");
2173 int vcd_server_mgr_set_private_data(int pid, const char* key, const char* data)
2175 /* check if pid is valid */
2176 if (false == vcd_client_manager_is_valid(pid)) {
2177 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] The manager pid(%d) is NOT valid", pid);
2178 return VCD_ERROR_INVALID_PARAMETER;
2181 vcd_state_e state = vcd_config_get_service_state();
2182 if (VCD_STATE_READY != state) {
2183 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Current state is not ready");
2184 return VCD_ERROR_INVALID_STATE;
2187 /* Set private data to engine */
2188 int ret = vcd_engine_set_private_data(pid, key, data);
2190 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to set private data : %d", ret);
2192 SLOG(LOG_INFO, TAG_VCD, "[Server SUCCESS] Set private data");
2198 int vcd_server_mgr_get_private_data(int pid, const char* key, char** data)
2200 /* check if pid is valid */
2201 if (false == vcd_client_manager_is_valid(pid)) {
2202 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] The manager pid(%d) is NOT valid", pid);
2203 return VCD_ERROR_INVALID_PARAMETER;
2205 vcd_state_e state = vcd_config_get_service_state();
2206 if (VCD_STATE_READY != state) {
2207 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Current state is not ready");
2208 return VCD_ERROR_INVALID_STATE;
2211 /* Get private data to engine */
2212 int ret = vcd_engine_get_private_data(pid, key, data);
2214 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to get private data : %d", ret);
2216 SLOG(LOG_INFO, TAG_VCD, "[Server SUCCESS] Set private data");
2222 int vcd_server_mgr_send_specific_engine_request(int pid, const char* engine_app_id, const char* event, const char* request)
2224 /* check if pid is valid */
2225 if (false == vcd_client_manager_is_valid(pid)) {
2226 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] The manager pid(%d) is NOT valid", pid);
2227 return VCD_ERROR_INVALID_PARAMETER;
2229 vcd_state_e state = vcd_config_get_service_state();
2230 if (VCD_STATE_READY != state && VCD_STATE_SYNTHESIZING != state) {
2231 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Current state is not ready and not synthesizing, state(%d)", state);
2232 return VCD_ERROR_INVALID_STATE;
2235 /* Get private data to engine */
2236 int ret = vcd_engine_send_specific_engine_request(engine_app_id, event, request);
2238 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to set specific engine request : %d", ret);
2240 SLOG(LOG_INFO, TAG_VCD, "[Server SUCCESS] Set specific engine request ");
2246 int vcd_server_mgr_do_action(int pid, int type, const char* action)
2250 /* check if pid is valid */
2251 if (false == vcd_client_manager_is_valid(pid)) {
2252 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] The manager pid(%d) is NOT valid", pid);
2253 return VCD_ERROR_INVALID_PARAMETER;
2256 vcd_state_e state = vcd_config_get_service_state();
2257 if (VCD_STATE_READY != state && VCD_STATE_SYNTHESIZING != state) {
2258 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Current state is not ready and not synthesizing, state(%d)", state);
2259 return VCD_ERROR_INVALID_STATE;
2262 /* Request do action to engine */
2263 if (VCD_SEND_EVENT_TYPE_TEXT == type)
2264 ret = vcd_engine_process_text(pid, action);
2265 else if (VCD_SEND_EVENT_TYPE_LIST_EVENT == type)
2266 ret = vcd_engine_process_list_event(pid, action);
2267 else if (VCD_SEND_EVENT_TYPE_HAPTIC_EVENT == type)
2268 ret = vcd_engine_process_haptic_event(pid, action);
2271 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to process do action : %d", ret);
2273 vcd_config_set_service_state(VCD_STATE_PROCESSING);
2274 vcdc_send_service_state(VCD_STATE_PROCESSING);
2275 SLOG(LOG_INFO, TAG_VCD, "[Server SUCCESS] Process do action");
2281 int vcd_server_mgr_set_disabled_command_type(int pid, int disabled_cmd_type)
2285 /* check if pid is valid */
2286 if (false == vcd_client_manager_is_valid(pid)) {
2287 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] The manager pid(%d) is NOT valid", pid);
2288 return VCD_ERROR_INVALID_PARAMETER;
2291 vcd_state_e state = vcd_config_get_service_state();
2292 if (VCD_STATE_READY != state) {
2293 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Current state is not ready");
2294 return VCD_ERROR_INVALID_STATE;
2297 ret = vcd_config_set_disabled_command_type(disabled_cmd_type);
2299 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to set command type");
2301 SLOG(LOG_ERROR, TAG_VCD, "[Server] Set command type(%d)", disabled_cmd_type);
2308 /* for TTS feedback */
2309 int vcd_server_mgr_start_feedback(void)
2311 /* check current state */
2312 /* not Recording??? */
2314 if (-1 == vcd_client_manager_get_pid()) {
2315 SLOG(LOG_ERROR, TAG_VCD, "[Server] Manager is NOT available");
2316 return VCD_ERROR_OPERATION_FAILED;
2319 SLOG(LOG_INFO, TAG_VCD, "[Server] start TTS feedback");
2321 /* check there is TTS buffer to be spoken */
2323 return VCD_ERROR_NONE;
2326 int vcd_server_mgr_stop_feedback(void)
2328 /* check current state */
2329 /* not Recording??? */
2331 if (-1 == vcd_client_manager_get_pid()) {
2332 SLOG(LOG_ERROR, TAG_VCD, "[Server] Manager is NOT available");
2333 return VCD_ERROR_OPERATION_FAILED;
2336 SLOG(LOG_INFO, TAG_VCD, "[Server] stop TTS feedback");
2338 return VCD_ERROR_NONE;
2341 int vcd_server_mgr_send_audio_streaming(int pid, int event, const char* buffer, unsigned int len)
2343 SLOG(LOG_INFO, TAG_VCD, "[DEBUG] Send Audio Streaming from Multi-assistant. event(%d), buffer(%p), len(%d)", event, &buffer, len);
2346 if (VCD_AUDIO_STREAMING_EVENT_START == event) {
2347 ret = vcd_recorder_start_streaming();
2349 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to start streaming, ret(%d)", ret);
2354 ret = vcd_recorder_send_streaming((const void*)buffer, (const unsigned int)len);
2356 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to start streaming, ret(%d)", ret);
2360 if (VCD_AUDIO_STREAMING_EVENT_FINISH == event) {
2361 ret = vcd_recorder_stop_streaming();
2363 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to stop streaming, ret(%d)", ret);
2368 return VCD_ERROR_NONE;
2371 int vcd_server_mgr_change_system_volume(int pid, vcd_system_volume_event_e system_volume_event)
2373 SLOG(LOG_INFO, TAG_VCD, "[DEBUG] change system volume, system volume event(%d)", system_volume_event);
2376 if (VCD_SYSTEM_VOLUME_EVENT_CHANGE == system_volume_event) {
2377 ret = vcd_recorder_change_system_volume();
2379 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to change system volume, ret(%d)", ret);
2382 } else if (VCD_SYSTEM_VOLUME_EVENT_RECOVER == system_volume_event) {
2383 ret = vcd_recorder_recover_system_volume();
2385 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to recover system volume, ret(%d)", ret);
2395 * VC Server Functions for Client
2397 int vcd_server_initialize(int pid)
2399 if (false == vcd_engine_is_available_engine()) {
2400 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] No Engine");
2401 return VCD_ERROR_ENGINE_NOT_FOUND;
2404 /* check if pid is valid */
2405 if (true == vcd_client_is_available(pid)) {
2406 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] The pid is already exist");
2407 return VCD_ERROR_NONE;
2410 /* Add client information to client manager */
2411 if (0 != vcd_client_add(pid)) {
2412 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to add client info");
2413 return VCD_ERROR_OPERATION_FAILED;
2416 SLOG(LOG_INFO, TAG_VCD, "[Server Success] Client Initialize : pid(%d)", pid);
2418 return VCD_ERROR_NONE;
2421 int vcd_server_finalize(int pid)
2423 /* check if pid is valid */
2424 if (false == vcd_client_is_available(pid)) {
2425 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] pid is NOT valid ");
2426 return VCD_ERROR_INVALID_PARAMETER;
2429 /* Remove client information */
2430 if (0 != vcd_client_delete(pid)) {
2431 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Fail to delete client");
2434 if (0 == vcd_client_get_ref_count()) {
2435 SLOG(LOG_INFO, TAG_VCD, "[Server] Connected client list is empty");
2436 ecore_timer_add(0, __finalize_quit_ecore_loop, NULL);
2439 SLOG(LOG_INFO, TAG_VCD, "[Server Success] Client Finalize : pid(%d)", pid);
2441 return VCD_ERROR_NONE;
2444 int vcd_server_set_command(int pid, vc_cmd_type_e cmd_type)
2446 /* check if pid is valid */
2447 if (false == vcd_client_is_available(pid)) {
2448 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] pid is NOT valid ");
2449 return VCD_ERROR_INVALID_PARAMETER;
2452 if (0 != vcd_client_set_command_type(pid, cmd_type)) {
2453 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to set command type : pid(%d), cmd_type(%d)", pid, cmd_type);
2454 return VCD_ERROR_OPERATION_FAILED;
2457 return VCD_ERROR_NONE;
2460 int vcd_server_unset_command(int pid, vc_cmd_type_e cmd_type)
2462 /* check if pid is valid */
2463 if (false == vcd_client_is_available(pid)) {
2464 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] pid is NOT valid ");
2465 return VCD_ERROR_INVALID_PARAMETER;
2468 if (0 != vcd_client_unset_command_type(pid, cmd_type)) {
2469 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to unset command type : pid(%d), cmd_type(%d)", pid, cmd_type);
2470 return VCD_ERROR_OPERATION_FAILED;
2473 return VCD_ERROR_NONE;
2476 int vcd_server_set_foreground(int pid, bool value)
2478 /* check if pid is valid */
2479 if (false == vcd_client_is_available(pid) && false == vcd_client_widget_is_available(pid)) {
2480 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] pid is NOT valid ");
2481 return VCD_ERROR_INVALID_PARAMETER;
2484 if (0 != vcd_config_set_foreground(pid, value)) {
2485 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to set foreground : pid(%d), value(%d)", pid, value);
2486 return VCD_ERROR_OPERATION_FAILED;
2489 return VCD_ERROR_NONE;
2492 static int __vcd_server_launch_manager_app()
2495 bool running = false;
2498 ret = vcd_client_manager_get_appid(&appid);
2499 if (0 != ret || NULL == appid) {
2500 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to get manager appid");
2501 return VCD_ERROR_OPERATION_FAILED;
2503 ret = app_manager_is_running(appid, &running);
2505 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to check running with appid(%s)", appid);
2508 return VCD_ERROR_OPERATION_FAILED;
2510 if (false == running) {
2511 int tmp_ret = __vcd_is_package_installed(appid);
2512 if (false == tmp_ret) {
2513 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] manager app is not installed, appid(%s)", appid);
2515 ret = __vcd_activate_app_by_appcontrol(appid);
2517 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to activate app");
2522 SLOG(LOG_ERROR, TAG_VCD, "Launch vc manager app: appid(%s)", appid);
2525 ret = __vcd_resume_app(appid);
2527 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to resume app");
2532 SLOG(LOG_ERROR, TAG_VCD, "Resume vc manager app: appid(%s)", appid);
2538 return VCD_ERROR_NONE;
2541 int vcd_server_set_server_dialog(int pid, const char* app_id, const char* credential)
2543 /* check if pid is valid */
2544 if (false == vcd_client_is_available(pid)) {
2545 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] pid is NOT valid ");
2546 return VCD_ERROR_INVALID_PARAMETER;
2549 int ret = vcd_engine_set_server_dialog(app_id, credential);
2551 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to set server dialog, pid(%d), app_id(%s), ret(%d)", pid, app_id, ret);
2552 vcd_client_set_server_dialog(pid, false);
2555 SLOG(LOG_ERROR, TAG_VCD, "[Success] Set server dialog, pid(%d), app_id(%s)", pid, app_id);
2557 if (0 != strncmp(credential, "#NULL", strlen(credential))) {
2558 ret = vcd_client_set_server_dialog(pid, true);
2560 SLOG(LOG_INFO, TAG_VCD, "[Server] Set to true for server dialog, app_id(%s)", app_id);
2562 ret = vcd_client_set_server_dialog(pid, false);
2564 SLOG(LOG_INFO, TAG_VCD, "[Server] Set to false for server dialog, app_id(%s)", app_id);
2567 return VCD_ERROR_NONE;
2570 int vcd_server_dialog(int pid, const char* disp_text, const char* utt_text, int continuous)
2572 /* check if pid is valid */
2573 if (false == vcd_client_is_available(pid) && false == vcd_client_widget_is_available(pid)) {
2574 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] pid is NOT valid ");
2575 return VCD_ERROR_INVALID_PARAMETER;
2578 bool is_server_dialog = false;
2579 int ret = vcd_client_get_server_dialog(pid, &is_server_dialog);
2581 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to get server dialog, pid(%d), ret(%d)", pid, ret);
2584 if (true == is_server_dialog) {
2585 /* ++ Request tts event to engine */
2587 /* -- Request tts event to engine */
2589 ret = __vcd_server_launch_manager_app();
2591 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);
2595 ret = vcdc_send_dialog(vcd_client_manager_get_pid(), pid, disp_text, utt_text, continuous);
2597 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);
2601 return VCD_ERROR_NONE;
2604 int vcd_server_is_system_command_valid(int pid, bool* is_sys_cmd_valid)
2606 /* check if pid is valid */
2607 if (false == vcd_client_is_available(pid) && false == vcd_client_widget_is_available(pid)) {
2608 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] pid is NOT valid ");
2609 return VCD_ERROR_INVALID_PARAMETER;
2612 /* check if system command is valid */
2613 if (true == vcd_client_manager_is_system_command_valid(vcd_client_manager_get_pid()))
2614 *is_sys_cmd_valid = true;
2616 *is_sys_cmd_valid = false;
2618 return VCD_ERROR_NONE;
2621 static void __start_tts_request_thread(void* data, Ecore_Thread* thread)
2623 SLOG(LOG_INFO, TAG_VCD, "[SUCCESS] Start tts request thread");
2624 vc_tts_text_data_s* tts_text_data = NULL;
2630 /* Get tts text data */
2631 ret = vcd_data_get_first_tts_text_data(&tts_text_data);
2632 if (0 != ret || NULL == tts_text_data) {
2634 if (0 >= vcd_data_get_tts_text_data_size()) {
2635 SLOG(LOG_INFO, TAG_VCD, "[DEBUG] No tts text data");
2638 SLOG(LOG_INFO, TAG_VCD, "[INFO] tts text data is just incoming");
2643 vcd_state_e state = vcd_config_get_service_state();
2644 if (VCD_STATE_READY != state) {
2645 if (0 == cnt++ % 10)
2646 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Waiting to request TTS, state(%d)", state);
2653 /* Set service state to synthesizing */
2654 vcd_config_set_service_state(VCD_STATE_SYNTHESIZING);
2656 /* Set current uid */
2657 g_current_tts_uid = tts_text_data->uid;
2659 /* Request tts to engine */
2660 ret = vcd_engine_request_tts(tts_text_data->pid, tts_text_data->utt_id, tts_text_data->text, tts_text_data->language);
2662 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to request tts : %d", ret);
2664 SLOG(LOG_INFO, TAG_VCD, "[Server SUCCESS] request tts, uid(%u) pid(%d), text(%s), language(%s), utt_id(%d)",
2665 tts_text_data->uid, tts_text_data->pid, tts_text_data->text, tts_text_data->language, tts_text_data->utt_id);
2667 /* clear tts text data after use */
2668 vcd_data_clear_tts_text_data(&tts_text_data);
2672 static void __end_tts_request_thread(void* data, Ecore_Thread* thread)
2674 SLOG(LOG_INFO, TAG_VCD, "[SUCCESS] End tts request thread");
2675 g_tts_thread = NULL;
2678 int vcd_server_request_tts(int pid, const char* text, const char* language, int to_vcm, int* utt_id)
2680 /* check if pid is valid */
2681 if (false == vcd_client_is_available(pid)) {
2682 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] pid is NOT valid ");
2683 return VCD_ERROR_INVALID_PARAMETER;
2686 vcd_state_e state = vcd_config_get_service_state();
2687 if (VCD_STATE_READY != state && VCD_STATE_SYNTHESIZING != state) {
2688 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Current state is not ready, state(%d)", state);
2689 return VCD_ERROR_INVALID_STATE;
2692 unsigned int tts_uid = VC_INVALID_TTS_UID;
2693 g_current_utt_id = (g_current_utt_id + 1) % 1000;
2694 *utt_id = g_current_utt_id;
2696 tts_uid = (unsigned int)pid * 1000u + (unsigned int)g_current_utt_id;
2698 tts_uid = (unsigned int)vcd_client_manager_get_pid() * 1000u + (unsigned int)g_current_utt_id;
2700 SLOG(LOG_INFO, TAG_VCD, "[Server INFO] pid(%d), text(%s), language(%s), to_vcm(%d), ", pid, text, language, to_vcm);
2701 SLOG(LOG_INFO, TAG_VCD, "[Server INFO] current_uid(%u), current_utt_id(%d)", tts_uid, g_current_utt_id);
2703 vc_tts_text_data_s* tts_text_data;
2704 tts_text_data = (vc_tts_text_data_s*)calloc(1, sizeof(vc_tts_text_data_s));
2705 if (!tts_text_data) {
2706 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to callocate memory ");
2707 return VCD_ERROR_OUT_OF_MEMORY;
2709 tts_text_data->uid = tts_uid;
2710 tts_text_data->pid = pid;
2711 tts_text_data->utt_id = g_current_utt_id;
2712 tts_text_data->text = strdup(text);
2713 tts_text_data->language = strdup(language);
2715 int ret = vcd_data_add_tts_text_data(tts_text_data);
2717 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to add tts text data : %d", ret);
2720 bool is_canceled = ecore_thread_check(g_tts_thread);
2721 if (NULL == g_tts_thread || TRUE == is_canceled) {
2722 SLOG(LOG_INFO, TAG_VCD, "[Server INFO] ecore thread run : start_tts_request_thread ");
2723 g_tts_thread = ecore_thread_run(__start_tts_request_thread, __end_tts_request_thread, NULL, NULL);
2726 return VCD_ERROR_NONE;
2729 int vcd_server_cancel_tts(int pid, int utt_id)
2731 /* check if pid is valid */
2732 if (false == vcd_client_is_available(pid)) {
2733 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] pid is NOT valid ");
2734 return VCD_ERROR_INVALID_PARAMETER;
2737 vcd_state_e state = vcd_config_get_service_state();
2738 if (VCD_STATE_READY != state && VCD_STATE_SYNTHESIZING != state) {
2739 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Current state is not ready, state(%d)", state);
2740 return VCD_ERROR_INVALID_STATE;
2743 vc_tts_text_data_s* tts_text_data = NULL;
2745 unsigned int tts_uid = (unsigned int)pid * 1000u + (unsigned int)utt_id;
2746 int ret = vcd_data_get_tts_text_data(tts_uid, &tts_text_data);
2748 SLOG(LOG_WARN, TAG_VCD, "[Server WARN] No data in vcd tts text queue");
2750 if (tts_text_data) {
2751 SLOG(LOG_INFO, TAG_VCD, "[Server] Clear tts text data, pid(%d), utt_id(%d), text(%s)", pid, utt_id, tts_text_data->text);
2752 vcd_data_clear_tts_text_data(&tts_text_data);
2753 tts_text_data = NULL;
2755 SLOG(LOG_INFO, TAG_VCD, "[Server] Clear tts text data, pid(%d), utt_id(%d), text(nullptr)", pid, utt_id);
2759 /* Request tts to engine */
2760 ret = vcd_engine_cancel_tts(pid, utt_id);
2762 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to cancel tts : %d", ret);
2764 SLOG(LOG_INFO, TAG_VCD, "[Server SUCCESS] request tts, pid(%d), utt_id(%d)", pid, utt_id);
2767 /* Set service state */
2768 vcd_config_set_service_state(VCD_STATE_READY);
2770 return VCD_ERROR_NONE;
2773 int vcd_server_get_tts_audio_format(int pid, int* rate, int* channel, int* audio_type)
2775 /* check if pid is valid */
2776 if (false == vcd_client_is_available(pid)) {
2777 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] pid is NOT valid ");
2778 return VCD_ERROR_INVALID_PARAMETER;
2781 vcd_state_e state = vcd_config_get_service_state();
2782 if (VCD_STATE_READY != state && VCD_STATE_SYNTHESIZING != state) {
2783 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Current state is not ready and not synthesizing, state(%d)", state);
2784 return VCD_ERROR_INVALID_STATE;
2787 /* Request tts to engine */
2788 int ret = vcd_engine_get_tts_audio_format(rate, channel, audio_type);
2790 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to get tts audio format : %d", ret);
2792 SLOG(LOG_INFO, TAG_VCD, "[Server SUCCESS] get tts audio format, pid(%d), rate(%d), channel(%d), audio_type(%d)", pid, *rate, *channel, *audio_type);
2799 int vcd_server_set_exclusive_command(int pid, bool value)
2801 /* check if pid is valid */
2802 if (false == vcd_client_is_available(pid)) {
2803 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] pid is NOT valid ");
2804 return VCD_ERROR_INVALID_PARAMETER;
2807 if (true == value) {
2808 if (0 != vcd_client_set_exclusive_command(pid)) {
2809 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to set exclusive command : pid(%d)", pid);
2810 return VCD_ERROR_OPERATION_FAILED;
2813 if (0 != vcd_client_unset_exclusive_command(pid)) {
2814 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to unset exclusive command : pid(%d)", pid);
2815 return VCD_ERROR_OPERATION_FAILED;
2819 return VCD_ERROR_NONE;
2822 int vcd_server_request_start(int pid, bool stop_by_silence)
2824 /* check if pid is valid */
2825 if (false == vcd_client_is_available(pid)) {
2826 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] pid(%d) is NOT foreground client", pid);
2827 return VCD_ERROR_INVALID_PARAMETER;
2831 /* Check current state */
2832 vcd_state_e state = vcd_config_get_service_state();
2834 /* Service state should be ready */
2835 if (VCD_STATE_READY != state) {
2836 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Current state is not Ready : pid(%d)", pid);
2837 return VCD_ERROR_INVALID_STATE;
2840 if (-1 != vcd_client_manager_get_pid()) {
2841 /* Check current pid is valid */
2842 if (false == vcd_client_manager_check_demandable_client(pid)) {
2843 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Current client is NOT available : pid(%d)", pid);
2844 return VCD_ERROR_INVALID_PARAMETER;
2848 ret = vcd_server_mgr_start(stop_by_silence, false);
2850 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Fail to start recognition");
2851 return VCD_ERROR_INVALID_PARAMETER;
2854 return VCD_ERROR_NONE;
2857 int vcd_server_request_stop(int pid)
2860 /* Check current state */
2861 vcd_state_e state = vcd_config_get_service_state();
2863 /* Service state should be ready */
2864 if (VCD_STATE_RECORDING != state) {
2865 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Current state is not Recording : pid(%d)", pid);
2866 return VCD_ERROR_INVALID_STATE;
2869 if (-1 != vcd_client_manager_get_pid()) {
2870 /* Check current pid is valid */
2871 if (false == vcd_client_manager_check_demandable_client(pid)) {
2872 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Current client is NOT available : pid(%d)", pid);
2873 return VCD_ERROR_INVALID_PARAMETER;
2877 ret = vcd_server_mgr_stop();
2879 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Fail to start recognition");
2880 return VCD_ERROR_OPERATION_FAILED;
2883 return VCD_ERROR_NONE;
2886 int vcd_server_request_cancel(int pid)
2889 /* Check current state */
2890 vcd_state_e state = vcd_config_get_service_state();
2892 /* Service state should be recording or processing */
2893 if (VCD_STATE_RECORDING != state && VCD_STATE_PROCESSING != state) {
2894 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Current state is not Recording or Processing : pid(%d)", pid);
2895 return VCD_ERROR_INVALID_STATE;
2898 if (-1 != vcd_client_manager_get_pid()) {
2899 /* Check current pid is valid */
2900 if (false == vcd_client_manager_check_demandable_client(pid)) {
2901 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Current client is NOT available : pid(%d)", pid);
2902 return VCD_ERROR_INVALID_PARAMETER;
2906 ret = vcd_server_mgr_cancel();
2908 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Fail to start recognition");
2909 return VCD_ERROR_OPERATION_FAILED;
2912 return VCD_ERROR_NONE;
2917 * VC Server Functions for Widget lib
2919 int vcd_server_widget_initialize(int pid)
2921 if (false == vcd_engine_is_available_engine()) {
2922 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] No Engine");
2923 return VCD_ERROR_ENGINE_NOT_FOUND;
2926 /* check if pid is valid */
2927 if (true == vcd_client_widget_is_available(pid)) {
2928 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] The pid is already exist");
2929 return VCD_ERROR_NONE;
2932 /* Add client information to client manager */
2933 if (0 != vcd_client_widget_add(pid)) {
2934 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to add client info");
2935 return VCD_ERROR_OPERATION_FAILED;
2938 SLOG(LOG_INFO, TAG_VCD, "[Server Success] Initialize widget : pid(%d)", pid);
2940 return VCD_ERROR_NONE;
2943 static void __vcd_server_widget_start_recording(void *data)
2945 SLOG(LOG_ERROR, TAG_VCD, "[Server INFO] start recording");
2947 if (0 != __start_internal_recognition()) {
2948 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to start recognition");
2952 int vcd_server_widget_finalize(int pid)
2954 /* check if pid is valid */
2955 if (false == vcd_client_widget_is_available(pid)) {
2956 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] pid is NOT valid ");
2957 if (0 == vcd_client_get_ref_count()) {
2958 SLOG(LOG_ERROR, TAG_VCD, "[Server] connected client list is empty, vc-service will be terminated");
2959 ecore_timer_add(0, __finalize_quit_ecore_loop, NULL);
2960 return VCD_ERROR_NONE;
2962 return VCD_ERROR_INVALID_PARAMETER;
2965 /* Remove client information */
2966 if (0 != vcd_client_widget_delete(pid)) {
2967 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Fail to delete client");
2970 if (0 == vcd_client_get_ref_count()) {
2971 SLOG(LOG_ERROR, TAG_VCD, "[Server] connected client list is empty, vc-service will be terminated");
2972 ecore_timer_add(0, __finalize_quit_ecore_loop, NULL);
2973 return VCD_ERROR_NONE;
2976 bool is_waiting = false;
2977 if (0 != vcd_client_widget_get_waiting_for_recording(pid, &is_waiting)) {
2978 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Fail to get waiting to recording");
2981 if (true == is_waiting) {
2982 SLOG(LOG_ERROR, TAG_VCD, "[Server INFO] invoke to start recording");
2983 ecore_main_loop_thread_safe_call_async(__vcd_server_widget_start_recording, NULL);
2985 return VCD_ERROR_NONE;
2988 int vcd_server_widget_start_recording(int pid, bool widget_command)
2990 /* check if pid is valid */
2991 if (false == vcd_client_widget_is_available(pid)) {
2992 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] pid is NOT valid ");
2993 return VCD_ERROR_INVALID_PARAMETER;
2997 if (0 != vcd_client_widget_get_waiting_for_recording(pid, &waiting) || false == waiting) {
2998 SLOG(LOG_ERROR, TAG_VCD, "[Server] Server is not waiting for recording, pid(%d), waiting(%d)", pid, waiting);
2999 return VCD_ERROR_NONE;
3002 if (true == widget_command) {
3003 vcd_client_widget_set_command(pid);
3004 SLOG(LOG_INFO, TAG_VCD, "[Server] widget command is available");
3006 vcd_client_widget_unset_command(pid);
3007 SLOG(LOG_WARN, TAG_VCD, "[Server] widget command is NOT available");
3010 SLOG(LOG_ERROR, TAG_VCD, "[Server] start internal recognition : %d", widget_command);
3011 int ret = __start_internal_recognition();
3013 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to start recognition : %d", ret);
3014 ecore_timer_add(0, __vcd_request_show_tooltip, (void*)false);
3017 return VCD_ERROR_NONE;
3020 int vcd_server_widget_start(int pid, bool stop_by_silence)
3022 /* check if pid is valid */
3023 int fore_pid = vcd_client_widget_get_foreground_pid();
3024 if (pid != fore_pid) {
3025 SLOG(LOG_ERROR, TAG_VCD, "[Server] pid is NOT foreground");
3026 return VCD_ERROR_INVALID_PARAMETER;
3029 /* Check current state */
3030 vcd_state_e state = vcd_config_get_service_state();
3032 /* Service state should be ready */
3033 if (VCD_STATE_READY != state) {
3034 SLOG(LOG_INFO, TAG_VCD, "[Server] Current state is not Ready : pid(%d)", pid);
3035 return VCD_ERROR_INVALID_STATE;
3038 vcd_client_set_slience_detection(stop_by_silence);
3040 /* Notify show tooltip */
3041 ecore_timer_add(0, __vcd_request_show_tooltip, (void*)true);
3043 return VCD_ERROR_NONE;
3046 int vcd_server_widget_stop(int pid)
3048 /* check if pid is valid */
3049 int fore_pid = vcd_client_widget_get_foreground_pid();
3050 if (pid != fore_pid) {
3051 SLOG(LOG_ERROR, TAG_VCD, "[Server] pid is NOT foreground");
3052 return VCD_ERROR_INVALID_PARAMETER;
3056 /* Check current state */
3057 vcd_state_e state = vcd_config_get_service_state();
3059 /* Service state should be recording */
3060 if (VCD_STATE_RECORDING != state) {
3061 SLOG(LOG_ERROR, TAG_VCD, "[Server] Current service state is not Recording : pid(%d)", pid);
3062 return VCD_ERROR_INVALID_STATE;
3065 ret = vcd_server_mgr_stop();
3067 SLOG(LOG_ERROR, TAG_VCD, "[Server] Fail to start recognition");
3068 return VCD_ERROR_OPERATION_FAILED;
3071 return VCD_ERROR_NONE;
3074 int vcd_server_widget_cancel(int pid)
3076 /* check if pid is valid */
3077 int fore_pid = vcd_client_widget_get_foreground_pid();
3078 if (pid != fore_pid) {
3079 SLOG(LOG_ERROR, TAG_VCD, "[Server] pid is NOT foreground");
3080 return VCD_ERROR_INVALID_PARAMETER;
3084 /* Check current state */
3085 vcd_state_e state = vcd_config_get_service_state();
3087 /* Service state should be recording or processing */
3088 if (VCD_STATE_RECORDING != state && VCD_STATE_PROCESSING != state) {
3089 SLOG(LOG_ERROR, TAG_VCD, "[Server] Current state is not Recording or Processing : pid(%d)", pid);
3090 return VCD_ERROR_INVALID_STATE;
3093 ret = vcd_server_mgr_cancel();
3095 SLOG(LOG_ERROR, TAG_VCD, "[Server] Fail to cancel recognition : %d", ret);
3099 return VCD_ERROR_NONE;
3102 int vcd_server_widget_enable_asr_result(int pid, bool enable)
3105 ret = vcd_client_widget_set_asr_result_enabled(pid, enable);
3107 SLOG(LOG_ERROR, TAG_VCD, "[Server] Fail to enable asr result : %d", ret);
3113 int vcd_server_set_language(const char* language)
3115 int ret = VCD_ERROR_NONE;
3117 ret = vcd_config_set_default_language(language);
3119 SLOG(LOG_ERROR, TAG_VCD, "[Server] Fail to set language : %d", ret);
3123 ret = vcd_engine_set_current_language(language);
3125 SLOG(LOG_ERROR, TAG_VCD, "[Server] Fail to set language : %d", ret);
3132 * For engine service
3134 int vcd_get_foreach_command(vce_cmd_h vce_command, vce_command_cb callback, void* user_data)
3136 SLOG(LOG_INFO, TAG_VCD, "[Server] Get foreach command");
3138 if (NULL == callback) {
3139 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] input parameter is NULL");
3140 return VCD_ERROR_INVALID_PARAMETER;
3144 ret = vcd_engine_agent_get_foreach_command(vce_command, callback, user_data);
3146 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to get foreach command : ret(%d)", ret);
3152 int vcd_get_command_count(vce_cmd_h vce_command, int* count)
3154 SLOG(LOG_INFO, TAG_VCD, "[Server] Get command count");
3157 ret = vcd_engine_agent_get_command_count(vce_command, count);
3159 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to get command count : ret(%d)", ret);
3165 int vcd_get_audio_type(char** audio_type)
3167 SLOG(LOG_INFO, TAG_VCD, "[Server] Get audio type");
3170 ret = vcd_engine_agent_get_audio_type(audio_type);
3172 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to get audio type : ret(%d)", ret);
3178 int vcd_set_private_data(const char* key, const char* data)
3180 vcd_state_e state = vcd_config_get_service_state();
3182 if (VCD_STATE_READY != state) {
3183 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Current state(%d) is NOT 'READY'", state);
3184 return VCD_ERROR_INVALID_STATE;
3187 int ret = vcd_engine_agent_set_private_data(key, data);
3189 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to set private data to the manager client : ret(%d)", ret);
3191 SLOG(LOG_INFO, TAG_VCD, "[Server] Set private data to the manager client, key(%s), data(%s)", key, data);
3197 int vcd_get_private_data(const char* key, char** data)
3199 vcd_state_e state = vcd_config_get_service_state();
3201 if (VCD_STATE_READY != state) {
3202 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Current state(%d) is NOT 'READY'", state);
3203 return VCD_ERROR_INVALID_STATE;
3206 int ret = vcd_engine_agent_get_private_data(key, data);
3208 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to get private data from the manager client : ret(%d)", ret);
3210 SLOG(LOG_INFO, TAG_VCD, "[Server] Get private data from the manager client, key(%s), data(%s)", key, *data);
3216 int vcd_start_recording()
3218 SLOG(LOG_INFO, TAG_VCD, "[Server] Start recording");
3221 ret = vcd_engine_agent_start_recording();
3223 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to start recording : ret(%d)", ret);
3229 int vcd_stop_recording()
3231 SLOG(LOG_INFO, TAG_VCD, "[Server] Stop recording");
3234 ret = vcd_engine_agent_stop_recording();
3236 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to stop recording : ret(%d)", ret);
3242 int vcd_send_update_status(vce_update_event_e update_event, const char* msg)
3244 SLOG(LOG_INFO, TAG_VCD, "[Server] update status, update event(%d), msg(%s)", update_event, msg);
3247 if (VCE_UPDATE_EVENT_START == update_event) {
3248 if (VCD_STATE_RECORDING == vcd_config_get_service_state() || VCD_STATE_PROCESSING == vcd_config_get_service_state()) {
3249 ret = vcd_server_mgr_cancel();
3251 SLOG(LOG_ERROR, TAG_VCD, "[Server Error] Fail to cancel, ret(%d)", ret);
3255 vcd_config_set_service_state(VCD_STATE_UPDATING);
3256 vcdc_send_service_state(VCD_STATE_UPDATING);
3258 } else if (VCE_UPDATE_EVENT_FINISH == update_event) {
3259 vcd_config_set_service_state(VCD_STATE_READY);
3260 vcdc_send_service_state(VCD_STATE_READY);
3262 } else if (VCE_UPDATE_EVENT_FAIL == update_event) {
3263 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Update event : Fail - msg(%s)", msg);
3266 return VCD_ERROR_NONE;
3269 int vcd_set_private_data_set_cb(vce_private_data_set_cb callback_func)
3271 SLOG(LOG_INFO, TAG_VCD, "[Server] Set private data set cb");
3274 ret = vcd_engine_agent_set_private_data_set_cb(callback_func);
3276 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to set private data set cb : ret(%d)", ret);
3282 int vcd_set_private_data_requested_cb(vce_private_data_requested_cb callback_func)
3284 SLOG(LOG_INFO, TAG_VCD, "[Server] Set private data requested cb");
3287 ret = vcd_engine_agent_set_private_data_requested_cb(callback_func);
3289 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to set private data requested cb : ret(%d)", ret);
3295 int vcd_set_nlu_base_info_requested_cb(vce_nlu_base_info_requested_cb callback_func)
3297 SLOG(LOG_INFO, TAG_VCD, "[Server] Set nlu base info requested cb");
3300 ret = vcd_engine_agent_set_nlu_base_info_requested_cb(callback_func);
3302 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to set nlu base info requested cb : ret(%d)", ret);
3308 int vcd_set_specific_engine_request_cb(vce_specific_engine_request_cb callback_func)
3310 SLOG(LOG_INFO, TAG_VCD, "[Server] Set specific engine request cb");
3312 ret = vcd_engine_agent_set_specific_engine_request_cb(callback_func);
3314 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to set specific engine request cb : ret(%d)", ret);
3320 int vcd_set_request_tts_cb(vce_request_tts_cb callback_func, void* user_data)
3322 SLOG(LOG_INFO, TAG_VCD, "[Server] Set request tts cb");
3324 ret = vcd_engine_agent_set_request_tts_cb(callback_func, user_data);
3326 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to set request tts cb : ret(%d)", ret);
3332 int vcd_set_cancel_tts_cb(vce_cancel_tts_cb callback_func, void* user_data)
3334 SLOG(LOG_INFO, TAG_VCD, "[Server] Set cancel tts cb");
3336 ret = vcd_engine_agent_set_cancel_tts_cb(callback_func, user_data);
3338 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to set cancel tts cb : ret(%d)", ret);
3344 int vcd_set_tts_audio_format_request_cb(vce_tts_audio_format_request_cb callback_func, void* user_data)
3346 SLOG(LOG_INFO, TAG_VCD, "[Server] Set tts audio format request cb");
3348 ret = vcd_engine_agent_set_get_tts_audio_format_cb(callback_func, user_data);
3350 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to set tts audio format request : ret(%d)", ret);