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 <sound_manager.h>
24 #include "vc_cmd_db.h"
25 #include "vc_info_parser.h"
27 #include "vcd_server.h"
28 #include "vcd_server_data.h"
29 #include "vcd_client_data.h"
31 #include "vcd_engine_agent.h"
32 #include "vcd_config.h"
33 #include "vcd_recorder.h"
35 #include "vce_internal.h"
37 #include "voice_control_command_expand.h"
38 #include "voice_control_common.h"
40 #define CLIENT_CLEAN_UP_TIME 500
42 * VC Server static variable
44 static GList *g_proc_list = NULL;
46 static Ecore_Timer *g_restart_timer = NULL;
47 static Ecore_Timer *g_check_widget_client_timer = NULL;
48 static Ecore_Timer *g_check_client_timer = NULL;
50 static Ecore_Thread* g_tts_thread = NULL;
51 static int g_current_uid = -1;
52 static int g_current_utt_id = -1;
55 * @brief Enumerations of send event type.
58 VCD_SEND_EVENT_TYPE_TEXT, /**< send text event to vc engine*/
59 VCD_SEND_EVENT_TYPE_LIST_EVENT, /**< send list event to vc engine */
60 VCD_SEND_EVENT_TYPE_HAPTIC_EVENT /**< send haptic event to vc engine */
61 } vcd_send_event_type_e;
63 static int __vcd_server_launch_manager_app();
64 static int __start_internal_recognition();
67 * VC Server Internal Functions
69 static Eina_Bool __stop_by_silence(void *data)
71 SLOG(LOG_INFO, TAG_VCD, "@@@ Silence Detected ");
73 vcd_server_mgr_stop();
75 SLOG(LOG_DEBUG, TAG_VCD, "@@@");
79 static Eina_Bool __cancel_by_interrupt(void *data)
81 SLOG(LOG_INFO, TAG_VCD, "@@@ Cancel by interrupt");
83 vcd_server_mgr_cancel();
85 SLOG(LOG_DEBUG, TAG_VCD, "@@@");
89 static void __cancel_by_error(void *data)
91 SLOG(LOG_INFO, TAG_VCD, "@@@ Cancel by error");
93 vcd_server_mgr_cancel();
95 SLOG(LOG_DEBUG, TAG_VCD, "@@@");
99 static Eina_Bool __restart_engine(void *data)
101 SLOG(LOG_INFO, TAG_VCD, "@@@ Restart by no result");
103 g_restart_timer = NULL;
105 /* Restart recognition */
106 int ret = vcd_engine_recognize_start(true);
108 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to restart recognition : result(%d)", ret);
112 SLOG(LOG_INFO, TAG_VCD, "[Server Success] Start engine");
114 vcd_recognition_mode_e mode = vcd_client_get_recognition_mode();
115 if (VCD_RECOGNITION_MODE_RESTART_AFTER_REJECT == mode || VCD_RECOGNITION_MODE_RESTART_CONTINUOUSLY == mode) {
116 vcd_config_set_service_state(VCD_STATE_RECORDING);
117 vcdc_send_service_state(VCD_STATE_RECORDING);
120 SLOG(LOG_INFO, TAG_VCD, "[Server Success] Restart recognition");
122 SLOG(LOG_DEBUG, TAG_VCD, "@@@");
126 static int __server_recorder_callback(const void* data, const unsigned int length)
128 vcd_state_e state = vcd_config_get_service_state();
129 if (VCD_STATE_READY == state) {
130 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Ready state, but recording");
131 } else if (VCD_STATE_PROCESSING == state) {
135 vce_speech_detect_e speech_detected = VCE_SPEECH_DETECT_NONE;
138 ret = vcd_engine_recognize_audio(data, length, &speech_detected);
142 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to set recording data to engine(%d)", ret);
143 ecore_timer_add(0, __cancel_by_interrupt, NULL);
144 /* Send error cb to manager */
145 if (VCE_ERROR_OUT_OF_NETWORK == ret) {
146 vcdc_send_error_signal_to_manager(vcd_client_manager_get_pid(), VCD_ERROR_TIMED_OUT, "voice_framework.error.engine.set_recording_fail");
148 vcdc_send_error_signal_to_manager(vcd_client_manager_get_pid(), VCD_ERROR_OPERATION_FAILED, "voice_framework.error.engine.set_recording_fail");
153 if (VCE_SPEECH_DETECT_BEGIN == speech_detected) {
154 if (-1 != vcd_client_manager_get_pid()) {
155 /* Manager client is available */
156 if (0 != vcdc_send_speech_detected(vcd_client_manager_get_pid())) {
157 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Fail to send speech detected");
160 } else if (VCE_SPEECH_DETECT_END == speech_detected) {
161 if (VCD_RECOGNITION_MODE_STOP_BY_SILENCE == vcd_client_get_recognition_mode()) {
162 /* silence detected */
163 ecore_timer_add(0, __stop_by_silence, NULL);
164 } else if (VCD_RECOGNITION_MODE_RESTART_AFTER_REJECT == vcd_client_get_recognition_mode()) {
165 /* Stop engine recognition */
166 int ret = vcd_engine_recognize_stop();
168 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to stop recognition : %d", ret);
170 vcd_config_set_service_state(VCD_STATE_PROCESSING);
171 vcdc_send_service_state(VCD_STATE_PROCESSING);
173 SLOG(LOG_INFO, TAG_VCD, "[Server] Stop engine only by silence");
174 } else if (VCD_RECOGNITION_MODE_RESTART_CONTINUOUSLY == vcd_client_get_recognition_mode()) {
175 /* Stop engine recognition */
176 int ret = vcd_engine_recognize_stop();
178 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to stop recognition : %d", ret);
186 void __server_recorder_interrupt_callback()
188 SLOG(LOG_INFO, TAG_VCD, "@@@ Cancel by sound interrupt");
190 ecore_timer_add(0, __cancel_by_interrupt, NULL);
192 SLOG(LOG_DEBUG, TAG_VCD, "@@@");
195 static void __config_lang_changed_cb(const char* current_lang, void* user_data)
197 SLOG(LOG_INFO, TAG_VCD, "@@@ Change language ");
199 /* Current state is recording */
200 vcd_state_e state = vcd_config_get_service_state();
201 if (VCD_STATE_RECORDING == state || VCD_STATE_PROCESSING == state) {
202 SLOG(LOG_INFO, TAG_VCD, "[Server] Current state is 'Recording'. Cancel recognition");
203 vcd_server_mgr_cancel();
207 ret = vcd_engine_set_current_language(current_lang);
209 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to set language of engine : %d", ret);
212 SLOG(LOG_INFO, TAG_VCD, "@@@");
217 static void __config_foreground_changed_cb(int previous, int current, void* user_data)
219 SLOG(LOG_DEBUG, TAG_VCD, "@@@ Change foreground");
221 SLOG(LOG_INFO, TAG_VCD, "Foreground pid(%d)", current);
223 if (VC_NO_FOREGROUND_PID != current) {
224 /* Foreground app is changed */
225 vcd_state_e state = vcd_config_get_service_state();
226 if (VCD_STATE_RECORDING == state) {
227 SLOG(LOG_INFO, TAG_VCD, "[Server] Foreground pid(%d) is changed. Cancel recognition", current);
228 ecore_timer_add(0, __cancel_by_interrupt, NULL);
232 SLOG(LOG_DEBUG, TAG_VCD, "@@@");
237 static int __vcd_activate_app_by_appcontrol(const char* appid)
240 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Invalid parameter");
241 return VCD_ERROR_INVALID_PARAMETER;
245 app_control_h app_control = NULL;
246 ret = app_control_create(&app_control);
247 if (APP_CONTROL_ERROR_NONE == ret) {
249 ret = app_control_add_extra_data(app_control, "voice_launch", "get_result");
250 if (APP_CONTROL_ERROR_NONE != ret) {
251 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to add extra data, ret(%d)", ret);
252 app_control_destroy(app_control);
253 return VCD_ERROR_OPERATION_FAILED;
256 ret = app_control_set_app_id(app_control, appid);
257 if (APP_CONTROL_ERROR_NONE != ret) {
258 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to set app id, ret(%d)", ret);
259 app_control_destroy(app_control);
260 return VCD_ERROR_OPERATION_FAILED;
262 // Sent launch request
263 ret = app_control_send_launch_request(app_control, NULL, NULL);
264 if (APP_CONTROL_ERROR_NONE != ret) {
265 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to send launch request, ret(%d)", ret);
266 app_control_destroy(app_control);
267 return VCD_ERROR_OPERATION_FAILED;
269 // Destroy app control
270 ret = app_control_destroy(app_control);
271 if (APP_CONTROL_ERROR_NONE != ret) {
272 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to destroy, ret(%d)", ret);
273 return VCD_ERROR_OPERATION_FAILED;
276 return VCD_ERROR_NONE;
279 static int __vcd_resume_app(const char* appid)
281 app_context_h app_context = NULL;
282 int ret = app_manager_get_app_context(appid, &app_context);
283 if (APP_MANAGER_ERROR_NONE != ret) {
284 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to get app_context, ret(%d), appid(%s)", ret, appid);
285 return VCD_ERROR_OPERATION_FAILED;
288 ret = app_manager_resume_app(app_context);
289 if (APP_MANAGER_ERROR_NONE != ret) {
290 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to resume app, ret(%d), appid(%s)", ret, appid);
291 return VCD_ERROR_OPERATION_FAILED;
293 return VCD_ERROR_NONE;
296 static bool __vcd_is_package_installed(const char* appid)
298 app_info_h app_info = NULL;
299 int ret = app_manager_get_app_info(appid, &app_info);
300 if (APP_MANAGER_ERROR_NONE != ret || NULL == app_info)
302 ret = app_info_destroy(app_info);
303 if (APP_MANAGER_ERROR_NONE != ret)
304 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to destroy app_info, ret(%d)", ret);
308 void __vc_free_deactivated_app(void* data)
310 vc_deactivated_app_s* d_app = (vc_deactivated_app_s*)data;
313 if (NULL != d_app->appid) {
323 static bool __vcd_launch_app(const char* result)
325 if (NULL == result) {
326 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Invalid parameter");
327 return VCD_ERROR_INVALID_PARAMETER;
330 GSList* app_list = NULL;
331 if (0 != vc_db_get_appid_list(result, &app_list)) {
332 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] result text is NULL");
333 return VCD_ERROR_INVALID_PARAMETER;
336 if (0 != g_slist_length(app_list)) {
339 vc_deactivated_app_s* temp_app = NULL;
340 iter = g_slist_nth(app_list, 0);
342 while (NULL != iter) {
343 temp_app = iter->data;
345 if (NULL != temp_app && NULL != temp_app->appid) {
347 bool running = false;
348 ret = app_manager_is_running(temp_app->appid, &running);
349 if (APP_MANAGER_ERROR_NONE != ret) {
350 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to check running with appid(%s)", temp_app->appid);
351 g_slist_free_full(iter, __vc_free_deactivated_app);
352 return VCD_ERROR_OPERATION_FAILED;
354 if (false == running) {
355 int tmp_ret = __vcd_is_package_installed(temp_app->appid);
356 if (false == tmp_ret) {
357 SLOG(LOG_WARN, TAG_VCD, "[WARNING] app is not installed, appid(%s)", temp_app->appid);
359 ret = __vcd_activate_app_by_appcontrol(temp_app->appid);
361 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to activate app");
362 g_slist_free_full(iter, __vc_free_deactivated_app);
365 SLOG(LOG_ERROR, TAG_VCD, "Launch app: appid(%s) result(%s)", temp_app->appid, result);
368 ret = __vcd_resume_app(temp_app->appid);
370 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to resume app");
371 g_slist_free_full(iter, __vc_free_deactivated_app);
374 SLOG(LOG_ERROR, TAG_VCD, "Resume app: appid(%s) result(%s)", temp_app->appid, result);
376 __vc_free_deactivated_app((void*)temp_app);
379 app_list = g_slist_remove_link(app_list, iter);
381 iter = g_slist_nth(app_list, 0);
386 return VCD_ERROR_NONE;
389 static Eina_Bool __vcd_send_selected_result(void *data)
391 GSList* pid_list = NULL;
392 const char* result = vcd_client_manager_get_result_text();
394 if (0 != vc_info_parser_get_result_pid_list(&pid_list, result)) {
395 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Fail to get pid list. No result");
397 if (0 < g_slist_length(pid_list)) {
399 vc_cmd_s* temp_cmd = NULL;
404 iter = g_slist_nth(pid_list, 0);
405 while (NULL != iter) {
406 temp_cmd = iter->data;
408 if (NULL != temp_cmd && (pre_pid != temp_cmd->pid || pre_type == VC_COMMAND_TYPE_WIDGET || temp_cmd->type == VC_COMMAND_TYPE_WIDGET)) {
409 /* Launch deactivated several apps that is matched with result */
410 ret = __vcd_launch_app(result);
412 SLOG(LOG_ERROR, TAG_VCD, "Fail to launch or resume app, ret(%d) result(%s)", ret, result);
414 /* send result noti */
415 ret = vcdc_send_result(temp_cmd->pid, vcd_client_manager_get_pid(), temp_cmd->type);
417 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Fail to send result, ret(%d)", ret);
418 g_slist_free_full(pid_list, free);
422 SLOG(LOG_ERROR, TAG_VCD, "[Server] Send result : pid(%d) type(%d)", temp_cmd->pid, temp_cmd->type);
423 pre_pid = temp_cmd->pid;
424 pre_type = temp_cmd->type;
430 pid_list = g_slist_remove_link(pid_list, iter);
432 iter = g_slist_nth(pid_list, 0);
437 if (VCD_RECOGNITION_MODE_RESTART_CONTINUOUSLY != vcd_client_get_recognition_mode()) {
438 vcd_config_set_service_state(VCD_STATE_READY);
439 vcdc_send_service_state(VCD_STATE_READY);
445 int vcd_send_asr_result(vce_asr_result_event_e event, const char* asr_result, void *user_data)
447 int ret = __vcd_server_launch_manager_app();
449 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);
453 if (NULL != asr_result) {
454 SECURE_SLOG(LOG_INFO, TAG_VCD, "[Server] ASR result - Event(%d), Text(%s)", event, asr_result);
455 ret = vcdc_send_pre_result_to_manager(vcd_client_manager_get_pid(), event, asr_result);
457 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);
464 int vcd_send_specific_engine_result(const char* engine_app_id, const char* event, const char* result, void *user_info)
466 if (NULL != result) {
467 SLOG(LOG_INFO, TAG_VCD, "[Server] specific engine result - Event(%s), Text(%s)", event, result);
468 vcdc_send_specific_engine_result_to_manager(vcd_client_manager_get_pid(), engine_app_id, event, result);
471 return VCD_ERROR_NONE;
474 int vcd_send_nlg_result(const char* nlg_result, void *user_data)
476 int ret = __vcd_server_launch_manager_app();
478 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);
482 SLOG(LOG_ERROR, TAG_VCD, "[Server] send dialog : mgr_pid(%d), nlg_result(%s)", vcd_client_manager_get_pid(), nlg_result);
483 ret = vcdc_send_dialog(vcd_client_manager_get_pid(), -1, nlg_result, NULL, 0); //0: VC_DIALOG_END
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 static void* __recorder_stop(void *data)
495 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)
498 vcd_recognition_mode_e recognition_mode = vcd_client_get_recognition_mode();
500 if (VCD_STATE_PROCESSING != vcd_config_get_service_state()) {
501 if (VCD_RECOGNITION_MODE_RESTART_CONTINUOUSLY != recognition_mode) {
502 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Current state is not 'Processing' and mode is not 'Restart continuously'");
503 return VCD_ERROR_INVALID_STATE;
507 vc_info_parser_unset_result(vcd_client_manager_get_exclusive());
508 vcd_client_manager_set_result_text(all_result);
510 SECURE_SLOG(LOG_INFO, TAG_VCD, "[Server] Event(%d), Text(%s) Nonfixed(%s) Msg(%s) Result count(%d)",
511 event, all_result, non_fixed_result, msg, count);
513 SECURE_SLOG(LOG_ERROR, TAG_VCD, "[Server] NLU result(%s)", nlu_result);
516 /* if nlu_result is exist, Add command handle(is_action) into result list */
518 SLOG(LOG_INFO, TAG_VCD, "[Server] @ Get engine result @");
520 vc_cmd_s* temp_cmd = NULL;
521 vc_cmd_list_h vc_cmd_list = NULL;
523 if (0 != vc_cmd_list_create(&vc_cmd_list)) {
524 SLOG(LOG_INFO, TAG_VCD, "[Server] Fail to create command list");
525 vcd_client_manager_set_exclusive(false);
526 vcd_config_set_service_state(VCD_STATE_READY);
527 vcdc_send_service_state(VCD_STATE_READY);
528 return VCD_ERROR_NONE;
531 /* priority filter */
532 /* system > exclusive > widget > foreground > system_background > widget partial > foreground partial > background */
534 int* filtered_id = (int*)calloc(count, sizeof(int));
536 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to allocate memory");
537 vc_cmd_list_destroy(vc_cmd_list, true);
539 return VCD_ERROR_OUT_OF_MEMORY;
541 int filtered_count = 0;
542 int top_priority = VC_COMMAND_PRIORITY_BACKGROUND;
543 for (i = 0; i < count; i++) {
544 SLOG(LOG_INFO, TAG_VCD, "[Server] [%d] Result id(%d)", i, result_id[i]);
546 if (0 > result_id[i]) {
547 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Result ID(%d) is NOT valid", result_id[i]);
551 ret = vcd_client_get_cmd_from_result_id(result_id[i], &temp_cmd);
552 if (0 == ret && NULL != temp_cmd) {
553 if (top_priority == temp_cmd->priority) {
554 filtered_id[filtered_count] = result_id[i];
556 } else if (top_priority > temp_cmd->priority) {
557 filtered_id[0] = result_id[i];
559 top_priority = temp_cmd->priority;
562 vc_cmd_destroy((vc_cmd_h)temp_cmd);
567 if (top_priority >= VC_COMMAND_PRIORITY_WIDGET) {
568 int pid = vcd_client_widget_get_foreground_pid();
570 if (NULL != all_result) {
571 vc_info_parser_set_result(all_result, event, msg, NULL, false);
573 vcd_client_widget_get_asr_result_enabled(pid, &enable);
574 if (true == enable) {
575 SLOG(LOG_INFO, TAG_VCD, "[Server] Send ASR result to Widget client");
576 bool is_consumed = false;
577 if (NULL != user_info) {
580 if (0 != vcdc_send_asr_result(pid, event, all_result, VC_COMMAND_TYPE_WIDGET, &is_consumed)) {
581 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to send asr result");
583 SLOG(LOG_INFO, TAG_VCD, "[Server] ASR result is consumed(%d)", is_consumed);
584 if (true == is_consumed) {
585 if (NULL != user_info) {
587 SLOG(LOG_ERROR, TAG_VCD, "[Server] Send whether ASR result is consumed or not (%d)", *user_info);
589 vcdc_send_show_tooltip(pid, false);
590 if (-1 != vcd_client_manager_get_pid()) {
591 /* Manager client is available */
592 vc_info_parser_unset_result(false);
593 vc_info_parser_set_result(all_result, VC_RESULT_EVENT_RESULT_SUCCESS, msg, NULL, false);
594 if (0 != vcdc_send_result_to_manager(vcd_client_manager_get_pid(), VC_RESULT_TYPE_NOTIFICATION)) {
595 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Fail to send result");
599 // Set state manually, because the result is already handled in ASR result by client.
600 // So, the daemon does not need to send the result to client.
601 vcd_client_manager_set_exclusive(false);
603 vcd_config_set_service_state(VCD_STATE_READY);
604 vcdc_send_service_state(VCD_STATE_READY);
605 vc_cmd_list_destroy(vc_cmd_list, true);
607 if (NULL != filtered_id) {
611 return VCD_ERROR_NONE;
620 for (i = 0; i < filtered_count; i++) {
621 SLOG(LOG_INFO, TAG_VCD, "[Server] [%d] Filtered Result id(%d)", i, filtered_id[i]);
623 if (filtered_id[i] < 0) {
624 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Filtered ID(%d) is NOT valid", filtered_id[i]);
628 ret = vcd_client_get_cmd_from_result_id(filtered_id[i], &temp_cmd);
629 if (0 == ret && NULL != temp_cmd) {
630 switch (temp_cmd->format) {
631 case VC_CMD_FORMAT_FIXED:
632 case VC_CMD_FORMAT_FIXED_AND_VFIXED:
633 case VC_CMD_FORMAT_VFIXED_AND_FIXED:
634 case VC_CMD_FORMAT_PARTIAL:
635 case VC_CMD_FORMAT_FIXED_AND_NONFIXED:
636 case VC_CMD_FORMAT_NONFIXED_AND_FIXED:
638 case VC_CMD_FORMAT_ACTION:
642 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Unknown command type : %d", temp_cmd->type);
646 if (0 != vc_cmd_list_add(vc_cmd_list, (vc_cmd_h)temp_cmd)) {
647 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Fail to add command to list");
648 vc_cmd_destroy((vc_cmd_h)temp_cmd);
652 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] NOT found matched result(%d)", filtered_id[i]);
656 if (NULL != filtered_id) {
661 if (NULL != nlu_result) {
662 SECURE_SLOG(LOG_INFO, TAG_VCD, "[Server] NLU (%s)", nlu_result);
663 vc_info_parser_set_nlu_result(nlu_result);
664 if (0 == is_action) {
666 if (0 != vc_cmd_create(&nlu_cmd)) {
667 SLOG(LOG_ERROR, TAG_VCD, "Fail to nlu cmd create");
669 if (0 != vc_cmd_set_type(nlu_cmd, VC_COMMAND_TYPE_SYSTEM)) {
670 SLOG(LOG_ERROR, TAG_VCD, "Fail to set type");
672 if (0 != vc_cmd_set_pid(nlu_cmd, vcd_client_manager_get_pid())) {
673 SLOG(LOG_ERROR, TAG_VCD, "Fail to set pid");
675 if (0 != vc_cmd_set_format(nlu_cmd, VC_CMD_FORMAT_ACTION)) {
676 SLOG(LOG_ERROR, TAG_VCD, "Fail to set format");
678 if (0 != vc_cmd_list_add(vc_cmd_list, nlu_cmd)) {
679 SLOG(LOG_ERROR, TAG_VCD, "Fail to add nlu cmd to list");
680 vc_cmd_destroy(nlu_cmd);
686 vc_cmd_print_list(vc_cmd_list);
688 SLOG(LOG_INFO, TAG_VCD, "[Server] @@@@");
690 int result_count = 0;
691 vc_cmd_list_get_count(vc_cmd_list, &result_count);
693 /* Handle the result list */
694 if (0 == result_count) {
696 vc_cmd_list_h widget_cmd_list = NULL;
697 vc_cmd_list_h foreground_cmd_list = NULL;
698 if (NULL != all_result) {
699 SECURE_SLOG(LOG_INFO, TAG_VCD, "[Server] Engine result is no command : %s", all_result);
702 if (0 != vc_cmd_list_create(&widget_cmd_list)) {
703 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to create widget command list handle");
704 vc_cmd_list_destroy(vc_cmd_list, true);
706 return VCD_ERROR_OUT_OF_MEMORY;
709 /* Get the list of widget type commands */
710 vcd_client_append_cmd_from_type(VC_COMMAND_TYPE_WIDGET, widget_cmd_list);
711 vc_cmd_list_get_count(widget_cmd_list, &cnt);
713 /* Matched with widget command partially */
714 vc_cmd_get_partially_matched_cmd_list(all_result, widget_cmd_list, vc_cmd_list, VC_SEARCH_NONE_LEVEL);
715 vc_cmd_list_get_count(vc_cmd_list, &cnt);
717 top_priority = VC_COMMAND_PRIORITY_WIDGET;
718 SLOG(LOG_INFO, TAG_VCD, "[INFO] Partially matched widget command");
721 if (0 != vc_cmd_list_create(&foreground_cmd_list)) {
722 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to create foreground command list handle");
723 vc_cmd_list_destroy(vc_cmd_list, true);
725 vc_cmd_list_destroy(widget_cmd_list, true);
726 widget_cmd_list = NULL;
727 return VCD_ERROR_OUT_OF_MEMORY;
730 /* Get the list of foreground type commands */
731 vcd_client_append_cmd_from_type(VC_COMMAND_TYPE_FOREGROUND, foreground_cmd_list);
732 vc_cmd_list_get_count(foreground_cmd_list, &cnt);
734 /* Matched with foreground command partially */
735 vc_cmd_get_partially_matched_cmd_list(all_result, foreground_cmd_list, vc_cmd_list, VC_SEARCH_NONE_LEVEL);
736 vc_cmd_list_get_count(vc_cmd_list, &cnt);
738 top_priority = VC_COMMAND_PRIORITY_FOREGROUND;
739 SLOG(LOG_INFO, TAG_VCD, "[INFO] Partially matched foreground command");
742 vc_cmd_list_destroy(foreground_cmd_list, true);
743 foreground_cmd_list = NULL;
745 vc_cmd_list_destroy(widget_cmd_list, true);
746 widget_cmd_list = NULL;
748 SLOG(LOG_INFO, TAG_VCD, "[Server] Engine all result is NULL");
751 vc_cmd_list_get_count(vc_cmd_list, &result_count);
753 // After running partial matching algorithm, if there is no result.
754 if (0 == result_count) {
755 SLOG(LOG_INFO, TAG_VCD, "[Server] No commands even after partial matching");
757 bool temp = vcd_client_manager_get_exclusive();
758 vc_info_parser_set_result(all_result, event, msg, NULL, temp);
760 int pid = vcd_client_widget_get_foreground_pid();
762 SLOG(LOG_INFO, TAG_VCD, "[Server] Request tooltip hide");
763 /* Send to hide tooltip */
764 vcdc_send_show_tooltip(pid, false);
767 if (-1 != vcd_client_manager_get_pid()) {
768 /* Manager client is available */
769 if (0 != vcdc_send_result_to_manager(vcd_client_manager_get_pid(), VC_RESULT_TYPE_NORMAL)) {
770 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Fail to send result");
774 /* set service state ready */
775 vcd_config_set_service_state(VCD_STATE_READY);
776 vcdc_send_service_state(VCD_STATE_READY);
778 vcd_client_manager_set_exclusive(false);
779 vc_cmd_list_destroy(vc_cmd_list, true);
782 return VCD_ERROR_NONE;
785 // Partial matching algorithm find some commands
786 event = VC_RESULT_EVENT_RESULT_SUCCESS;
789 // There are more than one result.
790 if (false == vcd_client_manager_get_exclusive()) {
791 vc_cmd_list_h temp_list = NULL;
793 /* Foreground, Widget, Background, System, System-Background */
794 if (top_priority >= VC_COMMAND_PRIORITY_BACKGROUND) {
795 vc_cmd_list_h widget_cmd_list = NULL;
796 vc_cmd_list_h foreground_cmd_list = NULL;
799 if (0 != vc_cmd_list_create(&temp_list)) {
800 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to create widget command list handle");
801 vc_cmd_list_destroy(vc_cmd_list, true);
803 return VCD_ERROR_OUT_OF_MEMORY;
806 if (0 != vc_cmd_list_create(&widget_cmd_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 vc_cmd_list_destroy(temp_list, true);
812 return VCD_ERROR_OUT_OF_MEMORY;
815 /* Get the list of widget type commands */
816 vcd_client_append_cmd_from_type(VC_COMMAND_TYPE_WIDGET, widget_cmd_list);
817 vc_cmd_list_get_count(widget_cmd_list, &cnt);
819 /* Matched with widget command partially */
820 vc_cmd_get_partially_matched_cmd_list(all_result, widget_cmd_list, temp_list, VC_SEARCH_NONE_LEVEL);
821 vc_cmd_list_get_count(temp_list, &cnt);
823 if (0 != vc_cmd_list_destroy(vc_cmd_list, true)) {
824 SLOG(LOG_WARN, TAG_VCD, "[WARNING] Fail to destroy list");
826 vc_cmd_list = temp_list;
827 top_priority = VC_COMMAND_PRIORITY_WIDGET;
828 event = VC_RESULT_EVENT_RESULT_SUCCESS;
829 SLOG(LOG_INFO, TAG_VCD, "[INFO] Partially matched widget command when background cmd exists");
832 if (0 != vc_cmd_list_create(&foreground_cmd_list)) {
833 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to create foreground command list handle");
834 vc_cmd_list_destroy(vc_cmd_list, true);
836 vc_cmd_list_destroy(widget_cmd_list, true);
837 widget_cmd_list = NULL;
838 return VCD_ERROR_OUT_OF_MEMORY;
841 /* Get the list of foreground type commands */
842 vcd_client_append_cmd_from_type(VC_COMMAND_TYPE_FOREGROUND, foreground_cmd_list);
843 vc_cmd_list_get_count(foreground_cmd_list, &cnt);
845 /* Matched with foreground command partially */
846 vc_cmd_get_partially_matched_cmd_list(all_result, foreground_cmd_list, temp_list, VC_SEARCH_NONE_LEVEL);
847 vc_cmd_list_get_count(temp_list, &cnt);
849 if (0 != vc_cmd_list_destroy(vc_cmd_list, true)) {
850 SLOG(LOG_WARN, TAG_VCD, "[WARNING] Fail to destroy list");
852 vc_cmd_list = temp_list;
853 top_priority = VC_COMMAND_PRIORITY_FOREGROUND;
854 event = VC_RESULT_EVENT_RESULT_SUCCESS;
855 SLOG(LOG_INFO, TAG_VCD, "[INFO] Partially matched foreground command when background cmd exists");
858 vc_cmd_list_destroy(foreground_cmd_list, true);
859 foreground_cmd_list = NULL;
861 vc_cmd_list_destroy(widget_cmd_list, true);
862 widget_cmd_list = NULL;
865 int pid = vcd_client_widget_get_foreground_pid();
867 SLOG(LOG_INFO, TAG_VCD, "[Server] Request tooltip hide");
868 vcdc_send_show_tooltip(pid, false);
871 vc_info_parser_set_result(all_result, event, msg, vc_cmd_list, false);
872 vc_cmd_list_destroy(vc_cmd_list, true);
875 if (-1 != vcd_client_manager_get_pid()) {
876 /* Manager client is available */
877 if (0 != vcdc_send_result_to_manager(vcd_client_manager_get_pid(), VC_RESULT_TYPE_NORMAL)) {
878 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Fail to send result");
881 SLOG(LOG_INFO, TAG_VCD, "[Server] Manager is NOT available. Send result to client directly");
882 ecore_timer_add(0, __vcd_send_selected_result, NULL);
885 /* exclusive command */
886 vc_info_parser_set_result(all_result, event, msg, vc_cmd_list, true);
887 vc_cmd_list_destroy(vc_cmd_list, true);
890 if (-1 != vcd_client_manager_get_pid()) {
891 /* Manager client is available */
892 if (0 != vcdc_send_result_to_manager(vcd_client_manager_get_pid(), VC_RESULT_TYPE_NORMAL)) {
893 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Fail to send result");
896 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Manager is NOT available");
899 vcd_client_manager_set_exclusive(false);
902 if (VCD_RECOGNITION_MODE_RESTART_AFTER_REJECT == recognition_mode) {
903 if (VCE_RESULT_EVENT_REJECTED == event) {
904 SLOG(LOG_INFO, TAG_VCD, "[Server] Restart by no or rejected result");
905 /* If no result and restart option is ON */
906 /* Send reject message */
907 bool temp = vcd_client_manager_get_exclusive();
908 vc_info_parser_set_result(all_result, event, msg, NULL, temp);
909 ret = vcdc_send_result_to_manager(vcd_client_manager_get_pid(), VC_RESULT_TYPE_NOTIFICATION);
911 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Fail to send result");
914 g_restart_timer = ecore_timer_add(0, __restart_engine, NULL);
917 SLOG(LOG_INFO, TAG_VCD, "[Server] Stop recorder due to success");
918 //vcd_recorder_stop();
919 ecore_main_loop_thread_safe_call_sync(__recorder_stop, NULL);
920 } else if (VCD_RECOGNITION_MODE_RESTART_CONTINUOUSLY == recognition_mode) {
921 SLOG(LOG_INFO, TAG_VCD, "[Server] Restart continuously");
922 /* Restart option is ON */
923 g_restart_timer = ecore_timer_add(0, __restart_engine, NULL);
924 if (VCE_RESULT_EVENT_REJECTED == event) {
925 bool temp = vcd_client_manager_get_exclusive();
926 vc_info_parser_set_result(all_result, event, msg, NULL, temp);
927 ret = vcdc_send_result_to_manager(vcd_client_manager_get_pid(), VC_RESULT_TYPE_NOTIFICATION);
929 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Fail to send result");
935 return VCD_ERROR_NONE;
939 if (NULL == result_id) {
941 if (NULL != all_result) {
942 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Engine result is no command : %s", all_result);
943 bool temp = vcd_client_manager_get_exclusive();
944 vc_info_parser_set_result(all_result, event, msg, NULL, temp);
947 int pid = vcd_client_widget_get_foreground_pid();
949 if (NULL != all_result) {
950 /* Send result text to widget */
951 vcdc_send_result(pid, vcd_client_manager_get_pid(), VC_COMMAND_TYPE_WIDGET);
954 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Request tooltip hide");
955 /* Send to hide tooltip */
956 vcdc_send_show_tooltip(pid, false);
959 if (-1 != vcd_client_manager_get_pid()) {
960 /* Manager client is available */
961 if (0 != vcdc_send_result_to_manager(vcd_client_manager_get_pid(), VC_RESULT_TYPE_NORMAL)) {
962 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Fail to send result");
966 vcd_client_manager_set_exclusive(false);
972 SLOG(LOG_DEBUG, TAG_VCD, "[Server] @ Get engine result @");
975 vc_cmd_s* temp_cmd = NULL;
976 vc_cmd_list_h vc_cmd_list = NULL;
978 if (0 != vc_cmd_list_create(&vc_cmd_list)) {
979 SLOG(LOG_ERROR, TAG_VCD, "[Server] Fail to create command list");
980 vcd_client_manager_set_exclusive(false);
981 vcd_config_set_service_state(VCD_STATE_READY);
982 vcdc_send_service_state(VCD_STATE_READY);
987 for (i = 0; i < count; i++) {
988 SLOG(LOG_DEBUG, TAG_VCD, "[Server] [%d] Result ID(%d)", i, result_id[i]);
990 if (result_id[i] < 0) {
991 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Result ID(%d) is NOT valid", result_id[i]);
995 ret = vcd_client_get_cmd_from_result_id(result_id[i], &temp_cmd);
996 if (0 == ret && NULL != temp_cmd) {
997 switch (temp_cmd->format) {
998 case VC_CMD_FORMAT_FIXED:
999 case VC_CMD_FORMAT_FIXED_AND_VFIXED:
1000 case VC_CMD_FORMAT_VFIXED_AND_FIXED:
1001 case VC_CMD_FORMAT_PARTIAL:
1002 /* Nonfixed result is NOT valid */
1004 case VC_CMD_FORMAT_FIXED_AND_NONFIXED:
1005 if (NULL == temp_cmd->parameter) {
1006 if (NULL != non_fixed_result) {
1007 temp_cmd->parameter = strdup(non_fixed_result);
1010 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Command type is NOT valid. Parameter (%s)", temp_cmd->parameter);
1013 case VC_CMD_FORMAT_NONFIXED_AND_FIXED:
1014 if (NULL == temp_cmd->command) {
1015 if (NULL != non_fixed_result) {
1016 temp_cmd->command = strdup(non_fixed_result);
1019 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Command type is NOT valid. Command (%s)", temp_cmd->command);
1024 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Unknown command type : %d", temp_cmd->type);
1028 if (0 != vc_cmd_list_add(vc_cmd_list, (vc_cmd_h)temp_cmd)) {
1029 SLOG(LOG_DEBUG, TAG_VCD, "Fail to add command to list");
1030 vc_cmd_destroy((vc_cmd_h)temp_cmd);
1033 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] NOT found matched result(%d)", result_id[i]);
1037 vc_cmd_print_list(vc_cmd_list);
1039 SLOG(LOG_DEBUG, TAG_VCD, "[Server] @@@@");
1041 int result_count = 0;
1042 vc_cmd_list_get_count(vc_cmd_list, &result_count);
1044 if (false == vcd_client_manager_get_exclusive()) {
1045 int pid = vcd_client_widget_get_foreground_pid();
1047 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Request tooltip hide");
1048 vcdc_send_show_tooltip(pid, false);
1051 vc_info_parser_set_result(all_result, event, msg, vc_cmd_list, false);
1053 if (-1 != vcd_client_manager_get_pid()) {
1054 /* Manager client is available */
1055 if (0 != vcdc_send_result_to_manager(vcd_client_manager_get_pid(), VC_RESULT_TYPE_NORMAL)) {
1056 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Fail to send result");
1059 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Manager is NOT available. Send result to client directly");
1060 /* Send result to client */
1061 ecore_timer_add(0, __vcd_send_selected_result, NULL);
1064 /* exclusive command */
1065 vc_info_parser_set_result(all_result, event, msg, vc_cmd_list, true);
1067 if (-1 != vcd_client_manager_get_pid()) {
1068 /* Manager client is available */
1069 if (0 != vcdc_send_result_to_manager(vcd_client_manager_get_pid(), VC_RESULT_TYPE_NORMAL)) {
1070 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Fail to send result");
1073 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Manager is NOT available");
1076 vcd_client_manager_set_exclusive(false);
1079 vc_cmd_list_destroy(vc_cmd_list, true);
1087 static void __vcd_server_nlu_result_cb(vce_result_event_e event, const char* nlu_result, void *user_data)
1089 SECURE_SLOG(LOG_DEBUG, TAG_VCD, "[Server] NLU result cb - event(%d)", event);
1090 SECURE_SLOG(LOG_DEBUG, TAG_VCD, "[Server] result (%s)", nlu_result);
1092 int ret = vc_info_parser_set_nlu_result(nlu_result);
1094 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to set nlu result (%d)", ret);
1101 int vcd_send_error(vce_error_e error, const char* msg, void *user_data)
1103 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Engine Error cb - reason(%d), msg(%s)", error, msg);
1104 ecore_main_loop_thread_safe_call_async(__cancel_by_error, NULL);
1106 char* error_msg = NULL;
1108 error_msg = strdup(msg);
1109 if (NULL == error_msg) {
1110 return VCD_ERROR_OUT_OF_MEMORY;
1114 int ret = VCD_ERROR_NONE;
1115 ret = vcdc_send_error_signal_to_manager(vcd_client_manager_get_pid(), error, error_msg);
1116 if (VCD_ERROR_NONE != ret) {
1117 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to send error signal");
1120 if (NULL != error_msg) {
1128 /* for TTS feedback */
1129 int vcd_send_feedback_audio_format(int rate, vce_audio_channel_e channel, vce_audio_type_e audio_type)
1131 SLOG(LOG_INFO, TAG_VCD, "[Server DEBUG] Engine - Send TTS feedback audio format, g_current_uid(%d)", g_current_uid);
1133 /* send TTS feedback audio format to VC manager */
1134 int ret = VCD_ERROR_NONE;
1135 int pid = g_current_uid / 1000;
1136 if (-1 == g_current_uid || vcd_client_manager_get_pid() == pid) {
1137 ret = vcdc_send_feedback_audio_format_to_manager(vcd_client_manager_get_pid(), rate, channel, audio_type);
1138 if (VCD_ERROR_NONE != ret) {
1139 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to send TTS feedback audio format to VC manager");
1142 SLOG(LOG_INFO, TAG_VCD, "[Server INFO] Do not send TTS feedback audio format to VC manager");
1148 int vcd_send_feedback_streaming(vce_feedback_event_e event, char* buffer, int len)
1150 if (-1 == g_current_uid && VCE_FEEDBACK_EVENT_START == event) {
1151 g_current_utt_id = (g_current_utt_id + 1) % 1000;
1152 g_current_uid = vcd_client_manager_get_pid() * 1000 + g_current_utt_id;
1153 SLOG(LOG_INFO, TAG_VCD, "[Server info] set current uid and utt_id as manager pid(%d)", vcd_client_manager_get_pid());
1156 int ret = VCD_ERROR_NONE;
1157 int pid = g_current_uid / 1000;
1158 int utt_id = g_current_uid % 1000;
1160 SLOG(LOG_INFO, TAG_VCD, "[Server DEBUG] Engine - Send TTS feedback streaming event(%d), uid(%d), is_mgr_client(%d)", event, g_current_uid, (pid == vcd_client_manager_get_pid() ? true : false));
1162 if (pid == vcd_client_manager_get_pid()) {
1163 /* send TTS feedback streaming to manager client */
1164 ret = vcdc_send_feedback_streaming_to_manager(vcd_client_manager_get_pid(), pid, utt_id, event, buffer, len);
1165 if (VCD_ERROR_NONE != ret) {
1166 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to send TTS feedback streaming to manager client");
1169 /* send TTS feedback streaming to client */
1170 ret = vcdc_send_feedback_streaming(pid, utt_id, event, buffer, len);
1171 if (VCD_ERROR_NONE != ret) {
1172 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to send TTS feedback streaming to client");
1176 if (VCE_FEEDBACK_EVENT_FINISH == event) {
1177 /* reset current uid */
1180 /* Set service state to ready if state is synthesizing */
1181 vcd_state_e state = vcd_config_get_service_state();
1182 if (VCD_STATE_SYNTHESIZING == state) {
1183 vcd_config_set_service_state(VCD_STATE_READY);
1185 SLOG(LOG_INFO, TAG_VCD, "[Server info] feedback streaming finish event, reset current uid & service state(%d)", vcd_config_get_service_state());
1192 * vcd server Interfaces
1194 static void __vcd_file_clean_up()
1196 SLOG(LOG_INFO, TAG_VCD, "== Old file clean up == ");
1199 struct dirent *dirp = NULL;
1201 dp = opendir(VC_RUNTIME_INFO_ROOT);
1203 SLOG(LOG_ERROR, TAG_VCD, "[File message WARN] Fail to open path : %s", VC_RUNTIME_INFO_ROOT);
1207 char remove_path[257] = {0, };
1212 if (!strncmp("vc_", dirp->d_name, strlen("vc_"))) {
1213 memset(remove_path, 0, 257);
1214 snprintf(remove_path, 257, "%s/%s", VC_RUNTIME_INFO_ROOT, dirp->d_name);
1217 if (0 != remove(remove_path)) {
1218 SLOG(LOG_WARN, TAG_VCD, "[File message WARN] Fail to remove file : %s", remove_path);
1220 SLOG(LOG_INFO, TAG_VCD, "[File message] Remove file : %s", remove_path);
1224 } while (NULL != dirp);
1231 static int __vcd_db_clean_up()
1234 int cnt = VC_COMMAND_TYPE_FOREGROUND;
1236 if (VC_COMMAND_TYPE_BACKGROUND != cnt)
1237 ret = vc_db_delete_commands(-1, cnt, NULL);
1238 } while (VC_COMMAND_TYPE_EXCLUSIVE >= ++cnt);
1243 static bool __is_default_engine()
1245 char* engine = NULL;
1246 engine = vconf_get_str(VCONFKEY_VC_ENGINE_DEFAULT);
1247 if (NULL == engine) {
1248 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to get sting for vc engine");
1252 char appid[1024] = {'\0', };
1253 if (0 != aul_app_get_appid_bypid(getpid(), appid, sizeof(appid) - 1)) {
1254 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to get callee appid by pid");
1257 SLOG(LOG_DEBUG, TAG_VCD, "[Server] VC Default Engine(%s), appId(%s)", engine, appid);
1258 if (0 == strncmp(engine, appid, strlen(engine))) {
1266 int vcd_initialize(vce_request_callback_s *callback)
1270 /* Remove old file */
1271 __vcd_file_clean_up();
1273 /* initialize modules */
1274 ret = vcd_config_initialize(__config_lang_changed_cb, __config_foreground_changed_cb, NULL);
1276 SLOG(LOG_ERROR, TAG_VCD, "[Server WARNING] Fail to initialize config.");
1279 ret = vc_db_initialize_for_daemon();
1281 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to initialize DB : %d", ret);
1285 /* Remove db data */
1286 ret = __vcd_db_clean_up();
1288 SLOG(LOG_ERROR, TAG_VCD, "[Server WARNING] Fail to remove db data");
1291 vcd_config_set_service_state(VCD_STATE_NONE);
1293 ret = vcd_engine_agent_init();
1295 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to engine agent initialize : result(%d)", ret);
1299 if (0 != vcd_recorder_create(__server_recorder_callback, __server_recorder_interrupt_callback)) {
1300 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to create recorder");
1301 return VCD_ERROR_OPERATION_FAILED;
1305 if (0 != vcd_engine_agent_load_current_engine(callback)) {
1306 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to load current engine");
1307 return VCD_ERROR_OPERATION_FAILED;
1310 /* Initialize manager info */
1311 vcd_client_manager_unset();
1313 if (TRUE == __is_default_engine()) {
1314 /* Open dbus connection */
1315 if (0 != vcd_dbus_open_connection()) {
1316 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to open connection");
1317 return VCD_ERROR_OPERATION_FAILED;
1321 vcd_config_set_service_state(VCD_STATE_READY);
1322 // vcdc_send_service_state(VCD_STATE_READY);
1324 /* Set timer cleanup client all */
1325 g_check_client_timer = ecore_timer_add(CLIENT_CLEAN_UP_TIME, vcd_cleanup_client_all, NULL);
1326 if (NULL == g_check_client_timer) {
1327 SLOG(LOG_WARN, TAG_VCD, "[Server Warning] Fail to create timer of client check");
1331 g_current_utt_id = -1;
1333 SLOG(LOG_ERROR, TAG_VCD, "[Server SUCCESS] initialize");
1341 if (0 < g_list_length(g_proc_list)) {
1342 iter = g_list_first(g_proc_list);
1343 while (NULL != iter) {
1344 g_proc_list = g_list_remove_link(g_proc_list, iter);
1345 iter = g_list_first(g_proc_list);
1349 if (NULL != g_restart_timer) {
1350 ecore_timer_del(g_restart_timer);
1351 g_restart_timer = NULL;
1354 if (NULL != g_check_client_timer) {
1355 ecore_timer_del(g_check_client_timer);
1356 g_check_client_timer = NULL;
1359 vcd_state_e state = vcd_config_get_service_state();
1360 if (VCD_STATE_READY != state) {
1361 if (VCD_STATE_RECORDING == state) {
1362 vcd_recorder_stop();
1364 vcd_engine_recognize_cancel();
1367 if (0 != vcd_recorder_destroy()) {
1368 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to destroy recorder");
1371 SLOG(LOG_DEBUG, TAG_VCD, "[Server] destroy recorder");
1374 if (0 != vcd_engine_agent_release()) {
1375 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to release engine");
1378 SLOG(LOG_DEBUG, TAG_VCD, "[Server] release engine");
1381 vcd_client_manager_unset_appid();
1383 int ret = vcd_config_finalize();
1385 SLOG(LOG_ERROR, TAG_VCD, "[Server WARNING] Fail to finalize config.");
1388 ret = vc_db_finalize();
1390 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to finalize DB : %d", ret);
1393 vcd_config_set_service_state(VCD_STATE_NONE);
1394 vcdc_send_service_state(VCD_STATE_NONE);
1396 /* Open dbus connection */
1397 if (0 != vcd_dbus_close_connection()) {
1398 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to close connection");
1401 SLOG(LOG_ERROR, TAG_VCD, "[Server] mode finalize");
1406 static Eina_Bool __finalize_quit_ecore_loop(void *data)
1408 bool ret = vcd_finalize();
1412 ecore_main_loop_quit();
1417 static void __read_proc()
1420 struct dirent *dirp = NULL;
1424 if (0 < g_list_length(g_proc_list)) {
1425 iter = g_list_first(g_proc_list);
1426 while (NULL != iter) {
1427 g_proc_list = g_list_remove_link(g_proc_list, iter);
1428 iter = g_list_first(g_proc_list);
1432 dp = opendir("/proc");
1434 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to open proc");
1440 tmp = atoi(dirp->d_name);
1441 if (0 >= tmp) continue;
1442 g_proc_list = g_list_append(g_proc_list, GINT_TO_POINTER(tmp));
1444 } while (NULL != dirp);
1450 static void __vcd_cleanup_client(vcd_client_type_e type)
1452 int* client_list = NULL;
1453 int client_count = 0;
1460 if (VCD_CLIENT_TYPE_NORMAL == type) {
1461 ret = vcd_client_get_list(&client_list, &client_count);
1462 } else if (VCD_CLIENT_TYPE_WIDGET == type) {
1463 ret = vcd_client_widget_get_list(&client_list, &client_count);
1464 } else if (VCD_CLIENT_TYPE_MANAGER == type) {
1465 mgr_pid = vcd_client_manager_get_pid();
1466 client_list = &mgr_pid;
1468 if (-1 == mgr_pid) {
1469 SLOG(LOG_WARN, TAG_VCD, "[WARNING] Invalid Manager pid");
1474 if (0 == ret || mgr_pid > 0) {
1475 SLOG(LOG_INFO, TAG_VCD, "@@@ Clean up %s client ", type ? (type == 1) ? "Widget" : "Manager" : "Normal");
1476 if (NULL != client_list && client_count > 0) {
1477 for (i = 0; i < client_count; i++) {
1480 for (j = 0; j < g_list_length(g_proc_list); j++) {
1481 iter = g_list_nth(g_proc_list, j);
1483 if (*(client_list + i) == GPOINTER_TO_INT(iter->data)) {
1484 SLOG(LOG_INFO, TAG_VCD, "%s pid(%d) is running", type ? (type == 1) ? "Widget" : "Manager" : "Normal", *(client_list + i));
1491 if (false == exist) {
1492 SLOG(LOG_ERROR, TAG_VCD, "%s pid(%d) should be removed", type ? (type == 1) ? "Widget" : "Manager" : "Normal", *(client_list + i));
1493 if (VCD_CLIENT_TYPE_NORMAL == type)
1494 vcd_server_finalize(*(client_list + i));
1495 else if (VCD_CLIENT_TYPE_WIDGET == type)
1496 vcd_server_widget_finalize(*(client_list + i));
1498 vcd_server_mgr_finalize(mgr_pid);
1502 SLOG(LOG_INFO, TAG_VCD, "@@@");
1504 if (NULL != client_list && -1 == mgr_pid) {
1511 Eina_Bool vcd_cleanup_client_all(void *data)
1515 __vcd_cleanup_client(VCD_CLIENT_TYPE_NORMAL);
1516 __vcd_cleanup_client(VCD_CLIENT_TYPE_WIDGET);
1517 __vcd_cleanup_client(VCD_CLIENT_TYPE_MANAGER);
1519 if (0 == vcd_client_get_ref_count()) {
1520 SLOG(LOG_INFO, TAG_VCD, "[Server] Connected client list is empty");
1521 ecore_timer_add(0, __finalize_quit_ecore_loop, NULL);
1524 if (0 == vcd_client_get_list(&client_list, &client_count)) {
1525 SLOG(LOG_DEBUG, TAG_VCD, "@@@ Clean up client ");
1526 if (NULL != client_list && client_count > 0) {
1527 for (i = 0; i < client_count; i++) {
1530 for (j = 0; j < g_list_length(g_proc_list); j++) {
1531 iter = g_list_nth(g_proc_list, j);
1533 if (client_list[i] == GPOINTER_TO_INT(iter->data)) {
1534 SLOG(LOG_DEBUG, TAG_VCD, "pid(%d) is running", client_list[i]);
1541 if (false == exist) {
1542 SLOG(LOG_ERROR, TAG_VCD, "pid(%d) should be removed", client_list[i]);
1543 vcd_server_finalize(client_list[i]);
1546 result = vcdc_send_hello(client_list[i], VCD_CLIENT_TYPE_NORMAL);
1549 SLOG(LOG_DEBUG, TAG_VCD, "[Server] pid(%d) should be removed.", client_list[i]);
1550 vcd_server_finalize(client_list[i]);
1551 } else if (-1 == result) {
1552 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Hello result has error");
1557 SLOG(LOG_DEBUG, TAG_VCD, "@@@");
1559 if (NULL != client_list) {
1564 /* If app is in background state, app cannot response message. */
1565 if (0 == vcd_client_widget_get_list(&client_list, &client_count)) {
1566 SLOG(LOG_DEBUG, TAG_VCD, "@@@ Clean up widget");
1567 if (NULL != client_list && client_count > 0) {
1568 for (i = 0; i < client_count; i++) {
1571 for (j = 0; j < g_list_length(g_proc_list); j++) {
1572 iter = g_list_nth(g_proc_list, j);
1574 if (client_list[i] == GPOINTER_TO_INT(iter->data)) {
1575 SLOG(LOG_DEBUG, TAG_VCD, "widget pid(%d) is running", client_list[i]);
1582 if (false == exist) {
1583 SLOG(LOG_ERROR, TAG_VCD, "widget pid(%d) should be removed", client_list[i]);
1584 vcd_server_widget_finalize(client_list[i]);
1587 result = vcdc_send_hello(client_list[i], VCD_CLIENT_TYPE_WIDGET);
1590 SLOG(LOG_DEBUG, TAG_VCD, "[Server] widget pid(%d) should be removed.", client_list[i]);
1591 vcd_server_widget_finalize(client_list[i]);
1592 } else if (-1 == result) {
1593 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Hello result has error");
1598 SLOG(LOG_DEBUG, TAG_VCD, "@@@");
1601 if (NULL != client_list) {
1609 int mgr_pid = vcd_client_manager_get_pid();
1611 for (j = 0; j < g_list_length(g_proc_list); j++) {
1612 iter = g_list_nth(g_proc_list, j);
1614 if (mgr_pid == GPOINTER_TO_INT(iter->data)) {
1615 SLOG(LOG_DEBUG, TAG_VCD, "manager pid(%d) is running", mgr_pid);
1622 if (false == exist) {
1623 SLOG(LOG_ERROR, TAG_VCD, "manager pid (%d) should be removed", mgr_pid);
1624 vcd_server_mgr_finalize(mgr_pid);
1631 int vcd_server_get_service_state()
1633 return vcd_config_get_service_state();
1636 int vcd_server_get_foreground()
1639 vcd_config_get_foreground(&pid);
1643 static Eina_Bool __vcd_send_service_state(void *data)
1645 vcd_config_set_service_state(VCD_STATE_READY);
1646 vcdc_send_service_state(VCD_STATE_READY);
1648 SLOG(LOG_INFO, TAG_VCD, "[Server Success] success to send service status for READY");
1656 int vcd_server_mgr_initialize(int pid)
1658 /* check if pid is valid */
1659 if (false == vcd_client_manager_is_valid(pid)) {
1660 SLOG(LOG_ERROR, TAG_VCD, "[Server] old manager pid(%d) be removed", vcd_client_manager_get_pid());
1661 vcd_server_mgr_cancel();
1662 vcd_client_manager_unset();
1665 /* Add client information to client manager */
1666 int ret = vcd_client_manager_set(pid);
1668 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to add manager");
1669 return VCD_ERROR_OPERATION_FAILED;
1672 if (0 != vcdc_send_manager_pid(pid))
1673 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Fail to send manager pid");
1675 ecore_timer_add(0.05, __vcd_send_service_state, NULL);
1677 SLOG(LOG_ERROR, TAG_VCD, "[Server Success] Manager initialize : pid(%d)", pid);
1679 return VCD_ERROR_NONE;
1682 int vcd_server_mgr_finalize(int pid)
1684 /* check if pid is valid */
1685 if (false == vcd_client_manager_is_valid(pid)) {
1686 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] The manager pid(%d) is NOT valid", pid);
1687 return VCD_ERROR_INVALID_PARAMETER;
1690 /* Cancel recognition */
1691 vcd_server_mgr_cancel();
1693 if (0 != vcdc_send_manager_pid(-1))
1694 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Fail to send manager pid");
1696 /* Remove manager information */
1697 if (0 != vcd_client_manager_unset()) {
1698 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Fail to delete client");
1701 if (0 == vcd_client_get_ref_count()) {
1702 SLOG(LOG_INFO, TAG_VCD, "[Server] Connected client list is empty");
1703 ecore_timer_add(0, __finalize_quit_ecore_loop, NULL);
1706 SLOG(LOG_ERROR, TAG_VCD, "[Server Success] Manager Finalize : pid(%d)", pid);
1708 return VCD_ERROR_NONE;
1711 int vcd_server_mgr_set_command(int pid)
1713 if (0 != vcd_client_manager_set_command(pid)) {
1714 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] The manager pid(%d) is NOT valid", pid);
1715 return VCD_ERROR_INVALID_PARAMETER;
1717 return VCD_ERROR_NONE;
1720 int vcd_server_mgr_unset_command(int pid)
1722 if (0 != vcd_client_manager_unset_command(pid)) {
1723 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] The manager pid(%d) is NOT valid", pid);
1724 return VCD_ERROR_INVALID_PARAMETER;
1726 return VCD_ERROR_NONE;
1729 int vcd_server_mgr_set_demandable_client(int pid)
1731 /* check if pid is valid */
1732 if (false == vcd_client_manager_is_valid(pid)) {
1733 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] The manager pid(%d) is NOT valid", pid);
1734 return VCD_ERROR_INVALID_PARAMETER;
1737 GSList* client_list = NULL;
1738 if (0 != vc_info_parser_get_demandable_clients(&client_list)) {
1739 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to get demandable client");
1740 return VCD_ERROR_OPERATION_FAILED;
1743 /* Save client list */
1744 if (0 != vcd_client_manager_set_demandable_client(pid, client_list)) {
1745 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to set demandable client list");
1746 return VCD_ERROR_OPERATION_FAILED;
1749 return VCD_ERROR_NONE;
1752 int vcd_server_mgr_set_audio_type(int pid, const char* audio_type)
1754 /* check if pid is valid */
1755 if (false == vcd_client_manager_is_valid(pid)) {
1756 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] The manager pid(%d) is NOT valid", pid);
1757 return VCD_ERROR_INVALID_PARAMETER;
1761 vce_audio_type_e type = VCE_AUDIO_TYPE_PCM_S16_LE;
1765 ret = vcd_engine_get_audio_format(audio_type, &type, &rate, &channel);
1767 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to get audio format : %d", ret);
1768 return VCD_ERROR_OPERATION_FAILED;
1771 ret = vcd_recorder_set(audio_type, type, rate, channel);
1773 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to set audio in type : %d", ret);
1774 return VCD_ERROR_OPERATION_FAILED;
1777 return VCD_ERROR_NONE;
1780 int vcd_server_mgr_get_audio_type(int pid, char** audio_type)
1782 /* check if pid is valid */
1783 if (false == vcd_client_manager_is_valid(pid)) {
1784 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] The manager pid(%d) is NOT valid", pid);
1785 return VCD_ERROR_INVALID_PARAMETER;
1788 int ret = vcd_recorder_get(audio_type);
1790 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to get audio in type : %d", ret);
1791 return VCD_ERROR_OPERATION_FAILED;
1794 return VCD_ERROR_NONE;
1797 int vcd_server_mgr_set_client_info(int pid)
1799 /* check if pid is valid */
1800 if (false == vcd_client_manager_is_valid(pid)) {
1801 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] The manager pid(%d) is NOT valid", pid);
1802 return VCD_ERROR_INVALID_PARAMETER;
1805 int ret = vcd_client_save_client_info();
1807 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to save client info : %d", ret);
1808 return VCD_ERROR_OPERATION_FAILED;
1811 return VCD_ERROR_NONE;
1814 static int __reset_waiting_for_widget_recording(void)
1816 SLOG(LOG_ERROR, TAG_VCD, "[Server] Reset waiting for widget recording");
1817 // Delete timer to check that widget client is terminated
1818 if (g_check_widget_client_timer) {
1819 ecore_timer_del(g_check_widget_client_timer);
1820 g_check_widget_client_timer = NULL;
1822 // Reset flag to wait for recording from widget client
1823 vcd_client_widget_set_waiting_for_recording(-1, false);
1828 static Eina_Bool __send_waiting_timeout_error_to_manager(void* data)
1830 intptr_t ppid = (intptr_t)data;
1831 int pid = (int)ppid;
1832 SLOG(LOG_ERROR, TAG_VCD, "Widget client didn't send to start recording, pid(%d)", pid);
1833 __reset_waiting_for_widget_recording();
1835 vcdc_send_error_signal_to_manager(vcd_client_manager_get_pid(), VCD_ERROR_OPERATION_FAILED, "voice_engine.error.proc_fail");
1839 static Eina_Bool __send_waiting_timeout_start_recording(void* data)
1841 intptr_t ppid = (intptr_t)data;
1842 int pid = (int)ppid;
1843 SLOG(LOG_ERROR, TAG_VCD, "Widget client didn't send to start recording, pid(%d)", pid);
1845 int ret = __start_internal_recognition();
1847 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to start recognition : %d", ret);
1854 static int __set_waiting_for_widget_recording(int pid)
1856 SLOG(LOG_ERROR, TAG_VCD, "[Server] Set waiting for widget recording, pid(%d)", pid);
1858 // Check if the app included widget client is terminated or not. If it is terminated, vcd_server_widget_finalize() function will be called
1859 // In that function, it will start recording
1860 intptr_t ppid = (intptr_t)pid;
1861 g_check_widget_client_timer = ecore_timer_add(2.0, __send_waiting_timeout_start_recording, (void*)ppid);
1863 // Set flag to wait for recording from widget client
1864 vcd_client_widget_set_waiting_for_recording(pid, true);
1868 static int __start_internal_recognition()
1871 __reset_waiting_for_widget_recording();
1873 if (0 != vcd_client_command_collect_command()) {
1874 SLOG(LOG_ERROR, TAG_VCD, "[Client Data ERROR] Fail to collect command");
1875 /* Send error cb to manager */
1876 int pid = vcd_client_widget_get_foreground_pid();
1878 vcdc_send_error_signal_to_manager(vcd_client_manager_get_pid(), VCD_ERROR_OPERATION_FAILED, "voice_framework.error.vcfw.collect_command_fail");
1879 return VCD_ERROR_OPERATION_FAILED;
1882 /* 3. Set command to engine */
1883 ret = vcd_engine_set_commands();
1885 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to set commands : %d", ret);
1886 /* Send error cb to manager */
1887 int pid = vcd_client_widget_get_foreground_pid();
1889 vcdc_send_error_signal_to_manager(vcd_client_manager_get_pid(), VCD_ERROR_OPERATION_FAILED, "voice_framework.error.engine.set_commands_fail");
1890 return VCD_ERROR_OPERATION_FAILED;
1893 SLOG(LOG_ERROR, TAG_VCD, "[Server Success] Set command");
1895 bool stop_by_silence = true;
1896 if (VCD_RECOGNITION_MODE_MANUAL == vcd_client_get_recognition_mode()) {
1897 stop_by_silence = false;
1900 vcd_client_manager_set_result_text(NULL);
1902 /* 4. start recognition */
1903 ret = vcd_engine_recognize_start(stop_by_silence);
1905 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to start recognition : result(%d)", ret);
1906 /* Send error cb to manager */
1907 int pid = vcd_client_widget_get_foreground_pid();
1909 vcdc_send_error_signal_to_manager(vcd_client_manager_get_pid(), VCD_ERROR_OPERATION_FAILED, "voice_framework.error.engine.start_fail");
1910 return VCD_ERROR_OPERATION_FAILED;
1913 SLOG(LOG_ERROR, TAG_VCD, "[Server Success] Start engine");
1916 /* 5. recorder start */
1917 ret = vcd_recorder_start();
1919 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to start recorder : result(%d)", ret);
1920 vcd_engine_recognize_cancel();
1921 /* Send error cb to manager */
1922 int pid = vcd_client_widget_get_foreground_pid();
1924 vcdc_send_error_signal_to_manager(vcd_client_manager_get_pid(), VCD_ERROR_OPERATION_FAILED, "voice_framework.error.vcfw.send_rc_fail");
1929 vcd_config_set_service_state(VCD_STATE_RECORDING);
1930 vcdc_send_service_state(VCD_STATE_RECORDING);
1932 SLOG(LOG_ERROR, TAG_VCD, "[Server Success] Start recognition(%d)", stop_by_silence);
1937 static Eina_Bool __vcd_request_show_tooltip(void *data)
1939 int pid = vcd_client_widget_get_foreground_pid();
1941 SLOG(LOG_ERROR, TAG_VCD, "[Server] Request tooltip show and widget command, show(%d)", (bool)data);
1942 vcdc_send_show_tooltip(pid, (bool)data);
1948 int vcd_server_mgr_start(vcd_recognition_mode_e recognition_mode, bool exclusive_cmd, bool start_by_client)
1950 /* 1. check current state */
1951 vcd_state_e state = vcd_config_get_service_state();
1953 if (VCD_STATE_READY != state && VCD_STATE_SYNTHESIZING != state) {
1954 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Current state is not ready and not synthesizine, state(%d)", state);
1955 return VCD_ERROR_INVALID_STATE;
1957 if (-1 == vcd_client_manager_get_pid()) {
1958 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Manager is NOT available.");
1959 return VCD_ERROR_OPERATION_FAILED;
1961 __reset_waiting_for_widget_recording();
1963 SLOG(LOG_ERROR, TAG_VCD, "[Server] set recognition mode = %d", recognition_mode);
1964 vcd_client_set_recognition_mode(recognition_mode);
1966 if (false == exclusive_cmd) {
1967 vcd_client_update_foreground_pid();
1968 /* Notify show tooltip */
1969 if (1 == vcd_config_get_command_type_enabled(VC_COMMAND_TYPE_WIDGET)) {
1970 int pid = vcd_client_widget_get_foreground_pid();
1972 SLOG(LOG_ERROR, TAG_VCD, "[Server] Request tooltip show and widget command");
1973 ecore_timer_add(0, __vcd_request_show_tooltip, (void*)true);
1975 __set_waiting_for_widget_recording(pid);
1980 vcd_client_manager_set_exclusive(exclusive_cmd);
1984 if (true == start_by_client) {
1985 /* Get foreground pid */
1986 if (0 != vcd_config_get_foreground(&fg_pid)) {
1987 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to get foreground");
1990 /* Set client exclusive option */
1991 if (0 != vcd_client_set_exclusive_command(fg_pid)) {
1992 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to set exclusive command");
1996 SLOG(LOG_ERROR, TAG_VCD, "[Server] start internal recognition");
1998 int ret = __start_internal_recognition();
2000 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to start recognition : %d", ret);
2004 if (true == start_by_client) {
2005 vcd_client_unset_exclusive_command(fg_pid);
2008 SLOG(LOG_ERROR, TAG_VCD, "[Server Success] start internal recognition");
2009 return VCD_ERROR_NONE;
2012 int vcd_server_mgr_stop()
2014 /* 1. Check current state is recording */
2015 if (VCD_STATE_RECORDING != vcd_config_get_service_state()) {
2016 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Current state is not recording");
2017 return VCD_ERROR_INVALID_STATE;
2019 if (-1 == vcd_client_manager_get_pid()) {
2020 SLOG(LOG_INFO, TAG_VCD, "[Server] Manager is NOT available.");
2021 return VCD_ERROR_OPERATION_FAILED;
2023 SLOG(LOG_ERROR, TAG_VCD, "[Server] stop internal recognition");
2026 /* 2. Stop recorder */
2027 vcd_recorder_stop();
2030 /* 3. Stop engine recognition */
2031 int ret = vcd_engine_recognize_stop();
2033 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to stop recognition : %d", ret);
2036 /* 4. Set original mode */
2037 vcd_config_set_service_state(VCD_STATE_PROCESSING);
2038 vcdc_send_service_state(VCD_STATE_PROCESSING);
2040 SLOG(LOG_ERROR, TAG_VCD, "[Server Success] stop internal recognition");
2041 return VCD_ERROR_NONE;
2044 int vcd_server_mgr_cancel()
2046 if (-1 == vcd_client_manager_get_pid()) {
2047 SLOG(LOG_ERROR, TAG_VCD, "[Server] Manager is NOT available.");
2048 return VCD_ERROR_OPERATION_FAILED;
2051 if (g_restart_timer != NULL) {
2052 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Delete restart engine timer");
2053 ecore_timer_del(g_restart_timer);
2054 g_restart_timer = NULL;
2057 /* 1. Check current state */
2058 vcd_state_e state = vcd_config_get_service_state();
2059 if (VCD_STATE_READY == state) {
2060 SLOG(LOG_INFO, TAG_VCD, "[Server] Current state is READY");
2061 vcd_recorder_stop();
2063 if (false == vcd_client_manager_get_exclusive()) {
2064 if (1 == vcd_config_get_command_type_enabled(VC_COMMAND_TYPE_WIDGET)) {
2065 int pid = vcd_client_widget_get_foreground_pid();
2067 SLOG(LOG_INFO, TAG_VCD, "[Server] Request tooltip hide");
2068 ecore_timer_add(0, __vcd_request_show_tooltip, (void*)false);
2073 vcdc_send_service_state(VCD_STATE_READY);
2074 return VCD_ERROR_NONE;
2076 SLOG(LOG_ERROR, TAG_VCD, "[Server] cancel internal recognition");
2079 /* 2. Stop recorder */
2080 vcd_recorder_stop();
2083 /* 3. Cancel engine */
2084 int ret = vcd_engine_recognize_cancel();
2086 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Fail to cancel : %d", ret);
2089 if (false == vcd_client_manager_get_exclusive()) {
2090 if (1 == vcd_config_get_command_type_enabled(VC_COMMAND_TYPE_WIDGET)) {
2091 int pid = vcd_client_widget_get_foreground_pid();
2093 SLOG(LOG_INFO, TAG_VCD, "[Server] Request tooltip hide");
2094 ecore_timer_add(0, __vcd_request_show_tooltip, (void*)false);
2098 vcd_client_manager_set_exclusive(false);
2102 vcd_config_set_service_state(VCD_STATE_READY);
2103 vcdc_send_service_state(VCD_STATE_READY);
2105 SLOG(LOG_ERROR, TAG_VCD, "[Server Success] cancel internal recognition");
2106 return VCD_ERROR_NONE;
2110 int vcd_server_mgr_result_select()
2112 __vcd_send_selected_result(NULL);
2114 return VCD_ERROR_NONE;
2117 int vcd_server_mgr_set_domain(int pid, const char* domain)
2119 /* check if pid is valid */
2120 if (false == vcd_client_manager_is_valid(pid)) {
2121 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] The manager pid(%d) is NOT valid", pid);
2122 return VCD_ERROR_INVALID_PARAMETER;
2125 vcd_state_e state = vcd_config_get_service_state();
2126 if (VCD_STATE_READY != state) {
2127 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Current state is not ready");
2128 return VCD_ERROR_INVALID_STATE;
2131 /* Set domain to engine */
2132 int ret = vcd_engine_set_domain(pid, domain);
2134 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to set domain : %d", ret);
2136 SLOG(LOG_INFO, TAG_VCD, "[Server SUCCESS] Set domain");
2142 int vcd_server_mgr_set_private_data(int pid, const char* key, const char* data)
2144 /* check if pid is valid */
2145 if (false == vcd_client_manager_is_valid(pid)) {
2146 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] The manager pid(%d) is NOT valid", pid);
2147 return VCD_ERROR_INVALID_PARAMETER;
2150 vcd_state_e state = vcd_config_get_service_state();
2151 if (VCD_STATE_READY != state) {
2152 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Current state is not ready");
2153 return VCD_ERROR_INVALID_STATE;
2156 /* Set private data to engine */
2157 int ret = vcd_engine_set_private_data(pid, key, data);
2159 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to set private data : %d", ret);
2161 SLOG(LOG_INFO, TAG_VCD, "[Server SUCCESS] Set private data");
2167 int vcd_server_mgr_get_private_data(int pid, const char* key, char** data)
2169 /* check if pid is valid */
2170 if (false == vcd_client_manager_is_valid(pid)) {
2171 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] The manager pid(%d) is NOT valid", pid);
2172 return VCD_ERROR_INVALID_PARAMETER;
2174 vcd_state_e state = vcd_config_get_service_state();
2175 if (VCD_STATE_READY != state) {
2176 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Current state is not ready");
2177 return VCD_ERROR_INVALID_STATE;
2180 /* Get private data to engine */
2181 int ret = vcd_engine_get_private_data(pid, key, data);
2183 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to get private data : %d", ret);
2185 SLOG(LOG_INFO, TAG_VCD, "[Server SUCCESS] Set private data");
2191 int vcd_server_mgr_send_specific_engine_request(int pid, const char* engine_app_id, const char* event, const char* request)
2193 /* check if pid is valid */
2194 if (false == vcd_client_manager_is_valid(pid)) {
2195 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] The manager pid(%d) is NOT valid", pid);
2196 return VCD_ERROR_INVALID_PARAMETER;
2198 vcd_state_e state = vcd_config_get_service_state();
2199 if (VCD_STATE_READY != state && VCD_STATE_SYNTHESIZING != state) {
2200 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Current state is not ready and not synthesizing, state(%d)", state);
2201 return VCD_ERROR_INVALID_STATE;
2204 /* Get private data to engine */
2205 int ret = vcd_engine_send_specific_engine_request(engine_app_id, event, request);
2207 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to set specific engine request : %d", ret);
2209 SLOG(LOG_INFO, TAG_VCD, "[Server SUCCESS] Set specific engine request ");
2215 int vcd_server_mgr_do_action(int pid, int type, const char* action)
2219 /* check if pid is valid */
2220 if (false == vcd_client_manager_is_valid(pid)) {
2221 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] The manager pid(%d) is NOT valid", pid);
2222 return VCD_ERROR_INVALID_PARAMETER;
2225 vcd_state_e state = vcd_config_get_service_state();
2226 if (VCD_STATE_READY != state && VCD_STATE_SYNTHESIZING != state) {
2227 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Current state is not ready and not synthesizing, state(%d)", state);
2228 return VCD_ERROR_INVALID_STATE;
2231 /* Request do action to engine */
2232 if (VCD_SEND_EVENT_TYPE_TEXT == type)
2233 ret = vcd_engine_process_text(pid, action);
2234 else if (VCD_SEND_EVENT_TYPE_LIST_EVENT == type)
2235 ret = vcd_engine_process_list_event(pid, action);
2236 else if (VCD_SEND_EVENT_TYPE_HAPTIC_EVENT == type)
2237 ret = vcd_engine_process_haptic_event(pid, action);
2240 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to process do action : %d", ret);
2242 vcd_config_set_service_state(VCD_STATE_PROCESSING);
2243 vcdc_send_service_state(VCD_STATE_PROCESSING);
2244 SLOG(LOG_INFO, TAG_VCD, "[Server SUCCESS] Process do action");
2250 int vcd_server_mgr_set_disabled_command_type(int pid, int disabled_cmd_type)
2254 /* check if pid is valid */
2255 if (false == vcd_client_manager_is_valid(pid)) {
2256 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] The manager pid(%d) is NOT valid", pid);
2257 return VCD_ERROR_INVALID_PARAMETER;
2260 vcd_state_e state = vcd_config_get_service_state();
2261 if (VCD_STATE_READY != state) {
2262 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Current state is not ready");
2263 return VCD_ERROR_INVALID_STATE;
2266 ret = vcd_config_set_disabled_command_type(disabled_cmd_type);
2268 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to set command type");
2270 SLOG(LOG_ERROR, TAG_VCD, "[Server] Set command type(%d)", disabled_cmd_type);
2277 /* for TTS feedback */
2278 int vcd_server_mgr_start_feedback(void)
2280 /* check current state */
2281 /* not Recording??? */
2283 if (-1 == vcd_client_manager_get_pid()) {
2284 SLOG(LOG_ERROR, TAG_VCD, "[Server] Manager is NOT available");
2285 return VCD_ERROR_OPERATION_FAILED;
2288 SLOG(LOG_INFO, TAG_VCD, "[Server] start TTS feedback");
2290 /* check there is TTS buffer to be spoken */
2292 return VCD_ERROR_NONE;
2295 int vcd_server_mgr_stop_feedback(void)
2297 /* check current state */
2298 /* not Recording??? */
2300 if (-1 == vcd_client_manager_get_pid()) {
2301 SLOG(LOG_ERROR, TAG_VCD, "[Server] Manager is NOT available");
2302 return VCD_ERROR_OPERATION_FAILED;
2305 SLOG(LOG_INFO, TAG_VCD, "[Server] stop TTS feedback");
2307 return VCD_ERROR_NONE;
2310 int vcd_server_mgr_send_audio_streaming(int pid, int event, unsigned char* buffer, unsigned int len)
2312 SLOG(LOG_INFO, TAG_VCD, "[DEBUG] Send Audio Streaming from Multi-assistant. event(%d), buffer(%p), len(%d)", event, &buffer, len);
2315 if (VCD_AUDIO_STREAMING_EVENT_START == event) {
2316 ret = vcd_recorder_start_streaming();
2318 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to start streaming, ret(%d)", ret);
2323 ret = vcd_recorder_send_streaming((const void*)buffer, (const unsigned int)len);
2325 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to start streaming, ret(%d)", ret);
2329 if (VCD_AUDIO_STREAMING_EVENT_FINISH == event) {
2330 ret = vcd_recorder_stop_streaming();
2332 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to stop streaming, ret(%d)", ret);
2337 return VCD_ERROR_NONE;
2340 int vcd_server_mgr_change_system_volume(int pid, vcd_system_volume_event_e system_volume_event)
2342 SLOG(LOG_INFO, TAG_VCD, "[DEBUG] change system volume, system volume event(%d)", system_volume_event);
2345 if (VCD_SYSTEM_VOLUME_EVENT_CHANGE == system_volume_event) {
2346 ret = vcd_recorder_change_system_volume();
2348 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to change system volume, ret(%d)", ret);
2351 } else if (VCD_SYSTEM_VOLUME_EVENT_RECOVER == system_volume_event) {
2352 ret = vcd_recorder_recover_system_volume();
2354 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to recover system volume, ret(%d)", ret);
2364 * VC Server Functions for Client
2366 int vcd_server_initialize(int pid)
2368 if (false == vcd_engine_is_available_engine()) {
2369 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] No Engine");
2370 return VCD_ERROR_ENGINE_NOT_FOUND;
2373 /* check if pid is valid */
2374 if (true == vcd_client_is_available(pid)) {
2375 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] The pid is already exist");
2376 return VCD_ERROR_NONE;
2379 /* Add client information to client manager */
2380 if (0 != vcd_client_add(pid)) {
2381 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to add client info");
2382 return VCD_ERROR_OPERATION_FAILED;
2385 SLOG(LOG_INFO, TAG_VCD, "[Server Success] Client Initialize : pid(%d)", pid);
2387 return VCD_ERROR_NONE;
2390 int vcd_server_finalize(int pid)
2392 /* check if pid is valid */
2393 if (false == vcd_client_is_available(pid)) {
2394 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] pid is NOT valid ");
2395 return VCD_ERROR_INVALID_PARAMETER;
2398 /* Remove client information */
2399 if (0 != vcd_client_delete(pid)) {
2400 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Fail to delete client");
2403 if (0 == vcd_client_get_ref_count()) {
2404 SLOG(LOG_INFO, TAG_VCD, "[Server] Connected client list is empty");
2405 ecore_timer_add(0, __finalize_quit_ecore_loop, NULL);
2408 SLOG(LOG_INFO, TAG_VCD, "[Server Success] Client Finalize : pid(%d)", pid);
2410 return VCD_ERROR_NONE;
2413 int vcd_server_set_command(int pid, vc_cmd_type_e cmd_type)
2415 /* check if pid is valid */
2416 if (false == vcd_client_is_available(pid)) {
2417 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] pid is NOT valid ");
2418 return VCD_ERROR_INVALID_PARAMETER;
2421 if (0 != vcd_client_set_command_type(pid, cmd_type)) {
2422 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to set command type : pid(%d), cmd_type(%d)", pid, cmd_type);
2423 return VCD_ERROR_OPERATION_FAILED;
2429 int vcd_server_unset_command(int pid, vc_cmd_type_e cmd_type)
2431 /* check if pid is valid */
2432 if (false == vcd_client_is_available(pid)) {
2433 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] pid is NOT valid ");
2434 return VCD_ERROR_INVALID_PARAMETER;
2437 if (0 != vcd_client_unset_command_type(pid, cmd_type)) {
2438 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to unset command type : pid(%d), cmd_type(%d)", pid, cmd_type);
2439 return VCD_ERROR_OPERATION_FAILED;
2445 int vcd_server_set_foreground(int pid, bool value)
2447 /* check if pid is valid */
2448 if (false == vcd_client_is_available(pid) && false == vcd_client_widget_is_available(pid)) {
2449 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] pid is NOT valid ");
2450 return VCD_ERROR_INVALID_PARAMETER;
2453 if (0 != vcd_config_set_foreground(pid, value)) {
2454 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to set foreground : pid(%d), value(%d)", pid, value);
2455 return VCD_ERROR_OPERATION_FAILED;
2461 static int __vcd_server_launch_manager_app()
2464 bool running = false;
2467 ret = vcd_client_manager_get_appid(&appid);
2468 if (0 != ret || NULL == appid) {
2469 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to get manager appid");
2470 return VCD_ERROR_OPERATION_FAILED;
2472 ret = app_manager_is_running(appid, &running);
2474 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to check running with appid(%s)", appid);
2477 return VCD_ERROR_OPERATION_FAILED;
2479 if (false == running) {
2480 int tmp_ret = __vcd_is_package_installed(appid);
2481 if (false == tmp_ret) {
2482 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] manager app is not installed, appid(%s)", appid);
2484 ret = __vcd_activate_app_by_appcontrol(appid);
2486 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to activate app");
2491 SLOG(LOG_ERROR, TAG_VCD, "Launch vc manager app: appid(%s)", appid);
2494 ret = __vcd_resume_app(appid);
2496 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to resume app");
2501 SLOG(LOG_ERROR, TAG_VCD, "Resume vc manager app: appid(%s)", appid);
2507 return VCD_ERROR_NONE;
2510 int vcd_server_set_server_dialog(int pid, const char* app_id, const char* credential)
2512 /* check if pid is valid */
2513 if (false == vcd_client_is_available(pid)) {
2514 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] pid is NOT valid ");
2515 return VCD_ERROR_INVALID_PARAMETER;
2518 int ret = vcd_engine_set_server_dialog(app_id, credential);
2520 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to set server dialog, pid(%d), app_id(%s), ret(%d)", pid, app_id, ret);
2521 vcd_client_set_server_dialog(pid, false);
2524 SLOG(LOG_ERROR, TAG_VCD, "[Success] Set server dialog, pid(%d), app_id(%s)", pid, app_id);
2526 if (0 != strncmp(credential, "#NULL", strlen(credential))) {
2527 ret = vcd_client_set_server_dialog(pid, true);
2529 SLOG(LOG_INFO, TAG_VCD, "[Server] Set to true for server dialog, app_id(%s)", app_id);
2531 ret = vcd_client_set_server_dialog(pid, false);
2533 SLOG(LOG_INFO, TAG_VCD, "[Server] Set to false for server dialog, app_id(%s)", app_id);
2539 int vcd_server_dialog(int pid, const char* disp_text, const char* utt_text, int continuous)
2541 /* check if pid is valid */
2542 if (false == vcd_client_is_available(pid) && false == vcd_client_widget_is_available(pid)) {
2543 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] pid is NOT valid ");
2544 return VCD_ERROR_INVALID_PARAMETER;
2547 bool is_server_dialog = false;
2548 int ret = vcd_client_get_server_dialog(pid, &is_server_dialog);
2550 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to get server dialog, pid(%d), ret(%d)", pid, ret);
2553 if (true == is_server_dialog) {
2554 /* ++ Request tts event to engine */
2556 /* -- Request tts event to engine */
2558 ret = __vcd_server_launch_manager_app();
2560 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);
2564 ret = vcdc_send_dialog(vcd_client_manager_get_pid(), pid, disp_text, utt_text, continuous);
2566 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);
2573 int vcd_server_is_system_command_valid(int pid, int* is_sys_cmd_valid)
2575 /* check if pid is valid */
2576 if (false == vcd_client_is_available(pid) && false == vcd_client_widget_is_available(pid)) {
2577 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] pid is NOT valid ");
2578 return VCD_ERROR_INVALID_PARAMETER;
2581 /* check if system command is valid */
2582 if (true == vcd_client_manager_is_system_command_valid(vcd_client_manager_get_pid()))
2583 *is_sys_cmd_valid = true;
2585 *is_sys_cmd_valid = false;
2590 static void __start_tts_request_thread(void* data, Ecore_Thread* thread)
2592 SLOG(LOG_INFO, TAG_VCD, "[SUCCESS] Start tts request thread");
2593 vc_tts_text_data_s* tts_text_data = NULL;
2599 /* Get tts text data */
2600 ret = vcd_data_get_first_tts_text_data(&tts_text_data);
2601 if (0 != ret || NULL == tts_text_data) {
2603 if (0 >= vcd_data_get_tts_text_data_size()) {
2604 SLOG(LOG_INFO, TAG_VCD, "[DEBUG] No tts text data");
2607 SLOG(LOG_INFO, TAG_VCD, "[INFO] tts text data is just incoming");
2612 vcd_state_e state = vcd_config_get_service_state();
2613 if (VCD_STATE_READY != state) {
2614 if (0 == cnt++ % 10)
2615 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Waiting to request TTS, state(%d)", state);
2622 /* Set service state to synthesizing */
2623 vcd_config_set_service_state(VCD_STATE_SYNTHESIZING);
2625 /* Set current uid */
2626 g_current_uid = tts_text_data->uid;
2628 /* Request tts to engine */
2629 ret = vcd_engine_request_tts(tts_text_data->pid, tts_text_data->utt_id, tts_text_data->text, tts_text_data->language);
2631 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to request tts : %d", ret);
2633 SLOG(LOG_INFO, TAG_VCD, "[Server SUCCESS] request tts, uid(%d) pid(%d), text(%s), language(%s), utt_id(%d)",
2634 tts_text_data->uid, tts_text_data->pid, tts_text_data->text, tts_text_data->language, tts_text_data->utt_id);
2636 /* clear tts text data after use */
2637 vcd_data_clear_tts_text_data(&tts_text_data);
2642 static void __end_tts_request_thread(void* data, Ecore_Thread* thread)
2644 SLOG(LOG_INFO, TAG_VCD, "[SUCCESS] End tts request thread");
2645 g_tts_thread = NULL;
2648 int vcd_server_request_tts(int pid, const char* text, const char* language, int to_vcm, int* utt_id)
2650 /* check if pid is valid */
2651 if (false == vcd_client_is_available(pid)) {
2652 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] pid is NOT valid ");
2653 return VCD_ERROR_INVALID_PARAMETER;
2656 vcd_state_e state = vcd_config_get_service_state();
2657 if (VCD_STATE_READY != state && VCD_STATE_SYNTHESIZING != state) {
2658 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Current state is not ready, state(%d)", state);
2659 return VCD_ERROR_INVALID_STATE;
2663 g_current_utt_id = (g_current_utt_id + 1) % 1000;
2664 *utt_id = g_current_utt_id;
2666 uid = pid * 1000 + g_current_utt_id;
2668 uid = vcd_client_manager_get_pid() * 1000 + g_current_utt_id;
2670 SLOG(LOG_INFO, TAG_VCD, "[Server INFO] pid(%d), text(%s), language(%s), to_vcm(%d), ", pid, text, language, to_vcm);
2671 SLOG(LOG_INFO, TAG_VCD, "[Server INFO] current_uid(%d), current_utt_id(%d)", uid, g_current_utt_id);
2673 vc_tts_text_data_s* tts_text_data;
2674 tts_text_data = (vc_tts_text_data_s*)calloc(1, sizeof(vc_tts_text_data_s));
2675 if (!tts_text_data) {
2676 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to callocate memory ");
2677 return VCD_ERROR_OUT_OF_MEMORY;
2679 tts_text_data->uid = uid;
2680 tts_text_data->pid = pid;
2681 tts_text_data->utt_id = g_current_utt_id;
2682 tts_text_data->text = strdup(text);
2683 tts_text_data->language = strdup(language);
2685 int ret = vcd_data_add_tts_text_data(tts_text_data->uid, tts_text_data);
2687 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to add tts text data : %d", ret);
2690 bool is_canceled = ecore_thread_check(g_tts_thread);
2691 if (NULL == g_tts_thread || TRUE == is_canceled) {
2692 SLOG(LOG_INFO, TAG_VCD, "[Server INFO] ecore thread run : start_tts_request_thread ");
2693 g_tts_thread = ecore_thread_run(__start_tts_request_thread, __end_tts_request_thread, NULL, NULL);
2699 int vcd_server_cancel_tts(int pid, int utt_id)
2701 /* check if pid is valid */
2702 if (false == vcd_client_is_available(pid)) {
2703 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] pid is NOT valid ");
2704 return VCD_ERROR_INVALID_PARAMETER;
2707 vcd_state_e state = vcd_config_get_service_state();
2708 if (VCD_STATE_READY != state && VCD_STATE_SYNTHESIZING != state) {
2709 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Current state is not ready, state(%d)", state);
2710 return VCD_ERROR_INVALID_STATE;
2713 vc_tts_text_data_s* tts_text_data = NULL;
2715 int uid = pid * 1000 + utt_id;
2716 int ret = vcd_data_get_tts_text_data(uid, &tts_text_data);
2718 SLOG(LOG_WARN, TAG_VCD, "[Server WARN] No data in vcd tts text queue");
2720 SLOG(LOG_INFO, TAG_VCD, "[Server] Clear tts text data, pid(%d), utt_id(%d), text(%s)", pid, utt_id, tts_text_data->text);
2721 vcd_data_clear_tts_text_data(&tts_text_data);
2724 /* Request tts to engine */
2725 ret = vcd_engine_cancel_tts(pid, utt_id);
2727 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to cancel tts : %d", ret);
2729 SLOG(LOG_INFO, TAG_VCD, "[Server SUCCESS] request tts, pid(%d), utt_id(%d)", pid, utt_id);
2735 int vcd_server_get_tts_audio_format(int pid, int* rate, int* channel, int* audio_type)
2737 /* check if pid is valid */
2738 if (false == vcd_client_is_available(pid)) {
2739 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] pid is NOT valid ");
2740 return VCD_ERROR_INVALID_PARAMETER;
2743 vcd_state_e state = vcd_config_get_service_state();
2744 if (VCD_STATE_READY != state && VCD_STATE_SYNTHESIZING != state) {
2745 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Current state is not ready and not synthesizing, state(%d)", state);
2746 return VCD_ERROR_INVALID_STATE;
2749 /* Request tts to engine */
2750 int ret = vcd_engine_get_tts_audio_format(rate, channel, audio_type);
2752 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to get tts audio format : %d", ret);
2754 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);
2761 int vcd_server_set_exclusive_command(int pid, bool value)
2763 /* check if pid is valid */
2764 if (false == vcd_client_is_available(pid)) {
2765 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] pid is NOT valid ");
2766 return VCD_ERROR_INVALID_PARAMETER;
2769 if (true == value) {
2770 if (0 != vcd_client_set_exclusive_command(pid)) {
2771 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to set exclusive command : pid(%d)", pid);
2772 return VCD_ERROR_OPERATION_FAILED;
2775 if (0 != vcd_client_unset_exclusive_command(pid)) {
2776 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to unset exclusive command : pid(%d)", pid);
2777 return VCD_ERROR_OPERATION_FAILED;
2784 int vcd_server_request_start(int pid, bool stop_by_silence)
2786 /* check if pid is valid */
2787 if (false == vcd_client_is_available(pid)) {
2788 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] pid(%d) is NOT foreground client", pid);
2789 return VCD_ERROR_INVALID_PARAMETER;
2793 /* Check current state */
2794 vcd_state_e state = vcd_config_get_service_state();
2796 /* Service state should be ready */
2797 if (VCD_STATE_READY != state) {
2798 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Current state is not Ready : pid(%d)", pid);
2799 return VCD_ERROR_INVALID_STATE;
2802 if (-1 != vcd_client_manager_get_pid()) {
2803 /* Check current pid is valid */
2804 if (false == vcd_client_manager_check_demandable_client(pid)) {
2805 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Current client is NOT available : pid(%d)", pid);
2806 return VCD_ERROR_INVALID_PARAMETER;
2810 ret = vcd_server_mgr_start(stop_by_silence, false);
2812 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Fail to start recognition");
2813 return VCD_ERROR_INVALID_PARAMETER;
2819 int vcd_server_request_stop(int pid)
2822 /* Check current state */
2823 vcd_state_e state = vcd_config_get_service_state();
2825 /* Service state should be ready */
2826 if (VCD_STATE_RECORDING != state) {
2827 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Current state is not Recording : 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_stop();
2841 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Fail to start recognition");
2842 return VCD_ERROR_OPERATION_FAILED;
2845 return VCD_ERROR_NONE;
2848 int vcd_server_request_cancel(int pid)
2851 /* Check current state */
2852 vcd_state_e state = vcd_config_get_service_state();
2854 /* Service state should be recording or processing */
2855 if (VCD_STATE_RECORDING != state && VCD_STATE_PROCESSING != state) {
2856 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Current state is not Recording or Processing : 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_cancel();
2870 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Fail to start recognition");
2871 return VCD_ERROR_OPERATION_FAILED;
2874 return VCD_ERROR_NONE;
2879 * VC Server Functions for Widget lib
2881 int vcd_server_widget_initialize(int pid)
2883 if (false == vcd_engine_is_available_engine()) {
2884 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] No Engine");
2885 return VCD_ERROR_ENGINE_NOT_FOUND;
2888 /* check if pid is valid */
2889 if (true == vcd_client_widget_is_available(pid)) {
2890 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] The pid is already exist");
2891 return VCD_ERROR_NONE;
2894 /* Add client information to client manager */
2895 if (0 != vcd_client_widget_add(pid)) {
2896 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to add client info");
2897 return VCD_ERROR_OPERATION_FAILED;
2900 SLOG(LOG_INFO, TAG_VCD, "[Server Success] Initialize widget : pid(%d)", pid);
2902 return VCD_ERROR_NONE;
2905 static void __vcd_server_widget_start_recording(void *data)
2907 SLOG(LOG_ERROR, TAG_VCD, "[Server INFO] start recording");
2909 if (0 != __start_internal_recognition()) {
2910 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to start recognition");
2914 int vcd_server_widget_finalize(int pid)
2916 /* check if pid is valid */
2917 if (false == vcd_client_widget_is_available(pid)) {
2918 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] pid is NOT valid ");
2919 if (0 == vcd_client_get_ref_count()) {
2920 SLOG(LOG_ERROR, TAG_VCD, "[Server] connected client list is empty, vc-service will be terminated");
2921 ecore_timer_add(0, __finalize_quit_ecore_loop, NULL);
2924 return VCD_ERROR_INVALID_PARAMETER;
2927 /* Remove client information */
2928 if (0 != vcd_client_widget_delete(pid)) {
2929 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Fail to delete client");
2932 if (0 == vcd_client_get_ref_count()) {
2933 SLOG(LOG_ERROR, TAG_VCD, "[Server] connected client list is empty, vc-service will be terminated");
2934 ecore_timer_add(0, __finalize_quit_ecore_loop, NULL);
2938 bool is_waiting = false;
2939 if (0 != vcd_client_widget_get_waiting_for_recording(pid, &is_waiting)) {
2940 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Fail to get waiting to recording");
2943 if (true == is_waiting) {
2944 SLOG(LOG_ERROR, TAG_VCD, "[Server INFO] invoke to start recording");
2945 ecore_main_loop_thread_safe_call_async(__vcd_server_widget_start_recording, NULL);
2947 return VCD_ERROR_NONE;
2950 int vcd_server_widget_start_recording(int pid, bool widget_command)
2952 /* check if pid is valid */
2953 if (false == vcd_client_widget_is_available(pid)) {
2954 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] pid is NOT valid ");
2955 return VCD_ERROR_INVALID_PARAMETER;
2959 if (0 != vcd_client_widget_get_waiting_for_recording(pid, &waiting) || false == waiting) {
2960 SLOG(LOG_ERROR, TAG_VCD, "[Server] Server is not waiting for recording, pid(%d), waiting(%d)", pid, waiting);
2964 if (true == widget_command) {
2965 vcd_client_widget_set_command(pid);
2966 SLOG(LOG_INFO, TAG_VCD, "[Server] widget command is available");
2968 vcd_client_widget_unset_command(pid);
2969 SLOG(LOG_WARN, TAG_VCD, "[Server] widget command is NOT available");
2972 SLOG(LOG_ERROR, TAG_VCD, "[Server] start internal recognition : %d", widget_command);
2973 int ret = __start_internal_recognition();
2975 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to start recognition : %d", ret);
2976 ecore_timer_add(0, __vcd_request_show_tooltip, (void*)false);
2982 int vcd_server_widget_start(int pid, bool stop_by_silence)
2984 /* check if pid is valid */
2985 int fore_pid = vcd_client_widget_get_foreground_pid();
2986 if (pid != fore_pid) {
2987 SLOG(LOG_ERROR, TAG_VCD, "[Server] pid is NOT foreground");
2988 return VCD_ERROR_INVALID_PARAMETER;
2991 /* Check current state */
2992 vcd_state_e state = vcd_config_get_service_state();
2994 /* Service state should be ready */
2995 if (VCD_STATE_READY != state) {
2996 SLOG(LOG_INFO, TAG_VCD, "[Server] Current state is not Ready : pid(%d)", pid);
2997 return VCD_ERROR_INVALID_STATE;
3000 vcd_client_set_slience_detection(stop_by_silence);
3002 /* Notify show tooltip */
3003 ecore_timer_add(0, __vcd_request_show_tooltip, (void*)true);
3008 int vcd_server_widget_stop(int pid)
3010 /* check if pid is valid */
3011 int fore_pid = vcd_client_widget_get_foreground_pid();
3012 if (pid != fore_pid) {
3013 SLOG(LOG_ERROR, TAG_VCD, "[Server] pid is NOT foreground");
3014 return VCD_ERROR_INVALID_PARAMETER;
3018 /* Check current state */
3019 vcd_state_e state = vcd_config_get_service_state();
3021 /* Service state should be recording */
3022 if (VCD_STATE_RECORDING != state) {
3023 SLOG(LOG_ERROR, TAG_VCD, "[Server] Current service state is not Recording : pid(%d)", pid);
3024 return VCD_ERROR_INVALID_STATE;
3027 ret = vcd_server_mgr_stop();
3029 SLOG(LOG_ERROR, TAG_VCD, "[Server] Fail to start recognition");
3030 return VCD_ERROR_OPERATION_FAILED;
3033 return VCD_ERROR_NONE;
3036 int vcd_server_widget_cancel(int pid)
3038 /* check if pid is valid */
3039 int fore_pid = vcd_client_widget_get_foreground_pid();
3040 if (pid != fore_pid) {
3041 SLOG(LOG_ERROR, TAG_VCD, "[Server] pid is NOT foreground");
3042 return VCD_ERROR_INVALID_PARAMETER;
3046 /* Check current state */
3047 vcd_state_e state = vcd_config_get_service_state();
3049 /* Service state should be recording or processing */
3050 if (VCD_STATE_RECORDING != state && VCD_STATE_PROCESSING != state) {
3051 SLOG(LOG_ERROR, TAG_VCD, "[Server] Current state is not Recording or Processing : pid(%d)", pid);
3052 return VCD_ERROR_INVALID_STATE;
3055 ret = vcd_server_mgr_cancel();
3057 SLOG(LOG_ERROR, TAG_VCD, "[Server] Fail to cancel recognition : %d", ret);
3061 return VCD_ERROR_NONE;
3064 int vcd_server_widget_enable_asr_result(int pid, bool enable)
3067 ret = vcd_client_widget_set_asr_result_enabled(pid, enable);
3069 SLOG(LOG_ERROR, TAG_VCD, "[Server] Fail to enable asr result : %d", ret);
3075 int vcd_server_set_language(const char* language)
3077 int ret = VCD_ERROR_NONE;
3079 ret = vcd_config_set_default_language(language);
3081 SLOG(LOG_ERROR, TAG_VCD, "[Server] Fail to set language : %d", ret);
3085 ret = vcd_engine_set_current_language(language);
3087 SLOG(LOG_ERROR, TAG_VCD, "[Server] Fail to set language : %d", ret);
3094 * For engine service
3096 int vcd_get_foreach_command(vce_cmd_h vce_command, vce_command_cb callback, void* user_data)
3098 SLOG(LOG_INFO, TAG_VCD, "[Server] Get foreach command");
3100 if (NULL == callback) {
3101 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] input parameter is NULL");
3102 return VCD_ERROR_INVALID_PARAMETER;
3106 ret = vcd_engine_agent_get_foreach_command(vce_command, callback, user_data);
3108 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to get foreach command : ret(%d)", ret);
3114 int vcd_get_command_count(vce_cmd_h vce_command, int* count)
3116 SLOG(LOG_INFO, TAG_VCD, "[Server] Get command count");
3119 ret = vcd_engine_agent_get_command_count(vce_command, count);
3121 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to get command count : ret(%d)", ret);
3127 int vcd_get_audio_type(char** audio_type)
3129 SLOG(LOG_INFO, TAG_VCD, "[Server] Get audio type");
3132 ret = vcd_engine_agent_get_audio_type(audio_type);
3134 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to get audio type : ret(%d)", ret);
3140 int vcd_set_private_data(const char* key, const char* data)
3142 vcd_state_e state = vcd_config_get_service_state();
3144 if (VCD_STATE_READY != state) {
3145 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Current state(%d) is NOT 'READY'", state);
3146 return VCD_ERROR_INVALID_STATE;
3149 int ret = vcd_engine_agent_set_private_data(key, data);
3151 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to set private data to the manager client : ret(%d)", ret);
3153 SLOG(LOG_INFO, TAG_VCD, "[Server] Set private data to the manager client, key(%s), data(%s)", key, data);
3159 int vcd_get_private_data(const char* key, char** data)
3161 vcd_state_e state = vcd_config_get_service_state();
3163 if (VCD_STATE_READY != state) {
3164 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Current state(%d) is NOT 'READY'", state);
3165 return VCD_ERROR_INVALID_STATE;
3168 int ret = vcd_engine_agent_get_private_data(key, data);
3170 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to get private data from the manager client : ret(%d)", ret);
3172 SLOG(LOG_INFO, TAG_VCD, "[Server] Get private data from the manager client, key(%s), data(%s)", key, *data);
3178 int vcd_start_recording()
3180 SLOG(LOG_INFO, TAG_VCD, "[Server] Start recording");
3183 ret = vcd_engine_agent_start_recording();
3185 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to start recording : ret(%d)", ret);
3191 int vcd_stop_recording()
3193 SLOG(LOG_INFO, TAG_VCD, "[Server] Stop recording");
3196 ret = vcd_engine_agent_stop_recording();
3198 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to stop recording : ret(%d)", ret);
3204 int vcd_send_update_status(vce_update_event_e update_event, const char* msg)
3206 SLOG(LOG_INFO, TAG_VCD, "[Server] update status, update event(%d), msg(%s)", update_event, msg);
3209 if (VCE_UPDATE_EVENT_START == update_event) {
3210 if (VCD_STATE_RECORDING == vcd_config_get_service_state() || VCD_STATE_PROCESSING == vcd_config_get_service_state()) {
3211 ret = vcd_server_mgr_cancel();
3213 SLOG(LOG_ERROR, TAG_VCD, "[Server Error] Fail to cancel, ret(%d)", ret);
3217 vcd_config_set_service_state(VCD_STATE_UPDATING);
3218 vcdc_send_service_state(VCD_STATE_UPDATING);
3220 } else if (VCE_UPDATE_EVENT_FINISH == update_event) {
3221 vcd_config_set_service_state(VCD_STATE_READY);
3222 vcdc_send_service_state(VCD_STATE_READY);
3224 } else if (VCE_UPDATE_EVENT_FAIL == update_event) {
3225 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Update event : Fail - msg(%s)", msg);
3231 int vcd_set_private_data_set_cb(vce_private_data_set_cb callback_func)
3233 SLOG(LOG_INFO, TAG_VCD, "[Server] Set private data set cb");
3236 ret = vcd_engine_agent_set_private_data_set_cb(callback_func);
3238 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to set private data set cb : ret(%d)", ret);
3244 int vcd_set_private_data_requested_cb(vce_private_data_requested_cb callback_func)
3246 SLOG(LOG_INFO, TAG_VCD, "[Server] Set private data requested cb");
3249 ret = vcd_engine_agent_set_private_data_requested_cb(callback_func);
3251 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to set private data requested cb : ret(%d)", ret);
3257 int vcd_set_nlu_base_info_requested_cb(vce_nlu_base_info_requested_cb callback_func)
3259 SLOG(LOG_INFO, TAG_VCD, "[Server] Set nlu base info requested cb");
3262 ret = vcd_engine_agent_set_nlu_base_info_requested_cb(callback_func);
3264 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to set nlu base info requested cb : ret(%d)", ret);
3270 int vcd_set_specific_engine_request_cb(vce_specific_engine_request_cb callback_func)
3272 SLOG(LOG_INFO, TAG_VCD, "[Server] Set specific engine request cb");
3274 ret = vcd_engine_agent_set_specific_engine_request_cb(callback_func);
3276 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to set specific engine request cb : ret(%d)", ret);
3282 int vcd_set_request_tts_cb(vce_request_tts_cb callback_func, void* user_data)
3284 SLOG(LOG_INFO, TAG_VCD, "[Server] Set request tts cb");
3286 ret = vcd_engine_agent_set_request_tts_cb(callback_func, user_data);
3288 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to set request tts cb : ret(%d)", ret);
3294 int vcd_set_cancel_tts_cb(vce_cancel_tts_cb callback_func, void* user_data)
3296 SLOG(LOG_INFO, TAG_VCD, "[Server] Set cancel tts cb");
3298 ret = vcd_engine_agent_set_cancel_tts_cb(callback_func, user_data);
3300 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to set cancel tts cb : ret(%d)", ret);
3306 int vcd_set_tts_audio_format_request_cb(vce_tts_audio_format_request_cb callback_func, void* user_data)
3308 SLOG(LOG_INFO, TAG_VCD, "[Server] Set tts audio format request cb");
3310 ret = vcd_engine_agent_set_get_tts_audio_format_cb(callback_func, user_data);
3312 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to set tts audio format request : ret(%d)", ret);