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 "vc_command.h"
19 #include "vc_config_mgr.h"
20 #include "vc_info_parser.h"
22 #include "vc_widget_client.h"
23 #include "vc_widget_dbus.h"
24 #include "voice_control_command.h"
25 #include "voice_control_command_expand.h"
26 #include "voice_control_widget.h"
29 #define VC_WIDGET_CONFIG_HANDLE 200000
31 static Ecore_Timer* g_w_connect_timer = NULL;
33 static Ecore_Timer* g_w_start_timer = NULL;
34 static Ecore_Timer* g_w_tooltip_timer = NULL;
36 static vc_h g_vc_w = NULL;
38 static Eina_Bool __vc_widget_notify_state_changed(void *data);
39 static Eina_Bool __vc_widget_notify_error(void *data);
46 static const char* __vc_widget_get_error_code(vc_error_e err)
49 case VC_ERROR_NONE: return "VC_ERROR_NONE";
50 case VC_ERROR_OUT_OF_MEMORY: return "VC_ERROR_OUT_OF_MEMORY";
51 case VC_ERROR_IO_ERROR: return "VC_ERROR_IO_ERROR";
52 case VC_ERROR_INVALID_PARAMETER:return "VC_ERROR_INVALID_PARAMETER";
53 case VC_ERROR_TIMED_OUT: return "VC_ERROR_TIMED_OUT";
54 case VC_ERROR_INVALID_STATE: return "VC_ERROR_INVALID_STATE";
55 case VC_ERROR_ENGINE_NOT_FOUND: return "VC_ERROR_ENGINE_NOT_FOUND";
56 case VC_ERROR_OPERATION_FAILED: return "VC_ERROR_OPERATION_FAILED";
57 default: return "Invalid error code";
62 static int __vc_widget_convert_config_error_code(vc_config_error_e code)
64 if (code == VC_CONFIG_ERROR_NONE) return VC_ERROR_NONE;
65 if (code == VC_CONFIG_ERROR_OUT_OF_MEMORY) return VC_ERROR_OUT_OF_MEMORY;
66 if (code == VC_CONFIG_ERROR_IO_ERROR) return VC_ERROR_IO_ERROR;
67 if (code == VC_CONFIG_ERROR_INVALID_PARAMETER) return VC_ERROR_INVALID_PARAMETER;
68 if (code == VC_CONFIG_ERROR_INVALID_STATE) return VC_ERROR_INVALID_STATE;
69 if (code == VC_CONFIG_ERROR_INVALID_LANGUAGE) return VC_ERROR_INVALID_LANGUAGE;
70 if (code == VC_CONFIG_ERROR_ENGINE_NOT_FOUND) return VC_ERROR_ENGINE_NOT_FOUND;
71 if (code == VC_CONFIG_ERROR_OPERATION_FAILED) return VC_ERROR_OPERATION_FAILED;
76 static void __vc_widget_lang_changed_cb(const char* before_lang, const char* current_lang)
78 SLOG(LOG_DEBUG, TAG_VCW, "Lang changed : Before lang(%s) Current lang(%s)",
79 before_lang, current_lang);
81 vc_current_language_changed_cb callback;
83 vc_widget_client_get_current_lang_changed_cb(g_vc_w, &callback, &lang_user_data);
85 if (NULL != callback) {
86 vc_widget_client_use_callback(g_vc_w);
87 callback(before_lang, current_lang, lang_user_data);
88 vc_widget_client_not_use_callback(g_vc_w);
89 SLOG(LOG_DEBUG, TAG_VCW, "Language changed callback is called");
91 SLOG(LOG_WARN, TAG_VCW, "[WARNING] Language changed callback is null");
97 int vc_widget_initialize()
99 SLOG(LOG_DEBUG, TAG_VCW, "===== [Widget] Initialize");
102 if (true == vc_widget_client_is_valid(g_vc_w)) {
103 SLOG(LOG_ERROR, TAG_VCW, "[WARNING] Already initialized");
104 return VC_ERROR_NONE;
107 if (0 == vc_widget_client_get_count()) {
108 if (0 != vc_widget_dbus_open_connection()) {
109 SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Fail to open connection");
110 return VC_ERROR_OPERATION_FAILED;
113 SLOG(LOG_WARN, TAG_VCW, "[WARN] Already initialized");
114 return VC_ERROR_NONE;
117 if (0 != vc_widget_client_create(&g_vc_w)) {
118 SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Fail to create client!!!!!");
119 return VC_ERROR_OUT_OF_MEMORY;
122 int ret = vc_config_mgr_initialize(g_vc_w->handle + VC_WIDGET_CONFIG_HANDLE);
124 SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Fail to init config manager : %s",
125 __vc_widget_get_error_code(__vc_widget_convert_config_error_code(ret)));
126 vc_widget_client_destroy(g_vc_w);
127 return __vc_widget_convert_config_error_code(ret);
130 ret = vc_config_mgr_set_lang_cb(g_vc_w->handle + VC_WIDGET_CONFIG_HANDLE, __vc_widget_lang_changed_cb);
132 SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Fail to set config changed : %d", ret);
133 vc_config_mgr_finalize(g_vc_w->handle + VC_WIDGET_CONFIG_HANDLE);
134 vc_widget_client_destroy(g_vc_w);
135 return __vc_widget_convert_config_error_code(ret);
138 SLOG(LOG_DEBUG, TAG_VCW, "[Success] pid(%d)", g_vc_w->handle);
140 SLOG(LOG_DEBUG, TAG_VCW, "=====");
141 SLOG(LOG_DEBUG, TAG_VCW, " ");
143 return VC_ERROR_NONE;
146 static void __vc_widget_internal_unprepare()
148 int ret = vc_widget_dbus_request_finalize(g_vc_w->handle);
150 SLOG(LOG_WARN, TAG_VCW, "[ERROR] Fail to request finalize : %s", __vc_widget_get_error_code(ret));
153 vc_cmd_parser_delete_file(getpid(), VC_COMMAND_TYPE_WIDGET);
158 int vc_widget_deinitialize()
160 SLOG(LOG_DEBUG, TAG_VCW, "===== [Widget] Deinitialize");
162 if (false == vc_widget_client_is_valid(g_vc_w)) {
163 SLOG(LOG_ERROR, TAG_VCW, "[ERROR] NOT initialized");
164 SLOG(LOG_DEBUG, TAG_VCW, "=====");
165 SLOG(LOG_DEBUG, TAG_VCW, " ");
166 return VC_ERROR_INVALID_STATE;
170 vc_widget_client_get_state(g_vc_w, &state);
175 __vc_widget_internal_unprepare();
176 /* no break. need to next step*/
177 case VC_STATE_INITIALIZED:
178 if (NULL != g_w_connect_timer) {
179 SLOG(LOG_DEBUG, TAG_VCW, "Connect Timer is deleted");
180 ecore_timer_del(g_w_connect_timer);
183 vc_config_mgr_unset_lang_cb(g_vc_w->handle + VC_WIDGET_CONFIG_HANDLE);
184 vc_config_mgr_finalize(g_vc_w->handle + VC_WIDGET_CONFIG_HANDLE);
187 vc_widget_client_destroy(g_vc_w);
196 SLOG(LOG_DEBUG, TAG_VCW, "Success: destroy");
198 if (0 != vc_widget_dbus_close_connection()) {
199 SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Fail to close connection");
202 SLOG(LOG_DEBUG, TAG_VCW, "=====");
203 SLOG(LOG_DEBUG, TAG_VCW, " ");
205 return VC_ERROR_NONE;
208 static Eina_Bool __vc_widget_connect_daemon(void *data)
211 if (0 != vc_widget_dbus_request_hello()) {
215 SLOG(LOG_DEBUG, TAG_VCW, "===== [Widget] Connect daemon");
217 /* request initialization */
219 int service_state = 0;
220 ret = vc_widget_dbus_request_initialize(g_vc_w->handle, &service_state);
222 if (VC_ERROR_ENGINE_NOT_FOUND == ret) {
223 SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Fail to initialize : %s", __vc_widget_get_error_code(ret));
225 vc_widget_client_set_error(g_vc_w, VC_ERROR_ENGINE_NOT_FOUND);
226 ecore_timer_add(0, __vc_widget_notify_error, g_vc_w);
228 SLOG(LOG_DEBUG, TAG_VCW, "=====");
229 SLOG(LOG_DEBUG, TAG_VCW, " ");
232 } else if (VC_ERROR_NONE != ret) {
233 SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Fail to initialize : %s", __vc_widget_get_error_code(ret));
235 vc_widget_client_set_error(g_vc_w, VC_ERROR_TIMED_OUT);
236 ecore_timer_add(0, __vc_widget_notify_error, g_vc_w);
238 SLOG(LOG_DEBUG, TAG_VCW, "=====");
239 SLOG(LOG_DEBUG, TAG_VCW, " ");
243 vc_widget_client_set_service_state(g_vc_w, (vc_service_state_e)service_state);
245 vc_widget_client_set_state(g_vc_w, VC_STATE_READY);
246 ecore_timer_add(0, __vc_widget_notify_state_changed, g_vc_w);
248 g_w_connect_timer = NULL;
250 SLOG(LOG_DEBUG, TAG_VCW, "=====");
251 SLOG(LOG_DEBUG, TAG_VCW, " ");
256 int vc_widget_prepare()
258 SLOG(LOG_DEBUG, TAG_VCW, "===== [Widget] Prepare");
261 if (0 != vc_widget_client_get_state(g_vc_w, &state)) {
262 SLOG(LOG_ERROR, TAG_VCW, "[ERROR] A handle is not available");
263 SLOG(LOG_DEBUG, TAG_VCW, "=====");
264 SLOG(LOG_DEBUG, TAG_VCW, " ");
265 return VC_ERROR_INVALID_STATE;
269 if (state != VC_STATE_INITIALIZED) {
270 SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Invalid State: Current state is not 'Initialized'");
271 SLOG(LOG_DEBUG, TAG_VCW, "=====");
272 SLOG(LOG_DEBUG, TAG_VCW, " ");
273 return VC_ERROR_INVALID_STATE;
276 g_w_connect_timer = ecore_timer_add(0, __vc_widget_connect_daemon, NULL);
278 SLOG(LOG_DEBUG, TAG_VCW, "=====");
279 SLOG(LOG_DEBUG, TAG_VCW, " ");
281 return VC_ERROR_NONE;
284 int vc_widget_unprepare()
286 SLOG(LOG_DEBUG, TAG_VCW, "===== [Widget] Unprepare");
289 if (0 != vc_widget_client_get_state(g_vc_w, &state)) {
290 SLOG(LOG_ERROR, TAG_VCW, "[ERROR] A handle is not available");
291 SLOG(LOG_DEBUG, TAG_VCW, "=====");
292 SLOG(LOG_DEBUG, TAG_VCW, " ");
293 return VC_ERROR_INVALID_STATE;
297 if (state != VC_STATE_READY) {
298 SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Invalid State: Current state is not 'READY'");
299 SLOG(LOG_DEBUG, TAG_VCW, "=====");
300 SLOG(LOG_DEBUG, TAG_VCW, " ");
301 return VC_ERROR_INVALID_STATE;
304 __vc_widget_internal_unprepare();
306 vc_widget_client_set_state(g_vc_w, VC_STATE_INITIALIZED);
307 ecore_timer_add(0, __vc_widget_notify_state_changed, g_vc_w);
309 SLOG(LOG_DEBUG, TAG_VCW, "=====");
310 SLOG(LOG_DEBUG, TAG_VCW, " ");
312 return VC_ERROR_NONE;
315 int vc_widget_foreach_supported_languages(vc_supported_language_cb callback, void* user_data)
317 SLOG(LOG_DEBUG, TAG_VCW, "===== [Widget] Foreach Supported Language");
319 if (NULL == callback) {
320 SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Input parameter is NULL");
321 SLOG(LOG_DEBUG, TAG_VCW, "=====");
322 SLOG(LOG_DEBUG, TAG_VCW, " ");
323 return VC_ERROR_INVALID_PARAMETER;
327 if (0 != vc_widget_client_get_state(g_vc_w, &state)) {
328 SLOG(LOG_ERROR, TAG_VCW, "[ERROR] A handle is not available");
329 SLOG(LOG_DEBUG, TAG_VCW, "=====");
330 SLOG(LOG_DEBUG, TAG_VCW, " ");
331 return VC_ERROR_INVALID_STATE;
335 ret = vc_config_mgr_get_language_list(callback, user_data);
337 ret = vc_config_convert_error_code((vc_config_error_e)ret);
338 SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Fail to get languages : %s", __vc_widget_get_error_code(ret));
341 SLOG(LOG_DEBUG, TAG_VCW, "=====");
342 SLOG(LOG_DEBUG, TAG_VCW, " ");
344 return VC_ERROR_NONE;
347 int vc_widget_get_current_language(char** language)
349 SLOG(LOG_DEBUG, TAG_VCW, "===== [Widget] Get Current Language");
351 if (NULL == language) {
352 SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Input parameter is NULL");
353 SLOG(LOG_DEBUG, TAG_VCW, "=====");
354 SLOG(LOG_DEBUG, TAG_VCW, " ");
355 return VC_ERROR_INVALID_PARAMETER;
359 if (0 != vc_widget_client_get_state(g_vc_w, &state)) {
360 SLOG(LOG_ERROR, TAG_VCW, "[ERROR] A handle is not available");
361 SLOG(LOG_DEBUG, TAG_VCW, "=====");
362 SLOG(LOG_DEBUG, TAG_VCW, " ");
363 return VC_ERROR_INVALID_STATE;
367 ret = vc_config_mgr_get_default_language(language);
369 ret = vc_config_convert_error_code((vc_config_error_e)ret);
370 SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Fail to get current languages : %s", __vc_widget_get_error_code(ret));
373 SLOG(LOG_DEBUG, TAG_VCW, "=====");
374 SLOG(LOG_DEBUG, TAG_VCW, " ");
379 int vc_widget_get_state(vc_state_e* state)
381 SLOG(LOG_DEBUG, TAG_VCW, "===== [Widget] Get State");
384 SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Input parameter is NULL");
385 return VC_ERROR_INVALID_PARAMETER;
389 if (0 != vc_widget_client_get_state(g_vc_w, &temp)) {
390 SLOG(LOG_ERROR, TAG_VCW, "[ERROR] A handle is not available");
391 SLOG(LOG_DEBUG, TAG_VCW, "=====");
392 SLOG(LOG_DEBUG, TAG_VCW, " ");
393 return VC_ERROR_INVALID_STATE;
399 case VC_STATE_NONE: SLOG(LOG_DEBUG, TAG_VCW, "Current state is 'None'"); break;
400 case VC_STATE_INITIALIZED: SLOG(LOG_DEBUG, TAG_VCW, "Current state is 'Created'"); break;
401 case VC_STATE_READY: SLOG(LOG_DEBUG, TAG_VCW, "Current state is 'Ready'"); break;
402 default: SLOG(LOG_ERROR, TAG_VCW, "Invalid state");
405 SLOG(LOG_DEBUG, TAG_VCW, "=====");
406 SLOG(LOG_DEBUG, TAG_VCW, " ");
408 return VC_ERROR_NONE;
411 int vc_widget_get_service_state(vc_service_state_e* state)
413 SLOG(LOG_DEBUG, TAG_VCW, "===== [Widget] Get Service State");
416 SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Input parameter is NULL");
417 return VC_ERROR_INVALID_PARAMETER;
421 if (0 != vc_widget_client_get_state(g_vc_w, &temp)) {
422 SLOG(LOG_ERROR, TAG_VCW, "[ERROR] A handle is not available");
423 SLOG(LOG_DEBUG, TAG_VCW, "=====");
424 SLOG(LOG_DEBUG, TAG_VCW, " ");
425 return VC_ERROR_INVALID_STATE;
428 if (temp != VC_STATE_READY) {
429 SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Invalid State: Current state is not 'READY'");
430 SLOG(LOG_DEBUG, TAG_VCW, "=====");
431 SLOG(LOG_DEBUG, TAG_VCW, " ");
432 return VC_ERROR_INVALID_STATE;
435 /* get service state */
436 vc_service_state_e service_state;
437 if (0 != vc_widget_client_get_service_state(g_vc_w, &service_state)) {
438 SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Fail to get service state");
439 return VC_ERROR_OPERATION_FAILED;
442 *state = service_state;
445 case VC_SERVICE_STATE_NONE: SLOG(LOG_DEBUG, TAG_VCW, "Current service state is 'None'"); break;
446 case VC_SERVICE_STATE_READY: SLOG(LOG_DEBUG, TAG_VCW, "Current service state is 'Ready'"); break;
447 case VC_SERVICE_STATE_RECORDING: SLOG(LOG_DEBUG, TAG_VCW, "Current service state is 'Recording'"); break;
448 case VC_SERVICE_STATE_PROCESSING: SLOG(LOG_DEBUG, TAG_VCW, "Current service state is 'Processing'"); break;
449 default: SLOG(LOG_ERROR, TAG_VCW, "Invalid service state");
452 SLOG(LOG_DEBUG, TAG_VCW, "=====");
453 SLOG(LOG_DEBUG, TAG_VCW, " ");
455 return VC_ERROR_NONE;
458 int vc_widget_set_foreground(bool value)
460 SLOG(LOG_DEBUG, TAG_VCW, "===== [Widget] Set foreground state");
463 if (0 != vc_widget_client_get_state(g_vc_w, &state)) {
464 SLOG(LOG_ERROR, TAG_VCW, "[ERROR] A handle is not valid");
465 SLOG(LOG_DEBUG, TAG_VCW, "=====");
466 SLOG(LOG_DEBUG, TAG_VCW, " ");
467 return VC_ERROR_INVALID_STATE;
471 if (state != VC_STATE_READY) {
472 SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Invalid State: Current state is not 'READY'");
473 SLOG(LOG_DEBUG, TAG_VCW, "=====");
474 SLOG(LOG_DEBUG, TAG_VCW, " ");
475 return VC_ERROR_INVALID_STATE;
478 SLOG(LOG_DEBUG, TAG_VCW, "Set foreground : pid(%d) value(%s)", getpid(), value ? "true" : "false");
479 int ret = vc_widget_dbus_set_foreground(getpid(), value);
481 ret = vc_config_convert_error_code((vc_config_error_e)ret);
482 SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Fail to set foreground : %s", __vc_widget_get_error_code(ret));
485 SLOG(LOG_DEBUG, TAG_VCW, "=====");
486 SLOG(LOG_DEBUG, TAG_VCW, " ");
488 return VC_ERROR_NONE;
491 int vc_widget_is_format_supported(vc_cmd_format_e format, bool* support)
493 SLOG(LOG_DEBUG, TAG_VCW, "===== [Widget] Is command type supported");
496 if (0 != vc_widget_client_get_state(g_vc_w, &state)) {
497 SLOG(LOG_ERROR, TAG_VCW, "[ERROR] A handle is not valid");
498 SLOG(LOG_DEBUG, TAG_VCW, "=====");
499 SLOG(LOG_DEBUG, TAG_VCW, " ");
500 return VC_ERROR_INVALID_STATE;
504 bool non_fixed_support = false;
505 if (0 != vc_config_mgr_get_nonfixed_support(&non_fixed_support)) {
506 SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Fail to get nonfixed support info");
510 case VC_CMD_FORMAT_FIXED: *support = true; break;
511 case VC_CMD_FORMAT_FIXED_AND_EXTRA: *support = non_fixed_support; break;
512 case VC_CMD_FORMAT_EXTRA_AND_FIXED: *support = non_fixed_support; break;
513 default: *support = false; break;
516 SLOG(LOG_ERROR, TAG_VCW, "[DEBUG] Format(%d) support(%s)", format, *support ? "true" : "false");
518 SLOG(LOG_DEBUG, TAG_VCW, "=====");
519 SLOG(LOG_DEBUG, TAG_VCW, " ");
521 return VC_ERROR_NONE;
525 * @brief Starts recognition.
527 * @param[in] stop_by_silence Silence detection option
529 * @return 0 on success, otherwise a negative error value
530 * @retval #VC_ERROR_NONE Successful
531 * @retval #VC_ERROR_INVALID_PARAMETER Invalid parameter.
532 * @retval #VC_ERROR_INVALID_STATE Invalid state
533 * @retval #VC_ERROR_OPERATION_FAILED Operation failure
535 * @pre The state should be #VC_STATE_READY.
536 * @post It will invoke vc_state_changed_cb(), if you register a callback with vc_state_changed_cb(). \n
537 * If this function succeeds, the state will be #VC_STATE_RECORDING.
539 * @see vc_widget_stop()
540 * @see vc_widget_cancel()
541 * @see vc_state_changed_cb()
544 int vc_widget_start(bool stop_by_silence, vc_cmd_group_h vc_group)
546 SLOG(LOG_DEBUG, TAG_VCW, "===== [Widget] Start");
549 if (0 != vc_widget_client_get_state(g_vc_w, &state)) {
550 SLOG(LOG_ERROR, TAG_VCW, "[ERROR] A handle is not available");
551 SLOG(LOG_DEBUG, TAG_VCW, "=====");
552 SLOG(LOG_DEBUG, TAG_VCW, " ");
553 return VC_ERROR_INVALID_STATE;
557 if (state != VC_STATE_READY) {
558 SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Invalid State: Current state is not 'READY'");
559 SLOG(LOG_DEBUG, TAG_VCW, "=====");
560 SLOG(LOG_DEBUG, TAG_VCW, " ");
561 return VC_ERROR_INVALID_STATE;
564 /* Check service state */
565 vc_service_state_e service_state = -1;
566 vc_widget_client_get_service_state(g_vc_w, &service_state);
567 if (service_state != VC_SERVICE_STATE_READY) {
568 SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Invalid State: service state is not 'READY'");
569 SLOG(LOG_DEBUG, TAG_VCW, "=====");
570 SLOG(LOG_DEBUG, TAG_VCW, " ");
571 return VC_ERROR_INVALID_STATE;
574 int ret = vc_widget_client_set_command_group(g_vc_w, vc_group);
576 SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Fail to set command to client : %d", ret);
581 if (0 > vc_cmd_group_get_cmd_list(vc_group, &list)) {
582 SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Fail to get command list : %d", ret);
586 ret = vc_cmd_parser_save_file(getpid(), VC_COMMAND_GROUP_TYPE_WIDGET, list);
588 ret = vc_config_convert_error_code((vc_config_error_e)ret);
589 SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Fail to save command group : %s", __vc_widget_get_error_code(ret));
593 ret = vc_widget_dbus_request_start(g_vc_w->handle, stop_by_silence);
595 if (VC_ERROR_TIMED_OUT != ret) {
596 SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Fail to request start : %s", __vc_widget_get_error_code(ret));
599 SLOG(LOG_WARN, TAG_VCW, "[WARNING] retry request start : %s", __vc_widget_get_error_code(ret));
602 if (VC_RETRY_COUNT == count) {
603 SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Fail to request");
611 SLOG(LOG_DEBUG, TAG_VCW, "=====");
612 SLOG(LOG_DEBUG, TAG_VCW, " ");
614 return VC_ERROR_NONE;
619 * @brief Stop interrupt.
621 * @return 0 on success, otherwise a negative error value
622 * @retval #VC_ERROR_NONE Successful
623 * @retval #VC_ERROR_INVALID_STATE Invalid state
624 * @retval #VC_ERROR_OPERATION_FAILED Operation failure
626 * @pre The state should be #VC_STATE_RECORDING.
627 * @post It will invoke vc_state_changed_cb(), if you register a callback with vc_state_changed_cb(). \n
628 * If this function succeeds, the state will be #VC_STATE_READY and vc_widget_result_cb() is called.
630 * @see vc_widget_start()
631 * @see vc_widget_cancel()
632 * @see vc_state_changed_cb()
637 SLOG(LOG_DEBUG, TAG_VCW, "===== [Widget] Stop");
640 if (0 != vc_widget_client_get_state(g_vc_w, &state)) {
641 SLOG(LOG_ERROR, TAG_VCW, "[ERROR] A handle is not available");
642 SLOG(LOG_DEBUG, TAG_VCW, "=====");
643 SLOG(LOG_DEBUG, TAG_VCW, " ");
644 return VC_ERROR_INVALID_STATE;
648 if (state != VC_STATE_READY) {
649 SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Invalid State: Current state is not 'READY'");
650 SLOG(LOG_DEBUG, TAG_VCW, "=====");
651 SLOG(LOG_DEBUG, TAG_VCW, " ");
652 return VC_ERROR_INVALID_STATE;
655 /* Check service state */
656 vc_service_state_e service_state = -1;
657 vc_widget_client_get_service_state(g_vc_w, &service_state);
658 if (service_state != VC_SERVICE_STATE_RECORDING) {
659 SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Invalid State: service state is not 'RECORDING'");
660 SLOG(LOG_DEBUG, TAG_VCW, "=====");
661 SLOG(LOG_DEBUG, TAG_VCW, " ");
662 return VC_ERROR_INVALID_STATE;
665 int ret = vc_widget_client_set_command_group(g_vc_w, NULL);
667 SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Fail to set command to client : %d", ret);
671 ret = vc_cmd_parser_delete_file(getpid(), VC_COMMAND_GROUP_TYPE_WIDGET);
673 ret = vc_config_convert_error_code((vc_config_error_e)ret);
674 SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Fail to delete command group : %s", __vc_widget_get_error_code(ret));
679 ret = vc_widget_dbus_request_stop(g_vc_w->handle);
681 if (VC_ERROR_TIMED_OUT != ret) {
682 SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Fail to request stop : %s", __vc_widget_get_error_code(ret));
685 SLOG(LOG_WARN, TAG_VCW, "[WARNING] retry request stop : %s", __vc_widget_get_error_code(ret));
688 if (VC_RETRY_COUNT == count) {
689 SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Fail to request");
700 int vc_widget_cancel()
702 SLOG(LOG_DEBUG, TAG_VCW, "===== [Widget] Cancel Recognition");
705 if (0 != vc_widget_client_get_state(g_vc_w, &state)) {
706 SLOG(LOG_ERROR, TAG_VCW, "[ERROR] A handle is not available");
707 SLOG(LOG_DEBUG, TAG_VCW, "=====");
708 SLOG(LOG_DEBUG, TAG_VCW, " ");
709 return VC_ERROR_INVALID_STATE;
713 if (state != VC_STATE_READY) {
714 SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Invalid State: Current state is not 'READY'");
715 SLOG(LOG_DEBUG, TAG_VCW, "=====");
716 SLOG(LOG_DEBUG, TAG_VCW, " ");
717 return VC_ERROR_INVALID_STATE;
720 /* Check service state */
721 vc_service_state_e service_state = -1;
722 vc_widget_client_get_service_state(g_vc_w, &service_state);
723 if (service_state != VC_SERVICE_STATE_RECORDING && service_state != VC_SERVICE_STATE_PROCESSING) {
724 SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Invalid State: service state is not 'RECORDING' or 'PROCESSING'");
725 SLOG(LOG_DEBUG, TAG_VCW, "=====");
726 SLOG(LOG_DEBUG, TAG_VCW, " ");
727 return VC_ERROR_INVALID_STATE;
734 ret = vc_widget_dbus_request_cancel(g_vc_w->handle);
736 if (VC_ERROR_TIMED_OUT != ret) {
737 SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Fail to request cancel : %s", __vc_widget_get_error_code(ret));
740 SLOG(LOG_WARN, TAG_VCW, "[WARNING] retry request cancel : %s", __vc_widget_get_error_code(ret));
743 if (VC_RETRY_COUNT == count) {
744 SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Fail to request");
751 SLOG(LOG_DEBUG, TAG_VCW, "=====");
756 static Eina_Bool __vc_widget_notify_error(void *data)
758 vc_error_cb callback = NULL;
762 vc_widget_client_get_error_cb(g_vc_w, &callback, &user_data);
763 vc_widget_client_get_error(g_vc_w, &reason);
765 if (NULL != callback) {
766 vc_widget_client_use_callback(g_vc_w);
767 callback(reason, user_data);
768 vc_widget_client_not_use_callback(g_vc_w);
769 SLOG(LOG_DEBUG, TAG_VCW, "[Error] callback is called");
771 SLOG(LOG_WARN, TAG_VCW, "[WARNING] Error callback is null");
777 int __vc_widget_cb_error(int pid, int reason)
779 if (0 != vc_widget_client_get_handle(pid, &g_vc_w)) {
780 SLOG(LOG_ERROR, TAG_VCW, "Handle is not valid : pid(%d)", pid);
784 vc_widget_client_set_error(g_vc_w, reason);
785 ecore_timer_add(0, __vc_widget_notify_error, g_vc_w);
790 static Eina_Bool __vc_widget_start_recording(void *data)
792 if (NULL != g_w_start_timer) {
793 ecore_timer_del(g_w_start_timer);
794 g_w_start_timer = NULL;
797 vc_widget_send_current_command_list_cb send_command_list_cb = NULL;
798 void* send_command_user_data = NULL;
799 vc_cmd_list_h vc_cmd_list = NULL;
801 vc_widget_client_get_send_command_list_cb(g_vc_w, &send_command_list_cb, &send_command_user_data);
803 if (NULL != send_command_list_cb) {
804 vc_widget_client_use_callback(g_vc_w);
805 send_command_list_cb(&vc_cmd_list, send_command_user_data);
806 vc_widget_client_not_use_callback(g_vc_w);
807 SLOG(LOG_DEBUG, TAG_VCW, "client result callback called");
810 SLOG(LOG_ERROR, TAG_VCW, "[ERROR] User show tooltip callback is NULL");
813 bool widget_command = false;
816 if (NULL != vc_cmd_list) {
817 vc_cmd_list_s* list = NULL;
818 list = (vc_cmd_list_s*)vc_cmd_list;
820 ret = vc_cmd_parser_save_file(getpid(), VC_COMMAND_TYPE_WIDGET, list->list);
822 /* widget command is valid */
823 widget_command = true;
824 SLOG(LOG_DEBUG, TAG_VCW, "Widget command is valid");
826 ret = VC_ERROR_OPERATION_FAILED;
827 SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Fail to save command group : %s", __vc_widget_get_error_code(ret));
834 ret = vc_widget_dbus_request_start_recording(g_vc_w->handle, widget_command);
836 if (VC_ERROR_TIMED_OUT != ret) {
837 SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Fail to request start recording to daemon : %s", __vc_widget_get_error_code(ret));
840 SLOG(LOG_WARN, TAG_VCW, "[WARNING] retry start recording : %s", __vc_widget_get_error_code(ret));
843 if (VC_RETRY_COUNT == count) {
844 SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Fail to request");
854 static Eina_Bool __vc_widget_notify_tooltip(void *data)
856 if (NULL != g_w_tooltip_timer) {
857 ecore_timer_del(g_w_tooltip_timer);
858 g_w_tooltip_timer = NULL;
861 vc_widget_show_tooltip_cb callback;
865 vc_widget_client_get_show_tooltip_cb(g_vc_w, &callback, &user_data);
866 vc_widget_client_get_show_tooltip(g_vc_w, &show);
868 if (NULL != callback) {
869 vc_widget_client_use_callback(g_vc_w);
870 callback(show, user_data);
871 vc_widget_client_not_use_callback(g_vc_w);
872 SLOG(LOG_DEBUG, TAG_VCW, "client result callback called");
874 SLOG(LOG_WARN, TAG_VCW, "[WARNING] Show tooltip callback is NULL");
878 g_w_start_timer = ecore_timer_add(0, __vc_widget_start_recording, NULL);
884 void __vc_widget_cb_show_tooltip(int pid, bool show)
886 if (0 != vc_widget_client_get_handle(pid, &g_vc_w)) {
887 SLOG(LOG_ERROR, TAG_VCW, "Handle is not valid : pid(%d)", pid);
891 vc_widget_client_set_show_tooltip(g_vc_w, show);
892 g_w_tooltip_timer = ecore_timer_add(0, __vc_widget_notify_tooltip, NULL);
897 static Eina_Bool __vc_widget_notify_result(void *data)
901 vc_cmd_list_h vc_cmd_list = NULL;
903 vc_result_cb callback = NULL;
904 void* user_data = NULL;
906 vc_widget_client_get_result_cb(g_vc_w, &callback, &user_data);
907 if (NULL == callback) {
908 SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Client result callback is NULL");
912 if (0 != vc_cmd_list_create(&vc_cmd_list)) {
913 SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Fail to create command list");
917 vc_info_parser_get_result(&temp_text, &event, NULL, getpid(), vc_cmd_list, false);
919 SLOG(LOG_DEBUG, TAG_VCW, "Result info : result text(%s) event(%d)", temp_text, event);
921 vc_cmd_print_list(vc_cmd_list);
923 vc_widget_client_use_callback(g_vc_w);
924 callback(event, vc_cmd_list, temp_text, user_data);
925 vc_widget_client_not_use_callback(g_vc_w);
927 SLOG(LOG_DEBUG, TAG_VCW, "Widget result callback called");
930 if (NULL != temp_text) free(temp_text);
932 vc_cmd_list_destroy(vc_cmd_list, true);
937 void __vc_widget_cb_result()
939 ecore_timer_add(0, __vc_widget_notify_result, NULL);
944 static Eina_Bool __vc_widget_notify_state_changed(void *data)
946 vc_state_changed_cb changed_callback = NULL;
949 vc_widget_client_get_state_changed_cb(g_vc_w, &changed_callback, &user_data);
951 vc_state_e current_state;
952 vc_state_e before_state;
954 vc_widget_client_get_before_state(g_vc_w, ¤t_state, &before_state);
956 if (NULL != changed_callback) {
957 vc_widget_client_use_callback(g_vc_w);
958 changed_callback(before_state, current_state, user_data);
959 vc_widget_client_not_use_callback(g_vc_w);
960 SLOG(LOG_DEBUG, TAG_VCW, "State changed callback is called");
962 SLOG(LOG_WARN, TAG_VCW, "[WARNING] State changed callback is null");
968 int vc_widget_set_result_cb(vc_result_cb callback, void* user_data)
970 if (NULL == callback)
971 return VC_ERROR_INVALID_PARAMETER;
974 if (0 != vc_widget_client_get_state(g_vc_w, &state)) {
975 return VC_ERROR_INVALID_STATE;
979 if (state != VC_STATE_INITIALIZED) {
980 SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Invalid State: Current state is not 'Initialized'");
981 return VC_ERROR_INVALID_STATE;
984 vc_widget_client_set_result_cb(g_vc_w, callback, user_data);
989 int vc_widget_unset_result_cb()
992 if (0 != vc_widget_client_get_state(g_vc_w, &state)) {
993 SLOG(LOG_ERROR, TAG_VCW, "[ERROR] A handle is not available");
994 return VC_ERROR_INVALID_STATE;
998 if (state != VC_STATE_INITIALIZED) {
999 SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Invalid State: Current state is not 'Initialized'");
1000 return VC_ERROR_INVALID_STATE;
1003 vc_widget_client_set_result_cb(g_vc_w, NULL, NULL);
1008 int vc_widget_set_show_tooltip_cb(vc_widget_show_tooltip_cb callback, void* user_data)
1010 if (NULL == callback)
1011 return VC_ERROR_INVALID_PARAMETER;
1014 if (0 != vc_widget_client_get_state(g_vc_w, &state)) {
1015 SLOG(LOG_ERROR, TAG_VCW, "[ERROR] A handle is not available");
1016 return VC_ERROR_INVALID_STATE;
1020 if (state != VC_STATE_INITIALIZED) {
1021 SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Invalid State: Current state is not 'Initialized'");
1022 return VC_ERROR_INVALID_STATE;
1025 vc_widget_client_set_show_tooltip_cb(g_vc_w, callback, user_data);
1030 int vc_widget_unset_show_tooltip_cb()
1033 if (0 != vc_widget_client_get_state(g_vc_w, &state)) {
1034 SLOG(LOG_ERROR, TAG_VCW, "[ERROR] A handle is not available");
1035 return VC_ERROR_INVALID_STATE;
1039 if (state != VC_STATE_INITIALIZED) {
1040 SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Invalid State: Current state is not 'Initialized'");
1041 return VC_ERROR_INVALID_STATE;
1044 vc_widget_client_set_show_tooltip_cb(g_vc_w, NULL, NULL);
1049 int vc_widget_set_send_current_command_list_cb(vc_widget_send_current_command_list_cb callback, void* user_data)
1052 if (0 != vc_widget_client_get_state(g_vc_w, &state)) {
1053 SLOG(LOG_ERROR, TAG_VCW, "[ERROR] A handle is not available");
1054 return VC_ERROR_INVALID_STATE;
1058 if (state != VC_STATE_INITIALIZED) {
1059 SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Invalid State: Current state is not 'Initialized'");
1060 return VC_ERROR_INVALID_STATE;
1063 vc_widget_client_set_send_command_list_cb(g_vc_w, callback, user_data);
1068 int vc_widget_unsset_send_current_command_list_cb()
1071 if (0 != vc_widget_client_get_state(g_vc_w, &state)) {
1072 SLOG(LOG_ERROR, TAG_VCW, "[ERROR] A handle is not available");
1073 return VC_ERROR_INVALID_STATE;
1077 if (state != VC_STATE_INITIALIZED) {
1078 SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Invalid State: Current state is not 'Initialized'");
1079 return VC_ERROR_INVALID_STATE;
1082 vc_widget_client_set_send_command_list_cb(g_vc_w, NULL, NULL);
1087 int __vc_widget_cb_service_state(int state)
1089 vc_service_state_e current_state = (vc_service_state_e)state;
1090 vc_service_state_e before_state;
1091 vc_widget_client_get_service_state(g_vc_w, &before_state);
1093 if (current_state == before_state) {
1097 SLOG(LOG_DEBUG, TAG_VCW, "Service State changed : Before(%d) Current(%d)",
1098 before_state, current_state);
1100 /* Save service state */
1101 vc_widget_client_set_service_state(g_vc_w, current_state);
1103 vc_service_state_changed_cb callback = NULL;
1104 void* service_user_data = NULL;
1105 vc_widget_client_get_service_state_changed_cb(g_vc_w, &callback, &service_user_data);
1107 if (NULL != callback) {
1108 vc_widget_client_use_callback(g_vc_w);
1109 callback((vc_service_state_e)before_state, (vc_service_state_e)current_state, service_user_data);
1110 vc_widget_client_not_use_callback(g_vc_w);
1111 SLOG(LOG_DEBUG, TAG_VCW, "Service state changed callback is called");
1113 SLOG(LOG_WARN, TAG_VCW, "[WARNING] Service state changed callback is null");
1119 int vc_widget_set_service_state_changed_cb(vc_service_state_changed_cb callback, void* user_data)
1122 if (0 != vc_widget_client_get_state(g_vc_w, &state)) {
1123 SLOG(LOG_ERROR, TAG_VCW, "[ERROR] A handle is not available");
1124 return VC_ERROR_INVALID_STATE;
1128 if (state != VC_STATE_INITIALIZED) {
1129 SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Invalid State: Current state is not 'Initialized'");
1130 return VC_ERROR_INVALID_STATE;
1133 vc_widget_client_set_service_state_changed_cb(g_vc_w, callback, user_data);
1138 int vc_widget_unset_service_state_changed_cb()
1141 if (0 != vc_widget_client_get_state(g_vc_w, &state)) {
1142 SLOG(LOG_ERROR, TAG_VCW, "[ERROR] A handle is not available");
1143 return VC_ERROR_INVALID_STATE;
1147 if (state != VC_STATE_INITIALIZED) {
1148 SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Invalid State: Current state is not 'Initialized'");
1149 return VC_ERROR_INVALID_STATE;
1152 vc_widget_client_set_service_state_changed_cb(g_vc_w, NULL, NULL);
1157 int vc_widget_set_state_changed_cb(vc_state_changed_cb callback, void* user_data)
1159 if (NULL == callback)
1160 return VC_ERROR_INVALID_PARAMETER;
1163 if (0 != vc_widget_client_get_state(g_vc_w, &state)) {
1164 SLOG(LOG_ERROR, TAG_VCW, "[ERROR] A handle is not available");
1165 return VC_ERROR_INVALID_STATE;
1169 if (state != VC_STATE_INITIALIZED) {
1170 SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Invalid State: Current state is not 'Initialized'");
1171 return VC_ERROR_INVALID_STATE;
1174 vc_widget_client_set_state_changed_cb(g_vc_w, callback, user_data);
1179 int vc_widget_unset_state_changed_cb()
1182 if (0 != vc_widget_client_get_state(g_vc_w, &state)) {
1183 SLOG(LOG_ERROR, TAG_VCW, "[ERROR] A handle is not available");
1184 return VC_ERROR_INVALID_STATE;
1188 if (state != VC_STATE_INITIALIZED) {
1189 SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Invalid State: Current state is not 'Initialized'");
1190 return VC_ERROR_INVALID_STATE;
1193 vc_widget_client_set_state_changed_cb(g_vc_w, NULL, NULL);
1198 int vc_widget_set_current_language_changed_cb(vc_current_language_changed_cb callback, void* user_data)
1200 if (NULL == callback)
1201 return VC_ERROR_INVALID_PARAMETER;
1204 if (0 != vc_widget_client_get_state(g_vc_w, &state)) {
1205 SLOG(LOG_ERROR, TAG_VCW, "[ERROR] A handle is not available");
1206 return VC_ERROR_INVALID_STATE;
1210 if (state != VC_STATE_INITIALIZED) {
1211 SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Invalid State: Current state is not 'Initialized'");
1212 return VC_ERROR_INVALID_STATE;
1215 vc_widget_client_set_current_lang_changed_cb(g_vc_w, callback, user_data);
1220 int vc_widget_unset_current_language_changed_cb()
1223 if (0 != vc_widget_client_get_state(g_vc_w, &state)) {
1224 SLOG(LOG_ERROR, TAG_VCW, "[ERROR] A handle is not available");
1225 return VC_ERROR_INVALID_STATE;
1229 if (state != VC_STATE_INITIALIZED) {
1230 SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Invalid State: Current state is not 'Initialized'");
1231 return VC_ERROR_INVALID_STATE;
1234 vc_widget_client_set_current_lang_changed_cb(g_vc_w, NULL, NULL);
1239 int vc_widget_set_error_cb(vc_error_cb callback, void* user_data)
1241 if (NULL == callback)
1242 return VC_ERROR_INVALID_PARAMETER;
1245 if (0 != vc_widget_client_get_state(g_vc_w, &state)) {
1246 SLOG(LOG_ERROR, TAG_VCW, "[ERROR] A handle is not available");
1247 return VC_ERROR_INVALID_STATE;
1251 if (state != VC_STATE_INITIALIZED) {
1252 SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Invalid State: Current state is not 'Initialized'");
1253 return VC_ERROR_INVALID_STATE;
1256 vc_widget_client_set_error_cb(g_vc_w, callback, user_data);
1261 int vc_widget_unset_error_cb()
1264 if (0 != vc_widget_client_get_state(g_vc_w, &state)) {
1265 SLOG(LOG_ERROR, TAG_VCW, "[ERROR] A handle is not available");
1266 return VC_ERROR_INVALID_STATE;
1270 if (state != VC_STATE_INITIALIZED) {
1271 SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Invalid State: Current state is not 'Initialized'");
1272 return VC_ERROR_INVALID_STATE;
1275 vc_widget_client_set_error_cb(g_vc_w, NULL, NULL);