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 <cynara-client.h>
19 #include <cynara-error.h>
20 #include <cynara-session.h>
21 #include <system_info.h>
23 #include "vc_client.h"
24 #include "vc_command.h"
25 #include "vc_config_mgr.h"
27 #include "vc_info_parser.h"
29 #include "voice_control.h"
30 #include "voice_control_authority.h"
31 #include "voice_control_command.h"
32 #include "voice_control_command_expand.h"
36 static Ecore_Timer* g_connect_timer = NULL;
38 static vc_h g_vc = NULL;
40 static int g_feature_enabled = -1;
42 static int g_privilege_allowed = -1;
43 static cynara *p_cynara = NULL;
46 static Ecore_Event_Handler* g_focus_in_hander = NULL;
47 static Ecore_Event_Handler* g_focus_out_hander = NULL;
50 Eina_Bool __vc_notify_state_changed(void *data);
51 Eina_Bool __vc_notify_error(void *data);
53 static int __vc_get_feature_enabled()
55 if (0 == g_feature_enabled) {
56 SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Voice control feature NOT supported");
57 return VC_ERROR_NOT_SUPPORTED;
58 } else if (-1 == g_feature_enabled) {
59 bool vc_supported = false;
60 bool mic_supported = false;
61 if (0 == system_info_get_platform_bool(VC_FEATURE_PATH, &vc_supported)) {
62 if (0 == system_info_get_platform_bool(VC_MIC_FEATURE_PATH, &mic_supported)) {
63 if (false == vc_supported || false == mic_supported) {
64 SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Voice control feature NOT supported");
65 g_feature_enabled = 0;
66 return VC_ERROR_NOT_SUPPORTED;
69 g_feature_enabled = 1;
71 SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Fail to get feature value");
72 return VC_ERROR_NOT_SUPPORTED;
75 SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Fail to get feature value");
76 return VC_ERROR_NOT_SUPPORTED;
83 static int __check_privilege_initialize()
85 int ret = cynara_initialize(&p_cynara, NULL);
86 if (CYNARA_API_SUCCESS != ret)
87 SLOG(LOG_ERROR, TAG_VCC, "[ERROR] fail to initialize");
89 return ret == CYNARA_API_SUCCESS;
92 static int __check_privilege(const char* uid, const char * privilege)
95 char smack_label[1024] = "/proc/self/attr/current";
101 fp = fopen(smack_label, "r");
103 if (fread(smack_label, 1, sizeof(smack_label), fp) <= 0)
104 SLOG(LOG_ERROR, TAG_VCC, "[ERROR] fail to fread");
109 pid_t pid = getpid();
110 char *session = cynara_session_from_pid(pid);
111 int ret = cynara_check(p_cynara, smack_label, session, uid, privilege);
112 SLOG(LOG_DEBUG, TAG_VCC, "[Client]cynara_check returned %d(%s)", ret, (CYNARA_API_ACCESS_ALLOWED == ret) ? "Allowed" : "Denied");
116 if (ret != CYNARA_API_ACCESS_ALLOWED)
121 static void __check_privilege_deinitialize()
124 cynara_finish(p_cynara);
128 static int __vc_check_privilege()
132 if (0 == g_privilege_allowed) {
133 SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Permission is denied");
134 return VC_ERROR_PERMISSION_DENIED;
135 } else if (-1 == g_privilege_allowed) {
136 if (false == __check_privilege_initialize()){
137 SLOG(LOG_ERROR, TAG_VCC, "[ERROR] privilege initialize is failed");
138 return VC_ERROR_PERMISSION_DENIED;
140 snprintf(uid, 16, "%d", getuid());
141 if (false == __check_privilege(uid, VC_PRIVILEGE)) {
142 SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Permission is denied");
143 g_privilege_allowed = 0;
144 __check_privilege_deinitialize();
145 return VC_ERROR_PERMISSION_DENIED;
147 __check_privilege_deinitialize();
150 g_privilege_allowed = 1;
151 return VC_ERROR_NONE;
154 static const char* __vc_get_error_code(vc_error_e err)
157 case VC_ERROR_NONE: return "VC_ERROR_NONE";
158 case VC_ERROR_OUT_OF_MEMORY: return "VC_ERROR_OUT_OF_MEMORY";
159 case VC_ERROR_IO_ERROR: return "VC_ERROR_IO_ERROR";
160 case VC_ERROR_INVALID_PARAMETER: return "VC_ERROR_INVALID_PARAMETER";
161 case VC_ERROR_TIMED_OUT: return "VC_ERROR_TIMED_OUT";
162 case VC_ERROR_RECORDER_BUSY: return "VC_ERROR_RECORDER_BUSY";
163 case VC_ERROR_INVALID_STATE: return "VC_ERROR_INVALID_STATE";
164 case VC_ERROR_INVALID_LANGUAGE: return "VC_ERROR_INVALID_LANGUAGE";
165 case VC_ERROR_ENGINE_NOT_FOUND: return "VC_ERROR_ENGINE_NOT_FOUND";
166 case VC_ERROR_OPERATION_FAILED: return "VC_ERROR_OPERATION_FAILED";
167 default: return "Invalid error code";
172 static int __vc_convert_config_error_code(vc_config_error_e code)
174 if (code == VC_CONFIG_ERROR_NONE) return VC_ERROR_NONE;
175 if (code == VC_CONFIG_ERROR_OUT_OF_MEMORY) return VC_ERROR_OUT_OF_MEMORY;
176 if (code == VC_CONFIG_ERROR_IO_ERROR) return VC_ERROR_IO_ERROR;
177 if (code == VC_CONFIG_ERROR_INVALID_PARAMETER) return VC_ERROR_INVALID_PARAMETER;
178 if (code == VC_CONFIG_ERROR_INVALID_STATE) return VC_ERROR_INVALID_STATE;
179 if (code == VC_CONFIG_ERROR_INVALID_LANGUAGE) return VC_ERROR_INVALID_LANGUAGE;
180 if (code == VC_CONFIG_ERROR_ENGINE_NOT_FOUND) return VC_ERROR_ENGINE_NOT_FOUND;
181 if (code == VC_CONFIG_ERROR_OPERATION_FAILED) return VC_ERROR_OPERATION_FAILED;
183 return VC_ERROR_NONE;
186 static void __vc_lang_changed_cb(const char* before_lang, const char* current_lang)
188 SLOG(LOG_DEBUG, TAG_VCC, "Lang changed : Before lang(%s) Current lang(%s)",
189 before_lang, current_lang);
191 vc_current_language_changed_cb callback;
192 void* lang_user_data;
193 vc_client_get_current_lang_changed_cb(g_vc, &callback, &lang_user_data);
195 if (NULL != callback) {
196 vc_client_use_callback(g_vc);
197 callback(before_lang, current_lang, lang_user_data);
198 vc_client_not_use_callback(g_vc);
199 SLOG(LOG_DEBUG, TAG_VCC, "Language changed callback is called");
201 SLOG(LOG_WARN, TAG_VCC, "[WARNING] Language changed callback is null");
207 static Eina_Bool __notify_auth_changed_cb(void *data)
209 vc_auth_state_changed_cb callback = NULL;
212 vc_client_get_auth_state_changed_cb(g_vc, &callback, &user_data);
214 vc_auth_state_e before = -1;
215 vc_auth_state_e current = -1;
217 vc_client_get_before_auth_state(g_vc, &before, ¤t);
219 if (NULL != callback) {
220 vc_client_use_callback(g_vc);
221 callback(before, current, user_data);
222 vc_client_not_use_callback(g_vc);
223 SLOG(LOG_DEBUG, TAG_VCC, "Auth state changed callback is called");
225 SLOG(LOG_WARN, TAG_VCC, "[WARNING] Auth state changed callback is null");
231 static int __vc_app_state_changed_cb(int app_state, void *data)
234 SLOG(LOG_DEBUG, TAG_VCC, "===== [Client] app state changed");
236 /* Set current pid */
237 if (STATUS_VISIBLE == app_state) {
238 SLOG(LOG_DEBUG, TAG_VCC, "===== Set foreground");
239 ret = vc_dbus_set_foreground(getpid(), true);
241 SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Fail to set foreground (true) : %d", ret);
244 ret = vc_client_set_is_foreground(g_vc, true);
246 SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Fail to save is_foreground (true) : %d", ret);
249 /* set authority valid */
250 vc_auth_state_e state = VC_AUTH_STATE_NONE;
251 if (0 != vc_client_get_auth_state(g_vc, &state)) {
252 SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Fail to get auth state");
254 if (VC_AUTH_STATE_INVALID == state) {
255 vc_client_set_auth_state(g_vc, VC_AUTH_STATE_VALID);
257 /* notify auth changed cb */
258 ecore_timer_add(0, __notify_auth_changed_cb, NULL);
260 } else if (STATUS_BG == app_state) {
261 SLOG(LOG_DEBUG, TAG_VCC, "===== Set background");
262 ret = vc_dbus_set_foreground(getpid(), false);
264 SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Fail to set foreground (false) : %d", ret);
267 ret = vc_client_set_is_foreground(g_vc, false);
269 SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Fail to save is_foreground (false) : %d", ret);
272 /* set authority valid */
273 vc_auth_state_e state = VC_AUTH_STATE_NONE;
274 if (0 != vc_client_get_auth_state(g_vc, &state)) {
275 SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Fail to get auth state");
277 if (VC_AUTH_STATE_VALID == state) {
278 vc_client_set_auth_state(g_vc, VC_AUTH_STATE_INVALID);
280 /* notify authority changed cb */
281 ecore_timer_add(0, __notify_auth_changed_cb, NULL);
284 SLOG(LOG_DEBUG, TAG_VCC, "===== App state is NOT valid");
287 SLOG(LOG_DEBUG, TAG_VCC, "=====");
288 SLOG(LOG_DEBUG, TAG_VCC, " ");
293 int vc_initialize(void)
295 if (0 != __vc_get_feature_enabled()) {
296 return VC_ERROR_NOT_SUPPORTED;
298 if (0 != __vc_check_privilege()) {
299 return VC_ERROR_PERMISSION_DENIED;
302 SLOG(LOG_DEBUG, TAG_VCC, "===== [Client] Initialize");
305 if (true == vc_client_is_valid(g_vc)) {
306 SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Already initialized");
307 return VC_ERROR_INVALID_STATE;
310 if (0 < vc_client_get_count()) {
311 SLOG(LOG_DEBUG, TAG_VCC, "[DEBUG] Already initialized");
312 return VC_ERROR_INVALID_STATE;
315 if (0 != vc_dbus_open_connection()) {
316 SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Fail to open connection");
317 return VC_ERROR_OPERATION_FAILED;
320 if (0 != vc_client_create(&g_vc)) {
321 SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Fail to create client!!!!!");
322 return VC_ERROR_OUT_OF_MEMORY;
325 int ret = vc_config_mgr_initialize(g_vc->handle);
327 SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Fail to init config manager : %s",
328 __vc_get_error_code(__vc_convert_config_error_code(ret)));
329 vc_client_destroy(g_vc);
330 return __vc_convert_config_error_code(ret);
333 ret = vc_config_mgr_set_lang_cb(g_vc->handle, __vc_lang_changed_cb);
335 SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Fail to set config changed : %d", ret);
336 vc_config_mgr_finalize(g_vc->handle);
337 vc_client_destroy(g_vc);
338 return __vc_convert_config_error_code(ret);
341 SLOG(LOG_DEBUG, TAG_VCC, "[Success] pid(%d)", g_vc->handle);
343 SLOG(LOG_DEBUG, TAG_VCC, "=====");
344 SLOG(LOG_DEBUG, TAG_VCC, " ");
346 return VC_ERROR_NONE;
349 static void __vc_internal_unprepare(void)
351 /* return authority */
352 vc_auth_state_e state = VC_AUTH_STATE_NONE;
353 if (0 != vc_client_get_auth_state(g_vc, &state)) {
354 SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Fail to get auth state");
357 if (VC_AUTH_STATE_NONE != state) {
358 if (0 != vc_auth_disable()) {
359 SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Fail to auth disable");
363 int ret = vc_dbus_request_finalize(g_vc->handle);
365 SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Fail to request finalize : %s", __vc_get_error_code(ret));
370 ecore_event_handler_del(g_focus_in_hander);
371 ecore_event_handler_del(g_focus_out_hander);
374 vc_cmd_parser_delete_file(getpid(), VC_COMMAND_TYPE_FOREGROUND);
375 vc_cmd_parser_delete_file(getpid(), VC_COMMAND_TYPE_BACKGROUND);
380 int vc_deinitialize(void)
382 if (0 != __vc_get_feature_enabled()) {
383 return VC_ERROR_NOT_SUPPORTED;
385 if (0 != __vc_check_privilege()) {
386 return VC_ERROR_PERMISSION_DENIED;
389 SLOG(LOG_DEBUG, TAG_VCC, "===== [Client] Deinitialize");
391 if (false == vc_client_is_valid(g_vc)) {
392 SLOG(LOG_ERROR, TAG_VCC, "[ERROR] NOT initialized");
393 SLOG(LOG_DEBUG, TAG_VCC, "=====");
394 SLOG(LOG_DEBUG, TAG_VCC, " ");
395 return VC_ERROR_INVALID_STATE;
399 vc_client_get_client_state(g_vc, &state);
404 __vc_internal_unprepare();
405 /* no break. need to next step*/
406 case VC_STATE_INITIALIZED:
407 if (NULL != g_connect_timer) {
408 SLOG(LOG_DEBUG, TAG_VCC, "Connect Timer is deleted");
409 ecore_timer_del(g_connect_timer);
412 vc_config_mgr_unset_lang_cb(g_vc->handle);
413 vc_config_mgr_finalize(g_vc->handle);
415 /* Free client resources */
416 vc_client_destroy(g_vc);
425 SLOG(LOG_DEBUG, TAG_VCC, "Success: destroy");
427 if (0 != vc_dbus_close_connection()) {
428 SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Fail to close connection");
431 SLOG(LOG_DEBUG, TAG_VCC, "=====");
432 SLOG(LOG_DEBUG, TAG_VCC, " ");
434 return VC_ERROR_NONE;
438 static Eina_Bool __vc_x_event_window_focus_in(void *data, int type, void *event)
440 Ecore_X_Event_Window_Focus_In *e;
445 if (0 != vc_client_get_xid(g_vc, &xid)) {
446 SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Fail to get current xid");
447 return ECORE_CALLBACK_PASS_ON;
450 if (e->win == (Ecore_X_Window)xid) {
451 SLOG(LOG_DEBUG, TAG_VCC, "Focus in : pid(%d) xid(%d)", getpid(), xid);
452 int ret = vc_config_mgr_set_foreground(getpid(), true);
454 ret = vc_config_convert_error_code((vc_config_error_e)ret);
455 SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Fail to set focus in : %s", __vc_get_error_code(ret));
457 /* set authority valid */
458 vc_auth_state_e state = VC_AUTH_STATE_NONE;
459 if (0 != vc_client_get_auth_state(g_vc, &state)) {
460 SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Fail to get auth state");
462 if (VC_AUTH_STATE_INVALID == state) {
463 vc_client_set_auth_state(g_vc, VC_AUTH_STATE_VALID);
465 /* notify auth changed cb */
466 ecore_timer_add(0, __notify_auth_changed_cb, NULL);
470 return ECORE_CALLBACK_PASS_ON;
473 static Eina_Bool __vc_x_event_window_focus_out(void *data, int type, void *event)
475 Ecore_X_Event_Window_Focus_In *e;
480 if (0 != vc_client_get_xid(g_vc, &xid)) {
481 SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Fail to get current xid");
482 return ECORE_CALLBACK_PASS_ON;
485 if (e->win == (Ecore_X_Window)xid) {
486 SLOG(LOG_DEBUG, TAG_VCC, "Focus out : pid(%d) xid(%d)", getpid(), xid);
487 int ret = vc_config_mgr_set_foreground(getpid(), false);
489 ret = vc_config_convert_error_code((vc_config_error_e)ret);
490 SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Fail to set focus out : %s", __vc_get_error_code(ret));
492 /* set authority valid */
493 vc_auth_state_e state = VC_AUTH_STATE_NONE;
494 if (0 != vc_client_get_auth_state(g_vc, &state)) {
495 SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Fail to get auth state");
497 if (VC_AUTH_STATE_VALID == state) {
498 vc_client_set_auth_state(g_vc, VC_AUTH_STATE_INVALID);
500 /* notify authority changed cb */
501 ecore_timer_add(0, __notify_auth_changed_cb, NULL);
505 return ECORE_CALLBACK_PASS_ON;
509 static Eina_Bool __vc_connect_daemon(void *data)
512 if (0 != vc_dbus_request_hello()) {
516 SLOG(LOG_DEBUG, TAG_VCC, "===== [Client] Connect daemon");
518 /* request initialization */
521 int service_state = 0;
522 ret = vc_dbus_request_initialize(g_vc->handle, &mgr_pid, &service_state);
523 if (VC_ERROR_ENGINE_NOT_FOUND == ret) {
524 SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Fail to initialize : %s", __vc_get_error_code(ret));
526 vc_client_set_error(g_vc, VC_ERROR_ENGINE_NOT_FOUND);
527 ecore_timer_add(0, __vc_notify_error, g_vc);
529 SLOG(LOG_DEBUG, TAG_VCC, "=====");
530 SLOG(LOG_DEBUG, TAG_VCC, " ");
533 } else if (0 != ret) {
534 SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Fail to initialize :%s", __vc_get_error_code(ret));
536 vc_client_set_error(g_vc, VC_ERROR_TIMED_OUT);
537 ecore_timer_add(0, __vc_notify_error, g_vc);
539 SLOG(LOG_DEBUG, TAG_VCC, "=====");
540 SLOG(LOG_DEBUG, TAG_VCC, " ");
543 /* Success to connect */
546 /* Set service state */
547 vc_client_set_service_state(g_vc, (vc_service_state_e)service_state);
549 g_connect_timer = NULL;
551 g_focus_in_hander = ecore_event_handler_add(ECORE_X_EVENT_WINDOW_FOCUS_IN, __vc_x_event_window_focus_in, NULL);
552 g_focus_out_hander = ecore_event_handler_add(ECORE_X_EVENT_WINDOW_FOCUS_OUT, __vc_x_event_window_focus_out, NULL);
554 ret = aul_add_status_local_cb(__vc_app_state_changed_cb, NULL);
556 SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Fail to set app stae changed callback");
559 vc_client_set_client_state(g_vc, VC_STATE_READY);
560 ecore_timer_add(0, __vc_notify_state_changed, g_vc);
562 vc_client_set_mgr_pid(g_vc, mgr_pid);
564 SLOG(LOG_DEBUG, TAG_VCC, "=====");
565 SLOG(LOG_DEBUG, TAG_VCC, " ");
572 if (0 != __vc_get_feature_enabled()) {
573 return VC_ERROR_NOT_SUPPORTED;
575 if (0 != __vc_check_privilege()) {
576 return VC_ERROR_PERMISSION_DENIED;
579 SLOG(LOG_DEBUG, TAG_VCC, "===== [Client] Prepare");
582 if (0 != vc_client_get_client_state(g_vc, &state)) {
583 SLOG(LOG_ERROR, TAG_VCC, "[ERROR] A handle is not available");
584 SLOG(LOG_DEBUG, TAG_VCC, "=====");
585 SLOG(LOG_DEBUG, TAG_VCC, " ");
586 return VC_ERROR_INVALID_STATE;
590 if (state != VC_STATE_INITIALIZED) {
591 SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Invalid State: Current state is not 'CREATED'");
592 SLOG(LOG_DEBUG, TAG_VCC, "=====");
593 SLOG(LOG_DEBUG, TAG_VCC, " ");
594 return VC_ERROR_INVALID_STATE;
597 g_connect_timer = ecore_timer_add(0, __vc_connect_daemon, NULL);
599 SLOG(LOG_DEBUG, TAG_VCC, "=====");
600 SLOG(LOG_DEBUG, TAG_VCC, " ");
602 return VC_ERROR_NONE;
605 int vc_unprepare(void)
607 if (0 != __vc_get_feature_enabled()) {
608 return VC_ERROR_NOT_SUPPORTED;
610 if (0 != __vc_check_privilege()) {
611 return VC_ERROR_PERMISSION_DENIED;
614 SLOG(LOG_DEBUG, TAG_VCC, "===== [Client] Unprepare");
617 if (0 != vc_client_get_client_state(g_vc, &state)) {
618 SLOG(LOG_ERROR, TAG_VCC, "[ERROR] A handle is not available");
619 SLOG(LOG_DEBUG, TAG_VCC, "=====");
620 SLOG(LOG_DEBUG, TAG_VCC, " ");
621 return VC_ERROR_INVALID_STATE;
625 if (state != VC_STATE_READY) {
626 SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Invalid State: Current state is not 'READY'");
627 SLOG(LOG_DEBUG, TAG_VCC, "=====");
628 SLOG(LOG_DEBUG, TAG_VCC, " ");
629 return VC_ERROR_INVALID_STATE;
632 __vc_internal_unprepare();
634 vc_client_set_client_state(g_vc, VC_STATE_INITIALIZED);
635 ecore_timer_add(0, __vc_notify_state_changed, g_vc);
637 SLOG(LOG_DEBUG, TAG_VCC, "=====");
638 SLOG(LOG_DEBUG, TAG_VCC, " ");
640 return VC_ERROR_NONE;
643 int vc_foreach_supported_languages(vc_supported_language_cb callback, void* user_data)
645 if (0 != __vc_get_feature_enabled()) {
646 return VC_ERROR_NOT_SUPPORTED;
648 if (0 != __vc_check_privilege()) {
649 return VC_ERROR_PERMISSION_DENIED;
652 SLOG(LOG_DEBUG, TAG_VCC, "===== [Client] Foreach Supported Language");
654 if (NULL == callback) {
655 SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Input parameter is NULL");
656 SLOG(LOG_DEBUG, TAG_VCC, "=====");
657 SLOG(LOG_DEBUG, TAG_VCC, " ");
658 return VC_ERROR_INVALID_PARAMETER;
662 if (0 != vc_client_get_client_state(g_vc, &state)) {
663 SLOG(LOG_ERROR, TAG_VCC, "[ERROR] A handle is not available");
664 SLOG(LOG_DEBUG, TAG_VCC, "=====");
665 SLOG(LOG_DEBUG, TAG_VCC, " ");
666 return VC_ERROR_INVALID_STATE;
670 ret = vc_config_mgr_get_language_list(callback, user_data);
672 ret = vc_config_convert_error_code((vc_config_error_e)ret);
673 SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Fail to get languages : %s", __vc_get_error_code(ret));
676 SLOG(LOG_DEBUG, TAG_VCC, "=====");
677 SLOG(LOG_DEBUG, TAG_VCC, " ");
679 return VC_ERROR_NONE;
683 int vc_get_current_language(char** language)
685 if (0 != __vc_get_feature_enabled()) {
686 return VC_ERROR_NOT_SUPPORTED;
688 if (0 != __vc_check_privilege()) {
689 return VC_ERROR_PERMISSION_DENIED;
692 SLOG(LOG_DEBUG, TAG_VCC, "===== [Client] Get Current Language");
694 if (NULL == language) {
695 SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Input parameter is NULL");
696 SLOG(LOG_DEBUG, TAG_VCC, "=====");
697 SLOG(LOG_DEBUG, TAG_VCC, " ");
698 return VC_ERROR_INVALID_PARAMETER;
702 if (0 != vc_client_get_client_state(g_vc, &state)) {
703 SLOG(LOG_ERROR, TAG_VCC, "[ERROR] A handle is not available");
704 SLOG(LOG_DEBUG, TAG_VCC, "=====");
705 SLOG(LOG_DEBUG, TAG_VCC, " ");
706 return VC_ERROR_INVALID_STATE;
710 ret = vc_config_mgr_get_default_language(language);
712 ret = vc_config_convert_error_code((vc_config_error_e)ret);
713 SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Fail to get current languages : %s", __vc_get_error_code(ret));
716 SLOG(LOG_DEBUG, TAG_VCC, "=====");
717 SLOG(LOG_DEBUG, TAG_VCC, " ");
722 int vc_get_state(vc_state_e* state)
724 if (0 != __vc_get_feature_enabled()) {
725 return VC_ERROR_NOT_SUPPORTED;
727 if (0 != __vc_check_privilege()) {
728 return VC_ERROR_PERMISSION_DENIED;
731 SLOG(LOG_DEBUG, TAG_VCC, "===== [Client] Get State");
734 SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Input parameter is NULL");
735 return VC_ERROR_INVALID_PARAMETER;
739 if (0 != vc_client_get_client_state(g_vc, &temp)) {
740 SLOG(LOG_ERROR, TAG_VCC, "[ERROR] A handle is not available");
741 SLOG(LOG_DEBUG, TAG_VCC, "=====");
742 SLOG(LOG_DEBUG, TAG_VCC, " ");
743 return VC_ERROR_INVALID_STATE;
749 case VC_STATE_NONE: SLOG(LOG_DEBUG, TAG_VCC, "Current state is 'None'"); break;
750 case VC_STATE_INITIALIZED: SLOG(LOG_DEBUG, TAG_VCC, "Current state is 'Created'"); break;
751 case VC_STATE_READY: SLOG(LOG_DEBUG, TAG_VCC, "Current state is 'Ready'"); break;
752 default: SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Invalid state");
755 SLOG(LOG_DEBUG, TAG_VCC, "=====");
756 SLOG(LOG_DEBUG, TAG_VCC, " ");
758 return VC_ERROR_NONE;
761 int vc_get_service_state(vc_service_state_e* state)
763 if (0 != __vc_get_feature_enabled()) {
764 return VC_ERROR_NOT_SUPPORTED;
766 if (0 != __vc_check_privilege()) {
767 return VC_ERROR_PERMISSION_DENIED;
770 SLOG(LOG_DEBUG, TAG_VCC, "===== [Client] Get Service State");
773 SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Input parameter is NULL");
774 return VC_ERROR_INVALID_PARAMETER;
778 if (0 != vc_client_get_client_state(g_vc, &temp)) {
779 SLOG(LOG_ERROR, TAG_VCC, "[ERROR] A handle is not available");
780 SLOG(LOG_DEBUG, TAG_VCC, "=====");
781 SLOG(LOG_DEBUG, TAG_VCC, " ");
782 return VC_ERROR_INVALID_STATE;
785 if (VC_STATE_READY != temp) {
786 SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Invalid State: Current state is not 'READY'");
787 SLOG(LOG_DEBUG, TAG_VCC, "=====");
788 SLOG(LOG_DEBUG, TAG_VCC, " ");
789 return VC_ERROR_INVALID_STATE;
792 /* get service state */
793 vc_service_state_e service_state;
794 if (0 != vc_client_get_service_state(g_vc, &service_state)) {
795 SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Fail to get service state");
796 return VC_ERROR_OPERATION_FAILED;
799 *state = service_state;
802 case VC_SERVICE_STATE_NONE: SLOG(LOG_DEBUG, TAG_VCC, "Current service state is 'None'"); break;
803 case VC_SERVICE_STATE_READY: SLOG(LOG_DEBUG, TAG_VCC, "Current service state is 'Ready'"); break;
804 case VC_SERVICE_STATE_RECORDING: SLOG(LOG_DEBUG, TAG_VCC, "Current service state is 'Recording'"); break;
805 case VC_SERVICE_STATE_PROCESSING: SLOG(LOG_DEBUG, TAG_VCC, "Current service state is 'Processing'"); break;
806 default: SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Invalid state");
809 SLOG(LOG_DEBUG, TAG_VCC, "=====");
810 SLOG(LOG_DEBUG, TAG_VCC, " ");
812 return VC_ERROR_NONE;
816 int vc_set_window_id(int wid)
818 SLOG(LOG_DEBUG, TAG_VCC, "===== [Client] Set Window id");
821 SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Input parameter is invalid");
822 SLOG(LOG_DEBUG, TAG_VCC, "=====");
823 SLOG(LOG_DEBUG, TAG_VCC, " ");
824 return VC_ERROR_INVALID_PARAMETER;
828 if (0 != vc_client_get_client_state(g_vc, &state)) {
829 SLOG(LOG_ERROR, TAG_VCC, "[ERROR] A handle is not available");
830 SLOG(LOG_DEBUG, TAG_VCC, "=====");
831 SLOG(LOG_DEBUG, TAG_VCC, " ");
832 return VC_ERROR_INVALID_STATE;
836 if (state != VC_STATE_READY) {
837 SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Invalid State: Current state is not 'READY'");
838 SLOG(LOG_DEBUG, TAG_VCC, "=====");
839 SLOG(LOG_DEBUG, TAG_VCC, " ");
840 return VC_ERROR_INVALID_STATE;
843 if (0 != vc_client_set_xid(g_vc, wid)) {
844 SLOG(LOG_ERROR, TAG_VCC, "[ERROR] A handle is not valid");
845 SLOG(LOG_DEBUG, TAG_VCC, "=====");
846 SLOG(LOG_DEBUG, TAG_VCC, " ");
847 return VC_ERROR_INVALID_STATE;
850 /* Check if current xid is top window */
852 if ((Ecore_X_Window)wid == ecore_x_window_focus_get()) {
853 /* Set current pid */
854 ret = vc_config_mgr_set_foreground(getpid(), true);
856 ret = vc_config_convert_error_code((vc_config_error_e)ret);
857 SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Fail to set focus in : %s", __vc_get_error_code(ret));
861 SLOG(LOG_DEBUG, TAG_VCC, "=====");
862 SLOG(LOG_DEBUG, TAG_VCC, " ");
867 int vc_get_window_id(int* wid)
869 SLOG(LOG_DEBUG, TAG_VCC, "===== [Client] Get Window id");
872 SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Input parameter is NULL");
873 SLOG(LOG_DEBUG, TAG_VCC, "=====");
874 SLOG(LOG_DEBUG, TAG_VCC, " ");
875 return VC_ERROR_INVALID_PARAMETER;
879 if (0 != vc_client_get_client_state(g_vc, &state)) {
880 SLOG(LOG_ERROR, TAG_VCC, "[ERROR] A handle is not available");
881 SLOG(LOG_DEBUG, TAG_VCC, "=====");
882 SLOG(LOG_DEBUG, TAG_VCC, " ");
883 return VC_ERROR_INVALID_STATE;
887 if (state != VC_STATE_READY) {
888 SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Invalid State: Current state is not 'READY'");
889 SLOG(LOG_DEBUG, TAG_VCC, "=====");
890 SLOG(LOG_DEBUG, TAG_VCC, " ");
891 return VC_ERROR_INVALID_STATE;
894 if (0 != vc_client_get_xid(g_vc, wid)) {
895 SLOG(LOG_ERROR, TAG_VCC, "[ERROR] A handle is not valid");
896 SLOG(LOG_DEBUG, TAG_VCC, "=====");
897 SLOG(LOG_DEBUG, TAG_VCC, " ");
898 return VC_ERROR_INVALID_STATE;
901 SLOG(LOG_DEBUG, TAG_VCC, "=====");
902 SLOG(LOG_DEBUG, TAG_VCC, " ");
904 return VC_ERROR_NONE;
909 * @brief Checks whether the command format is supported.
910 * @since_tizen @if MOBILE 2.4 @elseif WEARABLE 3.0 @endif
912 * @param[in] format The command format
913 * @param[out] support The result status @c true = supported, @c false = not supported
915 * @return 0 on success, otherwise a negative error value
916 * @retval #VC_ERROR_NONE Successful
917 * @retval #VC_ERROR_INVALID_PARAMETER Invalid parameter
918 * @retval #VC_ERROR_OPERATION_FAILED Operation failure
919 * @retval #VC_ERROR_INVALID_STATE Invalid state
921 * @pre The state should be #VC_STATE_READY.
924 int vc_is_command_format_supported(vc_cmd_format_e format, bool* support)
926 SLOG(LOG_DEBUG, TAG_VCC, "===== [Client] Is command format supported");
929 if (0 != vc_client_get_client_state(g_vc, &state)) {
930 SLOG(LOG_ERROR, TAG_VCC, "[ERROR] A handle is not available");
931 SLOG(LOG_DEBUG, TAG_VCC, "=====");
932 SLOG(LOG_DEBUG, TAG_VCC, " ");
933 return VC_ERROR_INVALID_STATE;
937 bool non_fixed_support = false;
938 if (0 != vc_config_mgr_get_nonfixed_support(&non_fixed_support)) {
939 SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Fail to get nonfixed support info");
943 case VC_CMD_FORMAT_FIXED: *support = true; break;
944 case VC_CMD_FORMAT_FIXED_AND_EXTRA: *support = non_fixed_support; break;
945 case VC_CMD_FORMAT_EXTRA_AND_FIXED: *support = non_fixed_support; break;
946 default: *support = false; break;
949 SLOG(LOG_ERROR, TAG_VCC, "[DEBUG] Format(%d) support(%s)", format, *support ? "true" : "false");
951 SLOG(LOG_DEBUG, TAG_VCC, "=====");
952 SLOG(LOG_DEBUG, TAG_VCC, " ");
954 return VC_ERROR_NONE;
958 int vc_set_command_list(vc_cmd_list_h vc_cmd_list, int type)
960 if (0 != __vc_get_feature_enabled()) {
961 return VC_ERROR_NOT_SUPPORTED;
963 if (0 != __vc_check_privilege()) {
964 return VC_ERROR_PERMISSION_DENIED;
967 SLOG(LOG_DEBUG, TAG_VCC, "===== [Client] Set Command list");
969 if (NULL == vc_cmd_list) {
970 SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Input parameter is NULL");
971 return VC_ERROR_INVALID_PARAMETER;
975 if (0 != vc_client_get_client_state(g_vc, &state)) {
976 SLOG(LOG_ERROR, TAG_VCC, "[ERROR] A handle is not available");
977 SLOG(LOG_DEBUG, TAG_VCC, "=====");
978 SLOG(LOG_DEBUG, TAG_VCC, " ");
979 return VC_ERROR_INVALID_STATE;
983 if (state != VC_STATE_READY) {
984 SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Invalid State: Current state is not 'READY'");
985 SLOG(LOG_DEBUG, TAG_VCC, "=====");
986 SLOG(LOG_DEBUG, TAG_VCC, " ");
987 return VC_ERROR_INVALID_STATE;
991 if ((VC_COMMAND_TYPE_FOREGROUND != type) && (VC_COMMAND_TYPE_BACKGROUND != type)) {
992 SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Invalid command type: input type is %d", type);
993 SLOG(LOG_DEBUG, TAG_VCC, "=====");
994 SLOG(LOG_DEBUG, TAG_VCC, " ");
995 return VC_ERROR_INVALID_PARAMETER;
998 vc_cmd_list_s* list = NULL;
999 list = (vc_cmd_list_s*)vc_cmd_list;
1002 if (0 != vc_cmd_parser_save_file(getpid(), (vc_cmd_type_e)type, list->list)) {
1003 ret = VC_ERROR_INVALID_PARAMETER;
1004 SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Fail to save command list : %s", __vc_get_error_code(ret));
1008 ret = vc_dbus_request_set_command(g_vc->handle, (vc_cmd_type_e)type);
1010 if (VC_ERROR_TIMED_OUT != ret) {
1011 SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Fail to request set command to daemon : %s", __vc_get_error_code(ret));
1014 SLOG(LOG_WARN, TAG_VCC, "[WARNING] retry request set command : %s", __vc_get_error_code(ret));
1017 if (VC_RETRY_COUNT == count) {
1018 SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Fail to request");
1026 SLOG(LOG_DEBUG, TAG_VCC, "=====");
1027 SLOG(LOG_DEBUG, TAG_VCC, " ");
1032 int vc_unset_command_list(int type)
1034 if (0 != __vc_get_feature_enabled()) {
1035 return VC_ERROR_NOT_SUPPORTED;
1037 if (0 != __vc_check_privilege()) {
1038 return VC_ERROR_PERMISSION_DENIED;
1041 SLOG(LOG_DEBUG, TAG_VCC, "===== [Client] Unset Command list");
1044 if (0 != vc_client_get_client_state(g_vc, &state)) {
1045 SLOG(LOG_ERROR, TAG_VCC, "[ERROR] A handle is not available");
1046 SLOG(LOG_DEBUG, TAG_VCC, "=====");
1047 SLOG(LOG_DEBUG, TAG_VCC, " ");
1048 return VC_ERROR_INVALID_STATE;
1052 if (state != VC_STATE_READY) {
1053 SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Invalid State: Current state is not 'READY'");
1054 SLOG(LOG_DEBUG, TAG_VCC, "=====");
1055 SLOG(LOG_DEBUG, TAG_VCC, " ");
1056 return VC_ERROR_INVALID_STATE;
1062 ret = vc_dbus_request_unset_command(g_vc->handle, (vc_cmd_type_e)type);
1064 if (VC_ERROR_TIMED_OUT != ret) {
1065 SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Fail to request unset command to daemon : %s", __vc_get_error_code(ret));
1068 SLOG(LOG_WARN, TAG_VCC, "[WARNING] retry request unset command : %s", __vc_get_error_code(ret));
1071 if (VC_RETRY_COUNT == count) {
1072 SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Fail to request");
1079 ret = vc_cmd_parser_delete_file(getpid(), (vc_cmd_type_e)type);
1081 ret = vc_config_convert_error_code((vc_config_error_e)ret);
1082 SLOG(LOG_ERROR, TAG_VCC, "[ERROR] cmd_type(%d), Fail to delete command list : %s", type, __vc_get_error_code(ret));
1085 SLOG(LOG_DEBUG, TAG_VCC, "=====");
1086 SLOG(LOG_DEBUG, TAG_VCC, " ");
1092 int vc_get_exclusive_command_option(bool* value)
1094 SLOG(LOG_DEBUG, TAG_VCC, "===== [Client] Get exclusive command");
1097 if (0 != vc_client_get_client_state(g_vc, &state)) {
1098 SLOG(LOG_ERROR, TAG_VCC, "[ERROR] A handle is not available");
1099 SLOG(LOG_DEBUG, TAG_VCC, "=====");
1100 SLOG(LOG_DEBUG, TAG_VCC, " ");
1101 return VC_ERROR_INVALID_STATE;
1105 if (state != VC_STATE_READY) {
1106 SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Invalid State: Current state is not 'READY'");
1107 SLOG(LOG_DEBUG, TAG_VCC, "=====");
1108 SLOG(LOG_DEBUG, TAG_VCC, " ");
1109 return VC_ERROR_INVALID_STATE;
1112 int ret = vc_client_get_exclusive_cmd(g_vc, value);
1114 SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Fail to set exclusive option : %d", ret);
1115 SLOG(LOG_DEBUG, TAG_VCC, "=====");
1116 SLOG(LOG_DEBUG, TAG_VCC, " ");
1120 SLOG(LOG_DEBUG, TAG_VCC, "=====");
1121 SLOG(LOG_DEBUG, TAG_VCC, " ");
1126 int vc_set_exclusive_command_option(bool value)
1128 if (0 != __vc_get_feature_enabled()) {
1129 return VC_ERROR_NOT_SUPPORTED;
1131 if (0 != __vc_check_privilege()) {
1132 return VC_ERROR_PERMISSION_DENIED;
1135 SLOG(LOG_DEBUG, TAG_VCC, "===== [Client] Set exclusive command");
1138 if (0 != vc_client_get_client_state(g_vc, &state)) {
1139 SLOG(LOG_ERROR, TAG_VCC, "[ERROR] A handle is not available");
1140 SLOG(LOG_DEBUG, TAG_VCC, "=====");
1141 SLOG(LOG_DEBUG, TAG_VCC, " ");
1142 return VC_ERROR_INVALID_STATE;
1146 if (state != VC_STATE_READY) {
1147 SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Invalid State: Current state is not 'READY'");
1148 SLOG(LOG_DEBUG, TAG_VCC, "=====");
1149 SLOG(LOG_DEBUG, TAG_VCC, " ");
1150 return VC_ERROR_INVALID_STATE;
1153 int ret = vc_client_set_exclusive_cmd(g_vc, value);
1155 SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Fail to set exclusive option : %d", ret);
1156 SLOG(LOG_DEBUG, TAG_VCC, "=====");
1157 SLOG(LOG_DEBUG, TAG_VCC, " ");
1161 /* Check if current xid is top window */
1164 ret = vc_dbus_request_set_exclusive_command(g_vc->handle, value);
1166 if (VC_ERROR_TIMED_OUT != ret) {
1167 SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Fail to request set exclusive command to daemon : %s", __vc_get_error_code(ret));
1170 SLOG(LOG_WARN, TAG_VCC, "[WARNING] retry request set exclusive command : %s", __vc_get_error_code(ret));
1173 if (VC_RETRY_COUNT == count) {
1174 SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Fail to request");
1181 SLOG(LOG_DEBUG, TAG_VCC, "=====");
1182 SLOG(LOG_DEBUG, TAG_VCC, " ");
1189 int vc_request_start(bool stop_by_silence)
1191 SLOG(LOG_DEBUG, TAG_VCC, "===== [Client] Request start");
1194 if (0 != vc_client_get_client_state(g_vc, &state)) {
1195 SLOG(LOG_ERROR, TAG_VCC, "[ERROR] A handle is not available");
1196 SLOG(LOG_DEBUG, TAG_VCC, "=====");
1197 SLOG(LOG_DEBUG, TAG_VCC, " ");
1198 return VC_ERROR_INVALID_STATE;
1202 if (state != VC_STATE_READY) {
1203 SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Invalid State: client state is not 'READY'");
1204 SLOG(LOG_DEBUG, TAG_VCC, "=====");
1205 SLOG(LOG_DEBUG, TAG_VCC, " ");
1206 return VC_ERROR_INVALID_STATE;
1209 /* Check service state */
1210 vc_service_state_e service_state = -1;
1211 vc_client_get_service_state(g_vc, &service_state);
1212 if (service_state != VC_SERVICE_STATE_READY) {
1213 SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Invalid State: service state is not 'READY'");
1214 SLOG(LOG_DEBUG, TAG_VCC, "=====");
1215 SLOG(LOG_DEBUG, TAG_VCC, " ");
1216 return VC_ERROR_INVALID_STATE;
1226 ret = vc_dbus_request_start(g_vc->handle, stop_by_silence);
1228 if (VC_ERROR_TIMED_OUT != ret) {
1229 SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Fail to start request start : %s", __vc_get_error_code(ret));
1232 SLOG(LOG_WARN, TAG_VCC, "[WARNING] retry start request start : %s", __vc_get_error_code(ret));
1235 if (VC_RETRY_COUNT == count) {
1236 SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Fail to request");
1241 SLOG(LOG_DEBUG, TAG_VCC, "[SUCCESS] start interrupt");
1245 SLOG(LOG_DEBUG, TAG_VCC, "=====");
1246 SLOG(LOG_DEBUG, TAG_VCC, " ");
1251 int vc_request_stop(void)
1253 SLOG(LOG_DEBUG, TAG_VCC, "===== [Client] Request stop");
1256 if (0 != vc_client_get_client_state(g_vc, &state)) {
1257 SLOG(LOG_ERROR, TAG_VCC, "[ERROR] A handle is not available");
1258 SLOG(LOG_DEBUG, TAG_VCC, "=====");
1259 SLOG(LOG_DEBUG, TAG_VCC, " ");
1260 return VC_ERROR_INVALID_STATE;
1264 if (state != VC_STATE_READY) {
1265 SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Invalid State: client state is not 'Ready'");
1266 SLOG(LOG_DEBUG, TAG_VCC, "=====");
1267 SLOG(LOG_DEBUG, TAG_VCC, " ");
1268 return VC_ERROR_INVALID_STATE;
1271 /* Check service state */
1272 vc_service_state_e service_state = -1;
1273 vc_client_get_service_state(g_vc, &service_state);
1274 if (service_state != VC_SERVICE_STATE_RECORDING) {
1275 SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Invalid State: service state is not 'RECORDING'");
1276 SLOG(LOG_DEBUG, TAG_VCC, "=====");
1277 SLOG(LOG_DEBUG, TAG_VCC, " ");
1278 return VC_ERROR_INVALID_STATE;
1285 ret = vc_dbus_request_stop(g_vc->handle);
1287 if (VC_ERROR_TIMED_OUT != ret) {
1288 SLOG(LOG_DEBUG, TAG_VCC, "[ERROR] Fail to stop request : %s", __vc_get_error_code(ret));
1291 SLOG(LOG_WARN, TAG_VCC, "[WARNING] retry stop request : %s", __vc_get_error_code(ret));
1294 if (VC_RETRY_COUNT == count) {
1295 SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Fail to request");
1300 SLOG(LOG_DEBUG, TAG_VCC, "[SUCCESS] Stop interrupt");
1304 SLOG(LOG_DEBUG, TAG_VCC, "=====");
1305 SLOG(LOG_DEBUG, TAG_VCC, " ");
1310 int vc_request_cancel(void)
1312 SLOG(LOG_DEBUG, TAG_VCC, "===== [Client] Request cancel Interrupt");
1315 if (0 != vc_client_get_client_state(g_vc, &state)) {
1316 SLOG(LOG_ERROR, TAG_VCC, "[ERROR] A handle is not available");
1317 SLOG(LOG_DEBUG, TAG_VCC, "=====");
1318 SLOG(LOG_DEBUG, TAG_VCC, " ");
1319 return VC_ERROR_INVALID_STATE;
1323 if (state != VC_STATE_READY) {
1324 SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Invalid State: Current state is not 'Ready'");
1325 SLOG(LOG_DEBUG, TAG_VCC, "=====");
1326 SLOG(LOG_DEBUG, TAG_VCC, " ");
1327 return VC_ERROR_INVALID_STATE;
1330 /* Check service state */
1331 vc_service_state_e service_state = -1;
1332 vc_client_get_service_state(g_vc, &service_state);
1333 if (service_state != VC_SERVICE_STATE_RECORDING && service_state != VC_SERVICE_STATE_PROCESSING) {
1334 SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Invalid State: service state is not 'RECORDING' or 'PROCESSING'");
1335 SLOG(LOG_DEBUG, TAG_VCC, "=====");
1336 SLOG(LOG_DEBUG, TAG_VCC, " ");
1337 return VC_ERROR_INVALID_STATE;
1343 ret = vc_dbus_request_cancel(g_vc->handle);
1345 if (VC_ERROR_TIMED_OUT != ret) {
1346 SLOG(LOG_DEBUG, TAG_VCC, "[ERROR] Fail to cancel request : %s", __vc_get_error_code(ret));
1349 SLOG(LOG_WARN, TAG_VCC, "[WARNING] retry cancel request : %s", __vc_get_error_code(ret));
1352 if (VC_RETRY_COUNT == count) {
1353 SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Fail to request");
1358 SLOG(LOG_DEBUG, TAG_VCC, "[SUCCESS] Cancel interrupt");
1362 SLOG(LOG_DEBUG, TAG_VCC, "=====");
1363 SLOG(LOG_DEBUG, TAG_VCC, " ");
1369 Eina_Bool __vc_notify_error(void *data)
1371 vc_h vc = (vc_h)data;
1373 vc_error_cb callback = NULL;
1377 vc_client_get_error_cb(vc, &callback, &user_data);
1378 vc_client_get_error(vc, &reason);
1380 if (NULL != callback) {
1381 vc_client_use_callback(vc);
1382 callback(reason, user_data);
1383 vc_client_not_use_callback(vc);
1384 SLOG(LOG_DEBUG, TAG_VCC, "Error callback is called");
1386 SLOG(LOG_WARN, TAG_VCC, "[WARNING] Error callback is null");
1392 int __vc_cb_error(int pid, int reason)
1394 if (0 != vc_client_get_handle(pid, &g_vc)) {
1395 SLOG(LOG_ERROR, TAG_VCC, "Handle is not valid : pid(%d)", pid);
1399 vc_client_set_error(g_vc, reason);
1400 ecore_timer_add(0, __vc_notify_error, g_vc);
1405 Eina_Bool __vc_notify_state_changed(void *data)
1407 vc_h vc = (vc_h)data;
1409 vc_state_changed_cb changed_callback = NULL;
1412 vc_client_get_state_changed_cb(vc, &changed_callback, &user_data);
1414 vc_state_e current_state;
1415 vc_state_e before_state;
1417 vc_client_get_before_state(vc, ¤t_state, &before_state);
1419 if (NULL != changed_callback) {
1420 vc_client_use_callback(vc);
1421 changed_callback(before_state, current_state, user_data);
1422 vc_client_not_use_callback(vc);
1423 SLOG(LOG_DEBUG, TAG_VCC, "State changed callback is called");
1425 SLOG(LOG_WARN, TAG_VCC, "[WARNING] State changed callback is null");
1431 static Eina_Bool __vc_notify_result(void *data)
1435 vc_cmd_list_h vc_cmd_list = NULL;
1437 vc_result_cb callback = NULL;
1438 void* user_data = NULL;
1440 vc_client_get_result_cb(g_vc, &callback, &user_data);
1442 if (NULL == callback) {
1443 SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Client result callback is NULL");
1447 if (0 != vc_cmd_list_create(&vc_cmd_list)) {
1448 SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Fail to create command list");
1452 vc_info_parser_get_result(&temp_text, &event, NULL, getpid(), vc_cmd_list, false);
1454 SLOG(LOG_DEBUG, TAG_VCC, "Result info : result text(%s) event(%d)", temp_text, event);
1456 vc_cmd_print_list(vc_cmd_list);
1458 vc_client_use_callback(g_vc);
1459 callback(event, vc_cmd_list, temp_text, user_data);
1460 vc_client_not_use_callback(g_vc);
1462 SLOG(LOG_DEBUG, TAG_VCC, "Client result callback called");
1464 vc_cmd_list_destroy(vc_cmd_list, true);
1466 /* Release result */
1467 if (NULL != temp_text) free(temp_text);
1472 void __vc_cb_result(void)
1474 ecore_timer_add(0, __vc_notify_result, NULL);
1479 int vc_set_result_cb(vc_result_cb callback, void* user_data)
1481 if (0 != __vc_get_feature_enabled()) {
1482 return VC_ERROR_NOT_SUPPORTED;
1484 if (0 != __vc_check_privilege()) {
1485 return VC_ERROR_PERMISSION_DENIED;
1488 if (NULL == callback)
1489 return VC_ERROR_INVALID_PARAMETER;
1492 if (0 != vc_client_get_client_state(g_vc, &state)) {
1493 SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Set result callback : A handle is not available");
1494 return VC_ERROR_INVALID_STATE;
1498 if (state != VC_STATE_INITIALIZED) {
1499 SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Set result callback : Current state is not 'Initialized'");
1500 return VC_ERROR_INVALID_STATE;
1503 vc_client_set_result_cb(g_vc, callback, user_data);
1508 int vc_unset_result_cb(void)
1510 if (0 != __vc_get_feature_enabled()) {
1511 return VC_ERROR_NOT_SUPPORTED;
1513 if (0 != __vc_check_privilege()) {
1514 return VC_ERROR_PERMISSION_DENIED;
1518 if (0 != vc_client_get_client_state(g_vc, &state)) {
1519 SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Unset result callback : A handle is not available");
1520 return VC_ERROR_INVALID_STATE;
1524 if (state != VC_STATE_INITIALIZED) {
1525 SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Unset result callback : Current state is not 'Initialized'");
1526 return VC_ERROR_INVALID_STATE;
1529 vc_client_set_result_cb(g_vc, NULL, NULL);
1534 int __vc_cb_service_state(int state)
1536 vc_service_state_e current_state = (vc_service_state_e)state;
1537 vc_service_state_e before_state;
1538 vc_client_get_service_state(g_vc, &before_state);
1540 if (current_state == before_state) {
1544 SLOG(LOG_DEBUG, TAG_VCC, "Service State changed : Before(%d) Current(%d)",
1545 before_state, current_state);
1547 /* Save service state */
1548 vc_client_set_service_state(g_vc, current_state);
1550 vc_service_state_changed_cb callback = NULL;
1551 void* service_user_data;
1552 vc_client_get_service_state_changed_cb(g_vc, &callback, &service_user_data);
1554 if (NULL != callback) {
1555 vc_client_use_callback(g_vc);
1556 callback((vc_service_state_e)before_state, (vc_service_state_e)current_state, service_user_data);
1557 vc_client_not_use_callback(g_vc);
1558 SLOG(LOG_DEBUG, TAG_VCC, "Service state changed callback is called");
1560 SLOG(LOG_WARN, TAG_VCC, "[WARNING] Service state changed callback is null");
1566 int vc_set_service_state_changed_cb(vc_service_state_changed_cb callback, void* user_data)
1568 if (0 != __vc_get_feature_enabled()) {
1569 return VC_ERROR_NOT_SUPPORTED;
1571 if (0 != __vc_check_privilege()) {
1572 return VC_ERROR_PERMISSION_DENIED;
1575 if (NULL == callback)
1576 return VC_ERROR_INVALID_PARAMETER;
1579 if (0 != vc_client_get_client_state(g_vc, &state)) {
1580 SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Set result callback : A handle is not available");
1581 return VC_ERROR_INVALID_STATE;
1585 if (state != VC_STATE_INITIALIZED) {
1586 SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Set result callback : Current state is not 'Initialized'");
1587 return VC_ERROR_INVALID_STATE;
1590 vc_client_set_service_state_changed_cb(g_vc, callback, user_data);
1595 int vc_unset_service_state_changed_cb(void)
1597 if (0 != __vc_get_feature_enabled()) {
1598 return VC_ERROR_NOT_SUPPORTED;
1600 if (0 != __vc_check_privilege()) {
1601 return VC_ERROR_PERMISSION_DENIED;
1605 if (0 != vc_client_get_client_state(g_vc, &state)) {
1606 SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Unset result callback : A handle is not available");
1607 return VC_ERROR_INVALID_STATE;
1611 if (state != VC_STATE_INITIALIZED) {
1612 SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Unset result callback : Current state is not 'Initialized'");
1613 return VC_ERROR_INVALID_STATE;
1616 vc_client_set_service_state_changed_cb(g_vc, NULL, NULL);
1621 int vc_set_state_changed_cb(vc_state_changed_cb callback, void* user_data)
1623 if (0 != __vc_get_feature_enabled()) {
1624 return VC_ERROR_NOT_SUPPORTED;
1626 if (0 != __vc_check_privilege()) {
1627 return VC_ERROR_PERMISSION_DENIED;
1630 if (callback == NULL)
1631 return VC_ERROR_INVALID_PARAMETER;
1634 if (0 != vc_client_get_client_state(g_vc, &state)) {
1635 SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Set state changed callback : A handle is not available");
1636 return VC_ERROR_INVALID_STATE;
1640 if (state != VC_STATE_INITIALIZED) {
1641 SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Set state changed callback : Current state is not 'Initialized'");
1642 return VC_ERROR_INVALID_STATE;
1645 vc_client_set_state_changed_cb(g_vc, callback, user_data);
1650 int vc_unset_state_changed_cb(void)
1652 if (0 != __vc_get_feature_enabled()) {
1653 return VC_ERROR_NOT_SUPPORTED;
1655 if (0 != __vc_check_privilege()) {
1656 return VC_ERROR_PERMISSION_DENIED;
1660 if (0 != vc_client_get_client_state(g_vc, &state)) {
1661 SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Unset state changed callback : A handle is not available");
1662 return VC_ERROR_INVALID_STATE;
1666 if (state != VC_STATE_INITIALIZED) {
1667 SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Unset state changed callback : Current state is not 'Initialized'");
1668 return VC_ERROR_INVALID_STATE;
1671 vc_client_set_state_changed_cb(g_vc, NULL, NULL);
1676 int vc_set_current_language_changed_cb(vc_current_language_changed_cb callback, void* user_data)
1678 if (0 != __vc_get_feature_enabled()) {
1679 return VC_ERROR_NOT_SUPPORTED;
1681 if (0 != __vc_check_privilege()) {
1682 return VC_ERROR_PERMISSION_DENIED;
1685 if (NULL == callback)
1686 return VC_ERROR_INVALID_PARAMETER;
1689 if (0 != vc_client_get_client_state(g_vc, &state)) {
1690 SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Set current language changed : A handle is not available");
1691 return VC_ERROR_INVALID_STATE;
1695 if (state != VC_STATE_INITIALIZED) {
1696 SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Set current language changed : Current state is not 'Initialized'");
1697 return VC_ERROR_INVALID_STATE;
1700 vc_client_set_current_lang_changed_cb(g_vc, callback, user_data);
1705 int vc_unset_current_language_changed_cb(void)
1707 if (0 != __vc_get_feature_enabled()) {
1708 return VC_ERROR_NOT_SUPPORTED;
1710 if (0 != __vc_check_privilege()) {
1711 return VC_ERROR_PERMISSION_DENIED;
1715 if (0 != vc_client_get_client_state(g_vc, &state)) {
1716 SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Unset current language changed : A handle is not available");
1717 return VC_ERROR_INVALID_STATE;
1721 if (state != VC_STATE_INITIALIZED) {
1722 SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Unset current language changed : Current state is not 'Initialized'");
1723 return VC_ERROR_INVALID_STATE;
1726 vc_client_set_current_lang_changed_cb(g_vc, NULL, NULL);
1731 int vc_set_error_cb(vc_error_cb callback, void* user_data)
1733 if (0 != __vc_get_feature_enabled()) {
1734 return VC_ERROR_NOT_SUPPORTED;
1736 if (0 != __vc_check_privilege()) {
1737 return VC_ERROR_PERMISSION_DENIED;
1740 if (NULL == callback)
1741 return VC_ERROR_INVALID_PARAMETER;
1744 if (0 != vc_client_get_client_state(g_vc, &state)) {
1745 SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Set error callback : A handle is not available");
1746 return VC_ERROR_INVALID_STATE;
1750 if (state != VC_STATE_INITIALIZED) {
1751 SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Set error callback : Current state is not 'Initialized'");
1752 return VC_ERROR_INVALID_STATE;
1755 vc_client_set_error_cb(g_vc, callback, user_data);
1760 int vc_unset_error_cb(void)
1762 if (0 != __vc_get_feature_enabled()) {
1763 return VC_ERROR_NOT_SUPPORTED;
1765 if (0 != __vc_check_privilege()) {
1766 return VC_ERROR_PERMISSION_DENIED;
1770 if (0 != vc_client_get_client_state(g_vc, &state)) {
1771 SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Unset error callback : A handle is not available");
1772 return VC_ERROR_INVALID_STATE;
1776 if (state != VC_STATE_INITIALIZED) {
1777 SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Unset error callback : Current state is not 'Initialized'");
1778 return VC_ERROR_INVALID_STATE;
1781 vc_client_set_error_cb(g_vc, NULL, NULL);
1787 int vc_auth_enable(void)
1791 if (0 != vc_client_get_client_state(g_vc, &state)) {
1792 SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Handle is not available");
1793 return VC_ERROR_INVALID_STATE;
1796 if (VC_STATE_READY != state) {
1797 SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Current state is not 'READY'");
1798 return VC_ERROR_INVALID_STATE;
1801 /* check already authority */
1802 vc_auth_state_e auth_state = VC_AUTH_STATE_NONE;
1803 if (0 != vc_client_get_auth_state(g_vc, &auth_state)) {
1804 SLOG(LOG_ERROR, TAG_VCC, "[ERROR] handle is not available");
1805 return VC_ERROR_INVALID_STATE;
1808 if (VC_AUTH_STATE_NONE != auth_state) {
1809 SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Already authority enabled");
1810 return VC_ERROR_INVALID_STATE;
1813 /* request authority */
1815 if (0 != vc_client_get_mgr_pid(g_vc, &mgr_pid)) {
1816 SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Fail to get mgr info");
1817 return VC_ERROR_OPERATION_FAILED;
1820 if (0 != vc_dbus_request_auth_enable(g_vc->handle, mgr_pid)) {
1821 SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Fail to authority enabled");
1822 return VC_ERROR_OPERATION_FAILED;
1825 /* set authority into handle */
1826 bool is_foreground = false;
1827 if (0 != vc_client_get_is_foreground(g_vc, &is_foreground)) {
1828 SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Fail to get is_foreground");
1829 return VC_ERROR_OPERATION_FAILED;
1832 if (is_foreground) {
1833 auth_state = VC_AUTH_STATE_VALID;
1835 auth_state = VC_AUTH_STATE_INVALID;
1838 if (0 != vc_client_set_auth_state(g_vc, auth_state)) {
1839 SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Fail to set auth state");
1840 return VC_ERROR_OPERATION_FAILED;
1843 ecore_timer_add(0, __notify_auth_changed_cb, NULL);
1845 SLOG(LOG_DEBUG, TAG_VCC, "[SUCCESS] Auth enable");
1847 return VC_ERROR_NONE;
1850 int vc_auth_disable(void)
1854 if (0 != vc_client_get_client_state(g_vc, &state)) {
1855 SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Handle is not available");
1856 return VC_ERROR_INVALID_STATE;
1859 if (VC_STATE_READY != state) {
1860 SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Current state is not 'READY'");
1861 return VC_ERROR_INVALID_STATE;
1864 /* check autority */
1865 vc_auth_state_e auth_state = VC_AUTH_STATE_NONE;
1866 if (0 != vc_client_get_auth_state(g_vc, &auth_state)) {
1867 SLOG(LOG_ERROR, TAG_VCC, "[ERROR] handle is not available");
1868 return VC_ERROR_INVALID_STATE;
1871 if (VC_AUTH_STATE_NONE == auth_state) {
1872 SLOG(LOG_ERROR, TAG_VCC, "[ERROR] No authority");
1873 return VC_ERROR_INVALID_STATE;
1876 if (0 != vc_auth_unset_state_changed_cb()) {
1877 SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Fail to unset state changed cb");
1880 /* request return authority by dbus */
1882 if (0 != vc_client_get_mgr_pid(g_vc, &mgr_pid)) {
1883 SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Fail to get mgr info");
1884 return VC_ERROR_OPERATION_FAILED;
1887 if (0 != vc_dbus_request_auth_disable(g_vc->handle, mgr_pid)) {
1888 SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Fail to authority disble");
1889 return VC_ERROR_OPERATION_FAILED;
1892 /* unset authority from handle */
1893 if (0 != vc_client_set_auth_state(g_vc, VC_AUTH_STATE_NONE)) {
1894 SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Fail to set auth state");
1895 return VC_ERROR_OPERATION_FAILED;
1898 ecore_timer_add(0, __notify_auth_changed_cb, NULL);
1900 SLOG(LOG_DEBUG, TAG_VCC, "[SUCCESS] Auth disable");
1902 return VC_ERROR_NONE;
1905 int vc_auth_get_state(vc_auth_state_e* state)
1908 vc_state_e vc_state;
1909 if (0 != vc_client_get_client_state(g_vc, &vc_state)) {
1910 SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Handle is not available");
1911 return VC_ERROR_INVALID_STATE;
1914 if (VC_STATE_READY != vc_state) {
1915 SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Current state is not 'READY'");
1916 return VC_ERROR_INVALID_STATE;
1920 vc_auth_state_e temp = VC_AUTH_STATE_NONE;
1921 if (0 != vc_client_get_auth_state(g_vc, &temp)) {
1922 SLOG(LOG_ERROR, TAG_VCC, "[ERROR] handle is not available");
1923 return VC_ERROR_INVALID_STATE;
1928 SLOG(LOG_DEBUG, TAG_VCC, "[SUCCESS] Current auth state is %d", *state);
1930 return VC_ERROR_NONE;
1933 int vc_auth_set_state_changed_cb(vc_auth_state_changed_cb callback, void* user_data)
1935 /* check parameter */
1936 if (NULL == callback) {
1937 SLOG(LOG_ERROR, TAG_VCC, "[ERROR] NULL Parameter");
1938 return VC_ERROR_INVALID_PARAMETER;
1942 vc_auth_state_e auth_state;
1943 if (0 != vc_client_get_auth_state(g_vc, &auth_state)) {
1944 SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Handle is not available");
1945 return VC_ERROR_INVALID_STATE;
1948 if (VC_AUTH_STATE_NONE == auth_state) {
1949 SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Auth is not enabled");
1950 return VC_ERROR_INVALID_STATE;
1953 /* set cb into handle */
1954 if (0 != vc_client_set_auth_state_changed_cb(g_vc, callback, user_data)) {
1955 SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Fail to set auth state changed cb");
1956 return VC_ERROR_OPERATION_FAILED;
1959 SLOG(LOG_DEBUG, TAG_VCC, "[SUCCESS] Set auth state changed cb");
1961 return VC_ERROR_NONE;
1964 int vc_auth_unset_state_changed_cb(void)
1967 vc_auth_state_e auth_state;
1968 if (0 != vc_client_get_auth_state(g_vc, &auth_state)) {
1969 SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Handle is not available");
1970 return VC_ERROR_INVALID_STATE;
1973 if (VC_AUTH_STATE_NONE == auth_state) {
1974 SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Auto is not enabled");
1975 return VC_ERROR_INVALID_STATE;
1978 /* unset cb from handle */
1979 if (0 != vc_client_unset_auth_state_changed_cb(g_vc)) {
1980 SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Fail to unset auth state changed cb");
1981 return VC_ERROR_OPERATION_FAILED;
1984 SLOG(LOG_DEBUG, TAG_VCC, "[SUCCESS] Unset auth state changed cb");
1986 return VC_ERROR_NONE;
1989 int vc_auth_start(void)
1991 SLOG(LOG_DEBUG, TAG_VCC, "===== [Client] Request start");
1994 if (0 != vc_client_get_client_state(g_vc, &state)) {
1995 SLOG(LOG_ERROR, TAG_VCC, "[ERROR] A handle is not available");
1996 SLOG(LOG_DEBUG, TAG_VCC, "=====");
1997 SLOG(LOG_DEBUG, TAG_VCC, " ");
1998 return VC_ERROR_INVALID_STATE;
2002 if (state != VC_STATE_READY) {
2003 SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Invalid State: client state is not 'READY'");
2004 SLOG(LOG_DEBUG, TAG_VCC, "=====");
2005 SLOG(LOG_DEBUG, TAG_VCC, " ");
2006 return VC_ERROR_INVALID_STATE;
2009 /* Check service state */
2010 vc_service_state_e service_state = -1;
2011 vc_client_get_service_state(g_vc, &service_state);
2012 if (service_state != VC_SERVICE_STATE_READY) {
2013 SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Invalid State: service state is not 'READY'");
2014 SLOG(LOG_DEBUG, TAG_VCC, "=====");
2015 SLOG(LOG_DEBUG, TAG_VCC, " ");
2016 return VC_ERROR_INVALID_STATE;
2019 /* Check authority */
2020 vc_auth_state_e auth_state = VC_AUTH_STATE_NONE;
2021 if (0 != vc_client_get_auth_state(g_vc, &auth_state)) {
2022 SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Fail to get auth state");
2023 return VC_ERROR_OPERATION_FAILED;
2026 if (VC_AUTH_STATE_VALID != auth_state) {
2027 SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Not auth valid");
2028 return VC_ERROR_OPERATION_FAILED;
2033 if (0 != vc_client_get_mgr_pid(g_vc, &mgr_pid)) {
2034 SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Fail to get mgr info");
2035 return VC_ERROR_OPERATION_FAILED;
2044 ret = vc_dbus_request_auth_start(g_vc->handle, mgr_pid);
2046 if (VC_ERROR_TIMED_OUT != ret) {
2047 SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Fail to request auth start : %s", __vc_get_error_code(ret));
2050 SLOG(LOG_WARN, TAG_VCC, "[WARNING] retry request auth start : %s", __vc_get_error_code(ret));
2053 if (VC_RETRY_COUNT == count) {
2054 SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Fail to request");
2059 SLOG(LOG_DEBUG, TAG_VCC, "[SUCCESS] request auth start");
2063 SLOG(LOG_DEBUG, TAG_VCC, "=====");
2064 SLOG(LOG_DEBUG, TAG_VCC, " ");
2069 int vc_auth_stop(void)
2071 SLOG(LOG_DEBUG, TAG_VCC, "===== [Client] Request stop");
2074 if (0 != vc_client_get_client_state(g_vc, &state)) {
2075 SLOG(LOG_ERROR, TAG_VCC, "[ERROR] A handle is not available");
2076 SLOG(LOG_DEBUG, TAG_VCC, "=====");
2077 SLOG(LOG_DEBUG, TAG_VCC, " ");
2078 return VC_ERROR_INVALID_STATE;
2082 if (state != VC_STATE_READY) {
2083 SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Invalid State: client state is not 'Ready'");
2084 SLOG(LOG_DEBUG, TAG_VCC, "=====");
2085 SLOG(LOG_DEBUG, TAG_VCC, " ");
2086 return VC_ERROR_INVALID_STATE;
2089 /* Check service state */
2090 vc_service_state_e service_state = -1;
2091 vc_client_get_service_state(g_vc, &service_state);
2092 if (service_state != VC_SERVICE_STATE_RECORDING) {
2093 SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Invalid State: service state is not 'RECORDING'");
2094 SLOG(LOG_DEBUG, TAG_VCC, "=====");
2095 SLOG(LOG_DEBUG, TAG_VCC, " ");
2096 return VC_ERROR_INVALID_STATE;
2099 /* Check authority */
2100 vc_auth_state_e auth_state = VC_AUTH_STATE_NONE;
2101 if (0 != vc_client_get_auth_state(g_vc, &auth_state)) {
2102 SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Fail to get auth state");
2103 return VC_ERROR_OPERATION_FAILED;
2106 if (VC_AUTH_STATE_VALID != auth_state) {
2107 SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Not auth valid");
2108 return VC_ERROR_OPERATION_FAILED;
2113 if (0 != vc_client_get_mgr_pid(g_vc, &mgr_pid)) {
2114 SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Fail to get mgr info");
2115 return VC_ERROR_OPERATION_FAILED;
2122 ret = vc_dbus_request_auth_stop(g_vc->handle, mgr_pid);
2124 if (VC_ERROR_TIMED_OUT != ret) {
2125 SLOG(LOG_DEBUG, TAG_VCC, "[ERROR] Fail to request auth stop: %s", __vc_get_error_code(ret));
2128 SLOG(LOG_WARN, TAG_VCC, "[WARNING] retry request auth stop: %s", __vc_get_error_code(ret));
2131 if (VC_RETRY_COUNT == count) {
2132 SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Fail to request");
2137 SLOG(LOG_DEBUG, TAG_VCC, "[SUCCESS] request auth stop");
2141 SLOG(LOG_DEBUG, TAG_VCC, "=====");
2142 SLOG(LOG_DEBUG, TAG_VCC, " ");
2147 int vc_auth_cancel(void)
2149 SLOG(LOG_DEBUG, TAG_VCC, "===== [Client] Request cancel");
2152 if (0 != vc_client_get_client_state(g_vc, &state)) {
2153 SLOG(LOG_ERROR, TAG_VCC, "[ERROR] A handle is not available");
2154 SLOG(LOG_DEBUG, TAG_VCC, "=====");
2155 SLOG(LOG_DEBUG, TAG_VCC, " ");
2156 return VC_ERROR_INVALID_STATE;
2160 if (state != VC_STATE_READY) {
2161 SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Invalid State: Current state is not 'Ready'");
2162 SLOG(LOG_DEBUG, TAG_VCC, "=====");
2163 SLOG(LOG_DEBUG, TAG_VCC, " ");
2164 return VC_ERROR_INVALID_STATE;
2167 /* Check service state */
2168 vc_service_state_e service_state = -1;
2169 vc_client_get_service_state(g_vc, &service_state);
2170 if (service_state != VC_SERVICE_STATE_RECORDING && service_state != VC_SERVICE_STATE_PROCESSING) {
2171 SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Invalid State: service state is not 'RECORDING' or 'PROCESSING'");
2172 SLOG(LOG_DEBUG, TAG_VCC, "=====");
2173 SLOG(LOG_DEBUG, TAG_VCC, " ");
2174 return VC_ERROR_INVALID_STATE;
2177 /* Check authority */
2178 vc_auth_state_e auth_state = VC_AUTH_STATE_NONE;
2179 if (0 != vc_client_get_auth_state(g_vc, &auth_state)) {
2180 SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Fail to get auth state");
2181 return VC_ERROR_OPERATION_FAILED;
2184 if (VC_AUTH_STATE_VALID != auth_state) {
2185 SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Not auth valid");
2186 return VC_ERROR_OPERATION_FAILED;
2191 if (0 != vc_client_get_mgr_pid(g_vc, &mgr_pid)) {
2192 SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Fail to get mgr info");
2193 return VC_ERROR_OPERATION_FAILED;
2199 ret = vc_dbus_request_auth_cancel(g_vc->handle, mgr_pid);
2201 if (VC_ERROR_TIMED_OUT != ret) {
2202 SLOG(LOG_DEBUG, TAG_VCC, "[ERROR] Fail to request auth cancel: %s", __vc_get_error_code(ret));
2205 SLOG(LOG_WARN, TAG_VCC, "[WARNING] retry request auth cancel: %s", __vc_get_error_code(ret));
2208 if (VC_RETRY_COUNT == count) {
2209 SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Fail to request");
2214 SLOG(LOG_DEBUG, TAG_VCC, "[SUCCESS] request auth cancel");
2218 SLOG(LOG_DEBUG, TAG_VCC, "=====");
2219 SLOG(LOG_DEBUG, TAG_VCC, " ");