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)) {
346 vc_deactivated_app_s* temp_app = NULL;
347 iter = g_slist_nth(app_list, 0);
349 while (NULL != iter) {
350 temp_app = iter->data;
352 if (NULL != temp_app && NULL != temp_app->appid) {
354 bool running = false;
355 ret = app_manager_is_running(temp_app->appid, &running);
356 if (APP_MANAGER_ERROR_NONE != ret) {
357 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to check running with appid(%s)", temp_app->appid);
358 g_slist_free_full(iter, __vc_free_deactivated_app);
359 return VCD_ERROR_OPERATION_FAILED;
361 if (false == running) {
362 int tmp_ret = __vcd_is_package_installed(temp_app->appid);
363 if (false == tmp_ret) {
364 SLOG(LOG_WARN, TAG_VCD, "[WARNING] app is not installed, appid(%s)", temp_app->appid);
366 ret = __vcd_activate_app_by_appcontrol(temp_app->appid);
368 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to activate app");
369 g_slist_free_full(iter, __vc_free_deactivated_app);
372 SLOG(LOG_ERROR, TAG_VCD, "Launch app: appid(%s) result(%s)", temp_app->appid, result);
375 ret = __vcd_resume_app(temp_app->appid);
377 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to resume app");
378 g_slist_free_full(iter, __vc_free_deactivated_app);
381 SLOG(LOG_ERROR, TAG_VCD, "Resume app: appid(%s) result(%s)", temp_app->appid, result);
383 __vc_free_deactivated_app((void*)temp_app);
386 app_list = g_slist_remove_link(app_list, iter);
388 iter = g_slist_nth(app_list, 0);
393 return VCD_ERROR_NONE;
396 static Eina_Bool __vcd_send_selected_result(void *data)
398 GSList* pid_list = NULL;
399 const char* result = vcd_client_manager_get_result_text();
401 if (0 != vc_info_parser_get_result_pid_list(&pid_list, result)) {
402 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Fail to get pid list. No result");
404 if (0 < g_slist_length(pid_list)) {
406 vc_cmd_s* temp_cmd = NULL;
411 iter = g_slist_nth(pid_list, 0);
412 while (NULL != iter) {
413 temp_cmd = iter->data;
415 if (NULL != temp_cmd && (pre_pid != temp_cmd->pid || pre_type == VC_COMMAND_TYPE_WIDGET || temp_cmd->type == VC_COMMAND_TYPE_WIDGET)) {
416 /* Launch deactivated several apps that is matched with result */
417 ret = __vcd_launch_app(result);
419 SLOG(LOG_ERROR, TAG_VCD, "Fail to launch or resume app, ret(%d) result(%s)", ret, result);
421 /* send result noti */
422 ret = vcdc_send_result(temp_cmd->pid, vcd_client_manager_get_pid(), temp_cmd->type);
424 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Fail to send result, ret(%d)", ret);
425 g_slist_free_full(pid_list, free);
429 SLOG(LOG_ERROR, TAG_VCD, "[Server] Send result : pid(%d) type(%d)", temp_cmd->pid, temp_cmd->type);
430 pre_pid = temp_cmd->pid;
431 pre_type = temp_cmd->type;
437 pid_list = g_slist_remove_link(pid_list, iter);
439 iter = g_slist_nth(pid_list, 0);
444 if (VCD_RECOGNITION_MODE_RESTART_CONTINUOUSLY != vcd_client_get_recognition_mode()) {
445 vcd_config_set_service_state(VCD_STATE_READY);
446 vcdc_send_service_state(VCD_STATE_READY);
452 int vcd_send_asr_result(vce_asr_result_event_e event, const char* asr_result, void *user_data)
454 int ret = __vcd_server_launch_manager_app();
456 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);
460 if (NULL != asr_result) {
461 SECURE_SLOG(LOG_INFO, TAG_VCD, "[Server] ASR result - Event(%d), Text(%s)", event, asr_result);
462 ret = vcdc_send_pre_result_to_manager(vcd_client_manager_get_pid(), event, asr_result);
464 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);
471 int vcd_send_specific_engine_result(const char* engine_app_id, const char* event, const char* result, void *user_info)
473 if (NULL != result) {
474 SLOG(LOG_INFO, TAG_VCD, "[Server] specific engine result - Event(%s), Text(%s)", event, result);
475 vcdc_send_specific_engine_result_to_manager(vcd_client_manager_get_pid(), engine_app_id, event, result);
478 return VCD_ERROR_NONE;
481 int vcd_send_nlg_result(const char* nlg_result, void *user_data)
483 int ret = __vcd_server_launch_manager_app();
485 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);
489 SLOG(LOG_ERROR, TAG_VCD, "[Server] send dialog : mgr_pid(%d), nlg_result(%s)", vcd_client_manager_get_pid(), nlg_result);
490 ret = vcdc_send_dialog(vcd_client_manager_get_pid(), -1, nlg_result, NULL, 0); //0: VC_DIALOG_END
492 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);
496 static void* __recorder_stop(void *data)
502 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)
505 vcd_recognition_mode_e recognition_mode = vcd_client_get_recognition_mode();
507 if (VCD_STATE_PROCESSING != vcd_config_get_service_state()) {
508 if (VCD_RECOGNITION_MODE_RESTART_CONTINUOUSLY != recognition_mode) {
509 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Current state is not 'Processing' and mode is not 'Restart continuously'");
510 return VCD_ERROR_INVALID_STATE;
514 vc_info_parser_unset_result(vcd_client_manager_get_exclusive());
515 vcd_client_manager_set_result_text(all_result);
517 SECURE_SLOG(LOG_INFO, TAG_VCD, "[Server] Event(%d), Text(%s) Nonfixed(%s) Msg(%s) Result count(%d)",
518 event, all_result, non_fixed_result, msg, count);
520 SECURE_SLOG(LOG_ERROR, TAG_VCD, "[Server] NLU result(%s)", nlu_result);
523 /* if nlu_result is exist, Add command handle(is_action) into result list */
525 SLOG(LOG_INFO, TAG_VCD, "[Server] @ Get engine result @");
527 vc_cmd_s* temp_cmd = NULL;
528 vc_cmd_list_h vc_cmd_list = NULL;
530 if (0 != vc_cmd_list_create(&vc_cmd_list)) {
531 SLOG(LOG_INFO, TAG_VCD, "[Server] Fail to create command list");
532 vcd_client_manager_set_exclusive(false);
533 vcd_config_set_service_state(VCD_STATE_READY);
534 vcdc_send_service_state(VCD_STATE_READY);
535 return VCD_ERROR_NONE;
538 /* priority filter */
539 /* system > exclusive > widget > foreground > system_background > widget partial > foreground partial > background */
541 int* filtered_id = (int*)calloc(count, sizeof(int));
543 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to allocate memory");
544 vc_cmd_list_destroy(vc_cmd_list, true);
546 return VCD_ERROR_OUT_OF_MEMORY;
548 int filtered_count = 0;
549 int top_priority = VC_COMMAND_PRIORITY_BACKGROUND;
550 for (i = 0; i < count; i++) {
551 SLOG(LOG_INFO, TAG_VCD, "[Server] [%d] Result id(%d)", i, result_id[i]);
553 if (0 > result_id[i]) {
554 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Result ID(%d) is NOT valid", result_id[i]);
558 ret = vcd_client_get_cmd_from_result_id(result_id[i], &temp_cmd);
559 if (0 == ret && NULL != temp_cmd) {
560 if (top_priority == temp_cmd->priority) {
561 filtered_id[filtered_count] = result_id[i];
563 } else if (top_priority > temp_cmd->priority) {
564 filtered_id[0] = result_id[i];
566 top_priority = temp_cmd->priority;
569 vc_cmd_destroy((vc_cmd_h)temp_cmd);
574 if (top_priority >= VC_COMMAND_PRIORITY_WIDGET) {
575 int pid = vcd_client_widget_get_foreground_pid();
577 if (NULL != all_result) {
578 vc_info_parser_set_result(all_result, event, msg, NULL, false);
580 vcd_client_widget_get_asr_result_enabled(pid, &enable);
581 if (true == enable) {
582 SLOG(LOG_INFO, TAG_VCD, "[Server] Send ASR result to Widget client");
583 bool is_consumed = false;
584 if (NULL != user_info) {
587 if (0 != vcdc_send_asr_result(pid, event, all_result, VC_COMMAND_TYPE_WIDGET, &is_consumed)) {
588 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to send asr result");
590 SLOG(LOG_INFO, TAG_VCD, "[Server] ASR result is consumed(%d)", is_consumed);
591 if (true == is_consumed) {
592 if (NULL != user_info) {
594 SLOG(LOG_ERROR, TAG_VCD, "[Server] Send whether ASR result is consumed or not (%d)", *user_info);
596 vcdc_send_show_tooltip(pid, false);
597 if (-1 != vcd_client_manager_get_pid()) {
598 /* Manager client is available */
599 vc_info_parser_unset_result(false);
600 vc_info_parser_set_result(all_result, VC_RESULT_EVENT_RESULT_SUCCESS, msg, NULL, false);
601 if (0 != vcdc_send_result_to_manager(vcd_client_manager_get_pid(), VC_RESULT_TYPE_NOTIFICATION)) {
602 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Fail to send result");
606 // Set state manually, because the result is already handled in ASR result by client.
607 // So, the daemon does not need to send the result to client.
608 vcd_client_manager_set_exclusive(false);
610 vcd_config_set_service_state(VCD_STATE_READY);
611 vcdc_send_service_state(VCD_STATE_READY);
612 vc_cmd_list_destroy(vc_cmd_list, true);
614 if (NULL != filtered_id) {
618 return VCD_ERROR_NONE;
627 for (i = 0; i < filtered_count; i++) {
628 SLOG(LOG_INFO, TAG_VCD, "[Server] [%d] Filtered Result id(%d)", i, filtered_id[i]);
630 if (filtered_id[i] < 0) {
631 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Filtered ID(%d) is NOT valid", filtered_id[i]);
635 ret = vcd_client_get_cmd_from_result_id(filtered_id[i], &temp_cmd);
636 if (0 == ret && NULL != temp_cmd) {
637 switch (temp_cmd->format) {
638 case VC_CMD_FORMAT_FIXED:
639 case VC_CMD_FORMAT_FIXED_AND_VFIXED:
640 case VC_CMD_FORMAT_VFIXED_AND_FIXED:
641 case VC_CMD_FORMAT_PARTIAL:
642 case VC_CMD_FORMAT_FIXED_AND_NONFIXED:
643 case VC_CMD_FORMAT_NONFIXED_AND_FIXED:
645 case VC_CMD_FORMAT_ACTION:
649 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Unknown command type : %d", temp_cmd->type);
653 if (0 != vc_cmd_list_add(vc_cmd_list, (vc_cmd_h)temp_cmd)) {
654 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Fail to add command to list");
655 vc_cmd_destroy((vc_cmd_h)temp_cmd);
659 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] NOT found matched result(%d)", filtered_id[i]);
663 if (NULL != filtered_id) {
668 if (NULL != nlu_result) {
669 SECURE_SLOG(LOG_INFO, TAG_VCD, "[Server] NLU (%s)", nlu_result);
670 vc_info_parser_set_nlu_result(nlu_result);
671 if (0 == is_action) {
673 if (0 != vc_cmd_create(&nlu_cmd)) {
674 SLOG(LOG_ERROR, TAG_VCD, "Fail to nlu cmd create");
676 if (0 != vc_cmd_set_type(nlu_cmd, VC_COMMAND_TYPE_SYSTEM)) {
677 SLOG(LOG_ERROR, TAG_VCD, "Fail to set type");
679 if (0 != vc_cmd_set_pid(nlu_cmd, vcd_client_manager_get_pid())) {
680 SLOG(LOG_ERROR, TAG_VCD, "Fail to set pid");
682 if (0 != vc_cmd_set_format(nlu_cmd, VC_CMD_FORMAT_ACTION)) {
683 SLOG(LOG_ERROR, TAG_VCD, "Fail to set format");
685 if (0 != vc_cmd_list_add(vc_cmd_list, nlu_cmd)) {
686 SLOG(LOG_ERROR, TAG_VCD, "Fail to add nlu cmd to list");
687 vc_cmd_destroy(nlu_cmd);
693 vc_cmd_print_list(vc_cmd_list);
695 SLOG(LOG_INFO, TAG_VCD, "[Server] @@@@");
697 int result_count = 0;
698 vc_cmd_list_get_count(vc_cmd_list, &result_count);
700 /* Handle the result list */
701 if (0 == result_count) {
703 vc_cmd_list_h widget_cmd_list = NULL;
704 vc_cmd_list_h foreground_cmd_list = NULL;
705 if (NULL != all_result) {
706 SECURE_SLOG(LOG_INFO, TAG_VCD, "[Server] Engine result is no command : %s", all_result);
709 if (0 != vc_cmd_list_create(&widget_cmd_list)) {
710 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to create widget command list handle");
711 vc_cmd_list_destroy(vc_cmd_list, true);
713 return VCD_ERROR_OUT_OF_MEMORY;
716 /* Get the list of widget type commands */
717 vcd_client_append_cmd_from_type(VC_COMMAND_TYPE_WIDGET, widget_cmd_list);
718 vc_cmd_list_get_count(widget_cmd_list, &cnt);
720 /* Matched with widget command partially */
721 vc_cmd_get_partially_matched_cmd_list(all_result, widget_cmd_list, vc_cmd_list, VC_SEARCH_NONE_LEVEL);
722 vc_cmd_list_get_count(vc_cmd_list, &cnt);
724 top_priority = VC_COMMAND_PRIORITY_WIDGET;
725 SLOG(LOG_INFO, TAG_VCD, "[INFO] Partially matched widget command");
728 if (0 != vc_cmd_list_create(&foreground_cmd_list)) {
729 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to create foreground command list handle");
730 vc_cmd_list_destroy(vc_cmd_list, true);
732 vc_cmd_list_destroy(widget_cmd_list, true);
733 widget_cmd_list = NULL;
734 return VCD_ERROR_OUT_OF_MEMORY;
737 /* Get the list of foreground type commands */
738 vcd_client_append_cmd_from_type(VC_COMMAND_TYPE_FOREGROUND, foreground_cmd_list);
739 vc_cmd_list_get_count(foreground_cmd_list, &cnt);
741 /* Matched with foreground command partially */
742 vc_cmd_get_partially_matched_cmd_list(all_result, foreground_cmd_list, vc_cmd_list, VC_SEARCH_NONE_LEVEL);
743 vc_cmd_list_get_count(vc_cmd_list, &cnt);
745 top_priority = VC_COMMAND_PRIORITY_FOREGROUND;
746 SLOG(LOG_INFO, TAG_VCD, "[INFO] Partially matched foreground command");
749 vc_cmd_list_destroy(foreground_cmd_list, true);
750 foreground_cmd_list = NULL;
752 vc_cmd_list_destroy(widget_cmd_list, true);
753 widget_cmd_list = NULL;
755 SLOG(LOG_INFO, TAG_VCD, "[Server] Engine all result is NULL");
758 vc_cmd_list_get_count(vc_cmd_list, &result_count);
760 // After running partial matching algorithm, if there is no result.
761 if (0 == result_count) {
762 SLOG(LOG_INFO, TAG_VCD, "[Server] No commands even after partial matching");
764 bool temp = vcd_client_manager_get_exclusive();
765 vc_info_parser_set_result(all_result, event, msg, NULL, temp);
767 int pid = vcd_client_widget_get_foreground_pid();
769 SLOG(LOG_INFO, TAG_VCD, "[Server] Request tooltip hide");
770 /* Send to hide tooltip */
771 vcdc_send_show_tooltip(pid, false);
774 if (-1 != vcd_client_manager_get_pid()) {
775 /* Manager client is available */
776 if (0 != vcdc_send_result_to_manager(vcd_client_manager_get_pid(), VC_RESULT_TYPE_NORMAL)) {
777 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Fail to send result");
781 /* set service state ready */
782 vcd_config_set_service_state(VCD_STATE_READY);
783 vcdc_send_service_state(VCD_STATE_READY);
785 vcd_client_manager_set_exclusive(false);
786 vc_cmd_list_destroy(vc_cmd_list, true);
789 return VCD_ERROR_NONE;
792 // Partial matching algorithm find some commands
793 event = VC_RESULT_EVENT_RESULT_SUCCESS;
796 // There are more than one result.
797 if (false == vcd_client_manager_get_exclusive()) {
798 vc_cmd_list_h temp_list = NULL;
800 /* Foreground, Widget, Background, System, System-Background */
801 if (top_priority >= VC_COMMAND_PRIORITY_BACKGROUND) {
802 vc_cmd_list_h widget_cmd_list = NULL;
803 vc_cmd_list_h foreground_cmd_list = NULL;
806 if (0 != vc_cmd_list_create(&temp_list)) {
807 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to create widget command list handle");
808 vc_cmd_list_destroy(vc_cmd_list, true);
810 return VCD_ERROR_OUT_OF_MEMORY;
813 if (0 != vc_cmd_list_create(&widget_cmd_list)) {
814 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to create widget command list handle");
815 vc_cmd_list_destroy(vc_cmd_list, true);
817 vc_cmd_list_destroy(temp_list, true);
819 return VCD_ERROR_OUT_OF_MEMORY;
822 /* Get the list of widget type commands */
823 vcd_client_append_cmd_from_type(VC_COMMAND_TYPE_WIDGET, widget_cmd_list);
824 vc_cmd_list_get_count(widget_cmd_list, &cnt);
826 /* Matched with widget command partially */
827 vc_cmd_get_partially_matched_cmd_list(all_result, widget_cmd_list, temp_list, VC_SEARCH_NONE_LEVEL);
828 vc_cmd_list_get_count(temp_list, &cnt);
830 if (0 != vc_cmd_list_destroy(vc_cmd_list, true)) {
831 SLOG(LOG_WARN, TAG_VCD, "[WARNING] Fail to destroy list");
833 vc_cmd_list = temp_list;
834 top_priority = VC_COMMAND_PRIORITY_WIDGET;
835 event = VC_RESULT_EVENT_RESULT_SUCCESS;
836 SLOG(LOG_INFO, TAG_VCD, "[INFO] Partially matched widget command when background cmd exists");
839 if (0 != vc_cmd_list_create(&foreground_cmd_list)) {
840 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to create foreground command list handle");
841 vc_cmd_list_destroy(vc_cmd_list, true);
843 vc_cmd_list_destroy(widget_cmd_list, true);
844 widget_cmd_list = NULL;
845 return VCD_ERROR_OUT_OF_MEMORY;
848 /* Get the list of foreground type commands */
849 vcd_client_append_cmd_from_type(VC_COMMAND_TYPE_FOREGROUND, foreground_cmd_list);
850 vc_cmd_list_get_count(foreground_cmd_list, &cnt);
852 /* Matched with foreground command partially */
853 vc_cmd_get_partially_matched_cmd_list(all_result, foreground_cmd_list, temp_list, VC_SEARCH_NONE_LEVEL);
854 vc_cmd_list_get_count(temp_list, &cnt);
856 if (0 != vc_cmd_list_destroy(vc_cmd_list, true)) {
857 SLOG(LOG_WARN, TAG_VCD, "[WARNING] Fail to destroy list");
859 vc_cmd_list = temp_list;
860 top_priority = VC_COMMAND_PRIORITY_FOREGROUND;
861 event = VC_RESULT_EVENT_RESULT_SUCCESS;
862 SLOG(LOG_INFO, TAG_VCD, "[INFO] Partially matched foreground command when background cmd exists");
865 vc_cmd_list_destroy(foreground_cmd_list, true);
866 foreground_cmd_list = NULL;
868 vc_cmd_list_destroy(widget_cmd_list, true);
869 widget_cmd_list = NULL;
872 int pid = vcd_client_widget_get_foreground_pid();
874 SLOG(LOG_INFO, TAG_VCD, "[Server] Request tooltip hide");
875 vcdc_send_show_tooltip(pid, false);
878 vc_info_parser_set_result(all_result, event, msg, vc_cmd_list, false);
879 vc_cmd_list_destroy(vc_cmd_list, true);
882 if (-1 != vcd_client_manager_get_pid()) {
883 /* Manager client is available */
884 if (0 != vcdc_send_result_to_manager(vcd_client_manager_get_pid(), VC_RESULT_TYPE_NORMAL)) {
885 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Fail to send result");
888 SLOG(LOG_INFO, TAG_VCD, "[Server] Manager is NOT available. Send result to client directly");
889 ecore_timer_add(0, __vcd_send_selected_result, NULL);
892 /* exclusive command */
893 vc_info_parser_set_result(all_result, event, msg, vc_cmd_list, true);
894 vc_cmd_list_destroy(vc_cmd_list, true);
897 if (-1 != vcd_client_manager_get_pid()) {
898 /* Manager client is available */
899 if (0 != vcdc_send_result_to_manager(vcd_client_manager_get_pid(), VC_RESULT_TYPE_NORMAL)) {
900 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Fail to send result");
903 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Manager is NOT available");
906 vcd_client_manager_set_exclusive(false);
909 if (VCD_RECOGNITION_MODE_RESTART_AFTER_REJECT == recognition_mode) {
910 if (VCE_RESULT_EVENT_REJECTED == event) {
911 SLOG(LOG_INFO, TAG_VCD, "[Server] Restart by no or rejected result");
912 /* If no result and restart option is ON */
913 /* Send reject message */
914 bool temp = vcd_client_manager_get_exclusive();
915 vc_info_parser_set_result(all_result, event, msg, NULL, temp);
916 ret = vcdc_send_result_to_manager(vcd_client_manager_get_pid(), VC_RESULT_TYPE_NOTIFICATION);
918 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Fail to send result");
921 g_restart_timer = ecore_timer_add(0, __restart_engine, NULL);
924 SLOG(LOG_INFO, TAG_VCD, "[Server] Stop recorder due to success");
925 //vcd_recorder_stop();
926 ecore_main_loop_thread_safe_call_sync(__recorder_stop, NULL);
927 } else if (VCD_RECOGNITION_MODE_RESTART_CONTINUOUSLY == recognition_mode) {
928 SLOG(LOG_INFO, TAG_VCD, "[Server] Restart continuously");
929 /* Restart option is ON */
930 g_restart_timer = ecore_timer_add(0, __restart_engine, NULL);
931 if (VCE_RESULT_EVENT_REJECTED == event) {
932 bool temp = vcd_client_manager_get_exclusive();
933 vc_info_parser_set_result(all_result, event, msg, NULL, temp);
934 ret = vcdc_send_result_to_manager(vcd_client_manager_get_pid(), VC_RESULT_TYPE_NOTIFICATION);
936 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Fail to send result");
942 return VCD_ERROR_NONE;
946 if (NULL == result_id) {
948 if (NULL != all_result) {
949 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Engine result is no command : %s", all_result);
950 bool temp = vcd_client_manager_get_exclusive();
951 vc_info_parser_set_result(all_result, event, msg, NULL, temp);
954 int pid = vcd_client_widget_get_foreground_pid();
956 if (NULL != all_result) {
957 /* Send result text to widget */
958 vcdc_send_result(pid, vcd_client_manager_get_pid(), VC_COMMAND_TYPE_WIDGET);
961 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Request tooltip hide");
962 /* Send to hide tooltip */
963 vcdc_send_show_tooltip(pid, false);
966 if (-1 != vcd_client_manager_get_pid()) {
967 /* Manager client is available */
968 if (0 != vcdc_send_result_to_manager(vcd_client_manager_get_pid(), VC_RESULT_TYPE_NORMAL)) {
969 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Fail to send result");
973 vcd_client_manager_set_exclusive(false);
979 SLOG(LOG_DEBUG, TAG_VCD, "[Server] @ Get engine result @");
982 vc_cmd_s* temp_cmd = NULL;
983 vc_cmd_list_h vc_cmd_list = NULL;
985 if (0 != vc_cmd_list_create(&vc_cmd_list)) {
986 SLOG(LOG_ERROR, TAG_VCD, "[Server] Fail to create command list");
987 vcd_client_manager_set_exclusive(false);
988 vcd_config_set_service_state(VCD_STATE_READY);
989 vcdc_send_service_state(VCD_STATE_READY);
994 for (i = 0; i < count; i++) {
995 SLOG(LOG_DEBUG, TAG_VCD, "[Server] [%d] Result ID(%d)", i, result_id[i]);
997 if (result_id[i] < 0) {
998 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Result ID(%d) is NOT valid", result_id[i]);
1002 ret = vcd_client_get_cmd_from_result_id(result_id[i], &temp_cmd);
1003 if (0 == ret && NULL != temp_cmd) {
1004 switch (temp_cmd->format) {
1005 case VC_CMD_FORMAT_FIXED:
1006 case VC_CMD_FORMAT_FIXED_AND_VFIXED:
1007 case VC_CMD_FORMAT_VFIXED_AND_FIXED:
1008 case VC_CMD_FORMAT_PARTIAL:
1009 /* Nonfixed result is NOT valid */
1011 case VC_CMD_FORMAT_FIXED_AND_NONFIXED:
1012 if (NULL == temp_cmd->parameter) {
1013 if (NULL != non_fixed_result) {
1014 temp_cmd->parameter = strdup(non_fixed_result);
1017 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Command type is NOT valid. Parameter (%s)", temp_cmd->parameter);
1020 case VC_CMD_FORMAT_NONFIXED_AND_FIXED:
1021 if (NULL == temp_cmd->command) {
1022 if (NULL != non_fixed_result) {
1023 temp_cmd->command = strdup(non_fixed_result);
1026 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Command type is NOT valid. Command (%s)", temp_cmd->command);
1031 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Unknown command type : %d", temp_cmd->type);
1035 if (0 != vc_cmd_list_add(vc_cmd_list, (vc_cmd_h)temp_cmd)) {
1036 SLOG(LOG_DEBUG, TAG_VCD, "Fail to add command to list");
1037 vc_cmd_destroy((vc_cmd_h)temp_cmd);
1040 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] NOT found matched result(%d)", result_id[i]);
1044 vc_cmd_print_list(vc_cmd_list);
1046 SLOG(LOG_DEBUG, TAG_VCD, "[Server] @@@@");
1048 int result_count = 0;
1049 vc_cmd_list_get_count(vc_cmd_list, &result_count);
1051 if (false == vcd_client_manager_get_exclusive()) {
1052 int pid = vcd_client_widget_get_foreground_pid();
1054 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Request tooltip hide");
1055 vcdc_send_show_tooltip(pid, false);
1058 vc_info_parser_set_result(all_result, event, msg, vc_cmd_list, false);
1060 if (-1 != vcd_client_manager_get_pid()) {
1061 /* Manager client is available */
1062 if (0 != vcdc_send_result_to_manager(vcd_client_manager_get_pid(), VC_RESULT_TYPE_NORMAL)) {
1063 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Fail to send result");
1066 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Manager is NOT available. Send result to client directly");
1067 /* Send result to client */
1068 ecore_timer_add(0, __vcd_send_selected_result, NULL);
1071 /* exclusive command */
1072 vc_info_parser_set_result(all_result, event, msg, vc_cmd_list, true);
1074 if (-1 != vcd_client_manager_get_pid()) {
1075 /* Manager client is available */
1076 if (0 != vcdc_send_result_to_manager(vcd_client_manager_get_pid(), VC_RESULT_TYPE_NORMAL)) {
1077 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Fail to send result");
1080 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Manager is NOT available");
1083 vcd_client_manager_set_exclusive(false);
1086 vc_cmd_list_destroy(vc_cmd_list, true);
1094 static void __vcd_server_nlu_result_cb(vce_result_event_e event, const char* nlu_result, void *user_data)
1096 SECURE_SLOG(LOG_DEBUG, TAG_VCD, "[Server] NLU result cb - event(%d)", event);
1097 SECURE_SLOG(LOG_DEBUG, TAG_VCD, "[Server] result (%s)", nlu_result);
1099 int ret = vc_info_parser_set_nlu_result(nlu_result);
1101 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to set nlu result (%d)", ret);
1108 int vcd_send_error(vce_error_e error, const char* msg, void *user_data)
1110 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Engine Error cb - reason(%d), msg(%s)", error, msg);
1112 char* error_msg = NULL;
1114 error_msg = strdup(msg);
1115 if (NULL == error_msg) {
1116 return VCD_ERROR_OUT_OF_MEMORY;
1120 int ret = VCD_ERROR_NONE;
1121 if (VCE_ERROR_TTS_FAILED == error) {
1122 int pid = __get_tts_played_pid();
1123 ret = vcdc_send_error_signal_to_app(pid, error, error_msg);
1125 ret = vcdc_send_error_to_manager(vcd_client_manager_get_pid(), error, error_msg);
1126 ecore_main_loop_thread_safe_call_async(__cancel_by_error, NULL);
1129 if (VCD_ERROR_NONE != ret) {
1130 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to send error signal");
1133 if (NULL != error_msg) {
1141 /* for TTS feedback */
1142 int vcd_send_feedback_audio_format(int rate, vce_audio_channel_e channel, vce_audio_type_e audio_type)
1144 SLOG(LOG_INFO, TAG_VCD, "[Server DEBUG] Engine - Send TTS feedback audio format, g_current_tts_uid(%u)", g_current_tts_uid);
1146 /* send TTS feedback audio format to VC manager */
1147 int ret = VCD_ERROR_NONE;
1148 int pid = __get_tts_played_pid();
1149 if (VC_INVALID_TTS_UID == pid || vcd_client_manager_get_pid() == pid) {
1150 ret = vcdc_send_feedback_audio_format_to_manager(vcd_client_manager_get_pid(), rate, channel, audio_type);
1151 if (VCD_ERROR_NONE != ret) {
1152 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to send TTS feedback audio format to VC manager");
1155 SLOG(LOG_INFO, TAG_VCD, "[Server INFO] Do not send TTS feedback audio format to VC manager");
1161 int vcd_send_feedback_streaming(vce_feedback_event_e event, char* buffer, int len)
1163 if (VC_INVALID_TTS_UID == g_current_tts_uid && VCE_FEEDBACK_EVENT_START == event) {
1164 g_current_utt_id = (g_current_utt_id + 1) % 1000;
1165 g_current_tts_uid = (unsigned int)vcd_client_manager_get_pid() * 1000u + g_current_utt_id;
1166 SLOG(LOG_INFO, TAG_VCD, "[Server info] set current uid and utt_id as manager pid(%d)", vcd_client_manager_get_pid());
1169 int ret = VCD_ERROR_NONE;
1170 int pid = __get_tts_played_pid();
1171 int utt_id = g_current_tts_uid % 1000;
1173 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));
1175 if (VC_INVALID_TTS_UID == pid || pid == vcd_client_manager_get_pid() || -1 == vcd_client_manager_get_pid()) {
1176 /* send TTS feedback streaming to manager client */
1177 ret = vcdc_send_feedback_streaming_to_manager(vcd_client_manager_get_pid(), pid, utt_id, event, buffer, len);
1178 if (VCD_ERROR_NONE != ret) {
1179 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to send TTS feedback streaming to manager client");
1182 /* send TTS feedback streaming to client */
1183 ret = vcdc_send_feedback_streaming(pid, utt_id, event, buffer, len);
1184 if (VCD_ERROR_NONE != ret) {
1185 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to send TTS feedback streaming to client");
1189 if (VCE_FEEDBACK_EVENT_FINISH == event) {
1190 /* reset current uid */
1191 g_current_tts_uid = VC_INVALID_TTS_UID;
1193 /* Set service state to ready if state is synthesizing */
1194 vcd_state_e state = vcd_config_get_service_state();
1195 if (VCD_STATE_SYNTHESIZING == state) {
1196 vcd_config_set_service_state(VCD_STATE_READY);
1198 SLOG(LOG_INFO, TAG_VCD, "[Server info] feedback streaming finish event, reset current uid & service state(%d)", vcd_config_get_service_state());
1205 * vcd server Interfaces
1207 static void __vcd_file_clean_up()
1209 SLOG(LOG_INFO, TAG_VCD, "== Old file clean up == ");
1212 struct dirent *dirp = NULL;
1214 dp = opendir(VC_RUNTIME_INFO_ROOT);
1216 SLOG(LOG_ERROR, TAG_VCD, "[File message WARN] Fail to open path : %s", VC_RUNTIME_INFO_ROOT);
1220 char remove_path[257] = {0, };
1225 if (!strncmp("vc_", dirp->d_name, strlen("vc_"))) {
1226 memset(remove_path, 0, 257);
1227 snprintf(remove_path, 257, "%s/%s", VC_RUNTIME_INFO_ROOT, dirp->d_name);
1230 if (0 != remove(remove_path)) {
1231 SLOG(LOG_WARN, TAG_VCD, "[File message WARN] Fail to remove file : %s", remove_path);
1233 SLOG(LOG_INFO, TAG_VCD, "[File message] Remove file : %s", remove_path);
1237 } while (NULL != dirp);
1244 static int __vcd_db_clean_up()
1247 int cnt = VC_COMMAND_TYPE_FOREGROUND;
1249 if (VC_COMMAND_TYPE_BACKGROUND != cnt)
1250 ret = vc_db_delete_commands(-1, cnt, NULL);
1251 } while (VC_COMMAND_TYPE_EXCLUSIVE >= ++cnt);
1257 static bool __is_default_engine()
1259 char* engine = NULL;
1260 engine = vconf_get_str(VCONFKEY_VC_ENGINE_DEFAULT);
1261 if (NULL == engine) {
1262 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to get sting for vc engine");
1266 char appid[1024] = {'\0', };
1267 if (0 != aul_app_get_appid_bypid(getpid(), appid, sizeof(appid) - 1)) {
1268 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to get callee appid by pid");
1271 SLOG(LOG_DEBUG, TAG_VCD, "[Server] VC Default Engine(%s), appId(%s)", engine, appid);
1272 if (0 == strncmp(engine, appid, strlen(engine))) {
1281 int vcd_initialize(vce_request_callback_s *callback)
1285 /* Remove old file */
1286 __vcd_file_clean_up();
1288 /* initialize modules */
1289 ret = vcd_config_initialize(__config_lang_changed_cb, __config_foreground_changed_cb, NULL);
1291 SLOG(LOG_ERROR, TAG_VCD, "[Server WARNING] Fail to initialize config.");
1294 ret = vc_db_initialize_for_daemon();
1296 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to initialize DB : %d", ret);
1297 if (TRUE != vcd_finalize()) {
1298 SLOG(LOG_ERROR, TAG_VCD, "[Server Error] Fail to finalize");
1303 /* Remove db data */
1304 ret = __vcd_db_clean_up();
1306 SLOG(LOG_ERROR, TAG_VCD, "[Server WARNING] Fail to remove db data");
1309 vcd_config_set_service_state(VCD_STATE_NONE);
1311 ret = vcd_engine_agent_init();
1313 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to engine agent initialize : result(%d)", ret);
1314 if (TRUE != vcd_finalize()) {
1315 SLOG(LOG_ERROR, TAG_VCD, "[Server Error] Fail to finalize");
1320 if (0 != vcd_recorder_create(__server_recorder_callback, __server_recorder_interrupt_callback)) {
1321 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to create recorder");
1322 if (TRUE != vcd_finalize()) {
1323 SLOG(LOG_ERROR, TAG_VCD, "[Server Error] Fail to finalize");
1325 return VCD_ERROR_OPERATION_FAILED;
1329 if (0 != vcd_engine_agent_load_current_engine(callback)) {
1330 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to load current engine");
1331 if (TRUE != vcd_finalize()) {
1332 SLOG(LOG_ERROR, TAG_VCD, "[Server Error] Fail to finalize");
1334 return VCD_ERROR_OPERATION_FAILED;
1337 /* Initialize manager info */
1338 vcd_client_manager_unset();
1340 // if (TRUE == __is_default_engine()) {
1341 /* Open tidl connection */
1342 if (0 != vcd_tidl_open_connection()) {
1343 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to open tidl connection");
1344 if (TRUE != vcd_finalize()) {
1345 SLOG(LOG_ERROR, TAG_VCD, "[Server Error] Fail to finalize");
1347 return VCD_ERROR_OPERATION_FAILED;
1351 vcd_config_set_service_state(VCD_STATE_READY);
1352 // vcdc_send_service_state(VCD_STATE_READY);
1354 /* Set timer cleanup client all */
1355 g_check_client_timer = ecore_timer_add(CLIENT_CLEAN_UP_TIME, vcd_cleanup_client_all, NULL);
1356 if (NULL == g_check_client_timer) {
1357 SLOG(LOG_WARN, TAG_VCD, "[Server Warning] Fail to create timer of client check");
1360 g_current_tts_uid = VC_INVALID_TTS_UID;
1361 g_current_utt_id = -1;
1363 SLOG(LOG_ERROR, TAG_VCD, "[Server SUCCESS] initialize");
1365 return VCD_ERROR_NONE;
1371 if (0 < g_list_length(g_proc_list)) {
1372 iter = g_list_first(g_proc_list);
1373 while (NULL != iter) {
1374 g_proc_list = g_list_delete_link(g_proc_list, iter);
1375 iter = g_list_first(g_proc_list);
1379 if (NULL != g_restart_timer) {
1380 ecore_timer_del(g_restart_timer);
1381 g_restart_timer = NULL;
1384 if (NULL != g_check_client_timer) {
1385 ecore_timer_del(g_check_client_timer);
1386 g_check_client_timer = NULL;
1389 vcd_state_e state = vcd_config_get_service_state();
1390 if (VCD_STATE_NONE != state && VCD_STATE_READY != state) {
1391 if (VCD_STATE_RECORDING == state) {
1392 vcd_recorder_stop();
1394 vcd_engine_recognize_cancel();
1397 if (0 != vcd_recorder_destroy()) {
1398 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to destroy recorder");
1401 SLOG(LOG_DEBUG, TAG_VCD, "[Server] destroy recorder");
1404 if (0 != vcd_engine_agent_release()) {
1405 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to release engine");
1408 SLOG(LOG_DEBUG, TAG_VCD, "[Server] release engine");
1411 vcd_client_manager_unset_appid();
1413 int ret = vcd_config_finalize();
1415 SLOG(LOG_ERROR, TAG_VCD, "[Server WARNING] Fail to finalize config.");
1418 ret = vc_db_finalize();
1420 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to finalize DB : %d", ret);
1423 if (VCD_STATE_NONE != state) {
1424 vcd_config_set_service_state(VCD_STATE_NONE);
1425 vcdc_send_service_state(VCD_STATE_NONE);
1428 /* Close tidl connection */
1429 if (0 != vcd_tidl_close_connection()) {
1430 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to close connection");
1433 SLOG(LOG_ERROR, TAG_VCD, "[Server] mode finalize");
1438 static Eina_Bool __finalize_quit_ecore_loop(void *data)
1440 bool ret = vcd_finalize();
1444 ecore_main_loop_quit();
1449 static void __read_proc()
1452 struct dirent *dirp = NULL;
1456 if (0 < g_list_length(g_proc_list)) {
1457 iter = g_list_first(g_proc_list);
1458 while (NULL != iter) {
1459 g_proc_list = g_list_delete_link(g_proc_list, iter);
1460 iter = g_list_first(g_proc_list);
1464 dp = opendir("/proc");
1466 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to open proc");
1472 tmp = atoi(dirp->d_name);
1473 if (0 >= tmp) continue;
1474 g_proc_list = g_list_append(g_proc_list, GINT_TO_POINTER(tmp));
1476 } while (NULL != dirp);
1482 static void __vcd_cleanup_client(vcd_client_type_e type)
1484 int* client_list = NULL;
1485 int client_count = 0;
1492 if (VCD_CLIENT_TYPE_NORMAL == type) {
1493 ret = vcd_client_get_list(&client_list, &client_count);
1494 } else if (VCD_CLIENT_TYPE_WIDGET == type) {
1495 ret = vcd_client_widget_get_list(&client_list, &client_count);
1496 } else if (VCD_CLIENT_TYPE_MANAGER == type) {
1497 mgr_pid = vcd_client_manager_get_pid();
1498 client_list = &mgr_pid;
1500 if (-1 == mgr_pid) {
1501 SLOG(LOG_WARN, TAG_VCD, "[WARNING] Invalid Manager pid");
1506 if (0 == ret || mgr_pid > 0) {
1507 SLOG(LOG_INFO, TAG_VCD, "@@@ Clean up %s client ", type ? (type == VCD_CLIENT_TYPE_WIDGET) ? "Widget" : "Manager" : "Normal");
1508 if (NULL != client_list && client_count > 0) {
1509 for (i = 0; i < client_count; i++) {
1512 for (j = 0; j < g_list_length(g_proc_list); j++) {
1513 iter = g_list_nth(g_proc_list, j);
1515 if (*(client_list + i) == GPOINTER_TO_INT(iter->data)) {
1516 SLOG(LOG_INFO, TAG_VCD, "%s pid(%d) is running", type ? (type == VCD_CLIENT_TYPE_WIDGET) ? "Widget" : "Manager" : "Normal", *(client_list + i));
1523 if (false == exist) {
1524 SLOG(LOG_ERROR, TAG_VCD, "%s pid(%d) should be removed", type ? (type == VCD_CLIENT_TYPE_WIDGET) ? "Widget" : "Manager" : "Normal", *(client_list + i));
1525 if (VCD_CLIENT_TYPE_NORMAL == type)
1526 vcd_server_finalize(*(client_list + i));
1527 else if (VCD_CLIENT_TYPE_WIDGET == type)
1528 vcd_server_widget_finalize(*(client_list + i));
1530 vcd_server_mgr_finalize(mgr_pid);
1534 SLOG(LOG_INFO, TAG_VCD, "@@@");
1536 if (NULL != client_list && -1 == mgr_pid) {
1543 Eina_Bool vcd_cleanup_client_all(void *data)
1547 __vcd_cleanup_client(VCD_CLIENT_TYPE_NORMAL);
1548 __vcd_cleanup_client(VCD_CLIENT_TYPE_WIDGET);
1549 __vcd_cleanup_client(VCD_CLIENT_TYPE_MANAGER);
1551 if (0 == vcd_client_get_ref_count()) {
1552 SLOG(LOG_INFO, TAG_VCD, "[Server] Connected client list is empty");
1553 ecore_timer_add(0, __finalize_quit_ecore_loop, NULL);
1556 if (0 == vcd_client_get_list(&client_list, &client_count)) {
1557 SLOG(LOG_DEBUG, TAG_VCD, "@@@ Clean up client ");
1558 if (NULL != client_list && client_count > 0) {
1559 for (i = 0; i < client_count; i++) {
1562 for (j = 0; j < g_list_length(g_proc_list); j++) {
1563 iter = g_list_nth(g_proc_list, j);
1565 if (client_list[i] == GPOINTER_TO_INT(iter->data)) {
1566 SLOG(LOG_DEBUG, TAG_VCD, "pid(%d) is running", client_list[i]);
1573 if (false == exist) {
1574 SLOG(LOG_ERROR, TAG_VCD, "pid(%d) should be removed", client_list[i]);
1575 vcd_server_finalize(client_list[i]);
1578 result = vcdc_send_hello(client_list[i], VCD_CLIENT_TYPE_NORMAL);
1581 SLOG(LOG_DEBUG, TAG_VCD, "[Server] pid(%d) should be removed.", client_list[i]);
1582 vcd_server_finalize(client_list[i]);
1583 } else if (-1 == result) {
1584 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Hello result has error");
1589 SLOG(LOG_DEBUG, TAG_VCD, "@@@");
1591 if (NULL != client_list) {
1596 /* If app is in background state, app cannot response message. */
1597 if (0 == vcd_client_widget_get_list(&client_list, &client_count)) {
1598 SLOG(LOG_DEBUG, TAG_VCD, "@@@ Clean up widget");
1599 if (NULL != client_list && client_count > 0) {
1600 for (i = 0; i < client_count; i++) {
1603 for (j = 0; j < g_list_length(g_proc_list); j++) {
1604 iter = g_list_nth(g_proc_list, j);
1606 if (client_list[i] == GPOINTER_TO_INT(iter->data)) {
1607 SLOG(LOG_DEBUG, TAG_VCD, "widget pid(%d) is running", client_list[i]);
1614 if (false == exist) {
1615 SLOG(LOG_ERROR, TAG_VCD, "widget pid(%d) should be removed", client_list[i]);
1616 vcd_server_widget_finalize(client_list[i]);
1619 result = vcdc_send_hello(client_list[i], VCD_CLIENT_TYPE_WIDGET);
1622 SLOG(LOG_DEBUG, TAG_VCD, "[Server] widget pid(%d) should be removed.", client_list[i]);
1623 vcd_server_widget_finalize(client_list[i]);
1624 } else if (-1 == result) {
1625 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Hello result has error");
1630 SLOG(LOG_DEBUG, TAG_VCD, "@@@");
1633 if (NULL != client_list) {
1641 int mgr_pid = vcd_client_manager_get_pid();
1643 for (j = 0; j < g_list_length(g_proc_list); j++) {
1644 iter = g_list_nth(g_proc_list, j);
1646 if (mgr_pid == GPOINTER_TO_INT(iter->data)) {
1647 SLOG(LOG_DEBUG, TAG_VCD, "manager pid(%d) is running", mgr_pid);
1654 if (false == exist) {
1655 SLOG(LOG_ERROR, TAG_VCD, "manager pid (%d) should be removed", mgr_pid);
1656 vcd_server_mgr_finalize(mgr_pid);
1663 int vcd_server_get_service_state()
1665 return vcd_config_get_service_state();
1668 int vcd_server_get_foreground()
1671 vcd_config_get_foreground(&pid);
1678 int vcd_server_mgr_initialize(int pid, vcd_audio_streaming_mode_e mode)
1680 /* check if pid is valid */
1681 if (false == vcd_client_manager_is_valid(pid)) {
1682 SLOG(LOG_ERROR, TAG_VCD, "[Server] old manager pid(%d) be removed", vcd_client_manager_get_pid());
1683 vcd_server_mgr_cancel();
1684 vcd_client_manager_unset();
1687 /* Add client information to client manager */
1688 int ret = vcd_client_manager_set(pid);
1690 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to add manager");
1691 return VCD_ERROR_OPERATION_FAILED;
1694 if (0 != vcdc_send_manager_pid(pid))
1695 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Fail to send manager pid");
1697 vcd_recorder_set_audio_streaming_mode(mode);
1699 SLOG(LOG_ERROR, TAG_VCD, "[Server Success] Manager initialize : pid(%d)", pid);
1701 return VCD_ERROR_NONE;
1704 int vcd_server_mgr_finalize(int pid)
1706 /* check if pid is valid */
1707 if (false == vcd_client_manager_is_valid(pid)) {
1708 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] The manager pid(%d) is NOT valid", pid);
1709 return VCD_ERROR_INVALID_PARAMETER;
1712 /* Cancel recognition */
1713 vcd_server_mgr_cancel();
1715 if (0 != vcdc_send_manager_pid(-1))
1716 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Fail to send manager pid");
1718 /* Remove manager information */
1719 if (0 != vcd_client_manager_unset()) {
1720 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Fail to delete client");
1723 if (0 == vcd_client_get_ref_count()) {
1724 SLOG(LOG_INFO, TAG_VCD, "[Server] Connected client list is empty");
1725 ecore_timer_add(0, __finalize_quit_ecore_loop, NULL);
1728 SLOG(LOG_ERROR, TAG_VCD, "[Server Success] Manager Finalize : pid(%d)", pid);
1730 return VCD_ERROR_NONE;
1733 int vcd_server_mgr_set_command(int pid)
1735 if (0 != vcd_client_manager_set_command(pid)) {
1736 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] The manager pid(%d) is NOT valid", pid);
1737 return VCD_ERROR_INVALID_PARAMETER;
1739 return VCD_ERROR_NONE;
1742 int vcd_server_mgr_unset_command(int pid)
1744 if (0 != vcd_client_manager_unset_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_set_demandable_client(int pid)
1753 /* check if pid is valid */
1754 if (false == vcd_client_manager_is_valid(pid)) {
1755 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] The manager pid(%d) is NOT valid", pid);
1756 return VCD_ERROR_INVALID_PARAMETER;
1759 GSList* client_list = NULL;
1760 if (0 != vc_info_parser_get_demandable_clients(&client_list)) {
1761 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to get demandable client");
1762 return VCD_ERROR_OPERATION_FAILED;
1765 /* Save client list */
1766 if (0 != vcd_client_manager_set_demandable_client(pid, client_list)) {
1767 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to set demandable client list");
1768 return VCD_ERROR_OPERATION_FAILED;
1771 return VCD_ERROR_NONE;
1774 int vcd_server_mgr_set_audio_type(int pid, const char* audio_type)
1776 /* check if pid is valid */
1777 if (false == vcd_client_manager_is_valid(pid)) {
1778 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] The manager pid(%d) is NOT valid", pid);
1779 return VCD_ERROR_INVALID_PARAMETER;
1783 vce_audio_type_e type = VCE_AUDIO_TYPE_PCM_S16_LE;
1787 ret = vcd_engine_get_audio_format(audio_type, &type, &rate, &channel);
1789 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to get audio format : %d", ret);
1790 return VCD_ERROR_OPERATION_FAILED;
1793 ret = vcd_recorder_set(audio_type, type, rate, channel);
1795 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to set audio in type : %d", ret);
1796 return VCD_ERROR_OPERATION_FAILED;
1799 return VCD_ERROR_NONE;
1802 int vcd_server_mgr_get_audio_type(int pid, char** audio_type)
1804 /* check if pid is valid */
1805 if (false == vcd_client_manager_is_valid(pid)) {
1806 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] The manager pid(%d) is NOT valid", pid);
1807 return VCD_ERROR_INVALID_PARAMETER;
1810 int ret = vcd_recorder_get(audio_type);
1812 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to get audio in type : %d", ret);
1813 return VCD_ERROR_OPERATION_FAILED;
1816 return VCD_ERROR_NONE;
1819 int vcd_server_mgr_set_client_info(int pid)
1821 /* check if pid is valid */
1822 if (false == vcd_client_manager_is_valid(pid)) {
1823 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] The manager pid(%d) is NOT valid", pid);
1824 return VCD_ERROR_INVALID_PARAMETER;
1827 int ret = vcd_client_save_client_info();
1829 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to save client info : %d", ret);
1830 return VCD_ERROR_OPERATION_FAILED;
1833 return VCD_ERROR_NONE;
1836 static int __reset_waiting_for_widget_recording(void)
1838 SLOG(LOG_ERROR, TAG_VCD, "[Server] Reset waiting for widget recording");
1839 // Delete timer to check that widget client is terminated
1840 if (g_check_widget_client_timer) {
1841 ecore_timer_del(g_check_widget_client_timer);
1842 g_check_widget_client_timer = NULL;
1844 // Reset flag to wait for recording from widget client
1845 vcd_client_widget_set_waiting_for_recording(-1, false);
1846 return VCD_ERROR_NONE;
1850 static Eina_Bool __send_waiting_timeout_error_to_manager(void* data)
1852 intptr_t ppid = (intptr_t)data;
1853 int pid = (int)ppid;
1854 SLOG(LOG_ERROR, TAG_VCD, "Widget client didn't send to start recording, pid(%d)", pid);
1855 __reset_waiting_for_widget_recording();
1857 vcdc_send_error_signal_to_manager(vcd_client_manager_get_pid(), VCD_ERROR_OPERATION_FAILED, "voice_engine.error.proc_fail");
1861 static Eina_Bool __send_waiting_timeout_start_recording(void* data)
1863 intptr_t ppid = (intptr_t)data;
1864 int pid = (int)ppid;
1865 SLOG(LOG_ERROR, TAG_VCD, "Widget client didn't send to start recording, pid(%d)", pid);
1867 int ret = __start_internal_recognition();
1869 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to start recognition : %d", ret);
1876 static int __set_waiting_for_widget_recording(int pid)
1878 SLOG(LOG_ERROR, TAG_VCD, "[Server] Set waiting for widget recording, pid(%d)", pid);
1880 // Check if the app included widget client is terminated or not. If it is terminated, vcd_server_widget_finalize() function will be called
1881 // In that function, it will start recording
1882 intptr_t ppid = (intptr_t)pid;
1883 g_check_widget_client_timer = ecore_timer_add(2.0, __send_waiting_timeout_start_recording, (void*)ppid);
1885 // Set flag to wait for recording from widget client
1886 vcd_client_widget_set_waiting_for_recording(pid, true);
1887 return VCD_ERROR_NONE;
1890 static int __start_internal_recognition()
1893 __reset_waiting_for_widget_recording();
1895 if (0 != vcd_client_command_collect_command()) {
1896 SLOG(LOG_ERROR, TAG_VCD, "[Client Data ERROR] Fail to collect command");
1897 /* Send error cb to manager */
1898 int pid = vcd_client_widget_get_foreground_pid();
1900 vcdc_send_error_to_manager(vcd_client_manager_get_pid(), VCD_ERROR_OPERATION_FAILED, "voice_framework.error.vcfw.collect_command_fail");
1901 return VCD_ERROR_OPERATION_FAILED;
1904 /* 3. Set command to engine */
1905 ret = vcd_engine_set_commands();
1907 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to set commands : %d", ret);
1908 /* Send error cb to manager */
1909 int pid = vcd_client_widget_get_foreground_pid();
1911 vcdc_send_error_to_manager(vcd_client_manager_get_pid(), VCD_ERROR_OPERATION_FAILED, "voice_framework.error.engine.set_commands_fail");
1912 return VCD_ERROR_OPERATION_FAILED;
1915 SLOG(LOG_ERROR, TAG_VCD, "[Server Success] Set command");
1917 bool stop_by_silence = true;
1918 if (VCD_RECOGNITION_MODE_MANUAL == vcd_client_get_recognition_mode()) {
1919 stop_by_silence = false;
1922 vcd_client_manager_set_result_text(NULL);
1924 /* 4. start recognition */
1925 ret = vcd_engine_recognize_start(stop_by_silence);
1927 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to start recognition : result(%d)", ret);
1928 /* Send error cb to manager */
1929 int pid = vcd_client_widget_get_foreground_pid();
1931 vcdc_send_error_to_manager(vcd_client_manager_get_pid(), ret, "voice_framework.error.engine.start_fail");
1935 SLOG(LOG_ERROR, TAG_VCD, "[Server Success] Start engine");
1938 /* 5. recorder start */
1939 ret = vcd_recorder_start();
1941 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to start recorder : result(%d)", ret);
1942 vcd_engine_recognize_cancel();
1943 /* Send error cb to manager */
1944 int pid = vcd_client_widget_get_foreground_pid();
1946 vcdc_send_error_to_manager(vcd_client_manager_get_pid(), VCD_ERROR_OPERATION_FAILED, "voice_framework.error.vcfw.send_rc_fail");
1951 vcd_config_set_service_state(VCD_STATE_RECORDING);
1952 vcdc_send_service_state(VCD_STATE_RECORDING);
1954 SLOG(LOG_ERROR, TAG_VCD, "[Server Success] Start recognition(%d)", stop_by_silence);
1956 return VCD_ERROR_NONE;
1959 static Eina_Bool __vcd_request_show_tooltip(void *data)
1961 int pid = vcd_client_widget_get_foreground_pid();
1963 SLOG(LOG_ERROR, TAG_VCD, "[Server] Request tooltip show and widget command, show(%d)", (bool)data);
1964 vcdc_send_show_tooltip(pid, (bool)data);
1970 int vcd_server_mgr_start(vcd_recognition_mode_e recognition_mode, bool exclusive_cmd, bool start_by_client)
1972 /* 1. check current state */
1973 vcd_state_e state = vcd_config_get_service_state();
1975 if (VCD_STATE_READY != state && VCD_STATE_SYNTHESIZING != state) {
1976 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Current state is not ready and not synthesizine, state(%d)", state);
1977 return VCD_ERROR_INVALID_STATE;
1979 if (-1 == vcd_client_manager_get_pid()) {
1980 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Manager is NOT available.");
1981 return VCD_ERROR_OPERATION_FAILED;
1983 __reset_waiting_for_widget_recording();
1985 SLOG(LOG_ERROR, TAG_VCD, "[Server] set recognition mode = %d", recognition_mode);
1986 vcd_client_set_recognition_mode(recognition_mode);
1988 if (false == exclusive_cmd) {
1989 vcd_client_update_foreground_pid();
1990 /* Notify show tooltip */
1991 if (1 == vcd_config_get_command_type_enabled(VC_COMMAND_TYPE_WIDGET)) {
1992 int pid = vcd_client_widget_get_foreground_pid();
1994 SLOG(LOG_ERROR, TAG_VCD, "[Server] Request tooltip show and widget command");
1995 ecore_timer_add(0, __vcd_request_show_tooltip, (void*)true);
1997 __set_waiting_for_widget_recording(pid);
1998 return VCD_ERROR_NONE;
2002 vcd_client_manager_set_exclusive(exclusive_cmd);
2006 if (true == start_by_client) {
2007 /* Get foreground pid */
2008 if (0 != vcd_config_get_foreground(&fg_pid)) {
2009 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to get foreground");
2012 /* Set client exclusive option */
2013 if (0 != vcd_client_set_exclusive_command(fg_pid)) {
2014 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to set exclusive command");
2018 SLOG(LOG_ERROR, TAG_VCD, "[Server] start internal recognition");
2020 int ret = __start_internal_recognition();
2022 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to start recognition : %d", ret);
2026 if (true == start_by_client) {
2027 vcd_client_unset_exclusive_command(fg_pid);
2030 SLOG(LOG_ERROR, TAG_VCD, "[Server Success] start internal recognition");
2031 return VCD_ERROR_NONE;
2034 int vcd_server_mgr_stop()
2036 /* 1. Check current state is recording */
2037 if (VCD_STATE_RECORDING != vcd_config_get_service_state()) {
2038 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Current state is not recording");
2039 return VCD_ERROR_INVALID_STATE;
2041 if (-1 == vcd_client_manager_get_pid()) {
2042 SLOG(LOG_INFO, TAG_VCD, "[Server] Manager is NOT available.");
2043 return VCD_ERROR_OPERATION_FAILED;
2045 SLOG(LOG_ERROR, TAG_VCD, "[Server] stop internal recognition");
2048 /* 2. Stop recorder */
2049 vcd_recorder_stop();
2052 /* 3. Stop engine recognition */
2053 int ret = vcd_engine_recognize_stop();
2055 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to stop recognition : %d", ret);
2058 /* 4. Set original mode */
2059 vcd_config_set_service_state(VCD_STATE_PROCESSING);
2060 vcdc_send_service_state(VCD_STATE_PROCESSING);
2062 SLOG(LOG_ERROR, TAG_VCD, "[Server Success] stop internal recognition");
2063 return VCD_ERROR_NONE;
2066 int vcd_server_mgr_cancel()
2068 if (-1 == vcd_client_manager_get_pid()) {
2069 SLOG(LOG_ERROR, TAG_VCD, "[Server] Manager is NOT available.");
2070 return VCD_ERROR_OPERATION_FAILED;
2073 if (g_restart_timer != NULL) {
2074 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Delete restart engine timer");
2075 ecore_timer_del(g_restart_timer);
2076 g_restart_timer = NULL;
2079 /* 1. Check current state */
2080 vcd_state_e state = vcd_config_get_service_state();
2081 if (VCD_STATE_READY == state) {
2082 SLOG(LOG_INFO, TAG_VCD, "[Server] Current state is READY");
2083 vcd_recorder_stop();
2085 if (false == vcd_client_manager_get_exclusive()) {
2086 if (1 == vcd_config_get_command_type_enabled(VC_COMMAND_TYPE_WIDGET)) {
2087 int pid = vcd_client_widget_get_foreground_pid();
2089 SLOG(LOG_INFO, TAG_VCD, "[Server] Request tooltip hide");
2090 ecore_timer_add(0, __vcd_request_show_tooltip, (void*)false);
2095 vcdc_send_service_state(VCD_STATE_READY);
2096 return VCD_ERROR_NONE;
2098 SLOG(LOG_ERROR, TAG_VCD, "[Server] cancel internal recognition");
2101 /* 2. Stop recorder */
2102 vcd_recorder_stop();
2105 /* 3. Cancel engine */
2106 int ret = vcd_engine_recognize_cancel();
2108 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Fail to cancel : %d", ret);
2111 if (false == vcd_client_manager_get_exclusive()) {
2112 if (1 == vcd_config_get_command_type_enabled(VC_COMMAND_TYPE_WIDGET)) {
2113 int pid = vcd_client_widget_get_foreground_pid();
2115 SLOG(LOG_INFO, TAG_VCD, "[Server] Request tooltip hide");
2116 ecore_timer_add(0, __vcd_request_show_tooltip, (void*)false);
2120 vcd_client_manager_set_exclusive(false);
2124 vcd_config_set_service_state(VCD_STATE_READY);
2125 vcdc_send_service_state(VCD_STATE_READY);
2127 SLOG(LOG_ERROR, TAG_VCD, "[Server Success] cancel internal recognition");
2128 return VCD_ERROR_NONE;
2132 int vcd_server_mgr_result_select()
2134 __vcd_send_selected_result(NULL);
2136 return VCD_ERROR_NONE;
2139 int vcd_server_mgr_set_domain(int pid, const char* domain)
2141 /* check if pid is valid */
2142 if (false == vcd_client_manager_is_valid(pid)) {
2143 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] The manager pid(%d) is NOT valid", pid);
2144 return VCD_ERROR_INVALID_PARAMETER;
2147 vcd_state_e state = vcd_config_get_service_state();
2148 if (VCD_STATE_READY != state) {
2149 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Current state is not ready");
2150 return VCD_ERROR_INVALID_STATE;
2153 /* Set domain to engine */
2154 int ret = vcd_engine_set_domain(pid, domain);
2156 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to set domain : %d", ret);
2158 SLOG(LOG_INFO, TAG_VCD, "[Server SUCCESS] Set domain");
2164 int vcd_server_mgr_set_private_data(int pid, const char* key, const char* data)
2166 /* check if pid is valid */
2167 if (false == vcd_client_manager_is_valid(pid)) {
2168 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] The manager pid(%d) is NOT valid", pid);
2169 return VCD_ERROR_INVALID_PARAMETER;
2172 vcd_state_e state = vcd_config_get_service_state();
2173 if (VCD_STATE_READY != state) {
2174 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Current state is not ready");
2175 return VCD_ERROR_INVALID_STATE;
2178 /* Set private data to engine */
2179 int ret = vcd_engine_set_private_data(pid, key, data);
2181 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to set private data : %d", ret);
2183 SLOG(LOG_INFO, TAG_VCD, "[Server SUCCESS] Set private data");
2189 int vcd_server_mgr_get_private_data(int pid, const char* key, char** data)
2191 /* check if pid is valid */
2192 if (false == vcd_client_manager_is_valid(pid)) {
2193 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] The manager pid(%d) is NOT valid", pid);
2194 return VCD_ERROR_INVALID_PARAMETER;
2196 vcd_state_e state = vcd_config_get_service_state();
2197 if (VCD_STATE_READY != state) {
2198 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Current state is not ready");
2199 return VCD_ERROR_INVALID_STATE;
2202 /* Get private data to engine */
2203 int ret = vcd_engine_get_private_data(pid, key, data);
2205 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to get private data : %d", ret);
2207 SLOG(LOG_INFO, TAG_VCD, "[Server SUCCESS] Set private data");
2213 int vcd_server_mgr_send_specific_engine_request(int pid, const char* engine_app_id, const char* event, const char* request)
2215 /* check if pid is valid */
2216 if (false == vcd_client_manager_is_valid(pid)) {
2217 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] The manager pid(%d) is NOT valid", pid);
2218 return VCD_ERROR_INVALID_PARAMETER;
2220 vcd_state_e state = vcd_config_get_service_state();
2221 if (VCD_STATE_READY != state && VCD_STATE_SYNTHESIZING != state) {
2222 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Current state is not ready and not synthesizing, state(%d)", state);
2223 return VCD_ERROR_INVALID_STATE;
2226 /* Get private data to engine */
2227 int ret = vcd_engine_send_specific_engine_request(engine_app_id, event, request);
2229 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to set specific engine request : %d", ret);
2231 SLOG(LOG_INFO, TAG_VCD, "[Server SUCCESS] Set specific engine request ");
2237 int vcd_server_mgr_do_action(int pid, int type, const char* action)
2241 /* check if pid is valid */
2242 if (false == vcd_client_manager_is_valid(pid)) {
2243 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] The manager pid(%d) is NOT valid", pid);
2244 return VCD_ERROR_INVALID_PARAMETER;
2247 vcd_state_e state = vcd_config_get_service_state();
2248 if (VCD_STATE_READY != state && VCD_STATE_SYNTHESIZING != state) {
2249 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Current state is not ready and not synthesizing, state(%d)", state);
2250 return VCD_ERROR_INVALID_STATE;
2253 /* Request do action to engine */
2254 if (VCD_SEND_EVENT_TYPE_TEXT == type)
2255 ret = vcd_engine_process_text(pid, action);
2256 else if (VCD_SEND_EVENT_TYPE_LIST_EVENT == type)
2257 ret = vcd_engine_process_list_event(pid, action);
2258 else if (VCD_SEND_EVENT_TYPE_HAPTIC_EVENT == type)
2259 ret = vcd_engine_process_haptic_event(pid, action);
2262 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to process do action : %d", ret);
2264 vcd_config_set_service_state(VCD_STATE_PROCESSING);
2265 vcdc_send_service_state(VCD_STATE_PROCESSING);
2266 SLOG(LOG_INFO, TAG_VCD, "[Server SUCCESS] Process do action");
2272 int vcd_server_mgr_set_disabled_command_type(int pid, int disabled_cmd_type)
2276 /* check if pid is valid */
2277 if (false == vcd_client_manager_is_valid(pid)) {
2278 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] The manager pid(%d) is NOT valid", pid);
2279 return VCD_ERROR_INVALID_PARAMETER;
2282 vcd_state_e state = vcd_config_get_service_state();
2283 if (VCD_STATE_READY != state) {
2284 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Current state is not ready");
2285 return VCD_ERROR_INVALID_STATE;
2288 ret = vcd_config_set_disabled_command_type(disabled_cmd_type);
2290 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to set command type");
2292 SLOG(LOG_ERROR, TAG_VCD, "[Server] Set command type(%d)", disabled_cmd_type);
2299 /* for TTS feedback */
2300 int vcd_server_mgr_start_feedback(void)
2302 /* check current state */
2303 /* not Recording??? */
2305 if (-1 == vcd_client_manager_get_pid()) {
2306 SLOG(LOG_ERROR, TAG_VCD, "[Server] Manager is NOT available");
2307 return VCD_ERROR_OPERATION_FAILED;
2310 SLOG(LOG_INFO, TAG_VCD, "[Server] start TTS feedback");
2312 /* check there is TTS buffer to be spoken */
2314 return VCD_ERROR_NONE;
2317 int vcd_server_mgr_stop_feedback(void)
2319 /* check current state */
2320 /* not Recording??? */
2322 if (-1 == vcd_client_manager_get_pid()) {
2323 SLOG(LOG_ERROR, TAG_VCD, "[Server] Manager is NOT available");
2324 return VCD_ERROR_OPERATION_FAILED;
2327 SLOG(LOG_INFO, TAG_VCD, "[Server] stop TTS feedback");
2329 return VCD_ERROR_NONE;
2332 int vcd_server_mgr_send_audio_streaming(int pid, int event, const char* buffer, unsigned int len)
2334 SLOG(LOG_INFO, TAG_VCD, "[DEBUG] Send Audio Streaming from Multi-assistant. event(%d), buffer(%p), len(%d)", event, &buffer, len);
2337 if (VCD_AUDIO_STREAMING_EVENT_START == event) {
2338 ret = vcd_recorder_start_streaming();
2340 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to start streaming, ret(%d)", ret);
2345 ret = vcd_recorder_send_streaming((const void*)buffer, (const unsigned int)len);
2347 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to start streaming, ret(%d)", ret);
2351 if (VCD_AUDIO_STREAMING_EVENT_FINISH == event) {
2352 ret = vcd_recorder_stop_streaming();
2354 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to stop streaming, ret(%d)", ret);
2359 return VCD_ERROR_NONE;
2362 int vcd_server_mgr_change_system_volume(int pid, vcd_system_volume_event_e system_volume_event)
2364 SLOG(LOG_INFO, TAG_VCD, "[DEBUG] change system volume, system volume event(%d)", system_volume_event);
2367 if (VCD_SYSTEM_VOLUME_EVENT_CHANGE == system_volume_event) {
2368 ret = vcd_recorder_change_system_volume();
2370 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to change system volume, ret(%d)", ret);
2373 } else if (VCD_SYSTEM_VOLUME_EVENT_RECOVER == system_volume_event) {
2374 ret = vcd_recorder_recover_system_volume();
2376 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to recover system volume, ret(%d)", ret);
2386 * VC Server Functions for Client
2388 int vcd_server_initialize(int pid)
2390 if (false == vcd_engine_is_available_engine()) {
2391 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] No Engine");
2392 return VCD_ERROR_ENGINE_NOT_FOUND;
2395 /* check if pid is valid */
2396 if (true == vcd_client_is_available(pid)) {
2397 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] The pid is already exist");
2398 return VCD_ERROR_NONE;
2401 /* Add client information to client manager */
2402 if (0 != vcd_client_add(pid)) {
2403 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to add client info");
2404 return VCD_ERROR_OPERATION_FAILED;
2407 SLOG(LOG_INFO, TAG_VCD, "[Server Success] Client Initialize : pid(%d)", pid);
2409 return VCD_ERROR_NONE;
2412 int vcd_server_finalize(int pid)
2414 /* check if pid is valid */
2415 if (false == vcd_client_is_available(pid)) {
2416 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] pid is NOT valid ");
2417 return VCD_ERROR_INVALID_PARAMETER;
2420 /* Remove client information */
2421 if (0 != vcd_client_delete(pid)) {
2422 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Fail to delete client");
2425 if (0 == vcd_client_get_ref_count()) {
2426 SLOG(LOG_INFO, TAG_VCD, "[Server] Connected client list is empty");
2427 ecore_timer_add(0, __finalize_quit_ecore_loop, NULL);
2430 SLOG(LOG_INFO, TAG_VCD, "[Server Success] Client Finalize : pid(%d)", pid);
2432 return VCD_ERROR_NONE;
2435 int vcd_server_set_command(int pid, vc_cmd_type_e cmd_type)
2437 /* check if pid is valid */
2438 if (false == vcd_client_is_available(pid)) {
2439 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] pid is NOT valid ");
2440 return VCD_ERROR_INVALID_PARAMETER;
2443 if (0 != vcd_client_set_command_type(pid, cmd_type)) {
2444 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to set command type : pid(%d), cmd_type(%d)", pid, cmd_type);
2445 return VCD_ERROR_OPERATION_FAILED;
2448 return VCD_ERROR_NONE;
2451 int vcd_server_unset_command(int pid, vc_cmd_type_e cmd_type)
2453 /* check if pid is valid */
2454 if (false == vcd_client_is_available(pid)) {
2455 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] pid is NOT valid ");
2456 return VCD_ERROR_INVALID_PARAMETER;
2459 if (0 != vcd_client_unset_command_type(pid, cmd_type)) {
2460 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to unset command type : pid(%d), cmd_type(%d)", pid, cmd_type);
2461 return VCD_ERROR_OPERATION_FAILED;
2464 return VCD_ERROR_NONE;
2467 int vcd_server_set_foreground(int pid, bool value)
2469 /* check if pid is valid */
2470 if (false == vcd_client_is_available(pid) && false == vcd_client_widget_is_available(pid)) {
2471 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] pid is NOT valid ");
2472 return VCD_ERROR_INVALID_PARAMETER;
2475 if (0 != vcd_config_set_foreground(pid, value)) {
2476 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to set foreground : pid(%d), value(%d)", pid, value);
2477 return VCD_ERROR_OPERATION_FAILED;
2480 return VCD_ERROR_NONE;
2483 static int __vcd_server_launch_manager_app()
2486 bool running = false;
2489 ret = vcd_client_manager_get_appid(&appid);
2490 if (0 != ret || NULL == appid) {
2491 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to get manager appid");
2492 return VCD_ERROR_OPERATION_FAILED;
2494 ret = app_manager_is_running(appid, &running);
2496 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to check running with appid(%s)", appid);
2499 return VCD_ERROR_OPERATION_FAILED;
2501 if (false == running) {
2502 int tmp_ret = __vcd_is_package_installed(appid);
2503 if (false == tmp_ret) {
2504 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] manager app is not installed, appid(%s)", appid);
2506 ret = __vcd_activate_app_by_appcontrol(appid);
2508 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to activate app");
2513 SLOG(LOG_ERROR, TAG_VCD, "Launch vc manager app: appid(%s)", appid);
2516 ret = __vcd_resume_app(appid);
2518 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to resume app");
2523 SLOG(LOG_ERROR, TAG_VCD, "Resume vc manager app: appid(%s)", appid);
2529 return VCD_ERROR_NONE;
2532 int vcd_server_set_server_dialog(int pid, const char* app_id, const char* credential)
2534 /* check if pid is valid */
2535 if (false == vcd_client_is_available(pid)) {
2536 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] pid is NOT valid ");
2537 return VCD_ERROR_INVALID_PARAMETER;
2540 int ret = vcd_engine_set_server_dialog(app_id, credential);
2542 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to set server dialog, pid(%d), app_id(%s), ret(%d)", pid, app_id, ret);
2543 vcd_client_set_server_dialog(pid, false);
2546 SLOG(LOG_ERROR, TAG_VCD, "[Success] Set server dialog, pid(%d), app_id(%s)", pid, app_id);
2548 if (0 != strncmp(credential, "#NULL", strlen(credential))) {
2549 ret = vcd_client_set_server_dialog(pid, true);
2551 SLOG(LOG_INFO, TAG_VCD, "[Server] Set to true for server dialog, app_id(%s)", app_id);
2553 ret = vcd_client_set_server_dialog(pid, false);
2555 SLOG(LOG_INFO, TAG_VCD, "[Server] Set to false for server dialog, app_id(%s)", app_id);
2558 return VCD_ERROR_NONE;
2561 int vcd_server_dialog(int pid, const char* disp_text, const char* utt_text, int continuous)
2563 /* check if pid is valid */
2564 if (false == vcd_client_is_available(pid) && false == vcd_client_widget_is_available(pid)) {
2565 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] pid is NOT valid ");
2566 return VCD_ERROR_INVALID_PARAMETER;
2569 bool is_server_dialog = false;
2570 int ret = vcd_client_get_server_dialog(pid, &is_server_dialog);
2572 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to get server dialog, pid(%d), ret(%d)", pid, ret);
2575 if (true == is_server_dialog) {
2576 /* ++ Request tts event to engine */
2578 /* -- Request tts event to engine */
2580 ret = __vcd_server_launch_manager_app();
2582 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);
2586 ret = vcdc_send_dialog(vcd_client_manager_get_pid(), pid, disp_text, utt_text, continuous);
2588 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);
2592 return VCD_ERROR_NONE;
2595 int vcd_server_is_system_command_valid(int pid, bool* is_sys_cmd_valid)
2597 /* check if pid is valid */
2598 if (false == vcd_client_is_available(pid) && false == vcd_client_widget_is_available(pid)) {
2599 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] pid is NOT valid ");
2600 return VCD_ERROR_INVALID_PARAMETER;
2603 /* check if system command is valid */
2604 if (true == vcd_client_manager_is_system_command_valid(vcd_client_manager_get_pid()))
2605 *is_sys_cmd_valid = true;
2607 *is_sys_cmd_valid = false;
2609 return VCD_ERROR_NONE;
2612 static void __start_tts_request_thread(void* data, Ecore_Thread* thread)
2614 SLOG(LOG_INFO, TAG_VCD, "[SUCCESS] Start tts request thread");
2615 vc_tts_text_data_s* tts_text_data = NULL;
2621 /* Get tts text data */
2622 ret = vcd_data_get_first_tts_text_data(&tts_text_data);
2623 if (0 != ret || NULL == tts_text_data) {
2625 if (0 >= vcd_data_get_tts_text_data_size()) {
2626 SLOG(LOG_INFO, TAG_VCD, "[DEBUG] No tts text data");
2629 SLOG(LOG_INFO, TAG_VCD, "[INFO] tts text data is just incoming");
2634 vcd_state_e state = vcd_config_get_service_state();
2635 if (VCD_STATE_READY != state) {
2636 if (0 == cnt++ % 10)
2637 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Waiting to request TTS, state(%d)", state);
2644 /* Set service state to synthesizing */
2645 vcd_config_set_service_state(VCD_STATE_SYNTHESIZING);
2647 /* Set current uid */
2648 g_current_tts_uid = tts_text_data->uid;
2650 /* Request tts to engine */
2651 ret = vcd_engine_request_tts(tts_text_data->pid, tts_text_data->utt_id, tts_text_data->text, tts_text_data->language);
2653 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to request tts : %d", ret);
2655 SLOG(LOG_INFO, TAG_VCD, "[Server SUCCESS] request tts, uid(%u) pid(%d), text(%s), language(%s), utt_id(%d)",
2656 tts_text_data->uid, tts_text_data->pid, tts_text_data->text, tts_text_data->language, tts_text_data->utt_id);
2658 /* clear tts text data after use */
2659 vcd_data_clear_tts_text_data(&tts_text_data);
2663 static void __end_tts_request_thread(void* data, Ecore_Thread* thread)
2665 SLOG(LOG_INFO, TAG_VCD, "[SUCCESS] End tts request thread");
2666 g_tts_thread = NULL;
2669 int vcd_server_request_tts(int pid, const char* text, const char* language, int to_vcm, int* utt_id)
2671 /* check if pid is valid */
2672 if (false == vcd_client_is_available(pid)) {
2673 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] pid is NOT valid ");
2674 return VCD_ERROR_INVALID_PARAMETER;
2677 vcd_state_e state = vcd_config_get_service_state();
2678 if (VCD_STATE_READY != state && VCD_STATE_SYNTHESIZING != state) {
2679 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Current state is not ready, state(%d)", state);
2680 return VCD_ERROR_INVALID_STATE;
2683 unsigned int tts_uid = VC_INVALID_TTS_UID;
2684 g_current_utt_id = (g_current_utt_id + 1) % 1000;
2685 *utt_id = g_current_utt_id;
2687 tts_uid = (unsigned int)pid * 1000u + (unsigned int)g_current_utt_id;
2689 tts_uid = (unsigned int)vcd_client_manager_get_pid() * 1000u + (unsigned int)g_current_utt_id;
2691 SLOG(LOG_INFO, TAG_VCD, "[Server INFO] pid(%d), text(%s), language(%s), to_vcm(%d), ", pid, text, language, to_vcm);
2692 SLOG(LOG_INFO, TAG_VCD, "[Server INFO] current_uid(%u), current_utt_id(%d)", tts_uid, g_current_utt_id);
2694 vc_tts_text_data_s* tts_text_data;
2695 tts_text_data = (vc_tts_text_data_s*)calloc(1, sizeof(vc_tts_text_data_s));
2696 if (!tts_text_data) {
2697 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to callocate memory ");
2698 return VCD_ERROR_OUT_OF_MEMORY;
2700 tts_text_data->uid = tts_uid;
2701 tts_text_data->pid = pid;
2702 tts_text_data->utt_id = g_current_utt_id;
2703 tts_text_data->text = strdup(text);
2704 tts_text_data->language = strdup(language);
2706 int ret = vcd_data_add_tts_text_data(tts_text_data);
2708 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to add tts text data : %d", ret);
2711 bool is_canceled = ecore_thread_check(g_tts_thread);
2712 if (NULL == g_tts_thread || TRUE == is_canceled) {
2713 SLOG(LOG_INFO, TAG_VCD, "[Server INFO] ecore thread run : start_tts_request_thread ");
2714 g_tts_thread = ecore_thread_run(__start_tts_request_thread, __end_tts_request_thread, NULL, NULL);
2717 return VCD_ERROR_NONE;
2720 int vcd_server_cancel_tts(int pid, int utt_id)
2722 /* check if pid is valid */
2723 if (false == vcd_client_is_available(pid)) {
2724 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] pid is NOT valid ");
2725 return VCD_ERROR_INVALID_PARAMETER;
2728 vcd_state_e state = vcd_config_get_service_state();
2729 if (VCD_STATE_READY != state && VCD_STATE_SYNTHESIZING != state) {
2730 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Current state is not ready, state(%d)", state);
2731 return VCD_ERROR_INVALID_STATE;
2734 vc_tts_text_data_s* tts_text_data = NULL;
2736 unsigned int tts_uid = (unsigned int)pid * 1000u + (unsigned int)utt_id;
2737 int ret = vcd_data_get_tts_text_data(tts_uid, &tts_text_data);
2739 SLOG(LOG_WARN, TAG_VCD, "[Server WARN] No data in vcd tts text queue");
2741 if (tts_text_data) {
2742 SLOG(LOG_INFO, TAG_VCD, "[Server] Clear tts text data, pid(%d), utt_id(%d), text(%s)", pid, utt_id, tts_text_data->text);
2743 vcd_data_clear_tts_text_data(&tts_text_data);
2744 tts_text_data = NULL;
2746 SLOG(LOG_INFO, TAG_VCD, "[Server] Clear tts text data, pid(%d), utt_id(%d), text(nullptr)", pid, utt_id);
2750 /* Request tts to engine */
2751 ret = vcd_engine_cancel_tts(pid, utt_id);
2753 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to cancel tts : %d", ret);
2755 SLOG(LOG_INFO, TAG_VCD, "[Server SUCCESS] request tts, pid(%d), utt_id(%d)", pid, utt_id);
2758 /* Set service state */
2759 vcd_config_set_service_state(VCD_STATE_READY);
2761 return VCD_ERROR_NONE;
2764 int vcd_server_get_tts_audio_format(int pid, int* rate, int* channel, int* audio_type)
2766 /* check if pid is valid */
2767 if (false == vcd_client_is_available(pid)) {
2768 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] pid is NOT valid ");
2769 return VCD_ERROR_INVALID_PARAMETER;
2772 vcd_state_e state = vcd_config_get_service_state();
2773 if (VCD_STATE_READY != state && VCD_STATE_SYNTHESIZING != state) {
2774 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Current state is not ready and not synthesizing, state(%d)", state);
2775 return VCD_ERROR_INVALID_STATE;
2778 /* Request tts to engine */
2779 int ret = vcd_engine_get_tts_audio_format(rate, channel, audio_type);
2781 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to get tts audio format : %d", ret);
2783 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);
2790 int vcd_server_set_exclusive_command(int pid, bool value)
2792 /* check if pid is valid */
2793 if (false == vcd_client_is_available(pid)) {
2794 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] pid is NOT valid ");
2795 return VCD_ERROR_INVALID_PARAMETER;
2798 if (true == value) {
2799 if (0 != vcd_client_set_exclusive_command(pid)) {
2800 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to set exclusive command : pid(%d)", pid);
2801 return VCD_ERROR_OPERATION_FAILED;
2804 if (0 != vcd_client_unset_exclusive_command(pid)) {
2805 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to unset exclusive command : pid(%d)", pid);
2806 return VCD_ERROR_OPERATION_FAILED;
2810 return VCD_ERROR_NONE;
2813 int vcd_server_request_start(int pid, bool stop_by_silence)
2815 /* check if pid is valid */
2816 if (false == vcd_client_is_available(pid)) {
2817 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] pid(%d) is NOT foreground client", pid);
2818 return VCD_ERROR_INVALID_PARAMETER;
2822 /* Check current state */
2823 vcd_state_e state = vcd_config_get_service_state();
2825 /* Service state should be ready */
2826 if (VCD_STATE_READY != state) {
2827 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Current state is not Ready : pid(%d)", pid);
2828 return VCD_ERROR_INVALID_STATE;
2831 if (-1 != vcd_client_manager_get_pid()) {
2832 /* Check current pid is valid */
2833 if (false == vcd_client_manager_check_demandable_client(pid)) {
2834 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Current client is NOT available : pid(%d)", pid);
2835 return VCD_ERROR_INVALID_PARAMETER;
2839 ret = vcd_server_mgr_start(stop_by_silence, false);
2841 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Fail to start recognition");
2842 return VCD_ERROR_INVALID_PARAMETER;
2845 return VCD_ERROR_NONE;
2848 int vcd_server_request_stop(int pid)
2851 /* Check current state */
2852 vcd_state_e state = vcd_config_get_service_state();
2854 /* Service state should be ready */
2855 if (VCD_STATE_RECORDING != state) {
2856 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Current state is not Recording : pid(%d)", pid);
2857 return VCD_ERROR_INVALID_STATE;
2860 if (-1 != vcd_client_manager_get_pid()) {
2861 /* Check current pid is valid */
2862 if (false == vcd_client_manager_check_demandable_client(pid)) {
2863 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Current client is NOT available : pid(%d)", pid);
2864 return VCD_ERROR_INVALID_PARAMETER;
2868 ret = vcd_server_mgr_stop();
2870 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Fail to start recognition");
2871 return VCD_ERROR_OPERATION_FAILED;
2874 return VCD_ERROR_NONE;
2877 int vcd_server_request_cancel(int pid)
2880 /* Check current state */
2881 vcd_state_e state = vcd_config_get_service_state();
2883 /* Service state should be recording or processing */
2884 if (VCD_STATE_RECORDING != state && VCD_STATE_PROCESSING != state) {
2885 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Current state is not Recording or Processing : pid(%d)", pid);
2886 return VCD_ERROR_INVALID_STATE;
2889 if (-1 != vcd_client_manager_get_pid()) {
2890 /* Check current pid is valid */
2891 if (false == vcd_client_manager_check_demandable_client(pid)) {
2892 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Current client is NOT available : pid(%d)", pid);
2893 return VCD_ERROR_INVALID_PARAMETER;
2897 ret = vcd_server_mgr_cancel();
2899 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Fail to start recognition");
2900 return VCD_ERROR_OPERATION_FAILED;
2903 return VCD_ERROR_NONE;
2908 * VC Server Functions for Widget lib
2910 int vcd_server_widget_initialize(int pid)
2912 if (false == vcd_engine_is_available_engine()) {
2913 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] No Engine");
2914 return VCD_ERROR_ENGINE_NOT_FOUND;
2917 /* check if pid is valid */
2918 if (true == vcd_client_widget_is_available(pid)) {
2919 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] The pid is already exist");
2920 return VCD_ERROR_NONE;
2923 /* Add client information to client manager */
2924 if (0 != vcd_client_widget_add(pid)) {
2925 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to add client info");
2926 return VCD_ERROR_OPERATION_FAILED;
2929 SLOG(LOG_INFO, TAG_VCD, "[Server Success] Initialize widget : pid(%d)", pid);
2931 return VCD_ERROR_NONE;
2934 static void __vcd_server_widget_start_recording(void *data)
2936 SLOG(LOG_ERROR, TAG_VCD, "[Server INFO] start recording");
2938 if (0 != __start_internal_recognition()) {
2939 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to start recognition");
2943 int vcd_server_widget_finalize(int pid)
2945 /* check if pid is valid */
2946 if (false == vcd_client_widget_is_available(pid)) {
2947 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] pid is NOT valid ");
2948 if (0 == vcd_client_get_ref_count()) {
2949 SLOG(LOG_ERROR, TAG_VCD, "[Server] connected client list is empty, vc-service will be terminated");
2950 ecore_timer_add(0, __finalize_quit_ecore_loop, NULL);
2951 return VCD_ERROR_NONE;
2953 return VCD_ERROR_INVALID_PARAMETER;
2956 /* Remove client information */
2957 if (0 != vcd_client_widget_delete(pid)) {
2958 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Fail to delete client");
2961 if (0 == vcd_client_get_ref_count()) {
2962 SLOG(LOG_ERROR, TAG_VCD, "[Server] connected client list is empty, vc-service will be terminated");
2963 ecore_timer_add(0, __finalize_quit_ecore_loop, NULL);
2964 return VCD_ERROR_NONE;
2967 bool is_waiting = false;
2968 if (0 != vcd_client_widget_get_waiting_for_recording(pid, &is_waiting)) {
2969 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Fail to get waiting to recording");
2972 if (true == is_waiting) {
2973 SLOG(LOG_ERROR, TAG_VCD, "[Server INFO] invoke to start recording");
2974 ecore_main_loop_thread_safe_call_async(__vcd_server_widget_start_recording, NULL);
2976 return VCD_ERROR_NONE;
2979 int vcd_server_widget_start_recording(int pid, bool widget_command)
2981 /* check if pid is valid */
2982 if (false == vcd_client_widget_is_available(pid)) {
2983 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] pid is NOT valid ");
2984 return VCD_ERROR_INVALID_PARAMETER;
2988 if (0 != vcd_client_widget_get_waiting_for_recording(pid, &waiting) || false == waiting) {
2989 SLOG(LOG_ERROR, TAG_VCD, "[Server] Server is not waiting for recording, pid(%d), waiting(%d)", pid, waiting);
2990 return VCD_ERROR_NONE;
2993 if (true == widget_command) {
2994 vcd_client_widget_set_command(pid);
2995 SLOG(LOG_INFO, TAG_VCD, "[Server] widget command is available");
2997 vcd_client_widget_unset_command(pid);
2998 SLOG(LOG_WARN, TAG_VCD, "[Server] widget command is NOT available");
3001 SLOG(LOG_ERROR, TAG_VCD, "[Server] start internal recognition : %d", widget_command);
3002 int ret = __start_internal_recognition();
3004 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to start recognition : %d", ret);
3005 ecore_timer_add(0, __vcd_request_show_tooltip, (void*)false);
3008 return VCD_ERROR_NONE;
3011 int vcd_server_widget_start(int pid, bool stop_by_silence)
3013 /* check if pid is valid */
3014 int fore_pid = vcd_client_widget_get_foreground_pid();
3015 if (pid != fore_pid) {
3016 SLOG(LOG_ERROR, TAG_VCD, "[Server] pid is NOT foreground");
3017 return VCD_ERROR_INVALID_PARAMETER;
3020 /* Check current state */
3021 vcd_state_e state = vcd_config_get_service_state();
3023 /* Service state should be ready */
3024 if (VCD_STATE_READY != state) {
3025 SLOG(LOG_INFO, TAG_VCD, "[Server] Current state is not Ready : pid(%d)", pid);
3026 return VCD_ERROR_INVALID_STATE;
3029 vcd_client_set_slience_detection(stop_by_silence);
3031 /* Notify show tooltip */
3032 ecore_timer_add(0, __vcd_request_show_tooltip, (void*)true);
3034 return VCD_ERROR_NONE;
3037 int vcd_server_widget_stop(int pid)
3039 /* check if pid is valid */
3040 int fore_pid = vcd_client_widget_get_foreground_pid();
3041 if (pid != fore_pid) {
3042 SLOG(LOG_ERROR, TAG_VCD, "[Server] pid is NOT foreground");
3043 return VCD_ERROR_INVALID_PARAMETER;
3047 /* Check current state */
3048 vcd_state_e state = vcd_config_get_service_state();
3050 /* Service state should be recording */
3051 if (VCD_STATE_RECORDING != state) {
3052 SLOG(LOG_ERROR, TAG_VCD, "[Server] Current service state is not Recording : pid(%d)", pid);
3053 return VCD_ERROR_INVALID_STATE;
3056 ret = vcd_server_mgr_stop();
3058 SLOG(LOG_ERROR, TAG_VCD, "[Server] Fail to start recognition");
3059 return VCD_ERROR_OPERATION_FAILED;
3062 return VCD_ERROR_NONE;
3065 int vcd_server_widget_cancel(int pid)
3067 /* check if pid is valid */
3068 int fore_pid = vcd_client_widget_get_foreground_pid();
3069 if (pid != fore_pid) {
3070 SLOG(LOG_ERROR, TAG_VCD, "[Server] pid is NOT foreground");
3071 return VCD_ERROR_INVALID_PARAMETER;
3075 /* Check current state */
3076 vcd_state_e state = vcd_config_get_service_state();
3078 /* Service state should be recording or processing */
3079 if (VCD_STATE_RECORDING != state && VCD_STATE_PROCESSING != state) {
3080 SLOG(LOG_ERROR, TAG_VCD, "[Server] Current state is not Recording or Processing : pid(%d)", pid);
3081 return VCD_ERROR_INVALID_STATE;
3084 ret = vcd_server_mgr_cancel();
3086 SLOG(LOG_ERROR, TAG_VCD, "[Server] Fail to cancel recognition : %d", ret);
3090 return VCD_ERROR_NONE;
3093 int vcd_server_widget_enable_asr_result(int pid, bool enable)
3096 ret = vcd_client_widget_set_asr_result_enabled(pid, enable);
3098 SLOG(LOG_ERROR, TAG_VCD, "[Server] Fail to enable asr result : %d", ret);
3104 int vcd_server_set_language(const char* language)
3106 int ret = VCD_ERROR_NONE;
3108 ret = vcd_config_set_default_language(language);
3110 SLOG(LOG_ERROR, TAG_VCD, "[Server] Fail to set language : %d", ret);
3114 ret = vcd_engine_set_current_language(language);
3116 SLOG(LOG_ERROR, TAG_VCD, "[Server] Fail to set language : %d", ret);
3123 * For engine service
3125 int vcd_get_foreach_command(vce_cmd_h vce_command, vce_command_cb callback, void* user_data)
3127 SLOG(LOG_INFO, TAG_VCD, "[Server] Get foreach command");
3129 if (NULL == callback) {
3130 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] input parameter is NULL");
3131 return VCD_ERROR_INVALID_PARAMETER;
3135 ret = vcd_engine_agent_get_foreach_command(vce_command, callback, user_data);
3137 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to get foreach command : ret(%d)", ret);
3143 int vcd_get_command_count(vce_cmd_h vce_command, int* count)
3145 SLOG(LOG_INFO, TAG_VCD, "[Server] Get command count");
3148 ret = vcd_engine_agent_get_command_count(vce_command, count);
3150 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to get command count : ret(%d)", ret);
3156 int vcd_get_audio_type(char** audio_type)
3158 SLOG(LOG_INFO, TAG_VCD, "[Server] Get audio type");
3161 ret = vcd_engine_agent_get_audio_type(audio_type);
3163 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to get audio type : ret(%d)", ret);
3169 int vcd_set_private_data(const char* key, const char* data)
3171 vcd_state_e state = vcd_config_get_service_state();
3173 if (VCD_STATE_READY != state) {
3174 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Current state(%d) is NOT 'READY'", state);
3175 return VCD_ERROR_INVALID_STATE;
3178 int ret = vcd_engine_agent_set_private_data(key, data);
3180 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to set private data to the manager client : ret(%d)", ret);
3182 SLOG(LOG_INFO, TAG_VCD, "[Server] Set private data to the manager client, key(%s), data(%s)", key, data);
3188 int vcd_get_private_data(const char* key, char** data)
3190 vcd_state_e state = vcd_config_get_service_state();
3192 if (VCD_STATE_READY != state) {
3193 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Current state(%d) is NOT 'READY'", state);
3194 return VCD_ERROR_INVALID_STATE;
3197 int ret = vcd_engine_agent_get_private_data(key, data);
3199 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to get private data from the manager client : ret(%d)", ret);
3201 SLOG(LOG_INFO, TAG_VCD, "[Server] Get private data from the manager client, key(%s), data(%s)", key, *data);
3207 int vcd_start_recording()
3209 SLOG(LOG_INFO, TAG_VCD, "[Server] Start recording");
3212 ret = vcd_engine_agent_start_recording();
3214 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to start recording : ret(%d)", ret);
3220 int vcd_stop_recording()
3222 SLOG(LOG_INFO, TAG_VCD, "[Server] Stop recording");
3225 ret = vcd_engine_agent_stop_recording();
3227 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to stop recording : ret(%d)", ret);
3233 int vcd_send_update_status(vce_update_event_e update_event, const char* msg)
3235 SLOG(LOG_INFO, TAG_VCD, "[Server] update status, update event(%d), msg(%s)", update_event, msg);
3238 if (VCE_UPDATE_EVENT_START == update_event) {
3239 if (VCD_STATE_RECORDING == vcd_config_get_service_state() || VCD_STATE_PROCESSING == vcd_config_get_service_state()) {
3240 ret = vcd_server_mgr_cancel();
3242 SLOG(LOG_ERROR, TAG_VCD, "[Server Error] Fail to cancel, ret(%d)", ret);
3246 vcd_config_set_service_state(VCD_STATE_UPDATING);
3247 vcdc_send_service_state(VCD_STATE_UPDATING);
3249 } else if (VCE_UPDATE_EVENT_FINISH == update_event) {
3250 vcd_config_set_service_state(VCD_STATE_READY);
3251 vcdc_send_service_state(VCD_STATE_READY);
3253 } else if (VCE_UPDATE_EVENT_FAIL == update_event) {
3254 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Update event : Fail - msg(%s)", msg);
3257 return VCD_ERROR_NONE;
3260 int vcd_set_private_data_set_cb(vce_private_data_set_cb callback_func)
3262 SLOG(LOG_INFO, TAG_VCD, "[Server] Set private data set cb");
3265 ret = vcd_engine_agent_set_private_data_set_cb(callback_func);
3267 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to set private data set cb : ret(%d)", ret);
3273 int vcd_set_private_data_requested_cb(vce_private_data_requested_cb callback_func)
3275 SLOG(LOG_INFO, TAG_VCD, "[Server] Set private data requested cb");
3278 ret = vcd_engine_agent_set_private_data_requested_cb(callback_func);
3280 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to set private data requested cb : ret(%d)", ret);
3286 int vcd_set_nlu_base_info_requested_cb(vce_nlu_base_info_requested_cb callback_func)
3288 SLOG(LOG_INFO, TAG_VCD, "[Server] Set nlu base info requested cb");
3291 ret = vcd_engine_agent_set_nlu_base_info_requested_cb(callback_func);
3293 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to set nlu base info requested cb : ret(%d)", ret);
3299 int vcd_set_specific_engine_request_cb(vce_specific_engine_request_cb callback_func)
3301 SLOG(LOG_INFO, TAG_VCD, "[Server] Set specific engine request cb");
3303 ret = vcd_engine_agent_set_specific_engine_request_cb(callback_func);
3305 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to set specific engine request cb : ret(%d)", ret);
3311 int vcd_set_request_tts_cb(vce_request_tts_cb callback_func, void* user_data)
3313 SLOG(LOG_INFO, TAG_VCD, "[Server] Set request tts cb");
3315 ret = vcd_engine_agent_set_request_tts_cb(callback_func, user_data);
3317 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to set request tts cb : ret(%d)", ret);
3323 int vcd_set_cancel_tts_cb(vce_cancel_tts_cb callback_func, void* user_data)
3325 SLOG(LOG_INFO, TAG_VCD, "[Server] Set cancel tts cb");
3327 ret = vcd_engine_agent_set_cancel_tts_cb(callback_func, user_data);
3329 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to set cancel tts cb : ret(%d)", ret);
3335 int vcd_set_tts_audio_format_request_cb(vce_tts_audio_format_request_cb callback_func, void* user_data)
3337 SLOG(LOG_INFO, TAG_VCD, "[Server] Set tts audio format request cb");
3339 ret = vcd_engine_agent_set_get_tts_audio_format_cb(callback_func, user_data);
3341 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to set tts audio format request : ret(%d)", ret);