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"
36 #define CLIENT_CLEAN_UP_TIME 500
38 * VC Server static variable
40 static GList *g_proc_list = NULL;
42 static Ecore_Timer *g_restart_timer = NULL;
43 static Ecore_Timer *g_check_widget_client_timer = NULL;
44 static Ecore_Timer *g_check_client_timer = NULL;
47 * @brief Enumerations of send event type.
50 VCD_SEND_EVENT_TYPE_TEXT, /**< send text event to vc engine*/
51 VCD_SEND_EVENT_TYPE_LIST_EVENT, /**< send list event to vc engine */
52 VCD_SEND_EVENT_TYPE_HAPTIC_EVENT /**< send haptic event to vc engine */
53 } vcd_send_event_type_e;
55 static int __vcd_server_launch_manager_app();
56 static int __start_internal_recognition();
59 * VC Server Internal Functions
61 static Eina_Bool __stop_by_silence(void *data)
63 SLOG(LOG_DEBUG, TAG_VCD, "@@@ Silence Detected ");
65 vcd_server_mgr_stop();
67 SLOG(LOG_DEBUG, TAG_VCD, "@@@");
71 static Eina_Bool __cancel_by_interrupt(void *data)
73 SLOG(LOG_DEBUG, TAG_VCD, "@@@ Cancel by interrupt");
75 vcd_server_mgr_cancel();
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, "@@@");
91 static Eina_Bool __restart_engine(void *data)
93 SLOG(LOG_DEBUG, TAG_VCD, "@@@ Restart by no result");
95 g_restart_timer = NULL;
97 /* Restart recognition */
98 int ret = vcd_engine_recognize_start(true);
100 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to restart recognition : result(%d)", ret);
104 SLOG(LOG_DEBUG, TAG_VCD, "[Server Success] Start engine");
106 vcd_recognition_mode_e mode = vcd_client_get_recognition_mode();
107 if (VCD_RECOGNITION_MODE_RESTART_AFTER_REJECT == mode || VCD_RECOGNITION_MODE_RESTART_CONTINUOUSLY == 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, "@@@");
118 static int __server_recorder_callback(const void* data, const unsigned int length)
120 vcd_state_e state = vcd_config_get_service_state();
121 if (VCD_STATE_READY == state) {
122 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Ready state, but recording");
123 } else if (VCD_STATE_PROCESSING == state) {
127 vce_speech_detect_e speech_detected = VCE_SPEECH_DETECT_NONE;
130 ret = vcd_engine_recognize_audio(data, length, &speech_detected);
134 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to set recording data to engine(%d)", ret);
135 ecore_timer_add(0, __cancel_by_interrupt, NULL);
136 /* Send error cb to manager */
137 if (VCE_ERROR_OUT_OF_NETWORK == ret) {
138 vcdc_send_error_signal_to_manager(vcd_client_manager_get_pid(), VCD_ERROR_TIMED_OUT, "Engine connection failed");
140 vcdc_send_error_signal_to_manager(vcd_client_manager_get_pid(), VCD_ERROR_OPERATION_FAILED, "Engine recognition failed");
145 if (VCE_SPEECH_DETECT_BEGIN == speech_detected) {
146 if (-1 != vcd_client_manager_get_pid()) {
147 /* Manager client is available */
148 if (0 != vcdc_send_speech_detected(vcd_client_manager_get_pid())) {
149 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Fail to send speech detected");
152 } else if (VCE_SPEECH_DETECT_END == speech_detected) {
153 if (VCD_RECOGNITION_MODE_STOP_BY_SILENCE == vcd_client_get_recognition_mode()) {
154 /* silence detected */
155 ecore_timer_add(0, __stop_by_silence, NULL);
156 } else if (VCD_RECOGNITION_MODE_RESTART_AFTER_REJECT == vcd_client_get_recognition_mode()) {
157 /* Stop engine recognition */
158 int ret = vcd_engine_recognize_stop();
160 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to stop recognition : %d", ret);
162 vcd_config_set_service_state(VCD_STATE_PROCESSING);
163 vcdc_send_service_state(VCD_STATE_PROCESSING);
165 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Stop engine only by silence");
166 } else if (VCD_RECOGNITION_MODE_RESTART_CONTINUOUSLY == vcd_client_get_recognition_mode()) {
167 /* Stop engine recognition */
168 int ret = vcd_engine_recognize_stop();
170 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to stop recognition : %d", ret);
178 void __server_recorder_interrupt_callback()
180 SLOG(LOG_DEBUG, TAG_VCD, "@@@ Cancel by sound interrupt");
182 ecore_timer_add(0, __cancel_by_interrupt, NULL);
184 SLOG(LOG_DEBUG, TAG_VCD, "@@@");
187 static void __config_lang_changed_cb(const char* current_lang, void* user_data)
189 SLOG(LOG_DEBUG, TAG_VCD, "@@@ Change language ");
191 /* Current state is recording */
192 vcd_state_e state = vcd_config_get_service_state();
193 if (VCD_STATE_RECORDING == state || VCD_STATE_PROCESSING == state) {
194 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Current state is 'Recording'. Cancel recognition");
195 vcd_server_mgr_cancel();
199 ret = vcd_engine_set_current_language(current_lang);
201 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to set language of engine : %d", ret);
204 SLOG(LOG_DEBUG, TAG_VCD, "@@@");
209 static void __config_foreground_changed_cb(int previous, int current, void* user_data)
211 SLOG(LOG_DEBUG, TAG_VCD, "@@@ Change foreground");
213 SLOG(LOG_DEBUG, TAG_VCD, "Foreground pid(%d)", current);
215 if (VC_NO_FOREGROUND_PID != current) {
216 /* Foreground app is changed */
217 vcd_state_e state = vcd_config_get_service_state();
218 if (VCD_STATE_RECORDING == state) {
219 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Foreground pid(%d) is changed. Cancel recognition", current);
220 ecore_timer_add(0, __cancel_by_interrupt, NULL);
224 SLOG(LOG_DEBUG, TAG_VCD, "@@@");
229 static int __vcd_activate_app_by_appcontrol(const char* appid)
232 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Invalid parameter");
233 return VCD_ERROR_INVALID_PARAMETER;
237 app_control_h app_control = NULL;
238 ret = app_control_create(&app_control);
239 if (APP_CONTROL_ERROR_NONE == ret) {
241 ret = app_control_add_extra_data(app_control, "voice_launch", "get_result");
242 if (APP_CONTROL_ERROR_NONE != ret) {
243 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to add extra data, ret(%d)", ret);
244 app_control_destroy(app_control);
245 return VCD_ERROR_OPERATION_FAILED;
248 ret = app_control_set_app_id(app_control, appid);
249 if (APP_CONTROL_ERROR_NONE != ret) {
250 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to set app id, ret(%d)", ret);
251 app_control_destroy(app_control);
252 return VCD_ERROR_OPERATION_FAILED;
254 // Sent launch request
255 ret = app_control_send_launch_request(app_control, NULL, NULL);
256 if (APP_CONTROL_ERROR_NONE != ret) {
257 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to send launch request, ret(%d)", ret);
258 app_control_destroy(app_control);
259 return VCD_ERROR_OPERATION_FAILED;
261 // Destroy app control
262 ret = app_control_destroy(app_control);
263 if (APP_CONTROL_ERROR_NONE != ret) {
264 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to destroy, ret(%d)", ret);
265 return VCD_ERROR_OPERATION_FAILED;
268 return VCD_ERROR_NONE;
271 static int __vcd_resume_app(const char* appid)
273 app_context_h app_context = NULL;
274 int ret = app_manager_get_app_context(appid, &app_context);
275 if (APP_MANAGER_ERROR_NONE != ret) {
276 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to get app_context, ret(%d), appid(%s)", ret, appid);
277 return VCD_ERROR_OPERATION_FAILED;
280 ret = app_manager_resume_app(app_context);
281 if (APP_MANAGER_ERROR_NONE != ret) {
282 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to resume app, ret(%d), appid(%s)", ret, appid);
283 return VCD_ERROR_OPERATION_FAILED;
285 return VCD_ERROR_NONE;
288 static bool __vcd_is_package_installed(const char* appid)
290 app_info_h app_info = NULL;
291 int ret = app_manager_get_app_info(appid, &app_info);
292 if (APP_MANAGER_ERROR_NONE != ret || NULL == app_info)
294 ret = app_info_destroy(app_info);
295 if (APP_MANAGER_ERROR_NONE != ret)
296 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to destroy app_info, ret(%d)", ret);
300 static bool __vcd_launch_app(const char* result)
302 if (NULL == result) {
303 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Invalid parameter");
304 return VCD_ERROR_INVALID_PARAMETER;
307 GSList* app_list = NULL;
308 if (0 != vc_db_get_appid_list(result, &app_list)) {
309 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] result text is NULL");
310 return VCD_ERROR_INVALID_PARAMETER;
313 if (0 != g_slist_length(app_list)) {
316 vc_deactivated_app_s* temp_app = NULL;
317 iter = g_slist_nth(app_list, 0);
319 while (NULL != iter) {
320 temp_app = iter->data;
322 if (NULL != temp_app) {
323 if (NULL != temp_app->appid) {
325 bool running = false;
326 ret = app_manager_is_running(temp_app->appid, &running);
327 if (APP_MANAGER_ERROR_NONE != ret) {
328 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to check running with appid(%s)", temp_app->appid);
329 free(temp_app->appid);
330 temp_app->appid = NULL;
333 return VCD_ERROR_OPERATION_FAILED;
335 if (false == running) {
336 int tmp_ret = __vcd_is_package_installed(temp_app->appid);
337 if (false == tmp_ret) {
338 SLOG(LOG_WARN, TAG_VCD, "[WARNING] app is not installed, appid(%s)", temp_app->appid);
340 ret = __vcd_activate_app_by_appcontrol(temp_app->appid);
342 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to activate app");
343 free(temp_app->appid);
344 temp_app->appid = NULL;
349 SLOG(LOG_ERROR, TAG_VCD, "Launch app: appid(%s) result(%s)", temp_app->appid, result);
352 ret = __vcd_resume_app(temp_app->appid);
354 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to resume app");
355 free(temp_app->appid);
356 temp_app->appid = NULL;
361 SLOG(LOG_ERROR, TAG_VCD, "Resume app: appid(%s) result(%s)", temp_app->appid, result);
363 free(temp_app->appid);
364 temp_app->appid = NULL;
369 iter = g_slist_next(iter);
374 return VCD_ERROR_NONE;
377 static Eina_Bool __vcd_send_selected_result(void *data)
379 GSList* pid_list = NULL;
380 const char* result = vcd_client_manager_get_result_text();
382 if (0 != vc_info_parser_get_result_pid_list(&pid_list, result)) {
383 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Fail to get pid list. No result");
385 if (0 < g_slist_length(pid_list)) {
387 vc_cmd_s* temp_cmd = NULL;
392 iter = g_slist_nth(pid_list, 0);
393 while (NULL != iter) {
394 temp_cmd = iter->data;
396 if (NULL != temp_cmd && (pre_pid != temp_cmd->pid || pre_type == VC_COMMAND_TYPE_WIDGET || temp_cmd->type == VC_COMMAND_TYPE_WIDGET)) {
397 /* Launch deactivated several apps that is matched with result */
398 ret = __vcd_launch_app(result);
400 SLOG(LOG_ERROR, TAG_VCD, "Fail to launch or resume app, ret(%d) result(%s)", ret, result);
402 /* send result noti */
403 ret = vcdc_send_result(temp_cmd->pid, vcd_client_manager_get_pid(), temp_cmd->type);
405 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Fail to send result, ret(%d)", ret);
408 SLOG(LOG_ERROR, TAG_VCD, "[Server] Send result : pid(%d) type(%d)", temp_cmd->pid, temp_cmd->type);
409 pre_pid = temp_cmd->pid;
410 pre_type = temp_cmd->type;
416 pid_list = g_slist_remove_link(pid_list, iter);
417 iter = g_slist_nth(pid_list, 0);
422 if (VCD_RECOGNITION_MODE_RESTART_CONTINUOUSLY != vcd_client_get_recognition_mode()) {
423 vcd_config_set_service_state(VCD_STATE_READY);
424 vcdc_send_service_state(VCD_STATE_READY);
430 int vcd_send_asr_result(vce_asr_result_event_e event, const char* asr_result, void *user_data)
432 int ret = __vcd_server_launch_manager_app();
434 SECURE_SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to send ASR result : mgr_pid(%d), asr_result(%s)", vcd_client_manager_get_pid(), asr_result);
438 if (NULL != asr_result) {
439 SECURE_SLOG(LOG_DEBUG, TAG_VCD, "[Server] ASR result - Event(%d), Text(%s)", event, asr_result);
440 ret = vcdc_send_pre_result_to_manager(vcd_client_manager_get_pid(), event, asr_result);
442 SECURE_SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to send ASR result : mgr_pid(%d), asr_result(%s)", vcd_client_manager_get_pid(), asr_result);
449 int vcd_send_specific_engine_result(const char* engine_app_id, const char* event, const char* result, void *user_info)
451 if (NULL != result) {
452 SLOG(LOG_DEBUG, TAG_VCD, "[Server] specific engine result - Event(%s), Text(%s)", event, result);
453 vcdc_send_specific_engine_result_to_manager(vcd_client_manager_get_pid(), engine_app_id, event, result);
456 return VCD_ERROR_NONE;
459 int vcd_send_nlg_result(const char* nlg_result, void *user_data)
461 int ret = __vcd_server_launch_manager_app();
463 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);
467 SLOG(LOG_ERROR, TAG_VCD, "[Server] send dialog : mgr_pid(%d), nlg_result(%s)", vcd_client_manager_get_pid(), nlg_result);
468 ret = vcdc_send_dialog(vcd_client_manager_get_pid(), -1, nlg_result, NULL, 0); //0: VC_DIALOG_END
470 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);
474 static void* __recorder_stop(void *data)
480 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)
483 vcd_recognition_mode_e recognition_mode = vcd_client_get_recognition_mode();
485 if (VCD_STATE_PROCESSING != vcd_config_get_service_state()) {
486 if (VCD_RECOGNITION_MODE_RESTART_CONTINUOUSLY != recognition_mode) {
487 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Current state is not 'Processing' and mode is not 'Restart continuously'");
488 return VCD_ERROR_INVALID_STATE;
492 vc_info_parser_unset_result(vcd_client_manager_get_exclusive());
493 vcd_client_manager_set_result_text(all_result);
495 SECURE_SLOG(LOG_INFO, TAG_VCD, "[Server] Event(%d), Text(%s) Nonfixed(%s) Msg(%s) Result count(%d)",
496 event, all_result, non_fixed_result, msg, count);
498 SECURE_SLOG(LOG_ERROR, TAG_VCD, "[Server] NLU result(%s)", nlu_result);
501 /* if nlu_result is exist, Add command handle(is_action) into result list */
503 SLOG(LOG_DEBUG, TAG_VCD, "[Server] @ Get engine result @");
505 vc_cmd_s* temp_cmd = NULL;
506 vc_cmd_list_h vc_cmd_list = NULL;
508 if (0 != vc_cmd_list_create(&vc_cmd_list)) {
509 SLOG(LOG_INFO, TAG_VCD, "[Server] Fail to create command list");
510 vcd_client_manager_set_exclusive(false);
511 vcd_config_set_service_state(VCD_STATE_READY);
512 vcdc_send_service_state(VCD_STATE_READY);
513 return VCD_ERROR_NONE;
516 /* priority filter */
517 /* system > exclusive > widget > foreground > system_background > widget partial > foreground partial > background */
519 int* filtered_id = (int*)calloc(count, sizeof(int));
521 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to allocate memory");
522 vc_cmd_list_destroy(vc_cmd_list, true);
523 return VCD_ERROR_OUT_OF_MEMORY;
525 int filtered_count = 0;
526 int top_priority = VC_COMMAND_PRIORITY_BACKGROUND;
527 for (i = 0; i < count; i++) {
528 SLOG(LOG_INFO, TAG_VCD, "[Server] [%d] Result id(%d)", i, result_id[i]);
530 if (0 > result_id[i]) {
531 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Result ID(%d) is NOT valid", result_id[i]);
535 ret = vcd_client_get_cmd_from_result_id(result_id[i], &temp_cmd);
536 if (0 == ret && NULL != temp_cmd) {
537 if (top_priority == temp_cmd->priority) {
538 filtered_id[filtered_count] = result_id[i];
540 } else if (top_priority > temp_cmd->priority) {
541 filtered_id[0] = result_id[i];
543 top_priority = temp_cmd->priority;
546 vc_cmd_destroy((vc_cmd_h)temp_cmd);
552 if (top_priority >= VC_COMMAND_PRIORITY_WIDGET) {
553 int pid = vcd_client_widget_get_foreground_pid();
555 if (NULL != all_result) {
556 vc_info_parser_set_result(all_result, event, msg, NULL, false);
558 vcd_client_widget_get_asr_result_enabled(pid, &enable);
559 if (true == enable) {
560 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Send ASR result to Widget client");
561 bool is_consumed = false;
562 if (NULL != user_info) {
565 if (0 != vcdc_send_asr_result(pid, event, all_result, VC_COMMAND_TYPE_WIDGET, &is_consumed)) {
566 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to send asr result");
568 SLOG(LOG_DEBUG, TAG_VCD, "[Server] ASR result is consumed(%d)", is_consumed);
569 if (true == is_consumed) {
570 if (NULL != user_info) {
572 SLOG(LOG_ERROR, TAG_VCD, "[Server] Send whether ASR result is consumed or not (%d)", *user_info);
574 vcdc_send_show_tooltip(pid, false);
575 if (-1 != vcd_client_manager_get_pid()) {
576 /* Manager client is available */
577 vc_info_parser_unset_result(false);
578 vc_info_parser_set_result(all_result, VC_RESULT_EVENT_RESULT_SUCCESS, msg, NULL, false);
579 if (0 != vcdc_send_result_to_manager(vcd_client_manager_get_pid(), VC_RESULT_TYPE_NOTIFICATION)) {
580 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Fail to send result");
584 // Set state manually, because the result is already handled in ASR result by client.
585 // So, the daemon does not need to send the result to client.
586 vcd_client_manager_set_exclusive(false);
588 vcd_config_set_service_state(VCD_STATE_READY);
589 vcdc_send_service_state(VCD_STATE_READY);
590 vc_cmd_list_destroy(vc_cmd_list, true);
591 if (NULL != filtered_id) {
595 return VCD_ERROR_NONE;
604 for (i = 0; i < filtered_count; i++) {
605 SLOG(LOG_INFO, TAG_VCD, "[Server] [%d] Filtered Result id(%d)", i, filtered_id[i]);
607 if (filtered_id[i] < 0) {
608 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Filtered ID(%d) is NOT valid", filtered_id[i]);
612 ret = vcd_client_get_cmd_from_result_id(filtered_id[i], &temp_cmd);
613 if (0 == ret && NULL != temp_cmd) {
614 switch (temp_cmd->format) {
615 case VC_CMD_FORMAT_FIXED:
616 case VC_CMD_FORMAT_FIXED_AND_VFIXED:
617 case VC_CMD_FORMAT_VFIXED_AND_FIXED:
618 case VC_CMD_FORMAT_PARTIAL:
619 case VC_CMD_FORMAT_FIXED_AND_NONFIXED:
620 case VC_CMD_FORMAT_NONFIXED_AND_FIXED:
622 case VC_CMD_FORMAT_ACTION:
626 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Unknown command type : %d", temp_cmd->type);
630 if (0 != vc_cmd_list_add(vc_cmd_list, (vc_cmd_h)temp_cmd)) {
631 SLOG(LOG_DEBUG, TAG_VCD, "Fail to add command to list");
632 vc_cmd_destroy((vc_cmd_h)temp_cmd);
636 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] NOT found matched result(%d)", filtered_id[i]);
640 if (NULL != filtered_id) {
645 if (NULL != nlu_result) {
646 SECURE_SLOG(LOG_INFO, TAG_VCD, "[Server] NLU (%s)", nlu_result);
647 vc_info_parser_set_nlu_result(nlu_result);
648 if (0 == is_action) {
650 if (0 != vc_cmd_create(&nlu_cmd)) {
651 SLOG(LOG_ERROR, TAG_VCD, "Fail to nlu cmd create");
653 if (0 != vc_cmd_set_type(nlu_cmd, VC_COMMAND_TYPE_SYSTEM)) {
654 SLOG(LOG_ERROR, TAG_VCD, "Fail to set type");
656 if (0 != vc_cmd_set_pid(nlu_cmd, vcd_client_manager_get_pid())) {
657 SLOG(LOG_ERROR, TAG_VCD, "Fail to set pid");
659 if (0 != vc_cmd_set_format(nlu_cmd, VC_CMD_FORMAT_ACTION)) {
660 SLOG(LOG_ERROR, TAG_VCD, "Fail to set format");
662 if (0 != vc_cmd_list_add(vc_cmd_list, nlu_cmd)) {
663 SLOG(LOG_ERROR, TAG_VCD, "Fail to add nlu cmd to list");
664 vc_cmd_destroy(nlu_cmd);
670 vc_cmd_print_list(vc_cmd_list);
672 SLOG(LOG_DEBUG, TAG_VCD, "[Server] @@@@");
674 int result_count = 0;
675 vc_cmd_list_get_count(vc_cmd_list, &result_count);
677 /* Handle the result list */
678 if (0 == result_count) {
680 vc_cmd_list_h widget_cmd_list = NULL;
681 vc_cmd_list_h foreground_cmd_list = NULL;
682 if (NULL != all_result) {
683 SECURE_SLOG(LOG_DEBUG, TAG_VCD, "[Server] Engine result is no command : %s", all_result);
686 if (0 != vc_cmd_list_create(&widget_cmd_list)) {
687 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to create widget command list handle");
688 vc_cmd_list_destroy(vc_cmd_list, true);
689 return VCD_ERROR_OUT_OF_MEMORY;
692 /* Get the list of widget type commands */
693 vcd_client_append_cmd_from_type(VC_COMMAND_TYPE_WIDGET, widget_cmd_list);
694 vc_cmd_list_get_count(widget_cmd_list, &cnt);
696 /* Matched with widget command partially */
697 vc_cmd_get_partially_matched_cmd_list(all_result, widget_cmd_list, vc_cmd_list, VC_SEARCH_NONE_LEVEL);
698 vc_cmd_list_get_count(vc_cmd_list, &cnt);
700 top_priority = VC_COMMAND_PRIORITY_WIDGET;
701 SLOG(LOG_INFO, TAG_VCD, "[INFO] Partially matched widget command");
704 if (0 != vc_cmd_list_create(&foreground_cmd_list)) {
705 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to create foreground command list handle");
706 vc_cmd_list_destroy(vc_cmd_list, true);
707 vc_cmd_list_destroy(widget_cmd_list, true);
708 return VCD_ERROR_OUT_OF_MEMORY;
711 /* Get the list of foreground type commands */
712 vcd_client_append_cmd_from_type(VC_COMMAND_TYPE_FOREGROUND, foreground_cmd_list);
713 vc_cmd_list_get_count(foreground_cmd_list, &cnt);
715 /* Matched with foreground command partially */
716 vc_cmd_get_partially_matched_cmd_list(all_result, foreground_cmd_list, vc_cmd_list, VC_SEARCH_NONE_LEVEL);
717 vc_cmd_list_get_count(vc_cmd_list, &cnt);
719 top_priority = VC_COMMAND_PRIORITY_FOREGROUND;
720 SLOG(LOG_INFO, TAG_VCD, "[INFO] Partially matched foreground command");
723 vc_cmd_list_destroy(foreground_cmd_list, true);
725 vc_cmd_list_destroy(widget_cmd_list, true);
727 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Engine result is NULL");
730 vc_cmd_list_get_count(vc_cmd_list, &result_count);
732 // After running partial matching algorithm, if there is no result.
733 if (0 == result_count) {
734 SLOG(LOG_DEBUG, TAG_VCD, "[Server] No commands even after partial matching");
736 bool temp = vcd_client_manager_get_exclusive();
737 vc_info_parser_set_result(all_result, event, msg, NULL, temp);
739 int pid = vcd_client_widget_get_foreground_pid();
741 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Request tooltip hide");
742 /* Send to hide tooltip */
743 vcdc_send_show_tooltip(pid, false);
746 if (-1 != vcd_client_manager_get_pid()) {
747 /* Manager client is available */
748 if (0 != vcdc_send_result_to_manager(vcd_client_manager_get_pid(), VC_RESULT_TYPE_NORMAL)) {
749 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Fail to send result");
753 vcd_client_manager_set_exclusive(false);
754 vc_cmd_list_destroy(vc_cmd_list, true);
756 return VCD_ERROR_NONE;
759 // Partial matching algorithm find some commands
760 event = VC_RESULT_EVENT_RESULT_SUCCESS;
763 // There are more than one result.
764 if (false == vcd_client_manager_get_exclusive()) {
765 vc_cmd_list_h temp_list = NULL;
767 /* Foreground, Widget, Background, System, System-Background */
768 if (top_priority >= VC_COMMAND_PRIORITY_BACKGROUND) {
769 vc_cmd_list_h widget_cmd_list = NULL;
770 vc_cmd_list_h foreground_cmd_list = NULL;
773 if (0 != vc_cmd_list_create(&temp_list)) {
774 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to create widget command list handle");
775 vc_cmd_list_destroy(vc_cmd_list, true);
776 return VCD_ERROR_OUT_OF_MEMORY;
779 if (0 != vc_cmd_list_create(&widget_cmd_list)) {
780 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to create widget command list handle");
781 vc_cmd_list_destroy(vc_cmd_list, true);
782 vc_cmd_list_destroy(temp_list, true);
783 return VCD_ERROR_OUT_OF_MEMORY;
786 /* Get the list of widget type commands */
787 vcd_client_append_cmd_from_type(VC_COMMAND_TYPE_WIDGET, widget_cmd_list);
788 vc_cmd_list_get_count(widget_cmd_list, &cnt);
790 /* Matched with widget command partially */
791 vc_cmd_get_partially_matched_cmd_list(all_result, widget_cmd_list, temp_list, VC_SEARCH_NONE_LEVEL);
792 vc_cmd_list_get_count(temp_list, &cnt);
794 if (0 != vc_cmd_list_destroy(vc_cmd_list, true)) {
795 SLOG(LOG_WARN, TAG_VCD, "[WARNING] Fail to destroy list");
797 vc_cmd_list = temp_list;
798 top_priority = VC_COMMAND_PRIORITY_WIDGET;
799 event = VC_RESULT_EVENT_RESULT_SUCCESS;
800 SLOG(LOG_INFO, TAG_VCD, "[INFO] Partially matched widget command when background cmd exists");
803 if (0 != vc_cmd_list_create(&foreground_cmd_list)) {
804 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to create foreground command list handle");
805 vc_cmd_list_destroy(vc_cmd_list, true);
806 vc_cmd_list_destroy(widget_cmd_list, true);
807 return VCD_ERROR_OUT_OF_MEMORY;
810 /* Get the list of foreground type commands */
811 vcd_client_append_cmd_from_type(VC_COMMAND_TYPE_FOREGROUND, foreground_cmd_list);
812 vc_cmd_list_get_count(foreground_cmd_list, &cnt);
814 /* Matched with foreground command partially */
815 vc_cmd_get_partially_matched_cmd_list(all_result, foreground_cmd_list, temp_list, VC_SEARCH_NONE_LEVEL);
816 vc_cmd_list_get_count(temp_list, &cnt);
818 if (0 != vc_cmd_list_destroy(vc_cmd_list, true)) {
819 SLOG(LOG_WARN, TAG_VCD, "[WARNING] Fail to destroy list");
821 vc_cmd_list = temp_list;
822 top_priority = VC_COMMAND_PRIORITY_FOREGROUND;
823 event = VC_RESULT_EVENT_RESULT_SUCCESS;
824 SLOG(LOG_INFO, TAG_VCD, "[INFO] Partially matched foreground command when background cmd exists");
827 vc_cmd_list_destroy(foreground_cmd_list, true);
829 vc_cmd_list_destroy(widget_cmd_list, true);
832 int pid = vcd_client_widget_get_foreground_pid();
834 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Request tooltip hide");
835 vcdc_send_show_tooltip(pid, false);
838 vc_info_parser_set_result(all_result, event, msg, vc_cmd_list, false);
839 vc_cmd_list_destroy(vc_cmd_list, true);
841 if (-1 != vcd_client_manager_get_pid()) {
842 /* Manager client is available */
843 if (0 != vcdc_send_result_to_manager(vcd_client_manager_get_pid(), VC_RESULT_TYPE_NORMAL)) {
844 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Fail to send result");
847 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Manager is NOT available. Send result to client directly");
848 ecore_timer_add(0, __vcd_send_selected_result, NULL);
851 /* exclusive command */
852 vc_info_parser_set_result(all_result, event, msg, vc_cmd_list, true);
853 vc_cmd_list_destroy(vc_cmd_list, true);
855 if (-1 != vcd_client_manager_get_pid()) {
856 /* Manager client is available */
857 if (0 != vcdc_send_result_to_manager(vcd_client_manager_get_pid(), VC_RESULT_TYPE_NORMAL)) {
858 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Fail to send result");
861 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Manager is NOT available");
864 vcd_client_manager_set_exclusive(false);
867 if (VCD_RECOGNITION_MODE_RESTART_AFTER_REJECT == recognition_mode) {
868 if (VCE_RESULT_EVENT_REJECTED == event) {
869 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Restart by no or rejected result");
870 /* If no result and restart option is ON */
871 /* Send reject message */
872 bool temp = vcd_client_manager_get_exclusive();
873 vc_info_parser_set_result(all_result, event, msg, NULL, temp);
874 ret = vcdc_send_result_to_manager(vcd_client_manager_get_pid(), VC_RESULT_TYPE_NOTIFICATION);
876 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Fail to send result");
879 g_restart_timer = ecore_timer_add(0, __restart_engine, NULL);
882 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Stop recorder due to success");
883 //vcd_recorder_stop();
884 ecore_main_loop_thread_safe_call_sync(__recorder_stop, NULL);
885 } else if (VCD_RECOGNITION_MODE_RESTART_CONTINUOUSLY == recognition_mode) {
886 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Restart continuously");
887 /* Restart option is ON */
888 g_restart_timer = ecore_timer_add(0, __restart_engine, NULL);
889 if (VCE_RESULT_EVENT_REJECTED == event) {
890 bool temp = vcd_client_manager_get_exclusive();
891 vc_info_parser_set_result(all_result, event, msg, NULL, temp);
892 ret = vcdc_send_result_to_manager(vcd_client_manager_get_pid(), VC_RESULT_TYPE_NOTIFICATION);
894 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Fail to send result");
900 return VCD_ERROR_NONE;
904 if (NULL == result_id) {
906 if (NULL != all_result) {
907 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Engine result is no command : %s", all_result);
908 bool temp = vcd_client_manager_get_exclusive();
909 vc_info_parser_set_result(all_result, event, msg, NULL, temp);
912 int pid = vcd_client_widget_get_foreground_pid();
914 if (NULL != all_result) {
915 /* Send result text to widget */
916 vcdc_send_result(pid, vcd_client_manager_get_pid(), VC_COMMAND_TYPE_WIDGET);
919 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Request tooltip hide");
920 /* Send to hide tooltip */
921 vcdc_send_show_tooltip(pid, false);
924 if (-1 != vcd_client_manager_get_pid()) {
925 /* Manager client is available */
926 if (0 != vcdc_send_result_to_manager(vcd_client_manager_get_pid(), VC_RESULT_TYPE_NORMAL)) {
927 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Fail to send result");
931 vcd_client_manager_set_exclusive(false);
937 SLOG(LOG_DEBUG, TAG_VCD, "[Server] @ Get engine result @");
940 vc_cmd_s* temp_cmd = NULL;
941 vc_cmd_list_h vc_cmd_list = NULL;
943 if (0 != vc_cmd_list_create(&vc_cmd_list)) {
944 SLOG(LOG_ERROR, TAG_VCD, "[Server] Fail to create command list");
945 vcd_client_manager_set_exclusive(false);
946 vcd_config_set_service_state(VCD_STATE_READY);
947 vcdc_send_service_state(VCD_STATE_READY);
952 for (i = 0; i < count; i++) {
953 SLOG(LOG_DEBUG, TAG_VCD, "[Server] [%d] Result ID(%d)", i, result_id[i]);
955 if (result_id[i] < 0) {
956 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Result ID(%d) is NOT valid", result_id[i]);
960 ret = vcd_client_get_cmd_from_result_id(result_id[i], &temp_cmd);
961 if (0 == ret && NULL != temp_cmd) {
962 switch (temp_cmd->format) {
963 case VC_CMD_FORMAT_FIXED:
964 case VC_CMD_FORMAT_FIXED_AND_VFIXED:
965 case VC_CMD_FORMAT_VFIXED_AND_FIXED:
966 case VC_CMD_FORMAT_PARTIAL:
967 /* Nonfixed result is NOT valid */
969 case VC_CMD_FORMAT_FIXED_AND_NONFIXED:
970 if (NULL == temp_cmd->parameter) {
971 if (NULL != non_fixed_result) {
972 temp_cmd->parameter = strdup(non_fixed_result);
975 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Command type is NOT valid. Parameter (%s)", temp_cmd->parameter);
978 case VC_CMD_FORMAT_NONFIXED_AND_FIXED:
979 if (NULL == temp_cmd->command) {
980 if (NULL != non_fixed_result) {
981 temp_cmd->command = strdup(non_fixed_result);
984 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Command type is NOT valid. Command (%s)", temp_cmd->command);
989 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Unknown command type : %d", temp_cmd->type);
993 if (0 != vc_cmd_list_add(vc_cmd_list, (vc_cmd_h)temp_cmd)) {
994 SLOG(LOG_DEBUG, TAG_VCD, "Fail to add command to list");
995 vc_cmd_destroy((vc_cmd_h)temp_cmd);
998 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] NOT found matched result(%d)", result_id[i]);
1002 vc_cmd_print_list(vc_cmd_list);
1004 SLOG(LOG_DEBUG, TAG_VCD, "[Server] @@@@");
1006 int result_count = 0;
1007 vc_cmd_list_get_count(vc_cmd_list, &result_count);
1009 if (false == vcd_client_manager_get_exclusive()) {
1010 int pid = vcd_client_widget_get_foreground_pid();
1012 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Request tooltip hide");
1013 vcdc_send_show_tooltip(pid, false);
1016 vc_info_parser_set_result(all_result, event, msg, vc_cmd_list, false);
1018 if (-1 != vcd_client_manager_get_pid()) {
1019 /* Manager client is available */
1020 if (0 != vcdc_send_result_to_manager(vcd_client_manager_get_pid(), VC_RESULT_TYPE_NORMAL)) {
1021 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Fail to send result");
1024 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Manager is NOT available. Send result to client directly");
1025 /* Send result to client */
1026 ecore_timer_add(0, __vcd_send_selected_result, NULL);
1029 /* exclusive command */
1030 vc_info_parser_set_result(all_result, event, msg, vc_cmd_list, true);
1032 if (-1 != vcd_client_manager_get_pid()) {
1033 /* Manager client is available */
1034 if (0 != vcdc_send_result_to_manager(vcd_client_manager_get_pid(), VC_RESULT_TYPE_NORMAL)) {
1035 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Fail to send result");
1038 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Manager is NOT available");
1041 vcd_client_manager_set_exclusive(false);
1044 vc_cmd_list_destroy(vc_cmd_list, true);
1051 static void __vcd_server_nlu_result_cb(vce_result_event_e event, const char* nlu_result, void *user_data)
1053 SECURE_SLOG(LOG_DEBUG, TAG_VCD, "[Server] NLU result cb - event(%d)", event);
1054 SECURE_SLOG(LOG_DEBUG, TAG_VCD, "[Server] result (%s)", nlu_result);
1056 int ret = vc_info_parser_set_nlu_result(nlu_result);
1058 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to set nlu result (%d)", ret);
1065 int vcd_send_error(vce_error_e error, const char* msg, void *user_data)
1067 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Engine Error cb - reason(%d), msg(%s)", error, msg);
1068 ecore_main_loop_thread_safe_call_async(__cancel_by_error, NULL);
1070 char* error_msg = NULL;
1072 error_msg = strdup(msg);
1073 if (NULL == error_msg) {
1074 return VCD_ERROR_OUT_OF_MEMORY;
1078 int ret = VCD_ERROR_NONE;
1079 ret = vcdc_send_error_signal_to_manager(vcd_client_manager_get_pid(), error, error_msg);
1080 if (VCD_ERROR_NONE != ret) {
1081 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to send error signal");
1084 if (NULL != error_msg) {
1092 /* for TTS feedback */
1093 int vcd_send_feedback_audio_format(int rate, vce_audio_channel_e channel, vce_audio_type_e audio_type)
1095 SLOG(LOG_INFO, TAG_VCD, "[Server DEBUG] Engine - Send TTS feedback audio format");
1097 /* send TTS feedback audio format to VC manager */
1098 int ret = VCD_ERROR_NONE;
1099 ret = vcdc_send_feedback_audio_format_to_manager(vcd_client_manager_get_pid(), rate, channel, audio_type);
1100 if (VCD_ERROR_NONE != ret) {
1101 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to send TTS feedback audio format to VC manager");
1107 int vcd_send_feedback_streaming(vce_feedback_event_e event, char* buffer, int len)
1109 SLOG(LOG_INFO, TAG_VCD, "[Server DEBUG] Engine - Send TTS feedback streaming");
1111 /* send TTS feedback streaming to VC manager */
1112 int ret = VCD_ERROR_NONE;
1113 ret = vcdc_send_feedback_streaming_to_manager(vcd_client_manager_get_pid(), event, buffer, len);
1114 if (VCD_ERROR_NONE != ret) {
1115 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to send TTS feedback streaming to VC manager");
1123 * vcd server Interfaces
1125 static void __vcd_file_clean_up()
1127 SLOG(LOG_DEBUG, TAG_VCD, "== Old file clean up == ");
1130 struct dirent *dirp = NULL;
1132 dp = opendir(VC_RUNTIME_INFO_ROOT);
1134 SLOG(LOG_ERROR, TAG_VCD, "[File message WARN] Fail to open path : %s", VC_RUNTIME_INFO_ROOT);
1138 char remove_path[256] = {0, };
1143 if (!strncmp("vc_", dirp->d_name, strlen("vc_"))) {
1144 memset(remove_path, 0, 256);
1145 snprintf(remove_path, 256, "%s/%s", VC_RUNTIME_INFO_ROOT, dirp->d_name);
1148 if (0 != remove(remove_path)) {
1149 SLOG(LOG_WARN, TAG_VCD, "[File message WARN] Fail to remove file : %s", remove_path);
1151 SLOG(LOG_DEBUG, TAG_VCD, "[File message] Remove file : %s", remove_path);
1155 } while (NULL != dirp);
1162 static int __vcd_db_clean_up()
1165 int cnt = VC_COMMAND_TYPE_FOREGROUND;
1167 if (VC_COMMAND_TYPE_BACKGROUND != cnt)
1168 ret = vc_db_delete_commands(-1, cnt, NULL);
1169 } while (VC_COMMAND_TYPE_EXCLUSIVE >= ++cnt);
1174 int vcd_initialize(vce_request_callback_s *callback)
1178 /* Remove old file */
1179 __vcd_file_clean_up();
1181 /* initialize modules */
1182 ret = vcd_config_initialize(__config_lang_changed_cb, __config_foreground_changed_cb, NULL);
1184 SLOG(LOG_ERROR, TAG_VCD, "[Server WARNING] Fail to initialize config.");
1187 /* Remove db data */
1188 ret = __vcd_db_clean_up();
1190 SLOG(LOG_ERROR, TAG_VCD, "[Server WARNING] Fail to remove db data");
1193 vcd_config_set_service_state(VCD_STATE_NONE);
1195 ret = vcd_engine_agent_init();
1197 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to engine agent initialize : result(%d)", ret);
1201 if (0 != vcd_recorder_create(__server_recorder_callback, __server_recorder_interrupt_callback)) {
1202 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to create recorder");
1203 return VCD_ERROR_OPERATION_FAILED;
1207 if (0 != vcd_engine_agent_load_current_engine(callback)) {
1208 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to load current engine");
1209 return VCD_ERROR_OPERATION_FAILED;
1212 /* Initialize manager info */
1213 vcd_client_manager_unset();
1215 vcd_config_set_service_state(VCD_STATE_READY);
1216 // vcdc_send_service_state(VCD_STATE_READY);
1218 /* Set timer cleanup client all */
1219 g_check_client_timer = ecore_timer_add(CLIENT_CLEAN_UP_TIME, vcd_cleanup_client_all, NULL);
1220 if (NULL == g_check_client_timer) {
1221 SLOG(LOG_WARN, TAG_VCD, "[Server Warning] Fail to create timer of client check");
1224 SLOG(LOG_ERROR, TAG_VCD, "[Server SUCCESS] initialize");
1232 if (0 < g_list_length(g_proc_list)) {
1233 iter = g_list_first(g_proc_list);
1234 while (NULL != iter) {
1235 g_proc_list = g_list_remove_link(g_proc_list, iter);
1236 iter = g_list_first(g_proc_list);
1240 if (NULL != g_restart_timer) {
1241 ecore_timer_del(g_restart_timer);
1242 g_restart_timer = NULL;
1245 if (NULL != g_check_client_timer) {
1246 ecore_timer_del(g_check_client_timer);
1247 g_check_client_timer = NULL;
1250 vcd_state_e state = vcd_config_get_service_state();
1251 if (VCD_STATE_READY != state) {
1252 if (VCD_STATE_RECORDING == state) {
1253 vcd_recorder_stop();
1255 vcd_engine_recognize_cancel();
1258 if (0 != vcd_recorder_destroy()) {
1259 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to destroy recorder");
1262 SLOG(LOG_DEBUG, TAG_VCD, "[Server] destroy recorder");
1265 if (0 != vcd_engine_agent_release()) {
1266 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to release engine");
1269 SLOG(LOG_DEBUG, TAG_VCD, "[Server] release engine");
1272 vcd_client_manager_unset_appid();
1274 vcd_config_set_service_state(VCD_STATE_NONE);
1275 vcdc_send_service_state(VCD_STATE_NONE);
1277 SLOG(LOG_ERROR, TAG_VCD, "[Server] mode finalize");
1282 static Eina_Bool __finalize_quit_ecore_loop(void *data)
1284 bool ret = vcd_finalize();
1288 ecore_main_loop_quit();
1293 static void __read_proc()
1296 struct dirent *dirp = NULL;
1300 if (0 < g_list_length(g_proc_list)) {
1301 iter = g_list_first(g_proc_list);
1302 while (NULL != iter) {
1303 g_proc_list = g_list_remove_link(g_proc_list, iter);
1304 iter = g_list_first(g_proc_list);
1308 dp = opendir("/proc");
1310 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to open proc");
1316 tmp = atoi(dirp->d_name);
1317 if (0 >= tmp) continue;
1318 g_proc_list = g_list_append(g_proc_list, GINT_TO_POINTER(tmp));
1320 } while (NULL != dirp);
1326 static void __vcd_cleanup_client(vcd_client_type_e type)
1328 int* client_list = NULL;
1329 int client_count = 0;
1336 if (VCD_CLIENT_TYPE_NORMAL == type) {
1337 ret = vcd_client_get_list(&client_list, &client_count);
1338 } else if (VCD_CLIENT_TYPE_WIDGET == type) {
1339 ret = vcd_client_widget_get_list(&client_list, &client_count);
1340 } else if (VCD_CLIENT_TYPE_MANAGER == type) {
1341 mgr_pid = vcd_client_manager_get_pid();
1342 client_list = &mgr_pid;
1344 if (-1 == mgr_pid) {
1345 SLOG(LOG_WARN, TAG_VCD, "[WARNING] Invalid Manager pid");
1350 if (0 == ret || mgr_pid > 0) {
1351 SLOG(LOG_DEBUG, TAG_VCD, "@@@ Clean up %s client ", type ? (type == 1) ? "Widget" : "Manager" : "Normal");
1352 if (NULL != client_list && client_count > 0) {
1353 for (i = 0; i < client_count; i++) {
1356 for (j = 0; j < g_list_length(g_proc_list); j++) {
1357 iter = g_list_nth(g_proc_list, j);
1359 if (*(client_list + i) == GPOINTER_TO_INT(iter->data)) {
1360 SLOG(LOG_DEBUG, TAG_VCD, "%s pid(%d) is running", type ? (type == 1) ? "Widget" : "Manager" : "Normal", *(client_list + i));
1367 if (false == exist) {
1368 SLOG(LOG_ERROR, TAG_VCD, "%s pid(%d) should be removed", type ? (type == 1) ? "Widget" : "Manager" : "Normal", *(client_list + i));
1369 if (VCD_CLIENT_TYPE_NORMAL == type)
1370 vcd_server_finalize(*(client_list + i));
1371 else if (VCD_CLIENT_TYPE_WIDGET == type)
1372 vcd_server_widget_finalize(*(client_list + i));
1374 vcd_server_mgr_finalize(mgr_pid);
1378 SLOG(LOG_DEBUG, TAG_VCD, "@@@");
1380 if (NULL != client_list && -1 == mgr_pid) {
1387 Eina_Bool vcd_cleanup_client_all(void *data)
1391 __vcd_cleanup_client(VCD_CLIENT_TYPE_NORMAL);
1392 __vcd_cleanup_client(VCD_CLIENT_TYPE_WIDGET);
1393 __vcd_cleanup_client(VCD_CLIENT_TYPE_MANAGER);
1396 if (0 == vcd_client_get_list(&client_list, &client_count)) {
1397 SLOG(LOG_DEBUG, TAG_VCD, "@@@ Clean up client ");
1398 if (NULL != client_list && client_count > 0) {
1399 for (i = 0; i < client_count; i++) {
1402 for (j = 0; j < g_list_length(g_proc_list); j++) {
1403 iter = g_list_nth(g_proc_list, j);
1405 if (client_list[i] == GPOINTER_TO_INT(iter->data)) {
1406 SLOG(LOG_DEBUG, TAG_VCD, "pid(%d) is running", client_list[i]);
1413 if (false == exist) {
1414 SLOG(LOG_ERROR, TAG_VCD, "pid(%d) should be removed", client_list[i]);
1415 vcd_server_finalize(client_list[i]);
1418 result = vcdc_send_hello(client_list[i], VCD_CLIENT_TYPE_NORMAL);
1421 SLOG(LOG_DEBUG, TAG_VCD, "[Server] pid(%d) should be removed.", client_list[i]);
1422 vcd_server_finalize(client_list[i]);
1423 } else if (-1 == result) {
1424 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Hello result has error");
1429 SLOG(LOG_DEBUG, TAG_VCD, "@@@");
1431 if (NULL != client_list) {
1436 /* If app is in background state, app cannot response message. */
1437 if (0 == vcd_client_widget_get_list(&client_list, &client_count)) {
1438 SLOG(LOG_DEBUG, TAG_VCD, "@@@ Clean up widget");
1439 if (NULL != client_list && client_count > 0) {
1440 for (i = 0; i < client_count; i++) {
1443 for (j = 0; j < g_list_length(g_proc_list); j++) {
1444 iter = g_list_nth(g_proc_list, j);
1446 if (client_list[i] == GPOINTER_TO_INT(iter->data)) {
1447 SLOG(LOG_DEBUG, TAG_VCD, "widget pid(%d) is running", client_list[i]);
1454 if (false == exist) {
1455 SLOG(LOG_ERROR, TAG_VCD, "widget pid(%d) should be removed", client_list[i]);
1456 vcd_server_widget_finalize(client_list[i]);
1459 result = vcdc_send_hello(client_list[i], VCD_CLIENT_TYPE_WIDGET);
1462 SLOG(LOG_DEBUG, TAG_VCD, "[Server] widget pid(%d) should be removed.", client_list[i]);
1463 vcd_server_widget_finalize(client_list[i]);
1464 } else if (-1 == result) {
1465 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Hello result has error");
1470 SLOG(LOG_DEBUG, TAG_VCD, "@@@");
1473 if (NULL != client_list) {
1481 int mgr_pid = vcd_client_manager_get_pid();
1483 for (j = 0; j < g_list_length(g_proc_list); j++) {
1484 iter = g_list_nth(g_proc_list, j);
1486 if (mgr_pid == GPOINTER_TO_INT(iter->data)) {
1487 SLOG(LOG_DEBUG, TAG_VCD, "manager pid(%d) is running", mgr_pid);
1494 if (false == exist) {
1495 SLOG(LOG_ERROR, TAG_VCD, "manager pid (%d) should be removed", mgr_pid);
1496 vcd_server_mgr_finalize(mgr_pid);
1503 int vcd_server_get_service_state()
1505 return vcd_config_get_service_state();
1508 int vcd_server_get_foreground()
1511 vcd_config_get_foreground(&pid);
1519 int vcd_server_mgr_initialize(int pid)
1521 /* check if pid is valid */
1522 if (false == vcd_client_manager_is_valid(pid)) {
1523 SLOG(LOG_ERROR, TAG_VCD, "[Server] old manager pid(%d) be removed", vcd_client_manager_get_pid());
1524 vcd_server_mgr_cancel();
1525 vcd_client_manager_unset();
1528 /* Add client information to client manager */
1529 if (0 != vcd_client_manager_set(pid)) {
1530 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to add manager");
1531 return VCD_ERROR_OPERATION_FAILED;
1534 if (0 != vcdc_send_manager_pid(pid))
1535 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Fail to send manager pid");
1537 SLOG(LOG_ERROR, TAG_VCD, "[Server Success] Manager initialize : pid(%d)", pid);
1539 return VCD_ERROR_NONE;
1542 int vcd_server_mgr_finalize(int pid)
1544 /* check if pid is valid */
1545 if (false == vcd_client_manager_is_valid(pid)) {
1546 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] The manager pid(%d) is NOT valid", pid);
1547 return VCD_ERROR_INVALID_PARAMETER;
1550 /* Cancel recognition */
1551 vcd_server_mgr_cancel();
1553 if (0 != vcdc_send_manager_pid(-1))
1554 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Fail to send manager pid");
1556 /* Remove manager information */
1557 if (0 != vcd_client_manager_unset()) {
1558 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Fail to delete client");
1561 if (0 == vcd_client_get_ref_count()) {
1562 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Connected client list is empty");
1563 ecore_timer_add(0, __finalize_quit_ecore_loop, NULL);
1566 SLOG(LOG_ERROR, TAG_VCD, "[Server Success] Manager Finalize : pid(%d)", pid);
1568 return VCD_ERROR_NONE;
1571 int vcd_server_mgr_set_command(int pid)
1573 if (0 != vcd_client_manager_set_command(pid)) {
1574 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] The manager pid(%d) is NOT valid", pid);
1575 return VCD_ERROR_INVALID_PARAMETER;
1577 return VCD_ERROR_NONE;
1580 int vcd_server_mgr_unset_command(int pid)
1582 if (0 != vcd_client_manager_unset_command(pid)) {
1583 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] The manager pid(%d) is NOT valid", pid);
1584 return VCD_ERROR_INVALID_PARAMETER;
1586 return VCD_ERROR_NONE;
1589 int vcd_server_mgr_set_demandable_client(int pid)
1591 /* check if pid is valid */
1592 if (false == vcd_client_manager_is_valid(pid)) {
1593 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] The manager pid(%d) is NOT valid", pid);
1594 return VCD_ERROR_INVALID_PARAMETER;
1597 GSList* client_list = NULL;
1598 if (0 != vc_info_parser_get_demandable_clients(&client_list)) {
1599 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to get demandable client");
1600 return VCD_ERROR_OPERATION_FAILED;
1603 /* Save client list */
1604 if (0 != vcd_client_manager_set_demandable_client(pid, client_list)) {
1605 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to set demandable client list");
1606 return VCD_ERROR_OPERATION_FAILED;
1609 return VCD_ERROR_NONE;
1612 int vcd_server_mgr_set_audio_type(int pid, const char* audio_type)
1614 /* check if pid is valid */
1615 if (false == vcd_client_manager_is_valid(pid)) {
1616 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] The manager pid(%d) is NOT valid", pid);
1617 return VCD_ERROR_INVALID_PARAMETER;
1621 vce_audio_type_e type = VCE_AUDIO_TYPE_PCM_S16_LE;
1625 ret = vcd_engine_get_audio_format(audio_type, &type, &rate, &channel);
1627 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to get audio format : %d", ret);
1628 return VCD_ERROR_OPERATION_FAILED;
1631 ret = vcd_recorder_set(audio_type, type, rate, channel);
1633 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to set audio in type : %d", ret);
1634 return VCD_ERROR_OPERATION_FAILED;
1637 return VCD_ERROR_NONE;
1640 int vcd_server_mgr_get_audio_type(int pid, char** audio_type)
1642 /* check if pid is valid */
1643 if (false == vcd_client_manager_is_valid(pid)) {
1644 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] The manager pid(%d) is NOT valid", pid);
1645 return VCD_ERROR_INVALID_PARAMETER;
1648 int ret = vcd_recorder_get(audio_type);
1650 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to get audio in type : %d", ret);
1651 return VCD_ERROR_OPERATION_FAILED;
1654 return VCD_ERROR_NONE;
1657 int vcd_server_mgr_set_client_info(int pid)
1659 /* check if pid is valid */
1660 if (false == vcd_client_manager_is_valid(pid)) {
1661 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] The manager pid(%d) is NOT valid", pid);
1662 return VCD_ERROR_INVALID_PARAMETER;
1665 int ret = vcd_client_save_client_info();
1667 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to save client info : %d", ret);
1668 return VCD_ERROR_OPERATION_FAILED;
1671 return VCD_ERROR_NONE;
1674 static int __reset_waiting_for_widget_recording(void)
1676 SLOG(LOG_ERROR, TAG_VCD, "[Server] Reset waiting for widget recording");
1677 // Delete timer to check that widget client is terminated
1678 if (g_check_widget_client_timer) {
1679 ecore_timer_del(g_check_widget_client_timer);
1680 g_check_widget_client_timer = NULL;
1682 // Reset flag to wait for recording from widget client
1683 vcd_client_widget_set_waiting_for_recording(-1, false);
1688 static Eina_Bool __send_waiting_timeout_error_to_manager(void* data)
1690 intptr_t ppid = (intptr_t)data;
1691 int pid = (int)ppid;
1692 SLOG(LOG_ERROR, TAG_VCD, "Widget client didn't send to start recording, pid(%d)", pid);
1693 __reset_waiting_for_widget_recording();
1695 vcdc_send_error_signal_to_manager(vcd_client_manager_get_pid(), VCD_ERROR_OPERATION_FAILED, "voice_engine.error.proc_fail");
1699 static Eina_Bool __send_waiting_timeout_start_recording(void* data)
1701 intptr_t ppid = (intptr_t)data;
1702 int pid = (int)ppid;
1703 SLOG(LOG_ERROR, TAG_VCD, "Widget client didn't send to start recording, pid(%d)", pid);
1705 int ret = __start_internal_recognition();
1707 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to start recognition : %d", ret);
1714 static int __set_waiting_for_widget_recording(int pid)
1716 SLOG(LOG_ERROR, TAG_VCD, "[Server] Set waiting for widget recording, pid(%d)", pid);
1718 // Check if the app included widget client is terminated or not. If it is terminated, vcd_server_widget_finalize() function will be called
1719 // In that function, it will start recording
1720 intptr_t ppid = (intptr_t)pid;
1721 g_check_widget_client_timer = ecore_timer_add(2.0, __send_waiting_timeout_start_recording, (void*)ppid);
1723 // Set flag to wait for recording from widget client
1724 vcd_client_widget_set_waiting_for_recording(pid, true);
1728 static int __start_internal_recognition()
1731 __reset_waiting_for_widget_recording();
1733 if (0 != vcd_client_command_collect_command()) {
1734 SLOG(LOG_ERROR, TAG_VCD, "[Client Data ERROR] Fail to collect command");
1735 /* Send error cb to manager */
1736 int pid = vcd_client_widget_get_foreground_pid();
1738 vcdc_send_error_signal_to_manager(vcd_client_manager_get_pid(), VCD_ERROR_OPERATION_FAILED, "voice_engine.error.proc_fail");
1739 return VCD_ERROR_OPERATION_FAILED;
1742 /* 3. Set command to engine */
1743 ret = vcd_engine_set_commands();
1745 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to set commands : %d", ret);
1746 /* Send error cb to manager */
1747 int pid = vcd_client_widget_get_foreground_pid();
1749 vcdc_send_error_signal_to_manager(vcd_client_manager_get_pid(), VCD_ERROR_OPERATION_FAILED, "voice_engine.error.proc_fail");
1750 return VCD_ERROR_OPERATION_FAILED;
1753 SLOG(LOG_ERROR, TAG_VCD, "[Server Success] Set command");
1755 bool stop_by_silence = true;
1756 if (VCD_RECOGNITION_MODE_MANUAL == vcd_client_get_recognition_mode()) {
1757 stop_by_silence = false;
1760 vcd_client_manager_set_result_text(NULL);
1762 /* 4. start recognition */
1763 ret = vcd_engine_recognize_start(stop_by_silence);
1765 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to start recognition : result(%d)", ret);
1766 /* Send error cb to manager */
1767 int pid = vcd_client_widget_get_foreground_pid();
1769 vcdc_send_error_signal_to_manager(vcd_client_manager_get_pid(), VCD_ERROR_OPERATION_FAILED, "voice_engine.error.proc_fail");
1770 return VCD_ERROR_OPERATION_FAILED;
1773 SLOG(LOG_ERROR, TAG_VCD, "[Server Success] Start engine");
1776 /* 5. recorder start */
1777 ret = vcd_recorder_start();
1779 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to start recorder : result(%d)", ret);
1780 vcd_engine_recognize_cancel();
1781 /* Send error cb to manager */
1782 int pid = vcd_client_widget_get_foreground_pid();
1784 vcdc_send_error_signal_to_manager(vcd_client_manager_get_pid(), VCD_ERROR_OPERATION_FAILED, "voice_engine.error.proc_fail");
1789 vcd_config_set_service_state(VCD_STATE_RECORDING);
1790 vcdc_send_service_state(VCD_STATE_RECORDING);
1792 SLOG(LOG_ERROR, TAG_VCD, "[Server Success] Start recognition(%d)", stop_by_silence);
1797 static Eina_Bool __vcd_request_show_tooltip(void *data)
1799 int pid = vcd_client_widget_get_foreground_pid();
1801 SLOG(LOG_ERROR, TAG_VCD, "[Server] Request tooltip show and widget command, show(%d)", (bool)data);
1802 vcdc_send_show_tooltip(pid, (bool)data);
1808 int vcd_server_mgr_start(vcd_recognition_mode_e recognition_mode, bool exclusive_cmd, bool start_by_client)
1810 /* 1. check current state */
1811 vcd_state_e state = vcd_config_get_service_state();
1813 if (VCD_STATE_READY != state) {
1814 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Current state is not ready");
1815 return VCD_ERROR_INVALID_STATE;
1817 if (-1 == vcd_client_manager_get_pid()) {
1818 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Manager is NOT available.");
1819 return VCD_ERROR_OPERATION_FAILED;
1821 __reset_waiting_for_widget_recording();
1823 SLOG(LOG_ERROR, TAG_VCD, "[Server] set recognition mode = %d", recognition_mode);
1824 vcd_client_set_recognition_mode(recognition_mode);
1826 if (false == exclusive_cmd) {
1827 vcd_client_update_foreground_pid();
1828 /* Notify show tooltip */
1829 if (1 == vcd_config_get_command_type_enabled(VC_COMMAND_TYPE_WIDGET)) {
1830 int pid = vcd_client_widget_get_foreground_pid();
1832 SLOG(LOG_ERROR, TAG_VCD, "[Server] Request tooltip show and widget command");
1833 ecore_timer_add(0, __vcd_request_show_tooltip, (void*)true);
1835 __set_waiting_for_widget_recording(pid);
1840 vcd_client_manager_set_exclusive(exclusive_cmd);
1844 if (true == start_by_client) {
1845 /* Get foreground pid */
1846 if (0 != vcd_config_get_foreground(&fg_pid)) {
1847 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to get foreground");
1850 /* Set client exclusive option */
1851 if (0 != vcd_client_set_exclusive_command(fg_pid)) {
1852 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to set exclusive command");
1856 SLOG(LOG_ERROR, TAG_VCD, "[Server] start internal recognition");
1858 int ret = __start_internal_recognition();
1860 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to start recognition : %d", ret);
1864 if (true == start_by_client) {
1865 vcd_client_unset_exclusive_command(fg_pid);
1868 SLOG(LOG_ERROR, TAG_VCD, "[Server Success] start internal recognition");
1869 return VCD_ERROR_NONE;
1872 int vcd_server_mgr_stop()
1874 /* 1. Check current state is recording */
1875 if (VCD_STATE_RECORDING != vcd_config_get_service_state()) {
1876 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Current state is not recording");
1877 return VCD_ERROR_INVALID_STATE;
1879 if (-1 == vcd_client_manager_get_pid()) {
1880 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Manager is NOT available.");
1881 return VCD_ERROR_OPERATION_FAILED;
1883 SLOG(LOG_ERROR, TAG_VCD, "[Server] stop internal recognition");
1886 /* 2. Stop recorder */
1887 vcd_recorder_stop();
1890 /* 3. Stop engine recognition */
1891 int ret = vcd_engine_recognize_stop();
1893 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to stop recognition : %d", ret);
1896 /* 4. Set original mode */
1897 vcd_config_set_service_state(VCD_STATE_PROCESSING);
1898 vcdc_send_service_state(VCD_STATE_PROCESSING);
1900 SLOG(LOG_ERROR, TAG_VCD, "[Server Success] stop internal recognition");
1901 return VCD_ERROR_NONE;
1904 int vcd_server_mgr_cancel()
1906 if (-1 == vcd_client_manager_get_pid()) {
1907 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Manager is NOT available.");
1908 return VCD_ERROR_OPERATION_FAILED;
1911 if (g_restart_timer != NULL) {
1912 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Delete restart engine timer");
1913 ecore_timer_del(g_restart_timer);
1914 g_restart_timer = NULL;
1917 /* 1. Check current state */
1918 vcd_state_e state = vcd_config_get_service_state();
1919 if (VCD_STATE_READY == state) {
1920 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Current state is READY");
1921 vcd_recorder_stop();
1923 if (false == vcd_client_manager_get_exclusive()) {
1924 if (1 == vcd_config_get_command_type_enabled(VC_COMMAND_TYPE_WIDGET)) {
1925 int pid = vcd_client_widget_get_foreground_pid();
1927 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Request tooltip hide");
1928 ecore_timer_add(0, __vcd_request_show_tooltip, (void*)false);
1933 vcdc_send_service_state(VCD_STATE_READY);
1934 return VCD_ERROR_NONE;
1936 SLOG(LOG_ERROR, TAG_VCD, "[Server] cancel internal recognition");
1939 /* 2. Stop recorder */
1940 vcd_recorder_stop();
1943 /* 3. Cancel engine */
1944 int ret = vcd_engine_recognize_cancel();
1946 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Fail to cancel : %d", ret);
1949 if (false == vcd_client_manager_get_exclusive()) {
1950 if (1 == vcd_config_get_command_type_enabled(VC_COMMAND_TYPE_WIDGET)) {
1951 int pid = vcd_client_widget_get_foreground_pid();
1953 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Request tooltip hide");
1954 ecore_timer_add(0, __vcd_request_show_tooltip, (void*)false);
1958 vcd_client_manager_set_exclusive(false);
1962 vcd_config_set_service_state(VCD_STATE_READY);
1963 vcdc_send_service_state(VCD_STATE_READY);
1965 SLOG(LOG_ERROR, TAG_VCD, "[Server Success] cancel internal recognition");
1966 return VCD_ERROR_NONE;
1970 int vcd_server_mgr_result_select()
1972 __vcd_send_selected_result(NULL);
1974 return VCD_ERROR_NONE;
1977 int vcd_server_mgr_set_domain(int pid, const char* domain)
1979 /* check if pid is valid */
1980 if (false == vcd_client_manager_is_valid(pid)) {
1981 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] The manager pid(%d) is NOT valid", pid);
1982 return VCD_ERROR_INVALID_PARAMETER;
1985 vcd_state_e state = vcd_config_get_service_state();
1986 if (VCD_STATE_READY != state) {
1987 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Current state is not ready");
1988 return VCD_ERROR_INVALID_STATE;
1991 /* Set domain to engine */
1992 int ret = vcd_engine_set_domain(pid, domain);
1994 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to set domain : %d", ret);
1996 SLOG(LOG_DEBUG, TAG_VCD, "[Server SUCCESS] Set domain");
2002 int vcd_server_mgr_set_private_data(int pid, const char* key, const char* data)
2004 /* check if pid is valid */
2005 if (false == vcd_client_manager_is_valid(pid)) {
2006 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] The manager pid(%d) is NOT valid", pid);
2007 return VCD_ERROR_INVALID_PARAMETER;
2010 vcd_state_e state = vcd_config_get_service_state();
2011 if (VCD_STATE_READY != state) {
2012 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Current state is not ready");
2013 return VCD_ERROR_INVALID_STATE;
2016 /* Set private data to engine */
2017 int ret = vcd_engine_set_private_data(pid, key, data);
2019 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to set private data : %d", ret);
2021 SLOG(LOG_DEBUG, TAG_VCD, "[Server SUCCESS] Set private data");
2027 int vcd_server_mgr_get_private_data(int pid, const char* key, char** data)
2029 /* check if pid is valid */
2030 if (false == vcd_client_manager_is_valid(pid)) {
2031 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] The manager pid(%d) is NOT valid", pid);
2032 return VCD_ERROR_INVALID_PARAMETER;
2034 vcd_state_e state = vcd_config_get_service_state();
2035 if (VCD_STATE_READY != state) {
2036 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Current state is not ready");
2037 return VCD_ERROR_INVALID_STATE;
2040 /* Get private data to engine */
2041 int ret = vcd_engine_get_private_data(pid, key, data);
2043 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to get private data : %d", ret);
2045 SLOG(LOG_DEBUG, TAG_VCD, "[Server SUCCESS] Set private data");
2051 int vcd_server_mgr_send_specific_engine_request(int pid, const char* engine_app_id, const char* event, const char* request)
2053 /* check if pid is valid */
2054 if (false == vcd_client_manager_is_valid(pid)) {
2055 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] The manager pid(%d) is NOT valid", pid);
2056 return VCD_ERROR_INVALID_PARAMETER;
2058 vcd_state_e state = vcd_config_get_service_state();
2059 if (VCD_STATE_READY != state) {
2060 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Current state is not ready");
2061 return VCD_ERROR_INVALID_STATE;
2064 /* Get private data to engine */
2065 int ret = vcd_engine_send_specific_engine_request(engine_app_id, event, request);
2067 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to set specific engine request : %d", ret);
2069 SLOG(LOG_DEBUG, TAG_VCD, "[Server SUCCESS] Set specific engine request ");
2075 int vcd_server_mgr_do_action(int pid, int type, const char* action)
2079 /* check if pid is valid */
2080 if (false == vcd_client_manager_is_valid(pid)) {
2081 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] The manager pid(%d) is NOT valid", pid);
2082 return VCD_ERROR_INVALID_PARAMETER;
2085 vcd_state_e state = vcd_config_get_service_state();
2086 if (VCD_STATE_READY != state) {
2087 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Current state is not ready");
2088 return VCD_ERROR_INVALID_STATE;
2091 /* Request do action to engine */
2092 if (VCD_SEND_EVENT_TYPE_TEXT == type)
2093 ret = vcd_engine_process_text(pid, action);
2094 else if (VCD_SEND_EVENT_TYPE_LIST_EVENT == type)
2095 ret = vcd_engine_process_list_event(pid, action);
2096 else if (VCD_SEND_EVENT_TYPE_HAPTIC_EVENT == type)
2097 ret = vcd_engine_process_haptic_event(pid, action);
2100 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to process do action : %d", ret);
2102 vcd_config_set_service_state(VCD_STATE_PROCESSING);
2103 vcdc_send_service_state(VCD_STATE_PROCESSING);
2104 SLOG(LOG_DEBUG, TAG_VCD, "[Server SUCCESS] Process do action");
2110 int vcd_server_mgr_enable_command_type(int pid, int cmd_type)
2114 /* check if pid is valid */
2115 if (false == vcd_client_manager_is_valid(pid)) {
2116 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] The manager pid(%d) is NOT valid", pid);
2117 return VCD_ERROR_INVALID_PARAMETER;
2120 vcd_state_e state = vcd_config_get_service_state();
2121 if (VCD_STATE_READY != state) {
2122 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Current state is not ready");
2123 return VCD_ERROR_INVALID_STATE;
2126 ret = vcd_config_enable_command_type(cmd_type);
2128 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to enable command type");
2130 SLOG(LOG_ERROR, TAG_VCD, "[Server] Enable command type(%d)", cmd_type);
2136 int vcd_server_mgr_disable_command_type(int pid, int cmd_type)
2140 /* check if pid is valid */
2141 if (false == vcd_client_manager_is_valid(pid)) {
2142 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] The manager pid(%d) is NOT valid", pid);
2143 return VCD_ERROR_INVALID_PARAMETER;
2146 vcd_state_e state = vcd_config_get_service_state();
2147 if (VCD_STATE_READY != state) {
2148 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Current state is not ready");
2149 return VCD_ERROR_INVALID_STATE;
2152 ret = vcd_config_disable_command_type(cmd_type);
2154 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to disable command type");
2156 SLOG(LOG_ERROR, TAG_VCD, "[Server] Disable command type(%d)", cmd_type);
2162 /* for TTS feedback */
2163 int vcd_server_mgr_start_feedback(void)
2165 /* check current state */
2166 /* not Recording??? */
2168 if (-1 == vcd_client_manager_get_pid()) {
2169 SLOG(LOG_ERROR, TAG_VCD, "[Server] Manager is NOT available");
2170 return VCD_ERROR_OPERATION_FAILED;
2173 SLOG(LOG_DEBUG, TAG_VCD, "[Server] start TTS feedback");
2175 /* check there is TTS buffer to be spoken */
2177 return VCD_ERROR_NONE;
2180 int vcd_server_mgr_stop_feedback(void)
2182 /* check current state */
2183 /* not Recording??? */
2185 if (-1 == vcd_client_manager_get_pid()) {
2186 SLOG(LOG_ERROR, TAG_VCD, "[Server] Manager is NOT available");
2187 return VCD_ERROR_OPERATION_FAILED;
2190 SLOG(LOG_DEBUG, TAG_VCD, "[Server] stop TTS feedback");
2192 return VCD_ERROR_NONE;
2197 * VC Server Functions for Client
2199 int vcd_server_initialize(int pid)
2201 if (false == vcd_engine_is_available_engine()) {
2202 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] No Engine");
2203 return VCD_ERROR_ENGINE_NOT_FOUND;
2206 /* check if pid is valid */
2207 if (true == vcd_client_is_available(pid)) {
2208 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] The pid is already exist");
2209 return VCD_ERROR_NONE;
2212 /* Add client information to client manager */
2213 if (0 != vcd_client_add(pid)) {
2214 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to add client info");
2215 return VCD_ERROR_OPERATION_FAILED;
2218 SLOG(LOG_DEBUG, TAG_VCD, "[Server Success] Client Initialize : pid(%d)", pid);
2220 return VCD_ERROR_NONE;
2223 int vcd_server_finalize(int pid)
2225 /* check if pid is valid */
2226 if (false == vcd_client_is_available(pid)) {
2227 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] pid is NOT valid ");
2228 return VCD_ERROR_INVALID_PARAMETER;
2231 /* Remove client information */
2232 if (0 != vcd_client_delete(pid)) {
2233 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Fail to delete client");
2236 if (0 == vcd_client_get_ref_count()) {
2237 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Connected client list is empty");
2238 ecore_timer_add(0, __finalize_quit_ecore_loop, NULL);
2241 SLOG(LOG_DEBUG, TAG_VCD, "[Server Success] Client Finalize : pid(%d)", pid);
2243 return VCD_ERROR_NONE;
2246 int vcd_server_set_command(int pid, vc_cmd_type_e cmd_type)
2248 /* check if pid is valid */
2249 if (false == vcd_client_is_available(pid)) {
2250 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] pid is NOT valid ");
2251 return VCD_ERROR_INVALID_PARAMETER;
2254 if (0 != vcd_client_set_command_type(pid, cmd_type)) {
2255 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to set command type : pid(%d), cmd_type(%d)", pid, cmd_type);
2256 return VCD_ERROR_OPERATION_FAILED;
2262 int vcd_server_unset_command(int pid, vc_cmd_type_e cmd_type)
2264 /* check if pid is valid */
2265 if (false == vcd_client_is_available(pid)) {
2266 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] pid is NOT valid ");
2267 return VCD_ERROR_INVALID_PARAMETER;
2270 if (0 != vcd_client_unset_command_type(pid, cmd_type)) {
2271 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to unset command type : pid(%d), cmd_type(%d)", pid, cmd_type);
2272 return VCD_ERROR_OPERATION_FAILED;
2278 int vcd_server_set_foreground(int pid, bool value)
2280 /* check if pid is valid */
2281 if (false == vcd_client_is_available(pid) && false == vcd_client_widget_is_available(pid)) {
2282 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] pid is NOT valid ");
2283 return VCD_ERROR_INVALID_PARAMETER;
2286 if (0 != vcd_config_set_foreground(pid, value)) {
2287 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to set foreground : pid(%d), value(%d)", pid, value);
2288 return VCD_ERROR_OPERATION_FAILED;
2294 static int __vcd_server_launch_manager_app()
2297 bool running = false;
2300 ret = vcd_client_manager_get_appid(&appid);
2301 if (0 != ret || NULL == appid) {
2302 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to get manager appid");
2303 return VCD_ERROR_OPERATION_FAILED;
2305 ret = app_manager_is_running(appid, &running);
2307 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to check running with appid(%s)", appid);
2310 return VCD_ERROR_OPERATION_FAILED;
2312 if (false == running) {
2313 int tmp_ret = __vcd_is_package_installed(appid);
2314 if (false == tmp_ret) {
2315 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] manager app is not installed, appid(%s)", appid);
2317 ret = __vcd_activate_app_by_appcontrol(appid);
2319 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to activate app");
2324 SLOG(LOG_ERROR, TAG_VCD, "Launch vc manager app: appid(%s)", appid);
2327 ret = __vcd_resume_app(appid);
2329 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to resume app");
2334 SLOG(LOG_ERROR, TAG_VCD, "Resume vc manager app: appid(%s)", appid);
2340 return VCD_ERROR_NONE;
2343 int vcd_server_set_server_dialog(int pid, const char* app_id, const char* credential)
2345 /* check if pid is valid */
2346 if (false == vcd_client_is_available(pid)) {
2347 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] pid is NOT valid ");
2348 return VCD_ERROR_INVALID_PARAMETER;
2351 int ret = vcd_engine_set_server_dialog(app_id, credential);
2353 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to set server dialog, pid(%d), app_id(%s), ret(%d)", pid, app_id, ret);
2354 vcd_client_set_server_dialog(pid, false);
2357 SLOG(LOG_ERROR, TAG_VCD, "[Success] Set server dialog, pid(%d), app_id(%s)", pid, app_id);
2359 if (0 != strncmp(credential, "#NULL", strlen(credential))) {
2360 ret = vcd_client_set_server_dialog(pid, true);
2362 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Set to true for server dialog, app_id(%s)", app_id);
2364 ret = vcd_client_set_server_dialog(pid, false);
2366 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Set to false for server dialog, app_id(%s)", app_id);
2372 int vcd_server_dialog(int pid, const char* disp_text, const char* utt_text, int continuous)
2374 /* check if pid is valid */
2375 if (false == vcd_client_is_available(pid) && false == vcd_client_widget_is_available(pid)) {
2376 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] pid is NOT valid ");
2377 return VCD_ERROR_INVALID_PARAMETER;
2380 bool is_server_dialog = false;
2381 int ret = vcd_client_get_server_dialog(pid, &is_server_dialog);
2383 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to get server dialog, pid(%d), ret(%d)", pid, ret);
2386 if (true == is_server_dialog) {
2387 /* ++ Request tts event to engine */
2389 /* -- Request tts event to engine */
2391 ret = __vcd_server_launch_manager_app();
2393 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);
2397 ret = vcdc_send_dialog(vcd_client_manager_get_pid(), pid, disp_text, utt_text, continuous);
2399 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);
2406 int vcd_server_is_system_command_valid(int pid, int* is_sys_cmd_valid)
2408 /* check if pid is valid */
2409 if (false == vcd_client_is_available(pid) && false == vcd_client_widget_is_available(pid)) {
2410 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] pid is NOT valid ");
2411 return VCD_ERROR_INVALID_PARAMETER;
2414 /* check if system command is valid */
2415 if (true == vcd_client_manager_is_system_command_valid(vcd_client_manager_get_pid()))
2416 *is_sys_cmd_valid = true;
2418 *is_sys_cmd_valid = false;
2424 int vcd_server_set_exclusive_command(int pid, bool value)
2426 /* check if pid is valid */
2427 if (false == vcd_client_is_available(pid)) {
2428 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] pid is NOT valid ");
2429 return VCD_ERROR_INVALID_PARAMETER;
2432 if (true == value) {
2433 if (0 != vcd_client_set_exclusive_command(pid)) {
2434 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to set exclusive command : pid(%d)", pid);
2435 return VCD_ERROR_OPERATION_FAILED;
2438 if (0 != vcd_client_unset_exclusive_command(pid)) {
2439 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to unset exclusive command : pid(%d)", pid);
2440 return VCD_ERROR_OPERATION_FAILED;
2447 int vcd_server_request_start(int pid, bool stop_by_silence)
2449 /* check if pid is valid */
2450 if (false == vcd_client_is_available(pid)) {
2451 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] pid(%d) is NOT foreground client", pid);
2452 return VCD_ERROR_INVALID_PARAMETER;
2456 /* Check current state */
2457 vcd_state_e state = vcd_config_get_service_state();
2459 /* Service state should be ready */
2460 if (VCD_STATE_READY != state) {
2461 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Current state is not Ready : pid(%d)", pid);
2462 return VCD_ERROR_INVALID_STATE;
2465 if (-1 != vcd_client_manager_get_pid()) {
2466 /* Check current pid is valid */
2467 if (false == vcd_client_manager_check_demandable_client(pid)) {
2468 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Current client is NOT available : pid(%d)", pid);
2469 return VCD_ERROR_INVALID_PARAMETER;
2473 ret = vcd_server_mgr_start(stop_by_silence, false);
2475 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Fail to start recognition");
2476 return VCD_ERROR_INVALID_PARAMETER;
2482 int vcd_server_request_stop(int pid)
2485 /* Check current state */
2486 vcd_state_e state = vcd_config_get_service_state();
2488 /* Service state should be ready */
2489 if (VCD_STATE_RECORDING != state) {
2490 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Current state is not Recording : pid(%d)", pid);
2491 return VCD_ERROR_INVALID_STATE;
2494 if (-1 != vcd_client_manager_get_pid()) {
2495 /* Check current pid is valid */
2496 if (false == vcd_client_manager_check_demandable_client(pid)) {
2497 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Current client is NOT available : pid(%d)", pid);
2498 return VCD_ERROR_INVALID_PARAMETER;
2502 ret = vcd_server_mgr_stop();
2504 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Fail to start recognition");
2505 return VCD_ERROR_OPERATION_FAILED;
2508 return VCD_ERROR_NONE;
2511 int vcd_server_request_cancel(int pid)
2514 /* Check current state */
2515 vcd_state_e state = vcd_config_get_service_state();
2517 /* Service state should be recording or processing */
2518 if (VCD_STATE_RECORDING != state && VCD_STATE_PROCESSING != state) {
2519 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Current state is not Recording or Processing : pid(%d)", pid);
2520 return VCD_ERROR_INVALID_STATE;
2523 if (-1 != vcd_client_manager_get_pid()) {
2524 /* Check current pid is valid */
2525 if (false == vcd_client_manager_check_demandable_client(pid)) {
2526 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Current client is NOT available : pid(%d)", pid);
2527 return VCD_ERROR_INVALID_PARAMETER;
2531 ret = vcd_server_mgr_cancel();
2533 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Fail to start recognition");
2534 return VCD_ERROR_OPERATION_FAILED;
2537 return VCD_ERROR_NONE;
2542 * VC Server Functions for Widget lib
2544 int vcd_server_widget_initialize(int pid)
2546 if (false == vcd_engine_is_available_engine()) {
2547 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] No Engine");
2548 return VCD_ERROR_ENGINE_NOT_FOUND;
2551 /* check if pid is valid */
2552 if (true == vcd_client_widget_is_available(pid)) {
2553 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] The pid is already exist");
2554 return VCD_ERROR_NONE;
2557 /* Add client information to client manager */
2558 if (0 != vcd_client_widget_add(pid)) {
2559 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to add client info");
2560 return VCD_ERROR_OPERATION_FAILED;
2563 SLOG(LOG_DEBUG, TAG_VCD, "[Server Success] Initialize widget : pid(%d)", pid);
2565 return VCD_ERROR_NONE;
2568 static void __vcd_server_widget_start_recording(void *data)
2570 SLOG(LOG_ERROR, TAG_VCD, "[Server INFO] start recording");
2572 if (0 != __start_internal_recognition()) {
2573 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to start recognition");
2577 int vcd_server_widget_finalize(int pid)
2579 /* check if pid is valid */
2580 if (false == vcd_client_widget_is_available(pid)) {
2581 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] pid is NOT valid ");
2582 return VCD_ERROR_INVALID_PARAMETER;
2585 /* Remove client information */
2586 if (0 != vcd_client_widget_delete(pid)) {
2587 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Fail to delete client");
2590 if (0 == vcd_client_get_ref_count()) {
2591 SLOG(LOG_ERROR, TAG_VCD, "[Server] connected client list is empty");
2592 ecore_timer_add(0, __finalize_quit_ecore_loop, NULL);
2596 bool is_waiting = false;
2597 if (0 != vcd_client_widget_get_waiting_for_recording(pid, &is_waiting)) {
2598 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Fail to get waiting to recording");
2601 if (true == is_waiting) {
2602 SLOG(LOG_ERROR, TAG_VCD, "[Server INFO] invoke to start recording");
2603 ecore_main_loop_thread_safe_call_async(__vcd_server_widget_start_recording, NULL);
2605 return VCD_ERROR_NONE;
2608 int vcd_server_widget_start_recording(int pid, bool widget_command)
2610 /* check if pid is valid */
2611 if (false == vcd_client_widget_is_available(pid)) {
2612 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] pid is NOT valid ");
2613 return VCD_ERROR_INVALID_PARAMETER;
2617 if (0 != vcd_client_widget_get_waiting_for_recording(pid, &waiting) || false == waiting) {
2618 SLOG(LOG_ERROR, TAG_VCD, "[Server] Server is not waiting for recording, pid(%d), waiting(%d)", pid, waiting);
2622 if (true == widget_command) {
2623 vcd_client_widget_set_command(pid);
2624 SLOG(LOG_DEBUG, TAG_VCD, "[Server] widget command is available");
2626 vcd_client_widget_unset_command(pid);
2627 SLOG(LOG_WARN, TAG_VCD, "[Server] widget command is NOT available");
2630 SLOG(LOG_ERROR, TAG_VCD, "[Server] start internal recognition : %d", widget_command);
2631 int ret = __start_internal_recognition();
2633 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to start recognition : %d", ret);
2634 ecore_timer_add(0, __vcd_request_show_tooltip, (void*)false);
2640 int vcd_server_widget_start(int pid, bool stop_by_silence)
2642 /* check if pid is valid */
2643 int fore_pid = vcd_client_widget_get_foreground_pid();
2644 if (pid != fore_pid) {
2645 SLOG(LOG_ERROR, TAG_VCD, "[Server] pid is NOT foreground");
2646 return VCD_ERROR_INVALID_PARAMETER;
2649 /* Check current state */
2650 vcd_state_e state = vcd_config_get_service_state();
2652 /* Service state should be ready */
2653 if (VCD_STATE_READY != state) {
2654 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Current state is not Ready : pid(%d)", pid);
2655 return VCD_ERROR_INVALID_STATE;
2658 vcd_client_set_slience_detection(stop_by_silence);
2660 /* Notify show tooltip */
2661 ecore_timer_add(0, __vcd_request_show_tooltip, (void*)true);
2666 int vcd_server_widget_stop(int pid)
2668 /* check if pid is valid */
2669 int fore_pid = vcd_client_widget_get_foreground_pid();
2670 if (pid != fore_pid) {
2671 SLOG(LOG_ERROR, TAG_VCD, "[Server] pid is NOT foreground");
2672 return VCD_ERROR_INVALID_PARAMETER;
2676 /* Check current state */
2677 vcd_state_e state = vcd_config_get_service_state();
2679 /* Service state should be recording */
2680 if (VCD_STATE_RECORDING != state) {
2681 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Current service state is not Recording : pid(%d)", pid);
2682 return VCD_ERROR_INVALID_STATE;
2685 ret = vcd_server_mgr_stop();
2687 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Fail to start recognition");
2688 return VCD_ERROR_OPERATION_FAILED;
2691 return VCD_ERROR_NONE;
2694 int vcd_server_widget_cancel(int pid)
2696 /* check if pid is valid */
2697 int fore_pid = vcd_client_widget_get_foreground_pid();
2698 if (pid != fore_pid) {
2699 SLOG(LOG_ERROR, TAG_VCD, "[Server] pid is NOT foreground");
2700 return VCD_ERROR_INVALID_PARAMETER;
2704 /* Check current state */
2705 vcd_state_e state = vcd_config_get_service_state();
2707 /* Service state should be recording or processing */
2708 if (VCD_STATE_RECORDING != state && VCD_STATE_PROCESSING != state) {
2709 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Current state is not Recording or Processing : pid(%d)", pid);
2710 return VCD_ERROR_INVALID_STATE;
2713 ret = vcd_server_mgr_cancel();
2715 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Fail to cancel recognition : %d", ret);
2719 return VCD_ERROR_NONE;
2722 int vcd_server_widget_enable_asr_result(int pid, bool enable)
2725 ret = vcd_client_widget_set_asr_result_enabled(pid, enable);
2727 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Fail to enable asr result : %d", ret);
2733 int vcd_server_set_language(const char* language)
2735 int ret = VCD_ERROR_NONE;
2737 ret = vcd_config_set_default_language(language);
2739 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Fail to set language : %d", ret);
2743 ret = vcd_engine_set_current_language(language);
2745 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Fail to set language : %d", ret);
2752 * For engine service
2754 int vcd_get_foreach_command(vce_cmd_h vce_command, vce_command_cb callback, void* user_data)
2756 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Get foreach command");
2758 if (NULL == callback) {
2759 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] input parameter is NULL");
2760 return VCD_ERROR_INVALID_PARAMETER;
2764 ret = vcd_engine_agent_get_foreach_command(vce_command, callback, user_data);
2766 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to get foreach command : ret(%d)", ret);
2772 int vcd_get_command_count(vce_cmd_h vce_command, int* count)
2774 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Get command count");
2777 ret = vcd_engine_agent_get_command_count(vce_command, count);
2779 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to get command count : ret(%d)", ret);
2785 int vcd_get_audio_type(char** audio_type)
2787 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Get audio type");
2790 ret = vcd_engine_agent_get_audio_type(audio_type);
2792 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to get audio type : ret(%d)", ret);
2798 int vcd_set_private_data(const char* key, const char* data)
2800 vcd_state_e state = vcd_config_get_service_state();
2802 if (VCD_STATE_READY != state) {
2803 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Current state(%d) is NOT 'READY'", state);
2804 return VCD_ERROR_INVALID_STATE;
2807 int ret = vcd_engine_agent_set_private_data(key, data);
2809 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to set private data to the manager client : ret(%d)", ret);
2811 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Set private data to the manager client, key(%s), data(%s)", key, data);
2817 int vcd_get_private_data(const char* key, char** data)
2819 vcd_state_e state = vcd_config_get_service_state();
2821 if (VCD_STATE_READY != state) {
2822 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Current state(%d) is NOT 'READY'", state);
2823 return VCD_ERROR_INVALID_STATE;
2826 int ret = vcd_engine_agent_get_private_data(key, data);
2828 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to get private data from the manager client : ret(%d)", ret);
2830 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Get private data from the manager client, key(%s), data(%s)", key, *data);
2836 int vcd_start_recording()
2838 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Start recording");
2841 ret = vcd_engine_agent_start_recording();
2843 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to start recording : ret(%d)", ret);
2849 int vcd_stop_recording()
2851 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Stop recording");
2854 ret = vcd_engine_agent_stop_recording();
2856 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to stop recording : ret(%d)", ret);
2862 int vcd_set_private_data_set_cb(vce_private_data_set_cb callback_func)
2864 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Set private data set cb");
2867 ret = vcd_engine_agent_set_private_data_set_cb(callback_func);
2869 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to set private data set cb : ret(%d)", ret);
2875 int vcd_set_private_data_requested_cb(vce_private_data_requested_cb callback_func)
2877 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Set private data requested cb");
2880 ret = vcd_engine_agent_set_private_data_requested_cb(callback_func);
2882 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to set private data requested cb : ret(%d)", ret);
2888 int vcd_set_nlu_base_info_requested_cb(vce_nlu_base_info_requested_cb callback_func)
2890 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Set nlu base info requested cb");
2893 ret = vcd_engine_agent_set_nlu_base_info_requested_cb(callback_func);
2895 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to set nlu base info requested cb : ret(%d)", ret);
2901 int vcd_set_specific_engine_request_cb(vce_specific_engine_request_cb callback_func)
2903 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Set specific engine request cb");
2905 ret = vcd_engine_agent_set_specific_engine_request_cb(callback_func);
2907 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to set specific engine request cb : ret(%d)", ret);