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 <system_info.h>
20 #include "vc_cmd_db.h"
21 #include "vc_config_mgr.h"
22 #include "vc_command.h"
23 #include "vc_info_parser.h"
24 #include "vc_json_parser.h"
26 #include "vc_mgr_client.h"
27 #include "vc_mgr_dbus.h"
28 #include "voice_control.h"
29 #include "voice_control_command.h"
30 #include "voice_control_command_expand.h"
31 #include "voice_control_common.h"
32 #include "voice_control_manager.h"
35 #define VC_MANAGER_CONFIG_HANDLE 100000
37 static Ecore_Timer* g_m_connect_timer = NULL;
39 static Ecore_Timer* g_m_set_volume_timer = NULL;
41 static vc_h g_vc_m = NULL;
43 static GSList* g_demandable_client_list = NULL;
45 static float g_volume_db = 0;
47 static float g_prev_volume_db = 0;
49 static float g_cur_volume_db = 0;
51 static int g_daemon_pid = 0;
53 static int g_feature_enabled = -1;
55 static bool g_err_callback_status = false;
57 static Eina_Bool __vc_mgr_notify_state_changed(void *data);
58 static Eina_Bool __vc_mgr_notify_error(void *data);
59 static Eina_Bool __vc_mgr_notify_result(void *data);
61 static const char* __vc_mgr_get_error_code(vc_error_e err)
64 case VC_ERROR_NONE: return "VC_ERROR_NONE";
65 case VC_ERROR_OUT_OF_MEMORY: return "VC_ERROR_OUT_OF_MEMORY";
66 case VC_ERROR_IO_ERROR: return "VC_ERROR_IO_ERROR";
67 case VC_ERROR_INVALID_PARAMETER: return "VC_ERROR_INVALID_PARAMETER";
68 case VC_ERROR_TIMED_OUT: return "VC_ERROR_TIMED_OUT";
69 case VC_ERROR_RECORDER_BUSY: return "VC_ERROR_RECORDER_BUSY";
70 case VC_ERROR_INVALID_STATE: return "VC_ERROR_INVALID_STATE";
71 case VC_ERROR_INVALID_LANGUAGE: return "VC_ERROR_INVALID_LANGUAGE";
72 case VC_ERROR_ENGINE_NOT_FOUND: return "VC_ERROR_ENGINE_NOT_FOUND";
73 case VC_ERROR_OPERATION_FAILED: return "VC_ERROR_OPERATION_FAILED";
74 default: return "Invalid error code";
79 static void __vc_mgr_lang_changed_cb(const char* before_lang, const char* current_lang)
81 SLOG(LOG_DEBUG, TAG_VCM, "Lang changed : Before lang(%s) Current lang(%s)",
82 before_lang, current_lang);
84 vc_current_language_changed_cb callback = NULL;
86 vc_mgr_client_get_current_lang_changed_cb(g_vc_m, &callback, &lang_user_data);
88 if (NULL != callback) {
89 vc_mgr_client_use_callback(g_vc_m);
90 callback(before_lang, current_lang, lang_user_data);
91 vc_mgr_client_not_use_callback(g_vc_m);
92 SLOG(LOG_DEBUG, TAG_VCM, "Language changed callback is called");
94 SLOG(LOG_WARN, TAG_VCM, "[WARNING] Language changed callback is null");
100 static int __vc_mgr_get_feature_enabled()
102 if (0 == g_feature_enabled) {
103 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Voice control feature NOT supported");
104 return VC_ERROR_NOT_SUPPORTED;
105 } else if (-1 == g_feature_enabled) {
106 bool vc_supported = false;
107 bool mic_supported = false;
108 if (0 == system_info_get_platform_bool(VC_FEATURE_PATH, &vc_supported)) {
109 if (0 == system_info_get_platform_bool(VC_MIC_FEATURE_PATH, &mic_supported)) {
110 if (false == vc_supported || false == mic_supported) {
111 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Voice control feature NOT supported");
112 g_feature_enabled = 0;
113 return VC_ERROR_NOT_SUPPORTED;
116 g_feature_enabled = 1;
124 int vc_mgr_initialize()
126 SLOG(LOG_DEBUG, TAG_VCM, "===== [Manager] Initialize");
129 if (0 != __vc_mgr_get_feature_enabled()) {
130 SLOG(LOG_DEBUG, TAG_VCM, "===== [Manager] not supported");
131 return VC_ERROR_NOT_SUPPORTED;
135 if (true == vc_mgr_client_is_valid(g_vc_m)) {
136 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Already initialized");
137 return VC_ERROR_NONE;
140 if (0 != vc_mgr_dbus_open_connection()) {
141 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to open connection");
142 return VC_ERROR_OPERATION_FAILED;
145 if (0 != vc_mgr_client_create(&g_vc_m)) {
146 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to create client!!!!!");
147 return VC_ERROR_OUT_OF_MEMORY;
150 int ret = vc_config_mgr_initialize(g_vc_m->handle + VC_MANAGER_CONFIG_HANDLE);
152 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to init config manager : %d", ret);
153 vc_mgr_client_destroy(g_vc_m);
154 return VC_ERROR_OPERATION_FAILED;
157 ret = vc_config_mgr_set_lang_cb(g_vc_m->handle + VC_MANAGER_CONFIG_HANDLE, __vc_mgr_lang_changed_cb);
159 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to set callback : %d", ret);
160 vc_config_mgr_finalize(g_vc_m->handle + VC_MANAGER_CONFIG_HANDLE);
161 vc_mgr_client_destroy(g_vc_m);
162 return VC_ERROR_OPERATION_FAILED;
165 ret = vc_db_initialize();
167 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to initialize DB : %d", ret);
168 vc_config_mgr_finalize(g_vc_m->handle + VC_MANAGER_CONFIG_HANDLE);
169 vc_mgr_client_destroy(g_vc_m);
173 SLOG(LOG_DEBUG, TAG_VCM, "[Success] pid(%d)", g_vc_m->handle);
175 SLOG(LOG_DEBUG, TAG_VCM, "=====");
176 SLOG(LOG_DEBUG, TAG_VCM, " ");
178 return VC_ERROR_NONE;
181 static void __vc_mgr_internal_unprepare()
183 int ret = vc_mgr_dbus_request_finalize(g_vc_m->handle);
185 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to request finalize : %s", __vc_mgr_get_error_code(ret));
188 vc_mgr_client_set_internal_state(g_vc_m, VC_INTERNAL_STATE_NONE);
192 int vc_mgr_deinitialize()
194 SLOG(LOG_DEBUG, TAG_VCM, "===== [Manager] Deinitialize");
196 if (false == vc_mgr_client_is_valid(g_vc_m)) {
197 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] NOT initialized");
198 SLOG(LOG_DEBUG, TAG_VCM, "=====");
199 SLOG(LOG_DEBUG, TAG_VCM, " ");
200 return VC_ERROR_INVALID_STATE;
204 vc_mgr_client_get_client_state(g_vc_m, &state);
209 __vc_mgr_internal_unprepare();
210 /* no break. need to next step*/
211 case VC_STATE_INITIALIZED:
212 if (NULL != g_m_connect_timer) {
213 SLOG(LOG_DEBUG, TAG_VCM, "Connect Timer is deleted");
214 ecore_timer_del(g_m_connect_timer);
215 g_m_connect_timer = NULL;
218 vc_config_mgr_unset_lang_cb(g_vc_m->handle + VC_MANAGER_CONFIG_HANDLE);
219 vc_config_mgr_finalize(g_vc_m->handle + VC_MANAGER_CONFIG_HANDLE);
221 /* Free client resources */
222 vc_mgr_client_destroy(g_vc_m);
229 SLOG(LOG_DEBUG, TAG_VCM, "Success: destroy");
231 int cnt = VC_COMMAND_TYPE_FOREGROUND;
233 int ret = vc_cmd_parser_delete_file(getpid(), cnt);
235 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to delete file, type(%d), ret(%d)", cnt, ret);
236 } while (VC_COMMAND_TYPE_EXCLUSIVE >= ++cnt);
238 int ret = vc_db_finalize();
240 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to finalize DB, ret(%d)", ret);
243 if (0 != vc_mgr_dbus_close_connection()) {
244 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to close connection");
247 SLOG(LOG_DEBUG, TAG_VCM, "=====");
248 SLOG(LOG_DEBUG, TAG_VCM, " ");
250 return VC_ERROR_NONE;
253 static Eina_Bool __vc_mgr_connect_daemon(void *data)
255 /* request initialization */
257 int service_state = 0;
258 int foreground = VC_RUNTIME_INFO_NO_FOREGROUND;
260 g_m_connect_timer = NULL;
262 ret = vc_mgr_dbus_request_initialize(g_vc_m->handle, &service_state, &foreground, &g_daemon_pid);
264 if (VC_ERROR_ENGINE_NOT_FOUND == ret) {
265 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to initialize : %s", __vc_mgr_get_error_code(ret));
267 vc_mgr_client_set_error(g_vc_m, VC_ERROR_ENGINE_NOT_FOUND);
268 ecore_timer_add(0, __vc_mgr_notify_error, g_vc_m);
270 SLOG(LOG_DEBUG, TAG_VCM, "=====");
271 SLOG(LOG_DEBUG, TAG_VCM, " ");
274 } else if (0 != ret) {
275 SLOG(LOG_ERROR, TAG_VCM, "[WARNING] Fail to connection. Retry to connect : %s", __vc_mgr_get_error_code(ret));
278 /* Success to connect */
281 /* Set service state */
282 vc_mgr_client_set_service_state(g_vc_m, (vc_service_state_e)service_state);
285 vc_mgr_client_set_foreground(g_vc_m, foreground, true);
287 SLOG(LOG_DEBUG, TAG_VCM, "[SUCCESS] Connected daemon");
289 vc_mgr_client_set_client_state(g_vc_m, VC_STATE_READY);
291 vc_state_changed_cb changed_callback = NULL;
292 void* user_data = NULL;
294 vc_mgr_client_get_state_changed_cb(g_vc_m, &changed_callback, &user_data);
296 vc_state_e current_state;
297 vc_state_e before_state;
299 vc_mgr_client_get_before_state(g_vc_m, ¤t_state, &before_state);
301 if (NULL != changed_callback) {
302 vc_mgr_client_use_callback(g_vc_m);
303 changed_callback(before_state, current_state, user_data);
304 vc_mgr_client_not_use_callback(g_vc_m);
305 SLOG(LOG_DEBUG, TAG_VCM, "State changed callback is called");
307 SLOG(LOG_WARN, TAG_VCM, "[WARNING] State changed callback is null");
310 SLOG(LOG_DEBUG, TAG_VCM, "=====");
311 SLOG(LOG_DEBUG, TAG_VCM, " ");
316 static void __start_prepare_thread(void *data, Ecore_Thread *thread)
318 SLOG(LOG_ERROR, TAG_VCM, "===== Start prepare thread");
319 int ret = 1, retry_count = 0;
324 if (retry_count == 10) {
325 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to request hello !!");
329 ret = vc_mgr_dbus_request_hello();
331 SLOG(LOG_DEBUG, TAG_VCM, "Success to request hello. retry count(%d)", retry_count);
342 if (retry_count == 10) {
343 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to connect daemon !!");
346 ret = __vc_mgr_connect_daemon(NULL);
356 static void __end_prepare_thread(void *data, Ecore_Thread *thread)
358 SLOG(LOG_DEBUG, TAG_VCM, "===== End prepare thread");
363 SLOG(LOG_DEBUG, TAG_VCM, "===== [Manager] Prepare");
366 if (0 != vc_mgr_client_get_client_state(g_vc_m, &state)) {
367 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] A handle is not available");
368 SLOG(LOG_DEBUG, TAG_VCM, "=====");
369 SLOG(LOG_DEBUG, TAG_VCM, " ");
370 return VC_ERROR_INVALID_STATE;
374 if (state != VC_STATE_INITIALIZED) {
375 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Invalid State: Current state is not 'CREATED'");
376 SLOG(LOG_DEBUG, TAG_VCM, "=====");
377 SLOG(LOG_DEBUG, TAG_VCM, " ");
378 return VC_ERROR_INVALID_STATE;
381 ecore_thread_run(__start_prepare_thread, __end_prepare_thread, NULL, NULL);
383 SLOG(LOG_DEBUG, TAG_VCM, "=====");
384 SLOG(LOG_DEBUG, TAG_VCM, " ");
386 return VC_ERROR_NONE;
389 int vc_mgr_unprepare()
391 SLOG(LOG_DEBUG, TAG_VCM, "===== [Manager] Unprepare");
394 if (0 != vc_mgr_client_get_client_state(g_vc_m, &state)) {
395 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] A handle is not available");
396 SLOG(LOG_DEBUG, TAG_VCM, "=====");
397 SLOG(LOG_DEBUG, TAG_VCM, " ");
398 return VC_ERROR_INVALID_STATE;
402 if (state != VC_STATE_READY) {
403 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Invalid State: Current state is not 'READY'");
404 SLOG(LOG_DEBUG, TAG_VCM, "=====");
405 SLOG(LOG_DEBUG, TAG_VCM, " ");
406 return VC_ERROR_INVALID_STATE;
409 __vc_mgr_internal_unprepare();
411 vc_mgr_client_set_client_state(g_vc_m, VC_STATE_INITIALIZED);
412 ecore_timer_add(0, __vc_mgr_notify_state_changed, g_vc_m);
414 SLOG(LOG_DEBUG, TAG_VCM, "=====");
415 SLOG(LOG_DEBUG, TAG_VCM, " ");
417 return VC_ERROR_NONE;
420 int vc_mgr_foreach_supported_languages(vc_supported_language_cb callback, void* user_data)
422 SLOG(LOG_DEBUG, TAG_VCM, "===== [Manager] Foreach Supported Language");
424 if (NULL == callback) {
425 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Input parameter is NULL");
426 SLOG(LOG_DEBUG, TAG_VCM, "=====");
427 SLOG(LOG_DEBUG, TAG_VCM, " ");
428 return VC_ERROR_INVALID_PARAMETER;
432 if (0 != vc_mgr_client_get_client_state(g_vc_m, &state)) {
433 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] A handle is not available");
434 SLOG(LOG_DEBUG, TAG_VCM, "=====");
435 SLOG(LOG_DEBUG, TAG_VCM, " ");
436 return VC_ERROR_INVALID_STATE;
440 ret = vc_config_mgr_get_language_list(callback, user_data);
442 ret = vc_config_convert_error_code((vc_config_error_e)ret);
443 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to get languages : %s", __vc_mgr_get_error_code(ret));
446 SLOG(LOG_DEBUG, TAG_VCM, "=====");
447 SLOG(LOG_DEBUG, TAG_VCM, " ");
449 return VC_ERROR_NONE;
452 int vc_mgr_get_current_language(char** language)
454 if (NULL == language) {
455 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Input parameter is NULL");
456 return VC_ERROR_INVALID_PARAMETER;
460 if (0 != vc_mgr_client_get_client_state(g_vc_m, &state)) {
461 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] A handle is not available");
462 return VC_ERROR_INVALID_STATE;
466 ret = vc_config_mgr_get_default_language(language);
468 ret = vc_config_convert_error_code((vc_config_error_e)ret);
469 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to get current languages : %s", __vc_mgr_get_error_code(ret));
471 SLOG(LOG_DEBUG, TAG_VCM, "[Get current language] language : %s", *language);
477 int vc_mgr_get_state(vc_state_e* state)
479 SLOG(LOG_DEBUG, TAG_VCM, "===== [Manager] Get State");
482 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Input parameter is NULL");
483 return VC_ERROR_INVALID_PARAMETER;
487 if (0 != vc_mgr_client_get_client_state(g_vc_m, &temp)) {
488 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] A handle is not available");
489 SLOG(LOG_DEBUG, TAG_VCM, "=====");
490 SLOG(LOG_DEBUG, TAG_VCM, " ");
491 return VC_ERROR_INVALID_STATE;
497 case VC_STATE_NONE: SLOG(LOG_DEBUG, TAG_VCM, "Current state is 'None'"); break;
498 case VC_STATE_INITIALIZED: SLOG(LOG_DEBUG, TAG_VCM, "Current state is 'Created'"); break;
499 case VC_STATE_READY: SLOG(LOG_DEBUG, TAG_VCM, "Current state is 'Ready'"); break;
500 default: SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Invalid state");
503 SLOG(LOG_DEBUG, TAG_VCM, "=====");
504 SLOG(LOG_DEBUG, TAG_VCM, " ");
506 return VC_ERROR_NONE;
509 int vc_mgr_get_service_state(vc_service_state_e* state)
511 SLOG(LOG_DEBUG, TAG_VCM, "===== [Manager] Get Service State");
514 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Input parameter is NULL");
515 return VC_ERROR_INVALID_PARAMETER;
518 vc_state_e client_state;
519 if (0 != vc_mgr_client_get_client_state(g_vc_m, &client_state)) {
520 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] A handle is not available");
521 return VC_ERROR_INVALID_STATE;
525 if (client_state != VC_STATE_READY) {
526 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Current state is not 'READY'");
527 return VC_ERROR_INVALID_STATE;
530 /* get service state */
531 vc_service_state_e service_state;
532 if (0 != vc_mgr_client_get_service_state(g_vc_m, &service_state)) {
533 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to get service state");
534 return VC_ERROR_OPERATION_FAILED;
537 *state = service_state;
540 case VC_SERVICE_STATE_NONE: SLOG(LOG_DEBUG, TAG_VCM, "Current service state is 'None'"); break;
541 case VC_SERVICE_STATE_READY: SLOG(LOG_DEBUG, TAG_VCM, "Current service state is 'Ready'"); break;
542 case VC_SERVICE_STATE_RECORDING: SLOG(LOG_DEBUG, TAG_VCM, "Current service state is 'Recording'"); break;
543 case VC_SERVICE_STATE_PROCESSING: SLOG(LOG_DEBUG, TAG_VCM, "Current service state is 'Processing'"); break;
544 default: SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Invalid state");
547 SLOG(LOG_DEBUG, TAG_VCM, "=====");
548 SLOG(LOG_DEBUG, TAG_VCM, " ");
550 return VC_ERROR_NONE;
553 int vc_mgr_set_demandable_client_rule(const char* rule)
555 SLOG(LOG_DEBUG, TAG_VCM, "===== [Manager] Set Demandable client rule");
558 if (0 != vc_mgr_client_get_client_state(g_vc_m, &state)) {
559 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] A handle is not available");
560 SLOG(LOG_DEBUG, TAG_VCM, "=====");
561 SLOG(LOG_DEBUG, TAG_VCM, " ");
562 return VC_ERROR_INVALID_STATE;
566 if (state != VC_STATE_READY) {
567 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Invalid State: Current state is not 'READY'");
568 SLOG(LOG_DEBUG, TAG_VCM, "=====");
569 SLOG(LOG_DEBUG, TAG_VCM, " ");
570 return VC_ERROR_INVALID_STATE;
574 ret = vc_info_parser_set_demandable_client(rule);
576 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] rule is NOT valid");
577 SLOG(LOG_DEBUG, TAG_VCM, "=====");
578 SLOG(LOG_DEBUG, TAG_VCM, " ");
579 return VC_ERROR_INVALID_PARAMETER;
582 if (0 != vc_info_parser_get_demandable_clients(&g_demandable_client_list)) {
583 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to get demandable clients");
584 return VC_ERROR_OPERATION_FAILED;
587 SLOG(LOG_DEBUG, TAG_VCM, "=====");
588 SLOG(LOG_DEBUG, TAG_VCM, " ");
593 int vc_mgr_unset_demandable_client_rule()
595 vc_info_parser_set_demandable_client(NULL);
600 ret = vc_mgr_dbus_request_demandable_client(g_vc_m->handle);
602 if (VC_ERROR_TIMED_OUT != ret) {
603 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to request unset client rule to daemon : %s", __vc_mgr_get_error_code(ret));
606 SLOG(LOG_WARN, TAG_VCM, "[WARNING] retry request unset client rule : %s", __vc_mgr_get_error_code(ret));
609 if (VC_RETRY_COUNT == count) {
610 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to request");
620 int vc_mgr_is_command_format_supported(vc_cmd_format_e format, bool* support)
622 SLOG(LOG_DEBUG, TAG_VCM, "===== [Manager] Is command type supported");
625 if (0 != vc_mgr_client_get_client_state(g_vc_m, &state)) {
626 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] A handle is not available");
627 SLOG(LOG_DEBUG, TAG_VCM, "=====");
628 SLOG(LOG_DEBUG, TAG_VCM, " ");
629 return VC_ERROR_INVALID_STATE;
633 bool non_fixed_support = false;
634 if (0 != vc_config_mgr_get_nonfixed_support(&non_fixed_support)) {
635 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to get nonfixed support info");
639 case VC_CMD_FORMAT_FIXED: *support = true; break;
640 case VC_CMD_FORMAT_FIXED_AND_VFIXED: *support = true; break;
641 case VC_CMD_FORMAT_VFIXED_AND_FIXED: *support = true; break;
642 case VC_CMD_FORMAT_FIXED_AND_NONFIXED: *support = non_fixed_support; break;
643 case VC_CMD_FORMAT_NONFIXED_AND_FIXED: *support = non_fixed_support; break;
644 default: *support = false; break;
647 SLOG(LOG_ERROR, TAG_VCM, "[DEBUG] Format(%d) support(%s)", format, *support ? "true" : "false");
649 SLOG(LOG_DEBUG, TAG_VCM, "=====");
650 SLOG(LOG_DEBUG, TAG_VCM, " ");
652 return VC_ERROR_NONE;
655 int vc_mgr_enable_command_type(int cmd_type)
657 SLOG(LOG_DEBUG, TAG_VCM, "===== [Manager] Enable Command Type");
660 if (0 != vc_mgr_client_get_client_state(g_vc_m, &state)) {
661 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] A handle is not available");
662 SLOG(LOG_DEBUG, TAG_VCM, "=====");
663 SLOG(LOG_DEBUG, TAG_VCM, " ");
664 return VC_ERROR_INVALID_STATE;
668 if (state != VC_STATE_READY) {
669 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Invalid State: Current state is not 'READY'");
670 SLOG(LOG_DEBUG, TAG_VCM, "=====");
671 SLOG(LOG_DEBUG, TAG_VCM, " ");
672 return VC_ERROR_INVALID_STATE;
675 /* Check service state */
676 vc_service_state_e service_state = -1;
677 vc_mgr_client_get_service_state(g_vc_m, &service_state);
678 if (service_state != VC_SERVICE_STATE_READY) {
679 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Invalid State: service state is not 'READY'");
680 SLOG(LOG_DEBUG, TAG_VCM, "=====");
681 SLOG(LOG_DEBUG, TAG_VCM, " ");
682 return VC_ERROR_INVALID_STATE;
688 ret = vc_mgr_dbus_request_enable_command_type(g_vc_m->handle, cmd_type);
690 if (VC_ERROR_TIMED_OUT != ret) {
691 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to request enable command type : %s", __vc_mgr_get_error_code(ret));
694 SLOG(LOG_WARN, TAG_VCM, "[WARNING] retry request enable command type : %s", __vc_mgr_get_error_code(ret));
697 if (VC_RETRY_COUNT == count) {
698 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to request");
705 SLOG(LOG_DEBUG, TAG_VCM, "=====");
706 SLOG(LOG_DEBUG, TAG_VCM, " ");
711 int vc_mgr_disable_command_type(int cmd_type)
713 SLOG(LOG_DEBUG, TAG_VCM, "===== [Manager] Disable Command Type");
716 if (0 != vc_mgr_client_get_client_state(g_vc_m, &state)) {
717 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] A handle is not available");
718 SLOG(LOG_DEBUG, TAG_VCM, "=====");
719 SLOG(LOG_DEBUG, TAG_VCM, " ");
720 return VC_ERROR_INVALID_STATE;
724 if (state != VC_STATE_READY) {
725 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Invalid State: Current state is not 'READY'");
726 SLOG(LOG_DEBUG, TAG_VCM, "=====");
727 SLOG(LOG_DEBUG, TAG_VCM, " ");
728 return VC_ERROR_INVALID_STATE;
731 /* Check service state */
732 vc_service_state_e service_state = -1;
733 vc_mgr_client_get_service_state(g_vc_m, &service_state);
734 if (service_state != VC_SERVICE_STATE_READY) {
735 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Invalid State: service state is not 'READY'");
736 SLOG(LOG_DEBUG, TAG_VCM, "=====");
737 SLOG(LOG_DEBUG, TAG_VCM, " ");
738 return VC_ERROR_INVALID_STATE;
744 ret = vc_mgr_dbus_request_disable_command_type(g_vc_m->handle, cmd_type);
746 if (VC_ERROR_TIMED_OUT != ret) {
747 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to request disable command type : %s", __vc_mgr_get_error_code(ret));
750 SLOG(LOG_WARN, TAG_VCM, "[WARNING] retry request disable command type : %s", __vc_mgr_get_error_code(ret));
753 if (VC_RETRY_COUNT == count) {
754 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to request");
761 SLOG(LOG_DEBUG, TAG_VCM, "=====");
762 SLOG(LOG_DEBUG, TAG_VCM, " ");
767 int vc_mgr_set_command_list(vc_cmd_list_h vc_cmd_list)
769 SLOG(LOG_DEBUG, TAG_VCM, "===== [Manager] Set Command list");
772 if (0 != vc_mgr_client_get_client_state(g_vc_m, &state)) {
773 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] A handle is not available");
774 SLOG(LOG_DEBUG, TAG_VCM, "=====");
775 SLOG(LOG_DEBUG, TAG_VCM, " ");
776 return VC_ERROR_INVALID_STATE;
780 if (state != VC_STATE_READY) {
781 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Invalid State: Current state is not 'READY'");
782 SLOG(LOG_DEBUG, TAG_VCM, "=====");
783 SLOG(LOG_DEBUG, TAG_VCM, " ");
784 return VC_ERROR_INVALID_STATE;
787 /* Check service state */
788 vc_service_state_e service_state = -1;
789 vc_mgr_client_get_service_state(g_vc_m, &service_state);
790 if (service_state != VC_SERVICE_STATE_READY) {
791 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Invalid State: service state is not 'READY'");
792 SLOG(LOG_DEBUG, TAG_VCM, "=====");
793 SLOG(LOG_DEBUG, TAG_VCM, " ");
794 return VC_ERROR_INVALID_STATE;
797 if (NULL == vc_cmd_list) {
798 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Input parameter is NULL");
799 return VC_ERROR_INVALID_PARAMETER;
802 vc_cmd_list_s* list = NULL;
803 list = (vc_cmd_list_s*)vc_cmd_list;
804 SLOG(LOG_INFO, TAG_VCM, "[List] (%p) (%p)", list, list->list);
806 if (NULL == list->list) {
807 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Invalid command list");
808 return VC_ERROR_INVALID_PARAMETER;
813 bool success_save = false;
814 for (i = VC_COMMAND_TYPE_FOREGROUND; i <= VC_COMMAND_TYPE_EXCLUSIVE; i++) {
815 ret = vc_cmd_parser_delete_file(getpid(), i);
817 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to delete file, type(%d), ret(%d)", i, ret);
819 ret = vc_cmd_parser_save_file(getpid(), i, list->list, NULL);
821 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to save file, type(%d), ret(%d)", i, ret);
823 SLOG(LOG_DEBUG, TAG_VCM, "[SUCCESS] Save file, type(%d)", i);
828 if (true != success_save) {
829 ret = VC_ERROR_INVALID_PARAMETER;
830 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to save command group : %s", __vc_mgr_get_error_code(ret));
834 ret = vc_mgr_dbus_request_set_command(g_vc_m->handle);
836 if (VC_ERROR_TIMED_OUT != ret) {
837 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to request set command to daemon : %s", __vc_mgr_get_error_code(ret));
840 SLOG(LOG_WARN, TAG_VCM, "[WARNING] retry request set command : %s", __vc_mgr_get_error_code(ret));
843 if (VC_RETRY_COUNT == count) {
844 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to request");
852 SLOG(LOG_DEBUG, TAG_VCM, "=====");
853 SLOG(LOG_DEBUG, TAG_VCM, " ");
858 int vc_mgr_unset_command_list()
860 SLOG(LOG_DEBUG, TAG_VCM, "===== [Manager] Unset Command list");
863 if (0 != vc_mgr_client_get_client_state(g_vc_m, &state)) {
864 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] A handle is not available");
865 return VC_ERROR_INVALID_STATE;
869 if (state != VC_STATE_READY) {
870 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Current state is not 'READY'");
871 return VC_ERROR_INVALID_STATE;
877 ret = vc_mgr_dbus_request_unset_command(g_vc_m->handle);
879 if (VC_ERROR_TIMED_OUT != ret) {
880 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to request unset command to daemon : %s", __vc_mgr_get_error_code(ret));
883 SLOG(LOG_WARN, TAG_VCM, "[WARNING] retry request unset command : %s", __vc_mgr_get_error_code(ret));
886 if (VC_RETRY_COUNT == count) {
887 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to request");
895 for (i = VC_COMMAND_TYPE_FOREGROUND; i <= VC_COMMAND_TYPE_EXCLUSIVE; i++) {
896 ret = vc_cmd_parser_delete_file(getpid(), i);
898 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to delete file, type(%d), ret(%d)", i, ret);
901 SLOG(LOG_DEBUG, TAG_VCM, "=====");
902 SLOG(LOG_DEBUG, TAG_VCM, " ");
907 int vc_mgr_set_command_list_from_file(const char* file_path, int type)
909 SLOG(LOG_DEBUG, TAG_VCM, "===== [Manager] Set Command list from file");
911 if (NULL == file_path) {
912 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Invalid parameter!!");
913 return VC_ERROR_INVALID_PARAMETER;
915 SLOG(LOG_DEBUG, TAG_VCM, "===== File path: %s", file_path);
919 if (VC_COMMAND_TYPE_FOREGROUND > type || VC_COMMAND_TYPE_EXCLUSIVE < type) {
920 SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Invalid command type: input type is %d", type);
921 SLOG(LOG_DEBUG, TAG_VCC, "=====");
922 SLOG(LOG_DEBUG, TAG_VCC, " ");
923 return VC_ERROR_INVALID_PARAMETER;
927 if (0 != vc_mgr_client_get_client_state(g_vc_m, &state)) {
928 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] A handle is not available");
929 return VC_ERROR_INVALID_STATE;
933 if (state != VC_STATE_READY) {
934 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Invalid State: Current state is not 'READY'");
935 return VC_ERROR_INVALID_STATE;
938 /* Check service state */
939 vc_service_state_e service_state = -1;
940 vc_mgr_client_get_service_state(g_vc_m, &service_state);
941 if (service_state != VC_SERVICE_STATE_READY) {
942 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Invalid State: service state is not 'READY'");
943 return VC_ERROR_INVALID_STATE;
946 int ret = vc_cmd_parser_delete_file(getpid(), type);
948 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to delete file, type(4), ret(%d)", ret);
950 if (0 != vc_json_set_commands_from_file(file_path, type, NULL)) {
951 ret = VC_ERROR_INVALID_PARAMETER;
952 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to save command list (%d)", ret);
956 ret = vc_mgr_dbus_request_set_command(g_vc_m->handle);
958 if (VC_ERROR_TIMED_OUT != ret) {
959 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to request set command to daemon : %s", __vc_mgr_get_error_code(ret));
962 SLOG(LOG_WARN, TAG_VCM, "[WARNING] retry request set command : %s", __vc_mgr_get_error_code(ret));
965 if (VC_RETRY_COUNT == count) {
966 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to request");
974 SLOG(LOG_DEBUG, TAG_VCM, "=====");
975 SLOG(LOG_DEBUG, TAG_VCM, " ");
980 int vc_mgr_set_preloaded_commands_from_file(const char* file_path)
982 SLOG(LOG_DEBUG, TAG_VCM, "===== [Manager] Set preloaded command list");
985 if (0 != vc_mgr_client_get_client_state(g_vc_m, &state)) {
986 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] A handle is not available");
987 return VC_ERROR_INVALID_STATE;
991 if (state != VC_STATE_READY) {
992 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Invalid State: Current state is not 'READY'");
993 return VC_ERROR_INVALID_STATE;
996 /* Check service state */
997 vc_service_state_e service_state = -1;
998 vc_mgr_client_get_service_state(g_vc_m, &service_state);
999 if (service_state != VC_SERVICE_STATE_READY) {
1000 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Invalid State: service state is not 'READY'");
1001 return VC_ERROR_INVALID_STATE;
1004 /* Only support to set background commands for preloaded application */
1005 int ret = vc_json_set_commands_from_file(file_path, VC_COMMAND_TYPE_BACKGROUND, NULL);
1007 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to insert preloaded commands into db");
1009 SLOG(LOG_DEBUG, TAG_VCM, "=====");
1010 SLOG(LOG_DEBUG, TAG_VCM, " ");
1014 int vc_mgr_set_audio_type(const char* audio_id)
1016 SLOG(LOG_DEBUG, TAG_VCM, "===== [Manager] Set audio type");
1018 if (NULL == audio_id) {
1019 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Input parameter is NULL");
1020 return VC_ERROR_INVALID_PARAMETER;
1024 if (0 != vc_mgr_client_get_client_state(g_vc_m, &state)) {
1025 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] A handle is not available");
1026 SLOG(LOG_DEBUG, TAG_VCM, "=====");
1027 SLOG(LOG_DEBUG, TAG_VCM, " ");
1028 return VC_ERROR_INVALID_STATE;
1032 if (state != VC_STATE_READY) {
1033 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Invalid State: Current state is not 'READY'");
1034 SLOG(LOG_DEBUG, TAG_VCM, "=====");
1035 SLOG(LOG_DEBUG, TAG_VCM, " ");
1036 return VC_ERROR_INVALID_STATE;
1039 /* Check service state */
1040 vc_service_state_e service_state = -1;
1041 vc_mgr_client_get_service_state(g_vc_m, &service_state);
1042 if (service_state != VC_SERVICE_STATE_READY) {
1043 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Invalid State: service state is not 'READY'");
1044 SLOG(LOG_DEBUG, TAG_VCM, "=====");
1045 SLOG(LOG_DEBUG, TAG_VCM, " ");
1046 return VC_ERROR_INVALID_STATE;
1054 ret = vc_mgr_dbus_request_set_audio_type(g_vc_m->handle, audio_id);
1056 if (VC_ERROR_TIMED_OUT != ret) {
1057 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to set audio type : %s", __vc_mgr_get_error_code(ret));
1060 SLOG(LOG_WARN, TAG_VCM, "[WARNING] retry to set audio type : %s", __vc_mgr_get_error_code(ret));
1063 if (VC_RETRY_COUNT == count) {
1064 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to request");
1069 SLOG(LOG_DEBUG, TAG_VCM, "[SUCCESS] Set audio type");
1071 vc_mgr_client_set_audio_type(g_vc_m, audio_id);
1075 SLOG(LOG_DEBUG, TAG_VCM, "=====");
1076 SLOG(LOG_DEBUG, TAG_VCM, " ");
1081 int vc_mgr_get_audio_type(char** audio_id)
1083 SLOG(LOG_DEBUG, TAG_VCM, "===== [Manager] Get audio type");
1085 if (NULL == audio_id) {
1086 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Input parameter is NULL");
1087 return VC_ERROR_INVALID_PARAMETER;
1091 if (0 != vc_mgr_client_get_client_state(g_vc_m, &state)) {
1092 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] A handle is not available");
1093 SLOG(LOG_DEBUG, TAG_VCM, "=====");
1094 SLOG(LOG_DEBUG, TAG_VCM, " ");
1095 return VC_ERROR_INVALID_STATE;
1099 if (state != VC_STATE_READY) {
1100 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Invalid State: Current state is not 'READY'");
1101 SLOG(LOG_DEBUG, TAG_VCM, "=====");
1102 SLOG(LOG_DEBUG, TAG_VCM, " ");
1103 return VC_ERROR_INVALID_STATE;
1106 /* Check service state */
1107 vc_service_state_e service_state = -1;
1108 vc_mgr_client_get_service_state(g_vc_m, &service_state);
1109 if (service_state != VC_SERVICE_STATE_READY) {
1110 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Invalid State: service state is not 'READY'");
1111 SLOG(LOG_DEBUG, TAG_VCM, "=====");
1112 SLOG(LOG_DEBUG, TAG_VCM, " ");
1113 return VC_ERROR_INVALID_STATE;
1118 vc_mgr_client_get_audio_type(g_vc_m, &temp);
1121 /* Not initiallized */
1125 ret = vc_mgr_dbus_request_get_audio_type(g_vc_m->handle, &temp);
1127 if (VC_ERROR_TIMED_OUT != ret) {
1128 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to get audio type : %s", __vc_mgr_get_error_code(ret));
1131 SLOG(LOG_WARN, TAG_VCM, "[WARNING] retry to get audio type : %s", __vc_mgr_get_error_code(ret));
1134 if (VC_RETRY_COUNT == count) {
1135 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to request");
1140 SLOG(LOG_DEBUG, TAG_VCM, "[SUCCESS] Get audio type : %s", temp);
1142 vc_mgr_client_set_audio_type(g_vc_m, temp);
1148 *audio_id = strdup(temp);
1156 int vc_mgr_get_current_commands(vc_cmd_list_h* vc_cmd_list)
1158 SLOG(LOG_DEBUG, TAG_VCM, "===== [Manager] Foreach current commands");
1161 if (0 != vc_mgr_client_get_client_state(g_vc_m, &state)) {
1162 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] A handle is not available");
1163 SLOG(LOG_DEBUG, TAG_VCM, "=====");
1164 SLOG(LOG_DEBUG, TAG_VCM, " ");
1165 return VC_ERROR_INVALID_STATE;
1169 if (state != VC_STATE_READY) {
1170 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Invalid State: Current state is not 'READY'");
1171 SLOG(LOG_DEBUG, TAG_VCM, "=====");
1172 SLOG(LOG_DEBUG, TAG_VCM, " ");
1173 return VC_ERROR_INVALID_STATE;
1176 /* Check service state */
1177 vc_service_state_e service_state = -1;
1178 vc_mgr_client_get_service_state(g_vc_m, &service_state);
1179 if (service_state != VC_SERVICE_STATE_READY) {
1180 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Invalid State: service state is not 'READY'");
1181 SLOG(LOG_DEBUG, TAG_VCM, "=====");
1182 SLOG(LOG_DEBUG, TAG_VCM, " ");
1183 return VC_ERROR_INVALID_STATE;
1186 if (NULL == vc_cmd_list) {
1187 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Invalid Parameter");
1188 SLOG(LOG_DEBUG, TAG_VCM, "=====");
1189 SLOG(LOG_DEBUG, TAG_VCM, " ");
1190 return VC_ERROR_INVALID_PARAMETER;
1193 vc_cmd_list_h temp_list = NULL;
1194 if (0 != vc_cmd_list_create(&temp_list)) {
1195 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to create list");
1196 return VC_ERROR_INVALID_PARAMETER;
1199 *vc_cmd_list = temp_list;
1206 /* Get foreground pid */
1207 if (0 != vc_mgr_client_get_foreground(g_vc_m, &fg_pid)) {
1208 /* There is no foreground app for voice control */
1209 SLOG(LOG_WARN, TAG_VCM, "[Manager WARNING] No foreground pid for voice control");
1211 SLOG(LOG_DEBUG, TAG_VCM, "[Manager] Foreground pid(%d)", fg_pid);
1214 if (0 != vc_mgr_client_get_pid(g_vc_m, &mgr_pid)) {
1215 SLOG(LOG_DEBUG, TAG_VCM, "[Manager] Fail to get manager pid");
1216 return VC_ERROR_OPERATION_FAILED;
1218 SLOG(LOG_DEBUG, TAG_VCM, "[Manager] Manager pid(%d)", mgr_pid);
1221 /* Get system command */
1222 ret = vc_cmd_parser_append_commands(mgr_pid, VC_COMMAND_TYPE_SYSTEM, temp_list);
1224 SLOG(LOG_DEBUG, TAG_VCM, "[Manager] No system commands");
1231 ret = vc_mgr_dbus_request_set_client_info(g_vc_m->handle);
1233 if (VC_ERROR_TIMED_OUT != ret) {
1234 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to set client info : %s", __vc_mgr_get_error_code(ret));
1237 SLOG(LOG_WARN, TAG_VCM, "[WARNING] retry to set client info : %s", __vc_mgr_get_error_code(ret));
1240 if (VC_RETRY_COUNT == count) {
1241 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to request");
1246 SLOG(LOG_DEBUG, TAG_VCM, "[SUCCESS] Set client info");
1250 GSList *iter = NULL;
1251 GSList* client_info_list = NULL;
1252 vc_client_info_s *client_info = NULL;
1253 bool is_fgpid = false;
1255 if (0 != vc_info_parser_get_client_info(&client_info_list)) {
1256 SLOG(LOG_DEBUG, TAG_VCM, "[DEBUG] No client");
1260 if (VC_NO_FOREGROUND_PID != fg_pid) {
1261 iter = g_slist_nth(client_info_list, 0);
1262 while (NULL != iter) {
1263 client_info = iter->data;
1264 if (NULL != client_info) {
1265 if (fg_pid == client_info->pid) {
1270 iter = g_slist_next(iter);
1274 /* Get foreground commands and widget */
1275 if (true == is_fgpid) {
1277 SLOG(LOG_DEBUG, TAG_VCM, "[Manager] fore cmd(%d)", client_info->fg_cmd);
1279 /* Get foreground command */
1280 if (true == client_info->fg_cmd) {
1281 ret = vc_cmd_parser_append_commands(fg_pid, VC_COMMAND_TYPE_FOREGROUND, temp_list);
1283 SLOG(LOG_ERROR, TAG_VCM, "[Client Data ERROR] Fail to get the fg command list");
1286 SLOG(LOG_DEBUG, TAG_VCM, "[Manager] No foreground commands");
1289 /* Check exclusive option */
1290 if (true == client_info->exclusive_cmd) {
1291 SLOG(LOG_DEBUG, TAG_VCM, "[Manager] Exclusive command is ON");
1293 /* Set background command for exclusive option */
1294 if (true == client_info->bg_cmd) {
1295 SLOG(LOG_DEBUG, TAG_VCM, "[Manager] Set background command");
1296 ret = vc_cmd_parser_append_commands(client_info->pid, VC_COMMAND_TYPE_BACKGROUND, temp_list);
1298 SLOG(LOG_ERROR, TAG_VCM, "[Client Data ERROR] Fail to get the bg command list : pid(%d)", client_info->pid);
1302 /* need to release client info */
1303 iter = g_slist_nth(client_info_list, 0);
1305 while (NULL != iter) {
1306 client_info = iter->data;
1307 if (NULL != client_info) {
1310 client_info_list = g_slist_remove_link(client_info_list, iter);
1311 iter = g_slist_nth(client_info_list, 0);
1314 SLOG(LOG_DEBUG, TAG_VCM, "=====");
1315 SLOG(LOG_DEBUG, TAG_VCM, " ");
1320 SLOG(LOG_DEBUG, TAG_VCM, "[Manager] No foreground app");
1323 /* Get background commands */
1324 if (0 < g_slist_length(client_info_list)) {
1325 iter = g_slist_nth(client_info_list, 0);
1327 while (NULL != iter) {
1328 client_info = iter->data;
1330 if (NULL != client_info) {
1331 SLOG(LOG_DEBUG, TAG_VCM, "[Manager] Pid(%d) Back cmd(%d)", client_info->pid, client_info->bg_cmd);
1332 if (true == client_info->bg_cmd) {
1333 ret = vc_cmd_parser_append_commands(client_info->pid, VC_COMMAND_TYPE_BACKGROUND, temp_list);
1335 SLOG(LOG_ERROR, TAG_VCM, "[Client Data ERROR] Fail to get the bg command list : pid(%d)", client_info->pid);
1340 client_info_list = g_slist_remove_link(client_info_list, iter);
1342 iter = g_slist_nth(client_info_list, 0);
1346 SLOG(LOG_DEBUG, TAG_VCM, "[Manager] No background commands");
1349 SLOG(LOG_DEBUG, TAG_VCM, "=====");
1350 SLOG(LOG_DEBUG, TAG_VCM, " ");
1355 int vc_mgr_set_recognition_mode(vc_recognition_mode_e mode)
1357 SLOG(LOG_DEBUG, TAG_VCM, "===== [Manager] Set recognition mode = %d", mode);
1360 if (0 != vc_mgr_client_get_client_state(g_vc_m, &state)) {
1361 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] A handle is not available");
1362 SLOG(LOG_DEBUG, TAG_VCM, "=====");
1363 SLOG(LOG_DEBUG, TAG_VCM, " ");
1364 return VC_ERROR_INVALID_STATE;
1368 if (state != VC_STATE_READY) {
1369 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Invalid State: Current state is not 'READY'");
1370 SLOG(LOG_DEBUG, TAG_VCM, "=====");
1371 SLOG(LOG_DEBUG, TAG_VCM, " ");
1372 return VC_ERROR_INVALID_STATE;
1375 /* Check service state */
1376 vc_service_state_e service_state = -1;
1377 vc_mgr_client_get_service_state(g_vc_m, &service_state);
1378 if (service_state != VC_SERVICE_STATE_READY) {
1379 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Invalid State: service state is not 'READY'");
1380 SLOG(LOG_DEBUG, TAG_VCM, "=====");
1381 SLOG(LOG_DEBUG, TAG_VCM, " ");
1382 return VC_ERROR_INVALID_STATE;
1385 vc_mgr_client_set_recognition_mode(g_vc_m, mode);
1389 int vc_mgr_get_recognition_mode(vc_recognition_mode_e* mode)
1393 ret = vc_mgr_client_get_recognition_mode(g_vc_m, mode);
1395 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to get recognition mode");
1399 SLOG(LOG_DEBUG, TAG_VCM, "===== [Manager] Get recognition mode = %d", *mode);
1403 int vc_mgr_set_private_data(const char* key, const char* data)
1405 SLOG(LOG_DEBUG, TAG_VCM, "===== [Manager] Set private data");
1408 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Invalid parameter");
1409 return VC_ERROR_INVALID_PARAMETER;
1413 if (0 != vc_mgr_client_get_client_state(g_vc_m, &state)) {
1414 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] A handle is not available");
1415 SLOG(LOG_DEBUG, TAG_VCM, "=====");
1416 SLOG(LOG_DEBUG, TAG_VCM, " ");
1417 return VC_ERROR_INVALID_STATE;
1421 if (state != VC_STATE_READY) {
1422 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Invalid State: Current state is not 'READY'");
1423 SLOG(LOG_DEBUG, TAG_VCM, "=====");
1424 SLOG(LOG_DEBUG, TAG_VCM, " ");
1425 return VC_ERROR_INVALID_STATE;
1428 /* Check service state */
1429 vc_service_state_e service_state = -1;
1430 vc_mgr_client_get_service_state(g_vc_m, &service_state);
1431 if (service_state != VC_SERVICE_STATE_READY) {
1432 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Invalid State: service state is not 'READY'");
1433 SLOG(LOG_DEBUG, TAG_VCM, "=====");
1434 SLOG(LOG_DEBUG, TAG_VCM, " ");
1435 return VC_ERROR_INVALID_STATE;
1441 ret = vc_mgr_dbus_request_set_private_data(g_vc_m->handle, key, data);
1443 if (VC_ERROR_TIMED_OUT != ret) {
1444 SLOG(LOG_DEBUG, TAG_VCM, "[ERROR] Fail to set private data request : %s", __vc_mgr_get_error_code(ret));
1447 SLOG(LOG_WARN, TAG_VCM, "[WARNING] retry set private data request : %s", __vc_mgr_get_error_code(ret));
1450 if (VC_RETRY_COUNT == count) {
1451 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to request");
1456 SLOG(LOG_DEBUG, TAG_VCM, "[SUCCESS] Set domain");
1459 SLOG(LOG_DEBUG, TAG_VCM, "=====");
1460 SLOG(LOG_DEBUG, TAG_VCM, " ");
1465 int vc_mgr_get_private_data(const char* key, char** data)
1467 SLOG(LOG_DEBUG, TAG_VCM, "===== [Manager] Get private data");
1469 if (NULL == key || NULL == data) {
1470 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Invalid parameter");
1471 return VC_ERROR_INVALID_PARAMETER;
1475 if (0 != vc_mgr_client_get_client_state(g_vc_m, &state)) {
1476 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] A handle is not available");
1477 SLOG(LOG_DEBUG, TAG_VCM, "=====");
1478 SLOG(LOG_DEBUG, TAG_VCM, " ");
1479 return VC_ERROR_INVALID_STATE;
1483 if (state != VC_STATE_READY) {
1484 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Invalid State: Current state is not 'READY'");
1485 SLOG(LOG_DEBUG, TAG_VCM, "=====");
1486 SLOG(LOG_DEBUG, TAG_VCM, " ");
1487 return VC_ERROR_INVALID_STATE;
1490 /* Check service state */
1491 vc_service_state_e service_state = -1;
1492 vc_mgr_client_get_service_state(g_vc_m, &service_state);
1493 if (service_state != VC_SERVICE_STATE_READY) {
1494 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Invalid State: service state is not 'READY'");
1495 SLOG(LOG_DEBUG, TAG_VCM, "=====");
1496 SLOG(LOG_DEBUG, TAG_VCM, " ");
1497 return VC_ERROR_INVALID_STATE;
1505 ret = vc_mgr_dbus_request_get_private_data(g_vc_m->handle, key, &temp);
1507 if (VC_ERROR_TIMED_OUT != ret) {
1508 SLOG(LOG_DEBUG, TAG_VCM, "[ERROR] Fail to get private data request : %s", __vc_mgr_get_error_code(ret));
1511 SLOG(LOG_WARN, TAG_VCM, "[WARNING] retry get private data request : %s", __vc_mgr_get_error_code(ret));
1514 if (VC_RETRY_COUNT == count) {
1515 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to request");
1520 SLOG(LOG_DEBUG, TAG_VCM, "[SUCCESS] Get private data, key(%s), data(%s)", key, temp);
1525 *data = strdup(temp);
1530 SLOG(LOG_DEBUG, TAG_VCM, "=====");
1531 SLOG(LOG_DEBUG, TAG_VCM, " ");
1536 int vc_mgr_set_domain(const char* domain)
1538 SLOG(LOG_DEBUG, TAG_VCM, "===== [Manager] Set domain");
1540 if (NULL == domain) {
1541 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Invalid parameter");
1542 return VC_ERROR_INVALID_PARAMETER;
1546 if (0 != vc_mgr_client_get_client_state(g_vc_m, &state)) {
1547 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] A handle is not available");
1548 SLOG(LOG_DEBUG, TAG_VCM, "=====");
1549 SLOG(LOG_DEBUG, TAG_VCM, " ");
1550 return VC_ERROR_INVALID_STATE;
1554 if (state != VC_STATE_READY) {
1555 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Invalid State: Current state is not 'READY'");
1556 SLOG(LOG_DEBUG, TAG_VCM, "=====");
1557 SLOG(LOG_DEBUG, TAG_VCM, " ");
1558 return VC_ERROR_INVALID_STATE;
1561 /* Check service state */
1562 vc_service_state_e service_state = -1;
1563 vc_mgr_client_get_service_state(g_vc_m, &service_state);
1564 if (service_state != VC_SERVICE_STATE_READY) {
1565 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Invalid State: service state is not 'READY'");
1566 SLOG(LOG_DEBUG, TAG_VCM, "=====");
1567 SLOG(LOG_DEBUG, TAG_VCM, " ");
1568 return VC_ERROR_INVALID_STATE;
1574 ret = vc_mgr_dbus_request_set_domain(g_vc_m->handle, domain);
1576 if (VC_ERROR_TIMED_OUT != ret) {
1577 SLOG(LOG_DEBUG, TAG_VCM, "[ERROR] Fail to set domain request : %s", __vc_mgr_get_error_code(ret));
1580 SLOG(LOG_WARN, TAG_VCM, "[WARNING] retry set domain request : %s", __vc_mgr_get_error_code(ret));
1583 if (VC_RETRY_COUNT == count) {
1584 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to request");
1589 SLOG(LOG_DEBUG, TAG_VCM, "[SUCCESS] Set domain");
1592 SLOG(LOG_DEBUG, TAG_VCM, "=====");
1593 SLOG(LOG_DEBUG, TAG_VCM, " ");
1598 int vc_mgr_do_action(vc_send_event_type_e type, char* send_event)
1600 SLOG(LOG_DEBUG, TAG_VCM, "===== [Manager] do action");
1602 if (NULL == send_event) {
1603 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Invalid parameter");
1604 return VC_ERROR_INVALID_PARAMETER;
1608 if (0 != vc_mgr_client_get_client_state(g_vc_m, &state)) {
1609 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] A handle is not available");
1610 SLOG(LOG_DEBUG, TAG_VCM, "=====");
1611 SLOG(LOG_DEBUG, TAG_VCM, " ");
1612 return VC_ERROR_INVALID_STATE;
1616 if (state != VC_STATE_READY) {
1617 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Invalid State: Current state is not 'READY'");
1618 SLOG(LOG_DEBUG, TAG_VCM, "=====");
1619 SLOG(LOG_DEBUG, TAG_VCM, " ");
1620 return VC_ERROR_INVALID_STATE;
1623 /* Check service state */
1624 vc_service_state_e service_state = -1;
1625 vc_mgr_client_get_service_state(g_vc_m, &service_state);
1626 if (service_state != VC_SERVICE_STATE_READY) {
1627 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Invalid State: service state is not 'READY'");
1628 SLOG(LOG_DEBUG, TAG_VCM, "=====");
1629 SLOG(LOG_DEBUG, TAG_VCM, " ");
1630 return VC_ERROR_INVALID_STATE;
1636 ret = vc_mgr_dbus_request_do_action(g_vc_m->handle, type, send_event);
1638 if (VC_ERROR_TIMED_OUT != ret) {
1639 SLOG(LOG_DEBUG, TAG_VCM, "[ERROR] Fail to do action request : %s", __vc_mgr_get_error_code(ret));
1642 SLOG(LOG_WARN, TAG_VCM, "[WARNING] retry do action request : %s", __vc_mgr_get_error_code(ret));
1645 if (VC_RETRY_COUNT == count) {
1646 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to request");
1651 SLOG(LOG_DEBUG, TAG_VCM, "[SUCCESS] do action");
1654 SLOG(LOG_DEBUG, TAG_VCM, "=====");
1655 SLOG(LOG_DEBUG, TAG_VCM, " ");
1660 int vc_mgr_start(bool exclusive_command_option)
1662 SLOG(LOG_DEBUG, TAG_VCM, "===== [Manager] Request start");
1665 if (0 != vc_mgr_client_get_client_state(g_vc_m, &state)) {
1666 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] A handle is not available");
1667 SLOG(LOG_DEBUG, TAG_VCM, "=====");
1668 SLOG(LOG_DEBUG, TAG_VCM, " ");
1669 return VC_ERROR_INVALID_STATE;
1673 if (state != VC_STATE_READY) {
1674 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Invalid State: Current state is not 'READY'");
1675 SLOG(LOG_DEBUG, TAG_VCM, "=====");
1676 SLOG(LOG_DEBUG, TAG_VCM, " ");
1677 return VC_ERROR_INVALID_STATE;
1680 /* Check service state */
1681 vc_service_state_e service_state = -1;
1682 vc_mgr_client_get_service_state(g_vc_m, &service_state);
1683 if (service_state != VC_SERVICE_STATE_READY) {
1684 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Invalid State: service state is not 'READY'");
1685 SLOG(LOG_DEBUG, TAG_VCM, "=====");
1686 SLOG(LOG_DEBUG, TAG_VCM, " ");
1687 return VC_ERROR_INVALID_STATE;
1690 /* Check internal state for async */
1691 vc_internal_state_e internal_state = -1;
1692 vc_mgr_client_get_internal_state(g_vc_m, &internal_state);
1693 if (internal_state != VC_INTERNAL_STATE_NONE) {
1694 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Invaid State : Internal state is NOT none : %d", internal_state);
1695 return VC_ERROR_IN_PROGRESS_TO_RECORDING;
1698 vc_mgr_client_set_exclusive_command(g_vc_m, exclusive_command_option);
1700 bool start_by_client = false;
1701 if (0 != vc_mgr_client_get_start_by_client(g_vc_m, &start_by_client)) {
1702 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to get start by client");
1707 vc_recognition_mode_e recognition_mode = VC_RECOGNITION_MODE_STOP_BY_SILENCE;
1708 if (0 != vc_mgr_get_recognition_mode(&recognition_mode)) {
1709 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to get recognition mode");
1716 vc_mgr_client_set_internal_state(g_vc_m, VC_INTERNAL_STATE_STARTING);
1717 ret = vc_mgr_dbus_request_start(g_vc_m->handle, (int)recognition_mode, exclusive_command_option, start_by_client);
1719 if (VC_ERROR_TIMED_OUT != ret) {
1720 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to start request start : %s", __vc_mgr_get_error_code(ret));
1721 vc_mgr_client_set_internal_state(g_vc_m, VC_INTERNAL_STATE_NONE);
1724 SLOG(LOG_WARN, TAG_VCM, "[WARNING] retry start request start : %s", __vc_mgr_get_error_code(ret));
1727 if (VC_RETRY_COUNT == count) {
1728 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to request");
1729 vc_mgr_client_set_exclusive_command(g_vc_m, false);
1730 vc_mgr_client_set_internal_state(g_vc_m, VC_INTERNAL_STATE_NONE);
1735 SLOG(LOG_DEBUG, TAG_VCM, "[SUCCESS] start recognition");
1740 g_prev_volume_db = 0;
1741 g_cur_volume_db = 0;
1743 SLOG(LOG_DEBUG, TAG_VCM, "=====");
1744 SLOG(LOG_DEBUG, TAG_VCM, " ");
1751 SLOG(LOG_DEBUG, TAG_VCM, "===== [Manager] Request stop");
1754 if (0 != vc_mgr_client_get_client_state(g_vc_m, &state)) {
1755 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] A handle is not available");
1756 SLOG(LOG_DEBUG, TAG_VCM, "=====");
1757 SLOG(LOG_DEBUG, TAG_VCM, " ");
1758 return VC_ERROR_INVALID_STATE;
1762 if (state != VC_STATE_READY) {
1763 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Invalid State: client state is not 'READY'");
1764 SLOG(LOG_DEBUG, TAG_VCM, "=====");
1765 SLOG(LOG_DEBUG, TAG_VCM, " ");
1766 return VC_ERROR_INVALID_STATE;
1769 /* Check service state */
1770 vc_service_state_e service_state = -1;
1771 vc_mgr_client_get_service_state(g_vc_m, &service_state);
1772 if (service_state != VC_SERVICE_STATE_RECORDING) {
1773 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Invalid State: service state is not 'RECORDING'");
1774 SLOG(LOG_DEBUG, TAG_VCM, "=====");
1775 SLOG(LOG_DEBUG, TAG_VCM, " ");
1776 return VC_ERROR_INVALID_STATE;
1779 /* Check internal state for async */
1780 vc_internal_state_e internal_state = -1;
1781 vc_mgr_client_get_internal_state(g_vc_m, &internal_state);
1782 if (VC_INTERNAL_STATE_STARTING == internal_state) {
1783 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Invalid State : Internal state is STARTING");
1784 return VC_ERROR_IN_PROGRESS_TO_RECORDING;
1785 } else if (VC_INTERNAL_STATE_STOPPING == internal_state) {
1786 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Invalid State : Internal state is STOPPING");
1787 return VC_ERROR_IN_PROGRESS_TO_PROCESSING;
1788 } else if (VC_INTERNAL_STATE_CANCELING == internal_state) {
1789 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Invalid State : Internal state is CANCELING");
1790 return VC_ERROR_IN_PROGRESS_TO_READY;
1797 vc_mgr_client_set_internal_state(g_vc_m, VC_INTERNAL_STATE_STOPPING);
1798 ret = vc_mgr_dbus_request_stop(g_vc_m->handle);
1800 if (VC_ERROR_TIMED_OUT != ret) {
1801 SLOG(LOG_DEBUG, TAG_VCM, "[ERROR] Fail to stop request : %s", __vc_mgr_get_error_code(ret));
1802 vc_mgr_client_set_internal_state(g_vc_m, VC_INTERNAL_STATE_NONE);
1805 SLOG(LOG_WARN, TAG_VCM, "[WARNING] retry stop request : %s", __vc_mgr_get_error_code(ret));
1808 if (VC_RETRY_COUNT == count) {
1809 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to request");
1810 vc_mgr_client_set_internal_state(g_vc_m, VC_INTERNAL_STATE_NONE);
1815 SLOG(LOG_DEBUG, TAG_VCM, "[SUCCESS] Stop recognition");
1819 SLOG(LOG_DEBUG, TAG_VCM, "=====");
1820 SLOG(LOG_DEBUG, TAG_VCM, " ");
1827 SLOG(LOG_DEBUG, TAG_VCM, "===== [Manager] Request cancel");
1830 if (0 != vc_mgr_client_get_client_state(g_vc_m, &state)) {
1831 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] A handle is not available");
1832 SLOG(LOG_DEBUG, TAG_VCM, "=====");
1833 SLOG(LOG_DEBUG, TAG_VCM, " ");
1834 return VC_ERROR_INVALID_STATE;
1838 if (state != VC_STATE_READY) {
1839 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Invalid State: client state is not 'READY'");
1840 SLOG(LOG_DEBUG, TAG_VCM, "=====");
1841 SLOG(LOG_DEBUG, TAG_VCM, " ");
1842 return VC_ERROR_INVALID_STATE;
1845 /* Check service state */
1846 vc_service_state_e service_state = -1;
1847 vc_mgr_client_get_service_state(g_vc_m, &service_state);
1848 if (service_state == VC_SERVICE_STATE_NONE) {
1849 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Invalid State");
1850 SLOG(LOG_DEBUG, TAG_VCM, "=====");
1851 SLOG(LOG_DEBUG, TAG_VCM, " ");
1852 return VC_ERROR_INVALID_STATE;
1855 vc_internal_state_e internal_state = -1;
1856 vc_mgr_client_get_internal_state(g_vc_m, &internal_state);
1857 if (VC_INTERNAL_STATE_STARTING == internal_state) {
1858 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Invalid State : Internal state is STARTING");
1859 return VC_ERROR_IN_PROGRESS_TO_RECORDING;
1860 } else if (VC_INTERNAL_STATE_STOPPING == internal_state) {
1861 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Invalid State : Internal state is STOPPING");
1862 return VC_ERROR_IN_PROGRESS_TO_PROCESSING;
1863 } else if (VC_INTERNAL_STATE_CANCELING == internal_state) {
1864 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Invalid State : Internal state is CANCELING");
1865 return VC_ERROR_IN_PROGRESS_TO_READY;
1871 vc_mgr_client_set_internal_state(g_vc_m, VC_INTERNAL_STATE_CANCELING);
1872 ret = vc_mgr_dbus_request_cancel(g_vc_m->handle);
1874 if (VC_ERROR_TIMED_OUT != ret) {
1875 SLOG(LOG_DEBUG, TAG_VCM, "[ERROR] Fail to cancel request : %s", __vc_mgr_get_error_code(ret));
1876 vc_mgr_client_set_internal_state(g_vc_m, VC_INTERNAL_STATE_NONE);
1879 SLOG(LOG_WARN, TAG_VCM, "[WARNING] retry cancel request : %s", __vc_mgr_get_error_code(ret));
1882 if (VC_RETRY_COUNT == count) {
1883 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to request");
1884 vc_mgr_client_set_internal_state(g_vc_m, VC_INTERNAL_STATE_NONE);
1889 SLOG(LOG_DEBUG, TAG_VCM, "[SUCCESS] Cancel recognition");
1893 vc_mgr_client_set_exclusive_command(g_vc_m, false);
1895 SLOG(LOG_DEBUG, TAG_VCM, "=====");
1896 SLOG(LOG_DEBUG, TAG_VCM, " ");
1901 static int g_cnt = 0;
1902 static Eina_Bool __vc_mgr_set_volume(void* data)
1905 g_volume_db = g_prev_volume_db + (g_cur_volume_db - g_prev_volume_db) / 5 * g_cnt;
1907 SLOG(LOG_DEBUG, TAG_VCM, "Set volume (%f)(%f)", g_volume_db, g_cur_volume_db);
1909 if (0 == g_cnt % 5) {
1915 int __vc_mgr_cb_set_volume(float volume)
1917 g_prev_volume_db = g_volume_db;
1918 g_cur_volume_db = volume;
1920 g_volume_db = g_prev_volume_db + (g_cur_volume_db - g_prev_volume_db) / 5;
1922 if (NULL != g_m_set_volume_timer) {
1923 ecore_timer_del(g_m_set_volume_timer);
1927 g_m_set_volume_timer = ecore_timer_add(0.05, __vc_mgr_set_volume, NULL);
1932 int vc_mgr_get_recording_volume(float* volume)
1934 if (NULL == volume) {
1935 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Input parameter is NULL");
1936 return VC_ERROR_INVALID_PARAMETER;
1939 vc_service_state_e service_state = -1;
1940 if (0 != vc_mgr_client_get_service_state(g_vc_m, &service_state)) {
1941 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] A handle is not available");
1942 return VC_ERROR_INVALID_STATE;
1946 if (VC_SERVICE_STATE_RECORDING != service_state) {
1947 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Invalid State: Service state is not 'RECORDING'");
1948 return VC_ERROR_INVALID_STATE;
1951 *volume = g_volume_db;
1956 int __vc_mgr_cb_set_foreground(int pid, bool value)
1958 vc_mgr_client_set_foreground(g_vc_m, pid, value);
1960 /* get authorized valid app */
1962 if (0 != vc_mgr_client_get_valid_authorized_client(g_vc_m, &tmp_pid)) {
1963 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to get authorized valid app");
1964 return VC_ERROR_INVALID_PARAMETER;
1967 if (true == value) {
1968 /* compare & set valid */
1969 if (tmp_pid != pid) {
1970 SLOG(LOG_DEBUG, TAG_VCM, "Authority(%d) changed to invalid", tmp_pid);
1972 /* set authorized valid */
1973 if (true == vc_mgr_client_is_authorized_client(g_vc_m, pid)) {
1974 SLOG(LOG_DEBUG, TAG_VCM, "Authority(%d) change to valid", pid);
1975 vc_mgr_client_set_valid_authorized_client(g_vc_m, pid);
1977 SLOG(LOG_DEBUG, TAG_VCM, "No valid Authority");
1978 vc_mgr_client_set_valid_authorized_client(g_vc_m, -1);
1982 if (tmp_pid == pid) {
1983 SLOG(LOG_DEBUG, TAG_VCM, "Authority(%d) changed to invalid", tmp_pid);
1984 vc_mgr_client_set_valid_authorized_client(g_vc_m, -1);
1991 int vc_mgr_set_selected_results(vc_cmd_list_h vc_cmd_list)
1993 SLOG(LOG_DEBUG, TAG_VCM, "===== [Manager] Select result");
1995 /* Do not check state for 'restart continusly' mode */
1997 vc_service_state_e service_state = -1;
1998 vc_mgr_client_get_service_state(g_vc_m, &service_state);
1999 if (service_state != VC_SERVICE_STATE_PROCESSING) {
2000 vc_recognition_mode_e recognition_mode;
2001 vc_mgr_get_recognition_mode(&recognition_mode);
2003 if (VC_RECOGNITION_MODE_RESTART_CONTINUOUSLY != recognition_mode) {
2004 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Invalid State: service state is not 'PROCESSING' and mode is not 'Restart continously'");
2005 SLOG(LOG_DEBUG, TAG_VCM, "=====");
2006 SLOG(LOG_DEBUG, TAG_VCM, " ");
2007 return VC_ERROR_INVALID_STATE;
2011 if (NULL != vc_cmd_list) {
2013 char* result_text = NULL;
2015 vc_mgr_client_get_all_result(g_vc_m, &event, &result_text);
2017 vc_info_parser_set_result(result_text, event, NULL, vc_cmd_list, false);
2019 if (NULL != result_text) {
2032 ret = vc_mgr_dbus_send_result_selection(g_vc_m->handle);
2034 if (VC_ERROR_TIMED_OUT != ret) {
2035 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to send result selection : %s", __vc_mgr_get_error_code(ret));
2038 SLOG(LOG_WARN, TAG_VCM, "[WARNING] retry send result selection : %s", __vc_mgr_get_error_code(ret));
2041 if (VC_RETRY_COUNT == count) {
2042 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to request");
2047 SLOG(LOG_DEBUG, TAG_VCM, "[SUCCESS] result selection");
2051 vc_mgr_client_unset_all_result(g_vc_m);
2053 SLOG(LOG_DEBUG, TAG_VCM, "=====");
2054 SLOG(LOG_DEBUG, TAG_VCM, " ");
2059 static Eina_Bool __vc_mgr_set_select_result(void *data)
2061 vc_mgr_set_selected_results(NULL);
2065 static void __vc_mgr_notify_all_result(vc_result_type_e result_type)
2067 char* temp_text = NULL;
2069 char* temp_message = NULL;
2070 vc_cmd_list_h vc_cmd_list = NULL;
2072 vc_mgr_all_result_cb all_callback = NULL;
2073 void* all_user_data = NULL;
2075 vc_mgr_client_get_all_result_cb(g_vc_m, &all_callback, &all_user_data);
2076 if (NULL == all_callback) {
2077 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] All result callback is NULL");
2081 if (0 != vc_cmd_list_create(&vc_cmd_list)) {
2082 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to create command list");
2086 vc_info_parser_get_result(&temp_text, &event, &temp_message, -1, vc_cmd_list, vc_mgr_client_get_exclusive_command(g_vc_m));
2088 SLOG(LOG_INFO, TAG_VCM, "Result info : result type(%d) result text(%s) event(%d) result_message(%s)",
2089 result_type, temp_text, event, temp_message);
2091 vc_cmd_print_list(vc_cmd_list);
2095 vc_mgr_client_set_all_result(g_vc_m, event, temp_text);
2097 vc_mgr_client_use_callback(g_vc_m);
2098 cb_ret = all_callback(event, vc_cmd_list, temp_text, temp_message, all_user_data);
2099 vc_mgr_client_not_use_callback(g_vc_m);
2101 if (true == vc_mgr_client_get_exclusive_command(g_vc_m)) {
2103 vc_result_cb callback = NULL;
2104 void* user_data = NULL;
2106 vc_mgr_client_get_result_cb(g_vc_m, &callback, &user_data);
2107 if (NULL == callback) {
2108 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Client result callback is NULL");
2112 vc_mgr_client_use_callback(g_vc_m);
2113 callback(event, vc_cmd_list, temp_text, user_data);
2114 vc_mgr_client_not_use_callback(g_vc_m);
2115 SLOG(LOG_DEBUG, TAG_VCM, "Exclusive result callback called");
2117 /* Release result */
2118 if (NULL != temp_text) free(temp_text);
2121 vc_cmd_list_destroy(vc_cmd_list, true);
2123 vc_mgr_client_set_exclusive_command(g_vc_m, false);
2129 vc_cmd_list_get_count(vc_cmd_list, &count);
2131 if (true == cb_ret) {
2132 SLOG(LOG_DEBUG, TAG_VCM, "Callback result is true");
2133 if (VC_RESULT_TYPE_NOTIFICATION != result_type)
2134 ecore_idler_add(__vc_mgr_set_select_result, NULL);
2136 SLOG(LOG_DEBUG, TAG_VCM, "Callback result is false");
2137 /* need to select conflicted result */
2140 if (VC_RESULT_TYPE_NOTIFICATION != result_type)
2141 ecore_idler_add(__vc_mgr_set_select_result, NULL);
2143 vc_mgr_client_set_exclusive_command(g_vc_m, false);
2144 vc_mgr_client_unset_all_result(g_vc_m);
2147 /* Release result */
2148 if (NULL != temp_text) {
2154 vc_cmd_list_destroy(vc_cmd_list, true);
2159 static Eina_Bool __vc_mgr_notify_result(void *data)
2161 char* temp_text = NULL;
2163 vc_cmd_list_h vc_cmd_list = NULL;
2165 vc_result_cb callback = NULL;
2166 void* user_data = NULL;
2168 vc_mgr_client_get_result_cb(g_vc_m, &callback, &user_data);
2169 if (NULL == callback) {
2170 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Client result callback is NULL");
2174 if (0 != vc_cmd_list_create(&vc_cmd_list)) {
2175 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to create command list");
2179 vc_info_parser_get_result(&temp_text, &event, NULL, getpid(), vc_cmd_list, false);
2181 SLOG(LOG_INFO, TAG_VCM, "Result : result text(%s) event(%d)", temp_text, event);
2183 vc_cmd_print_list(vc_cmd_list);
2185 vc_mgr_client_use_callback(g_vc_m);
2186 callback(event, vc_cmd_list, temp_text, user_data);
2187 vc_mgr_client_not_use_callback(g_vc_m);
2188 SLOG(LOG_INFO, TAG_VCM, "Result callback called");
2190 vc_cmd_list_destroy(vc_cmd_list, true);
2192 /* Release result */
2193 if (NULL != temp_text) free(temp_text);
2198 void __vc_mgr_cb_all_result(vc_result_type_e type)
2200 if (false == vc_mgr_client_get_exclusive_command(g_vc_m)) {
2201 __vc_mgr_notify_all_result(type);
2203 __vc_mgr_notify_result(0);
2209 void __vc_mgr_cb_pre_result(vc_pre_result_event_e event, const char* pre_result)
2211 vc_mgr_pre_result_cb callback = NULL;
2212 void* user_data = NULL;
2214 vc_mgr_client_get_pre_result_cb(g_vc_m, &callback, &user_data);
2215 if (NULL == callback) {
2216 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Client pre result callback is NULL");
2220 vc_mgr_client_use_callback(g_vc_m);
2221 callback(event, pre_result, user_data);
2222 vc_mgr_client_not_use_callback(g_vc_m);
2223 SLOG(LOG_DEBUG, TAG_VCM, "Pre result callback is called");
2228 void __vc_mgr_cb_system_result()
2230 __vc_mgr_notify_result(NULL);
2234 static Eina_Bool __vc_mgr_speech_detected(void *data)
2236 vc_mgr_begin_speech_detected_cb callback = NULL;
2237 void* user_data = NULL;
2239 vc_mgr_client_get_speech_detected_cb(g_vc_m, &callback, &user_data);
2240 if (NULL == callback) {
2241 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Client speech detected callback is NULL");
2245 vc_mgr_client_use_callback(g_vc_m);
2246 callback(user_data);
2247 vc_mgr_client_not_use_callback(g_vc_m);
2248 SLOG(LOG_DEBUG, TAG_VCM, "Speech detected callback called");
2253 void __vc_mgr_cb_speech_detected()
2255 __vc_mgr_speech_detected(NULL);
2260 int vc_mgr_set_all_result_cb(vc_mgr_all_result_cb callback, void* user_data)
2262 if (NULL == callback)
2263 return VC_ERROR_INVALID_PARAMETER;
2266 if (0 != vc_mgr_client_get_client_state(g_vc_m, &state)) {
2267 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Set result callback : A handle is not available");
2268 return VC_ERROR_INVALID_STATE;
2272 if (state != VC_STATE_INITIALIZED) {
2273 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Set result callback : Current state is not 'Initialized'");
2274 return VC_ERROR_INVALID_STATE;
2277 vc_mgr_client_set_all_result_cb(g_vc_m, callback, user_data);
2279 SLOG(LOG_DEBUG, TAG_VCM, "[SUCCESS] Set all result callback");
2284 int vc_mgr_unset_all_result_cb()
2287 if (0 != vc_mgr_client_get_client_state(g_vc_m, &state)) {
2288 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Unset result callback : A handle is not available");
2289 return VC_ERROR_INVALID_STATE;
2293 if (state != VC_STATE_INITIALIZED) {
2294 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Unset result callback : Current state is not 'Initialized'");
2295 return VC_ERROR_INVALID_STATE;
2298 vc_mgr_client_set_all_result_cb(g_vc_m, NULL, NULL);
2303 int vc_mgr_set_result_cb(vc_result_cb callback, void* user_data)
2305 if (NULL == callback)
2306 return VC_ERROR_INVALID_PARAMETER;
2309 if (0 != vc_mgr_client_get_client_state(g_vc_m, &state)) {
2310 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Set result callback : A handle is not available");
2311 return VC_ERROR_INVALID_STATE;
2315 if (state != VC_STATE_INITIALIZED) {
2316 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Set result callback : Current state is not 'Initialized'");
2317 return VC_ERROR_INVALID_STATE;
2320 vc_mgr_client_set_result_cb(g_vc_m, callback, user_data);
2325 int vc_mgr_unset_result_cb()
2328 if (0 != vc_mgr_client_get_client_state(g_vc_m, &state)) {
2329 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Unset result callback : A handle is not available");
2330 return VC_ERROR_INVALID_STATE;
2334 if (state != VC_STATE_INITIALIZED) {
2335 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Unset result callback : Current state is not 'Initialized'");
2336 return VC_ERROR_INVALID_STATE;
2339 vc_mgr_client_set_result_cb(g_vc_m, NULL, NULL);
2344 int vc_mgr_set_pre_result_cb(vc_mgr_pre_result_cb callback, void* user_data)
2346 if (NULL == callback)
2347 return VC_ERROR_INVALID_PARAMETER;
2350 if (0 != vc_mgr_client_get_client_state(g_vc_m, &state)) {
2351 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Set pre result callback : A handle is not available");
2352 return VC_ERROR_INVALID_STATE;
2356 if (state != VC_STATE_INITIALIZED) {
2357 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Set pre result callback : Current state is not 'Initialized'");
2358 return VC_ERROR_INVALID_STATE;
2361 vc_mgr_client_set_pre_result_cb(g_vc_m, callback, user_data);
2366 int vc_mgr_unset_pre_result_cb()
2369 if (0 != vc_mgr_client_get_client_state(g_vc_m, &state)) {
2370 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Unset pre result callback : A handle is not available");
2371 return VC_ERROR_INVALID_STATE;
2375 if (state != VC_STATE_INITIALIZED) {
2376 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Unset pre result callback : Current state is not 'Initialize'");
2377 return VC_ERROR_INVALID_STATE;
2380 vc_mgr_client_set_pre_result_cb(g_vc_m, NULL, NULL);
2385 int vc_mgr_get_error_message(char** err_msg)
2387 SLOG(LOG_DEBUG, TAG_VCM, "===== [Manager] Get error message");
2389 if (NULL == err_msg) {
2390 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] invalid parameter");
2391 return VC_ERROR_INVALID_PARAMETER;
2394 if (false == g_err_callback_status) {
2395 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Not in error callback");
2396 return VC_ERROR_OPERATION_FAILED;
2400 ret = vc_mgr_client_get_error_message(g_vc_m, err_msg);
2402 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to get error message");
2405 SLOG(LOG_DEBUG, TAG_VCM, "=====");
2406 SLOG(LOG_DEBUG, TAG_VCM, " ");
2411 static Eina_Bool __vc_mgr_notify_error(void *data)
2413 vc_h vc_m = (vc_h)data;
2415 vc_error_cb callback = NULL;
2416 void* user_data = NULL;
2419 vc_mgr_client_get_error_cb(vc_m, &callback, &user_data);
2420 vc_mgr_client_get_error(vc_m, &reason);
2422 if (NULL != callback) {
2423 vc_mgr_client_use_callback(vc_m);
2424 g_err_callback_status = true;
2425 callback(reason, user_data);
2426 g_err_callback_status = false;
2427 vc_mgr_client_not_use_callback(vc_m);
2428 SLOG(LOG_DEBUG, TAG_VCM, "Error callback is called");
2430 SLOG(LOG_WARN, TAG_VCM, "[WARNING] Error callback is null");
2436 int __vc_mgr_cb_error(int reason, int daemon_pid, char* msg)
2439 if (0 != vc_mgr_client_get_client_state(g_vc_m, &state)) {
2440 SLOG(LOG_ERROR, TAG_VCM, "[WARNING] Invalid client");
2445 if (state != VC_STATE_READY) {
2446 SLOG(LOG_ERROR, TAG_VCM, "[WARNING] not connected client yet");
2450 vc_mgr_client_set_internal_state(g_vc_m, VC_INTERNAL_STATE_NONE);
2452 if (VC_ERROR_SERVICE_RESET == reason) {
2453 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] VC daemon reset");
2455 vc_mgr_client_set_client_state(g_vc_m, VC_STATE_INITIALIZED);
2456 __vc_mgr_notify_state_changed(g_vc_m);
2458 if (0 != vc_mgr_prepare()) {
2459 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to prepare");
2463 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Error reason(%d), msg(%s)", reason, msg);
2465 vc_mgr_client_set_error(g_vc_m, reason);
2466 vc_mgr_client_set_error_message(g_vc_m, msg);
2467 __vc_mgr_notify_error(g_vc_m);
2472 static Eina_Bool __vc_mgr_notify_state_changed(void *data)
2474 vc_state_changed_cb changed_callback = NULL;
2477 vc_mgr_client_get_state_changed_cb(g_vc_m, &changed_callback, &user_data);
2479 vc_state_e current_state;
2480 vc_state_e before_state;
2482 vc_mgr_client_get_before_state(g_vc_m, ¤t_state, &before_state);
2484 if (NULL != changed_callback) {
2485 vc_mgr_client_use_callback(g_vc_m);
2486 changed_callback(before_state, current_state, user_data);
2487 vc_mgr_client_not_use_callback(g_vc_m);
2488 SLOG(LOG_DEBUG, TAG_VCM, "State changed callback is called");
2490 SLOG(LOG_WARN, TAG_VCM, "[WARNING] State changed callback is null");
2496 int vc_mgr_set_state_changed_cb(vc_state_changed_cb callback, void* user_data)
2498 if (callback == NULL)
2499 return VC_ERROR_INVALID_PARAMETER;
2502 if (0 != vc_mgr_client_get_client_state(g_vc_m, &state)) {
2503 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Set state changed callback : A handle is not available");
2504 return VC_ERROR_INVALID_STATE;
2508 if (state != VC_STATE_INITIALIZED) {
2509 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Set state changed callback : Current state is not 'Initialized'");
2510 return VC_ERROR_INVALID_STATE;
2513 vc_mgr_client_set_state_changed_cb(g_vc_m, callback, user_data);
2515 SLOG(LOG_DEBUG, TAG_VCM, "[SUCCESS] Set state changed callback");
2519 int vc_mgr_unset_state_changed_cb()
2522 if (0 != vc_mgr_client_get_client_state(g_vc_m, &state)) {
2523 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Unset state changed callback : A handle is not available");
2524 return VC_ERROR_INVALID_STATE;
2528 if (state != VC_STATE_INITIALIZED) {
2529 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Unset state changed callback : Current state is not 'Initialized'");
2530 return VC_ERROR_INVALID_STATE;
2533 vc_mgr_client_set_state_changed_cb(g_vc_m, NULL, NULL);
2538 int __vc_mgr_cb_service_state(int state)
2540 vc_service_state_e current_state = (vc_service_state_e)state;
2541 vc_service_state_e before_state;
2542 vc_mgr_client_get_service_state(g_vc_m, &before_state);
2544 SLOG(LOG_DEBUG, TAG_VCM, "Service State changed : Before(%d) Current(%d)",
2545 before_state, current_state);
2547 vc_internal_state_e internal_state = -1;
2548 vc_mgr_client_get_internal_state(g_vc_m, &internal_state);
2549 if ((VC_INTERNAL_STATE_STARTING == internal_state && VC_SERVICE_STATE_RECORDING == current_state) ||
2550 (VC_INTERNAL_STATE_STOPPING == internal_state && VC_SERVICE_STATE_PROCESSING == current_state) ||
2551 (VC_INTERNAL_STATE_CANCELING == internal_state && VC_SERVICE_STATE_READY == current_state)) {
2552 SLOG(LOG_DEBUG, TAG_VCM, "Internal state is changed to NONE");
2553 vc_mgr_client_set_internal_state(g_vc_m, VC_INTERNAL_STATE_NONE);
2556 if (current_state == before_state) {
2557 SLOG(LOG_WARN, TAG_VCM, "Service State NOT changed : Before(%d) Current(%d)",
2558 before_state, current_state);
2562 /* Save service state */
2563 vc_mgr_client_set_service_state(g_vc_m, current_state);
2565 vc_service_state_changed_cb callback = NULL;
2566 void* service_user_data = NULL;
2567 vc_mgr_client_get_service_state_changed_cb(g_vc_m, &callback, &service_user_data);
2569 if (NULL != callback) {
2570 vc_mgr_client_use_callback(g_vc_m);
2571 callback(before_state, current_state, service_user_data);
2572 vc_mgr_client_not_use_callback(g_vc_m);
2573 SLOG(LOG_DEBUG, TAG_VCM, "Service state changed callback is called");
2575 SLOG(LOG_WARN, TAG_VCM, "[WARNING] Service state changed callback is null");
2581 int vc_mgr_set_service_state_changed_cb(vc_service_state_changed_cb callback, void* user_data)
2583 if (callback == NULL)
2584 return VC_ERROR_INVALID_PARAMETER;
2587 if (0 != vc_mgr_client_get_client_state(g_vc_m, &state)) {
2588 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Set state changed callback : A handle is not available");
2589 return VC_ERROR_INVALID_STATE;
2593 if (state != VC_STATE_INITIALIZED) {
2594 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Set state changed callback : Current state is not 'Initialized'");
2595 return VC_ERROR_INVALID_STATE;
2598 vc_mgr_client_set_service_state_changed_cb(g_vc_m, callback, user_data);
2600 SLOG(LOG_DEBUG, TAG_VCM, "[SUCCESS] Set sevice state changed callback");
2604 int vc_mgr_unset_service_state_changed_cb()
2607 if (0 != vc_mgr_client_get_client_state(g_vc_m, &state)) {
2608 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Unset state changed callback : A handle is not available");
2609 return VC_ERROR_INVALID_STATE;
2613 if (state != VC_STATE_INITIALIZED) {
2614 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Unset state changed callback : Current state is not 'Initialized'");
2615 return VC_ERROR_INVALID_STATE;
2618 vc_mgr_client_set_service_state_changed_cb(g_vc_m, NULL, NULL);
2622 int vc_mgr_set_speech_detected_cb(vc_mgr_begin_speech_detected_cb callback, void* user_data)
2624 if (callback == NULL)
2625 return VC_ERROR_INVALID_PARAMETER;
2628 if (0 != vc_mgr_client_get_client_state(g_vc_m, &state)) {
2629 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Set state changed callback : A handle is not available");
2630 return VC_ERROR_INVALID_STATE;
2634 if (state != VC_STATE_INITIALIZED) {
2635 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Set speech detected callback : Current state is not 'Initialized'");
2636 return VC_ERROR_INVALID_STATE;
2639 vc_mgr_client_set_speech_detected_cb(g_vc_m, callback, user_data);
2641 SLOG(LOG_DEBUG, TAG_VCM, "[SUCCESS] Set speech detected callback");
2645 int vc_mgr_unset_speech_detected_cb()
2648 if (0 != vc_mgr_client_get_client_state(g_vc_m, &state)) {
2649 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Unset state changed callback : A handle is not available");
2650 return VC_ERROR_INVALID_STATE;
2654 if (state != VC_STATE_INITIALIZED) {
2655 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Unset state changed callback : Current state is not 'Initialized'");
2656 return VC_ERROR_INVALID_STATE;
2659 vc_mgr_client_set_speech_detected_cb(g_vc_m, NULL, NULL);
2663 int vc_mgr_set_current_language_changed_cb(vc_current_language_changed_cb callback, void* user_data)
2665 if (NULL == callback)
2666 return VC_ERROR_INVALID_PARAMETER;
2669 if (0 != vc_mgr_client_get_client_state(g_vc_m, &state)) {
2670 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Set current language changed : A handle is not available");
2671 return VC_ERROR_INVALID_STATE;
2675 if (state != VC_STATE_INITIALIZED) {
2676 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Set current language changed : Current state is not 'Initialized'");
2677 return VC_ERROR_INVALID_STATE;
2680 vc_mgr_client_set_current_lang_changed_cb(g_vc_m, callback, user_data);
2682 SLOG(LOG_DEBUG, TAG_VCM, "[SUCCESS] Set current language changed callback");
2686 int vc_mgr_unset_current_language_changed_cb()
2689 if (0 != vc_mgr_client_get_client_state(g_vc_m, &state)) {
2690 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Unset current language changed : A handle is not available");
2691 return VC_ERROR_INVALID_STATE;
2695 if (state != VC_STATE_INITIALIZED) {
2696 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Unset current language changed : Current state is not 'Initialized'");
2697 return VC_ERROR_INVALID_STATE;
2700 vc_mgr_client_set_current_lang_changed_cb(g_vc_m, NULL, NULL);
2705 int vc_mgr_set_error_cb(vc_error_cb callback, void* user_data)
2707 if (NULL == callback)
2708 return VC_ERROR_INVALID_PARAMETER;
2711 if (0 != vc_mgr_client_get_client_state(g_vc_m, &state)) {
2712 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Set error callback : A handle is not available");
2713 return VC_ERROR_INVALID_STATE;
2717 if (state != VC_STATE_INITIALIZED) {
2718 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Set error callback : Current state is not 'Initialized'");
2719 return VC_ERROR_INVALID_STATE;
2722 vc_mgr_client_set_error_cb(g_vc_m, callback, user_data);
2727 int vc_mgr_unset_error_cb()
2730 if (0 != vc_mgr_client_get_client_state(g_vc_m, &state)) {
2731 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Unset error callback : A handle is not available");
2732 return VC_ERROR_INVALID_STATE;
2736 if (state != VC_STATE_INITIALIZED) {
2737 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Unset error callback : Current state is not 'Initialized'");
2738 return VC_ERROR_INVALID_STATE;
2741 vc_mgr_client_set_error_cb(g_vc_m, NULL, NULL);
2746 int __vc_mgr_cb_dialog(int pid, const char* disp_text, const char* utt_text, bool continuous)
2748 vc_mgr_dialog_request_cb callback = NULL;
2749 void* user_data = NULL;
2751 vc_mgr_client_get_dialog_request_cb(g_vc_m, &callback, &user_data);
2753 if (NULL != callback) {
2754 vc_mgr_client_use_callback(g_vc_m);
2755 callback(pid, disp_text, utt_text, continuous, user_data);
2756 vc_mgr_client_not_use_callback(g_vc_m);
2757 SLOG(LOG_DEBUG, TAG_VCM, "Dialog callback is called, disp_text(%s), utt)text(%s), continous(%d)", disp_text, utt_text, continuous);
2759 SLOG(LOG_WARN, TAG_VCM, "[WARNING] Error callback is null");
2765 int __vc_mgr_cb_private_data_set(const char* key, const char* data)
2767 vc_mgr_private_data_set_cb callback = NULL;
2768 void* user_data = NULL;
2771 vc_mgr_client_get_private_data_set_cb(g_vc_m, &callback, &user_data);
2773 if (NULL != callback) {
2774 vc_mgr_client_use_callback(g_vc_m);
2775 ret = callback(key, data, user_data);
2776 vc_mgr_client_not_use_callback(g_vc_m);
2777 SLOG(LOG_DEBUG, TAG_VCM, "Private data set callback is called");
2779 SLOG(LOG_WARN, TAG_VCM, "[WARNING] Private data set callback is null");
2785 int __vc_mgr_cb_private_data_requested(const char* key, char** data)
2787 vc_mgr_private_data_requested_cb callback = NULL;
2788 void* user_data = NULL;
2791 vc_mgr_client_get_private_data_requested_cb(g_vc_m, &callback, &user_data);
2793 if (NULL != callback) {
2794 vc_mgr_client_use_callback(g_vc_m);
2795 ret = callback(key, data, user_data);
2796 vc_mgr_client_not_use_callback(g_vc_m);
2797 SLOG(LOG_DEBUG, TAG_VCM, "Private data requested callback is called");
2799 SLOG(LOG_WARN, TAG_VCM, "[WARNING] Private data requested callback is null");
2805 int vc_mgr_set_dialog_request_cb(vc_mgr_dialog_request_cb callback, void* user_data)
2807 if (NULL == callback)
2808 return VC_ERROR_INVALID_PARAMETER;
2811 if (0 != vc_mgr_client_get_client_state(g_vc_m, &state)) {
2812 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Set error callback : A handle is not available");
2813 return VC_ERROR_INVALID_STATE;
2817 if (state != VC_STATE_INITIALIZED) {
2818 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Set error callback : Current state is not 'Initialized'");
2819 return VC_ERROR_INVALID_STATE;
2822 vc_mgr_client_set_dialog_request_cb(g_vc_m, callback, user_data);
2827 int vc_mgr_unset_dialog_request_cb()
2830 if (0 != vc_mgr_client_get_client_state(g_vc_m, &state)) {
2831 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Unset error callback : A handle is not available");
2832 return VC_ERROR_INVALID_STATE;
2836 if (state != VC_STATE_INITIALIZED) {
2837 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Unset error callback : Current state is not 'Initialized'");
2838 return VC_ERROR_INVALID_STATE;
2841 vc_mgr_client_set_dialog_request_cb(g_vc_m, NULL, NULL);
2846 int vc_mgr_set_private_data_set_cb(vc_mgr_private_data_set_cb callback, void* user_data)
2848 if (NULL == callback)
2849 return VC_ERROR_INVALID_PARAMETER;
2852 if (0 != vc_mgr_client_get_client_state(g_vc_m, &state)) {
2853 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Set private data set callback : A handle is not available");
2854 return VC_ERROR_INVALID_STATE;
2858 if (VC_STATE_INITIALIZED != state) {
2859 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Set private data set callback : Current state is not 'Initialized'");
2860 return VC_ERROR_INVALID_STATE;
2863 vc_mgr_client_set_private_data_set_cb(g_vc_m, callback, user_data);
2868 int vc_mgr_unset_private_data_set_cb()
2871 if (0 != vc_mgr_client_get_client_state(g_vc_m, &state)) {
2872 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Unset private data set callback : A handle is not available");
2873 return VC_ERROR_INVALID_STATE;
2877 if (VC_STATE_INITIALIZED != state) {
2878 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Unset private data set callback : Current state is not 'Initialized'");
2879 return VC_ERROR_INVALID_STATE;
2882 vc_mgr_client_set_private_data_set_cb(g_vc_m, NULL, NULL);
2887 int vc_mgr_set_private_data_requested_cb(vc_mgr_private_data_requested_cb callback, void* user_data)
2889 if (NULL == callback)
2890 return VC_ERROR_INVALID_PARAMETER;
2893 if (0 != vc_mgr_client_get_client_state(g_vc_m, &state)) {
2894 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Set private data requested callback : A handle is not available");
2895 return VC_ERROR_INVALID_STATE;
2899 if (VC_STATE_INITIALIZED != state) {
2900 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Set private data requested callback : Current state is not 'Initialized'");
2901 return VC_ERROR_INVALID_STATE;
2904 vc_mgr_client_set_private_data_requested_cb(g_vc_m, callback, user_data);
2909 int vc_mgr_unset_private_data_requested_cb()
2912 if (0 != vc_mgr_client_get_client_state(g_vc_m, &state)) {
2913 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Unset private data requested callback : A handle is not available");
2914 return VC_ERROR_INVALID_STATE;
2918 if (VC_STATE_INITIALIZED != state) {
2919 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Unset private data requested callback : Current state is not 'Initialized'");
2920 return VC_ERROR_INVALID_STATE;
2923 vc_mgr_client_set_private_data_requested_cb(g_vc_m, NULL, NULL);
2928 static bool __vc_mgr_check_demandable_client(int pid)
2930 if (0 == g_slist_length(g_demandable_client_list)) {
2931 SLOG(LOG_WARN, TAG_VCM, "[WARNING] No demandable clients");
2935 char appid[128] = {'\0', };
2936 aul_app_get_appid_bypid(pid, appid, sizeof(appid));
2938 if (0 >= strlen(appid)) {
2939 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] No appid");
2942 SLOG(LOG_DEBUG, TAG_VCM, "[CHECK] Appid - %s", appid);
2944 GSList *iter = NULL;
2945 vc_demandable_client_s* temp_client;
2946 iter = g_slist_nth(g_demandable_client_list, 0);
2948 while (NULL != iter) {
2949 temp_client = iter->data;
2951 if (NULL != temp_client) {
2952 if (NULL != temp_client->appid) {
2953 if (!strcmp(temp_client->appid, appid)) {
2954 SLOG(LOG_DEBUG, TAG_VCM, "pid(%d) is available", pid);
2960 iter = g_slist_next(iter);
2967 int __vc_mgr_request_auth_enable(int pid)
2969 if (false == __vc_mgr_check_demandable_client(pid)) {
2970 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Not demandable client");
2971 return VC_ERROR_INVALID_PARAMETER;
2974 /* check already authorized */
2975 if (true == vc_mgr_client_is_authorized_client(g_vc_m, pid)) {
2976 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Already authorized");
2977 return VC_ERROR_INVALID_PARAMETER;
2980 /* add authorized list */
2981 if (0 != vc_mgr_client_add_authorized_client(g_vc_m, pid)) {
2982 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to add authorized client");
2983 return VC_ERROR_OPERATION_FAILED;
2986 /* foreground check */
2988 if (0 != vc_mgr_client_get_foreground(g_vc_m, &fore_pid)) {
2989 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to get foreground");
2990 return VC_ERROR_OPERATION_FAILED;
2993 if (pid == fore_pid) {
2994 vc_mgr_client_set_valid_authorized_client(g_vc_m, pid);
3000 int __vc_mgr_request_auth_disable(int pid)
3002 /* check authorized */
3003 if (false == vc_mgr_client_is_authorized_client(g_vc_m, pid)) {
3004 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] No authorized");
3005 return VC_ERROR_INVALID_PARAMETER;
3008 /* remove authorized list */
3009 if (0 != vc_mgr_client_remove_authorized_client(g_vc_m, pid)) {
3010 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to remove authorized client");
3011 return VC_ERROR_OPERATION_FAILED;
3014 /* check authority valid */
3015 if (true == vc_mgr_client_is_valid_authorized_client(g_vc_m, pid)) {
3016 SLOG(LOG_DEBUG, TAG_VCM, "Valid authorized client is removed");
3017 if (0 != vc_mgr_client_set_valid_authorized_client(g_vc_m, -1)) {
3018 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to set valid authorized client");
3019 return VC_ERROR_OPERATION_FAILED;
3026 static Eina_Bool __request_auth_start(void* data)
3028 SLOG(LOG_DEBUG, TAG_VCM, "Request Start");
3030 if (0 != vc_mgr_client_set_start_by_client(g_vc_m, true)) {
3031 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to set start by client");
3034 if (0 != vc_mgr_start(false)) {
3035 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Request start is failed");
3036 /* TODO - Error handling? */
3039 if (0 != vc_mgr_client_set_start_by_client(g_vc_m, false)) {
3040 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to set start by client");
3047 int __vc_mgr_request_auth_start(int pid)
3049 /* check authorized */
3050 if (false == vc_mgr_client_is_valid_authorized_client(g_vc_m, pid)) {
3051 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] No valid authorized client");
3052 return VC_ERROR_INVALID_PARAMETER;
3055 /* add timer for start recording */
3056 ecore_timer_add(0, __request_auth_start, NULL);
3061 static Eina_Bool __request_auth_stop(void* data)
3063 SLOG(LOG_DEBUG, TAG_VCM, "Request Stop");
3065 if (0 != vc_mgr_stop()) {
3066 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Request stop is failed");
3067 /* TODO - Error handling? */
3073 int __vc_mgr_request_auth_stop(int pid)
3075 /* check authorized */
3076 if (false == vc_mgr_client_is_valid_authorized_client(g_vc_m, pid)) {
3077 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] No valid authorized client");
3078 return VC_ERROR_INVALID_PARAMETER;
3081 /* add timer for start recording */
3082 ecore_timer_add(0, __request_auth_stop, NULL);
3087 static Eina_Bool __request_auth_cancel(void* data)
3089 SLOG(LOG_DEBUG, TAG_VCM, "Request Cancel");
3091 if (0 != vc_mgr_cancel()) {
3092 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Request cancel is failed");
3093 /* TODO - Error handling? */
3099 int __vc_mgr_request_auth_cancel(int pid)
3101 /* check authorized */
3102 if (false == vc_mgr_client_is_valid_authorized_client(g_vc_m, pid)) {
3103 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] No valid authorized client");
3104 return VC_ERROR_INVALID_PARAMETER;
3107 /* add timer for start recording */
3108 ecore_timer_add(0, __request_auth_cancel, NULL);