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>
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 GList *g_proc_list = NULL;
41 static Ecore_Timer *g_restart_timer = NULL;
44 * @brief Enumerations of send event type.
47 VCD_SEND_EVENT_TYPE_TEXT, /**< send text event to vc engine*/
48 VCD_SEND_EVENT_TYPE_LIST_EVENT, /**< send list event to vc engine */
49 VCD_SEND_EVENT_TYPE_HAPTIC_EVENT /**< send haptic event to vc engine */
50 } vcd_send_event_type_e;
52 static int __vcd_server_launch_manager_app();
55 * VC Server Internal Functions
57 static Eina_Bool __stop_by_silence(void *data)
59 SLOG(LOG_DEBUG, TAG_VCD, "@@@ Silence Detected ");
61 vcd_server_mgr_stop();
63 SLOG(LOG_DEBUG, TAG_VCD, "@@@");
67 static Eina_Bool __cancel_by_interrupt(void *data)
69 SLOG(LOG_DEBUG, TAG_VCD, "@@@ Cancel by interrupt");
71 vcd_server_mgr_cancel();
73 SLOG(LOG_DEBUG, TAG_VCD, "@@@");
77 static void __cancel_by_error(void *data)
79 SLOG(LOG_DEBUG, TAG_VCD, "@@@ Cancel by error");
81 vcd_server_mgr_cancel();
83 SLOG(LOG_DEBUG, TAG_VCD, "@@@");
87 static Eina_Bool __restart_engine(void *data)
89 SLOG(LOG_DEBUG, TAG_VCD, "@@@ Restart by no result");
91 g_restart_timer = NULL;
93 /* Restart recognition */
94 int ret = vcd_engine_recognize_start(true);
96 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to restart recognition : result(%d)", ret);
100 SLOG(LOG_DEBUG, TAG_VCD, "[Server Success] Start engine");
102 if (VCD_RECOGNITION_MODE_RESTART_AFTER_REJECT == vcd_client_get_recognition_mode()) {
103 vcd_config_set_service_state(VCD_STATE_RECORDING);
104 vcdc_send_service_state(VCD_STATE_RECORDING);
107 SLOG(LOG_DEBUG, TAG_VCD, "[Server Success] Restart recognition");
109 SLOG(LOG_DEBUG, TAG_VCD, "@@@");
113 static int __server_recorder_callback(const void* data, const unsigned int length)
115 vcd_state_e state = vcd_config_get_service_state();
116 if (VCD_STATE_READY == state) {
117 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Ready state, but recording");
118 } else if (VCD_STATE_PROCESSING == state) {
122 vce_speech_detect_e speech_detected = VCE_SPEECH_DETECT_NONE;
125 ret = vcd_engine_recognize_audio(data, length, &speech_detected);
129 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to set recording data to engine(%d)", ret);
130 ecore_timer_add(0, __cancel_by_interrupt, NULL);
131 /* Send error cb to manager */
132 if (VCE_ERROR_OUT_OF_NETWORK == ret) {
133 vcdc_send_error_signal_to_manager(vcd_client_manager_get_pid(), VCD_ERROR_TIMED_OUT, "Engine connection failed");
135 vcdc_send_error_signal_to_manager(vcd_client_manager_get_pid(), VCD_ERROR_OPERATION_FAILED, "Engine recognition failed");
140 if (VCE_SPEECH_DETECT_BEGIN == speech_detected) {
141 if (-1 != vcd_client_manager_get_pid()) {
142 /* Manager client is available */
143 if (0 != vcdc_send_speech_detected(vcd_client_manager_get_pid())) {
144 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Fail to send speech detected");
147 } else if (VCE_SPEECH_DETECT_END == speech_detected) {
148 if (VCD_RECOGNITION_MODE_STOP_BY_SILENCE == vcd_client_get_recognition_mode()) {
149 /* silence detected */
150 ecore_timer_add(0, __stop_by_silence, NULL);
151 } else if (VCD_RECOGNITION_MODE_RESTART_AFTER_REJECT == vcd_client_get_recognition_mode()) {
152 /* Stop engine recognition */
153 int ret = vcd_engine_recognize_stop();
155 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to stop recognition : %d", ret);
157 vcd_config_set_service_state(VCD_STATE_PROCESSING);
158 vcdc_send_service_state(VCD_STATE_PROCESSING);
160 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Stop engine only by silence");
161 } else if (VCD_RECOGNITION_MODE_RESTART_CONTINUOUSLY == vcd_client_get_recognition_mode()) {
162 /* Stop engine recognition */
163 int ret = vcd_engine_recognize_stop();
165 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to stop recognition : %d", ret);
173 void __server_recorder_interrupt_callback()
175 SLOG(LOG_DEBUG, TAG_VCD, "@@@ Cancel by sound interrupt");
177 ecore_timer_add(0, __cancel_by_interrupt, NULL);
179 SLOG(LOG_DEBUG, TAG_VCD, "@@@");
182 static void __config_lang_changed_cb(const char* current_lang, void* user_data)
184 SLOG(LOG_DEBUG, TAG_VCD, "@@@ Change language ");
186 /* Current state is recording */
187 vcd_state_e state = vcd_config_get_service_state();
188 if (VCD_STATE_RECORDING == state || VCD_STATE_PROCESSING == state) {
189 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Current state is 'Recording'. Cancel recognition");
190 vcd_server_mgr_cancel();
194 ret = vcd_engine_set_current_language(current_lang);
196 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to set language of engine : %d", ret);
199 SLOG(LOG_DEBUG, TAG_VCD, "@@@");
204 static void __config_foreground_changed_cb(int previous, int current, void* user_data)
206 SLOG(LOG_DEBUG, TAG_VCD, "@@@ Change foreground");
208 SLOG(LOG_DEBUG, TAG_VCD, "Foreground pid(%d)", current);
210 if (VC_NO_FOREGROUND_PID != current) {
211 /* Foreground app is changed */
212 vcd_state_e state = vcd_config_get_service_state();
213 if (VCD_STATE_RECORDING == state) {
214 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Foreground pid(%d) is changed. Cancel recognition", current);
215 ecore_timer_add(0, __cancel_by_interrupt, NULL);
219 SLOG(LOG_DEBUG, TAG_VCD, "@@@");
224 static int __vcd_activate_app_by_appcontrol(const char* appid)
227 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Invalid parameter");
228 return VCD_ERROR_INVALID_PARAMETER;
232 app_control_h app_control = NULL;
233 ret = app_control_create(&app_control);
234 if (APP_CONTROL_ERROR_NONE == ret) {
236 ret = app_control_add_extra_data(app_control, "voice_launch", "get_result");
237 if (APP_CONTROL_ERROR_NONE != ret) {
238 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to add extra data, ret(%d)", ret);
239 app_control_destroy(app_control);
240 return VCD_ERROR_OPERATION_FAILED;
243 ret = app_control_set_app_id(app_control, appid);
244 if (APP_CONTROL_ERROR_NONE != ret) {
245 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to set app id, ret(%d)", ret);
246 app_control_destroy(app_control);
247 return VCD_ERROR_OPERATION_FAILED;
249 // Sent launch request
250 ret = app_control_send_launch_request(app_control, NULL, NULL);
251 if (APP_CONTROL_ERROR_NONE != ret) {
252 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to send launch request, ret(%d)", ret);
253 app_control_destroy(app_control);
254 return VCD_ERROR_OPERATION_FAILED;
256 // Destroy app control
257 ret = app_control_destroy(app_control);
258 if (APP_CONTROL_ERROR_NONE != ret) {
259 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to destroy, ret(%d)", ret);
260 return VCD_ERROR_OPERATION_FAILED;
263 return VCD_ERROR_NONE;
266 static int __vcd_resume_app(const char* appid)
268 app_context_h app_context = NULL;
269 int ret = app_manager_get_app_context(appid, &app_context);
270 if (APP_MANAGER_ERROR_NONE != ret) {
271 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to get app_context, ret(%d), appid(%s)", ret, appid);
272 return VCD_ERROR_OPERATION_FAILED;
275 ret = app_manager_resume_app(app_context);
276 if (APP_MANAGER_ERROR_NONE != ret) {
277 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to resume app, ret(%d), appid(%s)", ret, appid);
278 return VCD_ERROR_OPERATION_FAILED;
280 return VCD_ERROR_NONE;
283 static bool __vcd_is_package_installed(const char* appid)
285 app_info_h app_info = NULL;
286 int ret = app_manager_get_app_info(appid, &app_info);
287 if (APP_MANAGER_ERROR_NONE != ret || NULL == app_info)
289 ret = app_info_destroy(app_info);
290 if (APP_MANAGER_ERROR_NONE != ret)
291 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to destroy app_info, ret(%d)", ret);
295 static bool __vcd_launch_app(const char* result)
297 if (NULL == result) {
298 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Invalid parameter");
299 return VCD_ERROR_INVALID_PARAMETER;
302 GSList* app_list = NULL;
303 if (0 != vc_db_get_appid_list(result, &app_list)) {
304 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] result text is NULL");
305 return VCD_ERROR_INVALID_PARAMETER;
308 if (0 != g_slist_length(app_list)) {
311 vc_deactivated_app_s* temp_app = NULL;
312 iter = g_slist_nth(app_list, 0);
314 while (NULL != iter) {
315 temp_app = iter->data;
317 if (NULL != temp_app) {
318 if (NULL != temp_app->appid) {
320 bool running = false;
321 ret = app_manager_is_running(temp_app->appid, &running);
322 if (APP_MANAGER_ERROR_NONE != ret) {
323 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to check running with appid(%s)", temp_app->appid);
324 free(temp_app->appid);
325 temp_app->appid = NULL;
328 return VCD_ERROR_OPERATION_FAILED;
330 if (false == running) {
331 int tmp_ret = __vcd_is_package_installed(temp_app->appid);
332 if (false == tmp_ret) {
333 SLOG(LOG_WARN, TAG_VCD, "[WARNING] app is not installed, appid(%s)", temp_app->appid);
335 ret = __vcd_activate_app_by_appcontrol(temp_app->appid);
337 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to activate app");
338 free(temp_app->appid);
339 temp_app->appid = NULL;
344 SLOG(LOG_ERROR, TAG_VCD, "Launch app: appid(%s) result(%s)", temp_app->appid, result);
347 ret = __vcd_resume_app(temp_app->appid);
349 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to resume app");
350 free(temp_app->appid);
351 temp_app->appid = NULL;
356 SLOG(LOG_ERROR, TAG_VCD, "Resume app: appid(%s) result(%s)", temp_app->appid, result);
358 free(temp_app->appid);
359 temp_app->appid = NULL;
364 iter = g_slist_next(iter);
369 return VCD_ERROR_NONE;
372 static Eina_Bool __vcd_send_selected_result(void *data)
374 GSList* pid_list = NULL;
375 const char* result = vcd_client_manager_get_result_text();
377 if (0 != vc_info_parser_get_result_pid_list(&pid_list, result)) {
378 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Fail to get pid list. No result");
380 if (0 < g_slist_length(pid_list)) {
382 vc_cmd_s* temp_cmd = NULL;
387 iter = g_slist_nth(pid_list, 0);
388 while (NULL != iter) {
389 temp_cmd = iter->data;
391 if (NULL != temp_cmd && (pre_pid != temp_cmd->pid || pre_type == VC_COMMAND_TYPE_WIDGET || temp_cmd->type == VC_COMMAND_TYPE_WIDGET)) {
392 /* Launch deactivated several apps that is matched with result */
393 ret = __vcd_launch_app(result);
395 SLOG(LOG_ERROR, TAG_VCD, "Fail to launch or resume app, ret(%d) result(%s)", ret, result);
397 /* send result noti */
398 ret = vcdc_send_result(temp_cmd->pid, vcd_client_manager_get_pid(), temp_cmd->type);
400 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Fail to send result, ret(%d)", ret);
403 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Send result : pid(%d) type(%d)", temp_cmd->pid, temp_cmd->type);
404 pre_pid = temp_cmd->pid;
405 pre_type = temp_cmd->type;
411 pid_list = g_slist_remove_link(pid_list, iter);
412 iter = g_slist_nth(pid_list, 0);
417 if (VCD_RECOGNITION_MODE_RESTART_CONTINUOUSLY != vcd_client_get_recognition_mode()) {
418 vcd_config_set_service_state(VCD_STATE_READY);
419 vcdc_send_service_state(VCD_STATE_READY);
425 int vcd_send_asr_result(vce_asr_result_event_e event, const char* asr_result, void *user_data)
427 if (NULL != asr_result) {
428 SECURE_SLOG(LOG_DEBUG, TAG_VCD, "[Server] ASR result - Event(%d), Text(%s)", event, asr_result);
429 vcdc_send_pre_result_to_manager(vcd_client_manager_get_pid(), event, asr_result);
432 return VCD_ERROR_NONE;
435 int vcd_send_nlg_result(const char* nlg_result, void *user_data)
437 int ret = __vcd_server_launch_manager_app();
439 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);
443 ret = vcdc_send_dialog(vcd_client_manager_get_pid(), -1, nlg_result, NULL, 0); //0: VC_DIALOG_END
445 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);
449 static void* __recorder_stop(void *data)
455 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)
459 if (VCD_STATE_PROCESSING != vcd_config_get_service_state()) {
460 if (VCD_RECOGNITION_MODE_RESTART_CONTINUOUSLY != vcd_client_get_recognition_mode()) {
461 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Current state is not 'Processing' and mode is not 'Restart continuously'");
462 return VCD_ERROR_INVALID_STATE;
466 vc_info_parser_unset_result(vcd_client_manager_get_exclusive());
467 vcd_client_manager_set_result_text(all_result);
469 SECURE_SLOG(LOG_INFO, TAG_VCD, "[Server] Event(%d), Text(%s) Nonfixed(%s) Msg(%s) Result count(%d)",
470 event, all_result, non_fixed_result, msg, count);
472 if (VCD_RECOGNITION_MODE_RESTART_AFTER_REJECT == vcd_client_get_recognition_mode()) {
473 if (VCE_RESULT_EVENT_REJECTED == event) {
474 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Restart by no or rejected result");
475 /* If no result and restart option is ON */
476 /* Send reject message */
477 bool temp = vcd_client_manager_get_exclusive();
478 vc_info_parser_set_result(all_result, event, msg, NULL, temp);
479 ret = vcdc_send_result_to_manager(vcd_client_manager_get_pid(), VC_RESULT_TYPE_NOTIFICATION);
481 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Fail to send result");
484 g_restart_timer = ecore_timer_add(0, __restart_engine, NULL);
487 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Stop recorder due to success");
488 //vcd_recorder_stop();
489 ecore_main_loop_thread_safe_call_sync(__recorder_stop, NULL);
490 } else if (VCD_RECOGNITION_MODE_RESTART_CONTINUOUSLY == vcd_client_get_recognition_mode()) {
491 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Restart continuously");
492 /* Restart option is ON */
493 g_restart_timer = ecore_timer_add(0, __restart_engine, NULL);
494 if (VCE_RESULT_EVENT_REJECTED == event) {
495 bool temp = vcd_client_manager_get_exclusive();
496 vc_info_parser_set_result(all_result, event, msg, NULL, temp);
497 ret = vcdc_send_result_to_manager(vcd_client_manager_get_pid(), VC_RESULT_TYPE_NOTIFICATION);
499 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Fail to send result");
505 /* if nlu_result is exist, Add command handle(is_action) into result list */
507 SLOG(LOG_DEBUG, TAG_VCD, "[Server] @ Get engine result @");
509 vc_cmd_s* temp_cmd = NULL;
510 vc_cmd_list_h vc_cmd_list = NULL;
512 if (0 != vc_cmd_list_create(&vc_cmd_list)) {
513 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Fail to create command list");
514 vcd_client_manager_set_exclusive(false);
515 vcd_config_set_service_state(VCD_STATE_READY);
516 vcdc_send_service_state(VCD_STATE_READY);
517 return VCD_ERROR_NONE;
520 /* priority filter */
521 /* system > exclusive > widget > foreground > system_background > background */
523 int* filtered_id = (int*)calloc(count, sizeof(int));
525 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to allocate memory");
526 return VCD_ERROR_OUT_OF_MEMORY;
528 int filtered_count = 0;
529 int top_priority = VC_COMMAND_PRIORITY_BACKGROUND;
530 for (i = 0; i < count; i++) {
531 SLOG(LOG_INFO, TAG_VCD, "[Server] [%d] Result id(%d)", i, result_id[i]);
533 if (0 > result_id[i]) {
534 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Result ID(%d) is NOT valid", result_id[i]);
538 ret = vcd_client_get_cmd_from_result_id(result_id[i], &temp_cmd);
539 if (0 == ret && NULL != temp_cmd) {
540 if (top_priority == temp_cmd->priority) {
541 filtered_id[filtered_count] = result_id[i];
543 } else if (top_priority > temp_cmd->priority) {
544 filtered_id[0] = result_id[i];
546 top_priority = temp_cmd->priority;
549 vc_cmd_destroy((vc_cmd_h)temp_cmd);
555 if (top_priority >= VC_COMMAND_PRIORITY_WIDGET) {
556 int pid = vcd_client_widget_get_foreground_pid();
558 if (NULL != all_result) {
559 vc_info_parser_set_result(all_result, event, msg, NULL, false);
561 vcd_client_widget_get_asr_result_enabled(pid, &enable);
562 if (true == enable) {
563 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Send ASR result to Widget client");
564 bool is_consumed = false;
565 if (NULL != user_info) {
568 if (0 != vcdc_send_asr_result(pid, event, all_result, VC_COMMAND_TYPE_WIDGET, &is_consumed)) {
569 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to send asr result");
571 SLOG(LOG_DEBUG, TAG_VCD, "[Server] ASR result is consumed(%d)", is_consumed);
572 if (true == is_consumed) {
573 if (NULL != user_info) {
575 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Send whether ASR result is consumed or not (%d)", *user_info);
577 vcdc_send_show_tooltip(pid, false);
578 if (-1 != vcd_client_manager_get_pid()) {
579 /* Manager client is available */
580 vc_info_parser_unset_result(false);
581 vc_info_parser_set_result(all_result, VC_RESULT_EVENT_RESULT_SUCCESS, msg, NULL, false);
582 if (0 != vcdc_send_result_to_manager(vcd_client_manager_get_pid(), VC_RESULT_TYPE_NOTIFICATION)) {
583 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Fail to send result");
587 vcd_client_manager_set_exclusive(false);
589 vcd_config_set_service_state(VCD_STATE_READY);
590 vcdc_send_service_state(VCD_STATE_READY);
591 vc_cmd_list_destroy(vc_cmd_list, true);
592 if (NULL != filtered_id) {
596 return VCD_ERROR_NONE;
605 for (i = 0; i < filtered_count; i++) {
606 SLOG(LOG_INFO, TAG_VCD, "[Server] [%d] Filtered Result id(%d)", i, filtered_id[i]);
608 if (filtered_id[i] < 0) {
609 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Filtered ID(%d) is NOT valid", filtered_id[i]);
613 ret = vcd_client_get_cmd_from_result_id(filtered_id[i], &temp_cmd);
614 if (0 == ret && NULL != temp_cmd) {
615 switch (temp_cmd->format) {
616 case VC_CMD_FORMAT_FIXED:
617 case VC_CMD_FORMAT_FIXED_AND_VFIXED:
618 case VC_CMD_FORMAT_VFIXED_AND_FIXED:
619 case VC_CMD_FORMAT_PARTIAL:
620 case VC_CMD_FORMAT_FIXED_AND_NONFIXED:
621 case VC_CMD_FORMAT_NONFIXED_AND_FIXED:
623 case VC_CMD_FORMAT_ACTION:
627 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Unknown command type : %d", temp_cmd->type);
631 if (0 != vc_cmd_list_add(vc_cmd_list, (vc_cmd_h)temp_cmd)) {
632 SLOG(LOG_DEBUG, TAG_VCD, "Fail to add command to list");
633 vc_cmd_destroy((vc_cmd_h)temp_cmd);
637 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] NOT found matached result(%d)", filtered_id[i]);
641 if (NULL != filtered_id) {
646 if (NULL != nlu_result) {
647 SECURE_SLOG(LOG_INFO, TAG_VCD, "[Server] NLU (%s)", nlu_result);
648 vc_info_parser_set_nlu_result(nlu_result);
649 if (0 == is_action) {
651 if (0 != vc_cmd_create(&nlu_cmd)) {
652 SLOG(LOG_ERROR, TAG_VCD, "Fail to nlu cmd create");
654 if (0 != vc_cmd_set_type(nlu_cmd, VC_COMMAND_TYPE_SYSTEM)) {
655 SLOG(LOG_ERROR, TAG_VCD, "Fail to set type");
657 if (0 != vc_cmd_set_pid(nlu_cmd, vcd_client_manager_get_pid())) {
658 SLOG(LOG_ERROR, TAG_VCD, "Fail to set pid");
660 if (0 != vc_cmd_set_format(nlu_cmd, VC_CMD_FORMAT_ACTION)) {
661 SLOG(LOG_ERROR, TAG_VCD, "Fail to set format");
663 if (0 != vc_cmd_list_add(vc_cmd_list, nlu_cmd)) {
664 SLOG(LOG_ERROR, TAG_VCD, "Fail to add nlu cmd to list");
665 vc_cmd_destroy(nlu_cmd);
671 vc_cmd_print_list(vc_cmd_list);
673 SLOG(LOG_DEBUG, TAG_VCD, "[Server] @@@@");
675 int result_count = 0;
676 vc_cmd_list_get_count(vc_cmd_list, &result_count);
678 if (0 == result_count) {
680 if (NULL != all_result) {
681 SECURE_SLOG(LOG_DEBUG, TAG_VCD, "[Server] Engine result is no command : %s", all_result);
683 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Engine result is NULL");
685 bool temp = vcd_client_manager_get_exclusive();
686 vc_info_parser_set_result(all_result, event, msg, NULL, temp);
688 int pid = vcd_client_widget_get_foreground_pid();
690 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Request tooltip hide");
691 /* Send to hide tooltip */
692 vcdc_send_show_tooltip(pid, false);
695 if (-1 != vcd_client_manager_get_pid()) {
696 /* Manager client is available */
697 if (0 != vcdc_send_result_to_manager(vcd_client_manager_get_pid(), VC_RESULT_TYPE_NORMAL)) {
698 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Fail to send result");
702 vcd_client_manager_set_exclusive(false);
704 return VCD_ERROR_NONE;
706 if (false == vcd_client_manager_get_exclusive()) {
707 int pid = vcd_client_widget_get_foreground_pid();
709 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Request tooltip hide");
710 vcdc_send_show_tooltip(pid, false);
713 vc_info_parser_set_result(all_result, event, msg, vc_cmd_list, false);
715 if (-1 != vcd_client_manager_get_pid()) {
716 /* Manager client is available */
717 if (0 != vcdc_send_result_to_manager(vcd_client_manager_get_pid(), VC_RESULT_TYPE_NORMAL)) {
718 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Fail to send result");
721 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Manager is NOT available. Send result to client directly");
722 /* Send result to client */
723 ecore_timer_add(0, __vcd_send_selected_result, NULL);
726 /* exclusive command */
727 vc_info_parser_set_result(all_result, event, msg, vc_cmd_list, true);
729 if (-1 != vcd_client_manager_get_pid()) {
730 /* Manager client is available */
731 if (0 != vcdc_send_result_to_manager(vcd_client_manager_get_pid(), VC_RESULT_TYPE_NORMAL)) {
732 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Fail to send result");
735 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Manager is NOT available");
738 vcd_client_manager_set_exclusive(false);
742 vc_cmd_list_destroy(vc_cmd_list, true);
744 return VCD_ERROR_NONE;
748 if (NULL == result_id) {
750 if (NULL != all_result) {
751 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Engine result is no command : %s", all_result);
752 bool temp = vcd_client_manager_get_exclusive();
753 vc_info_parser_set_result(all_result, event, msg, NULL, temp);
756 int pid = vcd_client_widget_get_foreground_pid();
758 if (NULL != all_result) {
759 /* Send result text to widget */
760 vcdc_send_result(pid, vcd_client_manager_get_pid(), VC_COMMAND_TYPE_WIDGET);
763 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Request tooltip hide");
764 /* Send to hide tooltip */
765 vcdc_send_show_tooltip(pid, false);
768 if (-1 != vcd_client_manager_get_pid()) {
769 /* Manager client is available */
770 if (0 != vcdc_send_result_to_manager(vcd_client_manager_get_pid(), VC_RESULT_TYPE_NORMAL)) {
771 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Fail to send result");
775 vcd_client_manager_set_exclusive(false);
781 SLOG(LOG_DEBUG, TAG_VCD, "[Server] @ Get engine result @");
784 vc_cmd_s* temp_cmd = NULL;
785 vc_cmd_list_h vc_cmd_list = NULL;
787 if (0 != vc_cmd_list_create(&vc_cmd_list)) {
788 SLOG(LOG_ERROR, TAG_VCD, "[Server] Fail to create command list");
789 vcd_client_manager_set_exclusive(false);
790 vcd_config_set_service_state(VCD_STATE_READY);
791 vcdc_send_service_state(VCD_STATE_READY);
796 for (i = 0; i < count; i++) {
797 SLOG(LOG_DEBUG, TAG_VCD, "[Server] [%d] Result ID(%d)", i, result_id[i]);
799 if (result_id[i] < 0) {
800 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Result ID(%d) is NOT valid", result_id[i]);
804 ret = vcd_client_get_cmd_from_result_id(result_id[i], &temp_cmd);
805 if (0 == ret && NULL != temp_cmd) {
806 switch (temp_cmd->format) {
807 case VC_CMD_FORMAT_FIXED:
808 case VC_CMD_FORMAT_FIXED_AND_VFIXED:
809 case VC_CMD_FORMAT_VFIXED_AND_FIXED:
810 case VC_CMD_FORMAT_PARTIAL:
811 /* Nonfixed result is NOT valid */
813 case VC_CMD_FORMAT_FIXED_AND_NONFIXED:
814 if (NULL == temp_cmd->parameter) {
815 if (NULL != non_fixed_result) {
816 temp_cmd->parameter = strdup(non_fixed_result);
819 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Command type is NOT vaild. Parameter (%s)", temp_cmd->parameter);
822 case VC_CMD_FORMAT_NONFIXED_AND_FIXED:
823 if (NULL == temp_cmd->command) {
824 if (NULL != non_fixed_result) {
825 temp_cmd->command = strdup(non_fixed_result);
828 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Command type is NOT vaild. Command (%s)", temp_cmd->command);
833 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Unknown command type : %d", temp_cmd->type);
837 if (0 != vc_cmd_list_add(vc_cmd_list, (vc_cmd_h)temp_cmd)) {
838 SLOG(LOG_DEBUG, TAG_VCD, "Fail to add command to list");
839 vc_cmd_destroy((vc_cmd_h)temp_cmd);
842 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] NOT found matached result(%d)", result_id[i]);
846 vc_cmd_print_list(vc_cmd_list);
848 SLOG(LOG_DEBUG, TAG_VCD, "[Server] @@@@");
850 int result_count = 0;
851 vc_cmd_list_get_count(vc_cmd_list, &result_count);
853 if (false == vcd_client_manager_get_exclusive()) {
854 int pid = vcd_client_widget_get_foreground_pid();
856 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Request tooltip hide");
857 vcdc_send_show_tooltip(pid, false);
860 vc_info_parser_set_result(all_result, event, msg, vc_cmd_list, false);
862 if (-1 != vcd_client_manager_get_pid()) {
863 /* Manager client is available */
864 if (0 != vcdc_send_result_to_manager(vcd_client_manager_get_pid(), VC_RESULT_TYPE_NORMAL)) {
865 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Fail to send result");
868 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Manager is NOT available. Send result to client directly");
869 /* Send result to client */
870 ecore_timer_add(0, __vcd_send_selected_result, NULL);
873 /* exclusive command */
874 vc_info_parser_set_result(all_result, event, msg, vc_cmd_list, true);
876 if (-1 != vcd_client_manager_get_pid()) {
877 /* Manager client is available */
878 if (0 != vcdc_send_result_to_manager(vcd_client_manager_get_pid(), VC_RESULT_TYPE_NORMAL)) {
879 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Fail to send result");
882 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Manager is NOT available");
885 vcd_client_manager_set_exclusive(false);
888 vc_cmd_list_destroy(vc_cmd_list, true);
895 static void __vcd_server_nlu_result_cb(vce_result_event_e event, const char* nlu_result, void *user_data)
897 SECURE_SLOG(LOG_DEBUG, TAG_VCD, "[Server] NLU result cb - event(%d)", event);
898 SECURE_SLOG(LOG_DEBUG, TAG_VCD, "[Server] result (%s)", nlu_result);
900 int ret = vc_info_parser_set_nlu_result(nlu_result);
902 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to set nlu result (%d)", ret);
909 int vcd_send_error(vce_error_e error, const char* msg, void *user_data)
911 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Engine Error cb - reason(%d), msg(%s)", error, msg);
912 ecore_main_loop_thread_safe_call_async(__cancel_by_error, NULL);
914 char* error_msg = NULL;
916 error_msg = strdup(msg);
919 if (0 != vcdc_send_error_signal_to_manager(vcd_client_manager_get_pid(), error, error_msg)) {
920 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to send error signal");
923 if (NULL != error_msg) {
928 return VCD_ERROR_NONE;
932 * vcd server Interfaces
934 static void __vcd_file_clean_up()
936 SLOG(LOG_DEBUG, TAG_VCD, "== Old file clean up == ");
939 struct dirent *dirp = NULL;
941 dp = opendir(VC_RUNTIME_INFO_ROOT);
943 SLOG(LOG_ERROR, TAG_VCD, "[File message WARN] Fail to open path : %s", VC_RUNTIME_INFO_ROOT);
947 char remove_path[256] = {0, };
952 if (!strncmp("vc_", dirp->d_name, strlen("vc_"))) {
953 memset(remove_path, 0, 256);
954 snprintf(remove_path, 256, "%s/%s", VC_RUNTIME_INFO_ROOT, dirp->d_name);
957 if (0 != remove(remove_path)) {
958 SLOG(LOG_WARN, TAG_VCD, "[File message WARN] Fail to remove file : %s", remove_path);
960 SLOG(LOG_DEBUG, TAG_VCD, "[File message] Remove file : %s", remove_path);
964 } while (NULL != dirp);
971 static int __vcd_db_clean_up()
974 int cnt = VC_COMMAND_TYPE_FOREGROUND;
976 if (VC_COMMAND_TYPE_BACKGROUND != cnt)
977 ret = vc_db_delete_commands(-1, cnt, NULL);
978 } while (VC_COMMAND_TYPE_EXCLUSIVE >= ++cnt);
983 int vcd_initialize(vce_request_callback_s *callback)
987 /* Remove old file */
988 __vcd_file_clean_up();
990 /* initialize modules */
991 ret = vcd_config_initialize(__config_lang_changed_cb, __config_foreground_changed_cb, NULL);
993 SLOG(LOG_ERROR, TAG_VCD, "[Server WARNING] Fail to initialize config.");
997 ret = __vcd_db_clean_up();
999 SLOG(LOG_ERROR, TAG_VCD, "[Server WARNING] Fail to remove db data");
1002 vcd_config_set_service_state(VCD_STATE_NONE);
1004 ret = vcd_engine_agent_init();
1006 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to engine agent initialize : result(%d)", ret);
1010 if (0 != vcd_recorder_create(__server_recorder_callback, __server_recorder_interrupt_callback)) {
1011 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to create recorder");
1012 return VCD_ERROR_OPERATION_FAILED;
1016 if (0 != vcd_engine_agent_load_current_engine(callback)) {
1017 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to load current engine");
1018 return VCD_ERROR_OPERATION_FAILED;
1021 /* Initialize manager info */
1022 vcd_client_manager_unset();
1024 vcd_config_set_service_state(VCD_STATE_READY);
1025 vcdc_send_service_state(VCD_STATE_READY);
1027 SLOG(LOG_DEBUG, TAG_VCD, "[Server SUCCESS] initialize");
1035 if (0 < g_list_length(g_proc_list)) {
1036 iter = g_list_first(g_proc_list);
1037 while (NULL != iter) {
1038 g_proc_list = g_list_remove_link(g_proc_list, iter);
1039 iter = g_list_first(g_proc_list);
1043 if (g_restart_timer != NULL) {
1044 ecore_timer_del(g_restart_timer);
1045 g_restart_timer = NULL;
1048 vcd_state_e state = vcd_config_get_service_state();
1049 if (VCD_STATE_READY != state) {
1050 if (VCD_STATE_RECORDING == state) {
1051 vcd_recorder_stop();
1053 vcd_engine_recognize_cancel();
1055 if (0 != vcd_recorder_destroy()) {
1056 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to destroy recorder");
1058 SLOG(LOG_DEBUG, TAG_VCD, "[Server] destroy recorder");
1061 if (0 != vcd_engine_agent_release()) {
1062 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to release engine");
1064 SLOG(LOG_DEBUG, TAG_VCD, "[Server] release engine");
1067 vcd_client_manager_unset_appid();
1069 vcd_config_set_service_state(VCD_STATE_NONE);
1070 vcdc_send_service_state(VCD_STATE_NONE);
1072 SLOG(LOG_DEBUG, TAG_VCD, "[Server] mode finalize");
1077 static Eina_Bool __finalize_quit_ecore_loop(void *data)
1079 SLOG(LOG_ERROR, TAG_VCD, "[Server] quit ecore main loop");
1080 ecore_main_loop_quit();
1084 static void __read_proc()
1087 struct dirent *dirp = NULL;
1091 if (0 < g_list_length(g_proc_list)) {
1092 iter = g_list_first(g_proc_list);
1093 while (NULL != iter) {
1094 g_proc_list = g_list_remove_link(g_proc_list, iter);
1095 iter = g_list_first(g_proc_list);
1099 dp = opendir("/proc");
1101 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to open proc");
1107 tmp = atoi(dirp->d_name);
1108 if (0 >= tmp) continue;
1109 g_proc_list = g_list_append(g_proc_list, GINT_TO_POINTER(tmp));
1111 } while (NULL != dirp);
1117 static void __vcd_cleanup_client(vcd_client_type_e type)
1119 int* client_list = NULL;
1120 int client_count = 0;
1127 if (VCD_CLIENT_TYPE_NORMAL == type) {
1128 ret = vcd_client_get_list(&client_list, &client_count);
1129 } else if (VCD_CLIENT_TYPE_WIDGET == type) {
1130 ret = vcd_client_widget_get_list(&client_list, &client_count);
1131 } else if (VCD_CLIENT_TYPE_MANAGER == type) {
1132 mgr_pid = vcd_client_manager_get_pid();
1133 client_list = &mgr_pid;
1135 if (-1 == mgr_pid) {
1136 SLOG(LOG_WARN, TAG_VCD, "[WARNING] Invalid Manager pid");
1141 if (0 == ret || mgr_pid > 0) {
1142 SLOG(LOG_DEBUG, TAG_VCD, "@@@ Clean up %s client ", type ? (type == 1) ? "Widget" : "Manager" : "Normal");
1143 if (NULL != client_list && client_count > 0) {
1144 for (i = 0; i < client_count; i++) {
1147 for (j = 0; j < g_list_length(g_proc_list); j++) {
1148 iter = g_list_nth(g_proc_list, j);
1150 if (*(client_list + i) == GPOINTER_TO_INT(iter->data)) {
1151 SLOG(LOG_DEBUG, TAG_VCD, "%s pid(%d) is running", type ? (type == 1) ? "Widget" : "Manager" : "Normal", *(client_list + i));
1158 if (false == exist) {
1159 SLOG(LOG_ERROR, TAG_VCD, "%s pid(%d) should be removed", type ? (type == 1) ? "Widget" : "Manager" : "Normal", *(client_list + i));
1160 if (VCD_CLIENT_TYPE_NORMAL == type)
1161 vcd_server_finalize(*(client_list + i));
1162 else if (VCD_CLIENT_TYPE_WIDGET == type)
1163 vcd_server_widget_finalize(*(client_list + i));
1165 vcd_server_mgr_finalize(mgr_pid);
1169 SLOG(LOG_DEBUG, TAG_VCD, "@@@");
1171 if (NULL != client_list && -1 == mgr_pid) {
1178 Eina_Bool vcd_cleanup_client_all(void *data)
1182 __vcd_cleanup_client(VCD_CLIENT_TYPE_NORMAL);
1183 __vcd_cleanup_client(VCD_CLIENT_TYPE_WIDGET);
1184 __vcd_cleanup_client(VCD_CLIENT_TYPE_MANAGER);
1187 if (0 == vcd_client_get_list(&client_list, &client_count)) {
1188 SLOG(LOG_DEBUG, TAG_VCD, "@@@ Clean up client ");
1189 if (NULL != client_list && client_count > 0) {
1190 for (i = 0; i < client_count; i++) {
1193 for (j = 0; j < g_list_length(g_proc_list); j++) {
1194 iter = g_list_nth(g_proc_list, j);
1196 if (client_list[i] == GPOINTER_TO_INT(iter->data)) {
1197 SLOG(LOG_DEBUG, TAG_VCD, "pid(%d) is running", client_list[i]);
1204 if (false == exist) {
1205 SLOG(LOG_ERROR, TAG_VCD, "pid(%d) should be removed", client_list[i]);
1206 vcd_server_finalize(client_list[i]);
1209 result = vcdc_send_hello(client_list[i], VCD_CLIENT_TYPE_NORMAL);
1212 SLOG(LOG_DEBUG, TAG_VCD, "[Server] pid(%d) should be removed.", client_list[i]);
1213 vcd_server_finalize(client_list[i]);
1214 } else if (-1 == result) {
1215 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Hello result has error");
1220 SLOG(LOG_DEBUG, TAG_VCD, "@@@");
1222 if (NULL != client_list) {
1227 /* If app is in background state, app cannot response message. */
1228 if (0 == vcd_client_widget_get_list(&client_list, &client_count)) {
1229 SLOG(LOG_DEBUG, TAG_VCD, "@@@ Clean up widget");
1230 if (NULL != client_list && client_count > 0) {
1231 for (i = 0; i < client_count; i++) {
1234 for (j = 0; j < g_list_length(g_proc_list); j++) {
1235 iter = g_list_nth(g_proc_list, j);
1237 if (client_list[i] == GPOINTER_TO_INT(iter->data)) {
1238 SLOG(LOG_DEBUG, TAG_VCD, "widget pid(%d) is running", client_list[i]);
1245 if (false == exist) {
1246 SLOG(LOG_ERROR, TAG_VCD, "widget pid(%d) should be removed", client_list[i]);
1247 vcd_server_widget_finalize(client_list[i]);
1250 result = vcdc_send_hello(client_list[i], VCD_CLIENT_TYPE_WIDGET);
1253 SLOG(LOG_DEBUG, TAG_VCD, "[Server] widget pid(%d) should be removed.", client_list[i]);
1254 vcd_server_widget_finalize(client_list[i]);
1255 } else if (-1 == result) {
1256 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Hello result has error");
1261 SLOG(LOG_DEBUG, TAG_VCD, "@@@");
1264 if (NULL != client_list) {
1272 int mgr_pid = vcd_client_manager_get_pid();
1274 for (j = 0; j < g_list_length(g_proc_list); j++) {
1275 iter = g_list_nth(g_proc_list, j);
1277 if (mgr_pid == GPOINTER_TO_INT(iter->data)) {
1278 SLOG(LOG_DEBUG, TAG_VCD, "manager pid(%d) is running", mgr_pid);
1285 if (false == exist) {
1286 SLOG(LOG_ERROR, TAG_VCD, "manager pid (%d) should be removed", mgr_pid);
1287 vcd_server_mgr_finalize(mgr_pid);
1294 int vcd_server_get_service_state()
1296 return vcd_config_get_service_state();
1299 int vcd_server_get_foreground()
1302 vcd_config_get_foreground(&pid);
1310 int vcd_server_mgr_initialize(int pid)
1312 /* check if pid is valid */
1313 if (false == vcd_client_manager_is_valid(pid)) {
1314 SLOG(LOG_ERROR, TAG_VCD, "[Server] old manager pid(%d) be removed", vcd_client_manager_get_pid());
1315 vcd_server_mgr_cancel();
1316 vcd_client_manager_unset();
1319 /* Add client information to client manager */
1320 if (0 != vcd_client_manager_set(pid)) {
1321 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to add manager");
1322 return VCD_ERROR_OPERATION_FAILED;
1325 if (0 != vcdc_send_manager_pid(pid))
1326 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Fail to send manager pid");
1328 SLOG(LOG_DEBUG, TAG_VCD, "[Server Success] Manager initialize : pid(%d)", pid);
1330 return VCD_ERROR_NONE;
1333 int vcd_server_mgr_finalize(int pid)
1335 /* check if pid is valid */
1336 if (false == vcd_client_manager_is_valid(pid)) {
1337 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] The manager pid(%d) is NOT valid", pid);
1338 return VCD_ERROR_INVALID_PARAMETER;
1341 /* Cancel recognition */
1342 vcd_server_mgr_cancel();
1344 if (0 != vcdc_send_manager_pid(-1))
1345 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Fail to send manager pid");
1347 /* Remove manager information */
1348 if (0 != vcd_client_manager_unset()) {
1349 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Fail to delete client");
1352 if (0 == vcd_client_get_ref_count()) {
1353 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Connected client list is empty");
1354 ecore_timer_add(0, __finalize_quit_ecore_loop, NULL);
1357 SLOG(LOG_DEBUG, TAG_VCD, "[Server Success] Manager Finalize : pid(%d)", pid);
1359 return VCD_ERROR_NONE;
1362 int vcd_server_mgr_set_command(int pid)
1364 if (0 != vcd_client_manager_set_command(pid)) {
1365 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] The manager pid(%d) is NOT valid", pid);
1366 return VCD_ERROR_INVALID_PARAMETER;
1368 return VCD_ERROR_NONE;
1371 int vcd_server_mgr_unset_command(int pid)
1373 if (0 != vcd_client_manager_unset_command(pid)) {
1374 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] The manager pid(%d) is NOT valid", pid);
1375 return VCD_ERROR_INVALID_PARAMETER;
1377 return VCD_ERROR_NONE;
1380 int vcd_server_mgr_set_demandable_client(int pid)
1382 /* check if pid is valid */
1383 if (false == vcd_client_manager_is_valid(pid)) {
1384 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] The manager pid(%d) is NOT valid", pid);
1385 return VCD_ERROR_INVALID_PARAMETER;
1388 GSList* client_list = NULL;
1389 if (0 != vc_info_parser_get_demandable_clients(&client_list)) {
1390 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to get demandable client");
1391 return VCD_ERROR_OPERATION_FAILED;
1394 /* Save client list */
1395 if (0 != vcd_client_manager_set_demandable_client(pid, client_list)) {
1396 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to set demandable client list");
1397 return VCD_ERROR_OPERATION_FAILED;
1400 return VCD_ERROR_NONE;
1403 int vcd_server_mgr_set_audio_type(int pid, const char* audio_type)
1405 /* check if pid is valid */
1406 if (false == vcd_client_manager_is_valid(pid)) {
1407 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] The manager pid(%d) is NOT valid", pid);
1408 return VCD_ERROR_INVALID_PARAMETER;
1412 vce_audio_type_e type = VCE_AUDIO_TYPE_PCM_S16_LE;
1416 ret = vcd_engine_get_audio_format(audio_type, &type, &rate, &channel);
1418 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to get audio format : %d", ret);
1419 return VCD_ERROR_OPERATION_FAILED;
1422 ret = vcd_recorder_set(audio_type, type, rate, channel);
1424 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to set audio in type : %d", ret);
1425 return VCD_ERROR_OPERATION_FAILED;
1428 return VCD_ERROR_NONE;
1431 int vcd_server_mgr_get_audio_type(int pid, char** audio_type)
1433 /* check if pid is valid */
1434 if (false == vcd_client_manager_is_valid(pid)) {
1435 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] The manager pid(%d) is NOT valid", pid);
1436 return VCD_ERROR_INVALID_PARAMETER;
1439 int ret = vcd_recorder_get(audio_type);
1441 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to get audio in type : %d", ret);
1442 return VCD_ERROR_OPERATION_FAILED;
1445 return VCD_ERROR_NONE;
1448 int vcd_server_mgr_set_client_info(int pid)
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_client_save_client_info();
1458 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to save client info : %d", ret);
1459 return VCD_ERROR_OPERATION_FAILED;
1462 return VCD_ERROR_NONE;
1465 static int __start_internal_recognition()
1468 vcd_client_widget_set_waiting_for_recording(-1, false);
1470 if (0 != vcd_client_command_collect_command()) {
1471 SLOG(LOG_ERROR, TAG_VCD, "[Client Data ERROR] Fail to collect command");
1472 /* Send error cb to manager */
1473 int pid = vcd_client_widget_get_foreground_pid();
1475 vcdc_send_error_signal_to_manager(vcd_client_manager_get_pid(), VCD_ERROR_OPERATION_FAILED, "voice_engine.error.proc_fail");
1476 return VCD_ERROR_OPERATION_FAILED;
1479 /* 3. Set command to engine */
1480 ret = vcd_engine_set_commands();
1482 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to set commands : %d", ret);
1483 /* Send error cb to manager */
1484 int pid = vcd_client_widget_get_foreground_pid();
1486 vcdc_send_error_signal_to_manager(vcd_client_manager_get_pid(), VCD_ERROR_OPERATION_FAILED, "voice_engine.error.proc_fail");
1487 return VCD_ERROR_OPERATION_FAILED;
1490 SLOG(LOG_DEBUG, TAG_VCD, "[Server Success] Set command");
1492 bool stop_by_silence = true;
1493 if (VCD_RECOGNITION_MODE_MANUAL == vcd_client_get_recognition_mode()) {
1494 stop_by_silence = false;
1497 vcd_client_manager_set_result_text(NULL);
1499 /* 4. start recognition */
1500 ret = vcd_engine_recognize_start(stop_by_silence);
1502 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to start recognition : result(%d)", ret);
1503 /* Send error cb to manager */
1504 int pid = vcd_client_widget_get_foreground_pid();
1506 vcdc_send_error_signal_to_manager(vcd_client_manager_get_pid(), VCD_ERROR_OPERATION_FAILED, "voice_engine.error.proc_fail");
1507 return VCD_ERROR_OPERATION_FAILED;
1510 SLOG(LOG_DEBUG, TAG_VCD, "[Server Success] Start engine");
1513 /* 5. recorder start */
1514 ret = vcd_recorder_start();
1516 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to start recorder : result(%d)", ret);
1517 vcd_engine_recognize_cancel();
1518 /* Send error cb to manager */
1519 int pid = vcd_client_widget_get_foreground_pid();
1521 vcdc_send_error_signal_to_manager(vcd_client_manager_get_pid(), VCD_ERROR_OPERATION_FAILED, "voice_engine.error.proc_fail");
1526 vcd_config_set_service_state(VCD_STATE_RECORDING);
1527 vcdc_send_service_state(VCD_STATE_RECORDING);
1529 SLOG(LOG_DEBUG, TAG_VCD, "[Server Success] Start recognition(%d)", stop_by_silence);
1534 static Eina_Bool __vcd_request_show_tooltip(void *data)
1536 int pid = vcd_client_widget_get_foreground_pid();
1538 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Request tooltip show and widget command");
1539 vcdc_send_show_tooltip(pid, (bool)data);
1545 int vcd_server_mgr_start(vcd_recognition_mode_e recognition_mode, bool exclusive_cmd, bool start_by_client)
1547 /* 1. check current state */
1548 vcd_state_e state = vcd_config_get_service_state();
1550 if (VCD_STATE_READY != state) {
1551 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Current state is not ready");
1552 return VCD_ERROR_INVALID_STATE;
1554 if (-1 == vcd_client_manager_get_pid()) {
1555 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Manager is NOT available.");
1556 return VCD_ERROR_OPERATION_FAILED;
1558 vcd_client_widget_set_waiting_for_recording(-1, false);
1560 SLOG(LOG_DEBUG, TAG_VCD, "[Server] set recognition mode = %d", recognition_mode);
1561 vcd_client_set_recognition_mode(recognition_mode);
1563 if (false == exclusive_cmd) {
1564 vcd_client_update_foreground_pid();
1565 /* Notify show tooltip */
1566 if (1 == vcd_config_get_command_type_enabled(VC_COMMAND_TYPE_WIDGET)) {
1567 int pid = vcd_client_widget_get_foreground_pid();
1569 SLOG(LOG_INFO, TAG_VCD, "[Server] Request tooltip show and widget command");
1570 ecore_timer_add(0, __vcd_request_show_tooltip, (void*)true);
1571 vcd_client_widget_set_waiting_for_recording(pid, true);
1576 vcd_client_manager_set_exclusive(exclusive_cmd);
1580 if (true == start_by_client) {
1581 /* Get foreground pid */
1582 if (0 != vcd_config_get_foreground(&fg_pid)) {
1583 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to get foreground");
1586 /* Set client exclusive option */
1587 if (0 != vcd_client_set_exclusive_command(fg_pid)) {
1588 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to set exclusive command");
1592 int ret = __start_internal_recognition();
1594 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to start recongition : %d", ret);
1598 if (true == start_by_client) {
1599 vcd_client_unset_exclusive_command(fg_pid);
1602 return VCD_ERROR_NONE;
1605 int vcd_server_mgr_stop()
1607 /* 1. Check current state is recording */
1608 if (VCD_STATE_RECORDING != vcd_config_get_service_state()) {
1609 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Current state is not recording");
1610 return VCD_ERROR_INVALID_STATE;
1612 if (-1 == vcd_client_manager_get_pid()) {
1613 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Manager is NOT available.");
1614 return VCD_ERROR_OPERATION_FAILED;
1618 /* 2. Stop recorder */
1619 vcd_recorder_stop();
1622 /* 3. Stop engine recognition */
1623 int ret = vcd_engine_recognize_stop();
1625 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to stop recognition : %d", ret);
1628 /* 4. Set original mode */
1629 vcd_config_set_service_state(VCD_STATE_PROCESSING);
1630 vcdc_send_service_state(VCD_STATE_PROCESSING);
1632 return VCD_ERROR_NONE;
1635 int vcd_server_mgr_cancel()
1637 if (-1 == vcd_client_manager_get_pid()) {
1638 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Manager is NOT available.");
1639 return VCD_ERROR_OPERATION_FAILED;
1642 if (g_restart_timer != NULL) {
1643 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Delete restart engine timer");
1644 ecore_timer_del(g_restart_timer);
1645 g_restart_timer = NULL;
1648 /* 1. Check current state */
1649 vcd_state_e state = vcd_config_get_service_state();
1650 if (VCD_STATE_READY == state) {
1651 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Current state is READY");
1652 vcd_recorder_stop();
1654 if (false == vcd_client_manager_get_exclusive()) {
1655 if (1 == vcd_config_get_command_type_enabled(VC_COMMAND_TYPE_WIDGET)) {
1656 int pid = vcd_client_widget_get_foreground_pid();
1658 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Request tooltip hide");
1659 ecore_timer_add(0, __vcd_request_show_tooltip, (void*)false);
1664 vcdc_send_service_state(VCD_STATE_READY);
1665 return VCD_ERROR_NONE;
1669 /* 2. Stop recorder */
1670 vcd_recorder_stop();
1673 /* 3. Cancel engine */
1674 int ret = vcd_engine_recognize_cancel();
1676 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Fail to cancel : %d", ret);
1679 if (false == vcd_client_manager_get_exclusive()) {
1680 if (1 == vcd_config_get_command_type_enabled(VC_COMMAND_TYPE_WIDGET)) {
1681 int pid = vcd_client_widget_get_foreground_pid();
1683 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Request tooltip hide");
1684 ecore_timer_add(0, __vcd_request_show_tooltip, (void*)false);
1688 vcd_client_manager_set_exclusive(false);
1692 vcd_config_set_service_state(VCD_STATE_READY);
1693 vcdc_send_service_state(VCD_STATE_READY);
1695 return VCD_ERROR_NONE;
1699 int vcd_server_mgr_result_select()
1701 __vcd_send_selected_result(NULL);
1703 return VCD_ERROR_NONE;
1706 int vcd_server_mgr_set_domain(int pid, const char* domain)
1708 /* check if pid is valid */
1709 if (false == vcd_client_manager_is_valid(pid)) {
1710 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] The manager pid(%d) is NOT valid", pid);
1711 return VCD_ERROR_INVALID_PARAMETER;
1714 vcd_state_e state = vcd_config_get_service_state();
1715 if (VCD_STATE_READY != state) {
1716 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Current state is not ready");
1717 return VCD_ERROR_INVALID_STATE;
1720 /* Set domain to engine */
1721 int ret = vcd_engine_set_domain(pid, domain);
1723 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to set domain : %d", ret);
1725 SLOG(LOG_DEBUG, TAG_VCD, "[Server SUCCESS] Set domain");
1731 int vcd_server_mgr_set_private_data(int pid, const char* key, const char* data)
1733 /* check if pid is valid */
1734 if (false == vcd_client_manager_is_valid(pid)) {
1735 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] The manager pid(%d) is NOT valid", pid);
1736 return VCD_ERROR_INVALID_PARAMETER;
1739 vcd_state_e state = vcd_config_get_service_state();
1740 if (VCD_STATE_READY != state) {
1741 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Current state is not ready");
1742 return VCD_ERROR_INVALID_STATE;
1745 /* Set private data to engine */
1746 int ret = vcd_engine_set_private_data(pid, key, data);
1748 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to set private data : %d", ret);
1750 SLOG(LOG_DEBUG, TAG_VCD, "[Server SUCCESS] Set private data");
1756 int vcd_server_mgr_get_private_data(int pid, const char* key, char** data)
1758 /* check if pid is valid */
1759 if (false == vcd_client_manager_is_valid(pid)) {
1760 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] The manager pid(%d) is NOT valid", pid);
1761 return VCD_ERROR_INVALID_PARAMETER;
1763 vcd_state_e state = vcd_config_get_service_state();
1764 if (VCD_STATE_READY != state) {
1765 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Current state is not ready");
1766 return VCD_ERROR_INVALID_STATE;
1769 /* Get private data to engine */
1770 int ret = vcd_engine_get_private_data(pid, key, data);
1772 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to get private data : %d", ret);
1774 SLOG(LOG_DEBUG, TAG_VCD, "[Server SUCCESS] Set private data");
1780 int vcd_server_mgr_do_action(int pid, int type, const char* action)
1784 /* check if pid is valid */
1785 if (false == vcd_client_manager_is_valid(pid)) {
1786 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] The manager pid(%d) is NOT valid", pid);
1787 return VCD_ERROR_INVALID_PARAMETER;
1790 vcd_state_e state = vcd_config_get_service_state();
1791 if (VCD_STATE_READY != state) {
1792 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Current state is not ready");
1793 return VCD_ERROR_INVALID_STATE;
1796 /* Reqeust do action to engine */
1797 if (VCD_SEND_EVENT_TYPE_TEXT == type)
1798 ret = vcd_engine_process_text(pid, action);
1799 else if (VCD_SEND_EVENT_TYPE_LIST_EVENT == type)
1800 ret = vcd_engine_process_list_event(pid, action);
1801 else if (VCD_SEND_EVENT_TYPE_HAPTIC_EVENT == type)
1802 ret = vcd_engine_process_haptic_event(pid, action);
1805 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to process do action : %d", ret);
1807 vcd_config_set_service_state(VCD_STATE_PROCESSING);
1808 vcdc_send_service_state(VCD_STATE_PROCESSING);
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 == vcd_engine_is_available_engine()) {
1873 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] No Engine");
1874 return VCD_ERROR_ENGINE_NOT_FOUND;
1877 /* check if pid is valid */
1878 if (true == vcd_client_is_available(pid)) {
1879 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] The pid is already exist");
1880 return VCD_ERROR_INVALID_PARAMETER;
1883 /* Add client information to client manager */
1884 if (0 != vcd_client_add(pid)) {
1885 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to add client info");
1886 return VCD_ERROR_OPERATION_FAILED;
1889 SLOG(LOG_DEBUG, TAG_VCD, "[Server Success] Client Initialize : pid(%d)", pid);
1891 return VCD_ERROR_NONE;
1894 int vcd_server_finalize(int pid)
1896 /* check if pid is valid */
1897 if (false == vcd_client_is_available(pid)) {
1898 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] pid is NOT valid ");
1899 return VCD_ERROR_INVALID_PARAMETER;
1902 /* Remove client information */
1903 if (0 != vcd_client_delete(pid)) {
1904 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Fail to delete client");
1907 if (0 == vcd_client_get_ref_count()) {
1908 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Connected client list is empty");
1909 ecore_timer_add(0, __finalize_quit_ecore_loop, NULL);
1912 SLOG(LOG_DEBUG, TAG_VCD, "[Server Success] Client Finalize : pid(%d)", pid);
1914 return VCD_ERROR_NONE;
1917 int vcd_server_set_command(int pid, vc_cmd_type_e cmd_type)
1919 /* check if pid is valid */
1920 if (false == vcd_client_is_available(pid)) {
1921 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] pid is NOT valid ");
1922 return VCD_ERROR_INVALID_PARAMETER;
1925 if (0 != vcd_client_set_command_type(pid, cmd_type)) {
1926 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to set command type : pid(%d), cmd_type(%d)", pid, cmd_type);
1927 return VCD_ERROR_OPERATION_FAILED;
1933 int vcd_server_unset_command(int pid, vc_cmd_type_e cmd_type)
1935 /* check if pid is valid */
1936 if (false == vcd_client_is_available(pid)) {
1937 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] pid is NOT valid ");
1938 return VCD_ERROR_INVALID_PARAMETER;
1941 if (0 != vcd_client_unset_command_type(pid, cmd_type)) {
1942 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to unset command type : pid(%d), cmd_type(%d)", pid, cmd_type);
1943 return VCD_ERROR_OPERATION_FAILED;
1949 int vcd_server_set_foreground(int pid, bool value)
1951 /* check if pid is valid */
1952 if (false == vcd_client_is_available(pid) && false == vcd_client_widget_is_available(pid)) {
1953 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] pid is NOT valid ");
1954 return VCD_ERROR_INVALID_PARAMETER;
1957 if (0 != vcd_config_set_foreground(pid, value)) {
1958 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to set foreground : pid(%d), value(%d)", pid, value);
1959 return VCD_ERROR_OPERATION_FAILED;
1965 static int __vcd_server_launch_manager_app()
1968 bool running = false;
1971 ret = vcd_client_manager_get_appid(&appid);
1972 if (0 != ret || NULL == appid) {
1973 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to get manager appid");
1974 return VCD_ERROR_OPERATION_FAILED;
1976 ret = app_manager_is_running(appid, &running);
1978 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to check running with appid(%s)", appid);
1981 return VCD_ERROR_OPERATION_FAILED;
1983 if (false == running) {
1984 int tmp_ret = __vcd_is_package_installed(appid);
1985 if (false == tmp_ret) {
1986 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] manager app is not installed, appid(%s)", appid);
1988 ret = __vcd_activate_app_by_appcontrol(appid);
1990 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to activate app");
1995 SLOG(LOG_ERROR, TAG_VCD, "Launch vc manager app: appid(%s)", appid);
1998 ret = __vcd_resume_app(appid);
2000 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to resume app");
2005 SLOG(LOG_ERROR, TAG_VCD, "Resume vc manager app: appid(%s)", appid);
2011 return VCD_ERROR_NONE;
2014 int vcd_server_dialog(int pid, const char* disp_text, const char* utt_text, int continuous)
2016 /* check if pid is valid */
2017 if (false == vcd_client_is_available(pid) && false == vcd_client_widget_is_available(pid)) {
2018 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] pid is NOT valid ");
2019 return VCD_ERROR_INVALID_PARAMETER;
2022 int ret = __vcd_server_launch_manager_app();
2024 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);
2028 ret = vcdc_send_dialog(vcd_client_manager_get_pid(), pid, disp_text, utt_text, continuous);
2030 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);
2037 int vcd_server_is_system_command_valid(int pid, int* is_sys_cmd_valid)
2039 /* check if pid is valid */
2040 if (false == vcd_client_is_available(pid) && false == vcd_client_widget_is_available(pid)) {
2041 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] pid is NOT valid ");
2042 return VCD_ERROR_INVALID_PARAMETER;
2045 /* check if system command is valid */
2046 if (true == vcd_client_manager_is_system_command_valid(vcd_client_manager_get_pid()))
2047 *is_sys_cmd_valid = true;
2049 *is_sys_cmd_valid = false;
2055 int vcd_server_set_exclusive_command(int pid, bool value)
2057 /* check if pid is valid */
2058 if (false == vcd_client_is_available(pid)) {
2059 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] pid is NOT valid ");
2060 return VCD_ERROR_INVALID_PARAMETER;
2063 if (true == value) {
2064 if (0 != vcd_client_set_exclusive_command(pid)) {
2065 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to set exclusive command : pid(%d)", pid);
2066 return VCD_ERROR_OPERATION_FAILED;
2069 if (0 != vcd_client_unset_exclusive_command(pid)) {
2070 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to unset exclusive command : pid(%d)", pid);
2071 return VCD_ERROR_OPERATION_FAILED;
2078 int vcd_server_request_start(int pid, bool stop_by_silence)
2080 /* check if pid is valid */
2081 if (false == vcd_client_is_available(pid)) {
2082 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] pid(%d) is NOT forground client", pid);
2083 return VCD_ERROR_INVALID_PARAMETER;
2087 /* Check current state */
2088 vcd_state_e state = vcd_config_get_service_state();
2090 /* Service state should be ready */
2091 if (VCD_STATE_READY != state) {
2092 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Current state is not Ready : pid(%d)", pid);
2093 return VCD_ERROR_INVALID_STATE;
2096 if (-1 != vcd_client_manager_get_pid()) {
2097 /* Check current pid is valid */
2098 if (false == vcd_client_manager_check_demandable_client(pid)) {
2099 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Current client is NOT available : pid(%d)", pid);
2100 return VCD_ERROR_INVALID_PARAMETER;
2104 ret = vcd_server_mgr_start(stop_by_silence, false);
2106 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Fail to start recognition");
2107 return VCD_ERROR_INVALID_PARAMETER;
2113 int vcd_server_request_stop(int pid)
2116 /* Check current state */
2117 vcd_state_e state = vcd_config_get_service_state();
2119 /* Service state should be ready */
2120 if (VCD_STATE_RECORDING != state) {
2121 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Current state is not Recording : pid(%d)", pid);
2122 return VCD_ERROR_INVALID_STATE;
2125 if (-1 != vcd_client_manager_get_pid()) {
2126 /* Check current pid is valid */
2127 if (false == vcd_client_manager_check_demandable_client(pid)) {
2128 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Current client is NOT available : pid(%d)", pid);
2129 return VCD_ERROR_INVALID_PARAMETER;
2133 ret = vcd_server_mgr_stop();
2135 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Fail to start recognition");
2136 return VCD_ERROR_OPERATION_FAILED;
2139 return VCD_ERROR_NONE;
2142 int vcd_server_request_cancel(int pid)
2145 /* Check current state */
2146 vcd_state_e state = vcd_config_get_service_state();
2148 /* Service state should be recording or processing */
2149 if (VCD_STATE_RECORDING != state && VCD_STATE_PROCESSING != state) {
2150 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Current state is not Recording or Processing : pid(%d)", pid);
2151 return VCD_ERROR_INVALID_STATE;
2154 if (-1 != vcd_client_manager_get_pid()) {
2155 /* Check current pid is valid */
2156 if (false == vcd_client_manager_check_demandable_client(pid)) {
2157 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Current client is NOT available : pid(%d)", pid);
2158 return VCD_ERROR_INVALID_PARAMETER;
2162 ret = vcd_server_mgr_cancel();
2164 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Fail to start recognition");
2165 return VCD_ERROR_OPERATION_FAILED;
2168 return VCD_ERROR_NONE;
2173 * VC Server Functions for Widget lib
2175 int vcd_server_widget_initialize(int pid)
2177 if (false == vcd_engine_is_available_engine()) {
2178 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] No Engine");
2179 return VCD_ERROR_ENGINE_NOT_FOUND;
2182 /* check if pid is valid */
2183 if (true == vcd_client_widget_is_available(pid)) {
2184 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] The pid is already exist");
2185 return VCD_ERROR_NONE;
2188 /* Add client information to client manager */
2189 if (0 != vcd_client_widget_add(pid)) {
2190 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to add client info");
2191 return VCD_ERROR_OPERATION_FAILED;
2194 SLOG(LOG_DEBUG, TAG_VCD, "[Server Success] Initialize widget : pid(%d)", pid);
2196 return VCD_ERROR_NONE;
2199 static void __vcd_server_widget_start_recording(void *data)
2201 if (0 != __start_internal_recognition()) {
2202 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to start recongition");
2204 vcd_client_widget_set_waiting_for_recording(-1, false);
2207 int vcd_server_widget_finalize(int pid)
2209 /* check if pid is valid */
2210 if (false == vcd_client_widget_is_available(pid)) {
2211 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] pid is NOT valid ");
2212 return VCD_ERROR_INVALID_PARAMETER;
2215 /* Remove client information */
2216 if (0 != vcd_client_widget_delete(pid)) {
2217 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Fail to delete client");
2220 if (0 == vcd_client_get_ref_count()) {
2221 SLOG(LOG_ERROR, TAG_VCD, "[Server] connected client list is empty");
2222 ecore_timer_add(0, __finalize_quit_ecore_loop, NULL);
2226 bool is_waiting = false;
2227 if (0 != vcd_client_widget_get_waiting_for_recording(pid, &is_waiting)) {
2228 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Fail to get waiting to recording");
2231 if (true == is_waiting) {
2232 SLOG(LOG_INFO, TAG_VCD, "[Server INFO] invoke to start recording");
2233 ecore_main_loop_thread_safe_call_async(__vcd_server_widget_start_recording, NULL);
2235 return VCD_ERROR_NONE;
2238 int vcd_server_widget_start_recording(int pid, bool widget_command)
2240 /* check if pid is valid */
2241 if (false == vcd_client_widget_is_available(pid)) {
2242 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] pid is NOT valid ");
2243 return VCD_ERROR_INVALID_PARAMETER;
2246 if (true == widget_command) {
2247 vcd_client_widget_set_command(pid);
2248 SLOG(LOG_DEBUG, TAG_VCD, "[Server] widget command is available");
2250 vcd_client_widget_unset_command(pid);
2251 SLOG(LOG_WARN, TAG_VCD, "[Server] widget command is NOT available");
2254 int ret = __start_internal_recognition();
2256 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to start recongition : %d", ret);
2257 ecore_timer_add(0, __vcd_request_show_tooltip, (void*)false);
2263 int vcd_server_widget_start(int pid, bool stop_by_silence)
2265 /* check if pid is valid */
2266 int fore_pid = vcd_client_widget_get_foreground_pid();
2267 if (pid != fore_pid) {
2268 SLOG(LOG_ERROR, TAG_VCD, "[Server] pid is NOT foreground");
2269 return VCD_ERROR_INVALID_PARAMETER;
2272 /* Check current state */
2273 vcd_state_e state = vcd_config_get_service_state();
2275 /* Service state should be ready */
2276 if (VCD_STATE_READY != state) {
2277 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Current state is not Ready : pid(%d)", pid);
2278 return VCD_ERROR_INVALID_STATE;
2281 vcd_client_set_slience_detection(stop_by_silence);
2283 /* Notify show tooltip */
2284 ecore_timer_add(0, __vcd_request_show_tooltip, (void*)true);
2289 int vcd_server_widget_stop(int pid)
2291 /* check if pid is valid */
2292 int fore_pid = vcd_client_widget_get_foreground_pid();
2293 if (pid != fore_pid) {
2294 SLOG(LOG_ERROR, TAG_VCD, "[Server] pid is NOT foreground");
2295 return VCD_ERROR_INVALID_PARAMETER;
2299 /* Check current state */
2300 vcd_state_e state = vcd_config_get_service_state();
2302 /* Service state should be recording */
2303 if (VCD_STATE_RECORDING != state) {
2304 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Current service state is not Recording : pid(%d)", pid);
2305 return VCD_ERROR_INVALID_STATE;
2308 ret = vcd_server_mgr_stop();
2310 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Fail to start recognition");
2311 return VCD_ERROR_OPERATION_FAILED;
2314 return VCD_ERROR_NONE;
2317 int vcd_server_widget_cancel(int pid)
2319 /* check if pid is valid */
2320 int fore_pid = vcd_client_widget_get_foreground_pid();
2321 if (pid != fore_pid) {
2322 SLOG(LOG_ERROR, TAG_VCD, "[Server] pid is NOT foreground");
2323 return VCD_ERROR_INVALID_PARAMETER;
2327 /* Check current state */
2328 vcd_state_e state = vcd_config_get_service_state();
2330 /* Service state should be recording or processing */
2331 if (VCD_STATE_RECORDING != state && VCD_STATE_PROCESSING != state) {
2332 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Current state is not Recording or Processing : pid(%d)", pid);
2333 return VCD_ERROR_INVALID_STATE;
2336 ret = vcd_server_mgr_cancel();
2338 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Fail to cancel recognition : %d", ret);
2342 return VCD_ERROR_NONE;
2345 int vcd_server_widget_enable_asr_result(int pid, bool enable)
2348 ret = vcd_client_widget_set_asr_result_enabled(pid, enable);
2350 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Fail to enable asr result : %d", ret);
2356 int vcd_server_set_language(const char* language)
2358 int ret = VCD_ERROR_NONE;
2360 ret = vcd_config_set_default_language(language);
2362 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Fail to set language : %d", ret);
2366 ret = vcd_engine_set_current_language(language);
2368 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Fail to set language : %d", ret);
2375 * For engine service
2377 int vcd_get_foreach_command(vce_cmd_h vce_command, vce_command_cb callback, void* user_data)
2379 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Get foreach command");
2381 if (NULL == callback) {
2382 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] input parameter is NULL");
2383 return VCD_ERROR_INVALID_PARAMETER;
2387 ret = vcd_engine_agent_get_foreach_command(vce_command, callback, user_data);
2389 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to get foreach command : ret(%d)", ret);
2395 int vcd_get_command_count(vce_cmd_h vce_command)
2397 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Get command count");
2400 ret = vcd_engine_agent_get_command_count(vce_command);
2402 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to get command count : ret(%d)", ret);
2408 int vcd_get_audio_type(char** audio_type)
2410 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Get audio type");
2413 ret = vcd_engine_agent_get_audio_type(audio_type);
2415 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to get audio type : ret(%d)", ret);
2421 int vcd_set_private_data(const char* key, const char* data)
2423 vcd_state_e state = vcd_config_get_service_state();
2425 if (VCD_STATE_READY != state) {
2426 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Current state(%d) is NOT 'READY'", state);
2427 return VCD_ERROR_INVALID_STATE;
2430 int ret = vcd_engine_agent_set_private_data(key, data);
2432 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to set private data to the manager client : ret(%d)", ret);
2434 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Set private data to the manager client, key(%s), data(%s)", key, data);
2440 int vcd_get_private_data(const char* key, char** data)
2442 vcd_state_e state = vcd_config_get_service_state();
2444 if (VCD_STATE_READY != state) {
2445 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Current state(%d) is NOT 'READY'", state);
2446 return VCD_ERROR_INVALID_STATE;
2449 int ret = vcd_engine_agent_get_private_data(key, data);
2451 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to get private data from the manager client : ret(%d)", ret);
2453 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Get private data from the manager client, key(%s), data(%s)", key, data);
2459 int vcd_start_recording()
2461 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Start recording");
2464 ret = vcd_engine_agent_start_recording();
2466 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to start recording : ret(%d)", ret);
2472 int vcd_stop_recording()
2474 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Stop recording");
2477 ret = vcd_engine_agent_stop_recording();
2479 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to stop recording : ret(%d)", ret);
2485 int vcd_set_private_data_set_cb(vce_private_data_set_cb callback_func)
2487 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Set private data set cb");
2490 ret = vcd_engine_agent_set_private_data_set_cb(callback_func);
2492 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to set private data set cb : ret(%d)", ret);
2498 int vcd_set_private_data_requested_cb(vce_private_data_requested_cb callback_func)
2500 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Set private data requested cb");
2503 ret = vcd_engine_agent_set_private_data_requested_cb(callback_func);
2505 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to set private data requested cb : ret(%d)", ret);
2511 int vcd_set_nlu_base_info_requested_cb(vce_nlu_base_info_requested_cb callback_func)
2513 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Set nlu base info requested cb");
2516 ret = vcd_engine_agent_set_nlu_base_info_requested_cb(callback_func);
2518 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to set nlu base info requested cb : ret(%d)", ret);