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 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 vc_info_parser_unset_result(vcd_client_manager_get_exclusive());
469 vcd_client_manager_set_result_text(all_result);
471 SLOG(LOG_INFO, TAG_VCD, "[Server] Event(%d), Text(%s) Nonfixed(%s) Msg(%s) Result count(%d)",
472 event, all_result, non_fixed_result, msg, count);
474 if (VCD_RECOGNITION_MODE_RESTART_AFTER_REJECT == vcd_client_get_recognition_mode()) {
475 if (VCP_RESULT_EVENT_REJECTED == event) {
476 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Restart by no or rejected result");
477 /* If no result and restart option is ON */
478 /* Send reject message */
479 bool temp = vcd_client_manager_get_exclusive();
480 vc_info_parser_set_result(all_result, event, msg, NULL, temp);
481 if (0 != vcdc_send_result_to_manager(vcd_client_manager_get_pid(), VC_RESULT_TYPE_NOTIFICATION)) {
482 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Fail to send result");
485 g_restart_timer = ecore_timer_add(0, __restart_engine, NULL);
488 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Stop recorder due to success");
489 //vcd_recorder_stop();
490 ecore_main_loop_thread_safe_call_sync(__recorder_stop, NULL);
491 } else if (VCD_RECOGNITION_MODE_RESTART_CONTINUOUSLY == vcd_client_get_recognition_mode()) {
492 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Restart continuously");
493 /* Restart option is ON */
494 g_restart_timer = ecore_timer_add(0, __restart_engine, NULL);
495 if (VCP_RESULT_EVENT_REJECTED == event) {
496 bool temp = vcd_client_manager_get_exclusive();
497 vc_info_parser_set_result(all_result, event, msg, NULL, temp);
498 if (0 != 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");
506 int pid = vcd_client_widget_get_foreground_pid();
508 if (NULL != all_result) {
509 vc_info_parser_set_result(all_result, event, msg, NULL, false);
511 vcd_client_widget_get_asr_result_enabled(pid, &enable);
512 if (true == enable) {
513 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Send ASR result to Widget client");
514 bool is_consumed = false;
515 if (0 != vcdc_send_asr_result(pid, VC_COMMAND_TYPE_WIDGET, &is_consumed)) {
516 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to send asr result");
518 SLOG(LOG_DEBUG, TAG_VCD, "[Server] ASR result is consumed(%d)", is_consumed);
519 if (true == is_consumed) {
520 vcdc_send_show_tooltip(pid, false);
521 if (-1 != vcd_client_manager_get_pid()) {
522 /* Manager client is available */
523 vc_info_parser_unset_result(false);
524 vc_info_parser_set_result(all_result, VC_RESULT_EVENT_RESULT_SUCCESS, msg, NULL, false);
525 if (0 != vcdc_send_result_to_manager(vcd_client_manager_get_pid(), VC_RESULT_TYPE_NOTIFICATION)) {
526 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Fail to send result");
530 vcd_client_manager_set_exclusive(false);
532 vcd_config_set_service_state(VCD_STATE_READY);
533 vcdc_send_service_state(VCD_STATE_READY);
541 /* if nlu_result is exist, Add command handle(is_action) into result list */
543 SLOG(LOG_DEBUG, TAG_VCD, "[Server] === Get engine result ===");
546 vc_cmd_s* temp_cmd = NULL;
547 vc_cmd_list_h vc_cmd_list = NULL;
549 if (0 != vc_cmd_list_create(&vc_cmd_list)) {
550 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Fail to create command list");
551 vcd_client_manager_set_exclusive(false);
552 vcd_config_set_service_state(VCD_STATE_READY);
553 vcdc_send_service_state(VCD_STATE_READY);
557 /* priority filter */
558 /* system > exclusive > foreground = widget > system_background > background */
560 int* filtered_id = (int*)calloc(count, sizeof(int));
561 int filtered_count = 0;
562 int top_priority = VC_COMMAND_PRIORITY_BACKGROUND;
563 for (i = 0; i < count; i++) {
564 SLOG(LOG_INFO, TAG_VCD, "[Server] [%d] Result id(%d)", i, result_id[i]);
566 if (0 > result_id[i]) {
567 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Result ID(%d) is NOT valid", result_id[i]);
571 ret = vcd_client_get_cmd_from_result_id(result_id[i], &temp_cmd);
572 if (0 == ret && NULL != temp_cmd) {
573 if (top_priority == temp_cmd->priority) {
574 filtered_id[filtered_count] = result_id[i];
576 } else if (top_priority < temp_cmd->priority) {
579 filtered_id[0] = result_id[i];
581 top_priority = temp_cmd->priority;
587 for (i = 0; i < filtered_count; i++) {
588 SLOG(LOG_INFO, TAG_VCD, "[Server] [%d] Filtered Result id(%d)", i, filtered_id[i]);
590 if (filtered_id[i] < 0) {
591 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Filtered ID(%d) is NOT valid", filtered_id[i]);
595 ret = vcd_client_get_cmd_from_result_id(filtered_id[i], &temp_cmd);
596 if (0 == ret && NULL != temp_cmd) {
597 switch (temp_cmd->format) {
598 case VC_CMD_FORMAT_FIXED:
599 case VC_CMD_FORMAT_FIXED_AND_VFIXED:
600 case VC_CMD_FORMAT_VFIXED_AND_FIXED:
601 case VC_CMD_FORMAT_PARTIAL:
602 case VC_CMD_FORMAT_FIXED_AND_NONFIXED:
603 case VC_CMD_FORMAT_NONFIXED_AND_FIXED:
605 case VC_CMD_FORMAT_ACTION:
609 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Unknown command type : %d", temp_cmd->type);
613 if (0 != vc_cmd_list_add(vc_cmd_list, (vc_cmd_h)temp_cmd)) {
614 SLOG(LOG_DEBUG, TAG_VCD, "Fail to add command to list");
615 vc_cmd_destroy((vc_cmd_h)temp_cmd);
618 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] NOT found matached result(%d)", filtered_id[i]);
622 if (NULL != filtered_id) {
627 if (NULL != nlu_result) {
628 SLOG(LOG_INFO, TAG_VCD, "[Server] NLU (%s)", nlu_result);
629 vc_info_parser_set_nlu_result(nlu_result);
630 if (0 == is_action) {
632 if (0 != vc_cmd_create(&nlu_cmd)) {
633 SLOG(LOG_ERROR, TAG_VCD, "Fail to nlu cmd create");
635 if (0 != vc_cmd_set_type(nlu_cmd, VC_COMMAND_TYPE_SYSTEM)) {
636 SLOG(LOG_ERROR, TAG_VCD, "Fail to set type");
638 if (0 != vc_cmd_set_pid(nlu_cmd, vcd_client_manager_get_pid())) {
639 SLOG(LOG_ERROR, TAG_VCD, "Fail to set pid");
641 if (0 != vc_cmd_set_format(nlu_cmd, VC_CMD_FORMAT_ACTION)) {
642 SLOG(LOG_ERROR, TAG_VCD, "Fail to set format");
644 if (0 != vc_cmd_list_add(vc_cmd_list, nlu_cmd)) {
645 SLOG(LOG_ERROR, TAG_VCD, "Fail to add nlu cmd to list");
646 vc_cmd_destroy(nlu_cmd);
652 vc_cmd_print_list(vc_cmd_list);
654 SLOG(LOG_DEBUG, TAG_VCD, "[Server] =========================");
656 int result_count = 0;
657 vc_cmd_list_get_count(vc_cmd_list, &result_count);
659 if (0 == result_count) {
661 if (NULL != all_result) {
662 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Engine result is no command : %s", all_result);
664 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Engine result is NULL");
666 bool temp = vcd_client_manager_get_exclusive();
667 vc_info_parser_set_result(all_result, event, msg, NULL, temp);
669 int pid = vcd_client_widget_get_foreground_pid();
671 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Request tooltip hide");
672 /* Send to hide tooltip */
673 vcdc_send_show_tooltip(pid, false);
676 if (-1 != vcd_client_manager_get_pid()) {
677 /* Manager client is available */
678 if (0 != vcdc_send_result_to_manager(vcd_client_manager_get_pid(), VC_RESULT_TYPE_NORMAL)) {
679 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Fail to send result");
683 vcd_client_manager_set_exclusive(false);
687 if (false == vcd_client_manager_get_exclusive()) {
688 int pid = vcd_client_widget_get_foreground_pid();
690 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Request tooltip hide");
691 vcdc_send_show_tooltip(pid, false);
694 vc_info_parser_set_result(all_result, event, msg, vc_cmd_list, false);
696 if (-1 != vcd_client_manager_get_pid()) {
697 /* Manager client is available */
698 if (0 != vcdc_send_result_to_manager(vcd_client_manager_get_pid(), VC_RESULT_TYPE_NORMAL)) {
699 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Fail to send result");
702 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Manager is NOT available. Send result to client directly");
703 /* Send result to client */
704 ecore_timer_add(0, __vcd_send_selected_result, NULL);
707 /* exclusive command */
708 vc_info_parser_set_result(all_result, event, msg, vc_cmd_list, true);
710 if (-1 != vcd_client_manager_get_pid()) {
711 /* Manager client is available */
712 if (0 != vcdc_send_result_to_manager(vcd_client_manager_get_pid(), VC_RESULT_TYPE_NORMAL)) {
713 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Fail to send result");
716 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Manager is NOT available");
719 vcd_client_manager_set_exclusive(false);
723 vc_cmd_list_destroy(vc_cmd_list, true);
729 if (NULL == result_id) {
731 if (NULL != all_result) {
732 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Engine result is no command : %s", all_result);
733 bool temp = vcd_client_manager_get_exclusive();
734 vc_info_parser_set_result(all_result, event, msg, NULL, temp);
737 int pid = vcd_client_widget_get_foreground_pid();
739 if (NULL != all_result) {
740 /* Send result text to widget */
741 vcdc_send_result(pid, vcd_client_manager_get_pid(), VC_COMMAND_TYPE_WIDGET);
744 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Request tooltip hide");
745 /* Send to hide tooltip */
746 vcdc_send_show_tooltip(pid, false);
749 if (-1 != vcd_client_manager_get_pid()) {
750 /* Manager client is available */
751 if (0 != vcdc_send_result_to_manager(vcd_client_manager_get_pid(), VC_RESULT_TYPE_NORMAL)) {
752 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Fail to send result");
756 vcd_client_manager_set_exclusive(false);
762 SLOG(LOG_DEBUG, TAG_VCD, "[Server] === Get engine result ===");
765 vc_cmd_s* temp_cmd = NULL;
766 vc_cmd_list_h vc_cmd_list = NULL;
768 if (0 != vc_cmd_list_create(&vc_cmd_list)) {
769 SLOG(LOG_ERROR, TAG_VCD, "[Server] Fail to create command list");
770 vcd_client_manager_set_exclusive(false);
771 vcd_config_set_service_state(VCD_STATE_READY);
772 vcdc_send_service_state(VCD_STATE_READY);
777 for (i = 0; i < count; i++) {
778 SLOG(LOG_DEBUG, TAG_VCD, "[Server] [%d] Result ID(%d)", i, result_id[i]);
780 if (result_id[i] < 0) {
781 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Result ID(%d) is NOT valid", result_id[i]);
785 ret = vcd_client_get_cmd_from_result_id(result_id[i], &temp_cmd);
786 if (0 == ret && NULL != temp_cmd) {
787 switch (temp_cmd->format) {
788 case VC_CMD_FORMAT_FIXED:
789 case VC_CMD_FORMAT_FIXED_AND_VFIXED:
790 case VC_CMD_FORMAT_VFIXED_AND_FIXED:
791 case VC_CMD_FORMAT_PARTIAL:
792 /* Nonfixed result is NOT valid */
794 case VC_CMD_FORMAT_FIXED_AND_NONFIXED:
795 if (NULL == temp_cmd->parameter) {
796 if (NULL != non_fixed_result) {
797 temp_cmd->parameter = strdup(non_fixed_result);
800 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Command type is NOT vaild. Parameter (%s)", temp_cmd->parameter);
803 case VC_CMD_FORMAT_NONFIXED_AND_FIXED:
804 if (NULL == temp_cmd->command) {
805 if (NULL != non_fixed_result) {
806 temp_cmd->command = strdup(non_fixed_result);
809 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Command type is NOT vaild. Command (%s)", temp_cmd->command);
814 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Unknown command type : %d", temp_cmd->type);
818 if (0 != vc_cmd_list_add(vc_cmd_list, (vc_cmd_h)temp_cmd)) {
819 SLOG(LOG_DEBUG, TAG_VCD, "Fail to add command to list");
820 vc_cmd_destroy((vc_cmd_h)temp_cmd);
823 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] NOT found matached result(%d)", result_id[i]);
827 vc_cmd_print_list(vc_cmd_list);
829 SLOG(LOG_DEBUG, TAG_VCD, "[Server] =========================");
831 int result_count = 0;
832 vc_cmd_list_get_count(vc_cmd_list, &result_count);
834 if (false == vcd_client_manager_get_exclusive()) {
835 int pid = vcd_client_widget_get_foreground_pid();
837 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Request tooltip hide");
838 vcdc_send_show_tooltip(pid, false);
841 vc_info_parser_set_result(all_result, event, msg, vc_cmd_list, false);
843 if (-1 != vcd_client_manager_get_pid()) {
844 /* Manager client is available */
845 if (0 != vcdc_send_result_to_manager(vcd_client_manager_get_pid(), VC_RESULT_TYPE_NORMAL)) {
846 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Fail to send result");
849 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Manager is NOT available. Send result to client directly");
850 /* Send result to client */
851 ecore_timer_add(0, __vcd_send_selected_result, NULL);
854 /* exclusive command */
855 vc_info_parser_set_result(all_result, event, msg, vc_cmd_list, true);
857 if (-1 != vcd_client_manager_get_pid()) {
858 /* Manager client is available */
859 if (0 != vcdc_send_result_to_manager(vcd_client_manager_get_pid(), VC_RESULT_TYPE_NORMAL)) {
860 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Fail to send result");
863 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Manager is NOT available");
866 vcd_client_manager_set_exclusive(false);
869 vc_cmd_list_destroy(vc_cmd_list, true);
876 static void __vcd_server_nlu_result_cb(vcp_result_event_e event, const char* nlu_result, void *user_data)
878 SLOG(LOG_DEBUG, TAG_VCD, "[Server] NLU result cb - event(%d)", event);
879 SLOG(LOG_DEBUG, TAG_VCD, "[Server] result (%s)", nlu_result);
881 int ret = vc_info_parser_set_nlu_result(nlu_result);
883 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to set nlu result (%d)", ret);
890 static void __vcd_server_error_cb(vcp_error_e error, const char* msg, void *user_data)
892 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Engine Error cb - reason(%d), msg(%s)", error, msg);
893 ecore_main_loop_thread_safe_call_async(__cancel_by_error, NULL);
895 char* error_msg = NULL;
897 error_msg = strdup(msg);
900 if (0 != vcdc_send_error_signal_to_manager(vcd_client_manager_get_pid(), error, error_msg)) {
901 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to send error signal");
904 if (NULL != error_msg) {
913 * vcd server Interfaces
915 static void __vcd_file_clean_up()
917 SLOG(LOG_DEBUG, TAG_VCD, "== Old file clean up == ");
920 struct dirent *dirp = NULL;
922 dp = opendir(VC_RUNTIME_INFO_ROOT);
924 SLOG(LOG_ERROR, TAG_VCD, "[File message WARN] Fail to open path : %s", VC_RUNTIME_INFO_ROOT);
928 char remove_path[256] = {0, };
933 if (!strncmp("vc_", dirp->d_name, strlen("vc_"))) {
934 memset(remove_path, 0, 256);
935 snprintf(remove_path, 256, "%s/%s", VC_RUNTIME_INFO_ROOT, dirp->d_name);
938 if (0 != remove(remove_path)) {
939 SLOG(LOG_WARN, TAG_VCD, "[File message WARN] Fail to remove file : %s", remove_path);
941 SLOG(LOG_DEBUG, TAG_VCD, "[File message] Remove file : %s", remove_path);
945 } while (NULL != dirp);
952 static int __vcd_db_clean_up()
955 int cnt = VC_COMMAND_TYPE_FOREGROUND;
957 if (VC_COMMAND_TYPE_BACKGROUND != cnt)
958 ret = vc_db_delete_commands(-1, cnt, NULL);
959 } while (VC_COMMAND_TYPE_EXCLUSIVE >= ++cnt);
968 /* Remove old file */
969 __vcd_file_clean_up();
971 /* initialize modules */
972 ret = vcd_config_initialize(__config_lang_changed_cb, __config_foreground_changed_cb, NULL);
974 SLOG(LOG_ERROR, TAG_VCD, "[Server WARNING] Fail to initialize config.");
978 ret = __vcd_db_clean_up();
980 SLOG(LOG_ERROR, TAG_VCD, "[Server WARNING] Fail to remove db data");
983 vcd_config_set_service_state(VCD_STATE_NONE);
985 //ret = vcd_engine_agent_init(__vcd_server_pre_result_cb, __vcd_server_result_cb, __vcd_server_nlu_result_cb, __vcd_server_error_cb);
986 ret = vcd_engine_agent_init(__vcd_server_asr_result_cb, __vcd_server_result_cb, __vcd_server_nlg_result_cb, __vcd_server_error_cb);
988 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to engine agent initialize : result(%d)", ret);
992 if (0 != vcd_recorder_create(__server_recorder_callback, __server_recorder_interrupt_callback)) {
993 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to create recorder");
994 return VCD_ERROR_OPERATION_FAILED;
998 ret = vcd_engine_agent_initialize_current_engine();
1000 if (VCD_ERROR_ENGINE_NOT_FOUND == ret)
1001 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] There is No Voice control engine");
1003 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to init engine");
1005 g_is_engine = false;
1011 if (0 != vcd_engine_agent_load_current_engine()) {
1012 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to load current engine");
1013 return VCD_ERROR_OPERATION_FAILED;
1016 /* Initialize manager info */
1017 vcd_client_manager_unset();
1019 vcd_config_set_service_state(VCD_STATE_READY);
1020 vcdc_send_service_state(VCD_STATE_READY);
1022 SLOG(LOG_DEBUG, TAG_VCD, "[Server SUCCESS] initialize");
1030 if (0 < g_list_length(g_proc_list)) {
1031 iter = g_list_first(g_proc_list);
1032 while (NULL != iter) {
1033 g_proc_list = g_list_remove_link(g_proc_list, iter);
1034 iter = g_list_first(g_proc_list);
1038 if (g_restart_timer != NULL) {
1039 ecore_timer_del(g_restart_timer);
1040 g_restart_timer = NULL;
1043 vcd_state_e state = vcd_config_get_service_state();
1044 if (VCD_STATE_READY != state) {
1045 if (VCD_STATE_RECORDING == state) {
1046 vcd_recorder_stop();
1048 vcd_engine_recognize_cancel();
1050 if (0 != vcd_recorder_destroy()) {
1051 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to destroy recorder");
1053 SLOG(LOG_DEBUG, TAG_VCD, "[Server] destroy recorder");
1056 if (0 != vcd_engine_agent_release()) {
1057 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to release engine");
1059 SLOG(LOG_DEBUG, TAG_VCD, "[Server] release engine");
1062 vcd_client_manager_unset_appid();
1064 vcd_config_set_service_state(VCD_STATE_NONE);
1065 vcdc_send_service_state(VCD_STATE_NONE);
1067 SLOG(LOG_DEBUG, TAG_VCD, "[Server] mode finalize");
1072 static Eina_Bool __finalize_quit_ecore_loop(void *data)
1074 SLOG(LOG_DEBUG, TAG_VCD, "[Server] quit ecore main loop");
1075 ecore_main_loop_quit();
1079 static void __read_proc()
1082 struct dirent *dirp = NULL;
1086 if (0 < g_list_length(g_proc_list)) {
1087 iter = g_list_first(g_proc_list);
1088 while (NULL != iter) {
1089 g_proc_list = g_list_remove_link(g_proc_list, iter);
1090 iter = g_list_first(g_proc_list);
1094 dp = opendir("/proc");
1096 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to open proc");
1102 tmp = atoi(dirp->d_name);
1103 if (0 >= tmp) continue;
1104 g_proc_list = g_list_append(g_proc_list, GINT_TO_POINTER(tmp));
1106 } while (NULL != dirp);
1112 static void __vcd_cleanup_client(vcd_client_type_e type)
1114 int* client_list = NULL;
1115 int client_count = 0;
1122 if (VCD_CLIENT_TYPE_NORMAL == type) {
1123 ret = vcd_client_get_list(&client_list, &client_count);
1124 } else if (VCD_CLIENT_TYPE_WIDGET == type) {
1125 ret = vcd_client_widget_get_list(&client_list, &client_count);
1126 } else if (VCD_CLIENT_TYPE_MANAGER == type) {
1127 mgr_pid = vcd_client_manager_get_pid();
1128 client_list = &mgr_pid;
1130 if (-1 == mgr_pid) {
1131 SLOG(LOG_WARN, TAG_VCD, "[WARNING] Invalid Manager pid");
1136 if (0 == ret || mgr_pid > 0) {
1137 SLOG(LOG_DEBUG, TAG_VCD, "===== Clean up %s client ", type ? (type == 1) ? "Widget" : "Manager" : "Normal");
1138 if (NULL != client_list && client_count > 0) {
1139 for (i = 0; i < client_count; i++) {
1142 for (j = 0; j < g_list_length(g_proc_list); j++) {
1143 iter = g_list_nth(g_proc_list, j);
1145 if (client_list[i] == GPOINTER_TO_INT(iter->data)) {
1146 SLOG(LOG_DEBUG, TAG_VCD, "%s pid(%d) is running", type ? (type == 1) ? "Widget" : "Manager" : "Normal", client_list[i]);
1153 if (false == exist) {
1154 SLOG(LOG_ERROR, TAG_VCD, "%s pid(%d) should be removed", type ? (type == 1) ? "Widget" : "Manager" : "Normal", client_list[i]);
1155 if (VCD_CLIENT_TYPE_NORMAL == type)
1156 vcd_server_finalize(client_list[i]);
1157 else if (VCD_CLIENT_TYPE_WIDGET == type)
1158 vcd_server_widget_finalize(client_list[i]);
1160 vcd_server_mgr_finalize(mgr_pid);
1164 SLOG(LOG_DEBUG, TAG_VCD, "=====");
1165 SLOG(LOG_DEBUG, TAG_VCD, " ");
1167 if (NULL != client_list && -1 == mgr_pid) {
1174 Eina_Bool vcd_cleanup_client_all(void *data)
1178 __vcd_cleanup_client(VCD_CLIENT_TYPE_NORMAL);
1179 __vcd_cleanup_client(VCD_CLIENT_TYPE_WIDGET);
1180 __vcd_cleanup_client(VCD_CLIENT_TYPE_MANAGER);
1183 if (0 == vcd_client_get_list(&client_list, &client_count)) {
1184 SLOG(LOG_DEBUG, TAG_VCD, "===== Clean up client ");
1185 if (NULL != client_list && client_count > 0) {
1186 for (i = 0; i < client_count; i++) {
1189 for (j = 0; j < g_list_length(g_proc_list); j++) {
1190 iter = g_list_nth(g_proc_list, j);
1192 if (client_list[i] == GPOINTER_TO_INT(iter->data)) {
1193 SLOG(LOG_DEBUG, TAG_VCD, "pid(%d) is running", client_list[i]);
1200 if (false == exist) {
1201 SLOG(LOG_ERROR, TAG_VCD, "pid(%d) should be removed", client_list[i]);
1202 vcd_server_finalize(client_list[i]);
1205 result = vcdc_send_hello(client_list[i], VCD_CLIENT_TYPE_NORMAL);
1208 SLOG(LOG_DEBUG, TAG_VCD, "[Server] pid(%d) should be removed.", client_list[i]);
1209 vcd_server_finalize(client_list[i]);
1210 } else if (-1 == result) {
1211 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Hello result has error");
1216 SLOG(LOG_DEBUG, TAG_VCD, "=====");
1217 SLOG(LOG_DEBUG, TAG_VCD, " ");
1219 if (NULL != client_list) {
1224 /* If app is in background state, app cannot response message. */
1225 if (0 == vcd_client_widget_get_list(&client_list, &client_count)) {
1226 SLOG(LOG_DEBUG, TAG_VCD, "===== Clean up widget");
1227 if (NULL != client_list && client_count > 0) {
1228 for (i = 0; i < client_count; i++) {
1231 for (j = 0; j < g_list_length(g_proc_list); j++) {
1232 iter = g_list_nth(g_proc_list, j);
1234 if (client_list[i] == GPOINTER_TO_INT(iter->data)) {
1235 SLOG(LOG_DEBUG, TAG_VCD, "widget pid(%d) is running", client_list[i]);
1242 if (false == exist) {
1243 SLOG(LOG_ERROR, TAG_VCD, "widget pid(%d) should be removed", client_list[i]);
1244 vcd_server_widget_finalize(client_list[i]);
1247 result = vcdc_send_hello(client_list[i], VCD_CLIENT_TYPE_WIDGET);
1250 SLOG(LOG_DEBUG, TAG_VCD, "[Server] widget pid(%d) should be removed.", client_list[i]);
1251 vcd_server_widget_finalize(client_list[i]);
1252 } else if (-1 == result) {
1253 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Hello result has error");
1258 SLOG(LOG_DEBUG, TAG_VCD, "=====");
1259 SLOG(LOG_DEBUG, TAG_VCD, " ");
1262 if (NULL != client_list) {
1270 int mgr_pid = vcd_client_manager_get_pid();
1272 for (j = 0; j < g_list_length(g_proc_list); j++) {
1273 iter = g_list_nth(g_proc_list, j);
1275 if (mgr_pid == GPOINTER_TO_INT(iter->data)) {
1276 SLOG(LOG_DEBUG, TAG_VCD, "manager pid(%d) is running", mgr_pid);
1283 if (false == exist) {
1284 SLOG(LOG_ERROR, TAG_VCD, "manager pid (%d) should be removed", mgr_pid);
1285 vcd_server_mgr_finalize(mgr_pid);
1292 int vcd_server_get_service_state()
1294 return vcd_config_get_service_state();
1297 int vcd_server_get_foreground()
1300 vcd_config_get_foreground(&pid);
1308 int vcd_server_mgr_initialize(int pid)
1310 if (false == g_is_engine) {
1311 if (0 != vcd_engine_agent_initialize_current_engine()) {
1312 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] No Engine");
1313 g_is_engine = false;
1314 return VCD_ERROR_ENGINE_NOT_FOUND;
1320 /* check if pid is valid */
1321 if (false == vcd_client_manager_is_valid(pid)) {
1322 SLOG(LOG_ERROR, TAG_VCD, "[Server] old manager pid(%d) be removed", vcd_client_manager_get_pid());
1323 vcd_server_mgr_cancel();
1324 vcd_client_manager_unset();
1327 /* Add client information to client manager */
1328 if (0 != vcd_client_manager_set(pid)) {
1329 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to add manager");
1330 return VCD_ERROR_OPERATION_FAILED;
1333 if (0 != vcdc_send_manager_pid(pid))
1334 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Fail to send manager pid");
1336 SLOG(LOG_DEBUG, TAG_VCD, "[Server Success] Manager initialize : pid(%d)", pid);
1338 return VCD_ERROR_NONE;
1341 int vcd_server_mgr_finalize(int pid)
1343 /* check if pid is valid */
1344 if (false == vcd_client_manager_is_valid(pid)) {
1345 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] The manager pid(%d) is NOT valid", pid);
1346 return VCD_ERROR_INVALID_PARAMETER;
1349 /* Cancel recognition */
1350 vcd_server_mgr_cancel();
1352 if (0 != vcdc_send_manager_pid(-1))
1353 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Fail to send manager pid");
1355 /* Remove manager information */
1356 if (0 != vcd_client_manager_unset()) {
1357 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Fail to delete client");
1360 if (0 == vcd_client_get_ref_count()) {
1361 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Connected client list is empty");
1362 ecore_timer_add(0, __finalize_quit_ecore_loop, NULL);
1365 SLOG(LOG_DEBUG, TAG_VCD, "[Server Success] Manager Finalize : pid(%d)", pid);
1367 return VCD_ERROR_NONE;
1370 int vcd_server_mgr_set_command(int pid)
1372 if (0 != vcd_client_manager_set_command(pid)) {
1373 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] The manager pid(%d) is NOT valid", pid);
1374 return VCD_ERROR_INVALID_PARAMETER;
1376 return VCD_ERROR_NONE;
1379 int vcd_server_mgr_unset_command(int pid)
1381 if (0 != vcd_client_manager_unset_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_set_demandable_client(int pid)
1390 /* check if pid is valid */
1391 if (false == vcd_client_manager_is_valid(pid)) {
1392 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] The manager pid(%d) is NOT valid", pid);
1393 return VCD_ERROR_INVALID_PARAMETER;
1396 GSList* client_list = NULL;
1397 if (0 != vc_info_parser_get_demandable_clients(&client_list)) {
1398 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to get demandable client");
1399 return VCD_ERROR_OPERATION_FAILED;
1402 /* Save client list */
1403 if (0 != vcd_client_manager_set_demandable_client(pid, client_list)) {
1404 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to set demandable client list");
1405 return VCD_ERROR_OPERATION_FAILED;
1408 return VCD_ERROR_NONE;
1411 int vcd_server_mgr_set_audio_type(int pid, const char* audio_type)
1413 /* check if pid is valid */
1414 if (false == vcd_client_manager_is_valid(pid)) {
1415 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] The manager pid(%d) is NOT valid", pid);
1416 return VCD_ERROR_INVALID_PARAMETER;
1420 vcp_audio_type_e type = VCP_AUDIO_TYPE_PCM_S16_LE;
1424 ret = vcd_engine_get_audio_format(audio_type, &type, &rate, &channel);
1426 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to get audio format : %d", ret);
1427 return VCD_ERROR_OPERATION_FAILED;
1430 ret = vcd_recorder_set(audio_type, type, rate, channel);
1432 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to set audio in type : %d", ret);
1433 return VCD_ERROR_OPERATION_FAILED;
1436 return VCD_ERROR_NONE;
1439 int vcd_server_mgr_get_audio_type(int pid, char** audio_type)
1441 /* check if pid is valid */
1442 if (false == vcd_client_manager_is_valid(pid)) {
1443 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] The manager pid(%d) is NOT valid", pid);
1444 return VCD_ERROR_INVALID_PARAMETER;
1447 int ret = vcd_recorder_get(audio_type);
1449 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to get audio in type : %d", ret);
1450 return VCD_ERROR_OPERATION_FAILED;
1453 return VCD_ERROR_NONE;
1456 int vcd_server_mgr_set_client_info(int pid)
1458 /* check if pid is valid */
1459 if (false == vcd_client_manager_is_valid(pid)) {
1460 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] The manager pid(%d) is NOT valid", pid);
1461 return VCD_ERROR_INVALID_PARAMETER;
1464 int ret = vcd_client_save_client_info();
1466 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to save client info : %d", ret);
1467 return VCD_ERROR_OPERATION_FAILED;
1470 return VCD_ERROR_NONE;
1473 static int __start_internal_recognition()
1477 if (0 != vcd_client_command_collect_command()) {
1478 SLOG(LOG_ERROR, TAG_VCD, "[Client Data ERROR] Fail to collect command");
1479 /* Send error cb to manager */
1480 int pid = vcd_client_widget_get_foreground_pid();
1482 vcdc_send_error_signal_to_manager(vcd_client_manager_get_pid(), VCD_ERROR_OPERATION_FAILED, "voice_engine.error.proc_fail");
1483 return VCD_ERROR_OPERATION_FAILED;
1486 /* 3. Set command to engine */
1487 ret = vcd_engine_set_commands();
1489 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to set commands : %d", ret);
1490 /* Send error cb to manager */
1491 int pid = vcd_client_widget_get_foreground_pid();
1493 vcdc_send_error_signal_to_manager(vcd_client_manager_get_pid(), VCD_ERROR_OPERATION_FAILED, "voice_engine.error.proc_fail");
1494 return VCD_ERROR_OPERATION_FAILED;
1497 SLOG(LOG_DEBUG, TAG_VCD, "[Server Success] Set command");
1499 bool stop_by_silence = true;
1500 if (VCD_RECOGNITION_MODE_MANUAL == vcd_client_get_recognition_mode()) {
1501 stop_by_silence = false;
1504 vcd_client_manager_set_result_text(NULL);
1506 /* 4. start recognition */
1507 ret = vcd_engine_recognize_start(stop_by_silence);
1509 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to start recognition : result(%d)", ret);
1510 /* Send error cb to manager */
1511 int pid = vcd_client_widget_get_foreground_pid();
1513 vcdc_send_error_signal_to_manager(vcd_client_manager_get_pid(), VCD_ERROR_OPERATION_FAILED, "voice_engine.error.proc_fail");
1514 return VCD_ERROR_OPERATION_FAILED;
1517 SLOG(LOG_DEBUG, TAG_VCD, "[Server Success] Start engine");
1520 /* 5. recorder start */
1521 ret = vcd_recorder_start();
1523 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to start recorder : result(%d)", ret);
1524 vcd_engine_recognize_cancel();
1525 /* Send error cb to manager */
1526 int pid = vcd_client_widget_get_foreground_pid();
1528 vcdc_send_error_signal_to_manager(vcd_client_manager_get_pid(), VCD_ERROR_OPERATION_FAILED, "voice_engine.error.proc_fail");
1533 vcd_config_set_service_state(VCD_STATE_RECORDING);
1534 vcdc_send_service_state(VCD_STATE_RECORDING);
1536 SLOG(LOG_DEBUG, TAG_VCD, "[Server Success] Start recognition(%d)", stop_by_silence);
1541 static Eina_Bool __vcd_request_show_tooltip(void *data)
1543 int pid = vcd_client_widget_get_foreground_pid();
1545 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Request tooltip show and widget command");
1546 vcdc_send_show_tooltip(pid, (bool)data);
1552 int vcd_server_mgr_start(vcd_recognition_mode_e recognition_mode, bool exclusive_cmd, bool start_by_client)
1554 /* 1. check current state */
1555 vcd_state_e state = vcd_config_get_service_state();
1557 if (VCD_STATE_READY != state) {
1558 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Current state is not ready");
1559 return VCD_ERROR_INVALID_STATE;
1561 if (-1 == vcd_client_manager_get_pid()) {
1562 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Manager is NOT available.");
1563 return VCD_ERROR_OPERATION_FAILED;
1566 SLOG(LOG_DEBUG, TAG_VCD, "[Server] set recognition mode = %d", recognition_mode);
1567 vcd_client_set_recognition_mode(recognition_mode);
1569 if (false == exclusive_cmd) {
1570 vcd_client_update_foreground_pid();
1571 /* Notify show tooltip */
1572 if (1 == vcd_config_get_command_type_enabled(VC_COMMAND_TYPE_WIDGET)) {
1573 int pid = vcd_client_widget_get_foreground_pid();
1575 SLOG(LOG_INFO, TAG_VCD, "[Server] Request tooltip show and widget command");
1576 ecore_timer_add(0, __vcd_request_show_tooltip, (void*)true);
1581 vcd_client_manager_set_exclusive(exclusive_cmd);
1585 if (true == start_by_client) {
1586 /* Get foreground pid */
1587 if (0 != vcd_config_get_foreground(&fg_pid)) {
1588 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to get foreground");
1591 /* Set client exclusive option */
1592 if (0 != vcd_client_set_exclusive_command(fg_pid)) {
1593 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to set exclusive command");
1597 int ret = __start_internal_recognition();
1599 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to start recongition : %d", ret);
1603 if (true == start_by_client) {
1604 vcd_client_unset_exclusive_command(fg_pid);
1607 return VCD_ERROR_NONE;
1610 int vcd_server_mgr_stop()
1612 /* 1. Check current state is recording */
1613 if (VCD_STATE_RECORDING != vcd_config_get_service_state()) {
1614 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Current state is not recording");
1615 return VCD_ERROR_INVALID_STATE;
1617 if (-1 == vcd_client_manager_get_pid()) {
1618 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Manager is NOT available.");
1619 return VCD_ERROR_OPERATION_FAILED;
1623 /* 2. Stop recorder */
1624 vcd_recorder_stop();
1627 /* 3. Stop engine recognition */
1628 int ret = vcd_engine_recognize_stop();
1630 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to stop recognition : %d", ret);
1633 /* 4. Set original mode */
1634 vcd_config_set_service_state(VCD_STATE_PROCESSING);
1635 vcdc_send_service_state(VCD_STATE_PROCESSING);
1637 return VCD_ERROR_NONE;
1640 int vcd_server_mgr_cancel()
1642 if (-1 == vcd_client_manager_get_pid()) {
1643 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Manager is NOT available.");
1644 return VCD_ERROR_OPERATION_FAILED;
1647 if (g_restart_timer != NULL) {
1648 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Delete restart engine timer");
1649 ecore_timer_del(g_restart_timer);
1650 g_restart_timer = NULL;
1653 /* 1. Check current state */
1654 vcd_state_e state = vcd_config_get_service_state();
1655 if (VCD_STATE_READY == state) {
1656 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Current state is READY");
1657 vcd_recorder_stop();
1658 return VCD_ERROR_NONE;
1662 /* 2. Stop recorder */
1663 vcd_recorder_stop();
1666 /* 3. Cancel engine */
1667 int ret = vcd_engine_recognize_cancel();
1669 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Fail to cancel : %d", ret);
1672 if (false == vcd_client_manager_get_exclusive()) {
1673 if (1 == vcd_config_get_command_type_enabled(VC_COMMAND_TYPE_WIDGET)) {
1674 int pid = vcd_client_widget_get_foreground_pid();
1676 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Request tooltip hide");
1677 ecore_timer_add(0, __vcd_request_show_tooltip, (void*)false);
1681 vcd_client_manager_set_exclusive(false);
1685 vcd_config_set_service_state(VCD_STATE_READY);
1686 vcdc_send_service_state(VCD_STATE_READY);
1688 return VCD_ERROR_NONE;
1692 int vcd_server_mgr_result_select()
1694 __vcd_send_selected_result(NULL);
1696 return VCD_ERROR_NONE;
1699 int vcd_server_mgr_set_domain(int pid, const char* domain)
1701 /* check if pid is valid */
1702 if (false == vcd_client_manager_is_valid(pid)) {
1703 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] The manager pid(%d) is NOT valid", pid);
1704 return VCD_ERROR_INVALID_PARAMETER;
1707 vcd_state_e state = vcd_config_get_service_state();
1708 if (VCD_STATE_READY != state) {
1709 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Current state is not ready");
1710 return VCD_ERROR_INVALID_STATE;
1713 /* Set domain to engine */
1714 int ret = vcd_engine_set_domain(pid, domain);
1716 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to set domain : %d", ret);
1718 SLOG(LOG_DEBUG, TAG_VCD, "[Server SUCCESS] Set domain");
1724 int vcd_server_mgr_set_private_data(int pid, const char* key, const char* data)
1726 /* check if pid is valid */
1727 if (false == vcd_client_manager_is_valid(pid)) {
1728 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] The manager pid(%d) is NOT valid", pid);
1729 return VCD_ERROR_INVALID_PARAMETER;
1732 vcd_state_e state = vcd_config_get_service_state();
1733 if (VCD_STATE_READY != state) {
1734 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Current state is not ready");
1735 return VCD_ERROR_INVALID_STATE;
1738 /* Set private data to engine */
1739 int ret = vcd_engine_set_private_data(pid, key, data);
1741 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to set private data : %d", ret);
1743 SLOG(LOG_DEBUG, TAG_VCD, "[Server SUCCESS] Set private data");
1749 int vcd_server_mgr_get_private_data(int pid, const char* key, char** data)
1751 /* check if pid is valid */
1752 if (false == vcd_client_manager_is_valid(pid)) {
1753 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] The manager pid(%d) is NOT valid", pid);
1754 return VCD_ERROR_INVALID_PARAMETER;
1756 vcd_state_e state = vcd_config_get_service_state();
1757 if (VCD_STATE_READY != state) {
1758 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Current state is not ready");
1759 return VCD_ERROR_INVALID_STATE;
1762 /* Get private data to engine */
1763 int ret = vcd_engine_get_private_data(pid, key, data);
1765 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to get private data : %d", ret);
1767 SLOG(LOG_DEBUG, TAG_VCD, "[Server SUCCESS] Set private data");
1773 int vcd_server_mgr_do_action(int pid, int type, const char* action)
1777 /* check if pid is valid */
1778 if (false == vcd_client_manager_is_valid(pid)) {
1779 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] The manager pid(%d) is NOT valid", pid);
1780 return VCD_ERROR_INVALID_PARAMETER;
1783 vcd_state_e state = vcd_config_get_service_state();
1784 if (VCD_STATE_READY != state) {
1785 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Current state is not ready");
1786 return VCD_ERROR_INVALID_STATE;
1789 /* Reqeust do action to engine */
1790 if (VCD_SEND_EVENT_TYPE_TEXT == type)
1791 ret = vcd_engine_process_text(pid, action);
1792 else if (VCD_SEND_EVENT_TYPE_LIST_EVENT == type)
1793 ret = vcd_engine_process_list_event(pid, action);
1794 else if (VCD_SEND_EVENT_TYPE_HAPTIC_EVENT == type)
1795 ret = vcd_engine_process_haptic_event(pid, action);
1798 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to process do action : %d", ret);
1800 vcd_config_set_service_state(VCD_STATE_PROCESSING);
1801 vcdc_send_service_state(VCD_STATE_PROCESSING);
1802 SLOG(LOG_DEBUG, TAG_VCD, "[Server SUCCESS] Process do action");
1808 int vcd_server_mgr_enable_command_type(int pid, int cmd_type)
1812 /* check if pid is valid */
1813 if (false == vcd_client_manager_is_valid(pid)) {
1814 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] The manager pid(%d) is NOT valid", pid);
1815 return VCD_ERROR_INVALID_PARAMETER;
1818 vcd_state_e state = vcd_config_get_service_state();
1819 if (VCD_STATE_READY != state) {
1820 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Current state is not ready");
1821 return VCD_ERROR_INVALID_STATE;
1824 ret = vcd_config_enable_command_type(cmd_type);
1826 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to enable command type");
1828 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Enable command type(%d)", cmd_type);
1834 int vcd_server_mgr_disable_command_type(int pid, int cmd_type)
1838 /* check if pid is valid */
1839 if (false == vcd_client_manager_is_valid(pid)) {
1840 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] The manager pid(%d) is NOT valid", pid);
1841 return VCD_ERROR_INVALID_PARAMETER;
1844 vcd_state_e state = vcd_config_get_service_state();
1845 if (VCD_STATE_READY != state) {
1846 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Current state is not ready");
1847 return VCD_ERROR_INVALID_STATE;
1850 ret = vcd_config_disable_command_type(cmd_type);
1852 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to disable command type");
1854 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Disable command type(%d)", cmd_type);
1861 * VC Server Functions for Client
1863 int vcd_server_initialize(int pid)
1865 if (false == g_is_engine) {
1866 if (0 != vcd_engine_agent_initialize_current_engine()) {
1867 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] No Engine");
1868 g_is_engine = false;
1869 return VCD_ERROR_ENGINE_NOT_FOUND;
1875 if (false == vcd_engine_is_available_engine()) {
1876 if (0 != vcd_engine_agent_initialize_current_engine()) {
1877 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] No Engine");
1878 return VCD_ERROR_ENGINE_NOT_FOUND;
1882 /* check if pid is valid */
1883 if (true == vcd_client_is_available(pid)) {
1884 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] The pid is already exist");
1885 return VCD_ERROR_INVALID_PARAMETER;
1888 /* Add client information to client manager */
1889 if (0 != vcd_client_add(pid)) {
1890 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to add client info");
1891 return VCD_ERROR_OPERATION_FAILED;
1894 SLOG(LOG_DEBUG, TAG_VCD, "[Server Success] Client Initialize : pid(%d)", pid);
1896 return VCD_ERROR_NONE;
1899 int vcd_server_finalize(int pid)
1901 /* check if pid is valid */
1902 if (false == vcd_client_is_available(pid)) {
1903 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] pid is NOT valid ");
1904 return VCD_ERROR_INVALID_PARAMETER;
1907 /* Remove client information */
1908 if (0 != vcd_client_delete(pid)) {
1909 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Fail to delete client");
1912 if (0 == vcd_client_get_ref_count()) {
1913 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Connected client list is empty");
1914 ecore_timer_add(0, __finalize_quit_ecore_loop, NULL);
1917 SLOG(LOG_DEBUG, TAG_VCD, "[Server Success] Client Finalize : pid(%d)", pid);
1919 return VCD_ERROR_NONE;
1922 int vcd_server_set_command(int pid, vc_cmd_type_e cmd_type)
1924 /* check if pid is valid */
1925 if (false == vcd_client_is_available(pid)) {
1926 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] pid is NOT valid ");
1927 return VCD_ERROR_INVALID_PARAMETER;
1930 if (0 != vcd_client_set_command_type(pid, cmd_type)) {
1931 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to set command type : pid(%d), cmd_type(%d)", pid, cmd_type);
1932 return VCD_ERROR_OPERATION_FAILED;
1938 int vcd_server_unset_command(int pid, vc_cmd_type_e cmd_type)
1940 /* check if pid is valid */
1941 if (false == vcd_client_is_available(pid)) {
1942 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] pid is NOT valid ");
1943 return VCD_ERROR_INVALID_PARAMETER;
1946 if (0 != vcd_client_unset_command_type(pid, cmd_type)) {
1947 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to unset command type : pid(%d), cmd_type(%d)", pid, cmd_type);
1948 return VCD_ERROR_OPERATION_FAILED;
1954 int vcd_server_set_foreground(int pid, bool value)
1956 /* check if pid is valid */
1957 if (false == vcd_client_is_available(pid) && false == vcd_client_widget_is_available(pid)) {
1958 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] pid is NOT valid ");
1959 return VCD_ERROR_INVALID_PARAMETER;
1962 if (0 != vcd_config_set_foreground(pid, value)) {
1963 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to set foreground : pid(%d), value(%d)", pid, value);
1964 return VCD_ERROR_OPERATION_FAILED;
1970 static int __vcd_server_launch_manager_app()
1973 bool running = false;
1976 ret = vcd_client_manager_get_appid(&appid);
1977 if (0 != ret || NULL == appid) {
1978 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to get manager appid");
1979 return VCD_ERROR_OPERATION_FAILED;
1981 ret = app_manager_is_running(appid, &running);
1983 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to check running with appid(%s)", appid);
1986 return VCD_ERROR_OPERATION_FAILED;
1988 if (false == running) {
1989 int tmp_ret = __vcd_is_package_installed(appid);
1990 if (false == tmp_ret) {
1991 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] manager app is not installed, appid(%s)", appid);
1993 ret = __vcd_activate_app_by_appcontrol(appid);
1995 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to activate app");
2000 SLOG(LOG_ERROR, TAG_VCD, "Launch vc manager app: appid(%s)", appid);
2003 ret = __vcd_resume_app(appid);
2005 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to resume app");
2010 SLOG(LOG_ERROR, TAG_VCD, "Resume vc manager app: appid(%s)", appid);
2016 return VCD_ERROR_NONE;
2019 int vcd_server_dialog(int pid, const char* disp_text, const char* utt_text, int continuous)
2021 /* check if pid is valid */
2022 if (false == vcd_client_is_available(pid) && false == vcd_client_widget_is_available(pid)) {
2023 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] pid is NOT valid ");
2024 return VCD_ERROR_INVALID_PARAMETER;
2027 int ret = __vcd_server_launch_manager_app();
2029 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);
2033 ret = vcdc_send_dialog(vcd_client_manager_get_pid(), pid, disp_text, utt_text, continuous);
2035 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);
2042 int vcd_server_is_system_command_valid(int pid, int* is_sys_cmd_valid)
2044 /* check if pid is valid */
2045 if (false == vcd_client_is_available(pid) && false == vcd_client_widget_is_available(pid)) {
2046 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] pid is NOT valid ");
2047 return VCD_ERROR_INVALID_PARAMETER;
2050 /* check if system command is valid */
2051 if (true == vcd_client_manager_is_system_command_valid(vcd_client_manager_get_pid()))
2052 *is_sys_cmd_valid = true;
2054 *is_sys_cmd_valid = false;
2060 int vcd_server_set_exclusive_command(int pid, bool value)
2062 /* check if pid is valid */
2063 if (false == vcd_client_is_available(pid)) {
2064 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] pid is NOT valid ");
2065 return VCD_ERROR_INVALID_PARAMETER;
2068 if (true == value) {
2069 if (0 != vcd_client_set_exclusive_command(pid)) {
2070 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to set exclusive command : pid(%d)", pid);
2071 return VCD_ERROR_OPERATION_FAILED;
2074 if (0 != vcd_client_unset_exclusive_command(pid)) {
2075 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to unset exclusive command : pid(%d)", pid);
2076 return VCD_ERROR_OPERATION_FAILED;
2083 int vcd_server_request_start(int pid, bool stop_by_silence)
2085 /* check if pid is valid */
2086 if (false == vcd_client_is_available(pid)) {
2087 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] pid(%d) is NOT forground client", pid);
2088 return VCD_ERROR_INVALID_PARAMETER;
2092 /* Check current state */
2093 vcd_state_e state = vcd_config_get_service_state();
2095 /* Service state should be ready */
2096 if (VCD_STATE_READY != state) {
2097 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Current state is not Ready : pid(%d)", pid);
2098 return VCD_ERROR_INVALID_STATE;
2101 if (-1 != vcd_client_manager_get_pid()) {
2102 /* Check current pid is valid */
2103 if (false == vcd_client_manager_check_demandable_client(pid)) {
2104 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Current client is NOT available : pid(%d)", pid);
2105 return VCD_ERROR_INVALID_PARAMETER;
2109 ret = vcd_server_mgr_start(stop_by_silence, false);
2111 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Fail to start recognition");
2112 return VCD_ERROR_INVALID_PARAMETER;
2118 int vcd_server_request_stop(int pid)
2121 /* Check current state */
2122 vcd_state_e state = vcd_config_get_service_state();
2124 /* Service state should be ready */
2125 if (VCD_STATE_RECORDING != state) {
2126 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Current state is not Recording : pid(%d)", pid);
2127 return VCD_ERROR_INVALID_STATE;
2130 if (-1 != vcd_client_manager_get_pid()) {
2131 /* Check current pid is valid */
2132 if (false == vcd_client_manager_check_demandable_client(pid)) {
2133 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Current client is NOT available : pid(%d)", pid);
2134 return VCD_ERROR_INVALID_PARAMETER;
2138 ret = vcd_server_mgr_stop();
2140 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Fail to start recognition");
2141 return VCD_ERROR_OPERATION_FAILED;
2144 return VCD_ERROR_NONE;
2147 int vcd_server_request_cancel(int pid)
2150 /* Check current state */
2151 vcd_state_e state = vcd_config_get_service_state();
2153 /* Service state should be recording or processing */
2154 if (VCD_STATE_RECORDING != state && VCD_STATE_PROCESSING != state) {
2155 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Current state is not Recording or Processing : pid(%d)", pid);
2156 return VCD_ERROR_INVALID_STATE;
2159 if (-1 != vcd_client_manager_get_pid()) {
2160 /* Check current pid is valid */
2161 if (false == vcd_client_manager_check_demandable_client(pid)) {
2162 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Current client is NOT available : pid(%d)", pid);
2163 return VCD_ERROR_INVALID_PARAMETER;
2167 ret = vcd_server_mgr_cancel();
2169 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Fail to start recognition");
2170 return VCD_ERROR_OPERATION_FAILED;
2173 return VCD_ERROR_NONE;
2178 * VC Server Functions for Widget lib
2180 int vcd_server_widget_initialize(int pid)
2182 if (false == g_is_engine) {
2183 if (0 != vcd_engine_agent_initialize_current_engine()) {
2184 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] No Engine");
2185 g_is_engine = false;
2186 return VCD_ERROR_ENGINE_NOT_FOUND;
2192 if (false == vcd_engine_is_available_engine()) {
2193 if (0 != vcd_engine_agent_initialize_current_engine()) {
2194 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] No Engine");
2195 return VCD_ERROR_ENGINE_NOT_FOUND;
2199 /* check if pid is valid */
2200 if (true == vcd_client_widget_is_available(pid)) {
2201 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] The pid is already exist");
2202 return VCD_ERROR_NONE;
2205 /* Add client information to client manager */
2206 if (0 != vcd_client_widget_add(pid)) {
2207 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to add client info");
2208 return VCD_ERROR_OPERATION_FAILED;
2211 SLOG(LOG_DEBUG, TAG_VCD, "[Server Success] Initialize widget : pid(%d)", pid);
2213 return VCD_ERROR_NONE;
2216 int vcd_server_widget_finalize(int pid)
2218 /* check if pid is valid */
2219 if (false == vcd_client_widget_is_available(pid)) {
2220 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] pid is NOT valid ");
2221 return VCD_ERROR_INVALID_PARAMETER;
2224 /* Remove client information */
2225 if (0 != vcd_client_widget_delete(pid)) {
2226 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Fail to delete client");
2229 if (0 == vcd_client_get_ref_count()) {
2230 SLOG(LOG_DEBUG, TAG_VCD, "[Server] connected client list is empty");
2231 ecore_timer_add(0, __finalize_quit_ecore_loop, NULL);
2234 return VCD_ERROR_NONE;
2237 int vcd_server_widget_start_recording(int pid, bool widget_command)
2239 /* check if pid is valid */
2240 if (false == vcd_client_widget_is_available(pid)) {
2241 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] pid is NOT valid ");
2242 return VCD_ERROR_INVALID_PARAMETER;
2245 if (true == widget_command) {
2246 vcd_client_widget_set_command(pid);
2247 SLOG(LOG_DEBUG, TAG_VCD, "[Server] widget command is available");
2249 vcd_client_widget_unset_command(pid);
2250 SLOG(LOG_WARN, TAG_VCD, "[Server] widget command is NOT available");
2253 int ret = __start_internal_recognition();
2255 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to start recongition : %d", ret);
2256 ecore_timer_add(0, __vcd_request_show_tooltip, (void*)false);
2262 int vcd_server_widget_start(int pid, bool stop_by_silence)
2264 /* check if pid is valid */
2265 int fore_pid = vcd_client_widget_get_foreground_pid();
2266 if (pid != fore_pid) {
2267 SLOG(LOG_ERROR, TAG_VCD, "[Server] pid is NOT foreground");
2268 return VCD_ERROR_INVALID_PARAMETER;
2271 /* Check current state */
2272 vcd_state_e state = vcd_config_get_service_state();
2274 /* Service state should be ready */
2275 if (VCD_STATE_READY != state) {
2276 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Current state is not Ready : pid(%d)", pid);
2277 return VCD_ERROR_INVALID_STATE;
2280 vcd_client_set_slience_detection(stop_by_silence);
2282 /* Notify show tooltip */
2283 ecore_timer_add(0, __vcd_request_show_tooltip, (void*)true);
2288 int vcd_server_widget_stop(int pid)
2290 /* check if pid is valid */
2291 int fore_pid = vcd_client_widget_get_foreground_pid();
2292 if (pid != fore_pid) {
2293 SLOG(LOG_ERROR, TAG_VCD, "[Server] pid is NOT foreground");
2294 return VCD_ERROR_INVALID_PARAMETER;
2298 /* Check current state */
2299 vcd_state_e state = vcd_config_get_service_state();
2301 /* Service state should be recording */
2302 if (VCD_STATE_RECORDING != state) {
2303 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Current service state is not Recording : pid(%d)", pid);
2304 return VCD_ERROR_INVALID_STATE;
2307 ret = vcd_server_mgr_stop();
2309 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Fail to start recognition");
2310 return VCD_ERROR_OPERATION_FAILED;
2313 return VCD_ERROR_NONE;
2316 int vcd_server_widget_cancel(int pid)
2318 /* check if pid is valid */
2319 int fore_pid = vcd_client_widget_get_foreground_pid();
2320 if (pid != fore_pid) {
2321 SLOG(LOG_ERROR, TAG_VCD, "[Server] pid is NOT foreground");
2322 return VCD_ERROR_INVALID_PARAMETER;
2326 /* Check current state */
2327 vcd_state_e state = vcd_config_get_service_state();
2329 /* Service state should be recording or processing */
2330 if (VCD_STATE_RECORDING != state && VCD_STATE_PROCESSING != state) {
2331 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Current state is not Recording or Processing : pid(%d)", pid);
2332 return VCD_ERROR_INVALID_STATE;
2335 ret = vcd_server_mgr_cancel();
2337 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Fail to cancel recognition : %d", ret);
2341 return VCD_ERROR_NONE;
2344 int vcd_server_widget_enable_asr_result(int pid, bool enable)
2347 ret = vcd_client_widget_set_asr_result_enabled(pid, enable);
2349 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Fail to enable asr result : %d", ret);