2 * Copyright (c) 2011-2015 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the License);
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an AS IS BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 #include <sound_manager.h>
20 #include "vc_info_parser.h"
22 #include "vcd_server.h"
23 #include "vcd_client_data.h"
25 #include "vcd_engine_agent.h"
26 #include "vcd_config.h"
27 #include "vcd_recorder.h"
30 #include "voice_control_command_expand.h"
33 * VC Server static variable
35 static bool g_is_engine;
37 static GList *g_proc_list = NULL;
40 * VC Server Internal Functions
42 static Eina_Bool __stop_by_silence(void *data)
44 SLOG(LOG_DEBUG, TAG_VCD, "===== Silence Detected ");
46 vcd_server_mgr_stop();
48 SLOG(LOG_DEBUG, TAG_VCD, "=====");
49 SLOG(LOG_DEBUG, TAG_VCD, " ");
53 static Eina_Bool __cancel_by_interrupt(void *data)
55 SLOG(LOG_DEBUG, TAG_VCD, "===== Cancel by interrupt");
57 vcd_server_mgr_cancel();
59 SLOG(LOG_DEBUG, TAG_VCD, "=====");
60 SLOG(LOG_DEBUG, TAG_VCD, " ");
64 static Eina_Bool __restart_engine(void *data)
66 SLOG(LOG_DEBUG, TAG_VCD, "===== Restart by no result");
68 /* Restart recognition */
69 int ret = vcd_engine_recognize_start(true);
71 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to restart recognition : result(%d)", ret);
75 SLOG(LOG_DEBUG, TAG_VCD, "[Server Success] Start engine");
77 if (VCD_RECOGNITION_MODE_RESTART_AFTER_REJECT == vcd_client_get_recognition_mode()) {
78 vcd_config_set_service_state(VCD_STATE_RECORDING);
79 vcdc_send_service_state(VCD_STATE_RECORDING);
82 SLOG(LOG_DEBUG, TAG_VCD, "[Server Success] Restart recognition");
84 SLOG(LOG_DEBUG, TAG_VCD, "=====");
85 SLOG(LOG_DEBUG, TAG_VCD, " ");
89 static int __server_recorder_callback(const void* data, const unsigned int length)
91 vcd_state_e state = vcd_config_get_service_state();
92 if (VCD_STATE_RECORDING != state) {
93 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Skip by engine processing");
97 vcp_speech_detect_e speech_detected = VCP_SPEECH_DETECT_NONE;
100 ret = vcd_engine_recognize_audio(data, length, &speech_detected);
104 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to set recording data to engine(%d)", ret);
105 ecore_timer_add(0, __cancel_by_interrupt, NULL);
109 if (VCP_SPEECH_DETECT_BEGIN == speech_detected) {
110 if (-1 != vcd_client_manager_get_pid()) {
111 /* Manager client is available */
112 if (0 != vcdc_send_speech_detected(vcd_client_manager_get_pid())) {
113 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Fail to send speech detected");
116 } else if (VCP_SPEECH_DETECT_END == speech_detected) {
117 if (VCD_RECOGNITION_MODE_STOP_BY_SILENCE == vcd_client_get_recognition_mode()) {
118 /* silence detected */
119 ecore_timer_add(0, __stop_by_silence, NULL);
120 } else if (VCD_RECOGNITION_MODE_RESTART_AFTER_REJECT == vcd_client_get_recognition_mode()) {
121 /* Stop engine recognition */
122 int ret = vcd_engine_recognize_stop();
124 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to stop recognition : %d", ret);
126 vcd_config_set_service_state(VCD_STATE_PROCESSING);
127 vcdc_send_service_state(VCD_STATE_PROCESSING);
129 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Stop engine only by silence");
130 } else if (VCD_RECOGNITION_MODE_RESTART_CONTINUOUSLY == vcd_client_get_recognition_mode()) {
131 /* Stop engine recognition */
132 int ret = vcd_engine_recognize_stop();
134 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to stop recognition : %d", ret);
142 void __server_recorder_interrupt_callback()
144 SLOG(LOG_DEBUG, TAG_VCD, "===== Cancel by sound interrupt");
146 ecore_timer_add(0, __cancel_by_interrupt, NULL);
148 SLOG(LOG_DEBUG, TAG_VCD, "=====");
149 SLOG(LOG_DEBUG, TAG_VCD, " ");
152 static void __config_lang_changed_cb(const char* current_lang, void* user_data)
154 SLOG(LOG_DEBUG, TAG_VCD, "===== Change language ");
156 /* Current state is recording */
157 vcd_state_e state = vcd_config_get_service_state();
158 if (VCD_STATE_RECORDING == state || VCD_STATE_PROCESSING == state) {
159 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Current state is 'Recording'. Cancel recognition");
160 vcd_server_mgr_cancel();
164 ret = vcd_engine_set_current_language(current_lang);
166 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to set language of engine : %d", ret);
169 SLOG(LOG_DEBUG, TAG_VCD, "=====");
170 SLOG(LOG_DEBUG, TAG_VCD, " ");
175 static void __config_foreground_changed_cb(int previous, int current, void* user_data)
177 SLOG(LOG_DEBUG, TAG_VCD, "===== Change foreground");
179 SLOG(LOG_DEBUG, TAG_VCD, "Foreground pid(%d)", current);
181 if (VC_NO_FOREGROUND_PID != current) {
182 /* Foreground app is changed */
183 vcd_state_e state = vcd_config_get_service_state();
184 if (VCD_STATE_RECORDING == state) {
185 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Foreground pid(%d) is changed. Cancel recognition", current);
186 ecore_timer_add(0, __cancel_by_interrupt, NULL);
190 SLOG(LOG_DEBUG, TAG_VCD, "=====");
191 SLOG(LOG_DEBUG, TAG_VCD, " ");
196 static Eina_Bool __vcd_send_selected_result(void *data)
198 GSList* pid_list = NULL;
199 if (0 != vc_info_parser_get_result_pid_list(&pid_list)) {
200 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Fail to get pid list. No result");
202 if (0 < g_slist_length(pid_list)) {
204 vc_cmd_s* temp_cmd = NULL;
208 iter = g_slist_nth(pid_list, 0);
209 while (NULL != iter) {
210 temp_cmd = iter->data;
212 if (NULL != temp_cmd) {
215 /* send result noti */
216 ret = vcdc_send_result(temp_cmd->pid, temp_cmd->type);
218 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Fail to send result");
219 if (VCD_ERROR_TIMED_OUT != ret) {
223 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Send result : pid(%d) type(%d)", temp_cmd->pid, temp_cmd->type);
227 if (100 == count) break;
228 /* While is retry code */
233 pid_list = g_slist_remove_link(pid_list, iter);
234 iter = g_slist_nth(pid_list, 0);
239 if (VCD_RECOGNITION_MODE_RESTART_CONTINUOUSLY != vcd_client_get_recognition_mode()) {
240 vcd_config_set_service_state(VCD_STATE_READY);
241 vcdc_send_service_state(VCD_STATE_READY);
247 static void __vcd_server_result_cb(vcp_result_event_e event, int* result_id, int count, const char* all_result,
248 const char* non_fixed_result, const char* msg, void *user_data)
250 if (VCD_STATE_PROCESSING != vcd_config_get_service_state()) {
251 if (VCD_RECOGNITION_MODE_RESTART_CONTINUOUSLY != vcd_client_get_recognition_mode()) {
252 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Current state is not 'Processing' and mode is not 'Restart continuously'");
257 vc_info_parser_unset_result(vcd_client_manager_get_exclusive());
259 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Event(%d), Text(%s) Nonfixed(%s) Msg(%s) Result count(%d)",
260 event, all_result, non_fixed_result, msg, count);
262 if (VCD_RECOGNITION_MODE_RESTART_AFTER_REJECT == vcd_client_get_recognition_mode()) {
263 if (VCP_RESULT_EVENT_REJECTED == event) {
264 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Restart by no or rejected result");
265 /* If no result and restart option is ON */
266 /* Send reject message */
267 bool temp = vcd_client_manager_get_exclusive();
268 vc_info_parser_set_result(all_result, event, msg, NULL, temp);
269 if (0 != vcdc_send_result_to_manager(vcd_client_manager_get_pid(), VC_RESULT_TYPE_NOTIFICATION)) {
270 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Fail to send result");
273 ecore_timer_add(0, __restart_engine, NULL);
276 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Stop recorder due to success");
278 } else if (VCD_RECOGNITION_MODE_RESTART_CONTINUOUSLY == vcd_client_get_recognition_mode()) {
279 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Restart continuously");
280 /* Restart option is ON */
281 ecore_timer_add(0, __restart_engine, NULL);
282 if (VCP_RESULT_EVENT_REJECTED == event) {
283 bool temp = vcd_client_manager_get_exclusive();
284 vc_info_parser_set_result(all_result, event, msg, NULL, temp);
285 if (0 != vcdc_send_result_to_manager(vcd_client_manager_get_pid(), VC_RESULT_TYPE_NOTIFICATION)) {
286 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Fail to send result");
293 if (NULL == result_id) {
295 if (NULL != all_result) {
296 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Engine result is no command : %s", all_result);
297 bool temp = vcd_client_manager_get_exclusive();
298 vc_info_parser_set_result(all_result, event, msg, NULL, temp);
301 int pid = vcd_client_widget_get_foreground_pid();
303 if (NULL != all_result) {
304 /* Send result text to widget */
305 vcdc_send_result(pid, VC_COMMAND_TYPE_WIDGET);
308 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Request tooltip hide");
309 /* Send to hide tooltip */
310 vcdc_send_show_tooltip(pid, false);
313 if (-1 != vcd_client_manager_get_pid()) {
314 /* Manager client is available */
315 if (0 != vcdc_send_result_to_manager(vcd_client_manager_get_pid(), VC_RESULT_TYPE_NORMAL)) {
316 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Fail to send result");
320 vcd_client_manager_set_exclusive(false);
326 SLOG(LOG_DEBUG, TAG_VCD, "[Server] === Get engine result ===");
329 vc_cmd_s* temp_cmd = NULL;
330 vc_cmd_list_h vc_cmd_list = NULL;
332 if (0 != vc_cmd_list_create(&vc_cmd_list)) {
333 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Fail to create command list");
334 vcd_client_manager_set_exclusive(false);
335 vcd_config_set_service_state(VCD_STATE_READY);
336 vcdc_send_service_state(VCD_STATE_READY);
341 for (i = 0; i < count; i++) {
342 SLOG(LOG_DEBUG, TAG_VCD, "[Server] [%d] Result ID(%d)", i, result_id[i]);
344 if (result_id[i] < 0) {
345 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Result ID(%d) is NOT valid", result_id[i]);
349 ret = vcd_client_get_cmd_from_result_id(result_id[i], &temp_cmd);
350 if (0 == ret && NULL != temp_cmd) {
351 switch (temp_cmd->format) {
352 case VC_CMD_FORMAT_FIXED:
353 /* Nonfixed result is NOT valid */
355 case VC_CMD_FORMAT_FIXED_AND_EXTRA:
356 if (NULL == temp_cmd->parameter) {
357 if (NULL != non_fixed_result) {
358 temp_cmd->parameter = strdup(non_fixed_result);
361 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Command type is NOT vaild. Parameter (%s)", temp_cmd->parameter);
364 case VC_CMD_FORMAT_EXTRA_AND_FIXED:
365 if (NULL == temp_cmd->command) {
366 if (NULL != non_fixed_result) {
367 temp_cmd->command = strdup(non_fixed_result);
370 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Command type is NOT vaild. Command (%s)", temp_cmd->command);
375 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Unknown command type : %d", temp_cmd->type);
379 if (0 != vc_cmd_list_add(vc_cmd_list, (vc_cmd_h)temp_cmd)) {
380 SLOG(LOG_DEBUG, TAG_VCD, "Fail to add command to list");
381 vc_cmd_destroy((vc_cmd_h)temp_cmd);
384 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] NOT found matached result(%d)", result_id[i]);
388 vc_cmd_print_list(vc_cmd_list);
390 SLOG(LOG_DEBUG, TAG_VCD, "[Server] =========================");
392 int result_count = 0;
393 vc_cmd_list_get_count(vc_cmd_list, &result_count);
395 if (false == vcd_client_manager_get_exclusive()) {
396 int pid = vcd_client_widget_get_foreground_pid();
398 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Request tooltip hide");
399 vcdc_send_show_tooltip(pid, false);
402 vc_info_parser_set_result(all_result, event, msg, vc_cmd_list, false);
404 if (-1 != vcd_client_manager_get_pid()) {
405 /* Manager client is available */
406 if (0 != vcdc_send_result_to_manager(vcd_client_manager_get_pid(), VC_RESULT_TYPE_NORMAL)) {
407 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Fail to send result");
410 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Manager is NOT available. Send result to client directly");
411 /* Send result to client */
412 ecore_timer_add(0, __vcd_send_selected_result, NULL);
415 /* exclusive command */
416 vc_info_parser_set_result(all_result, event, msg, vc_cmd_list, true);
418 if (-1 != vcd_client_manager_get_pid()) {
419 /* Manager client is available */
420 if (0 != vcdc_send_result_to_manager(vcd_client_manager_get_pid(), VC_RESULT_TYPE_NORMAL)) {
421 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Fail to send result");
424 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Manager is NOT available");
427 vcd_client_manager_set_exclusive(false);
430 vc_cmd_list_destroy(vc_cmd_list, true);
436 * vcd server Interfaces
438 static void __vcd_file_clean_up()
440 SLOG(LOG_DEBUG, TAG_VCD, "== Old file clean up == ");
445 struct dirent *dirp = NULL;
447 dp = opendir(VC_RUNTIME_INFO_ROOT);
449 SLOG(LOG_ERROR, TAG_VCD, "[File message WARN] Fail to open path : %s", VC_RUNTIME_INFO_ROOT);
453 char remove_path[256] = {0, };
455 ret = readdir_r(dp, &entry, &dirp);
457 SLOG(LOG_ERROR, TAG_VCD, "[File ERROR] Fail to read directory");
462 if (!strncmp("vc_", dirp->d_name, strlen("vc_"))) {
463 memset(remove_path, 0, 256);
464 snprintf(remove_path, 256, "%s/%s", VC_RUNTIME_INFO_ROOT, dirp->d_name);
467 if (0 != remove(remove_path)) {
468 SLOG(LOG_WARN, TAG_VCD, "[File message WARN] Fail to remove file : %s", remove_path);
470 SLOG(LOG_DEBUG, TAG_VCD, "[File message] Remove file : %s", remove_path);
474 } while (NULL != dirp);
485 /* Remove old file */
486 __vcd_file_clean_up();
488 /* initialize modules */
489 ret = vcd_config_initialize(__config_lang_changed_cb, __config_foreground_changed_cb, NULL);
491 SLOG(LOG_ERROR, TAG_VCD, "[Server WARNING] Fail to initialize config.");
494 vcd_config_set_service_state(VCD_STATE_NONE);
496 ret = vcd_engine_agent_init(__vcd_server_result_cb);
498 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to engine agent initialize : result(%d)", ret);
502 if (0 != vcd_recorder_create(__server_recorder_callback, __server_recorder_interrupt_callback)) {
503 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to create recorder");
504 return VCD_ERROR_OPERATION_FAILED;
508 ret = vcd_engine_agent_initialize_current_engine();
510 if (VCD_ERROR_ENGINE_NOT_FOUND == ret)
511 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] There is No Voice control engine");
513 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to init engine");
521 if (0 != vcd_engine_agent_load_current_engine()) {
522 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to load current engine");
523 return VCD_ERROR_OPERATION_FAILED;
526 /* Initialize manager info */
527 vcd_client_manager_unset();
529 vcd_config_set_service_state(VCD_STATE_READY);
530 vcdc_send_service_state(VCD_STATE_READY);
532 SLOG(LOG_DEBUG, TAG_VCD, "[Server SUCCESS] initialize");
540 if (0 < g_list_length(g_proc_list)) {
541 iter = g_list_first(g_proc_list);
542 while (NULL != iter) {
543 g_proc_list = g_list_remove_link(g_proc_list, iter);
544 iter = g_list_first(g_proc_list);
548 vcd_state_e state = vcd_config_get_service_state();
549 if (VCD_STATE_READY != state) {
550 if (VCD_STATE_RECORDING == state) {
553 vcd_engine_recognize_cancel();
555 if (0 != vcd_recorder_destroy()) {
556 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to destroy recorder");
558 SLOG(LOG_DEBUG, TAG_VCD, "[Server] destroy recorder");
561 if (0 != vcd_engine_agent_release()) {
562 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to release engine");
564 SLOG(LOG_DEBUG, TAG_VCD, "[Server] release engine");
567 vcd_config_set_service_state(VCD_STATE_NONE);
568 vcdc_send_service_state(VCD_STATE_NONE);
570 SLOG(LOG_DEBUG, TAG_VCD, "[Server] mode finalize");
575 static Eina_Bool __finalize_quit_ecore_loop(void *data)
577 SLOG(LOG_DEBUG, TAG_VCD, "[Server] quit ecore main loop");
578 ecore_main_loop_quit();
582 static void __read_proc()
586 struct dirent *dirp = NULL;
591 if (0 < g_list_length(g_proc_list)) {
592 iter = g_list_first(g_proc_list);
593 while (NULL != iter) {
594 g_proc_list = g_list_remove_link(g_proc_list, iter);
595 iter = g_list_first(g_proc_list);
599 dp = opendir("/proc");
601 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to open proc");
604 ret = readdir_r(dp, &entry, &dirp);
606 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to readdir");
611 tmp = atoi(dirp->d_name);
612 if (0 >= tmp) continue;
613 g_proc_list = g_list_append(g_proc_list, GINT_TO_POINTER(tmp));
615 } while (NULL != dirp);
621 static void __vcd_cleanup_client(vcd_client_type_e type)
623 int* client_list = NULL;
624 int client_count = 0;
631 if (VCD_CLIENT_TYPE_NORMAL == type) {
632 ret = vcd_client_get_list(&client_list, &client_count);
634 else if (VCD_CLIENT_TYPE_WIDGET == type) {
635 ret = vcd_client_widget_get_list(&client_list, &client_count);
637 else if (VCD_CLIENT_TYPE_MANAGER == type) {
638 mgr_pid = vcd_client_manager_get_pid();
639 client_list = &mgr_pid;
643 if (0 == ret || mgr_pid > 0) {
644 SLOG(LOG_DEBUG, TAG_VCD, "===== Clean up %s client ", type ? (type == 1) ? "Widget" : "Manager" : "Normal");
645 if (NULL != client_list && client_count > 0) {
646 for (i = 0; i < client_count; i++) {
649 for (j = 0; j < g_list_length(g_proc_list); j++) {
650 iter = g_list_nth(g_proc_list, j);
652 if (client_list[i] == GPOINTER_TO_INT(iter->data)) {
653 SLOG(LOG_DEBUG, TAG_VCD, "%s pid(%d) is running", type ? (type == 1) ? "Widget" : "Manager" : "Normal", client_list[i]);
660 if (false == exist) {
661 SLOG(LOG_ERROR, TAG_VCD, "%s pid(%d) should be removed", type ? (type == 1) ? "Widget" : "Manager" : "Normal", client_list[i]);
662 if (VCD_CLIENT_TYPE_NORMAL == type)
663 vcd_server_finalize(client_list[i]);
664 else if (VCD_CLIENT_TYPE_WIDGET == type)
665 vcd_server_widget_finalize(client_list[i]);
667 vcd_server_mgr_finalize(mgr_pid);
671 SLOG(LOG_DEBUG, TAG_VCD, "=====");
672 SLOG(LOG_DEBUG, TAG_VCD, " ");
674 if (NULL != client_list && -1 == mgr_pid) {
681 Eina_Bool vcd_cleanup_client_all(void *data)
685 __vcd_cleanup_client(VCD_CLIENT_TYPE_NORMAL);
686 __vcd_cleanup_client(VCD_CLIENT_TYPE_WIDGET);
687 __vcd_cleanup_client(VCD_CLIENT_TYPE_MANAGER);
690 if (0 == vcd_client_get_list(&client_list, &client_count)) {
691 SLOG(LOG_DEBUG, TAG_VCD, "===== Clean up client ");
692 if (NULL != client_list && client_count > 0) {
693 for (i = 0; i < client_count; i++) {
696 for (j = 0; j < g_list_length(g_proc_list); j++) {
697 iter = g_list_nth(g_proc_list, j);
699 if (client_list[i] == GPOINTER_TO_INT(iter->data)) {
700 SLOG(LOG_DEBUG, TAG_VCD, "pid(%d) is running", client_list[i]);
707 if (false == exist) {
708 SLOG(LOG_ERROR, TAG_VCD, "pid(%d) should be removed", client_list[i]);
709 vcd_server_finalize(client_list[i]);
712 result = vcdc_send_hello(client_list[i], VCD_CLIENT_TYPE_NORMAL);
715 SLOG(LOG_DEBUG, TAG_VCD, "[Server] pid(%d) should be removed.", client_list[i]);
716 vcd_server_finalize(client_list[i]);
717 } else if (-1 == result) {
718 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Hello result has error");
723 SLOG(LOG_DEBUG, TAG_VCD, "=====");
724 SLOG(LOG_DEBUG, TAG_VCD, " ");
726 if (NULL != client_list) {
731 /* If app is in background state, app cannot response message. */
732 if (0 == vcd_client_widget_get_list(&client_list, &client_count)) {
733 SLOG(LOG_DEBUG, TAG_VCD, "===== Clean up widget");
734 if (NULL != client_list && client_count > 0) {
735 for (i = 0; i < client_count; i++) {
738 for (j = 0; j < g_list_length(g_proc_list); j++) {
739 iter = g_list_nth(g_proc_list, j);
741 if (client_list[i] == GPOINTER_TO_INT(iter->data)) {
742 SLOG(LOG_DEBUG, TAG_VCD, "widget pid(%d) is running", client_list[i]);
749 if (false == exist) {
750 SLOG(LOG_ERROR, TAG_VCD, "widget pid(%d) should be removed", client_list[i]);
751 vcd_server_widget_finalize(client_list[i]);
754 result = vcdc_send_hello(client_list[i], VCD_CLIENT_TYPE_WIDGET);
757 SLOG(LOG_DEBUG, TAG_VCD, "[Server] widget pid(%d) should be removed.", client_list[i]);
758 vcd_server_widget_finalize(client_list[i]);
759 } else if (-1 == result) {
760 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Hello result has error");
765 SLOG(LOG_DEBUG, TAG_VCD, "=====");
766 SLOG(LOG_DEBUG, TAG_VCD, " ");
769 if (NULL != client_list) {
777 int mgr_pid = vcd_client_manager_get_pid();
779 for (j = 0; j < g_list_length(g_proc_list); j++) {
780 iter = g_list_nth(g_proc_list, j);
782 if (mgr_pid == GPOINTER_TO_INT(iter->data)) {
783 SLOG(LOG_DEBUG, TAG_VCD, "manager pid(%d) is running", mgr_pid);
790 if (false == exist) {
791 SLOG(LOG_ERROR, TAG_VCD, "manager pid (%d) should be removed", mgr_pid);
792 vcd_server_mgr_finalize(mgr_pid);
799 int vcd_server_get_service_state()
801 return vcd_config_get_service_state();
804 int vcd_server_get_foreground()
807 vcd_config_get_foreground(&pid);
815 int vcd_server_mgr_initialize(int pid)
817 if (false == g_is_engine) {
818 if (0 != vcd_engine_agent_initialize_current_engine()) {
819 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] No Engine");
821 return VCD_ERROR_ENGINE_NOT_FOUND;
827 /* check if pid is valid */
828 if (false == vcd_client_manager_is_valid(pid)) {
829 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] The pid(%d) is already exist", pid);
830 return VCD_ERROR_INVALID_PARAMETER;
833 /* Add client information to client manager */
834 if (0 != vcd_client_manager_set(pid)) {
835 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to add manager");
836 return VCD_ERROR_OPERATION_FAILED;
839 SLOG(LOG_DEBUG, TAG_VCD, "[Server Success] Manager initialize : pid(%d)", pid);
841 return VCD_ERROR_NONE;
844 int vcd_server_mgr_finalize(int pid)
846 /* check if pid is valid */
847 if (false == vcd_client_manager_is_valid(pid)) {
848 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] The manager pid(%d) is NOT valid", pid);
849 return VCD_ERROR_INVALID_PARAMETER;
852 /* Cancel recognition */
853 vcd_server_mgr_cancel();
855 /* Remove manager information */
856 if (0 != vcd_client_manager_unset()) {
857 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Fail to delete client");
860 if (0 == vcd_client_get_ref_count()) {
861 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Connected client list is empty");
862 ecore_timer_add(0, __finalize_quit_ecore_loop, NULL);
865 SLOG(LOG_DEBUG, TAG_VCD, "[Server Success] Manager Finalize : pid(%d)", pid);
867 return VCD_ERROR_NONE;
870 int vcd_server_mgr_set_command(int pid)
872 if (0 != vcd_client_manager_set_command(pid)) {
873 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] The manager pid(%d) is NOT valid", pid);
874 return VCD_ERROR_INVALID_PARAMETER;
876 return VCD_ERROR_NONE;
879 int vcd_server_mgr_unset_command(int pid)
881 if (0 != vcd_client_manager_unset_command(pid)) {
882 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] The manager pid(%d) is NOT valid", pid);
883 return VCD_ERROR_INVALID_PARAMETER;
885 return VCD_ERROR_NONE;
888 int vcd_server_mgr_set_demandable_client(int pid)
890 /* check if pid is valid */
891 if (false == vcd_client_manager_is_valid(pid)) {
892 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] The manager pid(%d) is NOT valid", pid);
893 return VCD_ERROR_INVALID_PARAMETER;
896 GSList* client_list = NULL;
897 if (0 != vc_info_parser_get_demandable_clients(&client_list)) {
898 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to get demandable client");
899 return VCD_ERROR_OPERATION_FAILED;
902 /* Save client list */
903 if (0 != vcd_client_manager_set_demandable_client(pid, client_list)) {
904 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to set demandable client list");
905 return VCD_ERROR_OPERATION_FAILED;
908 return VCD_ERROR_NONE;
911 int vcd_server_mgr_set_audio_type(int pid, const char* audio_type)
913 /* check if pid is valid */
914 if (false == vcd_client_manager_is_valid(pid)) {
915 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] The manager pid(%d) is NOT valid", pid);
916 return VCD_ERROR_INVALID_PARAMETER;
920 vcp_audio_type_e type = VCP_AUDIO_TYPE_PCM_S16_LE;
924 ret = vcd_engine_get_audio_format(audio_type, &type, &rate, &channel);
926 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to get audio format : %d", ret);
927 return VCD_ERROR_OPERATION_FAILED;
930 ret = vcd_recorder_set(audio_type, type, rate, channel);
932 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to set audio in type : %d", ret);
933 return VCD_ERROR_OPERATION_FAILED;
936 return VCD_ERROR_NONE;
939 int vcd_server_mgr_get_audio_type(int pid, char** audio_type)
941 /* check if pid is valid */
942 if (false == vcd_client_manager_is_valid(pid)) {
943 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] The manager pid(%d) is NOT valid", pid);
944 return VCD_ERROR_INVALID_PARAMETER;
947 int ret = vcd_recorder_get(audio_type);
949 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to get audio in type : %d", ret);
950 return VCD_ERROR_OPERATION_FAILED;
953 return VCD_ERROR_NONE;
956 int vcd_server_mgr_set_client_info(int pid)
958 /* check if pid is valid */
959 if (false == vcd_client_manager_is_valid(pid)) {
960 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] The manager pid(%d) is NOT valid", pid);
961 return VCD_ERROR_INVALID_PARAMETER;
964 int ret = vcd_client_save_client_info();
966 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to save client info : %d", ret);
967 return VCD_ERROR_OPERATION_FAILED;
970 return VCD_ERROR_NONE;
973 static int __start_internal_recognition()
977 /* 2. Get commands */
978 ret = vcd_client_command_collect_command();
980 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to collect command : %d", ret);
981 return VCD_ERROR_OPERATION_FAILED;
984 ret = vcd_client_get_length();
986 SLOG(LOG_WARN, TAG_VCD, "[Server WARNIING] No current command : %d", ret);
987 return VCD_ERROR_OPERATION_FAILED;
990 /* 3. Set command to engine */
991 ret = vcd_engine_set_commands();
993 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to collect command : %d", ret);
994 return VCD_ERROR_OPERATION_FAILED;
997 SLOG(LOG_DEBUG, TAG_VCD, "[Server Success] Set command");
999 bool stop_by_silence = true;
1000 if (VCD_RECOGNITION_MODE_MANUAL == vcd_client_get_recognition_mode()) {
1001 stop_by_silence = false;
1004 /* 4. start recognition */
1005 ret = vcd_engine_recognize_start(stop_by_silence);
1007 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to start recognition : result(%d)", ret);
1008 return VCD_ERROR_OPERATION_FAILED;
1011 SLOG(LOG_DEBUG, TAG_VCD, "[Server Success] Start engine");
1013 /* 5. recorder start */
1014 ret = vcd_recorder_start();
1016 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to start recorder : result(%d)", ret);
1017 vcd_engine_recognize_cancel();
1021 vcd_config_set_service_state(VCD_STATE_RECORDING);
1022 vcdc_send_service_state(VCD_STATE_RECORDING);
1024 SLOG(LOG_DEBUG, TAG_VCD, "[Server Success] Start recognition(%d)", stop_by_silence);
1029 static Eina_Bool __vcd_request_show_tooltip(void *data)
1031 int pid = vcd_client_widget_get_foreground_pid();
1033 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Request tooltip show and widget command");
1034 vcdc_send_show_tooltip(pid, (bool)data);
1040 int vcd_server_mgr_start(vcd_recognition_mode_e recognition_mode, bool exclusive_cmd, bool start_by_client)
1042 /* 1. check current state */
1043 vcd_state_e state = vcd_config_get_service_state();
1045 if (VCD_STATE_READY != state) {
1046 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Current state is not ready");
1047 return VCD_ERROR_INVALID_STATE;
1050 SLOG(LOG_DEBUG, TAG_VCD, "[Server] set recognition mode = %d", recognition_mode);
1051 vcd_client_set_recognition_mode(recognition_mode);
1053 if (false == exclusive_cmd) {
1054 /* Notify show tooltip */
1055 int pid = vcd_client_widget_get_foreground_pid();
1057 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Request tooltip show and widget command");
1058 ecore_timer_add(0, __vcd_request_show_tooltip, (void*)true);
1062 vcd_client_manager_set_exclusive(exclusive_cmd);
1066 if (true == start_by_client) {
1067 /* Get foreground pid */
1068 if (0 != vcd_config_get_foreground(&fg_pid)) {
1069 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to get foreground");
1072 /* Set client exclusive option */
1073 if (0 != vcd_client_set_exclusive_command(fg_pid)) {
1074 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to set exclusive command");
1078 int ret = __start_internal_recognition();
1080 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to start recongition : %d", ret);
1084 if (true == start_by_client) {
1085 vcd_client_unset_exclusive_command(fg_pid);
1088 return VCD_ERROR_NONE;
1091 int vcd_server_mgr_stop()
1093 /* 1. Check current state is recording */
1094 if (VCD_STATE_RECORDING != vcd_config_get_service_state()) {
1095 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Current state is not recording");
1096 return VCD_ERROR_INVALID_STATE;
1099 /* 2. Stop recorder */
1100 vcd_recorder_stop();
1102 /* 3. Stop engine recognition */
1103 int ret = vcd_engine_recognize_stop();
1105 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to stop recognition : %d", ret);
1108 /* 4. Set original mode */
1109 vcd_config_set_service_state(VCD_STATE_PROCESSING);
1110 vcdc_send_service_state(VCD_STATE_PROCESSING);
1112 return VCD_ERROR_NONE;
1115 int vcd_server_mgr_cancel()
1117 /* 1. Check current state */
1118 vcd_state_e state = vcd_config_get_service_state();
1119 if (VCD_STATE_RECORDING != state && VCD_STATE_PROCESSING != state) {
1120 SLOG(LOG_WARN, TAG_VCD, "[Server ERROR] Current state is not recording or processing");
1121 return VCD_ERROR_INVALID_STATE;
1124 /* 2. Stop recorder */
1125 vcd_recorder_stop();
1126 /* 3. Cancel engine */
1127 int ret = vcd_engine_recognize_cancel();
1129 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Fail to cancel : %d", ret);
1132 if (false == vcd_client_manager_get_exclusive()) {
1133 int pid = vcd_client_widget_get_foreground_pid();
1135 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Request tooltip hide");
1136 ecore_timer_add(0, __vcd_request_show_tooltip, (void*)false);
1139 vcd_client_manager_set_exclusive(false);
1143 vcd_config_set_service_state(VCD_STATE_READY);
1144 vcdc_send_service_state(VCD_STATE_READY);
1146 return VCD_ERROR_NONE;
1150 int vcd_server_mgr_result_select()
1152 __vcd_send_selected_result(NULL);
1154 return VCD_ERROR_NONE;
1158 * VC Server Functions for Client
1160 int vcd_server_initialize(int pid)
1162 if (false == g_is_engine) {
1163 if (0 != vcd_engine_agent_initialize_current_engine()) {
1164 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] No Engine");
1165 g_is_engine = false;
1166 return VCD_ERROR_ENGINE_NOT_FOUND;
1172 if (false == vcd_engine_is_available_engine()) {
1173 if (0 != vcd_engine_agent_initialize_current_engine()) {
1174 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] No Engine");
1175 return VCD_ERROR_ENGINE_NOT_FOUND;
1179 /* check if pid is valid */
1180 if (true == vcd_client_is_available(pid)) {
1181 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] The pid is already exist");
1182 return VCD_ERROR_INVALID_PARAMETER;
1185 /* Add client information to client manager */
1186 if (0 != vcd_client_add(pid)) {
1187 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to add client info");
1188 return VCD_ERROR_OPERATION_FAILED;
1191 SLOG(LOG_DEBUG, TAG_VCD, "[Server Success] Client Initialize : pid(%d)", pid);
1193 return VCD_ERROR_NONE;
1196 int vcd_server_finalize(int pid)
1198 /* check if pid is valid */
1199 if (false == vcd_client_is_available(pid)) {
1200 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] pid is NOT valid ");
1201 return VCD_ERROR_INVALID_PARAMETER;
1204 /* Remove client information */
1205 if (0 != vcd_client_delete(pid)) {
1206 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Fail to delete client");
1209 if (0 == vcd_client_get_ref_count()) {
1210 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Connected client list is empty");
1211 ecore_timer_add(0, __finalize_quit_ecore_loop, NULL);
1214 SLOG(LOG_DEBUG, TAG_VCD, "[Server Success] Client Finalize : pid(%d)", pid);
1216 return VCD_ERROR_NONE;
1219 int vcd_server_set_command(int pid, vc_cmd_type_e cmd_type)
1221 /* check if pid is valid */
1222 if (false == vcd_client_is_available(pid)) {
1223 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] pid is NOT valid ");
1224 return VCD_ERROR_INVALID_PARAMETER;
1227 if (0 != vcd_client_set_command_type(pid, cmd_type)) {
1228 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to set command type : pid(%d), cmd_type(%d)", pid, cmd_type);
1229 return VCD_ERROR_OPERATION_FAILED;
1235 int vcd_server_unset_command(int pid, vc_cmd_type_e cmd_type)
1237 /* check if pid is valid */
1238 if (false == vcd_client_is_available(pid)) {
1239 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] pid is NOT valid ");
1240 return VCD_ERROR_INVALID_PARAMETER;
1243 if (0 != vcd_client_unset_command_type(pid, cmd_type)) {
1244 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to unset command type : pid(%d), cmd_type(%d)", pid, cmd_type);
1245 return VCD_ERROR_OPERATION_FAILED;
1251 int vcd_server_set_foreground(int pid, bool value)
1253 /* check if pid is valid */
1254 if (false == vcd_client_is_available(pid) && false == vcd_client_widget_is_available(pid)) {
1255 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] pid is NOT valid ");
1256 return VCD_ERROR_INVALID_PARAMETER;
1259 if (0 != vcd_config_set_foreground(pid, value)) {
1260 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to set foreground : pid(%d), value(%d)", pid, value);
1261 return VCD_ERROR_OPERATION_FAILED;
1268 int vcd_server_set_exclusive_command(int pid, bool value)
1270 /* check if pid is valid */
1271 if (false == vcd_client_is_available(pid)) {
1272 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] pid is NOT valid ");
1273 return VCD_ERROR_INVALID_PARAMETER;
1276 if (true == value) {
1277 if (0 != vcd_client_set_exclusive_command(pid)) {
1278 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to set exclusive command : pid(%d)", pid);
1279 return VCD_ERROR_OPERATION_FAILED;
1282 if (0 != vcd_client_unset_exclusive_command(pid)) {
1283 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to unset exclusive command : pid(%d)", pid);
1284 return VCD_ERROR_OPERATION_FAILED;
1291 int vcd_server_request_start(int pid, bool stop_by_silence)
1293 /* check if pid is valid */
1294 if (false == vcd_client_is_available(pid)) {
1295 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] pid(%d) is NOT forground client", pid);
1296 return VCD_ERROR_INVALID_PARAMETER;
1300 /* Check current state */
1301 vcd_state_e state = vcd_config_get_service_state();
1303 /* Service state should be ready */
1304 if (VCD_STATE_READY != state) {
1305 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Current state is not Ready : pid(%d)", pid);
1306 return VCD_ERROR_INVALID_STATE;
1309 if (-1 != vcd_client_manager_get_pid()) {
1310 /* Check current pid is valid */
1311 if (false == vcd_client_manager_check_demandable_client(pid)) {
1312 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Current client is NOT available : pid(%d)", pid);
1313 return VCD_ERROR_INVALID_PARAMETER;
1317 ret = vcd_server_mgr_start(stop_by_silence, false);
1319 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Fail to start recognition");
1320 return VCD_ERROR_INVALID_PARAMETER;
1326 int vcd_server_request_stop(int pid)
1329 /* Check current state */
1330 vcd_state_e state = vcd_config_get_service_state();
1332 /* Service state should be ready */
1333 if (VCD_STATE_RECORDING != state) {
1334 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Current state is not Recording : pid(%d)", pid);
1335 return VCD_ERROR_INVALID_STATE;
1338 if (-1 != vcd_client_manager_get_pid()) {
1339 /* Check current pid is valid */
1340 if (false == vcd_client_manager_check_demandable_client(pid)) {
1341 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Current client is NOT available : pid(%d)", pid);
1342 return VCD_ERROR_INVALID_PARAMETER;
1346 ret = vcd_server_mgr_stop();
1348 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Fail to start recognition");
1349 return VCD_ERROR_OPERATION_FAILED;
1352 return VCD_ERROR_NONE;
1355 int vcd_server_request_cancel(int pid)
1358 /* Check current state */
1359 vcd_state_e state = vcd_config_get_service_state();
1361 /* Service state should be recording or processing */
1362 if (VCD_STATE_RECORDING != state && VCD_STATE_PROCESSING != state) {
1363 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Current state is not Recording or Processing : pid(%d)", pid);
1364 return VCD_ERROR_INVALID_STATE;
1367 if (-1 != vcd_client_manager_get_pid()) {
1368 /* Check current pid is valid */
1369 if (false == vcd_client_manager_check_demandable_client(pid)) {
1370 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Current client is NOT available : pid(%d)", pid);
1371 return VCD_ERROR_INVALID_PARAMETER;
1375 ret = vcd_server_mgr_cancel();
1377 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Fail to start recognition");
1378 return VCD_ERROR_OPERATION_FAILED;
1381 return VCD_ERROR_NONE;
1386 * VC Server Functions for Widget lib
1388 int vcd_server_widget_initialize(int pid)
1390 if (false == g_is_engine) {
1391 if (0 != vcd_engine_agent_initialize_current_engine()) {
1392 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] No Engine");
1393 g_is_engine = false;
1394 return VCD_ERROR_ENGINE_NOT_FOUND;
1400 if (false == vcd_engine_is_available_engine()) {
1401 if (0 != vcd_engine_agent_initialize_current_engine()) {
1402 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] No Engine");
1403 return VCD_ERROR_ENGINE_NOT_FOUND;
1407 /* check if pid is valid */
1408 if (true == vcd_client_widget_is_available(pid)) {
1409 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] The pid is already exist");
1410 return VCD_ERROR_INVALID_PARAMETER;
1413 /* Add client information to client manager */
1414 if (0 != vcd_client_widget_add(pid)) {
1415 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to add client info");
1416 return VCD_ERROR_OPERATION_FAILED;
1419 SLOG(LOG_DEBUG, TAG_VCD, "[Server Success] Initialize widget : pid(%d)", pid);
1421 return VCD_ERROR_NONE;
1424 int vcd_server_widget_finalize(int pid)
1426 /* check if pid is valid */
1427 if (false == vcd_client_widget_is_available(pid)) {
1428 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] pid is NOT valid ");
1429 return VCD_ERROR_INVALID_PARAMETER;
1432 /* Remove client information */
1433 if (0 != vcd_client_widget_delete(pid)) {
1434 SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Fail to delete client");
1437 if (0 == vcd_client_get_ref_count()) {
1438 SLOG(LOG_DEBUG, TAG_VCD, "[Server] connected client list is empty");
1439 ecore_timer_add(0, __finalize_quit_ecore_loop, NULL);
1442 return VCD_ERROR_NONE;
1445 int vcd_server_widget_start_recording(int pid, bool widget_command)
1447 /* check if pid is valid */
1448 if (false == vcd_client_widget_is_available(pid)) {
1449 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] pid is NOT valid ");
1450 return VCD_ERROR_INVALID_PARAMETER;
1453 if (true == widget_command) {
1454 vcd_client_widget_set_command(pid);
1455 SLOG(LOG_DEBUG, TAG_VCD, "[Server] widget command is available");
1457 vcd_client_widget_unset_command(pid);
1458 SLOG(LOG_WARN, TAG_VCD, "[Server] widget command is NOT available");
1461 int ret = __start_internal_recognition();
1463 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to start recongition : %d", ret);
1464 ecore_timer_add(0, __vcd_request_show_tooltip, (void*)false);
1470 int vcd_server_widget_start(int pid, bool stop_by_silence)
1472 /* check if pid is valid */
1473 int fore_pid = vcd_client_widget_get_foreground_pid();
1474 if (pid != fore_pid) {
1475 SLOG(LOG_ERROR, TAG_VCD, "[Server] pid is NOT foreground");
1476 return VCD_ERROR_INVALID_PARAMETER;
1479 /* Check current state */
1480 vcd_state_e state = vcd_config_get_service_state();
1482 /* Service state should be ready */
1483 if (VCD_STATE_READY != state) {
1484 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Current state is not Ready : pid(%d)", pid);
1485 return VCD_ERROR_INVALID_STATE;
1488 vcd_client_set_slience_detection(stop_by_silence);
1490 /* Notify show tooltip */
1491 ecore_timer_add(0, __vcd_request_show_tooltip, (void*)true);
1496 int vcd_server_widget_stop(int pid)
1498 /* check if pid is valid */
1499 int fore_pid = vcd_client_widget_get_foreground_pid();
1500 if (pid != fore_pid) {
1501 SLOG(LOG_ERROR, TAG_VCD, "[Server] pid is NOT foreground");
1502 return VCD_ERROR_INVALID_PARAMETER;
1506 /* Check current state */
1507 vcd_state_e state = vcd_config_get_service_state();
1509 /* Service state should be recording */
1510 if (VCD_STATE_RECORDING != state) {
1511 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Current service state is not Recording : pid(%d)", pid);
1512 return VCD_ERROR_INVALID_STATE;
1515 ret = vcd_server_mgr_stop();
1517 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Fail to start recognition");
1518 return VCD_ERROR_OPERATION_FAILED;
1521 return VCD_ERROR_NONE;
1524 int vcd_server_widget_cancel(int pid)
1526 /* check if pid is valid */
1527 int fore_pid = vcd_client_widget_get_foreground_pid();
1528 if (pid != fore_pid) {
1529 SLOG(LOG_ERROR, TAG_VCD, "[Server] pid is NOT foreground");
1530 return VCD_ERROR_INVALID_PARAMETER;
1534 /* Check current state */
1535 vcd_state_e state = vcd_config_get_service_state();
1537 /* Service state should be recording or processing */
1538 if (VCD_STATE_RECORDING != state && VCD_STATE_PROCESSING != state) {
1539 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Current state is not Recording or Processing : pid(%d)", pid);
1540 return VCD_ERROR_INVALID_STATE;
1543 ret = vcd_server_mgr_cancel();
1545 SLOG(LOG_DEBUG, TAG_VCD, "[Server] Fail to cancel recognition : %d", ret);
1549 return VCD_ERROR_NONE;