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.
17 #include <cynara-client.h>
18 #include <cynara-error.h>
19 #include <cynara-session.h>
22 #include <system_info.h>
24 #include "vc_command.h"
26 #include "voice_control_command.h"
27 #include "voice_control_command_expand.h"
28 #include "voice_control_common.h"
29 #include "voice_control_key_defines.h"
31 static int g_feature_enabled = -1;
33 static int g_privilege_allowed = 1; /* Always True */
34 static cynara *p_cynara = NULL;
36 static int __vc_cmd_get_feature_enabled()
38 if (0 == g_feature_enabled) {
39 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Voice control feature NOT supported");
40 return VC_ERROR_NOT_SUPPORTED;
41 } else if (-1 == g_feature_enabled) {
42 bool vc_supported = false;
43 bool mic_supported = false;
44 if (0 == system_info_get_platform_bool(VC_FEATURE_PATH, &vc_supported)) {
45 if (0 == system_info_get_platform_bool(VC_MIC_FEATURE_PATH, &mic_supported)) {
46 if (false == vc_supported || false == mic_supported) {
47 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Voice control feature NOT supported");
48 g_feature_enabled = 0;
49 return VC_ERROR_NOT_SUPPORTED;
52 g_feature_enabled = 1;
54 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Fail to get feature value");
55 return VC_ERROR_NOT_SUPPORTED;
58 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Fail to get feature value");
59 return VC_ERROR_NOT_SUPPORTED;
66 static int __check_privilege_initialize()
68 int ret = cynara_initialize(&p_cynara, NULL);
69 if (CYNARA_API_SUCCESS != ret)
70 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] fail to initialize");
72 return ret == CYNARA_API_SUCCESS;
75 static int __check_privilege(const char* uid, const char * privilege)
78 char smack_label[1024] = "/proc/self/attr/current";
84 fp = fopen(smack_label, "r");
86 if (fread(smack_label, 1, sizeof(smack_label), fp) <= 0)
87 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] fail to fread");
93 char *session = cynara_session_from_pid(pid);
94 int ret = cynara_check(p_cynara, smack_label, session, uid, privilege);
95 SLOG(LOG_DEBUG, TAG_VCCMD, "[Client]cynara_check returned %d(%s)", ret, (CYNARA_API_ACCESS_ALLOWED == ret) ? "Allowed" : "Denied");
99 if (ret != CYNARA_API_ACCESS_ALLOWED)
104 static void __check_privilege_deinitialize()
107 cynara_finish(p_cynara);
111 static int __vc_cmd_check_privilege()
115 if (0 == g_privilege_allowed) {
116 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Permission is denied");
117 return VC_ERROR_PERMISSION_DENIED;
118 } else if (-1 == g_privilege_allowed) {
119 if (false == __check_privilege_initialize()) {
120 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] privilege initialize is failed");
121 return VC_ERROR_PERMISSION_DENIED;
123 snprintf(uid, 16, "%d", getuid());
124 if (false == __check_privilege(uid, VC_PRIVILEGE)) {
125 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Permission is denied");
126 g_privilege_allowed = 0;
127 __check_privilege_deinitialize();
128 return VC_ERROR_PERMISSION_DENIED;
130 __check_privilege_deinitialize();
133 g_privilege_allowed = 1;
135 return VC_ERROR_NONE;
138 int vc_cmd_list_create(vc_cmd_list_h* vc_cmd_list)
140 if (0 != __vc_cmd_get_feature_enabled()) {
141 return VC_ERROR_NOT_SUPPORTED;
143 if (0 != __vc_cmd_check_privilege()) {
144 return VC_ERROR_PERMISSION_DENIED;
147 if (NULL == vc_cmd_list) {
148 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Input parameter is NULL");
149 return VC_ERROR_INVALID_PARAMETER;
152 vc_cmd_list_s* list = (vc_cmd_list_s*)calloc(1, sizeof(vc_cmd_list_s));
155 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Not enough memory");
156 return VC_ERROR_OUT_OF_MEMORY;
162 *vc_cmd_list = (vc_cmd_list_h)list;
164 SLOG(LOG_DEBUG, TAG_VCCMD, "[List] list(%p)", *vc_cmd_list);
166 return VC_ERROR_NONE;
169 int vc_cmd_list_destroy(vc_cmd_list_h vc_cmd_list, bool release_command)
171 if (0 != __vc_cmd_get_feature_enabled()) {
172 return VC_ERROR_NOT_SUPPORTED;
174 if (0 != __vc_cmd_check_privilege()) {
175 return VC_ERROR_PERMISSION_DENIED;
178 if (NULL == vc_cmd_list) {
179 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Input parameter is NULL");
180 return VC_ERROR_INVALID_PARAMETER;
183 vc_cmd_list_remove_all(vc_cmd_list, release_command);
185 vc_cmd_list_s* list = NULL;
186 list = (vc_cmd_list_s*)vc_cmd_list;
188 SLOG(LOG_DEBUG, TAG_VCCMD, "[List] list(%p)", list);
195 return VC_ERROR_NONE;
198 int vc_cmd_list_get_count(vc_cmd_list_h vc_cmd_list, int* count)
200 if (0 != __vc_cmd_get_feature_enabled()) {
201 return VC_ERROR_NOT_SUPPORTED;
203 if (0 != __vc_cmd_check_privilege()) {
204 return VC_ERROR_PERMISSION_DENIED;
207 if (NULL == vc_cmd_list || NULL == count) {
208 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Get command count : Input parameter is NULL");
209 return VC_ERROR_INVALID_PARAMETER;
212 vc_cmd_list_s* list = NULL;
213 list = (vc_cmd_list_s*)vc_cmd_list;
215 *count = g_slist_length(list->list);
217 SLOG(LOG_DEBUG, TAG_VCCMD, "[List] list(%p), count(%d)", list, *count);
219 return VC_ERROR_NONE;
222 int vc_cmd_list_add(vc_cmd_list_h vc_cmd_list, vc_cmd_h vc_command)
224 if (0 != __vc_cmd_get_feature_enabled()) {
225 return VC_ERROR_NOT_SUPPORTED;
227 if (0 != __vc_cmd_check_privilege()) {
228 return VC_ERROR_PERMISSION_DENIED;
231 if (NULL == vc_cmd_list || NULL == vc_command) {
232 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Input parameter is NULL");
233 return VC_ERROR_INVALID_PARAMETER;
236 vc_cmd_list_s* list = NULL;
237 list = (vc_cmd_list_s*)vc_cmd_list;
239 vc_cmd_s* cmd = NULL;
240 cmd = (vc_cmd_s*)vc_command;
242 list->list = g_slist_append(list->list, cmd);
244 if (1 == g_slist_length(list->list)) {
248 SLOG(LOG_DEBUG, TAG_VCCMD, "[List] list(%p), command(%p)", list, cmd);
250 return VC_ERROR_NONE;
253 int vc_cmd_list_remove(vc_cmd_list_h vc_cmd_list, vc_cmd_h vc_command)
255 if (0 != __vc_cmd_get_feature_enabled()) {
256 return VC_ERROR_NOT_SUPPORTED;
258 if (0 != __vc_cmd_check_privilege()) {
259 return VC_ERROR_PERMISSION_DENIED;
262 if (NULL == vc_cmd_list || NULL == vc_command) {
263 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Input parameter is NULL");
264 return VC_ERROR_INVALID_PARAMETER;
267 vc_cmd_list_s* list = NULL;
268 list = (vc_cmd_list_s*)vc_cmd_list;
270 vc_cmd_s* cmd = NULL;
271 cmd = (vc_cmd_s*)vc_command;
273 SLOG(LOG_DEBUG, TAG_VCCMD, "[List] list(%p), command(%p)", list, cmd);
275 vc_cmd_s* temp_cmd = NULL;
278 iter = g_slist_nth(list->list, 0);
280 while (NULL != iter) {
281 temp_cmd = iter->data;
283 if (NULL != temp_cmd && cmd == temp_cmd) {
284 list->list = g_slist_remove(list->list, temp_cmd);
286 if (true == release_command) {
287 SLOG(LOG_DEBUG, TAG_VCCMD, "Release command data");
288 if (NULL != temp_cmd->command) free(temp_cmd->command);
289 if (NULL != temp_cmd->parameter) free(temp_cmd->parameter);
296 iter = g_slist_next(iter);
299 int count = g_slist_length(list->list);
303 } else if (list->index == count) {
304 list->index = count - 1;
307 return VC_ERROR_NONE;
310 int vc_cmd_list_remove_all(vc_cmd_list_h vc_cmd_list, bool release_command)
312 if (0 != __vc_cmd_get_feature_enabled()) {
313 return VC_ERROR_NOT_SUPPORTED;
315 if (0 != __vc_cmd_check_privilege()) {
316 return VC_ERROR_PERMISSION_DENIED;
319 SLOG(LOG_DEBUG, TAG_VCCMD, "===== Destroy all command");
321 if (NULL == vc_cmd_list) {
322 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Input parameter is NULL");
323 return VC_ERROR_INVALID_PARAMETER;
326 vc_cmd_list_s* list = NULL;
327 list = (vc_cmd_list_s*)vc_cmd_list;
329 SLOG(LOG_DEBUG, TAG_VCCMD, "[List] list (%p), release command (%s)"
330 , list, release_command ? "true" : "false");
332 int count = g_slist_length(list->list);
337 for (i = 0; i < count ; i++) {
338 temp_cmd = g_slist_nth_data(list->list, 0);
340 if (NULL != temp_cmd) {
341 list->list = g_slist_remove(list->list, temp_cmd);
343 if (true == release_command) {
344 SLOG(LOG_DEBUG, TAG_VCCMD, "Free command(%p)", temp_cmd);
345 if (NULL != temp_cmd->command) free(temp_cmd->command);
346 if (NULL != temp_cmd->parameter) free(temp_cmd->parameter);
355 SLOG(LOG_DEBUG, TAG_VCCMD, "=====");
356 SLOG(LOG_DEBUG, TAG_VCCMD, " ");
358 return VC_ERROR_NONE;
361 int vc_cmd_list_foreach_commands(vc_cmd_list_h vc_cmd_list, vc_cmd_list_cb callback, void* user_data)
363 if (0 != __vc_cmd_get_feature_enabled()) {
364 return VC_ERROR_NOT_SUPPORTED;
366 if (0 != __vc_cmd_check_privilege()) {
367 return VC_ERROR_PERMISSION_DENIED;
370 if (NULL == vc_cmd_list) {
371 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Input parameter is NULL");
372 return VC_ERROR_INVALID_PARAMETER;
375 vc_cmd_list_s* list = NULL;
376 list = (vc_cmd_list_s*)vc_cmd_list;
378 int count = g_slist_length(list->list);
384 iter = g_slist_nth(list->list, 0);
386 for (i = 0; i < count; i++) {
388 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] No command in list");
389 return VC_ERROR_OPERATION_FAILED;
392 temp_cmd = iter->data;
394 if (NULL != temp_cmd) {
395 if (false == callback((vc_cmd_h)temp_cmd, user_data)) {
400 iter = g_slist_next(iter);
403 SLOG(LOG_DEBUG, TAG_VCCMD, "===== Foreach commands Done");
405 return VC_ERROR_NONE;
408 int vc_cmd_list_filter_by_type(vc_cmd_list_h original, int type, vc_cmd_list_h* filtered)
410 SLOG(LOG_DEBUG, TAG_VCCMD, "===== Filter by type");
412 if (0 != __vc_cmd_get_feature_enabled()) {
413 return VC_ERROR_NOT_SUPPORTED;
415 if (0 != __vc_cmd_check_privilege()) {
416 return VC_ERROR_PERMISSION_DENIED;
419 if (NULL == original) {
420 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Input parameter is NULL");
421 return VC_ERROR_INVALID_PARAMETER;
424 if (VC_COMMAND_TYPE_NONE >= type || VC_COMMAND_TYPE_EXCLUSIVE < type) {
425 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Invalid type");
426 return VC_ERROR_INVALID_PARAMETER;
429 vc_cmd_list_s* list = NULL;
430 list = (vc_cmd_list_s*)original;
432 vc_cmd_list_h temp_list;
433 if (0 != vc_cmd_list_create(&temp_list)) {
434 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Fail to list create");
435 return VC_ERROR_OPERATION_FAILED;
438 int count = g_slist_length(list->list);
444 iter = g_slist_nth(list->list, 0);
446 for (i = 0; i < count; i++) {
448 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] No command in list");
449 return VC_ERROR_OPERATION_FAILED;
451 if (NULL != iter->data) {
452 iter_cmd = iter->data;
454 if (NULL != iter_cmd) {
456 if (0 != vc_cmd_get_type((vc_cmd_h)iter_cmd, &iter_type)) {
457 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Fail to get command type");
461 if (iter_type == type) {
463 if (0 != vc_cmd_create(&temp_cmd)) {
464 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Fail to create cmd");
468 memcpy(temp_cmd, iter_cmd, sizeof(vc_cmd_s));
469 if (NULL != iter_cmd->command) {
470 ((vc_cmd_s*)temp_cmd)->command = strdup(iter_cmd->command);
472 if (NULL != iter_cmd->parameter) {
473 ((vc_cmd_s*)temp_cmd)->parameter = strdup(iter_cmd->parameter);
476 if (0 != vc_cmd_list_add(temp_list, temp_cmd)) {
477 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Fail to cmd list add");
478 vc_cmd_destroy(temp_cmd);
484 iter = g_slist_next(iter);
488 if (0 != vc_cmd_list_get_count(temp_list, &count)) {
489 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Fail to get count");
491 SLOG(LOG_DEBUG, TAG_VCCMD, "Filtering result : (%d) command", count);
494 *filtered = temp_list;
496 SLOG(LOG_DEBUG, TAG_VCCMD, "=====");
498 return VC_ERROR_NONE;
501 int vc_cmd_list_first(vc_cmd_list_h vc_cmd_list)
503 if (0 != __vc_cmd_get_feature_enabled()) {
504 return VC_ERROR_NOT_SUPPORTED;
506 if (0 != __vc_cmd_check_privilege()) {
507 return VC_ERROR_PERMISSION_DENIED;
510 if (NULL == vc_cmd_list) {
511 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Input parameter is NULL");
512 return VC_ERROR_INVALID_PARAMETER;
515 vc_cmd_list_s* list = NULL;
516 list = (vc_cmd_list_s*)vc_cmd_list;
518 if (0 == g_slist_length(list->list)) {
519 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] List is empty");
520 return VC_ERROR_EMPTY;
525 return VC_ERROR_NONE;
528 int vc_cmd_list_last(vc_cmd_list_h vc_cmd_list)
530 if (0 != __vc_cmd_get_feature_enabled()) {
531 return VC_ERROR_NOT_SUPPORTED;
533 if (0 != __vc_cmd_check_privilege()) {
534 return VC_ERROR_PERMISSION_DENIED;
537 if (NULL == vc_cmd_list) {
538 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Input parameter is NULL");
539 return VC_ERROR_INVALID_PARAMETER;
542 vc_cmd_list_s* list = NULL;
543 list = (vc_cmd_list_s*)vc_cmd_list;
545 int count = g_slist_length(list->list);
548 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] List is empty");
549 return VC_ERROR_EMPTY;
551 list->index = count - 1;
552 SLOG(LOG_DEBUG, TAG_VCCMD, "[DEBUG] List index : %d", list->index);
555 return VC_ERROR_NONE;
558 int vc_cmd_list_next(vc_cmd_list_h vc_cmd_list)
560 if (0 != __vc_cmd_get_feature_enabled()) {
561 return VC_ERROR_NOT_SUPPORTED;
563 if (0 != __vc_cmd_check_privilege()) {
564 return VC_ERROR_PERMISSION_DENIED;
567 if (NULL == vc_cmd_list) {
568 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Input parameter is NULL");
569 return VC_ERROR_INVALID_PARAMETER;
572 vc_cmd_list_s* list = NULL;
573 list = (vc_cmd_list_s*)vc_cmd_list;
575 int count = g_slist_length(list->list);
577 if (list->index < count - 1) {
578 list->index = list->index + 1;
579 SLOG(LOG_DEBUG, TAG_VCCMD, "[DEBUG] List index : %d", list->index);
581 SLOG(LOG_DEBUG, TAG_VCCMD, "[DEBUG] List index : %d", list->index);
582 return VC_ERROR_ITERATION_END;
585 return VC_ERROR_NONE;
588 int vc_cmd_list_prev(vc_cmd_list_h vc_cmd_list)
590 if (0 != __vc_cmd_get_feature_enabled()) {
591 return VC_ERROR_NOT_SUPPORTED;
593 if (0 != __vc_cmd_check_privilege()) {
594 return VC_ERROR_PERMISSION_DENIED;
597 if (NULL == vc_cmd_list) {
598 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Input parameter is NULL");
599 return VC_ERROR_INVALID_PARAMETER;
602 vc_cmd_list_s* list = NULL;
603 list = (vc_cmd_list_s*)vc_cmd_list;
605 if (list->index > 0) {
606 list->index = list->index - 1;
607 SLOG(LOG_DEBUG, TAG_VCCMD, "[DEBUG] List index : %d", list->index);
609 SLOG(LOG_DEBUG, TAG_VCCMD, "[DEBUG] List index : %d", list->index);
610 return VC_ERROR_ITERATION_END;
613 return VC_ERROR_NONE;
616 int vc_cmd_list_get_current(vc_cmd_list_h vc_cmd_list, vc_cmd_h* vc_command)
618 if (0 != __vc_cmd_get_feature_enabled()) {
619 return VC_ERROR_NOT_SUPPORTED;
621 if (0 != __vc_cmd_check_privilege()) {
622 return VC_ERROR_PERMISSION_DENIED;
625 if (NULL == vc_cmd_list || NULL == vc_command) {
626 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Input parameter is NULL");
627 return VC_ERROR_INVALID_PARAMETER;
630 vc_cmd_list_s* list = NULL;
631 list = (vc_cmd_list_s*)vc_cmd_list;
633 SLOG(LOG_DEBUG, TAG_VCCMD, "[List] list (%p), index (%d)", list, list->index);
635 if (0 == g_slist_length(list->list)) {
636 SLOG(LOG_DEBUG, TAG_VCCMD, "[List] list is empty");
638 return VC_ERROR_EMPTY;
641 vc_cmd_s *temp_cmd = NULL;
642 temp_cmd = g_slist_nth_data(list->list, list->index);
644 *vc_command = (vc_cmd_h)temp_cmd;
646 SLOG(LOG_DEBUG, TAG_VCCMD, "[List] Get current command (%p)", *vc_command);
648 return VC_ERROR_NONE;
652 int vc_cmd_create(vc_cmd_h* vc_command)
654 if (0 != __vc_cmd_get_feature_enabled()) {
655 return VC_ERROR_NOT_SUPPORTED;
657 if (0 != __vc_cmd_check_privilege()) {
658 return VC_ERROR_PERMISSION_DENIED;
661 if (NULL == vc_command) {
662 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Input parameter is NULL");
663 return VC_ERROR_INVALID_PARAMETER;
666 vc_cmd_s* command = (vc_cmd_s*)calloc(1, sizeof(vc_cmd_s));
668 if (NULL == command) {
669 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Not enough memory");
670 return VC_ERROR_OUT_OF_MEMORY;
676 command->type = VC_COMMAND_TYPE_NONE;
677 command->format = VC_CMD_FORMAT_FIXED;
678 command->command = NULL;
679 command->parameter = NULL;
681 command->key = VC_KEY_NONE;
682 command->modifier = VC_MODIFIER_NONE;
684 *vc_command = (vc_cmd_h)command;
686 SLOG(LOG_DEBUG, TAG_VCCMD, "[Create command][%p]", *vc_command);
688 return VC_ERROR_NONE;
691 int vc_cmd_destroy(vc_cmd_h vc_command)
693 if (0 != __vc_cmd_get_feature_enabled()) {
694 return VC_ERROR_NOT_SUPPORTED;
696 if (0 != __vc_cmd_check_privilege()) {
697 return VC_ERROR_PERMISSION_DENIED;
700 if (NULL == vc_command) {
701 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Input parameter is NULL");
702 return VC_ERROR_INVALID_PARAMETER;
705 vc_cmd_s* command = NULL;
706 command = (vc_cmd_s*)vc_command;
708 SLOG(LOG_DEBUG, TAG_VCCMD, "[Destroy command][%p]", command);
710 if (NULL != command) {
711 if (NULL != command->command) free(command->command);
712 if (NULL != command->parameter) free(command->parameter);
717 return VC_ERROR_NONE;
720 int vc_cmd_set_id(vc_cmd_h vc_command, int id)
722 if (0 != __vc_cmd_get_feature_enabled()) {
723 return VC_ERROR_NOT_SUPPORTED;
725 if (0 != __vc_cmd_check_privilege()) {
726 return VC_ERROR_PERMISSION_DENIED;
729 if (NULL == vc_command) {
730 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Invalid parameter ");
731 return VC_ERROR_INVALID_PARAMETER;
734 vc_cmd_s* cmd = NULL;
735 cmd = (vc_cmd_s*)vc_command;
739 SLOG(LOG_DEBUG, TAG_VCCMD, "[Set id][%p] id(%d)", vc_command, cmd->id);
745 int vc_cmd_get_id(vc_cmd_h vc_command, int* id)
747 if (0 != __vc_cmd_get_feature_enabled()) {
748 return VC_ERROR_NOT_SUPPORTED;
750 if (0 != __vc_cmd_check_privilege()) {
751 return VC_ERROR_PERMISSION_DENIED;
754 if (NULL == vc_command || NULL == id) {
755 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Invalid handle ");
756 return VC_ERROR_INVALID_PARAMETER;
759 vc_cmd_s* cmd = NULL;
760 cmd = (vc_cmd_s*)vc_command;
764 SLOG(LOG_DEBUG, TAG_VCCMD, "[Get id][%p] id(%d)", vc_command, *id);
770 int vc_cmd_set_command(vc_cmd_h vc_command, const char* command)
772 if (0 != __vc_cmd_get_feature_enabled()) {
773 return VC_ERROR_NOT_SUPPORTED;
775 if (0 != __vc_cmd_check_privilege()) {
776 return VC_ERROR_PERMISSION_DENIED;
779 if (NULL == vc_command) {
780 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Invalid parameter ");
781 return VC_ERROR_INVALID_PARAMETER;
784 vc_cmd_s* cmd = NULL;
785 cmd = (vc_cmd_s*)vc_command;
787 if (NULL != cmd->command) {
793 if (NULL != command) {
794 cmd->command = strdup(command);
797 SLOG(LOG_DEBUG, TAG_VCCMD, "[Set command][%p] Command(%s)", vc_command, cmd->command);
802 int vc_cmd_get_command(vc_cmd_h vc_command, char** command)
804 if (0 != __vc_cmd_get_feature_enabled()) {
805 return VC_ERROR_NOT_SUPPORTED;
807 if (0 != __vc_cmd_check_privilege()) {
808 return VC_ERROR_PERMISSION_DENIED;
811 if (NULL == vc_command || NULL == command) {
812 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Invalid handle ");
813 return VC_ERROR_INVALID_PARAMETER;
816 vc_cmd_s* cmd = NULL;
817 cmd = (vc_cmd_s*)vc_command;
819 if (NULL != cmd->command) {
820 *command = strdup(gettext(cmd->command));
823 SLOG(LOG_DEBUG, TAG_VCCMD, "[Get command][%p] Command(%s)", vc_command, *command);
828 int vc_cmd_set_unfixed_command(vc_cmd_h vc_command, const char* command)
830 if (0 != __vc_cmd_get_feature_enabled()) {
831 return VC_ERROR_NOT_SUPPORTED;
833 if (0 != __vc_cmd_check_privilege()) {
834 return VC_ERROR_PERMISSION_DENIED;
837 if (NULL == vc_command) {
838 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Invalid parameter ");
839 return VC_ERROR_INVALID_PARAMETER;
842 vc_cmd_s* cmd = NULL;
843 cmd = (vc_cmd_s*)vc_command;
845 if (NULL != cmd->parameter) {
846 free(cmd->parameter);
849 cmd->parameter = NULL;
851 if (NULL != command) {
852 cmd->parameter = strdup(command);
853 SLOG(LOG_DEBUG, TAG_VCCMD, "[Set parameter][%p] parameter(%s)", vc_command, cmd->parameter);
859 int vc_cmd_get_unfixed_command(vc_cmd_h vc_command, char** command)
861 if (0 != __vc_cmd_get_feature_enabled()) {
862 return VC_ERROR_NOT_SUPPORTED;
864 if (0 != __vc_cmd_check_privilege()) {
865 return VC_ERROR_PERMISSION_DENIED;
868 if (NULL == vc_command || NULL == command) {
869 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Invalid handle ");
870 return VC_ERROR_INVALID_PARAMETER;
873 vc_cmd_s* cmd = NULL;
874 cmd = (vc_cmd_s*)vc_command;
876 if (NULL != cmd->parameter) {
877 *command = strdup(gettext(cmd->parameter));
878 SLOG(LOG_DEBUG, TAG_VCCMD, "[Get nonfixed command][%p] nonfixed command(%s)", vc_command, *command);
884 int vc_cmd_set_type(vc_cmd_h vc_command, int type)
886 if (0 != __vc_cmd_get_feature_enabled()) {
887 return VC_ERROR_NOT_SUPPORTED;
889 if (0 != __vc_cmd_check_privilege()) {
890 return VC_ERROR_PERMISSION_DENIED;
893 if (NULL == vc_command) {
894 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Invalid parameter ");
895 return VC_ERROR_INVALID_PARAMETER;
898 vc_cmd_s* cmd = NULL;
899 cmd = (vc_cmd_s*)vc_command;
903 SLOG(LOG_DEBUG, TAG_VCCMD, "[Set type][%p] type(%d)", vc_command, cmd->type);
908 int vc_cmd_get_type(vc_cmd_h vc_command, int* type)
910 if (0 != __vc_cmd_get_feature_enabled()) {
911 return VC_ERROR_NOT_SUPPORTED;
913 if (0 != __vc_cmd_check_privilege()) {
914 return VC_ERROR_PERMISSION_DENIED;
917 if (NULL == vc_command || NULL == type) {
918 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Invalid parameter ");
919 return VC_ERROR_INVALID_PARAMETER;
922 vc_cmd_s* cmd = NULL;
923 cmd = (vc_cmd_s*)vc_command;
927 SLOG(LOG_DEBUG, TAG_VCCMD, "[Get type][%p] type(%d)", vc_command, *type);
932 int vc_cmd_set_format(vc_cmd_h vc_command, vc_cmd_format_e format)
934 if (0 != __vc_cmd_get_feature_enabled()) {
935 return VC_ERROR_NOT_SUPPORTED;
937 if (0 != __vc_cmd_check_privilege()) {
938 return VC_ERROR_PERMISSION_DENIED;
941 if (NULL == vc_command) {
942 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Invalid parameter ");
943 return VC_ERROR_INVALID_PARAMETER;
946 vc_cmd_s* cmd = NULL;
947 cmd = (vc_cmd_s*)vc_command;
949 cmd->format = format;
951 SLOG(LOG_DEBUG, TAG_VCCMD, "[Set format][%p] format(%d)", vc_command, format);
956 int vc_cmd_get_format(vc_cmd_h vc_command, vc_cmd_format_e* format)
958 if (0 != __vc_cmd_get_feature_enabled()) {
959 return VC_ERROR_NOT_SUPPORTED;
961 if (0 != __vc_cmd_check_privilege()) {
962 return VC_ERROR_PERMISSION_DENIED;
965 if (NULL == vc_command || NULL == format) {
966 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Invalid parameter ");
967 return VC_ERROR_INVALID_PARAMETER;
970 vc_cmd_s* cmd = NULL;
971 cmd = (vc_cmd_s*)vc_command;
973 *format = cmd->format;
975 SLOG(LOG_DEBUG, TAG_VCCMD, "[Get format][%p] format(%d)", vc_command, *format);
980 int vc_cmd_set_pid(vc_cmd_h vc_command, int pid)
982 if (0 != __vc_cmd_get_feature_enabled()) {
983 return VC_ERROR_NOT_SUPPORTED;
985 if (0 != __vc_cmd_check_privilege()) {
986 return VC_ERROR_PERMISSION_DENIED;
989 if (NULL == vc_command) {
990 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Invalid parameter ");
991 return VC_ERROR_INVALID_PARAMETER;
994 vc_cmd_s* cmd = NULL;
995 cmd = (vc_cmd_s*)vc_command;
999 SLOG(LOG_DEBUG, TAG_VCCMD, "[Set pid][%p] pid(%d)", vc_command, cmd->pid);
1004 int vc_cmd_get_pid(vc_cmd_h vc_command, int* pid)
1006 if (0 != __vc_cmd_get_feature_enabled()) {
1007 return VC_ERROR_NOT_SUPPORTED;
1009 if (0 != __vc_cmd_check_privilege()) {
1010 return VC_ERROR_PERMISSION_DENIED;
1013 if (NULL == vc_command || NULL == pid) {
1014 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Invalid parameter ");
1015 return VC_ERROR_INVALID_PARAMETER;
1018 vc_cmd_s* cmd = NULL;
1019 cmd = (vc_cmd_s*)vc_command;
1023 SLOG(LOG_DEBUG, TAG_VCCMD, "[Get pid][%p] pid(%d)", vc_command, *pid);
1028 int vc_cmd_set_domain(vc_cmd_h vc_command, int domain)
1030 if (0 != __vc_cmd_get_feature_enabled()) {
1031 return VC_ERROR_NOT_SUPPORTED;
1033 if (0 != __vc_cmd_check_privilege()) {
1034 return VC_ERROR_PERMISSION_DENIED;
1037 if (NULL == vc_command) {
1038 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Invalid parameter ");
1039 return VC_ERROR_INVALID_PARAMETER;
1042 vc_cmd_s* cmd = NULL;
1043 cmd = (vc_cmd_s*)vc_command;
1045 cmd->domain = domain;
1047 SLOG(LOG_DEBUG, TAG_VCCMD, "[Set domain] domain : %d", domain);
1052 int vc_cmd_get_domain(vc_cmd_h vc_command, int* domain)
1054 if (0 != __vc_cmd_get_feature_enabled()) {
1055 return VC_ERROR_NOT_SUPPORTED;
1057 if (0 != __vc_cmd_check_privilege()) {
1058 return VC_ERROR_PERMISSION_DENIED;
1061 if (NULL == vc_command || NULL == domain) {
1062 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Invalid parameter ");
1063 return VC_ERROR_INVALID_PARAMETER;
1066 vc_cmd_s* cmd = NULL;
1067 cmd = (vc_cmd_s*)vc_command;
1069 *domain = cmd->domain;
1071 SLOG(LOG_DEBUG, TAG_VCCMD, "[Get domain] domain : %d", *domain);
1077 * @brief Sets key value of command.
1079 * @param[in] vc_command Command handle
1080 * @param[in] key key value
1081 * @param[in] modifier modifier value
1083 * @return 0 on success, otherwise a negative error value
1084 * @retval #VC_ERROR_NONE Successful
1085 * @retval #VC_ERROR_INVALID_PARAMETER Invalid parameter
1087 * @see vc_cmd_get_result_key()
1089 int vc_cmd_set_result_key(vc_cmd_h vc_command, int key, int modifier)
1091 SLOG(LOG_DEBUG, TAG_VCCMD, "===== Set result key");
1093 if (NULL == vc_command) {
1094 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Invalid parameter ");
1095 return VC_ERROR_INVALID_PARAMETER;
1098 vc_cmd_s* cmd = NULL;
1099 cmd = (vc_cmd_s*)vc_command;
1101 SLOG(LOG_DEBUG, TAG_VCCMD, "key : %d, modifier : %d", key, modifier);
1104 cmd->modifier = modifier;
1106 SLOG(LOG_DEBUG, TAG_VCCMD, "=====");
1107 SLOG(LOG_DEBUG, TAG_VCCMD, " ");
1113 * @brief Gets key value of command.
1115 * @param[in] vc_command Command handle
1116 * @param[out] key key value
1117 * @param[out] modifier modifier value
1119 * @return 0 on success, otherwise a negative error value
1120 * @retval #VC_ERROR_NONE Successful
1121 * @retval #VC_ERROR_INVALID_PARAMETER Invalid parameter
1123 * @see vc_cmd_add_result_key()
1125 int vc_cmd_get_result_key(vc_cmd_h vc_command, int* key, int* modifier)
1127 SLOG(LOG_DEBUG, TAG_VCCMD, "===== Get result key");
1129 if (NULL == vc_command || NULL == key || NULL == modifier) {
1130 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Invalid parameter ");
1131 return VC_ERROR_INVALID_PARAMETER;
1134 vc_cmd_s* cmd = NULL;
1135 cmd = (vc_cmd_s*)vc_command;
1138 *modifier = cmd->modifier;
1140 SLOG(LOG_DEBUG, TAG_VCCMD, "=====");
1141 SLOG(LOG_DEBUG, TAG_VCCMD, " ");
1146 int vc_cmd_print_list(vc_cmd_list_h vc_cmd_list)
1148 if (NULL == vc_cmd_list) {
1152 vc_cmd_list_s* list = NULL;
1153 list = (vc_cmd_list_s*)vc_cmd_list;
1155 SLOG(LOG_DEBUG, TAG_VCCMD, "=== Command List ===");
1156 SLOG(LOG_DEBUG, TAG_VCCMD, "[List][%p]", list);
1158 int count = g_slist_length(list->list);
1161 vc_cmd_s *temp_cmd = NULL;
1163 for (i = 0; i < count ; i++) {
1164 temp_cmd = g_slist_nth_data(list->list, i);
1166 if (NULL != temp_cmd) {
1167 SLOG(LOG_DEBUG, TAG_VCCMD, " [%d][%p] PID(%d) ID(%d) Type(%d) Format(%d) Domain(%d) Command(%s) Param(%s)",
1168 i, temp_cmd, temp_cmd->pid, temp_cmd->index, temp_cmd->type, temp_cmd->format, temp_cmd->domain, temp_cmd->command, temp_cmd->parameter);
1172 SLOG(LOG_DEBUG, TAG_VCCMD, "==================");
1173 SLOG(LOG_DEBUG, TAG_VCCMD, " ");