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>
19 #include <cynara-client.h>
20 #include <cynara-error.h>
21 #include <cynara-session.h>
23 #include <sound_manager.h>
24 #include <sound_manager_internal.h>
27 #include "vc_cmd_db.h"
28 #include "vc_config_mgr.h"
29 #include "vc_command.h"
30 #include "vc_info_parser.h"
31 #include "vc_json_parser.h"
33 #include "vc_mgr_client.h"
34 #include "vc_mgr_tidl.h"
35 #include "vc_mgr_data.h"
36 #include "vc_mgr_player.h"
37 #include "voice_control.h"
38 #include "voice_control_command.h"
39 #include "voice_control_command_expand.h"
40 #include "voice_control_common.h"
41 #include "voice_control_manager.h"
42 #include "voice_control_manager_internal.h"
45 #define VC_MANAGER_CONFIG_HANDLE 10000000
47 static Ecore_Timer* g_send_hello_timer = NULL;
48 static Ecore_Timer* g_request_init_timer = NULL;
49 static int g_tidl_send_hello_count = 0;
51 static Ecore_Timer* g_m_set_volume_timer = NULL;
53 static vc_h g_vc_m = NULL;
55 static GSList* g_demandable_client_list = NULL;
57 static float g_volume_db = 0;
59 static float g_prev_volume_db = 0;
61 static float g_cur_volume_db = 0;
63 static int g_daemon_pid = 0;
65 static int g_feature_enabled = -1;
67 static bool g_privilege_allowed = false;
69 static cynara *p_cynara = NULL;
70 static pthread_mutex_t g_cynara_mutex = PTHREAD_MUTEX_INITIALIZER;
72 static bool g_err_callback_status = false;
74 /* for changing volume on each sound stream */
75 static sound_stream_info_h g_stream_for_volume_h = NULL;
76 static virtual_sound_stream_h g_virtual_sound_stream_h = NULL;
78 /* for TTS feedback */
79 static int g_feedback_rate = 16000;
80 static vc_audio_channel_e g_feedback_audio_channel = 0;
81 static vc_audio_type_e g_feedback_audio_type = 0;
82 static Ecore_Thread* g_feedback_thread = NULL;
84 static pthread_mutex_t g_feedback_streaming_cb_mutex = PTHREAD_MUTEX_INITIALIZER;
85 static pthread_mutex_t g_vc_tts_streaming_cb_mutex = PTHREAD_MUTEX_INITIALIZER;
87 static Eina_Bool __vc_mgr_notify_state_changed(void *data);
88 static void __vc_mgr_notify_error(void *data);
89 static Eina_Bool __vc_mgr_notify_result(void *data);
91 int __vc_mgr_cb_error(int reason, int daemon_pid, char* msg);
94 static const char* __vc_mgr_get_error_code(vc_error_e err)
97 case VC_ERROR_NONE: return "VC_ERROR_NONE";
98 case VC_ERROR_OUT_OF_MEMORY: return "VC_ERROR_OUT_OF_MEMORY";
99 case VC_ERROR_IO_ERROR: return "VC_ERROR_IO_ERROR";
100 case VC_ERROR_INVALID_PARAMETER: return "VC_ERROR_INVALID_PARAMETER";
101 case VC_ERROR_TIMED_OUT: return "VC_ERROR_TIMED_OUT";
102 case VC_ERROR_RECORDER_BUSY: return "VC_ERROR_RECORDER_BUSY";
103 case VC_ERROR_INVALID_STATE: return "VC_ERROR_INVALID_STATE";
104 case VC_ERROR_INVALID_LANGUAGE: return "VC_ERROR_INVALID_LANGUAGE";
105 case VC_ERROR_ENGINE_NOT_FOUND: return "VC_ERROR_ENGINE_NOT_FOUND";
106 case VC_ERROR_OPERATION_FAILED: return "VC_ERROR_OPERATION_FAILED";
107 default: return "Invalid error code";
112 static void __vc_mgr_lang_changed_cb(const char* before_lang, const char* current_lang)
114 SLOG(LOG_INFO, TAG_VCM, "Lang changed : Before lang(%s) Current lang(%s)",
115 before_lang, current_lang);
117 vc_current_language_changed_cb callback = NULL;
118 void* lang_user_data;
119 vc_mgr_client_get_current_lang_changed_cb(g_vc_m, &callback, &lang_user_data);
121 if (NULL != callback) {
122 vc_mgr_client_use_callback(g_vc_m);
123 callback(before_lang, current_lang, lang_user_data);
124 vc_mgr_client_not_use_callback(g_vc_m);
125 SLOG(LOG_INFO, TAG_VCM, "Language changed callback is called");
127 SLOG(LOG_WARN, TAG_VCM, "[WARNING] Language changed callback is null");
133 static int __vc_mgr_get_feature_enabled()
135 if (0 == g_feature_enabled) {
136 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Voice control feature NOT supported");
137 return VC_ERROR_NOT_SUPPORTED;
138 } else if (-1 == g_feature_enabled) {
139 bool vc_supported = false;
140 bool mic_supported = false;
141 if (0 == system_info_get_platform_bool(VC_MGR_FEATURE_PATH, &vc_supported)) {
142 if (0 == system_info_get_platform_bool(VC_MIC_FEATURE_PATH, &mic_supported)) {
143 if (false == vc_supported || false == mic_supported) {
144 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Voice control feature NOT supported");
145 g_feature_enabled = 0;
146 return VC_ERROR_NOT_SUPPORTED;
149 g_feature_enabled = 1;
154 return VC_ERROR_NONE;
157 static int __check_privilege_initialize()
159 int ret = cynara_initialize(&p_cynara, NULL);
160 if (NULL == p_cynara || CYNARA_API_SUCCESS != ret) {
161 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] fail to initialize(%d)", ret);
165 return ret == CYNARA_API_SUCCESS;
168 static int __check_privilege(const char* uid, const char * privilege)
171 char label_path[1024] = "/proc/self/attr/current";
172 char smack_label[1024] = {'\0',};
175 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] p_cynara is NULL");
179 fp = fopen(label_path, "r");
181 if (fread(smack_label, 1, sizeof(smack_label), fp) <= 0)
182 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] fail to fread");
187 pid_t pid = getpid();
188 char *session = cynara_session_from_pid(pid);
189 int ret = cynara_check(p_cynara, smack_label, session, uid, privilege);
194 if (ret != CYNARA_API_ACCESS_ALLOWED) {
195 SLOG(LOG_INFO, TAG_VCM, "[Client]cynara_check returned %d(Denied), p_cynara(%p), label(%s), session(%s), uid(%s), priv(%s)", ret, p_cynara, smack_label, session, uid, privilege);
202 static void __check_privilege_deinitialize()
205 int ret = cynara_finish(p_cynara);
206 if (ret != CYNARA_API_SUCCESS)
207 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] cynara finish %d", ret);
212 static int __vc_mgr_check_privilege()
214 if (true == g_privilege_allowed)
215 return VC_ERROR_NONE;
217 pthread_mutex_lock(&g_cynara_mutex);
219 if (false == g_privilege_allowed) {
221 ret = __check_privilege_initialize();
223 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] privilege initialize is failed");
224 g_privilege_allowed = false;
225 pthread_mutex_unlock(&g_cynara_mutex);
226 return VC_ERROR_PERMISSION_DENIED;
230 snprintf(uid, 32, "%d", getuid());
232 ret = __check_privilege(uid, VC_PRIVILEGE_RECORDER);
234 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Permission is denied(%s)(%s)", VC_PRIVILEGE_RECORDER, uid);
235 __check_privilege_deinitialize();
236 g_privilege_allowed = false;
237 pthread_mutex_unlock(&g_cynara_mutex);
238 return VC_ERROR_PERMISSION_DENIED;
241 ret = __check_privilege(uid, VC_MGR_PRIVILEGE);
243 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Permission is denied(%s)(%s)", VC_MGR_PRIVILEGE, uid);
244 __check_privilege_deinitialize();
245 g_privilege_allowed = false;
246 pthread_mutex_unlock(&g_cynara_mutex);
247 return VC_ERROR_PERMISSION_DENIED;
250 ret = __check_privilege(uid, VC_PRIVILEGE_DATASHARING);
252 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Permission is denied(%s)(%s)", VC_PRIVILEGE_DATASHARING, uid);
253 __check_privilege_deinitialize();
254 g_privilege_allowed = false;
255 pthread_mutex_unlock(&g_cynara_mutex);
256 return VC_ERROR_PERMISSION_DENIED;
259 ret = __check_privilege(uid, VC_PRIVILEGE_APPMGR);
261 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Permission is denied(%s)(%s)", VC_PRIVILEGE_APPMGR, uid);
262 __check_privilege_deinitialize();
263 g_privilege_allowed = false;
264 pthread_mutex_unlock(&g_cynara_mutex);
265 return VC_ERROR_PERMISSION_DENIED;
268 __check_privilege_deinitialize();
271 g_privilege_allowed = true;
272 pthread_mutex_unlock(&g_cynara_mutex);
273 return VC_ERROR_NONE;
276 int vc_mgr_initialize(void)
278 SLOG(LOG_ERROR, TAG_VCM, "@@@ [Manager] Initialize");
281 if (0 != __vc_mgr_get_feature_enabled()) {
282 SLOG(LOG_DEBUG, TAG_VCM, "@@@ [Manager] not supported");
283 return VC_ERROR_NOT_SUPPORTED;
286 if (0 != __vc_mgr_check_privilege()) {
287 return VC_ERROR_PERMISSION_DENIED;
291 if (true == vc_mgr_client_is_valid(g_vc_m)) {
292 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Already initialized");
293 return VC_ERROR_NONE;
296 if (0 != vc_mgr_tidl_open_connection()) {
297 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to open tidl connection");
298 return VC_ERROR_OPERATION_FAILED;
301 if (0 != vc_mgr_client_create(&g_vc_m)) {
302 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to create client!!!!!");
303 return VC_ERROR_OUT_OF_MEMORY;
306 int ret = vc_config_mgr_initialize(g_vc_m->handle + VC_MANAGER_CONFIG_HANDLE);
308 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to init config manager : %d", ret);
309 vc_mgr_client_destroy(g_vc_m);
310 return VC_ERROR_OPERATION_FAILED;
313 ret = vc_config_mgr_set_lang_cb(g_vc_m->handle + VC_MANAGER_CONFIG_HANDLE, __vc_mgr_lang_changed_cb);
315 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to set callback : %d", ret);
316 vc_config_mgr_finalize(g_vc_m->handle + VC_MANAGER_CONFIG_HANDLE);
317 vc_mgr_client_destroy(g_vc_m);
318 return VC_ERROR_OPERATION_FAILED;
321 ret = vc_mgr_client_set_audio_streaming_mode(g_vc_m, VC_AUDIO_STREAMING_MODE_VC_SERVICE);
323 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to set audio streaming mode : %d", ret);
324 vc_config_mgr_finalize(g_vc_m->handle + VC_MANAGER_CONFIG_HANDLE);
325 vc_mgr_client_destroy(g_vc_m);
329 /* for TTS feedback */
330 /* ret = vc_mgr_player_init();
332 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to initialize VC mgr player : %d", ret);
335 SLOG(LOG_ERROR, TAG_VCM, "[Success] pid(%d)", g_vc_m->handle);
337 SLOG(LOG_DEBUG, TAG_VCM, "@@@ [Manager] Initialize DONE");
339 return VC_ERROR_NONE;
342 static void __vc_mgr_internal_unprepare()
344 int ret = vc_mgr_tidl_request_finalize(g_vc_m->handle);
346 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to request finalize : %s", __vc_mgr_get_error_code(ret));
349 vc_mgr_client_set_internal_state(g_vc_m, VC_INTERNAL_STATE_NONE);
353 int vc_mgr_deinitialize(void)
355 SLOG(LOG_ERROR, TAG_VCM, "@@@ [Manager] Deinitialize");
357 if (0 != __vc_mgr_get_feature_enabled()) {
358 SLOG(LOG_DEBUG, TAG_VCM, "@@@ [Manager] not supported");
359 return VC_ERROR_NOT_SUPPORTED;
362 if (0 != __vc_mgr_check_privilege()) {
363 return VC_ERROR_PERMISSION_DENIED;
366 if (false == vc_mgr_client_is_valid(g_vc_m)) {
367 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] NOT initialized");
368 return VC_ERROR_INVALID_STATE;
372 vc_mgr_client_get_client_state(g_vc_m, &state);
377 __vc_mgr_internal_unprepare();
378 /* no break. need to next step*/
379 case VC_STATE_INITIALIZED:
380 if (NULL != g_send_hello_timer) {
381 SLOG(LOG_DEBUG, TAG_VCM, "Connect Timer is deleted");
382 ecore_timer_del(g_send_hello_timer);
383 g_send_hello_timer = NULL;
385 if (g_request_init_timer) {
386 SLOG(LOG_DEBUG, TAG_VCM, "Connect idler is deleted");
387 ecore_timer_del(g_request_init_timer);
388 g_request_init_timer = NULL;
391 vc_config_mgr_unset_lang_cb(g_vc_m->handle + VC_MANAGER_CONFIG_HANDLE);
392 vc_config_mgr_finalize(g_vc_m->handle + VC_MANAGER_CONFIG_HANDLE);
394 /* Free client resources */
395 vc_mgr_client_destroy(g_vc_m);
402 SLOG(LOG_DEBUG, TAG_VCM, "Success: destroy");
404 int cnt = VC_COMMAND_TYPE_FOREGROUND;
406 int ret = vc_cmd_parser_delete_file(getpid(), cnt);
408 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to delete file, type(%d), ret(%d)", cnt, ret);
409 } while (VC_COMMAND_TYPE_EXCLUSIVE >= ++cnt);
411 int ret = vc_db_finalize();
413 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to finalize DB, ret(%d)", ret);
416 /* for TTS feedback */
417 /* ret = vc_mgr_player_release();
419 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to release VC mgr player(%d)", ret);
423 if (0 != vc_mgr_tidl_close_connection()) {
424 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to close connection");
427 SLOG(LOG_ERROR, TAG_VCM, "@@@ [Manager] Deinitialize DONE");
429 return VC_ERROR_NONE;
432 static Eina_Bool __request_initialize(void *data)
434 /* request initialization */
436 int service_state = 0;
437 int foreground = VC_RUNTIME_INFO_NO_FOREGROUND;
441 if (true == vc_mgr_client_is_valid(g_vc_m)) {
442 SLOG(LOG_DEBUG, TAG_VCM, "[DEBUG] g_vc_m is valid");
445 ret = vc_db_initialize();
447 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to initialize DB : %d", ret);
451 vc_audio_streaming_mode_e streaming_mode;
452 vc_mgr_client_get_audio_streaming_mode(g_vc_m, &streaming_mode);
454 ret = vc_mgr_tidl_request_initialize(g_vc_m->handle, (int)streaming_mode, &service_state, &foreground, &g_daemon_pid);
456 if (VC_ERROR_ENGINE_NOT_FOUND == ret) {
457 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to initialize : %s", __vc_mgr_get_error_code(ret));
459 vc_mgr_client_set_error(g_vc_m, VC_ERROR_ENGINE_NOT_FOUND);
460 ecore_main_loop_thread_safe_call_async(__vc_mgr_notify_error, (void*)g_vc_m);
462 SLOG(LOG_DEBUG, TAG_VCM, "@@@");
463 g_request_init_timer = NULL;
466 } else if (0 != ret) {
467 SLOG(LOG_ERROR, TAG_VCM, "[WARNING] Fail to connection. Retry to connect : %s", __vc_mgr_get_error_code(ret));
468 ret = vc_db_finalize();
470 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to finalize DB : %d", ret);
474 /* Success to connect */
477 /* Set service state */
478 vc_service_state_e previous_service_state;
479 vc_mgr_client_get_service_state(g_vc_m, &previous_service_state);
480 vc_mgr_client_set_service_state(g_vc_m, (vc_service_state_e)service_state);
482 vc_service_state_changed_cb service_changed_callback = NULL;
483 void* user_data = NULL;
484 vc_mgr_client_get_service_state_changed_cb(g_vc_m, &service_changed_callback, &user_data);
486 if (NULL != service_changed_callback) {
487 vc_mgr_client_use_callback(g_vc_m);
488 service_changed_callback(previous_service_state, service_state, user_data);
489 vc_mgr_client_not_use_callback(g_vc_m);
490 SLOG(LOG_INFO, TAG_VCM, "Service state changed callback is called");
492 SLOG(LOG_WARN, TAG_VCM, "[WARNING] Service state changed callback is null");
496 vc_mgr_client_set_foreground(g_vc_m, foreground, true);
498 SLOG(LOG_ERROR, TAG_VCM, "[SUCCESS] Connected daemon");
500 /* Set client state */
501 vc_mgr_client_set_client_state(g_vc_m, VC_STATE_READY);
503 vc_state_changed_cb changed_callback = NULL;
505 vc_mgr_client_get_state_changed_cb(g_vc_m, &changed_callback, &user_data);
507 vc_state_e current_state;
508 vc_state_e before_state;
510 vc_mgr_client_get_before_state(g_vc_m, ¤t_state, &before_state);
512 if (NULL != changed_callback) {
513 vc_mgr_client_use_callback(g_vc_m);
514 changed_callback(before_state, current_state, user_data);
515 vc_mgr_client_not_use_callback(g_vc_m);
516 SLOG(LOG_INFO, TAG_VCM, "State changed callback is called");
518 SLOG(LOG_WARN, TAG_VCM, "[WARNING] State changed callback is null");
521 SLOG(LOG_ERROR, TAG_VCM, "[Not ERROR] g_vc_m is not valid. It is destroyed."); //LCOV_EXCL_LINE
522 g_request_init_timer = NULL;
526 SLOG(LOG_ERROR, TAG_VCM, "@@@");
528 g_request_init_timer = NULL;
533 static Eina_Bool __send_hello_message(void *data)
536 if (0 != vc_mgr_tidl_request_hello()) {
537 if (g_tidl_send_hello_count == VC_TIDL_RETRY_COUNT) {
538 g_tidl_send_hello_count = 0;
539 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to request hello !! send error to manager");
540 __vc_mgr_cb_error(VC_ERROR_TIMED_OUT, -1, "voice_framework.error.vcfw.connect_engine_fail");
541 g_send_hello_timer = NULL;
544 // TODO: discuss when updating connect/reconnect
545 g_tidl_send_hello_count++;
551 SLOG(LOG_DEBUG, TAG_VCM, "===== [Manager] Connect daemon");
553 if (NULL == g_request_init_timer) {
554 SLOG(LOG_INFO, TAG_VCM, "[DEBUG] Create a new idler for preparation");
555 g_request_init_timer = ecore_timer_add(0.0, __request_initialize, NULL);
557 SLOG(LOG_INFO, TAG_VCM, "[INFO] idler handle is already created");
560 g_send_hello_timer = NULL;
564 int vc_mgr_prepare(void)
566 SLOG(LOG_ERROR, TAG_VCM, "@@@ [Manager] Prepare");
568 if (0 != __vc_mgr_get_feature_enabled()) {
569 SLOG(LOG_DEBUG, TAG_VCM, "@@@ [Manager] not supported");
570 return VC_ERROR_NOT_SUPPORTED;
573 if (0 != __vc_mgr_check_privilege()) {
574 return VC_ERROR_PERMISSION_DENIED;
578 if (0 != vc_mgr_client_get_client_state(g_vc_m, &state)) {
579 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] A handle is not available");
580 return VC_ERROR_INVALID_STATE;
584 RETVM_IF(state != VC_STATE_INITIALIZED, VC_ERROR_INVALID_STATE, TAG_VCM, "[ERROR] Invalid State: Current state(%d) is not 'Initialized'", state);
586 if (NULL == g_send_hello_timer) {
587 g_tidl_send_hello_count = 0;
588 SLOG(LOG_INFO, TAG_VCM, "[DEBUG] Create a new timer for preparation");
589 ecore_thread_main_loop_begin();
590 g_send_hello_timer = ecore_timer_add(0.02, __send_hello_message, NULL);
591 ecore_thread_main_loop_end();
593 SLOG(LOG_INFO, TAG_VCM, "[INFO] timer handle is already created");
596 SLOG(LOG_DEBUG, TAG_VCM, "@@@ [Manager] Calling Prepare DONE");
598 return VC_ERROR_NONE;
601 int vc_mgr_unprepare(void)
603 SLOG(LOG_ERROR, TAG_VCM, "@@@ [Manager] Unprepare");
605 if (0 != __vc_mgr_get_feature_enabled()) {
606 SLOG(LOG_DEBUG, TAG_VCM, "@@@ [Manager] not supported");
607 return VC_ERROR_NOT_SUPPORTED;
610 if (0 != __vc_mgr_check_privilege()) {
611 return VC_ERROR_PERMISSION_DENIED;
615 if (0 != vc_mgr_client_get_client_state(g_vc_m, &state)) {
616 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] A handle is not available");
617 return VC_ERROR_INVALID_STATE;
621 RETVM_IF(state != VC_STATE_READY, VC_ERROR_INVALID_STATE, TAG_VCM, "[ERROR] Invalid State: Current state(%d) is not 'Ready'", state);
623 __vc_mgr_internal_unprepare();
625 vc_mgr_client_set_client_state(g_vc_m, VC_STATE_INITIALIZED);
626 ecore_timer_add(0, __vc_mgr_notify_state_changed, g_vc_m);
628 SLOG(LOG_DEBUG, TAG_VCM, "@@@ [Manager] Unprepare DONE");
630 return VC_ERROR_NONE;
633 int vc_mgr_foreach_supported_languages(vc_supported_language_cb callback, void* user_data)
635 SLOG(LOG_INFO, TAG_VCM, "@@@ [Manager] Foreach Supported Language");
637 if (0 != __vc_mgr_get_feature_enabled()) {
638 SLOG(LOG_DEBUG, TAG_VCM, "@@@ [Manager] not supported");
639 return VC_ERROR_NOT_SUPPORTED;
642 if (0 != __vc_mgr_check_privilege()) {
643 return VC_ERROR_PERMISSION_DENIED;
646 RETVM_IF(NULL == callback, VC_ERROR_INVALID_PARAMETER, TAG_VCM, "[ERROR] Input parameter is NULL");
649 if (0 != vc_mgr_client_get_client_state(g_vc_m, &state)) {
650 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] A handle is not available");
651 return VC_ERROR_INVALID_STATE;
655 ret = vc_config_mgr_get_language_list(callback, user_data);
657 ret = vc_config_convert_error_code((vc_config_error_e)ret);
658 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to get languages : %s", __vc_mgr_get_error_code(ret));
661 SLOG(LOG_DEBUG, TAG_VCM, "@@@ [Manager] Foreach Supported Language DONE");
663 return VC_ERROR_NONE;
666 int vc_mgr_get_current_language(char** language)
668 if (0 != __vc_mgr_get_feature_enabled()) {
669 SLOG(LOG_DEBUG, TAG_VCM, "@@@ [Manager] not supported");
670 return VC_ERROR_NOT_SUPPORTED;
673 if (0 != __vc_mgr_check_privilege()) {
674 return VC_ERROR_PERMISSION_DENIED;
677 RETVM_IF(NULL == language, VC_ERROR_INVALID_PARAMETER, TAG_VCM, "[ERROR] Input parameter is NULL");
680 if (0 != vc_mgr_client_get_client_state(g_vc_m, &state)) {
681 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] A handle is not available");
682 return VC_ERROR_INVALID_STATE;
686 ret = vc_config_mgr_get_default_language(language);
688 ret = vc_config_convert_error_code((vc_config_error_e)ret);
689 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to get current languages : %s", __vc_mgr_get_error_code(ret));
691 SLOG(LOG_ERROR, TAG_VCM, "[Get current language] language : %s", *language);
697 int vc_mgr_get_state(vc_state_e* state)
699 SLOG(LOG_DEBUG, TAG_VCM, "@@@ [Manager] Get State");
701 if (0 != __vc_mgr_get_feature_enabled()) {
702 SLOG(LOG_DEBUG, TAG_VCM, "@@@ [Manager] not supported");
703 return VC_ERROR_NOT_SUPPORTED;
706 if (0 != __vc_mgr_check_privilege()) {
707 return VC_ERROR_PERMISSION_DENIED;
710 RETVM_IF(NULL == state, VC_ERROR_INVALID_PARAMETER, TAG_VCM, "[ERROR] Input parameter is NULL");
713 if (NULL == g_vc_m) {
714 temp = VC_STATE_NONE;
715 } else if (0 != vc_mgr_client_get_client_state(g_vc_m, &temp)) {
716 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] A handle is not available");
717 return VC_ERROR_INVALID_STATE;
723 case VC_STATE_NONE: SLOG(LOG_INFO, TAG_VCM, "Current state is 'None'"); break;
724 case VC_STATE_INITIALIZED: SLOG(LOG_INFO, TAG_VCM, "Current state is 'Created'"); break;
725 case VC_STATE_READY: SLOG(LOG_INFO, TAG_VCM, "Current state is 'Ready'"); break;
726 default: SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Invalid state");
729 SLOG(LOG_DEBUG, TAG_VCM, "@@@ [Manager] Get State DONE");
731 return VC_ERROR_NONE;
734 int vc_mgr_get_service_state(vc_service_state_e* state)
736 SLOG(LOG_DEBUG, TAG_VCM, "@@@ [Manager] Get Service State");
738 if (0 != __vc_mgr_get_feature_enabled()) {
739 SLOG(LOG_DEBUG, TAG_VCM, "@@@ [Manager] not supported");
740 return VC_ERROR_NOT_SUPPORTED;
743 if (0 != __vc_mgr_check_privilege()) {
744 return VC_ERROR_PERMISSION_DENIED;
747 RETVM_IF(NULL == state, VC_ERROR_INVALID_PARAMETER, TAG_VCM, "[ERROR] Input parameter is NULL");
749 vc_state_e client_state;
750 if (0 != vc_mgr_client_get_client_state(g_vc_m, &client_state)) {
751 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] A handle is not available");
752 return VC_ERROR_INVALID_STATE;
756 RETVM_IF(client_state != VC_STATE_READY, VC_ERROR_INVALID_STATE, TAG_VCM, "[ERROR] Current state is not 'READY'");
758 /* get service state */
759 vc_service_state_e service_state;
760 if (0 != vc_mgr_client_get_service_state(g_vc_m, &service_state)) {
761 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to get service state");
762 return VC_ERROR_OPERATION_FAILED;
765 *state = service_state;
768 case VC_SERVICE_STATE_NONE: SLOG(LOG_DEBUG, TAG_VCM, "Current service state is 'None'"); break;
769 case VC_SERVICE_STATE_READY: SLOG(LOG_DEBUG, TAG_VCM, "Current service state is 'Ready'"); break;
770 case VC_SERVICE_STATE_RECORDING: SLOG(LOG_DEBUG, TAG_VCM, "Current service state is 'Recording'"); break;
771 case VC_SERVICE_STATE_PROCESSING: SLOG(LOG_DEBUG, TAG_VCM, "Current service state is 'Processing'"); break;
772 default: SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Invalid state");
775 SLOG(LOG_DEBUG, TAG_VCM, "@@@ [Manager] Get Service State DONE");
777 return VC_ERROR_NONE;
780 int vc_mgr_set_demandable_client_rule(const char* rule)
782 SLOG(LOG_INFO, TAG_VCM, "@@@ [Manager] Set Demandable client rule(%s)", rule);
784 if (0 != __vc_mgr_get_feature_enabled()) {
785 SLOG(LOG_DEBUG, TAG_VCM, "@@@ [Manager] not supported");
786 return VC_ERROR_NOT_SUPPORTED;
789 if (0 != __vc_mgr_check_privilege()) {
790 return VC_ERROR_PERMISSION_DENIED;
794 if (0 != vc_mgr_client_get_client_state(g_vc_m, &state)) {
795 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] A handle is not available");
796 return VC_ERROR_INVALID_STATE;
800 RETVM_IF(state != VC_STATE_READY, VC_ERROR_INVALID_STATE, TAG_VCM, "[ERROR] Invalid State: Current state(%d) is not 'Ready'", state);
803 ret = vc_info_parser_set_demandable_client(rule);
805 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] rule is NOT valid");
806 SLOG(LOG_DEBUG, TAG_VCM, "@@@");
807 return VC_ERROR_INVALID_PARAMETER;
810 if (0 != vc_info_parser_get_demandable_clients(&g_demandable_client_list)) {
811 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to get demandable clients");
812 return VC_ERROR_OPERATION_FAILED;
815 SLOG(LOG_DEBUG, TAG_VCM, "@@@ [Manager] Set Demandable client rule(%s) DONE", rule);
817 return VC_ERROR_NONE;
820 int vc_mgr_unset_demandable_client_rule(void)
822 SLOG(LOG_INFO, TAG_VCM, "@@@ [Manager] Unset Demandable client");
824 if (0 != __vc_mgr_get_feature_enabled()) {
825 SLOG(LOG_DEBUG, TAG_VCM, "@@@ [Manager] not supported");
826 return VC_ERROR_NOT_SUPPORTED;
829 if (0 != __vc_mgr_check_privilege()) {
830 return VC_ERROR_PERMISSION_DENIED;
833 vc_info_parser_set_demandable_client(NULL);
835 int ret = vc_mgr_tidl_request_demandable_client(g_vc_m->handle);
837 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to request unset client rule to daemon : %s", __vc_mgr_get_error_code(ret));
840 // TODO: check return value correct or not
841 return VC_ERROR_NONE;
844 int vc_mgr_is_command_format_supported(int format, bool* support)
846 SLOG(LOG_ERROR, TAG_VCM, "@@@ [Manager] Is command type supported");
848 if (0 != __vc_mgr_get_feature_enabled()) {
849 SLOG(LOG_DEBUG, TAG_VCM, "@@@ [Manager] not supported");
850 return VC_ERROR_NOT_SUPPORTED;
853 if (0 != __vc_mgr_check_privilege()) {
854 return VC_ERROR_PERMISSION_DENIED;
857 RETVM_IF(NULL == support, VC_ERROR_INVALID_PARAMETER, TAG_VCM, "[ERROR] Input parameter is NULL");
860 if (0 != vc_mgr_client_get_client_state(g_vc_m, &state)) {
861 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] A handle is not available");
862 return VC_ERROR_INVALID_STATE;
866 bool non_fixed_support = false;
867 if (0 != vc_config_mgr_get_nonfixed_support(&non_fixed_support)) {
868 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to get nonfixed support info");
872 case VC_CMD_FORMAT_FIXED: *support = true; break;
873 case VC_CMD_FORMAT_FIXED_AND_VFIXED: *support = true; break;
874 case VC_CMD_FORMAT_VFIXED_AND_FIXED: *support = true; break;
875 case VC_CMD_FORMAT_FIXED_AND_NONFIXED: *support = non_fixed_support; break;
876 case VC_CMD_FORMAT_NONFIXED_AND_FIXED: *support = non_fixed_support; break;
877 default: *support = false; break;
880 SLOG(LOG_ERROR, TAG_VCM, "[DEBUG] Format(%d) support(%s)", format, *support ? "true" : "false");
882 SLOG(LOG_DEBUG, TAG_VCM, "@@@ [Manager] Is command type supported DONE");
884 return VC_ERROR_NONE;
887 int vc_mgr_enable_command_type(int cmd_type)
889 SLOG(LOG_ERROR, TAG_VCM, "@@@ [Manager] Enable Command Type, cmd_type(%d)", cmd_type);
891 if (0 != __vc_mgr_get_feature_enabled()) {
892 SLOG(LOG_DEBUG, TAG_VCM, "@@@ [Manager] not supported");
893 return VC_ERROR_NOT_SUPPORTED;
896 if (0 != __vc_mgr_check_privilege()) {
897 return VC_ERROR_PERMISSION_DENIED;
900 if (VC_COMMAND_TYPE_FOREGROUND > cmd_type || VC_COMMAND_TYPE_EXCLUSIVE < cmd_type) {
901 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] cmd_type is not valid. (%d)", cmd_type);
902 return VC_ERROR_INVALID_PARAMETER;
906 if (0 != vc_mgr_client_get_client_state(g_vc_m, &state)) {
907 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] A handle is not available");
908 return VC_ERROR_INVALID_STATE;
912 RETVM_IF(state != VC_STATE_READY, VC_ERROR_INVALID_STATE, TAG_VCM, "[ERROR] Invalid State: Current state(%d) is not 'Ready'", state);
914 /* Check service state */
915 vc_service_state_e service_state = -1;
916 vc_mgr_client_get_service_state(g_vc_m, &service_state);
917 RETVM_IF(service_state != VC_SERVICE_STATE_READY, VC_ERROR_INVALID_STATE, TAG_VCM, "[ERROR] Invalid State: Current service state(%d) is not 'READY'", service_state);
921 ret = vc_mgr_client_enable_command_type(g_vc_m, (vc_cmd_type_e)cmd_type); // enable the cmd type
923 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to enable the command type(%d). ret(%d)", cmd_type, ret);
925 SLOG(LOG_DEBUG, TAG_VCM, "[DEBUG] Success to enable the command type(%d)", cmd_type);
928 SLOG(LOG_ERROR, TAG_VCM, "@@@ [Manager] Enable Command Type DONE, ret(%d)", ret);
933 int vc_mgr_disable_command_type(int cmd_type)
935 SLOG(LOG_ERROR, TAG_VCM, "@@@ [Manager] Disable Command Type, cmd_type(%d)", cmd_type);
937 if (0 != __vc_mgr_get_feature_enabled()) {
938 SLOG(LOG_DEBUG, TAG_VCM, "@@@ [Manager] not supported");
939 return VC_ERROR_NOT_SUPPORTED;
942 if (0 != __vc_mgr_check_privilege()) {
943 return VC_ERROR_PERMISSION_DENIED;
946 if (VC_COMMAND_TYPE_FOREGROUND > cmd_type || VC_COMMAND_TYPE_EXCLUSIVE < cmd_type) {
947 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] cmd type is not valid, (%d)", cmd_type);
948 return VC_ERROR_INVALID_PARAMETER;
952 if (0 != vc_mgr_client_get_client_state(g_vc_m, &state)) {
953 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] A handle is not available");
954 return VC_ERROR_INVALID_STATE;
958 RETVM_IF(state != VC_STATE_READY, VC_ERROR_INVALID_STATE, TAG_VCM, "[ERROR] Invalid State: Current state(%d) is not 'Ready'", state);
960 /* Check service state */
961 vc_service_state_e service_state = -1;
962 vc_mgr_client_get_service_state(g_vc_m, &service_state);
963 RETVM_IF(service_state != VC_SERVICE_STATE_READY, VC_ERROR_INVALID_STATE, TAG_VCM, "[ERROR] Invalid State: Current service state(%d) is not 'READY'", service_state);
967 ret = vc_mgr_client_disable_command_type(g_vc_m, (vc_cmd_type_e)cmd_type); // enable the cmd type
969 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to disable the command type(%d). ret(%d)", cmd_type, ret);
971 SLOG(LOG_DEBUG, TAG_VCM, "[DEBUG] Success to disable the command type(%d)", cmd_type);
974 SLOG(LOG_ERROR, TAG_VCM, "@@@ [Manager] Disable Command Type DONE, ret(%d)", ret);
979 int vc_mgr_set_command_list(vc_cmd_list_h vc_cmd_list)
981 SLOG(LOG_ERROR, TAG_VCM, "@@@ [Manager] Set Command list");
983 if (0 != __vc_mgr_get_feature_enabled()) {
984 SLOG(LOG_DEBUG, TAG_VCM, "@@@ [Manager] not supported");
985 return VC_ERROR_NOT_SUPPORTED;
988 if (0 != __vc_mgr_check_privilege()) {
989 return VC_ERROR_PERMISSION_DENIED;
993 if (0 != vc_mgr_client_get_client_state(g_vc_m, &state)) {
994 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] A handle is not available");
995 return VC_ERROR_INVALID_STATE;
999 RETVM_IF(state != VC_STATE_READY, VC_ERROR_INVALID_STATE, TAG_VCM, "[ERROR] Invalid State: Current state(%d) is not 'READY'", state);
1001 /* Check service state */
1002 vc_service_state_e service_state = -1;
1003 vc_mgr_client_get_service_state(g_vc_m, &service_state);
1004 RETVM_IF(service_state != VC_SERVICE_STATE_READY, VC_ERROR_INVALID_STATE, TAG_VCM, "[ERROR] Invalid State: service state(%d) is not 'READY'", service_state);
1006 RETVM_IF(NULL == vc_cmd_list, VC_ERROR_INVALID_PARAMETER, TAG_VCM, "[ERROR] Input parameter is NULL");
1008 vc_cmd_list_s* list = NULL;
1009 list = (vc_cmd_list_s*)vc_cmd_list;
1010 SLOG(LOG_INFO, TAG_VCM, "[List] (%p) (%p)", list, list->list);
1012 RETVM_IF(NULL == list->list, VC_ERROR_INVALID_PARAMETER, TAG_VCM, "[ERROR] Input command list");
1016 bool success_save = false;
1017 for (i = VC_COMMAND_TYPE_FOREGROUND; i <= VC_COMMAND_TYPE_EXCLUSIVE; i++) {
1018 ret = vc_cmd_parser_delete_file(getpid(), i);
1020 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to delete file, type(%d), ret(%d)", i, ret);
1022 ret = vc_cmd_parser_save_file(getpid(), i, list->list, NULL);
1024 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to save file, type(%d), ret(%d)", i, ret);
1026 SLOG(LOG_INFO, TAG_VCM, "[SUCCESS] Save file, type(%d)", i);
1027 success_save = true;
1031 if (true != success_save) {
1032 ret = VC_ERROR_INVALID_PARAMETER;
1033 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to save command group : %s", __vc_mgr_get_error_code(ret));
1035 ret = vc_mgr_tidl_request_set_command(g_vc_m->handle);
1037 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to request set command to daemon : %s", __vc_mgr_get_error_code(ret));
1041 SLOG(LOG_ERROR, TAG_VCM, "@@@ [Manager] Set Command list DONE, ret(%d)", ret);
1046 int vc_mgr_unset_command_list(void)
1048 SLOG(LOG_ERROR, TAG_VCM, "@@@ [Manager] Unset Command list");
1050 if (0 != __vc_mgr_get_feature_enabled()) {
1051 SLOG(LOG_DEBUG, TAG_VCM, "@@@ [Manager] not supported");
1052 return VC_ERROR_NOT_SUPPORTED;
1055 if (0 != __vc_mgr_check_privilege()) {
1056 return VC_ERROR_PERMISSION_DENIED;
1060 if (0 != vc_mgr_client_get_client_state(g_vc_m, &state)) {
1061 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] A handle is not available");
1062 return VC_ERROR_INVALID_STATE;
1066 RETVM_IF(state != VC_STATE_READY, VC_ERROR_INVALID_STATE, TAG_VCM, "[ERROR] Invalid State: Current state(%d) is not 'READY'", state);
1070 ret = vc_mgr_tidl_request_unset_command(g_vc_m->handle);
1072 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to request unset command to daemon : %s", __vc_mgr_get_error_code(ret));
1076 for (i = VC_COMMAND_TYPE_FOREGROUND; i <= VC_COMMAND_TYPE_EXCLUSIVE; i++) {
1077 ret = vc_cmd_parser_delete_file(getpid(), i);
1079 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to delete file, type(%d), ret(%d)", i, ret);
1082 SLOG(LOG_ERROR, TAG_VCM, "@@@ [Manager] Unset Command list DONE");
1084 // TODO: check return value correct or not
1085 return VC_ERROR_NONE;
1088 int vc_mgr_set_command_list_from_file(const char* file_path, int type)
1090 SLOG(LOG_ERROR, TAG_VCM, "@@@ [Manager] Set Command list from file, type(%d)", type);
1092 if (0 != __vc_mgr_get_feature_enabled()) {
1093 SLOG(LOG_DEBUG, TAG_VCM, "@@@ [Manager] not supported");
1094 return VC_ERROR_NOT_SUPPORTED;
1097 if (0 != __vc_mgr_check_privilege()) {
1098 return VC_ERROR_PERMISSION_DENIED;
1101 RETVM_IF(NULL == file_path, VC_ERROR_INVALID_PARAMETER, TAG_VCM, "[ERROR] Invalid parameter");
1102 SLOG(LOG_INFO, TAG_VCM, "@@@ File path: %s", file_path);
1105 if (VC_COMMAND_TYPE_FOREGROUND > type || VC_COMMAND_TYPE_EXCLUSIVE < type) {
1106 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Invalid command type: input type is %d", type);
1107 return VC_ERROR_INVALID_PARAMETER;
1111 if (0 != vc_mgr_client_get_client_state(g_vc_m, &state)) {
1112 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] A handle is not available");
1113 return VC_ERROR_INVALID_STATE;
1117 RETVM_IF(state != VC_STATE_READY, VC_ERROR_INVALID_STATE, TAG_VCM, "[ERROR] Invalid State: Current state(%d) is not 'READY'", state);
1119 /* Check service state */
1120 vc_service_state_e service_state = -1;
1121 vc_mgr_client_get_service_state(g_vc_m, &service_state);
1122 RETVM_IF(service_state != VC_SERVICE_STATE_READY, VC_ERROR_INVALID_STATE, TAG_VCM, "[ERROR] Invalid State: Current service state(%d) is not 'READY'", service_state);
1124 int ret = vc_cmd_parser_delete_file(getpid(), type);
1126 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to delete file, type(4), ret(%d)", ret);
1128 if (0 != vc_json_set_commands_from_file(file_path, type, NULL)) {
1129 ret = VC_ERROR_INVALID_PARAMETER;
1130 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to save command list (%d)", ret);
1132 ret = vc_mgr_tidl_request_set_command(g_vc_m->handle);
1134 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to request set command to daemon : %s", __vc_mgr_get_error_code(ret));
1138 SLOG(LOG_ERROR, TAG_VCM, "@@@ [Manager] Set Command list from file DONE, ret(%d)", ret);
1143 int vc_mgr_set_preloaded_commands_from_file(const char* file_path)
1145 SLOG(LOG_ERROR, TAG_VCM, "@@@ [Manager] Set preloaded command list");
1147 if (0 != __vc_mgr_get_feature_enabled()) {
1148 SLOG(LOG_DEBUG, TAG_VCM, "@@@ [Manager] not supported");
1149 return VC_ERROR_NOT_SUPPORTED;
1152 if (0 != __vc_mgr_check_privilege()) {
1153 return VC_ERROR_PERMISSION_DENIED;
1156 RETVM_IF(NULL == file_path, VC_ERROR_INVALID_PARAMETER, TAG_VCM, "[ERROR] Invalid parameter");
1157 SLOG(LOG_INFO, TAG_VCM, "@@@ File path: %s", file_path);
1160 if (0 != vc_mgr_client_get_client_state(g_vc_m, &state)) {
1161 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] A handle is not available");
1162 return VC_ERROR_INVALID_STATE;
1166 RETVM_IF(state != VC_STATE_READY, VC_ERROR_INVALID_STATE, TAG_VCM, "[ERROR] Invalid State: Current state(%d) is not 'READY'", state);
1168 /* Check service state */
1169 vc_service_state_e service_state = -1;
1170 vc_mgr_client_get_service_state(g_vc_m, &service_state);
1171 RETVM_IF(service_state != VC_SERVICE_STATE_READY, VC_ERROR_INVALID_STATE, TAG_VCM, "[ERROR] Invalid State: Current service state(%d) is not 'READY'", service_state);
1173 /* Only support to set background commands for preloaded application */
1174 int ret = vc_json_set_commands_from_file(file_path, VC_COMMAND_TYPE_BACKGROUND, NULL);
1176 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to insert preloaded commands into db");
1178 SLOG(LOG_ERROR, TAG_VCM, "@@@ [Manager] Set preloaded command list DONE, ret(%d)", ret);
1182 int vc_mgr_set_audio_type(const char* audio_id)
1184 SLOG(LOG_ERROR, TAG_VCM, "@@@ [Manager] Set audio type, audio_id(%s)", audio_id);
1186 if (0 != __vc_mgr_get_feature_enabled()) {
1187 SLOG(LOG_DEBUG, TAG_VCM, "@@@ [Manager] not supported");
1188 return VC_ERROR_NOT_SUPPORTED;
1191 if (0 != __vc_mgr_check_privilege()) {
1192 return VC_ERROR_PERMISSION_DENIED;
1195 if (NULL == audio_id || !strncmp(audio_id, "", strlen(audio_id))) {
1196 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Input parameter is NULL");
1197 return VC_ERROR_INVALID_PARAMETER;
1201 if (0 != vc_mgr_client_get_client_state(g_vc_m, &state)) {
1202 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] A handle is not available");
1203 return VC_ERROR_INVALID_STATE;
1207 RETVM_IF(state != VC_STATE_READY, VC_ERROR_INVALID_STATE, TAG_VCM, "[ERROR] Invalid State: Current state(%d) is not 'READY'", state);
1209 /* Check service state */
1210 vc_service_state_e service_state = -1;
1211 vc_mgr_client_get_service_state(g_vc_m, &service_state);
1212 RETVM_IF(service_state != VC_SERVICE_STATE_READY, VC_ERROR_INVALID_STATE, TAG_VCM, "[ERROR] Invalid State: Current service state(%d) is not 'READY'", service_state);
1216 ret = vc_mgr_tidl_request_set_audio_type(g_vc_m->handle, audio_id);
1218 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to set audio type : %s", __vc_mgr_get_error_code(ret));
1220 SLOG(LOG_INFO, TAG_VCM, "[SUCCESS] Set audio type");
1222 vc_mgr_client_set_audio_type(g_vc_m, audio_id);
1225 SLOG(LOG_ERROR, TAG_VCM, "@@@ [Manager] Set audio type DONE, ret(%d)", ret);
1230 int vc_mgr_get_audio_type(char** audio_id)
1232 SLOG(LOG_ERROR, TAG_VCM, "@@@ [Manager] Get audio type");
1234 if (0 != __vc_mgr_get_feature_enabled()) {
1235 SLOG(LOG_DEBUG, TAG_VCM, "@@@ [Manager] not supported");
1236 return VC_ERROR_NOT_SUPPORTED;
1239 if (0 != __vc_mgr_check_privilege()) {
1240 return VC_ERROR_PERMISSION_DENIED;
1243 RETVM_IF(NULL == audio_id, VC_ERROR_INVALID_PARAMETER, TAG_VCM, "[ERROR] Invalid parameter");
1246 if (0 != vc_mgr_client_get_client_state(g_vc_m, &state)) {
1247 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] A handle is not available");
1248 return VC_ERROR_INVALID_STATE;
1252 RETVM_IF(state != VC_STATE_READY, VC_ERROR_INVALID_STATE, TAG_VCM, "[ERROR] Invalid State: Current state(%d) is not 'READY'", state);
1254 /* Check service state */
1255 vc_service_state_e service_state = -1;
1256 vc_mgr_client_get_service_state(g_vc_m, &service_state);
1257 RETVM_IF(service_state != VC_SERVICE_STATE_READY, VC_ERROR_INVALID_STATE, TAG_VCM, "[ERROR] Invalid State: Current service state(%d) is not 'READY'", service_state);
1261 vc_mgr_client_get_audio_type(g_vc_m, &temp);
1264 /* Not initiallized */
1267 ret = vc_mgr_tidl_request_get_audio_type(g_vc_m->handle, &temp);
1269 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to get audio type : %s", __vc_mgr_get_error_code(ret));
1271 SLOG(LOG_ERROR, TAG_VCM, "[SUCCESS] Get audio type : %s", temp);
1273 vc_mgr_client_set_audio_type(g_vc_m, temp);
1279 *audio_id = strdup(temp);
1284 // TODO: check return value correct or not
1285 return VC_ERROR_NONE;
1288 int vc_mgr_get_current_commands(vc_cmd_list_h* vc_cmd_list)
1290 SLOG(LOG_ERROR, TAG_VCM, "@@@ [Manager] Foreach current commands");
1292 if (0 != __vc_mgr_get_feature_enabled()) {
1293 SLOG(LOG_DEBUG, TAG_VCM, "@@@ [Manager] not supported");
1294 return VC_ERROR_NOT_SUPPORTED;
1297 if (0 != __vc_mgr_check_privilege()) {
1298 return VC_ERROR_PERMISSION_DENIED;
1302 if (0 != vc_mgr_client_get_client_state(g_vc_m, &state)) {
1303 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] A handle is not available");
1304 return VC_ERROR_INVALID_STATE;
1308 RETVM_IF(state != VC_STATE_READY, VC_ERROR_INVALID_STATE, TAG_VCM, "[ERROR] Invalid State: Current state(%d) is not 'READY'", state);
1310 /* Check service state */
1311 vc_service_state_e service_state = -1;
1312 vc_mgr_client_get_service_state(g_vc_m, &service_state);
1313 RETVM_IF(service_state != VC_SERVICE_STATE_READY, VC_ERROR_INVALID_STATE, TAG_VCM, "[ERROR] Invalid State: service state(%d) is not 'READY'", service_state);
1315 RETVM_IF(NULL == vc_cmd_list, VC_ERROR_INVALID_PARAMETER, TAG_VCM, "[ERROR] Invalid Parameter");
1317 vc_cmd_list_h temp_list = NULL;
1318 if (0 != vc_cmd_list_create(&temp_list)) {
1319 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to create list");
1320 return VC_ERROR_INVALID_PARAMETER;
1323 *vc_cmd_list = temp_list;
1329 /* Get foreground pid */
1330 if (0 != vc_mgr_client_get_foreground(g_vc_m, &fg_pid)) {
1331 /* There is no foreground app for voice control */
1332 SLOG(LOG_WARN, TAG_VCM, "[Manager WARNING] No foreground pid for voice control");
1334 SLOG(LOG_INFO, TAG_VCM, "[Manager] Foreground pid(%d)", fg_pid);
1337 if (0 != vc_mgr_client_get_pid(g_vc_m, &mgr_pid)) {
1338 SLOG(LOG_ERROR, TAG_VCM, "[Manager] Fail to get manager pid");
1339 return VC_ERROR_OPERATION_FAILED;
1341 SLOG(LOG_INFO, TAG_VCM, "[Manager] Manager pid(%d)", mgr_pid);
1344 /* Get system command */
1345 ret = vc_cmd_parser_append_commands(mgr_pid, VC_COMMAND_TYPE_SYSTEM, temp_list);
1347 SLOG(LOG_INFO, TAG_VCM, "[Manager] No system commands");
1351 ret = vc_mgr_tidl_request_set_client_info(g_vc_m->handle);
1353 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to set client info : %s", __vc_mgr_get_error_code(ret));
1355 SLOG(LOG_INFO, TAG_VCM, "[SUCCESS] Set client info");
1358 GSList *iter = NULL;
1359 GSList* client_info_list = NULL;
1360 vc_client_info_s *client_info = NULL;
1361 bool is_fgpid = false;
1363 if (0 != vc_info_parser_get_client_info(&client_info_list)) {
1364 SLOG(LOG_INFO, TAG_VCM, "[DEBUG] No client");
1365 return VC_ERROR_NONE;
1368 if (VC_NO_FOREGROUND_PID != fg_pid) {
1369 iter = g_slist_nth(client_info_list, 0);
1370 while (NULL != iter) {
1371 client_info = iter->data;
1372 if (NULL != client_info) {
1373 if (fg_pid == client_info->pid) {
1378 iter = g_slist_next(iter);
1382 /* Get foreground commands and widget */
1383 if (true == is_fgpid) {
1385 SLOG(LOG_INFO, TAG_VCM, "[Manager] fore cmd(%d)", client_info->fg_cmd);
1387 /* Get foreground command */
1388 if (true == client_info->fg_cmd) {
1389 ret = vc_cmd_parser_append_commands(fg_pid, VC_COMMAND_TYPE_FOREGROUND, temp_list);
1391 SLOG(LOG_ERROR, TAG_VCM, "[Client Data ERROR] Fail to get the fg command list");
1394 SLOG(LOG_INFO, TAG_VCM, "[Manager] No foreground commands");
1397 /* Check exclusive option */
1398 if (true == client_info->exclusive_cmd) {
1399 SLOG(LOG_INFO, TAG_VCM, "[Manager] Exclusive command is ON");
1401 /* Set background command for exclusive option */
1402 if (true == client_info->bg_cmd) {
1403 SLOG(LOG_INFO, TAG_VCM, "[Manager] Set background command");
1404 ret = vc_cmd_parser_append_commands(client_info->pid, VC_COMMAND_TYPE_BACKGROUND, temp_list);
1406 SLOG(LOG_ERROR, TAG_VCM, "[Client Data ERROR] Fail to get the bg command list : pid(%d)", client_info->pid);
1410 /* need to release client info */
1411 iter = g_slist_nth(client_info_list, 0);
1413 while (NULL != iter) {
1414 client_info = iter->data;
1415 if (NULL != client_info) {
1418 client_info_list = g_slist_remove_link(client_info_list, iter);
1419 iter = g_slist_nth(client_info_list, 0);
1422 SLOG(LOG_DEBUG, TAG_VCM, "@@@ [Manager] Foreach current commands DONE");
1424 return VC_ERROR_NONE;
1427 SLOG(LOG_INFO, TAG_VCM, "[Manager] No foreground app");
1430 /* Get background commands */
1431 if (0 < g_slist_length(client_info_list)) {
1432 iter = g_slist_nth(client_info_list, 0);
1434 while (NULL != iter) {
1435 client_info = iter->data;
1437 if (NULL != client_info) {
1438 SLOG(LOG_INFO, TAG_VCM, "[Manager] Pid(%d) Back cmd(%d)", client_info->pid, client_info->bg_cmd);
1439 if (true == client_info->bg_cmd) {
1440 ret = vc_cmd_parser_append_commands(client_info->pid, VC_COMMAND_TYPE_BACKGROUND, temp_list);
1442 SLOG(LOG_ERROR, TAG_VCM, "[Client Data ERROR] Fail to get the bg command list : pid(%d)", client_info->pid);
1447 client_info_list = g_slist_remove_link(client_info_list, iter);
1449 iter = g_slist_nth(client_info_list, 0);
1453 SLOG(LOG_INFO, TAG_VCM, "[Manager] No background commands");
1456 SLOG(LOG_ERROR, TAG_VCM, "@@@ [Manager] Foreach current commands DONE");
1458 // TODO: check return value correct or not
1459 return VC_ERROR_NONE;
1462 int vc_mgr_set_recognition_mode(vc_recognition_mode_e mode)
1464 SLOG(LOG_INFO, TAG_VCM, "@@@ [Manager] Set recognition mode = %d", mode);
1466 if (0 != __vc_mgr_get_feature_enabled()) {
1467 SLOG(LOG_DEBUG, TAG_VCM, "@@@ [Manager] not supported");
1468 return VC_ERROR_NOT_SUPPORTED;
1471 if (0 != __vc_mgr_check_privilege()) {
1472 return VC_ERROR_PERMISSION_DENIED;
1475 /* check vc recognition mode */
1476 if (mode < VC_RECOGNITION_MODE_STOP_BY_SILENCE || mode > VC_RECOGNITION_MODE_MANUAL) {
1477 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] invalid parameter: 'mode' is not supported mode (%d)", mode);
1478 return VC_ERROR_INVALID_PARAMETER;
1482 if (0 != vc_mgr_client_get_client_state(g_vc_m, &state)) {
1483 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] A handle is not available");
1484 return VC_ERROR_INVALID_STATE;
1488 RETVM_IF(state != VC_STATE_READY, VC_ERROR_INVALID_STATE, TAG_VCM, "[ERROR] Invalid State: Current state(%d) is not 'READY'", 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 RETVM_IF(service_state != VC_SERVICE_STATE_READY, VC_ERROR_INVALID_STATE, TAG_VCM, "[ERROR] Invalid State: Current service state(%d) is not 'READY'", service_state);
1495 vc_mgr_client_set_recognition_mode(g_vc_m, mode);
1496 return VC_ERROR_NONE;
1499 int vc_mgr_get_recognition_mode(vc_recognition_mode_e* mode)
1501 if (0 != __vc_mgr_get_feature_enabled()) {
1502 SLOG(LOG_DEBUG, TAG_VCM, "@@@ [Manager] not supported");
1503 return VC_ERROR_NOT_SUPPORTED;
1506 if (0 != __vc_mgr_check_privilege()) {
1507 return VC_ERROR_PERMISSION_DENIED;
1512 RETVM_IF(NULL == mode, VC_ERROR_INVALID_PARAMETER, TAG_VCM, "[ERROR] Invalid parameter, mode is NULL ptr");
1515 if (0 != vc_mgr_client_get_client_state(g_vc_m, &state)) {
1516 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] A handle is not available");
1517 return VC_ERROR_INVALID_STATE;
1520 ret = vc_mgr_client_get_recognition_mode(g_vc_m, mode);
1522 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to get recognition mode");
1526 SLOG(LOG_INFO, TAG_VCM, "@@@ [Manager] Get recognition mode = %d", *mode);
1527 return VC_ERROR_NONE;
1530 int vc_mgr_set_private_data(const char* key, const char* data)
1532 SLOG(LOG_INFO, TAG_VCM, "@@@ [Manager] Set private data");
1534 if (0 != __vc_mgr_get_feature_enabled()) {
1535 SLOG(LOG_DEBUG, TAG_VCM, "@@@ [Manager] not supported");
1536 return VC_ERROR_NOT_SUPPORTED;
1539 if (0 != __vc_mgr_check_privilege()) {
1540 return VC_ERROR_PERMISSION_DENIED;
1543 RETVM_IF(NULL == key, VC_ERROR_INVALID_PARAMETER, TAG_VCM, "[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 return VC_ERROR_INVALID_STATE;
1552 RETVM_IF(state != VC_STATE_READY, VC_ERROR_INVALID_STATE, TAG_VCM, "[ERROR] Invalid State: Current state(%d) is not 'READY'", state);
1554 /* Check service state */
1555 vc_service_state_e service_state = -1;
1556 vc_mgr_client_get_service_state(g_vc_m, &service_state);
1557 RETVM_IF(service_state != VC_SERVICE_STATE_READY, VC_ERROR_INVALID_STATE, TAG_VCM, "[ERROR] Invalid State: Current service state(%d) is not 'READY'", service_state);
1560 ret = vc_mgr_tidl_request_set_private_data(g_vc_m->handle, key, data);
1562 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to set private data : %s", __vc_mgr_get_error_code(ret));
1565 SLOG(LOG_DEBUG, TAG_VCM, "[SUCCESS] Set private data");
1568 SLOG(LOG_DEBUG, TAG_VCM, "@@@ [Manager] Set private data DONE");
1570 return VC_ERROR_NONE;
1573 int vc_mgr_get_private_data(const char* key, char** data)
1575 SLOG(LOG_DEBUG, TAG_VCM, "@@@ [Manager] Get private data");
1577 if (0 != __vc_mgr_get_feature_enabled()) {
1578 SLOG(LOG_DEBUG, TAG_VCM, "@@@ [Manager] not supported");
1579 return VC_ERROR_NOT_SUPPORTED;
1582 if (0 != __vc_mgr_check_privilege()) {
1583 return VC_ERROR_PERMISSION_DENIED;
1586 if (NULL == key || NULL == data) {
1587 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Invalid parameter");
1588 return VC_ERROR_INVALID_PARAMETER;
1592 if (0 != vc_mgr_client_get_client_state(g_vc_m, &state)) {
1593 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] A handle is not available");
1594 return VC_ERROR_INVALID_STATE;
1598 RETVM_IF(state != VC_STATE_READY, VC_ERROR_INVALID_STATE, TAG_VCM, "[ERROR] Invalid State: Current state(%d) is not 'READY'", state);
1600 /* Check service state */
1601 vc_service_state_e service_state = -1;
1602 vc_mgr_client_get_service_state(g_vc_m, &service_state);
1603 RETVM_IF(service_state != VC_SERVICE_STATE_READY, VC_ERROR_INVALID_STATE, TAG_VCM, "[ERROR] Invalid State: Current service state(%d) is not 'READY'", service_state);
1609 ret = vc_mgr_tidl_request_get_private_data(g_vc_m->handle, key, &temp);
1611 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to get private data request : %s", __vc_mgr_get_error_code(ret));
1613 SLOG(LOG_INFO, TAG_VCM, "[SUCCESS] Get private data, key(%s), data(%s)", key, temp);
1618 *data = strdup(temp);
1623 SLOG(LOG_DEBUG, TAG_VCM, "@@@ [Manager] Get private data DONE");
1625 // TODO: check return value correct or not
1626 return VC_ERROR_NONE;
1629 int vc_mgr_set_domain(const char* domain)
1631 SLOG(LOG_DEBUG, TAG_VCM, "@@@ [Manager] Set domain");
1633 if (0 != __vc_mgr_get_feature_enabled()) {
1634 SLOG(LOG_DEBUG, TAG_VCM, "@@@ [Manager] not supported");
1635 return VC_ERROR_NOT_SUPPORTED;
1638 if (0 != __vc_mgr_check_privilege()) {
1639 return VC_ERROR_PERMISSION_DENIED;
1642 RETVM_IF(NULL == domain, VC_ERROR_INVALID_PARAMETER, TAG_VCM, "[ERROR] Invalid parameter");
1645 if (0 != vc_mgr_client_get_client_state(g_vc_m, &state)) {
1646 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] A handle is not available");
1647 return VC_ERROR_INVALID_STATE;
1651 RETVM_IF(state != VC_STATE_READY, VC_ERROR_INVALID_STATE, TAG_VCM, "[ERROR] Invalid State: Current state(%d) is not 'READY'", state);
1653 /* Check service state */
1654 vc_service_state_e service_state = -1;
1655 vc_mgr_client_get_service_state(g_vc_m, &service_state);
1656 RETVM_IF(service_state != VC_SERVICE_STATE_READY, VC_ERROR_INVALID_STATE, TAG_VCM, "[ERROR] Invalid State: Current service state(%d) is not 'READY'", service_state);
1660 ret = vc_mgr_tidl_request_set_domain(g_vc_m->handle, domain);
1662 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to set domain request : %s", __vc_mgr_get_error_code(ret));
1664 SLOG(LOG_INFO, TAG_VCM, "[SUCCESS] Set domain");
1667 SLOG(LOG_DEBUG, TAG_VCM, "@@@ [Manager] Set domain DONE");
1669 return VC_ERROR_NONE;
1672 int vc_mgr_do_action(vc_send_event_type_e type, char* send_event)
1674 SLOG(LOG_INFO, TAG_VCM, "@@@ [Manager] do action");
1676 if (0 != __vc_mgr_get_feature_enabled()) {
1677 SLOG(LOG_DEBUG, TAG_VCM, "@@@ [Manager] not supported");
1678 return VC_ERROR_NOT_SUPPORTED;
1681 if (0 != __vc_mgr_check_privilege()) {
1682 return VC_ERROR_PERMISSION_DENIED;
1685 if (type < VC_SEND_EVENT_TYPE_TEXT || VC_SEND_EVENT_TYPE_HAPTIC_EVENT < type) {
1686 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] send event type is not valid, (%d)", type);
1687 return VC_ERROR_INVALID_PARAMETER;
1690 RETVM_IF(NULL == send_event, VC_ERROR_INVALID_PARAMETER, TAG_VCM, "[ERROR] Invalid parameter");
1693 if (0 != vc_mgr_client_get_client_state(g_vc_m, &state)) {
1694 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] A handle is not available");
1695 return VC_ERROR_INVALID_STATE;
1699 RETVM_IF(state != VC_STATE_READY, VC_ERROR_INVALID_STATE, TAG_VCM, "[ERROR] Invalid State: Current state(%d) is not 'READY'", state);
1701 /* Check service state */
1702 vc_service_state_e service_state = -1;
1703 vc_mgr_client_get_service_state(g_vc_m, &service_state);
1704 RETVM_IF(service_state != VC_SERVICE_STATE_READY, VC_ERROR_INVALID_STATE, TAG_VCM, "[ERROR] Invalid State: Current service state(%d) is not 'READY'", service_state);
1707 ret = vc_mgr_tidl_request_do_action(g_vc_m->handle, type, send_event);
1709 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to do action request : %s", __vc_mgr_get_error_code(ret));
1712 SLOG(LOG_INFO, TAG_VCM, "[SUCCESS] do action");
1714 SLOG(LOG_DEBUG, TAG_VCM, "@@@ [Manager] do action DONE");
1716 return VC_ERROR_NONE;
1719 int vc_mgr_send_specific_engine_request(const char* engine_app_id, const char* event, const char* request)
1721 SLOG(LOG_INFO, TAG_VCM, "@@@ [Manager] send specific engine request");
1723 if (0 != __vc_mgr_get_feature_enabled()) {
1724 SLOG(LOG_DEBUG, TAG_VCM, "@@@ [Manager] not supported");
1725 return VC_ERROR_NOT_SUPPORTED;
1728 if (0 != __vc_mgr_check_privilege()) {
1729 return VC_ERROR_PERMISSION_DENIED;
1732 SLOG(LOG_INFO, TAG_VCM, "@@@ [Manager] specific engine request. engine app id(%s), event(%s), request(%s)", engine_app_id, event, request);
1734 if (NULL == engine_app_id || NULL == event) {
1735 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Invalid parameter");
1736 return VC_ERROR_INVALID_PARAMETER;
1739 if (NULL == request) {
1740 SLOG(LOG_ERROR, TAG_VCM, "[INFO] Input parameter is NULL. (no request)");
1744 if (0 != vc_mgr_client_get_client_state(g_vc_m, &state)) {
1745 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] A handle is not available");
1746 return VC_ERROR_INVALID_STATE;
1750 RETVM_IF(state != VC_STATE_READY, VC_ERROR_INVALID_STATE, TAG_VCM, "[ERROR] Invalid State: Current state(%d) is not 'READY'", state);
1752 /* Check service state */
1753 vc_service_state_e service_state = -1;
1754 vc_mgr_client_get_service_state(g_vc_m, &service_state);
1755 RETVM_IF(service_state != VC_SERVICE_STATE_READY, VC_ERROR_INVALID_STATE, TAG_VCM, "[ERROR] Invalid State: Current service state(%d) is not 'READY'", service_state);
1758 ret = vc_mgr_tidl_send_specific_engine_request(g_vc_m->handle, engine_app_id, event, request);
1760 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to specific engine request : %s", __vc_mgr_get_error_code(ret));
1763 SLOG(LOG_INFO, TAG_VCM, "[SUCCESS] specific engine request");
1765 SLOG(LOG_DEBUG, TAG_VCM, "@@@ [Manager] send specific engine request DONE");
1767 return VC_ERROR_NONE;
1770 int vc_mgr_start(bool exclusive_command_option)
1772 SLOG(LOG_ERROR, TAG_VCM, "@@@ [Manager] Request start");
1774 if (0 != __vc_mgr_get_feature_enabled()) {
1775 SLOG(LOG_DEBUG, TAG_VCM, "@@@ [Manager] not supported");
1776 return VC_ERROR_NOT_SUPPORTED;
1779 if (0 != __vc_mgr_check_privilege()) {
1780 return VC_ERROR_PERMISSION_DENIED;
1784 if (0 != vc_mgr_client_get_client_state(g_vc_m, &state)) {
1785 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] A handle is not available");
1786 return VC_ERROR_INVALID_STATE;
1790 RETVM_IF(state != VC_STATE_READY, VC_ERROR_INVALID_STATE, TAG_VCM, "[ERROR] Invalid State: Current state(%d) is not 'READY'", state);
1792 /* Check service state */
1793 vc_service_state_e service_state = -1;
1794 vc_mgr_client_get_service_state(g_vc_m, &service_state);
1795 RETVM_IF(service_state != VC_SERVICE_STATE_READY, VC_ERROR_INVALID_STATE, TAG_VCM, "[ERROR] Invalid State: Current service state(%d) is not 'READY'", service_state);
1797 /* Check internal state for async */
1798 vc_internal_state_e internal_state = -1;
1799 vc_mgr_client_get_internal_state(g_vc_m, &internal_state);
1800 if (internal_state != VC_INTERNAL_STATE_NONE) {
1801 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Invalid State : Internal state is NOT none : %d", internal_state);
1802 return VC_ERROR_IN_PROGRESS_TO_RECORDING;
1805 vc_mgr_client_set_exclusive_command(g_vc_m, exclusive_command_option);
1807 bool start_by_client = false;
1808 if (0 != vc_mgr_client_get_start_by_client(g_vc_m, &start_by_client)) {
1809 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to get start by client");
1812 int disabled_cmd_type = 0;
1813 if (0 != vc_mgr_client_get_disabled_command_type(g_vc_m, &disabled_cmd_type)) {
1814 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to get disabled command type");
1818 vc_recognition_mode_e recognition_mode = VC_RECOGNITION_MODE_STOP_BY_SILENCE;
1819 if (0 != vc_mgr_get_recognition_mode(&recognition_mode)) {
1820 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to get recognition mode");
1825 vc_mgr_client_set_internal_state(g_vc_m, VC_INTERNAL_STATE_STARTING);
1826 ret = vc_mgr_tidl_request_start(g_vc_m->handle, (int)recognition_mode, exclusive_command_option, start_by_client, disabled_cmd_type);
1828 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to start request start : %s", __vc_mgr_get_error_code(ret));
1829 vc_mgr_client_set_internal_state(g_vc_m, VC_INTERNAL_STATE_NONE);
1831 SLOG(LOG_INFO, TAG_VCM, "[SUCCESS] start recognition");
1835 g_prev_volume_db = 0;
1836 g_cur_volume_db = 0;
1838 SLOG(LOG_ERROR, TAG_VCM, "@@@ [Manager] Request start DONE, ret(%d)", ret);
1843 int vc_mgr_stop(void)
1845 SLOG(LOG_ERROR, TAG_VCM, "@@@ [Manager] Request stop");
1847 if (0 != __vc_mgr_get_feature_enabled()) {
1848 SLOG(LOG_DEBUG, TAG_VCM, "@@@ [Manager] not supported");
1849 return VC_ERROR_NOT_SUPPORTED;
1852 if (0 != __vc_mgr_check_privilege()) {
1853 return VC_ERROR_PERMISSION_DENIED;
1857 if (0 != vc_mgr_client_get_client_state(g_vc_m, &state)) {
1858 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] A handle is not available");
1859 return VC_ERROR_INVALID_STATE;
1863 RETVM_IF(state != VC_STATE_READY, VC_ERROR_INVALID_STATE, TAG_VCM, "[ERROR] Invalid State: Current state(%d) is not 'READY'", state);
1865 /* Check service state */
1866 vc_service_state_e service_state = -1;
1867 vc_mgr_client_get_service_state(g_vc_m, &service_state);
1868 RETVM_IF(service_state != VC_SERVICE_STATE_RECORDING, VC_ERROR_INVALID_STATE, TAG_VCM, "[ERROR] Invalid State: Current service state(%d) is not 'RECORDING'", service_state);
1870 /* Check internal state for async */
1871 vc_internal_state_e internal_state = -1;
1872 vc_mgr_client_get_internal_state(g_vc_m, &internal_state);
1873 if (VC_INTERNAL_STATE_STARTING == internal_state) {
1874 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Invalid State : Internal state is STARTING");
1875 return VC_ERROR_IN_PROGRESS_TO_RECORDING;
1876 } else if (VC_INTERNAL_STATE_STOPPING == internal_state) {
1877 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Invalid State : Internal state is STOPPING");
1878 return VC_ERROR_IN_PROGRESS_TO_PROCESSING;
1879 } else if (VC_INTERNAL_STATE_CANCELING == internal_state) {
1880 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Invalid State : Internal state is CANCELING");
1881 return VC_ERROR_IN_PROGRESS_TO_READY;
1886 vc_mgr_client_set_internal_state(g_vc_m, VC_INTERNAL_STATE_STOPPING);
1887 ret = vc_mgr_tidl_request_stop(g_vc_m->handle);
1889 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to stop request : %s", __vc_mgr_get_error_code(ret));
1890 vc_mgr_client_set_internal_state(g_vc_m, VC_INTERNAL_STATE_NONE);
1892 SLOG(LOG_INFO, TAG_VCM, "[SUCCESS] Stop recognition");
1895 SLOG(LOG_DEBUG, TAG_VCM, "@@@ [Manager] Request stop DONE");
1900 int vc_mgr_cancel(void)
1902 SLOG(LOG_INFO, TAG_VCM, "@@@ [Manager] Request cancel");
1904 if (0 != __vc_mgr_get_feature_enabled()) {
1905 SLOG(LOG_DEBUG, TAG_VCM, "@@@ [Manager] not supported");
1906 return VC_ERROR_NOT_SUPPORTED;
1909 if (0 != __vc_mgr_check_privilege()) {
1910 return VC_ERROR_PERMISSION_DENIED;
1914 if (0 != vc_mgr_client_get_client_state(g_vc_m, &state)) {
1915 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] A handle is not available");
1916 return VC_ERROR_INVALID_STATE;
1920 RETVM_IF(state != VC_STATE_READY, VC_ERROR_INVALID_STATE, TAG_VCM, "[ERROR] Invalid State: Current state(%d) is not 'READY'", state);
1922 /* Check service state */
1923 vc_service_state_e service_state = -1;
1924 vc_mgr_client_get_service_state(g_vc_m, &service_state);
1925 RETVM_IF(service_state == VC_SERVICE_STATE_NONE, VC_ERROR_INVALID_STATE, TAG_VCM, "[ERROR] Invalid State: Current state is NONE");
1927 vc_internal_state_e internal_state = -1;
1928 vc_mgr_client_get_internal_state(g_vc_m, &internal_state);
1929 if (VC_INTERNAL_STATE_STARTING == internal_state) {
1930 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Invalid State : Internal state is STARTING");
1931 return VC_ERROR_IN_PROGRESS_TO_RECORDING;
1932 } else if (VC_INTERNAL_STATE_STOPPING == internal_state) {
1933 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Invalid State : Internal state is STOPPING");
1934 return VC_ERROR_IN_PROGRESS_TO_PROCESSING;
1935 } else if (VC_INTERNAL_STATE_CANCELING == internal_state) {
1936 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Invalid State : Internal state is CANCELING");
1937 return VC_ERROR_IN_PROGRESS_TO_READY;
1941 vc_mgr_client_set_internal_state(g_vc_m, VC_INTERNAL_STATE_CANCELING);
1942 ret = vc_mgr_tidl_request_cancel(g_vc_m->handle);
1944 SLOG(LOG_DEBUG, TAG_VCM, "[ERROR] Fail to cancel request : %s", __vc_mgr_get_error_code(ret));
1945 vc_mgr_client_set_internal_state(g_vc_m, VC_INTERNAL_STATE_NONE);
1947 SLOG(LOG_INFO, TAG_VCM, "[SUCCESS] Cancel recognition");
1950 vc_mgr_client_set_exclusive_command(g_vc_m, false);
1952 SLOG(LOG_DEBUG, TAG_VCM, "@@@ [Manager] Request cancel DONE");
1957 static int g_cnt = 0;
1958 static Eina_Bool __vc_mgr_set_volume_timer_cb(void* data)
1961 g_volume_db = g_prev_volume_db + (g_cur_volume_db - g_prev_volume_db) / 5 * g_cnt;
1963 SLOG(LOG_INFO, TAG_VCM, "Set volume (%f)(%f)", g_volume_db, g_cur_volume_db);
1965 if (0 == g_cnt % 5) {
1971 int __vc_mgr_cb_set_volume(float volume)
1973 // called in vc_mgr_tidl
1974 g_prev_volume_db = g_volume_db;
1975 g_cur_volume_db = volume;
1977 g_volume_db = g_prev_volume_db + (g_cur_volume_db - g_prev_volume_db) / 5;
1979 if (NULL != g_m_set_volume_timer) {
1980 ecore_timer_del(g_m_set_volume_timer);
1984 g_m_set_volume_timer = ecore_timer_add(0.05, __vc_mgr_set_volume_timer_cb, NULL);
1986 return VC_ERROR_NONE;
1989 int __vc_mgr_set_volume(float volume)
1991 // called by app directly
1992 g_volume_db = volume;
1994 return VC_ERROR_NONE;
1997 int vc_mgr_get_recording_volume(float* volume)
1999 if (0 != __vc_mgr_get_feature_enabled()) {
2000 SLOG(LOG_DEBUG, TAG_VCM, "@@@ [Manager] not supported");
2001 return VC_ERROR_NOT_SUPPORTED;
2004 if (0 != __vc_mgr_check_privilege()) {
2005 return VC_ERROR_PERMISSION_DENIED;
2008 RETVM_IF(NULL == volume, VC_ERROR_INVALID_PARAMETER, TAG_VCM, "[ERROR] Invalid parameter");
2010 vc_service_state_e service_state = -1;
2011 if (0 != vc_mgr_client_get_service_state(g_vc_m, &service_state)) {
2012 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] A handle is not available");
2013 return VC_ERROR_INVALID_STATE;
2017 RETVM_IF(VC_SERVICE_STATE_RECORDING != service_state, VC_ERROR_INVALID_STATE, TAG_VCM, "[ERROR] Invalid State: Service state is not 'RECORDING'");
2019 *volume = g_volume_db;
2021 return VC_ERROR_NONE;
2024 int __vc_mgr_cb_set_foreground(int pid, bool value)
2026 vc_mgr_client_set_foreground(g_vc_m, pid, value);
2028 /* get authorized valid app */
2030 if (0 != vc_mgr_client_get_valid_authorized_client(g_vc_m, &tmp_pid)) {
2031 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to get authorized valid app");
2032 return VC_ERROR_INVALID_PARAMETER;
2035 if (true == value) {
2036 /* compare & set valid */
2037 if (tmp_pid != pid) {
2038 SLOG(LOG_INFO, TAG_VCM, "Authority(%d) changed to invalid", tmp_pid);
2040 /* set authorized valid */
2041 if (true == vc_mgr_client_is_authorized_client(g_vc_m, pid)) {
2042 SLOG(LOG_DEBUG, TAG_VCM, "Authority(%d) change to valid", pid);
2043 vc_mgr_client_set_valid_authorized_client(g_vc_m, pid);
2045 SLOG(LOG_DEBUG, TAG_VCM, "No valid Authority");
2046 vc_mgr_client_set_valid_authorized_client(g_vc_m, -1);
2050 if (tmp_pid == pid) {
2051 SLOG(LOG_INFO, TAG_VCM, "Authority(%d) changed to invalid", tmp_pid);
2052 vc_mgr_client_set_valid_authorized_client(g_vc_m, -1);
2056 return VC_ERROR_NONE;
2059 int vc_mgr_set_selected_results(vc_cmd_list_h vc_cmd_list)
2061 SLOG(LOG_INFO, TAG_VCM, "@@@ [Manager] Select result");
2063 if (0 != __vc_mgr_get_feature_enabled()) {
2064 SLOG(LOG_DEBUG, TAG_VCM, "@@@ [Manager] not supported");
2065 return VC_ERROR_NOT_SUPPORTED;
2068 if (0 != __vc_mgr_check_privilege()) {
2069 return VC_ERROR_PERMISSION_DENIED;
2072 /* Do not check state for 'restart continuously' mode */
2074 vc_service_state_e service_state = -1;
2075 vc_mgr_client_get_service_state(g_vc_m, &service_state);
2076 if (service_state != VC_SERVICE_STATE_PROCESSING) {
2077 vc_recognition_mode_e recognition_mode;
2078 vc_mgr_get_recognition_mode(&recognition_mode);
2080 if (VC_RECOGNITION_MODE_RESTART_CONTINUOUSLY != recognition_mode) {
2081 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Invalid State: service state is not 'PROCESSING' and mode is not 'Restart continuously'");
2082 return VC_ERROR_INVALID_STATE;
2086 if (NULL != vc_cmd_list) {
2088 char* result_text = NULL;
2090 vc_mgr_client_get_all_result(g_vc_m, &event, &result_text);
2092 vc_info_parser_set_result(result_text, event, NULL, vc_cmd_list, false);
2094 if (NULL != result_text) {
2102 ret = vc_mgr_tidl_send_result_selection(g_vc_m->handle);
2104 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to send result selection : %s", __vc_mgr_get_error_code(ret));
2107 SLOG(LOG_INFO, TAG_VCM, "[SUCCESS] result selection");
2110 vc_mgr_client_unset_all_result(g_vc_m);
2112 SLOG(LOG_DEBUG, TAG_VCM, "@@@ [Manager] Select result DONE");
2114 return VC_ERROR_NONE;
2117 static Eina_Bool __vc_mgr_set_select_result(void *data)
2119 vc_mgr_set_selected_results(NULL);
2123 static void __vc_mgr_notify_all_result(vc_result_type_e result_type)
2125 char* temp_text = NULL;
2127 char* temp_message = NULL;
2128 vc_cmd_list_h vc_cmd_list = NULL;
2130 vc_mgr_all_result_cb all_callback = NULL;
2131 void* all_user_data = NULL;
2133 vc_mgr_client_get_all_result_cb(g_vc_m, &all_callback, &all_user_data);
2134 RETM_IF(NULL == all_callback, TAG_VCM, "[ERROR] All result callback is NULL");
2136 if (0 != vc_cmd_list_create(&vc_cmd_list)) {
2137 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to create command list");
2141 vc_info_parser_get_result(&temp_text, &event, &temp_message, -1, vc_cmd_list, vc_mgr_client_get_exclusive_command(g_vc_m));
2143 SECURE_SLOG(LOG_INFO, TAG_VCM, "Result info : result type(%d) result text(%s) event(%d) result_message(%s)",
2144 result_type, temp_text, event, temp_message);
2146 vc_cmd_print_list(vc_cmd_list);
2148 bool cb_ret = false;
2150 vc_mgr_client_set_all_result(g_vc_m, event, temp_text);
2152 vc_mgr_client_use_callback(g_vc_m);
2153 cb_ret = all_callback(event, vc_cmd_list, temp_text, temp_message, all_user_data);
2154 vc_mgr_client_not_use_callback(g_vc_m);
2156 if (true == vc_mgr_client_get_exclusive_command(g_vc_m)) {
2158 vc_result_cb callback = NULL;
2159 void* user_data = NULL;
2161 vc_mgr_client_get_result_cb(g_vc_m, &callback, &user_data);
2162 RETM_IF(NULL == callback, TAG_VCM, "[ERROR] Client result callback is NULL");
2164 vc_mgr_client_use_callback(g_vc_m);
2165 callback(event, vc_cmd_list, temp_text, user_data);
2166 vc_mgr_client_not_use_callback(g_vc_m);
2167 SLOG(LOG_DEBUG, TAG_VCM, "Exclusive result callback called");
2169 /* Release result */
2170 if (NULL != temp_text) {
2174 if (NULL != temp_message) {
2176 temp_message = NULL;
2181 vc_cmd_list_destroy(vc_cmd_list, true);
2184 vc_mgr_client_set_exclusive_command(g_vc_m, false);
2190 vc_cmd_list_get_count(vc_cmd_list, &count);
2192 if (true == cb_ret) {
2193 SLOG(LOG_INFO, TAG_VCM, "Callback result is true");
2194 if (VC_RESULT_TYPE_NOTIFICATION != result_type)
2195 ecore_idler_add(__vc_mgr_set_select_result, NULL);
2197 SLOG(LOG_INFO, TAG_VCM, "Callback result is false");
2198 /* need to select conflicted result */
2201 if (VC_RESULT_TYPE_NOTIFICATION != result_type)
2202 ecore_idler_add(__vc_mgr_set_select_result, NULL);
2204 vc_mgr_client_set_exclusive_command(g_vc_m, false);
2205 vc_mgr_client_unset_all_result(g_vc_m);
2208 /* Release result */
2209 if (NULL != temp_text) {
2213 if (NULL != temp_message) {
2215 temp_message = NULL;
2220 vc_cmd_list_destroy(vc_cmd_list, true);
2226 static Eina_Bool __vc_mgr_notify_result(void *data)
2228 char* temp_text = NULL;
2230 vc_cmd_list_h vc_cmd_list = NULL;
2232 vc_result_cb callback = NULL;
2233 void* user_data = NULL;
2235 vc_mgr_client_get_result_cb(g_vc_m, &callback, &user_data);
2236 RETVM_IF(NULL == callback, EINA_FALSE, TAG_VCM, "[ERROR] Client result callback is NULL");
2238 if (0 != vc_cmd_list_create(&vc_cmd_list)) {
2239 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to create command list");
2243 vc_info_parser_get_result(&temp_text, &event, NULL, getpid(), vc_cmd_list, false);
2245 SECURE_SLOG(LOG_INFO, TAG_VCM, "Result : result text(%s) event(%d)", temp_text, event);
2247 vc_cmd_print_list(vc_cmd_list);
2249 vc_mgr_client_use_callback(g_vc_m);
2250 callback(event, vc_cmd_list, temp_text, user_data);
2251 vc_mgr_client_not_use_callback(g_vc_m);
2252 SLOG(LOG_INFO, TAG_VCM, "Result callback called");
2255 vc_cmd_list_destroy(vc_cmd_list, true);
2258 /* Release result */
2266 void __vc_mgr_cb_all_result(vc_result_type_e type)
2268 if (false == vc_mgr_client_get_exclusive_command(g_vc_m)) {
2269 __vc_mgr_notify_all_result(type);
2271 __vc_mgr_notify_result(0);
2277 void __vc_mgr_cb_pre_result(vc_pre_result_event_e event, const char* pre_result)
2279 vc_mgr_pre_result_cb callback = NULL;
2280 void* user_data = NULL;
2282 vc_mgr_client_get_pre_result_cb(g_vc_m, &callback, &user_data);
2283 RETM_IF(NULL == callback, TAG_VCM, "[ERROR] Client pre result callback is NULL");
2285 vc_mgr_client_use_callback(g_vc_m);
2286 callback(event, pre_result, user_data);
2287 vc_mgr_client_not_use_callback(g_vc_m);
2288 SLOG(LOG_INFO, TAG_VCM, "Pre result callback is called");
2293 void __vc_mgr_cb_system_result()
2295 __vc_mgr_notify_result(NULL);
2299 static Eina_Bool __vc_mgr_speech_detected(void *data)
2301 vc_mgr_begin_speech_detected_cb callback = NULL;
2302 void* user_data = NULL;
2304 vc_mgr_client_get_speech_detected_cb(g_vc_m, &callback, &user_data);
2305 RETVM_IF(NULL == callback, EINA_FALSE, TAG_VCM, "[ERROR] Client speech detected callback is NULL");
2307 vc_mgr_client_use_callback(g_vc_m);
2308 callback(user_data);
2309 vc_mgr_client_not_use_callback(g_vc_m);
2310 SLOG(LOG_INFO, TAG_VCM, "Speech detected callback called");
2315 void __vc_mgr_cb_speech_detected()
2317 __vc_mgr_speech_detected(NULL);
2322 int vc_mgr_set_all_result_cb(vc_mgr_all_result_cb callback, void* user_data)
2324 if (0 != __vc_mgr_get_feature_enabled()) {
2325 SLOG(LOG_DEBUG, TAG_VCM, "@@@ [Manager] not supported");
2326 return VC_ERROR_NOT_SUPPORTED;
2329 if (0 != __vc_mgr_check_privilege()) {
2330 return VC_ERROR_PERMISSION_DENIED;
2333 RETVM_IF(NULL == callback, VC_ERROR_INVALID_PARAMETER, TAG_VCM, "[ERROR] Invalid parameter");
2336 if (0 != vc_mgr_client_get_client_state(g_vc_m, &state)) {
2337 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Set result callback : A handle is not available");
2338 return VC_ERROR_INVALID_STATE;
2342 RETVM_IF(state != VC_STATE_INITIALIZED, VC_ERROR_INVALID_STATE, TAG_VCM, "[ERROR] Invalid State: Current state(%d) is not 'Initialized'", state);
2344 vc_mgr_client_set_all_result_cb(g_vc_m, callback, user_data);
2346 SLOG(LOG_INFO, TAG_VCM, "[SUCCESS] Set all result callback");
2348 return VC_ERROR_NONE;
2351 int vc_mgr_unset_all_result_cb(void)
2353 if (0 != __vc_mgr_get_feature_enabled()) {
2354 SLOG(LOG_INFO, TAG_VCM, "@@@ [Manager] not supported");
2355 return VC_ERROR_NOT_SUPPORTED;
2358 if (0 != __vc_mgr_check_privilege()) {
2359 return VC_ERROR_PERMISSION_DENIED;
2363 if (0 != vc_mgr_client_get_client_state(g_vc_m, &state)) {
2364 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Unset result callback : A handle is not available");
2365 return VC_ERROR_INVALID_STATE;
2369 RETVM_IF(state != VC_STATE_INITIALIZED, VC_ERROR_INVALID_STATE, TAG_VCM, "[ERROR] Invalid State: Current state(%d) is not 'Initialized'", state);
2371 vc_mgr_client_set_all_result_cb(g_vc_m, NULL, NULL);
2373 return VC_ERROR_NONE;
2376 int vc_mgr_set_result_cb(vc_result_cb callback, void* user_data)
2378 if (0 != __vc_mgr_get_feature_enabled()) {
2379 SLOG(LOG_DEBUG, TAG_VCM, "@@@ [Manager] not supported");
2380 return VC_ERROR_NOT_SUPPORTED;
2383 if (0 != __vc_mgr_check_privilege()) {
2384 return VC_ERROR_PERMISSION_DENIED;
2387 RETVM_IF(NULL == callback, VC_ERROR_INVALID_PARAMETER, TAG_VCM, "[ERROR] Invalid parameter");
2390 if (0 != vc_mgr_client_get_client_state(g_vc_m, &state)) {
2391 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Set result callback : A handle is not available");
2392 return VC_ERROR_INVALID_STATE;
2396 RETVM_IF(state != VC_STATE_INITIALIZED, VC_ERROR_INVALID_STATE, TAG_VCM, "[ERROR] Invalid State: Current state(%d) is not 'Initialized'", state);
2398 vc_mgr_client_set_result_cb(g_vc_m, callback, user_data);
2400 return VC_ERROR_NONE;
2403 int vc_mgr_unset_result_cb(void)
2405 if (0 != __vc_mgr_get_feature_enabled()) {
2406 SLOG(LOG_DEBUG, TAG_VCM, "@@@ [Manager] not supported");
2407 return VC_ERROR_NOT_SUPPORTED;
2410 if (0 != __vc_mgr_check_privilege()) {
2411 return VC_ERROR_PERMISSION_DENIED;
2415 if (0 != vc_mgr_client_get_client_state(g_vc_m, &state)) {
2416 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Unset result callback : A handle is not available");
2417 return VC_ERROR_INVALID_STATE;
2421 RETVM_IF(state != VC_STATE_INITIALIZED, VC_ERROR_INVALID_STATE, TAG_VCM, "[ERROR] Invalid State: Current state(%d) is not 'Initialized'", state);
2423 vc_mgr_client_set_result_cb(g_vc_m, NULL, NULL);
2425 return VC_ERROR_NONE;
2428 int vc_mgr_set_pre_result_cb(vc_mgr_pre_result_cb callback, void* user_data)
2430 if (0 != __vc_mgr_get_feature_enabled()) {
2431 SLOG(LOG_DEBUG, TAG_VCM, "@@@ [Manager] not supported");
2432 return VC_ERROR_NOT_SUPPORTED;
2435 if (0 != __vc_mgr_check_privilege()) {
2436 return VC_ERROR_PERMISSION_DENIED;
2439 RETVM_IF(NULL == callback, VC_ERROR_INVALID_PARAMETER, TAG_VCM, "[ERROR] Invalid parameter");
2442 if (0 != vc_mgr_client_get_client_state(g_vc_m, &state)) {
2443 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Set pre result callback : A handle is not available");
2444 return VC_ERROR_INVALID_STATE;
2448 RETVM_IF(state != VC_STATE_INITIALIZED, VC_ERROR_INVALID_STATE, TAG_VCM, "[ERROR] Invalid State: Current state(%d) is not 'Initialized'", state);
2450 vc_mgr_client_set_pre_result_cb(g_vc_m, callback, user_data);
2452 return VC_ERROR_NONE;
2455 int vc_mgr_unset_pre_result_cb(void)
2457 if (0 != __vc_mgr_get_feature_enabled()) {
2458 SLOG(LOG_DEBUG, TAG_VCM, "@@@ [Manager] not supported");
2459 return VC_ERROR_NOT_SUPPORTED;
2462 if (0 != __vc_mgr_check_privilege()) {
2463 return VC_ERROR_PERMISSION_DENIED;
2467 if (0 != vc_mgr_client_get_client_state(g_vc_m, &state)) {
2468 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Unset pre result callback : A handle is not available");
2469 return VC_ERROR_INVALID_STATE;
2473 RETVM_IF(state != VC_STATE_INITIALIZED, VC_ERROR_INVALID_STATE, TAG_VCM, "[ERROR] Invalid State: Current state(%d) is not 'Initialized'", state);
2475 vc_mgr_client_set_pre_result_cb(g_vc_m, NULL, NULL);
2477 return VC_ERROR_NONE;
2480 int vc_mgr_get_error_message(char** err_msg)
2482 SLOG(LOG_DEBUG, TAG_VCM, "@@@ [Manager] Get error message");
2484 if (0 != __vc_mgr_get_feature_enabled()) {
2485 SLOG(LOG_DEBUG, TAG_VCM, "@@@ [Manager] not supported");
2486 return VC_ERROR_NOT_SUPPORTED;
2489 if (0 != __vc_mgr_check_privilege()) {
2490 return VC_ERROR_PERMISSION_DENIED;
2495 if (0 != vc_mgr_client_get_client_state(g_vc_m, &state)) {
2496 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] vc_mgr handle is not available");
2497 return VC_ERROR_INVALID_STATE;
2500 RETVM_IF(NULL == err_msg, VC_ERROR_INVALID_PARAMETER, TAG_VCM, "[ERROR] Invalid parameter");
2502 if (false == g_err_callback_status) {
2503 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Not in error callback");
2504 return VC_ERROR_OPERATION_FAILED;
2508 ret = vc_mgr_client_get_error_message(g_vc_m, err_msg);
2510 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to get error message");
2513 SLOG(LOG_DEBUG, TAG_VCM, "@@@ [Manager] Get error message DONE");
2518 static void __vc_mgr_notify_error(void *data)
2520 vc_h vc_m = (vc_h)data;
2522 vc_error_cb callback = NULL;
2523 void* user_data = NULL;
2526 vc_mgr_client_get_error_cb(vc_m, &callback, &user_data);
2527 vc_mgr_client_get_error(vc_m, &reason);
2529 if (NULL != callback) {
2530 vc_mgr_client_use_callback(vc_m);
2531 g_err_callback_status = true;
2532 callback(reason, user_data);
2533 g_err_callback_status = false;
2534 vc_mgr_client_not_use_callback(vc_m);
2535 SLOG(LOG_INFO, TAG_VCM, "Error callback is called");
2537 SLOG(LOG_WARN, TAG_VCM, "[WARNING] Error callback is null");
2541 int __vc_mgr_cb_error(int reason, int daemon_pid, char* msg)
2544 if (0 != vc_mgr_client_get_client_state(g_vc_m, &state)) {
2545 SLOG(LOG_ERROR, TAG_VCM, "[WARNING] Invalid client");
2546 return VC_ERROR_INVALID_PARAMETER;
2550 if (state != VC_STATE_INITIALIZED && state != VC_STATE_READY) {
2551 SLOG(LOG_ERROR, TAG_VCM, "[WARNING] not connected client yet");
2552 return VC_ERROR_INVALID_STATE;
2555 vc_mgr_client_set_internal_state(g_vc_m, VC_INTERNAL_STATE_NONE);
2557 if (VC_ERROR_SERVICE_RESET == reason) {
2558 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] VC daemon reset");
2560 vc_service_state_e service_state = -1;
2561 vc_mgr_client_get_service_state(g_vc_m, &service_state);
2562 if (VC_SERVICE_STATE_UPDATING == service_state) {
2563 SLOG(LOG_INFO, TAG_VCM, "[INFO] VC daemon is terminated by update manager");
2564 return VC_ERROR_NONE;
2567 vc_mgr_client_set_client_state(g_vc_m, VC_STATE_INITIALIZED);
2568 __vc_mgr_notify_state_changed(g_vc_m);
2570 if (0 != vc_mgr_prepare()) {
2571 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to prepare");
2575 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Error reason(%d), msg(%s)", reason, msg);
2577 vc_mgr_client_set_error(g_vc_m, reason);
2578 vc_mgr_client_set_error_message(g_vc_m, msg);
2579 __vc_mgr_notify_error(g_vc_m);
2581 return VC_ERROR_NONE;
2584 static Eina_Bool __vc_mgr_notify_state_changed(void *data)
2586 vc_state_changed_cb changed_callback = NULL;
2589 vc_mgr_client_get_state_changed_cb(g_vc_m, &changed_callback, &user_data);
2591 vc_state_e current_state;
2592 vc_state_e before_state;
2594 vc_mgr_client_get_before_state(g_vc_m, ¤t_state, &before_state);
2596 if (NULL != changed_callback) {
2597 vc_mgr_client_use_callback(g_vc_m);
2598 changed_callback(before_state, current_state, user_data);
2599 vc_mgr_client_not_use_callback(g_vc_m);
2600 SLOG(LOG_INFO, TAG_VCM, "State changed callback is called");
2602 SLOG(LOG_WARN, TAG_VCM, "[WARNING] State changed callback is null");
2608 int vc_mgr_set_state_changed_cb(vc_state_changed_cb callback, void* user_data)
2610 if (0 != __vc_mgr_get_feature_enabled()) {
2611 SLOG(LOG_DEBUG, TAG_VCM, "@@@ [Manager] not supported");
2612 return VC_ERROR_NOT_SUPPORTED;
2615 if (0 != __vc_mgr_check_privilege()) {
2616 return VC_ERROR_PERMISSION_DENIED;
2619 if (callback == NULL)
2620 return VC_ERROR_INVALID_PARAMETER;
2623 if (0 != vc_mgr_client_get_client_state(g_vc_m, &state)) {
2624 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Set state changed callback : A handle is not available");
2625 return VC_ERROR_INVALID_STATE;
2629 RETVM_IF(state != VC_STATE_INITIALIZED, VC_ERROR_INVALID_STATE, TAG_VCM, "[ERROR] Invalid State: Current state(%d) is not 'Initialized'", state);
2631 vc_mgr_client_set_state_changed_cb(g_vc_m, callback, user_data);
2633 SLOG(LOG_INFO, TAG_VCM, "[SUCCESS] Set state changed callback");
2634 return VC_ERROR_NONE;
2637 int vc_mgr_unset_state_changed_cb(void)
2639 if (0 != __vc_mgr_get_feature_enabled()) {
2640 SLOG(LOG_DEBUG, TAG_VCM, "@@@ [Manager] not supported");
2641 return VC_ERROR_NOT_SUPPORTED;
2644 if (0 != __vc_mgr_check_privilege()) {
2645 return VC_ERROR_PERMISSION_DENIED;
2649 if (0 != vc_mgr_client_get_client_state(g_vc_m, &state)) {
2650 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Unset state changed callback : A handle is not available");
2651 return VC_ERROR_INVALID_STATE;
2655 RETVM_IF(state != VC_STATE_INITIALIZED, VC_ERROR_INVALID_STATE, TAG_VCM, "[ERROR] Invalid State: Current state(%d) is not 'Initialized'", state);
2657 vc_mgr_client_set_state_changed_cb(g_vc_m, NULL, NULL);
2659 return VC_ERROR_NONE;
2662 int __vc_mgr_cb_service_state(int state)
2664 vc_service_state_e current_state = (vc_service_state_e)state;
2665 vc_service_state_e before_state;
2666 vc_mgr_client_get_service_state(g_vc_m, &before_state);
2668 SLOG(LOG_INFO, TAG_VCM, "Service State changed : Before(%d) Current(%d)",
2669 before_state, current_state);
2671 vc_internal_state_e internal_state = -1;
2672 vc_mgr_client_get_internal_state(g_vc_m, &internal_state);
2673 if ((VC_INTERNAL_STATE_STARTING == internal_state && VC_SERVICE_STATE_RECORDING == current_state) ||
2674 (VC_INTERNAL_STATE_STOPPING == internal_state && VC_SERVICE_STATE_PROCESSING == current_state) ||
2675 (VC_INTERNAL_STATE_CANCELING == internal_state && VC_SERVICE_STATE_READY == current_state)) {
2676 SLOG(LOG_INFO, TAG_VCM, "Internal state is changed to NONE");
2677 vc_mgr_client_set_internal_state(g_vc_m, VC_INTERNAL_STATE_NONE);
2679 if (VC_SERVICE_STATE_UPDATING == current_state) {
2680 SLOG(LOG_INFO, TAG_VCM, "Internal state is changed to NONE by updating");
2681 vc_mgr_client_set_internal_state(g_vc_m, VC_INTERNAL_STATE_NONE);
2684 if (current_state == before_state) {
2685 SLOG(LOG_WARN, TAG_VCM, "Service State NOT changed : Before(%d) Current(%d)",
2686 before_state, current_state);
2687 return VC_ERROR_NONE;
2690 /* Save service state */
2691 vc_mgr_client_set_service_state(g_vc_m, current_state);
2693 vc_service_state_changed_cb callback = NULL;
2694 void* service_user_data = NULL;
2695 vc_mgr_client_get_service_state_changed_cb(g_vc_m, &callback, &service_user_data);
2697 if (NULL != callback) {
2698 vc_mgr_client_use_callback(g_vc_m);
2699 callback(before_state, current_state, service_user_data);
2700 vc_mgr_client_not_use_callback(g_vc_m);
2701 SLOG(LOG_INFO, TAG_VCM, "Service state changed callback is called");
2703 SLOG(LOG_WARN, TAG_VCM, "[WARNING] Service state changed callback is null");
2706 return VC_ERROR_NONE;
2709 int vc_mgr_set_service_state_changed_cb(vc_service_state_changed_cb callback, void* user_data)
2711 if (0 != __vc_mgr_get_feature_enabled()) {
2712 SLOG(LOG_DEBUG, TAG_VCM, "@@@ [Manager] not supported");
2713 return VC_ERROR_NOT_SUPPORTED;
2716 if (0 != __vc_mgr_check_privilege()) {
2717 return VC_ERROR_PERMISSION_DENIED;
2720 if (callback == NULL)
2721 return VC_ERROR_INVALID_PARAMETER;
2724 if (0 != vc_mgr_client_get_client_state(g_vc_m, &state)) {
2725 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Set state changed callback : A handle is not available");
2726 return VC_ERROR_INVALID_STATE;
2730 RETVM_IF(state != VC_STATE_INITIALIZED, VC_ERROR_INVALID_STATE, TAG_VCM, "[ERROR] Invalid State: Current state(%d) is not 'Initialized'", state);
2732 vc_mgr_client_set_service_state_changed_cb(g_vc_m, callback, user_data);
2734 SLOG(LOG_INFO, TAG_VCM, "[SUCCESS] Set service state changed callback");
2735 return VC_ERROR_NONE;
2738 int vc_mgr_unset_service_state_changed_cb(void)
2740 if (0 != __vc_mgr_get_feature_enabled()) {
2741 SLOG(LOG_DEBUG, TAG_VCM, "@@@ [Manager] not supported");
2742 return VC_ERROR_NOT_SUPPORTED;
2745 if (0 != __vc_mgr_check_privilege()) {
2746 return VC_ERROR_PERMISSION_DENIED;
2750 if (0 != vc_mgr_client_get_client_state(g_vc_m, &state)) {
2751 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Unset state changed callback : A handle is not available");
2752 return VC_ERROR_INVALID_STATE;
2756 RETVM_IF(state != VC_STATE_INITIALIZED, VC_ERROR_INVALID_STATE, TAG_VCM, "[ERROR] Invalid State: Current state(%d) is not 'Initialized'", state);
2758 vc_mgr_client_set_service_state_changed_cb(g_vc_m, NULL, NULL);
2759 return VC_ERROR_NONE;
2762 int vc_mgr_set_speech_detected_cb(vc_mgr_begin_speech_detected_cb callback, void* user_data)
2764 if (0 != __vc_mgr_get_feature_enabled()) {
2765 SLOG(LOG_DEBUG, TAG_VCM, "@@@ [Manager] not supported");
2766 return VC_ERROR_NOT_SUPPORTED;
2769 if (0 != __vc_mgr_check_privilege()) {
2770 return VC_ERROR_PERMISSION_DENIED;
2773 if (callback == NULL)
2774 return VC_ERROR_INVALID_PARAMETER;
2777 if (0 != vc_mgr_client_get_client_state(g_vc_m, &state)) {
2778 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Set state changed callback : A handle is not available");
2779 return VC_ERROR_INVALID_STATE;
2783 RETVM_IF(state != VC_STATE_INITIALIZED, VC_ERROR_INVALID_STATE, TAG_VCM, "[ERROR] Invalid State: Current state(%d) is not 'Initialized'", state);
2785 vc_mgr_client_set_speech_detected_cb(g_vc_m, callback, user_data);
2787 SLOG(LOG_INFO, TAG_VCM, "[SUCCESS] Set speech detected callback");
2788 return VC_ERROR_NONE;
2791 int vc_mgr_unset_speech_detected_cb(void)
2793 if (0 != __vc_mgr_get_feature_enabled()) {
2794 SLOG(LOG_DEBUG, TAG_VCM, "@@@ [Manager] not supported");
2795 return VC_ERROR_NOT_SUPPORTED;
2798 if (0 != __vc_mgr_check_privilege()) {
2799 return VC_ERROR_PERMISSION_DENIED;
2803 if (0 != vc_mgr_client_get_client_state(g_vc_m, &state)) {
2804 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Unset state changed callback : A handle is not available");
2805 return VC_ERROR_INVALID_STATE;
2809 RETVM_IF(state != VC_STATE_INITIALIZED, VC_ERROR_INVALID_STATE, TAG_VCM, "[ERROR] Invalid State: Current state(%d) is not 'Initialized'", state);
2811 vc_mgr_client_set_speech_detected_cb(g_vc_m, NULL, NULL);
2812 return VC_ERROR_NONE;
2815 int vc_mgr_set_current_language_changed_cb(vc_current_language_changed_cb callback, void* user_data)
2817 if (0 != __vc_mgr_get_feature_enabled()) {
2818 SLOG(LOG_DEBUG, TAG_VCM, "@@@ [Manager] not supported");
2819 return VC_ERROR_NOT_SUPPORTED;
2822 if (0 != __vc_mgr_check_privilege()) {
2823 return VC_ERROR_PERMISSION_DENIED;
2826 RETVM_IF(NULL == callback, VC_ERROR_INVALID_PARAMETER, TAG_VCM, "[ERROR] Invalid parameter");
2829 if (0 != vc_mgr_client_get_client_state(g_vc_m, &state)) {
2830 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Set current language changed : A handle is not available");
2831 return VC_ERROR_INVALID_STATE;
2835 RETVM_IF(state != VC_STATE_INITIALIZED, VC_ERROR_INVALID_STATE, TAG_VCM, "[ERROR] Invalid State: Current state(%d) is not 'Initialized'", state);
2837 vc_mgr_client_set_current_lang_changed_cb(g_vc_m, callback, user_data);
2839 SLOG(LOG_INFO, TAG_VCM, "[SUCCESS] Set current language changed callback");
2840 return VC_ERROR_NONE;
2843 int vc_mgr_unset_current_language_changed_cb(void)
2845 if (0 != __vc_mgr_get_feature_enabled()) {
2846 SLOG(LOG_DEBUG, TAG_VCM, "@@@ [Manager] not supported");
2847 return VC_ERROR_NOT_SUPPORTED;
2850 if (0 != __vc_mgr_check_privilege()) {
2851 return VC_ERROR_PERMISSION_DENIED;
2855 if (0 != vc_mgr_client_get_client_state(g_vc_m, &state)) {
2856 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Unset current language changed : A handle is not available");
2857 return VC_ERROR_INVALID_STATE;
2861 RETVM_IF(state != VC_STATE_INITIALIZED, VC_ERROR_INVALID_STATE, TAG_VCM, "[ERROR] Invalid State: Current state(%d) is not 'Initialized'", state);
2863 vc_mgr_client_set_current_lang_changed_cb(g_vc_m, NULL, NULL);
2865 return VC_ERROR_NONE;
2868 int vc_mgr_set_error_cb(vc_error_cb callback, void* user_data)
2870 if (0 != __vc_mgr_get_feature_enabled()) {
2871 SLOG(LOG_DEBUG, TAG_VCM, "@@@ [Manager] not supported");
2872 return VC_ERROR_NOT_SUPPORTED;
2875 if (0 != __vc_mgr_check_privilege()) {
2876 return VC_ERROR_PERMISSION_DENIED;
2879 RETVM_IF(NULL == callback, VC_ERROR_INVALID_PARAMETER, TAG_VCM, "[ERROR] Invalid parameter");
2882 if (0 != vc_mgr_client_get_client_state(g_vc_m, &state)) {
2883 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Set error callback : A handle is not available");
2884 return VC_ERROR_INVALID_STATE;
2888 RETVM_IF(state != VC_STATE_INITIALIZED, VC_ERROR_INVALID_STATE, TAG_VCM, "[ERROR] Invalid State: Current state(%d) is not 'Initialized'", state);
2890 vc_mgr_client_set_error_cb(g_vc_m, callback, user_data);
2892 return VC_ERROR_NONE;
2895 int vc_mgr_unset_error_cb(void)
2897 if (0 != __vc_mgr_get_feature_enabled()) {
2898 SLOG(LOG_DEBUG, TAG_VCM, "@@@ [Manager] not supported");
2899 return VC_ERROR_NOT_SUPPORTED;
2902 if (0 != __vc_mgr_check_privilege()) {
2903 return VC_ERROR_PERMISSION_DENIED;
2907 if (0 != vc_mgr_client_get_client_state(g_vc_m, &state)) {
2908 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Unset error callback : A handle is not available");
2909 return VC_ERROR_INVALID_STATE;
2913 RETVM_IF(state != VC_STATE_INITIALIZED, VC_ERROR_INVALID_STATE, TAG_VCM, "[ERROR] Invalid State: Current state(%d) is not 'Initialized'", state);
2915 vc_mgr_client_set_error_cb(g_vc_m, NULL, NULL);
2917 return VC_ERROR_NONE;
2920 int __vc_mgr_cb_dialog(int pid, const char* disp_text, const char* utt_text, bool continuous)
2922 vc_mgr_dialog_request_cb callback = NULL;
2923 void* user_data = NULL;
2925 vc_mgr_client_get_dialog_request_cb(g_vc_m, &callback, &user_data);
2927 if (NULL != callback) {
2928 vc_mgr_client_use_callback(g_vc_m);
2929 callback(pid, disp_text, utt_text, continuous, user_data);
2930 vc_mgr_client_not_use_callback(g_vc_m);
2931 SLOG(LOG_INFO, TAG_VCM, "Dialog callback is called, disp_text(%s), utt)text(%s), continuous(%d)", disp_text, utt_text, continuous);
2933 SLOG(LOG_WARN, TAG_VCM, "[WARNING] Error callback is null");
2936 return VC_ERROR_NONE;
2939 int __vc_mgr_cb_private_data_set(const char* key, const char* data)
2941 vc_mgr_private_data_set_cb callback = NULL;
2942 void* user_data = NULL;
2945 vc_mgr_client_get_private_data_set_cb(g_vc_m, &callback, &user_data);
2947 if (NULL != callback) {
2948 vc_mgr_client_use_callback(g_vc_m);
2949 ret = callback(key, data, user_data);
2950 vc_mgr_client_not_use_callback(g_vc_m);
2951 SLOG(LOG_INFO, TAG_VCM, "Private data set callback is called");
2953 SLOG(LOG_WARN, TAG_VCM, "[WARNING] Private data set callback is null");
2959 int __vc_mgr_cb_private_data_requested(const char* key, char** data)
2961 vc_mgr_private_data_requested_cb callback = NULL;
2962 void* user_data = NULL;
2965 vc_mgr_client_get_private_data_requested_cb(g_vc_m, &callback, &user_data);
2967 if (NULL != callback) {
2968 vc_mgr_client_use_callback(g_vc_m);
2969 ret = callback(key, data, user_data);
2970 vc_mgr_client_not_use_callback(g_vc_m);
2971 SLOG(LOG_INFO, TAG_VCM, "Private data requested callback is called");
2973 SLOG(LOG_WARN, TAG_VCM, "[WARNING] Private data requested callback is null");
2979 /* for TTS feedback */
2980 int __vc_mgr_cb_feedback_audio_format(int rate, vc_audio_channel_e channel, vc_audio_type_e audio_type)
2982 vc_mgr_feedback_audio_format_cb callback = NULL;
2983 void* user_data = NULL;
2985 /* set global audio formats */
2986 g_feedback_rate = rate;
2987 g_feedback_audio_channel = channel;
2988 g_feedback_audio_type = audio_type;
2990 vc_mgr_client_get_feedback_audio_format_cb(g_vc_m, &callback, &user_data);
2992 if (NULL != callback) {
2993 vc_mgr_client_use_callback(g_vc_m);
2994 callback(rate, channel, audio_type, user_data);
2995 vc_mgr_client_not_use_callback(g_vc_m);
2996 SLOG(LOG_INFO, TAG_VCM, "TTS feedback audio format callback is called");
2998 SLOG(LOG_WARN, TAG_VCM, "[WARNING] TTS feedback audio format callback is null");
3001 return VC_ERROR_NONE;
3004 int __vc_mgr_cb_feedback_streaming(int pid, int utt_id, vc_feedback_event_e event, char* buffer, int len)
3006 /* add feedback data */
3007 vc_feedback_data_s* temp_feedback_data = NULL;
3008 temp_feedback_data = (vc_feedback_data_s*)calloc(1, sizeof(vc_feedback_data_s));
3009 RETVM_IF(NULL == temp_feedback_data, VC_ERROR_OUT_OF_MEMORY, TAG_VCM, "[ERROR] Out of memory");
3010 SLOG(LOG_INFO, TAG_VCM, "[INFO] feedback streaming before queing");
3012 temp_feedback_data->data = NULL;
3013 temp_feedback_data->rate = g_feedback_rate;
3014 temp_feedback_data->data_size = 0;
3017 temp_feedback_data->data = (char*)calloc(len + 5, sizeof(char));
3018 if (NULL != temp_feedback_data->data) {
3019 memcpy(temp_feedback_data->data, buffer, len);
3020 temp_feedback_data->data_size = len;
3021 SLOG(LOG_DEBUG, TAG_VCM, "[DEBUG][memcpy] data(%p) size(%d)",
3022 temp_feedback_data->data, temp_feedback_data->data_size);
3024 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] fail to allocate memory");
3027 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] feedback data is NULL");
3030 temp_feedback_data->pid = pid;
3031 temp_feedback_data->utt_id = utt_id;
3032 temp_feedback_data->event = event;
3033 temp_feedback_data->audio_type = g_feedback_audio_type;
3034 temp_feedback_data->channel = g_feedback_audio_channel;
3036 SLOG(LOG_INFO, TAG_VCM, "[INFO] add feedback data, pid(%d), utt_id(%d), event(%d), audio_type(%d), channel(%d)", pid, utt_id, event, g_feedback_audio_type, g_feedback_audio_channel);
3038 int ret = vc_mgr_data_add_feedback_data(temp_feedback_data);
3040 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to add feedback data");
3041 if (NULL != temp_feedback_data->data) {
3042 free(temp_feedback_data->data);
3043 temp_feedback_data->data = NULL;
3045 if (NULL != temp_feedback_data) {
3046 free(temp_feedback_data);
3047 temp_feedback_data = NULL;
3055 int vc_mgr_set_dialog_request_cb(vc_mgr_dialog_request_cb callback, void* user_data)
3057 if (0 != __vc_mgr_get_feature_enabled()) {
3058 SLOG(LOG_DEBUG, TAG_VCM, "@@@ [Manager] not supported");
3059 return VC_ERROR_NOT_SUPPORTED;
3062 if (0 != __vc_mgr_check_privilege()) {
3063 return VC_ERROR_PERMISSION_DENIED;
3066 RETVM_IF(NULL == callback, VC_ERROR_INVALID_PARAMETER, TAG_VCM, "[ERROR] Invalid parameter");
3069 if (0 != vc_mgr_client_get_client_state(g_vc_m, &state)) {
3070 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Set error callback : A handle is not available");
3071 return VC_ERROR_INVALID_STATE;
3075 RETVM_IF(state != VC_STATE_INITIALIZED, VC_ERROR_INVALID_STATE, TAG_VCM, "[ERROR] Invalid State: Current state(%d) is not 'Initialized'", state);
3077 vc_mgr_client_set_dialog_request_cb(g_vc_m, callback, user_data);
3079 return VC_ERROR_NONE;
3082 int vc_mgr_unset_dialog_request_cb(void)
3084 if (0 != __vc_mgr_get_feature_enabled()) {
3085 SLOG(LOG_DEBUG, TAG_VCM, "@@@ [Manager] not supported");
3086 return VC_ERROR_NOT_SUPPORTED;
3089 if (0 != __vc_mgr_check_privilege()) {
3090 return VC_ERROR_PERMISSION_DENIED;
3094 if (0 != vc_mgr_client_get_client_state(g_vc_m, &state)) {
3095 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Unset error callback : A handle is not available");
3096 return VC_ERROR_INVALID_STATE;
3100 RETVM_IF(state != VC_STATE_INITIALIZED, VC_ERROR_INVALID_STATE, TAG_VCM, "[ERROR] Invalid State: Current state(%d) is not 'Initialized'", state);
3102 vc_mgr_client_set_dialog_request_cb(g_vc_m, NULL, NULL);
3104 return VC_ERROR_NONE;
3107 int vc_mgr_set_private_data_set_cb(vc_mgr_private_data_set_cb callback, void* user_data)
3109 if (0 != __vc_mgr_get_feature_enabled()) {
3110 SLOG(LOG_DEBUG, TAG_VCM, "@@@ [Manager] not supported");
3111 return VC_ERROR_NOT_SUPPORTED;
3114 if (0 != __vc_mgr_check_privilege()) {
3115 return VC_ERROR_PERMISSION_DENIED;
3118 RETVM_IF(NULL == callback, VC_ERROR_INVALID_PARAMETER, TAG_VCM, "[ERROR] Invalid parameter");
3121 if (0 != vc_mgr_client_get_client_state(g_vc_m, &state)) {
3122 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Set private data set callback : A handle is not available");
3123 return VC_ERROR_INVALID_STATE;
3127 RETVM_IF(VC_STATE_INITIALIZED != state, VC_ERROR_INVALID_STATE, TAG_VCM, "[ERROR] Set private data set callback : Current state is not 'Initialized'");
3129 vc_mgr_client_set_private_data_set_cb(g_vc_m, callback, user_data);
3131 return VC_ERROR_NONE;
3134 int vc_mgr_unset_private_data_set_cb(void)
3136 if (0 != __vc_mgr_get_feature_enabled()) {
3137 SLOG(LOG_DEBUG, TAG_VCM, "@@@ [Manager] not supported");
3138 return VC_ERROR_NOT_SUPPORTED;
3141 if (0 != __vc_mgr_check_privilege()) {
3142 return VC_ERROR_PERMISSION_DENIED;
3146 if (0 != vc_mgr_client_get_client_state(g_vc_m, &state)) {
3147 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Unset private data set callback : A handle is not available");
3148 return VC_ERROR_INVALID_STATE;
3152 RETVM_IF(VC_STATE_INITIALIZED != state, VC_ERROR_INVALID_STATE, TAG_VCM, "[ERROR] Unset private data set callback : Current state is not 'Initialized'");
3154 vc_mgr_client_set_private_data_set_cb(g_vc_m, NULL, NULL);
3156 return VC_ERROR_NONE;
3159 int vc_mgr_set_private_data_requested_cb(vc_mgr_private_data_requested_cb callback, void* user_data)
3161 if (0 != __vc_mgr_get_feature_enabled()) {
3162 SLOG(LOG_DEBUG, TAG_VCM, "@@@ [Manager] not supported");
3163 return VC_ERROR_NOT_SUPPORTED;
3166 if (0 != __vc_mgr_check_privilege()) {
3167 return VC_ERROR_PERMISSION_DENIED;
3170 RETVM_IF(NULL == callback, VC_ERROR_INVALID_PARAMETER, TAG_VCM, "[ERROR] Invalid parameter");
3173 if (0 != vc_mgr_client_get_client_state(g_vc_m, &state)) {
3174 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Set private data requested callback : A handle is not available");
3175 return VC_ERROR_INVALID_STATE;
3179 RETVM_IF(VC_STATE_INITIALIZED != state, VC_ERROR_INVALID_STATE, TAG_VCM, "[ERROR] Set private data requested callback : Current state is not 'Initialized'");
3181 vc_mgr_client_set_private_data_requested_cb(g_vc_m, callback, user_data);
3183 return VC_ERROR_NONE;
3186 int vc_mgr_unset_private_data_requested_cb(void)
3188 if (0 != __vc_mgr_get_feature_enabled()) {
3189 SLOG(LOG_DEBUG, TAG_VCM, "@@@ [Manager] not supported");
3190 return VC_ERROR_NOT_SUPPORTED;
3193 if (0 != __vc_mgr_check_privilege()) {
3194 return VC_ERROR_PERMISSION_DENIED;
3198 if (0 != vc_mgr_client_get_client_state(g_vc_m, &state)) {
3199 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Unset private data requested callback : A handle is not available");
3200 return VC_ERROR_INVALID_STATE;
3204 RETVM_IF(VC_STATE_INITIALIZED != state, VC_ERROR_INVALID_STATE, TAG_VCM, "[ERROR] Unset private data requested callback : Current state is not 'Initialized'");
3206 vc_mgr_client_set_private_data_requested_cb(g_vc_m, NULL, NULL);
3208 return VC_ERROR_NONE;
3211 static bool __vc_mgr_check_demandable_client(int pid)
3213 if (0 == g_slist_length(g_demandable_client_list)) {
3214 SLOG(LOG_WARN, TAG_VCM, "[WARNING] No demandable clients");
3218 char appid[1024] = {'\0', };
3219 if (0 != aul_app_get_appid_bypid(pid, appid, sizeof(appid) - 1)) {
3220 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to get callee appid by pid");
3223 SLOG(LOG_INFO, TAG_VCM, "[CHECK] Appid - %s", appid);
3225 GSList *iter = NULL;
3226 vc_demandable_client_s* temp_client;
3227 iter = g_slist_nth(g_demandable_client_list, 0);
3229 while (NULL != iter) {
3230 temp_client = iter->data;
3232 if (NULL != temp_client) {
3233 if (NULL != temp_client->appid) {
3234 if (!strcmp(temp_client->appid, appid)) {
3235 SLOG(LOG_DEBUG, TAG_VCM, "pid(%d) is available", pid);
3241 iter = g_slist_next(iter);
3248 int __vc_mgr_request_auth_enable(int pid)
3250 if (false == __vc_mgr_check_demandable_client(pid)) {
3251 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Not demandable client");
3252 return VC_ERROR_INVALID_PARAMETER;
3255 /* check already authorized */
3256 if (true == vc_mgr_client_is_authorized_client(g_vc_m, pid)) {
3257 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Already authorized");
3258 return VC_ERROR_INVALID_PARAMETER;
3261 /* add authorized list */
3262 if (0 != vc_mgr_client_add_authorized_client(g_vc_m, pid)) {
3263 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to add authorized client");
3264 return VC_ERROR_OPERATION_FAILED;
3267 /* foreground check */
3269 if (0 != vc_mgr_client_get_foreground(g_vc_m, &fore_pid)) {
3270 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to get foreground");
3271 return VC_ERROR_OPERATION_FAILED;
3274 if (pid == fore_pid) {
3275 vc_mgr_client_set_valid_authorized_client(g_vc_m, pid);
3278 return VC_ERROR_NONE;
3281 int __vc_mgr_request_auth_disable(int pid)
3283 /* check authorized */
3284 if (false == vc_mgr_client_is_authorized_client(g_vc_m, pid)) {
3285 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] No authorized");
3286 return VC_ERROR_INVALID_PARAMETER;
3289 /* remove authorized list */
3290 if (0 != vc_mgr_client_remove_authorized_client(g_vc_m, pid)) {
3291 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to remove authorized client");
3292 return VC_ERROR_OPERATION_FAILED;
3295 /* check authority valid */
3296 if (true == vc_mgr_client_is_valid_authorized_client(g_vc_m, pid)) {
3297 SLOG(LOG_DEBUG, TAG_VCM, "Valid authorized client is removed");
3298 if (0 != vc_mgr_client_set_valid_authorized_client(g_vc_m, -1)) {
3299 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to set valid authorized client");
3300 return VC_ERROR_OPERATION_FAILED;
3304 return VC_ERROR_NONE;
3307 static Eina_Bool __request_auth_start(void* data)
3309 SLOG(LOG_INFO, TAG_VCM, "Request Start");
3311 if (0 != vc_mgr_client_set_start_by_client(g_vc_m, true)) {
3312 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to set start by client");
3315 if (0 != vc_mgr_start(false)) {
3316 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Request start is failed");
3317 /* TODO - Error handling? */
3320 if (0 != vc_mgr_client_set_start_by_client(g_vc_m, false)) {
3321 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to set start by client");
3328 int __vc_mgr_request_auth_start(int pid)
3330 /* check authorized */
3331 if (false == vc_mgr_client_is_valid_authorized_client(g_vc_m, pid)) {
3332 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] No valid authorized client");
3333 return VC_ERROR_INVALID_PARAMETER;
3336 /* add timer for start recording */
3337 ecore_timer_add(0, __request_auth_start, NULL);
3339 return VC_ERROR_NONE;
3342 static Eina_Bool __request_auth_stop(void* data)
3344 SLOG(LOG_INFO, TAG_VCM, "Request Stop");
3346 if (0 != vc_mgr_stop()) {
3347 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Request stop is failed");
3348 /* TODO - Error handling? */
3354 int __vc_mgr_request_auth_stop(int pid)
3356 /* check authorized */
3357 if (false == vc_mgr_client_is_valid_authorized_client(g_vc_m, pid)) {
3358 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] No valid authorized client");
3359 return VC_ERROR_INVALID_PARAMETER;
3362 /* add timer for start recording */
3363 ecore_timer_add(0, __request_auth_stop, NULL);
3365 return VC_ERROR_NONE;
3368 static Eina_Bool __request_auth_cancel(void* data)
3370 SLOG(LOG_INFO, TAG_VCM, "Request Cancel");
3372 if (0 != vc_mgr_cancel()) {
3373 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Request cancel is failed");
3374 /* TODO - Error handling? */
3380 int __vc_mgr_request_auth_cancel(int pid)
3382 /* check authorized */
3383 if (false == vc_mgr_client_is_valid_authorized_client(g_vc_m, pid)) {
3384 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] No valid authorized client");
3385 return VC_ERROR_INVALID_PARAMETER;
3388 /* add timer for start recording */
3389 ecore_timer_add(0, __request_auth_cancel, NULL);
3391 return VC_ERROR_NONE;
3394 int vc_mgr_set_specific_engine_result_cb(vc_mgr_specific_engine_result_cb callback, void* user_data)
3396 if (0 != __vc_mgr_get_feature_enabled()) {
3397 return VC_ERROR_NOT_SUPPORTED;
3400 if (0 != __vc_mgr_check_privilege()) {
3401 return VC_ERROR_PERMISSION_DENIED;
3404 RETVM_IF(NULL == callback, VC_ERROR_INVALID_PARAMETER, TAG_VCM, "[ERROR] Invalid parameter");
3407 if (0 != vc_mgr_client_get_client_state(g_vc_m, &state)) {
3408 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Set specific engine result callback : A handle is not available");
3409 return VC_ERROR_INVALID_STATE;
3413 RETVM_IF(state != VC_STATE_INITIALIZED, VC_ERROR_INVALID_STATE, TAG_VCM, "[ERROR] Invalid State: Current state(%d) is not 'Initialized'", state);
3415 vc_mgr_client_set_specific_engine_result_cb(g_vc_m, callback, user_data);
3417 return VC_ERROR_NONE;
3419 int vc_mgr_unset_specific_engine_result_cb(void)
3421 if (0 != __vc_mgr_get_feature_enabled()) {
3422 return VC_ERROR_NOT_SUPPORTED;
3426 if (0 != vc_mgr_client_get_client_state(g_vc_m, &state)) {
3427 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Unset specific engine result callback : A handle is not available");
3428 return VC_ERROR_INVALID_STATE;
3432 RETVM_IF(state != VC_STATE_INITIALIZED, VC_ERROR_INVALID_STATE, TAG_VCM, "[ERROR] Invalid State: Current state(%d) is not 'Initialized'", state);
3434 vc_mgr_client_set_specific_engine_result_cb(g_vc_m, NULL, NULL);
3436 return VC_ERROR_NONE;
3439 void __vc_mgr_cb_specific_engine_result(const char* engine_app_id, const char* event, const char* result)
3441 vc_mgr_specific_engine_result_cb callback = NULL;
3442 void* user_data = NULL;
3444 vc_mgr_client_get_specific_engine_result_cb(g_vc_m, &callback, &user_data);
3445 RETM_IF(NULL == callback, TAG_VCM, "[ERROR] Client specific engine result callback is NULL");
3447 vc_mgr_client_use_callback(g_vc_m);
3448 callback(engine_app_id, event, result, user_data);
3449 vc_mgr_client_not_use_callback(g_vc_m);
3450 SLOG(LOG_INFO, TAG_VCM, "Specific engine result callback is called, engine app id(%s), event(%s), result(%s)", engine_app_id, event, result);
3455 /* for TTS feedback */
3456 int vc_mgr_set_feedback_audio_format_cb(vc_mgr_feedback_audio_format_cb callback, void* user_data)
3458 SLOG(LOG_INFO, TAG_VCM, "@@@ [Manager] set feedback audio format");
3460 if (0 != __vc_mgr_get_feature_enabled()) {
3461 return VC_ERROR_NOT_SUPPORTED;
3464 if (0 != __vc_mgr_check_privilege()) {
3465 return VC_ERROR_PERMISSION_DENIED;
3468 RETVM_IF(NULL == callback, VC_ERROR_INVALID_PARAMETER, TAG_VCM, "[ERROR] Invalid parameter");
3471 if (0 != vc_mgr_client_get_client_state(g_vc_m, &state)) {
3472 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Set feedback audio format callback : A handle is not available");
3473 return VC_ERROR_INVALID_STATE;
3477 RETVM_IF(VC_STATE_INITIALIZED != state, VC_ERROR_INVALID_STATE, TAG_VCM, "[ERROR] Set feedback audio format callback : Current state is not 'Initialized'");
3479 vc_mgr_client_set_feedback_audio_format_cb(g_vc_m, callback, user_data);
3481 SLOG(LOG_INFO, TAG_VCM, "[SUCCESS] Set feedback audio format callback");
3483 return VC_ERROR_NONE;
3486 int vc_mgr_unset_feedback_audio_format_cb()
3488 SLOG(LOG_INFO, TAG_VCM, "@@@ [Manager] unset feedback audio format");
3490 if (0 != __vc_mgr_get_feature_enabled()) {
3491 return VC_ERROR_NOT_SUPPORTED;
3494 if (0 != __vc_mgr_check_privilege()) {
3495 return VC_ERROR_PERMISSION_DENIED;
3499 if (0 != vc_mgr_client_get_client_state(g_vc_m, &state)) {
3500 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Unset feedback audio format callback : A handle is not available");
3501 return VC_ERROR_INVALID_STATE;
3505 RETVM_IF(VC_STATE_INITIALIZED != state, VC_ERROR_INVALID_STATE, TAG_VCM, "[ERROR] Unset feedback audio format callback : Current state is not 'Initialized'");
3507 vc_mgr_client_set_feedback_audio_format_cb(g_vc_m, NULL, NULL);
3509 SLOG(LOG_INFO, TAG_VCM, "[SUCCESS] Unset feedback audio format callback");
3511 return VC_ERROR_NONE;
3514 int vc_mgr_set_feedback_streaming_cb(vc_mgr_feedback_streaming_cb callback, void* user_data)
3516 SLOG(LOG_INFO, TAG_VCM, "@@@ [Manager] set feedback streaming");
3518 if (0 != __vc_mgr_get_feature_enabled()) {
3519 return VC_ERROR_NOT_SUPPORTED;
3522 if (0 != __vc_mgr_check_privilege()) {
3523 return VC_ERROR_PERMISSION_DENIED;
3526 RETVM_IF(NULL == callback, VC_ERROR_INVALID_PARAMETER, TAG_VCM, "[ERROR] Invalid parameter");
3528 pthread_mutex_lock(&g_feedback_streaming_cb_mutex);
3531 if (0 != vc_mgr_client_get_client_state(g_vc_m, &state)) {
3532 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Set feedback streaming callback : A handle is not available");
3533 pthread_mutex_unlock(&g_feedback_streaming_cb_mutex);
3534 return VC_ERROR_INVALID_STATE;
3538 if (VC_STATE_INITIALIZED != state) {
3539 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Set feedback streaming callback : Current state is not 'Initialized' (%d)", state);
3540 pthread_mutex_unlock(&g_feedback_streaming_cb_mutex);
3541 return VC_ERROR_INVALID_STATE;
3544 vc_mgr_client_set_feedback_streaming_cb(g_vc_m, callback, user_data);
3546 pthread_mutex_unlock(&g_feedback_streaming_cb_mutex);
3548 SLOG(LOG_INFO, TAG_VCM, "[SUCCESS] Set feedback streaming callback");
3550 return VC_ERROR_NONE;
3553 int vc_mgr_unset_feedback_streaming_cb()
3555 SLOG(LOG_INFO, TAG_VCM, "@@@ [Manager] unset feedback streaming");
3557 if (0 != __vc_mgr_get_feature_enabled()) {
3558 return VC_ERROR_NOT_SUPPORTED;
3561 if (0 != __vc_mgr_check_privilege()) {
3562 return VC_ERROR_PERMISSION_DENIED;
3565 pthread_mutex_lock(&g_feedback_streaming_cb_mutex);
3568 if (0 != vc_mgr_client_get_client_state(g_vc_m, &state)) {
3569 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Unset feedback streaming callback : A handle is not available");
3570 pthread_mutex_unlock(&g_feedback_streaming_cb_mutex);
3571 return VC_ERROR_INVALID_STATE;
3575 if (VC_STATE_INITIALIZED != state) {
3576 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Unset feedback streaming callback : Current state is not 'Initialized' (%d)", state);
3577 pthread_mutex_unlock(&g_feedback_streaming_cb_mutex);
3578 return VC_ERROR_INVALID_STATE;
3581 vc_mgr_client_set_feedback_streaming_cb(g_vc_m, NULL, NULL);
3583 pthread_mutex_unlock(&g_feedback_streaming_cb_mutex);
3585 SLOG(LOG_INFO, TAG_VCM, "[SUCCESS] Unset feedback streaming callback");
3587 return VC_ERROR_NONE;
3590 int vc_mgr_set_vc_tts_streaming_cb(vc_mgr_vc_tts_streaming_cb callback, void* user_data)
3592 SLOG(LOG_INFO, TAG_VCM, "@@@ [Manager] set vc tts streaming callback");
3594 if (0 != __vc_mgr_get_feature_enabled()) {
3595 SLOG(LOG_DEBUG, TAG_VCM, "@@@ [Manager] not supported");
3596 return VC_ERROR_NOT_SUPPORTED;
3599 if (0 != __vc_mgr_check_privilege()) {
3600 return VC_ERROR_PERMISSION_DENIED;
3603 RETVM_IF(NULL == callback, VC_ERROR_INVALID_PARAMETER, TAG_VCM, "[ERROR] Invalid parameter");
3605 pthread_mutex_lock(&g_vc_tts_streaming_cb_mutex);
3608 if (0 != vc_mgr_client_get_client_state(g_vc_m, &state)) {
3609 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Set feedback streaming callback : A handle is not available");
3610 pthread_mutex_unlock(&g_vc_tts_streaming_cb_mutex);
3611 return VC_ERROR_INVALID_STATE;
3615 if (VC_STATE_INITIALIZED != state) {
3616 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Set feedback streaming callback : Current state is not 'Initialized' (%d)", state);
3617 pthread_mutex_unlock(&g_vc_tts_streaming_cb_mutex);
3618 return VC_ERROR_INVALID_STATE;
3621 vc_mgr_client_set_vc_tts_streaming_cb(g_vc_m, callback, user_data);
3623 pthread_mutex_unlock(&g_vc_tts_streaming_cb_mutex);
3625 SLOG(LOG_INFO, TAG_VCM, "[SUCCESS] Set feedback streaming callback");
3627 return VC_ERROR_NONE;
3630 int vc_mgr_unset_vc_tts_streaming_cb()
3632 SLOG(LOG_INFO, TAG_VCM, "@@@ [Manager] unset vc tts streaming callback");
3634 if (0 != __vc_mgr_get_feature_enabled()) {
3635 SLOG(LOG_DEBUG, TAG_VCM, "@@@ [Manager] not supported");
3636 return VC_ERROR_NOT_SUPPORTED;
3639 if (0 != __vc_mgr_check_privilege()) {
3640 return VC_ERROR_PERMISSION_DENIED;
3643 pthread_mutex_lock(&g_vc_tts_streaming_cb_mutex);
3646 if (0 != vc_mgr_client_get_client_state(g_vc_m, &state)) {
3647 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Unset feedback streaming callback : A handle is not available");
3648 pthread_mutex_unlock(&g_vc_tts_streaming_cb_mutex);
3649 return VC_ERROR_INVALID_STATE;
3653 if (VC_STATE_INITIALIZED != state) {
3654 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Unset feedback streaming callback : Current state is not 'Initialized' (%d)", state);
3655 pthread_mutex_unlock(&g_vc_tts_streaming_cb_mutex);
3656 return VC_ERROR_INVALID_STATE;
3659 vc_mgr_client_set_vc_tts_streaming_cb(g_vc_m, NULL, NULL);
3661 pthread_mutex_unlock(&g_vc_tts_streaming_cb_mutex);
3663 SLOG(LOG_INFO, TAG_VCM, "[SUCCESS] Unset feedback streaming callback");
3665 return VC_ERROR_NONE;
3668 static void __tts_feedback_thread(void* data, Ecore_Thread* thread)
3670 SLOG(LOG_INFO, TAG_VCM, "[SUCCESS] Start thread");
3672 vc_feedback_data_s* feedback_data = NULL;
3678 /* get feedback data */
3679 ret = vc_mgr_data_get_feedback_data(&feedback_data);
3680 if (0 != ret || NULL == feedback_data) {
3682 SLOG(LOG_INFO, TAG_VCM, "[DEBUG] No feedback data. Waiting mode");
3687 if (0 < vc_mgr_data_get_feedback_data_size()) {
3688 SLOG(LOG_INFO, TAG_VCM, "[INFO] Resume thread");
3692 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Wrong request, there's no pcm data");
3693 vc_mgr_data_clear_feedback_data(&feedback_data);
3698 SLOG(LOG_INFO, TAG_VCM, "[INFO] Finish to wait for new feedback data come");
3700 /* resume feedback thread */
3701 vc_mgr_data_clear_feedback_data(&feedback_data);
3705 if (NULL != feedback_data) {
3706 if (getpid() == feedback_data->pid) {
3707 vc_mgr_feedback_streaming_cb callback = NULL;
3708 void* user_data = NULL;
3710 pthread_mutex_lock(&g_feedback_streaming_cb_mutex);
3712 vc_mgr_client_get_feedback_streaming_cb(g_vc_m, &callback, &user_data);
3713 if (NULL == callback) {
3714 SLOG(LOG_WARN, TAG_VCM, "[WARNING] TTS feedback streaming callback is null");
3715 vc_mgr_data_clear_feedback_data(&feedback_data);
3716 pthread_mutex_unlock(&g_feedback_streaming_cb_mutex);
3720 SLOG(LOG_DEBUG, TAG_VCM, "TTS feedback streaming callback is called");
3721 vc_mgr_client_use_callback(g_vc_m);
3722 callback(feedback_data->event, feedback_data->data, feedback_data->data_size, user_data);
3723 vc_mgr_client_not_use_callback(g_vc_m);
3725 pthread_mutex_unlock(&g_feedback_streaming_cb_mutex);
3727 /* If no feedback data and EVENT_FINISH */
3728 if (0 >= vc_mgr_data_get_feedback_data_size() && VC_FEEDBACK_EVENT_FINISH == feedback_data->event) {
3729 SLOG(LOG_INFO, TAG_VCM, "[INFO] Finish feedback");
3730 if (feedback_data) {
3731 free(feedback_data);
3732 feedback_data = NULL;
3737 vc_mgr_vc_tts_streaming_cb callback = NULL;
3738 void* user_data = NULL;
3740 pthread_mutex_lock(&g_vc_tts_streaming_cb_mutex);
3742 vc_mgr_client_get_vc_tts_streaming_cb(g_vc_m, &callback, &user_data);
3743 if (NULL == callback) {
3744 SLOG(LOG_WARN, TAG_VCM, "[WARNING] vc tts streaming callback is null");
3745 vc_mgr_data_clear_feedback_data(&feedback_data);
3746 pthread_mutex_unlock(&g_vc_tts_streaming_cb_mutex);
3750 SLOG(LOG_DEBUG, TAG_VCM, "vc tts feedback streaming callback is called");
3751 vc_mgr_client_use_callback(g_vc_m);
3752 callback(feedback_data->pid, feedback_data->utt_id, feedback_data->event, feedback_data->data, feedback_data->data_size, user_data);
3753 vc_mgr_client_not_use_callback(g_vc_m);
3755 pthread_mutex_unlock(&g_vc_tts_streaming_cb_mutex);
3757 /* If no feedback data and EVENT_FINISH */
3758 if (0 >= vc_mgr_data_get_feedback_data_size() && VC_FEEDBACK_EVENT_FINISH == feedback_data->event) {
3759 SLOG(LOG_INFO, TAG_VCM, "[INFO] Finish vc tts feedback");
3760 if (feedback_data) {
3761 free(feedback_data);
3762 feedback_data = NULL;
3767 free(feedback_data);
3768 feedback_data = NULL;
3773 static void __end_tts_feedback_thread(void* data, Ecore_Thread* thread)
3775 SLOG(LOG_INFO, TAG_VCM, "[SUCCESS] End thread");
3776 g_feedback_thread = NULL;
3779 int vc_mgr_start_feedback(void)
3781 SLOG(LOG_INFO, TAG_VCM, "@@@ [Manager] start feedback");
3783 if (0 != __vc_mgr_get_feature_enabled()) {
3784 return VC_ERROR_NOT_SUPPORTED;
3787 if (0 != __vc_mgr_check_privilege()) {
3788 return VC_ERROR_PERMISSION_DENIED;
3791 SLOG(LOG_INFO, TAG_VCM, "@@@ [Manager] Request start TTS feedback");
3794 if (0 != vc_mgr_client_get_client_state(g_vc_m, &state)) {
3795 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Start feedback : A handle is not available");
3796 return VC_ERROR_INVALID_STATE;
3800 RETVM_IF(VC_STATE_READY != state, VC_ERROR_INVALID_STATE, TAG_VCM, "[ERROR] Start feedback : Current state is not 'Ready' (%d)", state);
3803 bool is_exist = ecore_thread_check(g_feedback_thread);
3804 if (NULL == g_feedback_thread || TRUE == is_exist) {
3805 SLOG(LOG_INFO, TAG_VCM, "[INFO] ecore thread run : __tts_feedback_thread");
3806 g_feedback_thread = ecore_thread_run(__tts_feedback_thread, __end_tts_feedback_thread, NULL, NULL);
3809 /* start playing TTS feedback */
3811 ret = vc_mgr_player_play();
3813 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to player play, ret(%d)", ret);
3816 return VC_ERROR_NONE;
3819 int vc_mgr_stop_feedback(void)
3821 SLOG(LOG_INFO, TAG_VCM, "@@@ [Manager] stop feedback");
3823 if (0 != __vc_mgr_get_feature_enabled()) {
3824 return VC_ERROR_NOT_SUPPORTED;
3827 if (0 != __vc_mgr_check_privilege()) {
3828 return VC_ERROR_PERMISSION_DENIED;
3831 SLOG(LOG_INFO, TAG_VCM, "@@@ [Manager] Request stop TTS feedback");
3834 if (0 != vc_mgr_client_get_client_state(g_vc_m, &state)) {
3835 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Stop feedback : A handle is not available");
3836 return VC_ERROR_INVALID_STATE;
3840 RETVM_IF(VC_STATE_READY != state, VC_ERROR_INVALID_STATE, TAG_VCM, "[ERROR] Stop feedback : Current state is not 'Ready' (%d)", state);
3846 vc_feedback_data_s* feedback_data = NULL;
3848 /* get feedback data */
3849 ret = vc_mgr_data_get_feedback_data(&feedback_data);
3850 if (0 != ret || NULL == feedback_data) {
3852 SLOG(LOG_INFO, TAG_VCM, "[INFO] No feedback data to stop any more");
3853 return VC_ERROR_NONE;
3855 ret = vc_mgr_data_clear_feedback_data(&feedback_data);
3857 SLOG(LOG_INFO, TAG_VCM, "[ERROR] Fail to clear data, ret(%d)", ret);
3862 /* request to stop playing TTS feedback */
3864 ret = vc_mgr_player_stop();
3866 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to player stop, ret(%d)", ret);
3872 int vc_mgr_send_utterance_status(int pid, int utt_id, vc_tts_utterance_status_e utt_status)
3874 SLOG(LOG_INFO, TAG_VCM, "@@@ [Manager] send utterance status, pid(%d), utt_id(%d), utt_status(%d)", pid, utt_id, utt_status);
3876 if (0 != __vc_mgr_get_feature_enabled()) {
3877 SLOG(LOG_DEBUG, TAG_VCM, "@@@ [Manager] not supported");
3878 return VC_ERROR_NOT_SUPPORTED;
3881 if (0 != __vc_mgr_check_privilege()) {
3882 return VC_ERROR_PERMISSION_DENIED;
3885 if (VC_TTS_UTTERANCE_NONE > utt_status || VC_TTS_UTTERANCE_CANCELED < utt_status || 0 == utt_status) {
3886 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] utt_status is not valid. (%d)", utt_status);
3887 return VC_ERROR_INVALID_PARAMETER;
3891 if (0 != vc_mgr_client_get_client_state(g_vc_m, &state)) {
3892 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] A handle is not available");
3893 return VC_ERROR_INVALID_STATE;
3897 RETVM_IF(state != VC_STATE_READY, VC_ERROR_INVALID_STATE, TAG_VCM, "[ERROR] Invalid State: Current state(%d) is not 'Ready'", state);
3899 /* Check service state */
3900 vc_service_state_e service_state = -1;
3901 vc_mgr_client_get_service_state(g_vc_m, &service_state);
3902 RETVM_IF(service_state != VC_SERVICE_STATE_READY, VC_ERROR_INVALID_STATE, TAG_VCM, "[ERROR] Invalid State: Current service state(%d) is not 'READY'", service_state);
3904 int ret = vc_mgr_tidl_send_utterance_status(pid, utt_id, utt_status);
3906 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to send utterance status : %s", __vc_mgr_get_error_code(ret));
3908 SLOG(LOG_INFO, TAG_VCM, "[SUCCESS] Send utterance status");
3910 SLOG(LOG_DEBUG, TAG_VCM, "@@@ [Manager] send utterance status DONE");
3914 static float __get_volume_decibel(char* data, int size)
3916 #define MAX_AMPLITUDE_MEAN_16 32768
3923 unsigned long long square_sum = 0;
3928 for (i = 0; i < size; i += (depthByte<<1)) {
3930 memcpy(&pcm16, data + i, sizeof(short));
3931 square_sum += pcm16 * pcm16;
3935 if (0 == count || 0 == square_sum) {
3936 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] No data");
3939 rms = sqrt((float)square_sum/count);
3942 db = 20 * log10(rms/MAX_AMPLITUDE_MEAN_16);
3946 int vc_mgr_send_audio_streaming(vc_audio_streaming_event_e event, unsigned char* buffer, unsigned int len)
3948 SLOG(LOG_INFO, TAG_VCM, "[Manager] Send audio streaming to the engine service, event(%d)", event);
3950 if (0 != __vc_mgr_get_feature_enabled()) {
3951 SLOG(LOG_DEBUG, TAG_VCM, "@@@ [Manager] not supported");
3952 return VC_ERROR_NOT_SUPPORTED;
3955 if (0 != __vc_mgr_check_privilege()) {
3956 return VC_ERROR_PERMISSION_DENIED;
3959 if (VC_AUDIO_STREAMING_EVENT_FAIL > event || VC_AUDIO_STREAMING_EVENT_FINISH < event || 0 == event) {
3960 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] event is invalid parameter (%d)", event);
3961 return VC_ERROR_INVALID_PARAMETER;
3964 RETVM_IF(NULL == buffer, VC_ERROR_INVALID_PARAMETER, TAG_VCM, "[ERROR] Invalid parameter");
3966 vc_state_e state = VC_STATE_NONE;
3967 int ret = vc_mgr_client_get_client_state(g_vc_m, &state);
3969 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] A handle is not available");
3970 return VC_ERROR_INVALID_STATE;
3973 RETVM_IF(state != VC_STATE_READY, VC_ERROR_INVALID_STATE, TAG_VCM, "[ERROR] Invalid State: Current state(%d) is not 'Ready'", state);
3975 vc_service_state_e service_state = VC_SERVICE_STATE_NONE;
3976 ret = vc_mgr_client_get_service_state(g_vc_m, &service_state);
3978 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] A handle is not available");
3979 return VC_ERROR_INVALID_STATE;
3982 if (VC_SERVICE_STATE_READY != service_state && VC_SERVICE_STATE_RECORDING != service_state) {
3983 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Invalid State: service state is not 'READY' and 'RECORDING', state(%d)", service_state);
3984 return VC_ERROR_INVALID_STATE;
3987 float volume = __get_volume_decibel((char*)buffer, len);
3988 __vc_mgr_set_volume(volume);
3990 ret = vc_mgr_tidl_send_audio_streaming(g_vc_m->handle, event, buffer, len);
3992 SLOG(LOG_WARN, TAG_VCM, "[WARNING] retry to send audio streaming data");
3994 SLOG(LOG_INFO, TAG_VCM, "[DEBUG] Success to send");
3998 int vc_mgr_set_audio_streaming_mode(vc_audio_streaming_mode_e mode)
4000 SLOG(LOG_INFO, TAG_VCM, "[Manager] Set multi assistant mode, mode(%d)", mode);
4002 if (0 != __vc_mgr_get_feature_enabled()) {
4003 SLOG(LOG_DEBUG, TAG_VCM, "@@@ [Manager] not supported");
4004 return VC_ERROR_NOT_SUPPORTED;
4007 if (0 != __vc_mgr_check_privilege()) {
4008 return VC_ERROR_PERMISSION_DENIED;
4011 if (VC_AUDIO_STREAMING_MODE_VC_SERVICE > mode || VC_AUDIO_STREAMING_MODE_OUTSIDE < mode) {
4012 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] mode is invalid parameter (%d)", mode);
4013 return VC_ERROR_INVALID_PARAMETER;
4016 vc_state_e state = VC_STATE_NONE;
4017 int ret = vc_mgr_client_get_client_state(g_vc_m, &state);
4019 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] A handle is not available");
4020 return VC_ERROR_INVALID_STATE;
4023 vc_service_state_e service_state = VC_SERVICE_STATE_NONE;
4024 ret = vc_mgr_client_get_service_state(g_vc_m, &service_state);
4026 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] A handle is not available");
4027 return VC_ERROR_INVALID_STATE;
4030 if (VC_STATE_INITIALIZED == state && VC_SERVICE_STATE_NONE == service_state) {
4031 ret = vc_mgr_client_set_audio_streaming_mode(g_vc_m, mode);
4032 if (VC_ERROR_NONE != ret) {
4033 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to set multi assistant mode : %s", __vc_mgr_get_error_code(ret));
4034 return VC_ERROR_INVALID_STATE;
4036 SLOG(LOG_DEBUG, TAG_VCM, "[SUCCESS] Set audio streaming mode in vc mgr client");
4038 } else if (VC_STATE_READY == state && VC_SERVICE_STATE_READY == service_state) {
4039 ret = vc_mgr_client_set_audio_streaming_mode(g_vc_m, mode);
4040 if (VC_ERROR_NONE != ret) {
4041 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to set multi assistant mode : %s", __vc_mgr_get_error_code(ret));
4042 return VC_ERROR_INVALID_STATE;
4044 SLOG(LOG_DEBUG, TAG_VCM, "[SUCCESS] Set audio streaming mode in vc mgr client");
4047 ret = vc_mgr_tidl_request_set_audio_streaming_mode(g_vc_m->handle, mode);
4048 if (VC_ERROR_NONE != ret) {
4049 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to set audio streaming mode : %s", __vc_mgr_get_error_code(ret));
4050 return VC_ERROR_OPERATION_FAILED;
4052 SLOG(LOG_DEBUG, TAG_VCM, "[SUCCESS] Set audio streaming mode in vc mgr tidl");
4055 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Invalid State: Current state is not 'INITIALIZED', state(%d)", state);
4056 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Invalid State: Current service state is not 'READY', service_state(%d)", service_state);
4057 return VC_ERROR_INVALID_STATE;
4060 return VC_ERROR_NONE;
4063 int __vc_change_system_volume(vc_system_volume_event_e volume_event)
4065 int stream_type = -1;
4066 if (VC_SYSTEM_VOLUME_EVENT_CHANGE_FOR_FARFIELD == volume_event) {
4067 stream_type = SOUND_STREAM_TYPE_VOICE_RECOGNITION;
4068 } else if (VC_SYSTEM_VOLUME_EVENT_CHANGE_FOR_NEARFIELD == volume_event) {
4069 stream_type = SOUND_STREAM_TYPE_VOICE_RECOGNITION_SERVICE;
4071 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] volume type is invalid, type(%d)", volume_event);
4072 return VC_ERROR_INVALID_PARAMETER;
4075 SLOG(LOG_INFO, TAG_VCM, "[INFO] Change system volume, volume_type(%d)", volume_event);
4077 int ret = VC_ERROR_NONE;
4078 /* destroy virtual - destroy stream info - create stream info - create virtual */
4079 if (g_virtual_sound_stream_h) {
4080 SLOG(LOG_INFO, TAG_VCM, "[INFO] Virtual stream is already created, destroy virtual stream)");
4081 ret = sound_manager_stop_virtual_stream(g_virtual_sound_stream_h);
4083 SLOG(LOG_WARN, TAG_VCM, "[WARNING] Fail to stop virtual stream, ret(%d)", ret);
4085 ret = sound_manager_destroy_virtual_stream(g_virtual_sound_stream_h);
4087 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to destroy virtual stream, ret(%d)", ret);
4089 g_virtual_sound_stream_h = NULL;
4092 if (g_stream_for_volume_h) {
4093 SLOG(LOG_INFO, TAG_VCM, "[INFO] Stream is already created, destroy stream)");
4094 ret = sound_manager_destroy_stream_information(g_stream_for_volume_h);
4096 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to destroy stream information, ret(%d)", ret);
4098 g_stream_for_volume_h = NULL;
4101 ret = sound_manager_create_stream_information_internal(stream_type, NULL, NULL, &g_stream_for_volume_h);
4103 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to create stream information, ret(%d)", ret);
4104 return VC_ERROR_OPERATION_FAILED;
4107 ret = sound_manager_create_virtual_stream(g_stream_for_volume_h, &g_virtual_sound_stream_h);
4109 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to create virtual stream, ret(%d)", ret);
4110 ret = sound_manager_destroy_stream_information(g_stream_for_volume_h);
4112 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to destroy stream information, ret(%d)", ret);
4114 g_stream_for_volume_h = NULL;
4115 return VC_ERROR_OPERATION_FAILED;
4118 ret = sound_manager_start_virtual_stream(g_virtual_sound_stream_h);
4120 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to start virtual stream, ret(%d)", ret);
4121 ret = sound_manager_destroy_virtual_stream(g_virtual_sound_stream_h);
4123 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to destroy virtual stream, ret(%d)", ret);
4125 g_virtual_sound_stream_h = NULL;
4127 ret = sound_manager_destroy_stream_information(g_stream_for_volume_h);
4129 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to destroy stream information, ret(%d)", ret);
4131 g_stream_for_volume_h = NULL;
4133 return VC_ERROR_OPERATION_FAILED;
4136 SLOG(LOG_INFO, TAG_VCM, "[SUCCESS] Change system volume");
4137 return VC_ERROR_NONE;
4140 int __vc_recover_system_volume()
4142 SLOG(LOG_INFO, TAG_VCM, "[INFO] Recover system volume");
4144 int ret = VC_ERROR_NONE;
4146 if (g_virtual_sound_stream_h) {
4147 ret = sound_manager_stop_virtual_stream(g_virtual_sound_stream_h);
4149 SLOG(LOG_WARN, TAG_VCM, "[WARNING] Fail to stop virtual stream, ret(%d)", ret);
4151 ret = sound_manager_destroy_virtual_stream(g_virtual_sound_stream_h);
4153 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to destroy virtual stream, ret(%d)", ret);
4154 return VC_ERROR_OPERATION_FAILED;
4156 g_virtual_sound_stream_h = NULL;
4159 if (g_stream_for_volume_h) {
4160 ret = sound_manager_destroy_stream_information(g_stream_for_volume_h);
4162 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to destroy stream information, ret(%d)", ret);
4163 return VC_ERROR_OPERATION_FAILED;
4165 g_stream_for_volume_h = NULL;
4168 SLOG(LOG_INFO, TAG_VCM, "[SUCCESS] Recover system volume");
4169 return VC_ERROR_NONE;
4172 int vc_mgr_change_system_volume(vc_system_volume_event_e event)
4174 SLOG(LOG_INFO, TAG_VCM, "[Manager] Change system volume");
4176 if (0 != __vc_mgr_get_feature_enabled()) {
4177 SLOG(LOG_DEBUG, TAG_VCM, "@@@ [Manager] not supported");
4178 return VC_ERROR_NOT_SUPPORTED;
4181 if (0 != __vc_mgr_check_privilege()) {
4182 return VC_ERROR_PERMISSION_DENIED;
4185 if (VC_SYSTEM_VOLUME_EVENT_CHANGE_FOR_NEARFIELD > event || VC_SYSTEM_VOLUME_EVENT_CHANGE_FOR_FARFIELD < event) {
4186 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] event is invalid parameter (%d)", event);
4187 return VC_ERROR_INVALID_PARAMETER;
4191 int ret = vc_mgr_client_get_client_state(g_vc_m, &state);
4193 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] A handle is not available");
4194 return VC_ERROR_INVALID_STATE;
4197 if (state != VC_STATE_READY && state != VC_STATE_INITIALIZED) {
4198 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Invalid State: Current state is not 'READY' and not 'INITIALIZED', state(%d)", state);
4199 return VC_ERROR_INVALID_STATE;
4202 ret = __vc_change_system_volume(event);
4204 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to change volume");
4206 SLOG(LOG_INFO, TAG_VCM, "[DEBUG] Success to change volume");
4210 int vc_mgr_recover_system_volume(void)
4212 SLOG(LOG_INFO, TAG_VCM, "[Manager] recover system volume");
4214 if (0 != __vc_mgr_get_feature_enabled()) {
4215 SLOG(LOG_DEBUG, TAG_VCM, "@@@ [Manager] not supported");
4216 return VC_ERROR_NOT_SUPPORTED;
4219 if (0 != __vc_mgr_check_privilege()) {
4220 return VC_ERROR_PERMISSION_DENIED;
4223 vc_state_e state = VC_STATE_NONE;
4224 int ret = vc_mgr_client_get_client_state(g_vc_m, &state);
4226 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] A handle is not available");
4227 return VC_ERROR_INVALID_STATE;
4230 if (state != VC_STATE_READY && state != VC_STATE_INITIALIZED) {
4231 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Invalid State: Current state is not 'READY' and not 'INITIALIZED', state(%d)", state);
4232 return VC_ERROR_INVALID_STATE;
4235 /* recover volume */
4236 ret = __vc_recover_system_volume();
4238 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to recover volume");
4240 SLOG(LOG_INFO, TAG_VCM, "[DEBUG] Success to recover volume");