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.
18 #include <app_manager.h>
20 #include <sound_manager.h>
22 #include "vc_cmd_db.h"
23 #include "vc_info_parser.h"
25 #include "vcd_server.h"
26 #include "vcd_client_data.h"
28 #include "vcd_engine_agent.h"
29 #include "vcd_config.h"
30 #include "vcd_recorder.h"
33 #include "voice_control_command_expand.h"
34 #include "voice_control_common.h"
37 * VC Server static variable
39 static bool g_is_engine;
41 static GList *g_proc_list = NULL;
43 static Ecore_Timer *g_restart_timer = NULL;
46 * @brief Enumerations of send event type.
49 VCD_SEND_EVENT_TYPE_TEXT, /**< send text event to vc engine*/
50 VCD_SEND_EVENT_TYPE_LIST_EVENT, /**< send list event to vc engine */
51 VCD_SEND_EVENT_TYPE_HAPTIC_EVENT /**< send haptic event to vc engine */
52 } vcd_send_event_type_e;
54 static int __vcd_server_launch_manager_app();
57 * VC Server Internal Functions
59 static Eina_Bool __stop_by_silence(void *data)
61 SLOG(LOG_DEBUG, TAG_VCD, "===== Silence Detected ");
63 vcd_server_mgr_stop();
65 SLOG(LOG_DEBUG, TAG_VCD, "=====");
66 SLOG(LOG_DEBUG, TAG_VCD, " ");
70 static Eina_Bool __cancel_by_interrupt(void *data)
72 SLOG(LOG_DEBUG, TAG_VCD, "===== Cancel by interrupt");
74 vcd_server_mgr_cancel();
76 SLOG(LOG_DEBUG, TAG_VCD, "=====");
77 SLOG(LOG_DEBUG, TAG_VCD, " ");
81 static void __cancel_by_error(void *data)
83 SLOG(LOG_DEBUG, TAG_VCD, "===== Cancel by error");
85 vcd_server_mgr_cancel();
87 SLOG(LOG_DEBUG, TAG_VCD, "=====");
88 SLOG(LOG_DEBUG, TAG_VCD, " ");
92 static Eina_Bool __restart_engine(void *data)
94 SLOG(LOG_DEBUG, TAG_VCD, "===== Restart by no result");
96 g_restart_timer = NULL;
98 /* Restart recognition */
99 int ret = vcd_engine_recognize_start(true);
101 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to restart recognition : result(%d)", ret);
105 SLOG(LOG_DEBUG, TAG_VCD, "[Server Success] Start engine");
107 if (VCD_RECOGNITION_MODE_RESTART_AFTER_REJECT == vcd_client_get_recognition_mode()) {
108 vcd_config_set_service_state(VCD_STATE_RECORDING);
109 vcdc_send_service_state(VCD_STATE_RECORDING);
112 SLOG(LOG_DEBUG, TAG_VCD, "[Server Success] Restart recognition");
114 SLOG(LOG_DEBUG, TAG_VCD, "=====");
115 SLOG(LOG_DEBUG, TAG_VCD, " ");
119 static int __server_recorder_callback(const void* data, const unsigned int length)
121 vcd_state_e state = vcd_config_get_service_state();
122 if (VCD_STATE_READY == state) {
123 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Ready state, but recording");
124 } else if (VCD_STATE_PROCESSING == state) {
128 vcp_speech_detect_e speech_detected = VCP_SPEECH_DETECT_NONE;
131 ret = vcd_engine_recognize_audio(data, length, &speech_detected);
135 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to set recording data to engine(%d)", ret);
136 ecore_timer_add(0, __cancel_by_interrupt, NULL);
137 /* Send error cb to manager */
138 if (VCP_ERROR_OUT_OF_NETWORK == ret) {
139 vcdc_send_error_signal_to_manager(vcd_client_manager_get_pid(), VCD_ERROR_TIMED_OUT, "Engine connection failed");
141 vcdc_send_error_signal_to_manager(vcd_client_manager_get_pid(), VCD_ERROR_OPERATION_FAILED, "Engine recognition failed");
146 if (VCP_SPEECH_DETECT_BEGIN == speech_detected) {
147 if (-1 != vcd_client_manager_get_pid()) {
148 /* Manager client is available */
149 if (0 != vcdc_send_speech_detected(vcd_client_manager_get_pid())) {
150 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Fail to send speech detected");
153 } else if (VCP_SPEECH_DETECT_END == speech_detected) {
154 if (VCD_RECOGNITION_MODE_STOP_BY_SILENCE == vcd_client_get_recognition_mode()) {
155 /* silence detected */
156 ecore_timer_add(0, __stop_by_silence, NULL);
157 } else if (VCD_RECOGNITION_MODE_RESTART_AFTER_REJECT == vcd_client_get_recognition_mode()) {
158 /* Stop engine recognition */
159 int ret = vcd_engine_recognize_stop();
161 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to stop recognition : %d", ret);
163 vcd_config_set_service_state(VCD_STATE_PROCESSING);
164 vcdc_send_service_state(VCD_STATE_PROCESSING);
166 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Stop engine only by silence");
167 } else if (VCD_RECOGNITION_MODE_RESTART_CONTINUOUSLY == vcd_client_get_recognition_mode()) {
168 /* Stop engine recognition */
169 int ret = vcd_engine_recognize_stop();
171 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to stop recognition : %d", ret);
179 void __server_recorder_interrupt_callback()
181 SLOG(LOG_DEBUG, TAG_VCD, "===== Cancel by sound interrupt");
183 ecore_timer_add(0, __cancel_by_interrupt, NULL);
185 SLOG(LOG_DEBUG, TAG_VCD, "=====");
186 SLOG(LOG_DEBUG, TAG_VCD, " ");
189 static void __config_lang_changed_cb(const char* current_lang, void* user_data)
191 SLOG(LOG_DEBUG, TAG_VCD, "===== Change language ");
193 /* Current state is recording */
194 vcd_state_e state = vcd_config_get_service_state();
195 if (VCD_STATE_RECORDING == state || VCD_STATE_PROCESSING == state) {
196 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Current state is 'Recording'. Cancel recognition");
197 vcd_server_mgr_cancel();
201 ret = vcd_engine_set_current_language(current_lang);
203 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to set language of engine : %d", ret);
206 SLOG(LOG_DEBUG, TAG_VCD, "=====");
207 SLOG(LOG_DEBUG, TAG_VCD, " ");
212 static void __config_foreground_changed_cb(int previous, int current, void* user_data)
214 SLOG(LOG_DEBUG, TAG_VCD, "===== Change foreground");
216 SLOG(LOG_DEBUG, TAG_VCD, "Foreground pid(%d)", current);
218 if (VC_NO_FOREGROUND_PID != current) {
219 /* Foreground app is changed */
220 vcd_state_e state = vcd_config_get_service_state();
221 if (VCD_STATE_RECORDING == state) {
222 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Foreground pid(%d) is changed. Cancel recognition", current);
223 ecore_timer_add(0, __cancel_by_interrupt, NULL);
227 SLOG(LOG_DEBUG, TAG_VCD, "=====");
228 SLOG(LOG_DEBUG, TAG_VCD, " ");
233 static int __vcd_activate_app_by_appcontrol(const char* appid)
236 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Invalid parameter");
237 return VCD_ERROR_INVALID_PARAMETER;
241 app_control_h app_control = NULL;
242 ret = app_control_create(&app_control);
243 if (APP_CONTROL_ERROR_NONE == ret) {
245 ret = app_control_add_extra_data(app_control, "voice_launch", "get_result");
246 if (APP_CONTROL_ERROR_NONE != ret) {
247 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to add extra data, ret(%d)", ret);
248 app_control_destroy(app_control);
249 return VCD_ERROR_OPERATION_FAILED;
252 ret = app_control_set_app_id(app_control, appid);
253 if (APP_CONTROL_ERROR_NONE != ret) {
254 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to set app id, ret(%d)", ret);
255 app_control_destroy(app_control);
256 return VCD_ERROR_OPERATION_FAILED;
258 // Sent launch request
259 ret = app_control_send_launch_request(app_control, NULL, NULL);
260 if (APP_CONTROL_ERROR_NONE != ret) {
261 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to send launch request, ret(%d)", ret);
262 app_control_destroy(app_control);
263 return VCD_ERROR_OPERATION_FAILED;
265 // Destroy app control
266 ret = app_control_destroy(app_control);
267 if (APP_CONTROL_ERROR_NONE != ret) {
268 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to destroy, ret(%d)", ret);
269 return VCD_ERROR_OPERATION_FAILED;
272 return VCD_ERROR_NONE;
275 static int __vcd_resume_app(const char* appid)
277 app_context_h app_context = NULL;
278 int ret = app_manager_get_app_context(appid, &app_context);
279 if (APP_MANAGER_ERROR_NONE != ret) {
280 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to get app_context, ret(%d), appid(%s)", ret, appid);
281 return VCD_ERROR_OPERATION_FAILED;
284 ret = app_manager_resume_app(app_context);
285 if (APP_MANAGER_ERROR_NONE != ret) {
286 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to resume app, ret(%d), appid(%s)", ret, appid);
287 return VCD_ERROR_OPERATION_FAILED;
289 return VCD_ERROR_NONE;
292 static bool __vcd_is_package_installed(const char* appid)
294 app_info_h app_info = NULL;
295 int ret = app_manager_get_app_info(appid, &app_info);
296 if (APP_MANAGER_ERROR_NONE != ret || NULL == app_info)
298 ret = app_info_destroy(app_info);
299 if (APP_MANAGER_ERROR_NONE != ret)
300 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to destroy app_info, ret(%d)", ret);
304 static bool __vcd_launch_app(const char* result)
306 if (NULL == result) {
307 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Invalid parameter");
308 return VCD_ERROR_INVALID_PARAMETER;
311 GSList* app_list = NULL;
312 if (0 != vc_db_get_appid_list(result, &app_list)) {
313 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] result text is NULL");
314 return VCD_ERROR_INVALID_PARAMETER;
317 if (0 != g_slist_length(app_list)) {
320 vc_deactivated_app_s* temp_app = NULL;
321 iter = g_slist_nth(app_list, 0);
323 while (NULL != iter) {
324 temp_app = iter->data;
326 if (NULL != temp_app) {
327 if (NULL != temp_app->appid) {
329 bool running = false;
330 ret = app_manager_is_running(temp_app->appid, &running);
331 if (APP_MANAGER_ERROR_NONE != ret) {
332 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to check running with appid(%s)", temp_app->appid);
333 free(temp_app->appid);
334 temp_app->appid = NULL;
337 return VCD_ERROR_OPERATION_FAILED;
339 if (false == running) {
340 int tmp_ret = __vcd_is_package_installed(temp_app->appid);
341 if (false == tmp_ret) {
342 SLOG(LOG_WARN, TAG_VCD, "[WARNING] app is not installed, appid(%s)", temp_app->appid);
344 ret = __vcd_activate_app_by_appcontrol(temp_app->appid);
346 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to activate app");
347 free(temp_app->appid);
348 temp_app->appid = NULL;
353 SLOG(LOG_ERROR, TAG_VCD, "Launch app: appid(%s) result(%s)", temp_app->appid, result);
356 ret = __vcd_resume_app(temp_app->appid);
358 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to resume app");
359 free(temp_app->appid);
360 temp_app->appid = NULL;
365 SLOG(LOG_ERROR, TAG_VCD, "Resume app: appid(%s) result(%s)", temp_app->appid, result);
367 free(temp_app->appid);
368 temp_app->appid = NULL;
373 iter = g_slist_next(iter);
378 return VCD_ERROR_NONE;
381 static Eina_Bool __vcd_send_selected_result(void *data)
383 GSList* pid_list = NULL;
384 const char* result = vcd_client_manager_get_result_text();
386 if (0 != vc_info_parser_get_result_pid_list(&pid_list, result)) {
387 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Fail to get pid list. No result");
389 if (0 < g_slist_length(pid_list)) {
391 vc_cmd_s* temp_cmd = NULL;
396 iter = g_slist_nth(pid_list, 0);
397 while (NULL != iter) {
398 temp_cmd = iter->data;
400 if (NULL != temp_cmd && (pre_pid != temp_cmd->pid || pre_type == VC_COMMAND_TYPE_WIDGET || temp_cmd->type == VC_COMMAND_TYPE_WIDGET)) {
401 /* Launch deactivated several apps that is matched with result */
402 ret = __vcd_launch_app(result);
404 SLOG(LOG_ERROR, TAG_VCD, "Fail to launch or resume app, ret(%d) result(%s)", ret, result);
406 /* send result noti */
407 ret = vcdc_send_result(temp_cmd->pid, vcd_client_manager_get_pid(), temp_cmd->type);
409 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Fail to send result, ret(%d)", ret);
412 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Send result : pid(%d) type(%d)", temp_cmd->pid, temp_cmd->type);
413 pre_pid = temp_cmd->pid;
414 pre_type = temp_cmd->type;
420 pid_list = g_slist_remove_link(pid_list, iter);
421 iter = g_slist_nth(pid_list, 0);
426 if (VCD_RECOGNITION_MODE_RESTART_CONTINUOUSLY != vcd_client_get_recognition_mode()) {
427 vcd_config_set_service_state(VCD_STATE_READY);
428 vcdc_send_service_state(VCD_STATE_READY);
434 //static void __vcd_server_pre_result_cb(vcp_pre_result_event_e event, const char* pre_result, void *user_data)
435 static void __vcd_server_asr_result_cb(vcp_asr_result_event_e event, const char* asr_result, void *user_data)
437 if (NULL != asr_result) {
438 SLOG(LOG_DEBUG, TAG_VCD, "[Server] ASR result - Event(%d), Text(%s)", event, asr_result);
439 vcdc_send_pre_result_to_manager(vcd_client_manager_get_pid(), event, asr_result);
445 static void __vcd_server_nlg_result_cb(const char* nlg_result, void *user_data)
447 int ret = __vcd_server_launch_manager_app();
449 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to send dialog : mgr_pid(%d), nlg_result(%s)", vcd_client_manager_get_pid(), nlg_result);
453 ret = vcdc_send_dialog(vcd_client_manager_get_pid(), -1, nlg_result, NULL, 0); //0: VC_DIALOG_END
455 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to send dialog : mgr_pid(%d), nlg_result(%s)", vcd_client_manager_get_pid(), nlg_result);
459 static void* __recorder_stop(void *data)
465 static void __vcd_server_result_cb(vcp_result_event_e event, int* result_id, int count, const char* all_result,
466 const char* non_fixed_result, const char* nlu_result, const char* msg, void *user_data)
468 if (VCD_STATE_PROCESSING != vcd_config_get_service_state()) {
469 if (VCD_RECOGNITION_MODE_RESTART_CONTINUOUSLY != vcd_client_get_recognition_mode()) {
470 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Current state is not 'Processing' and mode is not 'Restart continuously'");
475 vc_info_parser_unset_result(vcd_client_manager_get_exclusive());
476 vcd_client_manager_set_result_text(all_result);
478 SLOG(LOG_INFO, TAG_VCD, "[Server] Event(%d), Text(%s) Nonfixed(%s) Msg(%s) Result count(%d)",
479 event, all_result, non_fixed_result, msg, count);
481 if (VCD_RECOGNITION_MODE_RESTART_AFTER_REJECT == vcd_client_get_recognition_mode()) {
482 if (VCP_RESULT_EVENT_REJECTED == event) {
483 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Restart by no or rejected result");
484 /* If no result and restart option is ON */
485 /* Send reject message */
486 bool temp = vcd_client_manager_get_exclusive();
487 vc_info_parser_set_result(all_result, event, msg, NULL, temp);
488 if (0 != vcdc_send_result_to_manager(vcd_client_manager_get_pid(), VC_RESULT_TYPE_NOTIFICATION)) {
489 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Fail to send result");
492 g_restart_timer = ecore_timer_add(0, __restart_engine, NULL);
495 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Stop recorder due to success");
496 //vcd_recorder_stop();
497 ecore_main_loop_thread_safe_call_sync(__recorder_stop, NULL);
498 } else if (VCD_RECOGNITION_MODE_RESTART_CONTINUOUSLY == vcd_client_get_recognition_mode()) {
499 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Restart continuously");
500 /* Restart option is ON */
501 g_restart_timer = ecore_timer_add(0, __restart_engine, NULL);
502 if (VCP_RESULT_EVENT_REJECTED == event) {
503 bool temp = vcd_client_manager_get_exclusive();
504 vc_info_parser_set_result(all_result, event, msg, NULL, temp);
505 if (0 != vcdc_send_result_to_manager(vcd_client_manager_get_pid(), VC_RESULT_TYPE_NOTIFICATION)) {
506 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Fail to send result");
513 int pid = vcd_client_widget_get_foreground_pid();
515 if (NULL != all_result) {
516 vc_info_parser_set_result(all_result, event, msg, NULL, false);
518 vcd_client_widget_get_asr_result_enabled(pid, &enable);
519 if (true == enable) {
520 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Send ASR result to Widget client");
521 bool is_consumed = false;
522 if (0 != vcdc_send_asr_result(pid, VC_COMMAND_TYPE_WIDGET, &is_consumed)) {
523 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to send asr result");
525 SLOG(LOG_DEBUG, TAG_VCD, "[Server] ASR result is consumed(%d)", is_consumed);
526 if (true == is_consumed) {
527 vcdc_send_show_tooltip(pid, false);
528 if (-1 != vcd_client_manager_get_pid()) {
529 /* Manager client is available */
530 vc_info_parser_unset_result(false);
531 vc_info_parser_set_result(all_result, VC_RESULT_EVENT_RESULT_SUCCESS, msg, NULL, false);
532 if (0 != vcdc_send_result_to_manager(vcd_client_manager_get_pid(), VC_RESULT_TYPE_NOTIFICATION)) {
533 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Fail to send result");
537 vcd_client_manager_set_exclusive(false);
539 vcd_config_set_service_state(VCD_STATE_READY);
540 vcdc_send_service_state(VCD_STATE_READY);
548 /* if nlu_result is exist, Add command handle(is_action) into result list */
550 SLOG(LOG_DEBUG, TAG_VCD, "[Server] === Get engine result ===");
553 vc_cmd_s* temp_cmd = NULL;
554 vc_cmd_list_h vc_cmd_list = NULL;
556 if (0 != vc_cmd_list_create(&vc_cmd_list)) {
557 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Fail to create command list");
558 vcd_client_manager_set_exclusive(false);
559 vcd_config_set_service_state(VCD_STATE_READY);
560 vcdc_send_service_state(VCD_STATE_READY);
564 /* priority filter */
565 /* system > exclusive > foreground = widget > system_background > background */
567 int* filtered_id = (int*)calloc(count, sizeof(int));
568 int filtered_count = 0;
569 int top_priority = VC_COMMAND_PRIORITY_BACKGROUND;
570 for (i = 0; i < count; i++) {
571 SLOG(LOG_INFO, TAG_VCD, "[Server] [%d] Result id(%d)", i, result_id[i]);
573 if (0 > result_id[i]) {
574 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Result ID(%d) is NOT valid", result_id[i]);
578 ret = vcd_client_get_cmd_from_result_id(result_id[i], &temp_cmd);
579 if (0 == ret && NULL != temp_cmd) {
580 if (top_priority == temp_cmd->priority) {
581 filtered_id[filtered_count] = result_id[i];
583 } else if (top_priority < temp_cmd->priority) {
586 filtered_id[0] = result_id[i];
588 top_priority = temp_cmd->priority;
594 for (i = 0; i < filtered_count; i++) {
595 SLOG(LOG_INFO, TAG_VCD, "[Server] [%d] Filtered Result id(%d)", i, filtered_id[i]);
597 if (filtered_id[i] < 0) {
598 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Filtered ID(%d) is NOT valid", filtered_id[i]);
602 ret = vcd_client_get_cmd_from_result_id(filtered_id[i], &temp_cmd);
603 if (0 == ret && NULL != temp_cmd) {
604 switch (temp_cmd->format) {
605 case VC_CMD_FORMAT_FIXED:
606 case VC_CMD_FORMAT_FIXED_AND_VFIXED:
607 case VC_CMD_FORMAT_VFIXED_AND_FIXED:
608 case VC_CMD_FORMAT_PARTIAL:
609 case VC_CMD_FORMAT_FIXED_AND_NONFIXED:
610 case VC_CMD_FORMAT_NONFIXED_AND_FIXED:
612 case VC_CMD_FORMAT_ACTION:
616 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Unknown command type : %d", temp_cmd->type);
620 if (0 != vc_cmd_list_add(vc_cmd_list, (vc_cmd_h)temp_cmd)) {
621 SLOG(LOG_DEBUG, TAG_VCD, "Fail to add command to list");
622 vc_cmd_destroy((vc_cmd_h)temp_cmd);
625 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] NOT found matached result(%d)", filtered_id[i]);
629 if (NULL != filtered_id) {
634 if (NULL != nlu_result) {
635 SLOG(LOG_INFO, TAG_VCD, "[Server] NLU (%s)", nlu_result);
636 vc_info_parser_set_nlu_result(nlu_result);
637 if (0 == is_action) {
639 if (0 != vc_cmd_create(&nlu_cmd)) {
640 SLOG(LOG_ERROR, TAG_VCD, "Fail to nlu cmd create");
642 if (0 != vc_cmd_set_type(nlu_cmd, VC_COMMAND_TYPE_SYSTEM)) {
643 SLOG(LOG_ERROR, TAG_VCD, "Fail to set type");
645 if (0 != vc_cmd_set_pid(nlu_cmd, vcd_client_manager_get_pid())) {
646 SLOG(LOG_ERROR, TAG_VCD, "Fail to set pid");
648 if (0 != vc_cmd_set_format(nlu_cmd, VC_CMD_FORMAT_ACTION)) {
649 SLOG(LOG_ERROR, TAG_VCD, "Fail to set format");
651 if (0 != vc_cmd_list_add(vc_cmd_list, nlu_cmd)) {
652 SLOG(LOG_ERROR, TAG_VCD, "Fail to add nlu cmd to list");
653 vc_cmd_destroy(nlu_cmd);
659 vc_cmd_print_list(vc_cmd_list);
661 SLOG(LOG_DEBUG, TAG_VCD, "[Server] =========================");
663 int result_count = 0;
664 vc_cmd_list_get_count(vc_cmd_list, &result_count);
666 if (0 == result_count) {
668 if (NULL != all_result) {
669 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Engine result is no command : %s", all_result);
671 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Engine result is NULL");
673 bool temp = vcd_client_manager_get_exclusive();
674 vc_info_parser_set_result(all_result, event, msg, NULL, temp);
676 int pid = vcd_client_widget_get_foreground_pid();
678 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Request tooltip hide");
679 /* Send to hide tooltip */
680 vcdc_send_show_tooltip(pid, false);
683 if (-1 != vcd_client_manager_get_pid()) {
684 /* Manager client is available */
685 if (0 != vcdc_send_result_to_manager(vcd_client_manager_get_pid(), VC_RESULT_TYPE_NORMAL)) {
686 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Fail to send result");
690 vcd_client_manager_set_exclusive(false);
694 if (false == vcd_client_manager_get_exclusive()) {
695 int pid = vcd_client_widget_get_foreground_pid();
697 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Request tooltip hide");
698 vcdc_send_show_tooltip(pid, false);
701 vc_info_parser_set_result(all_result, event, msg, vc_cmd_list, false);
703 if (-1 != vcd_client_manager_get_pid()) {
704 /* Manager client is available */
705 if (0 != vcdc_send_result_to_manager(vcd_client_manager_get_pid(), VC_RESULT_TYPE_NORMAL)) {
706 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Fail to send result");
709 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Manager is NOT available. Send result to client directly");
710 /* Send result to client */
711 ecore_timer_add(0, __vcd_send_selected_result, NULL);
714 /* exclusive command */
715 vc_info_parser_set_result(all_result, event, msg, vc_cmd_list, true);
717 if (-1 != vcd_client_manager_get_pid()) {
718 /* Manager client is available */
719 if (0 != vcdc_send_result_to_manager(vcd_client_manager_get_pid(), VC_RESULT_TYPE_NORMAL)) {
720 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Fail to send result");
723 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Manager is NOT available");
726 vcd_client_manager_set_exclusive(false);
730 vc_cmd_list_destroy(vc_cmd_list, true);
736 if (NULL == result_id) {
738 if (NULL != all_result) {
739 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Engine result is no command : %s", all_result);
740 bool temp = vcd_client_manager_get_exclusive();
741 vc_info_parser_set_result(all_result, event, msg, NULL, temp);
744 int pid = vcd_client_widget_get_foreground_pid();
746 if (NULL != all_result) {
747 /* Send result text to widget */
748 vcdc_send_result(pid, vcd_client_manager_get_pid(), VC_COMMAND_TYPE_WIDGET);
751 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Request tooltip hide");
752 /* Send to hide tooltip */
753 vcdc_send_show_tooltip(pid, false);
756 if (-1 != vcd_client_manager_get_pid()) {
757 /* Manager client is available */
758 if (0 != vcdc_send_result_to_manager(vcd_client_manager_get_pid(), VC_RESULT_TYPE_NORMAL)) {
759 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Fail to send result");
763 vcd_client_manager_set_exclusive(false);
769 SLOG(LOG_DEBUG, TAG_VCD, "[Server] === Get engine result ===");
772 vc_cmd_s* temp_cmd = NULL;
773 vc_cmd_list_h vc_cmd_list = NULL;
775 if (0 != vc_cmd_list_create(&vc_cmd_list)) {
776 SLOG(LOG_ERROR, TAG_VCD, "[Server] Fail to create command list");
777 vcd_client_manager_set_exclusive(false);
778 vcd_config_set_service_state(VCD_STATE_READY);
779 vcdc_send_service_state(VCD_STATE_READY);
784 for (i = 0; i < count; i++) {
785 SLOG(LOG_DEBUG, TAG_VCD, "[Server] [%d] Result ID(%d)", i, result_id[i]);
787 if (result_id[i] < 0) {
788 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Result ID(%d) is NOT valid", result_id[i]);
792 ret = vcd_client_get_cmd_from_result_id(result_id[i], &temp_cmd);
793 if (0 == ret && NULL != temp_cmd) {
794 switch (temp_cmd->format) {
795 case VC_CMD_FORMAT_FIXED:
796 case VC_CMD_FORMAT_FIXED_AND_VFIXED:
797 case VC_CMD_FORMAT_VFIXED_AND_FIXED:
798 case VC_CMD_FORMAT_PARTIAL:
799 /* Nonfixed result is NOT valid */
801 case VC_CMD_FORMAT_FIXED_AND_NONFIXED:
802 if (NULL == temp_cmd->parameter) {
803 if (NULL != non_fixed_result) {
804 temp_cmd->parameter = strdup(non_fixed_result);
807 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Command type is NOT vaild. Parameter (%s)", temp_cmd->parameter);
810 case VC_CMD_FORMAT_NONFIXED_AND_FIXED:
811 if (NULL == temp_cmd->command) {
812 if (NULL != non_fixed_result) {
813 temp_cmd->command = strdup(non_fixed_result);
816 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Command type is NOT vaild. Command (%s)", temp_cmd->command);
821 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Unknown command type : %d", temp_cmd->type);
825 if (0 != vc_cmd_list_add(vc_cmd_list, (vc_cmd_h)temp_cmd)) {
826 SLOG(LOG_DEBUG, TAG_VCD, "Fail to add command to list");
827 vc_cmd_destroy((vc_cmd_h)temp_cmd);
830 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] NOT found matached result(%d)", result_id[i]);
834 vc_cmd_print_list(vc_cmd_list);
836 SLOG(LOG_DEBUG, TAG_VCD, "[Server] =========================");
838 int result_count = 0;
839 vc_cmd_list_get_count(vc_cmd_list, &result_count);
841 if (false == vcd_client_manager_get_exclusive()) {
842 int pid = vcd_client_widget_get_foreground_pid();
844 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Request tooltip hide");
845 vcdc_send_show_tooltip(pid, false);
848 vc_info_parser_set_result(all_result, event, msg, vc_cmd_list, false);
850 if (-1 != vcd_client_manager_get_pid()) {
851 /* Manager client is available */
852 if (0 != vcdc_send_result_to_manager(vcd_client_manager_get_pid(), VC_RESULT_TYPE_NORMAL)) {
853 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Fail to send result");
856 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Manager is NOT available. Send result to client directly");
857 /* Send result to client */
858 ecore_timer_add(0, __vcd_send_selected_result, NULL);
861 /* exclusive command */
862 vc_info_parser_set_result(all_result, event, msg, vc_cmd_list, true);
864 if (-1 != vcd_client_manager_get_pid()) {
865 /* Manager client is available */
866 if (0 != vcdc_send_result_to_manager(vcd_client_manager_get_pid(), VC_RESULT_TYPE_NORMAL)) {
867 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Fail to send result");
870 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Manager is NOT available");
873 vcd_client_manager_set_exclusive(false);
876 vc_cmd_list_destroy(vc_cmd_list, true);
883 static void __vcd_server_nlu_result_cb(vcp_result_event_e event, const char* nlu_result, void *user_data)
885 SLOG(LOG_DEBUG, TAG_VCD, "[Server] NLU result cb - event(%d)", event);
886 SLOG(LOG_DEBUG, TAG_VCD, "[Server] result (%s)", nlu_result);
888 int ret = vc_info_parser_set_nlu_result(nlu_result);
890 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to set nlu result (%d)", ret);
897 static void __vcd_server_error_cb(vcp_error_e error, const char* msg, void *user_data)
899 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Engine Error cb - reason(%d), msg(%s)", error, msg);
900 ecore_main_loop_thread_safe_call_async(__cancel_by_error, NULL);
902 char* error_msg = NULL;
904 error_msg = strdup(msg);
906 error_msg = strdup("no message");
909 if (0 != vcdc_send_error_signal_to_manager(vcd_client_manager_get_pid(), error, error_msg)) {
910 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to send error signal");
913 if (NULL != error_msg) {
922 * vcd server Interfaces
924 static void __vcd_file_clean_up()
926 SLOG(LOG_DEBUG, TAG_VCD, "== Old file clean up == ");
929 struct dirent *dirp = NULL;
931 dp = opendir(VC_RUNTIME_INFO_ROOT);
933 SLOG(LOG_ERROR, TAG_VCD, "[File message WARN] Fail to open path : %s", VC_RUNTIME_INFO_ROOT);
937 char remove_path[256] = {0, };
942 if (!strncmp("vc_", dirp->d_name, strlen("vc_"))) {
943 memset(remove_path, 0, 256);
944 snprintf(remove_path, 256, "%s/%s", VC_RUNTIME_INFO_ROOT, dirp->d_name);
947 if (0 != remove(remove_path)) {
948 SLOG(LOG_WARN, TAG_VCD, "[File message WARN] Fail to remove file : %s", remove_path);
950 SLOG(LOG_DEBUG, TAG_VCD, "[File message] Remove file : %s", remove_path);
954 } while (NULL != dirp);
961 static int __vcd_db_clean_up()
964 int cnt = VC_COMMAND_TYPE_FOREGROUND;
966 if (VC_COMMAND_TYPE_BACKGROUND != cnt)
967 ret = vc_db_delete_commands(-1, cnt, NULL);
968 } while (VC_COMMAND_TYPE_EXCLUSIVE >= ++cnt);
977 /* Remove old file */
978 __vcd_file_clean_up();
980 /* initialize modules */
981 ret = vcd_config_initialize(__config_lang_changed_cb, __config_foreground_changed_cb, NULL);
983 SLOG(LOG_ERROR, TAG_VCD, "[Server WARNING] Fail to initialize config.");
987 ret = __vcd_db_clean_up();
989 SLOG(LOG_ERROR, TAG_VCD, "[Server WARNING] Fail to remove db data");
992 vcd_config_set_service_state(VCD_STATE_NONE);
994 //ret = vcd_engine_agent_init(__vcd_server_pre_result_cb, __vcd_server_result_cb, __vcd_server_nlu_result_cb, __vcd_server_error_cb);
995 ret = vcd_engine_agent_init(__vcd_server_asr_result_cb, __vcd_server_result_cb, __vcd_server_nlg_result_cb, __vcd_server_error_cb);
997 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to engine agent initialize : result(%d)", ret);
1001 if (0 != vcd_recorder_create(__server_recorder_callback, __server_recorder_interrupt_callback)) {
1002 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to create recorder");
1003 return VCD_ERROR_OPERATION_FAILED;
1007 ret = vcd_engine_agent_initialize_current_engine();
1009 if (VCD_ERROR_ENGINE_NOT_FOUND == ret)
1010 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] There is No Voice control engine");
1012 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to init engine");
1014 g_is_engine = false;
1020 if (0 != vcd_engine_agent_load_current_engine()) {
1021 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to load current engine");
1022 return VCD_ERROR_OPERATION_FAILED;
1025 /* Initialize manager info */
1026 vcd_client_manager_unset();
1028 vcd_config_set_service_state(VCD_STATE_READY);
1029 vcdc_send_service_state(VCD_STATE_READY);
1031 SLOG(LOG_DEBUG, TAG_VCD, "[Server SUCCESS] initialize");
1039 if (0 < g_list_length(g_proc_list)) {
1040 iter = g_list_first(g_proc_list);
1041 while (NULL != iter) {
1042 g_proc_list = g_list_remove_link(g_proc_list, iter);
1043 iter = g_list_first(g_proc_list);
1047 if (g_restart_timer != NULL) {
1048 ecore_timer_del(g_restart_timer);
1049 g_restart_timer = NULL;
1052 vcd_state_e state = vcd_config_get_service_state();
1053 if (VCD_STATE_READY != state) {
1054 if (VCD_STATE_RECORDING == state) {
1055 vcd_recorder_stop();
1057 vcd_engine_recognize_cancel();
1059 if (0 != vcd_recorder_destroy()) {
1060 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to destroy recorder");
1062 SLOG(LOG_DEBUG, TAG_VCD, "[Server] destroy recorder");
1065 if (0 != vcd_engine_agent_release()) {
1066 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to release engine");
1068 SLOG(LOG_DEBUG, TAG_VCD, "[Server] release engine");
1071 vcd_client_manager_unset_appid();
1073 vcd_config_set_service_state(VCD_STATE_NONE);
1074 vcdc_send_service_state(VCD_STATE_NONE);
1076 SLOG(LOG_DEBUG, TAG_VCD, "[Server] mode finalize");
1081 static Eina_Bool __finalize_quit_ecore_loop(void *data)
1083 SLOG(LOG_DEBUG, TAG_VCD, "[Server] quit ecore main loop");
1084 ecore_main_loop_quit();
1088 static void __read_proc()
1091 struct dirent *dirp = NULL;
1095 if (0 < g_list_length(g_proc_list)) {
1096 iter = g_list_first(g_proc_list);
1097 while (NULL != iter) {
1098 g_proc_list = g_list_remove_link(g_proc_list, iter);
1099 iter = g_list_first(g_proc_list);
1103 dp = opendir("/proc");
1105 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to open proc");
1111 tmp = atoi(dirp->d_name);
1112 if (0 >= tmp) continue;
1113 g_proc_list = g_list_append(g_proc_list, GINT_TO_POINTER(tmp));
1115 } while (NULL != dirp);
1121 static void __vcd_cleanup_client(vcd_client_type_e type)
1123 int* client_list = NULL;
1124 int client_count = 0;
1131 if (VCD_CLIENT_TYPE_NORMAL == type) {
1132 ret = vcd_client_get_list(&client_list, &client_count);
1133 } else if (VCD_CLIENT_TYPE_WIDGET == type) {
1134 ret = vcd_client_widget_get_list(&client_list, &client_count);
1135 } else if (VCD_CLIENT_TYPE_MANAGER == type) {
1136 mgr_pid = vcd_client_manager_get_pid();
1137 client_list = &mgr_pid;
1139 if (-1 == mgr_pid) {
1140 SLOG(LOG_WARN, TAG_VCD, "[WARNING] Invalid Manager pid");
1145 if (0 == ret || mgr_pid > 0) {
1146 SLOG(LOG_DEBUG, TAG_VCD, "===== Clean up %s client ", type ? (type == 1) ? "Widget" : "Manager" : "Normal");
1147 if (NULL != client_list && client_count > 0) {
1148 for (i = 0; i < client_count; i++) {
1151 for (j = 0; j < g_list_length(g_proc_list); j++) {
1152 iter = g_list_nth(g_proc_list, j);
1154 if (client_list[i] == GPOINTER_TO_INT(iter->data)) {
1155 SLOG(LOG_DEBUG, TAG_VCD, "%s pid(%d) is running", type ? (type == 1) ? "Widget" : "Manager" : "Normal", client_list[i]);
1162 if (false == exist) {
1163 SLOG(LOG_ERROR, TAG_VCD, "%s pid(%d) should be removed", type ? (type == 1) ? "Widget" : "Manager" : "Normal", client_list[i]);
1164 if (VCD_CLIENT_TYPE_NORMAL == type)
1165 vcd_server_finalize(client_list[i]);
1166 else if (VCD_CLIENT_TYPE_WIDGET == type)
1167 vcd_server_widget_finalize(client_list[i]);
1169 vcd_server_mgr_finalize(mgr_pid);
1173 SLOG(LOG_DEBUG, TAG_VCD, "=====");
1174 SLOG(LOG_DEBUG, TAG_VCD, " ");
1176 if (NULL != client_list && -1 == mgr_pid) {
1183 Eina_Bool vcd_cleanup_client_all(void *data)
1187 __vcd_cleanup_client(VCD_CLIENT_TYPE_NORMAL);
1188 __vcd_cleanup_client(VCD_CLIENT_TYPE_WIDGET);
1189 __vcd_cleanup_client(VCD_CLIENT_TYPE_MANAGER);
1192 if (0 == vcd_client_get_list(&client_list, &client_count)) {
1193 SLOG(LOG_DEBUG, TAG_VCD, "===== Clean up client ");
1194 if (NULL != client_list && client_count > 0) {
1195 for (i = 0; i < client_count; i++) {
1198 for (j = 0; j < g_list_length(g_proc_list); j++) {
1199 iter = g_list_nth(g_proc_list, j);
1201 if (client_list[i] == GPOINTER_TO_INT(iter->data)) {
1202 SLOG(LOG_DEBUG, TAG_VCD, "pid(%d) is running", client_list[i]);
1209 if (false == exist) {
1210 SLOG(LOG_ERROR, TAG_VCD, "pid(%d) should be removed", client_list[i]);
1211 vcd_server_finalize(client_list[i]);
1214 result = vcdc_send_hello(client_list[i], VCD_CLIENT_TYPE_NORMAL);
1217 SLOG(LOG_DEBUG, TAG_VCD, "[Server] pid(%d) should be removed.", client_list[i]);
1218 vcd_server_finalize(client_list[i]);
1219 } else if (-1 == result) {
1220 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Hello result has error");
1225 SLOG(LOG_DEBUG, TAG_VCD, "=====");
1226 SLOG(LOG_DEBUG, TAG_VCD, " ");
1228 if (NULL != client_list) {
1233 /* If app is in background state, app cannot response message. */
1234 if (0 == vcd_client_widget_get_list(&client_list, &client_count)) {
1235 SLOG(LOG_DEBUG, TAG_VCD, "===== Clean up widget");
1236 if (NULL != client_list && client_count > 0) {
1237 for (i = 0; i < client_count; i++) {
1240 for (j = 0; j < g_list_length(g_proc_list); j++) {
1241 iter = g_list_nth(g_proc_list, j);
1243 if (client_list[i] == GPOINTER_TO_INT(iter->data)) {
1244 SLOG(LOG_DEBUG, TAG_VCD, "widget pid(%d) is running", client_list[i]);
1251 if (false == exist) {
1252 SLOG(LOG_ERROR, TAG_VCD, "widget pid(%d) should be removed", client_list[i]);
1253 vcd_server_widget_finalize(client_list[i]);
1256 result = vcdc_send_hello(client_list[i], VCD_CLIENT_TYPE_WIDGET);
1259 SLOG(LOG_DEBUG, TAG_VCD, "[Server] widget pid(%d) should be removed.", client_list[i]);
1260 vcd_server_widget_finalize(client_list[i]);
1261 } else if (-1 == result) {
1262 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Hello result has error");
1267 SLOG(LOG_DEBUG, TAG_VCD, "=====");
1268 SLOG(LOG_DEBUG, TAG_VCD, " ");
1271 if (NULL != client_list) {
1279 int mgr_pid = vcd_client_manager_get_pid();
1281 for (j = 0; j < g_list_length(g_proc_list); j++) {
1282 iter = g_list_nth(g_proc_list, j);
1284 if (mgr_pid == GPOINTER_TO_INT(iter->data)) {
1285 SLOG(LOG_DEBUG, TAG_VCD, "manager pid(%d) is running", mgr_pid);
1292 if (false == exist) {
1293 SLOG(LOG_ERROR, TAG_VCD, "manager pid (%d) should be removed", mgr_pid);
1294 vcd_server_mgr_finalize(mgr_pid);
1301 int vcd_server_get_service_state()
1303 return vcd_config_get_service_state();
1306 int vcd_server_get_foreground()
1309 vcd_config_get_foreground(&pid);
1317 int vcd_server_mgr_initialize(int pid)
1319 if (false == g_is_engine) {
1320 if (0 != vcd_engine_agent_initialize_current_engine()) {
1321 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] No Engine");
1322 g_is_engine = false;
1323 return VCD_ERROR_ENGINE_NOT_FOUND;
1329 /* check if pid is valid */
1330 if (false == vcd_client_manager_is_valid(pid)) {
1331 SLOG(LOG_ERROR, TAG_VCD, "[Server] old manager pid(%d) be removed", vcd_client_manager_get_pid());
1332 vcd_server_mgr_cancel();
1333 vcd_client_manager_unset();
1336 /* Add client information to client manager */
1337 if (0 != vcd_client_manager_set(pid)) {
1338 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to add manager");
1339 return VCD_ERROR_OPERATION_FAILED;
1342 if (0 != vcdc_send_manager_pid(pid))
1343 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Fail to send manager pid");
1345 SLOG(LOG_DEBUG, TAG_VCD, "[Server Success] Manager initialize : pid(%d)", pid);
1347 return VCD_ERROR_NONE;
1350 int vcd_server_mgr_finalize(int pid)
1352 /* check if pid is valid */
1353 if (false == vcd_client_manager_is_valid(pid)) {
1354 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] The manager pid(%d) is NOT valid", pid);
1355 return VCD_ERROR_INVALID_PARAMETER;
1358 /* Cancel recognition */
1359 vcd_server_mgr_cancel();
1361 if (0 != vcdc_send_manager_pid(-1))
1362 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Fail to send manager pid");
1364 /* Remove manager information */
1365 if (0 != vcd_client_manager_unset()) {
1366 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Fail to delete client");
1369 if (0 == vcd_client_get_ref_count()) {
1370 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Connected client list is empty");
1371 ecore_timer_add(0, __finalize_quit_ecore_loop, NULL);
1374 SLOG(LOG_DEBUG, TAG_VCD, "[Server Success] Manager Finalize : pid(%d)", pid);
1376 return VCD_ERROR_NONE;
1379 int vcd_server_mgr_set_command(int pid)
1381 if (0 != vcd_client_manager_set_command(pid)) {
1382 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] The manager pid(%d) is NOT valid", pid);
1383 return VCD_ERROR_INVALID_PARAMETER;
1385 return VCD_ERROR_NONE;
1388 int vcd_server_mgr_unset_command(int pid)
1390 if (0 != vcd_client_manager_unset_command(pid)) {
1391 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] The manager pid(%d) is NOT valid", pid);
1392 return VCD_ERROR_INVALID_PARAMETER;
1394 return VCD_ERROR_NONE;
1397 int vcd_server_mgr_set_demandable_client(int pid)
1399 /* check if pid is valid */
1400 if (false == vcd_client_manager_is_valid(pid)) {
1401 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] The manager pid(%d) is NOT valid", pid);
1402 return VCD_ERROR_INVALID_PARAMETER;
1405 GSList* client_list = NULL;
1406 if (0 != vc_info_parser_get_demandable_clients(&client_list)) {
1407 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to get demandable client");
1408 return VCD_ERROR_OPERATION_FAILED;
1411 /* Save client list */
1412 if (0 != vcd_client_manager_set_demandable_client(pid, client_list)) {
1413 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to set demandable client list");
1414 return VCD_ERROR_OPERATION_FAILED;
1417 return VCD_ERROR_NONE;
1420 int vcd_server_mgr_set_audio_type(int pid, const char* audio_type)
1422 /* check if pid is valid */
1423 if (false == vcd_client_manager_is_valid(pid)) {
1424 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] The manager pid(%d) is NOT valid", pid);
1425 return VCD_ERROR_INVALID_PARAMETER;
1429 vcp_audio_type_e type = VCP_AUDIO_TYPE_PCM_S16_LE;
1433 ret = vcd_engine_get_audio_format(audio_type, &type, &rate, &channel);
1435 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to get audio format : %d", ret);
1436 return VCD_ERROR_OPERATION_FAILED;
1439 ret = vcd_recorder_set(audio_type, type, rate, channel);
1441 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to set audio in type : %d", ret);
1442 return VCD_ERROR_OPERATION_FAILED;
1445 return VCD_ERROR_NONE;
1448 int vcd_server_mgr_get_audio_type(int pid, char** audio_type)
1450 /* check if pid is valid */
1451 if (false == vcd_client_manager_is_valid(pid)) {
1452 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] The manager pid(%d) is NOT valid", pid);
1453 return VCD_ERROR_INVALID_PARAMETER;
1456 int ret = vcd_recorder_get(audio_type);
1458 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to get audio in type : %d", ret);
1459 return VCD_ERROR_OPERATION_FAILED;
1462 return VCD_ERROR_NONE;
1465 int vcd_server_mgr_set_client_info(int pid)
1467 /* check if pid is valid */
1468 if (false == vcd_client_manager_is_valid(pid)) {
1469 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] The manager pid(%d) is NOT valid", pid);
1470 return VCD_ERROR_INVALID_PARAMETER;
1473 int ret = vcd_client_save_client_info();
1475 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to save client info : %d", ret);
1476 return VCD_ERROR_OPERATION_FAILED;
1479 return VCD_ERROR_NONE;
1482 static int __start_internal_recognition()
1486 if (0 != vcd_client_command_collect_command()) {
1487 SLOG(LOG_ERROR, TAG_VCD, "[Client Data ERROR] Fail to collect command");
1488 /* Send error cb to manager */
1489 int pid = vcd_client_widget_get_foreground_pid();
1491 vcdc_send_error_signal_to_manager(vcd_client_manager_get_pid(), VCD_ERROR_OPERATION_FAILED, "voice_engine.error.proc_fail");
1492 return VCD_ERROR_OPERATION_FAILED;
1495 /* 3. Set command to engine */
1496 ret = vcd_engine_set_commands();
1498 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to set commands : %d", ret);
1499 /* Send error cb to manager */
1500 int pid = vcd_client_widget_get_foreground_pid();
1502 vcdc_send_error_signal_to_manager(vcd_client_manager_get_pid(), VCD_ERROR_OPERATION_FAILED, "voice_engine.error.proc_fail");
1503 return VCD_ERROR_OPERATION_FAILED;
1506 SLOG(LOG_DEBUG, TAG_VCD, "[Server Success] Set command");
1508 bool stop_by_silence = true;
1509 if (VCD_RECOGNITION_MODE_MANUAL == vcd_client_get_recognition_mode()) {
1510 stop_by_silence = false;
1513 vcd_client_manager_set_result_text(NULL);
1515 /* 4. start recognition */
1516 ret = vcd_engine_recognize_start(stop_by_silence);
1518 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to start recognition : result(%d)", ret);
1519 /* Send error cb to manager */
1520 int pid = vcd_client_widget_get_foreground_pid();
1522 vcdc_send_error_signal_to_manager(vcd_client_manager_get_pid(), VCD_ERROR_OPERATION_FAILED, "voice_engine.error.proc_fail");
1523 return VCD_ERROR_OPERATION_FAILED;
1526 SLOG(LOG_DEBUG, TAG_VCD, "[Server Success] Start engine");
1529 /* 5. recorder start */
1530 ret = vcd_recorder_start();
1532 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to start recorder : result(%d)", ret);
1533 vcd_engine_recognize_cancel();
1534 /* Send error cb to manager */
1535 int pid = vcd_client_widget_get_foreground_pid();
1537 vcdc_send_error_signal_to_manager(vcd_client_manager_get_pid(), VCD_ERROR_OPERATION_FAILED, "voice_engine.error.proc_fail");
1542 vcd_config_set_service_state(VCD_STATE_RECORDING);
1543 vcdc_send_service_state(VCD_STATE_RECORDING);
1545 SLOG(LOG_DEBUG, TAG_VCD, "[Server Success] Start recognition(%d)", stop_by_silence);
1550 static Eina_Bool __vcd_request_show_tooltip(void *data)
1552 int pid = vcd_client_widget_get_foreground_pid();
1554 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Request tooltip show and widget command");
1555 vcdc_send_show_tooltip(pid, (bool)data);
1561 int vcd_server_mgr_start(vcd_recognition_mode_e recognition_mode, bool exclusive_cmd, bool start_by_client)
1563 /* 1. check current state */
1564 vcd_state_e state = vcd_config_get_service_state();
1566 if (VCD_STATE_READY != state) {
1567 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Current state is not ready");
1568 return VCD_ERROR_INVALID_STATE;
1570 if (-1 == vcd_client_manager_get_pid()) {
1571 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Manager is NOT available.");
1572 return VCD_ERROR_OPERATION_FAILED;
1575 SLOG(LOG_DEBUG, TAG_VCD, "[Server] set recognition mode = %d", recognition_mode);
1576 vcd_client_set_recognition_mode(recognition_mode);
1578 if (false == exclusive_cmd) {
1579 vcd_client_update_foreground_pid();
1580 /* Notify show tooltip */
1581 if (1 == vcd_config_get_command_type_enabled(VC_COMMAND_TYPE_WIDGET)) {
1582 int pid = vcd_client_widget_get_foreground_pid();
1584 SLOG(LOG_INFO, TAG_VCD, "[Server] Request tooltip show and widget command");
1585 ecore_timer_add(0, __vcd_request_show_tooltip, (void*)true);
1590 vcd_client_manager_set_exclusive(exclusive_cmd);
1594 if (true == start_by_client) {
1595 /* Get foreground pid */
1596 if (0 != vcd_config_get_foreground(&fg_pid)) {
1597 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to get foreground");
1600 /* Set client exclusive option */
1601 if (0 != vcd_client_set_exclusive_command(fg_pid)) {
1602 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to set exclusive command");
1606 int ret = __start_internal_recognition();
1608 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to start recongition : %d", ret);
1612 if (true == start_by_client) {
1613 vcd_client_unset_exclusive_command(fg_pid);
1616 return VCD_ERROR_NONE;
1619 int vcd_server_mgr_stop()
1621 /* 1. Check current state is recording */
1622 if (VCD_STATE_RECORDING != vcd_config_get_service_state()) {
1623 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Current state is not recording");
1624 return VCD_ERROR_INVALID_STATE;
1626 if (-1 == vcd_client_manager_get_pid()) {
1627 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Manager is NOT available.");
1628 return VCD_ERROR_OPERATION_FAILED;
1632 /* 2. Stop recorder */
1633 vcd_recorder_stop();
1636 /* 3. Stop engine recognition */
1637 int ret = vcd_engine_recognize_stop();
1639 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to stop recognition : %d", ret);
1642 /* 4. Set original mode */
1643 vcd_config_set_service_state(VCD_STATE_PROCESSING);
1644 vcdc_send_service_state(VCD_STATE_PROCESSING);
1646 return VCD_ERROR_NONE;
1649 int vcd_server_mgr_cancel()
1651 if (-1 == vcd_client_manager_get_pid()) {
1652 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Manager is NOT available.");
1653 return VCD_ERROR_OPERATION_FAILED;
1656 if (g_restart_timer != NULL) {
1657 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Delete restart engine timer");
1658 ecore_timer_del(g_restart_timer);
1659 g_restart_timer = NULL;
1662 /* 1. Check current state */
1663 vcd_state_e state = vcd_config_get_service_state();
1664 if (VCD_STATE_READY == state) {
1665 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Current state is READY");
1666 vcd_recorder_stop();
1667 return VCD_ERROR_NONE;
1671 /* 2. Stop recorder */
1672 vcd_recorder_stop();
1675 /* 3. Cancel engine */
1676 int ret = vcd_engine_recognize_cancel();
1678 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Fail to cancel : %d", ret);
1681 if (false == vcd_client_manager_get_exclusive()) {
1682 if (1 == vcd_config_get_command_type_enabled(VC_COMMAND_TYPE_WIDGET)) {
1683 int pid = vcd_client_widget_get_foreground_pid();
1685 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Request tooltip hide");
1686 ecore_timer_add(0, __vcd_request_show_tooltip, (void*)false);
1690 vcd_client_manager_set_exclusive(false);
1694 vcd_config_set_service_state(VCD_STATE_READY);
1695 vcdc_send_service_state(VCD_STATE_READY);
1697 return VCD_ERROR_NONE;
1701 int vcd_server_mgr_result_select()
1703 __vcd_send_selected_result(NULL);
1705 return VCD_ERROR_NONE;
1708 int vcd_server_mgr_set_domain(int pid, const char* domain)
1710 /* check if pid is valid */
1711 if (false == vcd_client_manager_is_valid(pid)) {
1712 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] The manager pid(%d) is NOT valid", pid);
1713 return VCD_ERROR_INVALID_PARAMETER;
1716 vcd_state_e state = vcd_config_get_service_state();
1717 if (VCD_STATE_READY != state) {
1718 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Current state is not ready");
1719 return VCD_ERROR_INVALID_STATE;
1722 /* Set domain to engine */
1723 int ret = vcd_engine_set_domain(pid, domain);
1725 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to set domain : %d", ret);
1727 SLOG(LOG_DEBUG, TAG_VCD, "[Server SUCCESS] Set domain");
1733 int vcd_server_mgr_set_private_data(int pid, const char* key, const char* data)
1735 /* check if pid is valid */
1736 if (false == vcd_client_manager_is_valid(pid)) {
1737 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] The manager pid(%d) is NOT valid", pid);
1738 return VCD_ERROR_INVALID_PARAMETER;
1741 vcd_state_e state = vcd_config_get_service_state();
1742 if (VCD_STATE_READY != state) {
1743 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Current state is not ready");
1744 return VCD_ERROR_INVALID_STATE;
1747 /* Set private data to engine */
1748 int ret = vcd_engine_set_private_data(pid, key, data);
1750 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to set private data : %d", ret);
1752 SLOG(LOG_DEBUG, TAG_VCD, "[Server SUCCESS] Set private data");
1758 int vcd_server_mgr_get_private_data(int pid, const char* key, char** data)
1760 /* check if pid is valid */
1761 if (false == vcd_client_manager_is_valid(pid)) {
1762 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] The manager pid(%d) is NOT valid", pid);
1763 return VCD_ERROR_INVALID_PARAMETER;
1765 vcd_state_e state = vcd_config_get_service_state();
1766 if (VCD_STATE_READY != state) {
1767 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Current state is not ready");
1768 return VCD_ERROR_INVALID_STATE;
1771 /* Get private data to engine */
1772 int ret = vcd_engine_get_private_data(pid, key, data);
1774 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to get private data : %d", ret);
1776 SLOG(LOG_DEBUG, TAG_VCD, "[Server SUCCESS] Set private data");
1782 int vcd_server_mgr_do_action(int pid, int type, const char* action)
1786 /* check if pid is valid */
1787 if (false == vcd_client_manager_is_valid(pid)) {
1788 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] The manager pid(%d) is NOT valid", pid);
1789 return VCD_ERROR_INVALID_PARAMETER;
1792 vcd_state_e state = vcd_config_get_service_state();
1793 if (VCD_STATE_READY != state) {
1794 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Current state is not ready");
1795 return VCD_ERROR_INVALID_STATE;
1798 /* Reqeust do action to engine */
1799 if (VCD_SEND_EVENT_TYPE_TEXT == type)
1800 ret = vcd_engine_process_text(pid, action);
1801 else if (VCD_SEND_EVENT_TYPE_LIST_EVENT == type)
1802 ret = vcd_engine_process_list_event(pid, action);
1803 else if (VCD_SEND_EVENT_TYPE_HAPTIC_EVENT == type)
1804 ret = vcd_engine_process_haptic_event(pid, action);
1807 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to process do action : %d", ret);
1809 SLOG(LOG_DEBUG, TAG_VCD, "[Server SUCCESS] Process do action");
1815 int vcd_server_mgr_enable_command_type(int pid, int cmd_type)
1819 /* check if pid is valid */
1820 if (false == vcd_client_manager_is_valid(pid)) {
1821 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] The manager pid(%d) is NOT valid", pid);
1822 return VCD_ERROR_INVALID_PARAMETER;
1825 vcd_state_e state = vcd_config_get_service_state();
1826 if (VCD_STATE_READY != state) {
1827 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Current state is not ready");
1828 return VCD_ERROR_INVALID_STATE;
1831 ret = vcd_config_enable_command_type(cmd_type);
1833 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to enable command type");
1835 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Enable command type(%d)", cmd_type);
1841 int vcd_server_mgr_disable_command_type(int pid, int cmd_type)
1845 /* check if pid is valid */
1846 if (false == vcd_client_manager_is_valid(pid)) {
1847 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] The manager pid(%d) is NOT valid", pid);
1848 return VCD_ERROR_INVALID_PARAMETER;
1851 vcd_state_e state = vcd_config_get_service_state();
1852 if (VCD_STATE_READY != state) {
1853 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Current state is not ready");
1854 return VCD_ERROR_INVALID_STATE;
1857 ret = vcd_config_disable_command_type(cmd_type);
1859 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to disable command type");
1861 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Disable command type(%d)", cmd_type);
1868 * VC Server Functions for Client
1870 int vcd_server_initialize(int pid)
1872 if (false == g_is_engine) {
1873 if (0 != vcd_engine_agent_initialize_current_engine()) {
1874 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] No Engine");
1875 g_is_engine = false;
1876 return VCD_ERROR_ENGINE_NOT_FOUND;
1882 if (false == vcd_engine_is_available_engine()) {
1883 if (0 != vcd_engine_agent_initialize_current_engine()) {
1884 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] No Engine");
1885 return VCD_ERROR_ENGINE_NOT_FOUND;
1889 /* check if pid is valid */
1890 if (true == vcd_client_is_available(pid)) {
1891 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] The pid is already exist");
1892 return VCD_ERROR_INVALID_PARAMETER;
1895 /* Add client information to client manager */
1896 if (0 != vcd_client_add(pid)) {
1897 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to add client info");
1898 return VCD_ERROR_OPERATION_FAILED;
1901 SLOG(LOG_DEBUG, TAG_VCD, "[Server Success] Client Initialize : pid(%d)", pid);
1903 return VCD_ERROR_NONE;
1906 int vcd_server_finalize(int pid)
1908 /* check if pid is valid */
1909 if (false == vcd_client_is_available(pid)) {
1910 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] pid is NOT valid ");
1911 return VCD_ERROR_INVALID_PARAMETER;
1914 /* Remove client information */
1915 if (0 != vcd_client_delete(pid)) {
1916 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Fail to delete client");
1919 if (0 == vcd_client_get_ref_count()) {
1920 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Connected client list is empty");
1921 ecore_timer_add(0, __finalize_quit_ecore_loop, NULL);
1924 SLOG(LOG_DEBUG, TAG_VCD, "[Server Success] Client Finalize : pid(%d)", pid);
1926 return VCD_ERROR_NONE;
1929 int vcd_server_set_command(int pid, vc_cmd_type_e cmd_type)
1931 /* check if pid is valid */
1932 if (false == vcd_client_is_available(pid)) {
1933 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] pid is NOT valid ");
1934 return VCD_ERROR_INVALID_PARAMETER;
1937 if (0 != vcd_client_set_command_type(pid, cmd_type)) {
1938 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to set command type : pid(%d), cmd_type(%d)", pid, cmd_type);
1939 return VCD_ERROR_OPERATION_FAILED;
1945 int vcd_server_unset_command(int pid, vc_cmd_type_e cmd_type)
1947 /* check if pid is valid */
1948 if (false == vcd_client_is_available(pid)) {
1949 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] pid is NOT valid ");
1950 return VCD_ERROR_INVALID_PARAMETER;
1953 if (0 != vcd_client_unset_command_type(pid, cmd_type)) {
1954 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to unset command type : pid(%d), cmd_type(%d)", pid, cmd_type);
1955 return VCD_ERROR_OPERATION_FAILED;
1961 int vcd_server_set_foreground(int pid, bool value)
1963 /* check if pid is valid */
1964 if (false == vcd_client_is_available(pid) && false == vcd_client_widget_is_available(pid)) {
1965 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] pid is NOT valid ");
1966 return VCD_ERROR_INVALID_PARAMETER;
1969 if (0 != vcd_config_set_foreground(pid, value)) {
1970 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to set foreground : pid(%d), value(%d)", pid, value);
1971 return VCD_ERROR_OPERATION_FAILED;
1977 static int __vcd_server_launch_manager_app()
1980 bool running = false;
1983 ret = vcd_client_manager_get_appid(&appid);
1984 if (0 != ret || NULL == appid) {
1985 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to get manager appid");
1986 return VCD_ERROR_OPERATION_FAILED;
1988 ret = app_manager_is_running(appid, &running);
1990 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to check running with appid(%s)", appid);
1993 return VCD_ERROR_OPERATION_FAILED;
1995 if (false == running) {
1996 int tmp_ret = __vcd_is_package_installed(appid);
1997 if (false == tmp_ret) {
1998 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] manager app is not installed, appid(%s)", appid);
2000 ret = __vcd_activate_app_by_appcontrol(appid);
2002 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to activate app");
2007 SLOG(LOG_ERROR, TAG_VCD, "Launch vc manager app: appid(%s)", appid);
2010 ret = __vcd_resume_app(appid);
2012 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to resume app");
2017 SLOG(LOG_ERROR, TAG_VCD, "Resume vc manager app: appid(%s)", appid);
2023 return VCD_ERROR_NONE;
2026 int vcd_server_dialog(int pid, const char* disp_text, const char* utt_text, int continuous)
2028 /* check if pid is valid */
2029 if (false == vcd_client_is_available(pid) && false == vcd_client_widget_is_available(pid)) {
2030 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] pid is NOT valid ");
2031 return VCD_ERROR_INVALID_PARAMETER;
2034 int ret = __vcd_server_launch_manager_app();
2036 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);
2040 ret = vcdc_send_dialog(vcd_client_manager_get_pid(), pid, disp_text, utt_text, continuous);
2042 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);
2049 int vcd_server_is_system_command_valid(int pid, int* is_sys_cmd_valid)
2051 /* check if pid is valid */
2052 if (false == vcd_client_is_available(pid) && false == vcd_client_widget_is_available(pid)) {
2053 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] pid is NOT valid ");
2054 return VCD_ERROR_INVALID_PARAMETER;
2057 /* check if system command is valid */
2058 if (true == vcd_client_manager_is_system_command_valid(vcd_client_manager_get_pid()))
2059 *is_sys_cmd_valid = true;
2061 *is_sys_cmd_valid = false;
2067 int vcd_server_set_exclusive_command(int pid, bool value)
2069 /* check if pid is valid */
2070 if (false == vcd_client_is_available(pid)) {
2071 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] pid is NOT valid ");
2072 return VCD_ERROR_INVALID_PARAMETER;
2075 if (true == value) {
2076 if (0 != vcd_client_set_exclusive_command(pid)) {
2077 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to set exclusive command : pid(%d)", pid);
2078 return VCD_ERROR_OPERATION_FAILED;
2081 if (0 != vcd_client_unset_exclusive_command(pid)) {
2082 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to unset exclusive command : pid(%d)", pid);
2083 return VCD_ERROR_OPERATION_FAILED;
2090 int vcd_server_request_start(int pid, bool stop_by_silence)
2092 /* check if pid is valid */
2093 if (false == vcd_client_is_available(pid)) {
2094 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] pid(%d) is NOT forground client", pid);
2095 return VCD_ERROR_INVALID_PARAMETER;
2099 /* Check current state */
2100 vcd_state_e state = vcd_config_get_service_state();
2102 /* Service state should be ready */
2103 if (VCD_STATE_READY != state) {
2104 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Current state is not Ready : pid(%d)", pid);
2105 return VCD_ERROR_INVALID_STATE;
2108 if (-1 != vcd_client_manager_get_pid()) {
2109 /* Check current pid is valid */
2110 if (false == vcd_client_manager_check_demandable_client(pid)) {
2111 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Current client is NOT available : pid(%d)", pid);
2112 return VCD_ERROR_INVALID_PARAMETER;
2116 ret = vcd_server_mgr_start(stop_by_silence, false);
2118 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Fail to start recognition");
2119 return VCD_ERROR_INVALID_PARAMETER;
2125 int vcd_server_request_stop(int pid)
2128 /* Check current state */
2129 vcd_state_e state = vcd_config_get_service_state();
2131 /* Service state should be ready */
2132 if (VCD_STATE_RECORDING != state) {
2133 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Current state is not Recording : pid(%d)", pid);
2134 return VCD_ERROR_INVALID_STATE;
2137 if (-1 != vcd_client_manager_get_pid()) {
2138 /* Check current pid is valid */
2139 if (false == vcd_client_manager_check_demandable_client(pid)) {
2140 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Current client is NOT available : pid(%d)", pid);
2141 return VCD_ERROR_INVALID_PARAMETER;
2145 ret = vcd_server_mgr_stop();
2147 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Fail to start recognition");
2148 return VCD_ERROR_OPERATION_FAILED;
2151 return VCD_ERROR_NONE;
2154 int vcd_server_request_cancel(int pid)
2157 /* Check current state */
2158 vcd_state_e state = vcd_config_get_service_state();
2160 /* Service state should be recording or processing */
2161 if (VCD_STATE_RECORDING != state && VCD_STATE_PROCESSING != state) {
2162 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Current state is not Recording or Processing : pid(%d)", pid);
2163 return VCD_ERROR_INVALID_STATE;
2166 if (-1 != vcd_client_manager_get_pid()) {
2167 /* Check current pid is valid */
2168 if (false == vcd_client_manager_check_demandable_client(pid)) {
2169 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Current client is NOT available : pid(%d)", pid);
2170 return VCD_ERROR_INVALID_PARAMETER;
2174 ret = vcd_server_mgr_cancel();
2176 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Fail to start recognition");
2177 return VCD_ERROR_OPERATION_FAILED;
2180 return VCD_ERROR_NONE;
2185 * VC Server Functions for Widget lib
2187 int vcd_server_widget_initialize(int pid)
2189 if (false == g_is_engine) {
2190 if (0 != vcd_engine_agent_initialize_current_engine()) {
2191 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] No Engine");
2192 g_is_engine = false;
2193 return VCD_ERROR_ENGINE_NOT_FOUND;
2199 if (false == vcd_engine_is_available_engine()) {
2200 if (0 != vcd_engine_agent_initialize_current_engine()) {
2201 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] No Engine");
2202 return VCD_ERROR_ENGINE_NOT_FOUND;
2206 /* check if pid is valid */
2207 if (true == vcd_client_widget_is_available(pid)) {
2208 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] The pid is already exist");
2209 return VCD_ERROR_NONE;
2212 /* Add client information to client manager */
2213 if (0 != vcd_client_widget_add(pid)) {
2214 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to add client info");
2215 return VCD_ERROR_OPERATION_FAILED;
2218 SLOG(LOG_DEBUG, TAG_VCD, "[Server Success] Initialize widget : pid(%d)", pid);
2220 return VCD_ERROR_NONE;
2223 int vcd_server_widget_finalize(int pid)
2225 /* check if pid is valid */
2226 if (false == vcd_client_widget_is_available(pid)) {
2227 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] pid is NOT valid ");
2228 return VCD_ERROR_INVALID_PARAMETER;
2231 /* Remove client information */
2232 if (0 != vcd_client_widget_delete(pid)) {
2233 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Fail to delete client");
2236 if (0 == vcd_client_get_ref_count()) {
2237 SLOG(LOG_DEBUG, TAG_VCD, "[Server] connected client list is empty");
2238 ecore_timer_add(0, __finalize_quit_ecore_loop, NULL);
2241 return VCD_ERROR_NONE;
2244 int vcd_server_widget_start_recording(int pid, bool widget_command)
2246 /* check if pid is valid */
2247 if (false == vcd_client_widget_is_available(pid)) {
2248 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] pid is NOT valid ");
2249 return VCD_ERROR_INVALID_PARAMETER;
2252 if (true == widget_command) {
2253 vcd_client_widget_set_command(pid);
2254 SLOG(LOG_DEBUG, TAG_VCD, "[Server] widget command is available");
2256 vcd_client_widget_unset_command(pid);
2257 SLOG(LOG_WARN, TAG_VCD, "[Server] widget command is NOT available");
2260 int ret = __start_internal_recognition();
2262 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to start recongition : %d", ret);
2263 ecore_timer_add(0, __vcd_request_show_tooltip, (void*)false);
2269 int vcd_server_widget_start(int pid, bool stop_by_silence)
2271 /* check if pid is valid */
2272 int fore_pid = vcd_client_widget_get_foreground_pid();
2273 if (pid != fore_pid) {
2274 SLOG(LOG_ERROR, TAG_VCD, "[Server] pid is NOT foreground");
2275 return VCD_ERROR_INVALID_PARAMETER;
2278 /* Check current state */
2279 vcd_state_e state = vcd_config_get_service_state();
2281 /* Service state should be ready */
2282 if (VCD_STATE_READY != state) {
2283 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Current state is not Ready : pid(%d)", pid);
2284 return VCD_ERROR_INVALID_STATE;
2287 vcd_client_set_slience_detection(stop_by_silence);
2289 /* Notify show tooltip */
2290 ecore_timer_add(0, __vcd_request_show_tooltip, (void*)true);
2295 int vcd_server_widget_stop(int pid)
2297 /* check if pid is valid */
2298 int fore_pid = vcd_client_widget_get_foreground_pid();
2299 if (pid != fore_pid) {
2300 SLOG(LOG_ERROR, TAG_VCD, "[Server] pid is NOT foreground");
2301 return VCD_ERROR_INVALID_PARAMETER;
2305 /* Check current state */
2306 vcd_state_e state = vcd_config_get_service_state();
2308 /* Service state should be recording */
2309 if (VCD_STATE_RECORDING != state) {
2310 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Current service state is not Recording : pid(%d)", pid);
2311 return VCD_ERROR_INVALID_STATE;
2314 ret = vcd_server_mgr_stop();
2316 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Fail to start recognition");
2317 return VCD_ERROR_OPERATION_FAILED;
2320 return VCD_ERROR_NONE;
2323 int vcd_server_widget_cancel(int pid)
2325 /* check if pid is valid */
2326 int fore_pid = vcd_client_widget_get_foreground_pid();
2327 if (pid != fore_pid) {
2328 SLOG(LOG_ERROR, TAG_VCD, "[Server] pid is NOT foreground");
2329 return VCD_ERROR_INVALID_PARAMETER;
2333 /* Check current state */
2334 vcd_state_e state = vcd_config_get_service_state();
2336 /* Service state should be recording or processing */
2337 if (VCD_STATE_RECORDING != state && VCD_STATE_PROCESSING != state) {
2338 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Current state is not Recording or Processing : pid(%d)", pid);
2339 return VCD_ERROR_INVALID_STATE;
2342 ret = vcd_server_mgr_cancel();
2344 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Fail to cancel recognition : %d", ret);
2348 return VCD_ERROR_NONE;
2351 int vcd_server_widget_enable_asr_result(int pid, bool enable)
2354 ret = vcd_client_widget_set_asr_result_enabled(pid, enable);
2356 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Fail to enable asr result : %d", ret);