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;
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()
117 if (0 == g_privilege_allowed) {
118 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Permission is denied");
119 return VC_ERROR_PERMISSION_DENIED;
120 } else if (-1 == g_privilege_allowed) {
121 if (false == __check_privilege_initialize()){
122 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] privilege initialize is failed");
123 return VC_ERROR_PERMISSION_DENIED;
125 snprintf(uid, 16, "%d", getuid());
126 if (false == __check_privilege(uid, VC_PRIVILEGE)) {
127 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Permission is denied");
128 g_privilege_allowed = 0;
129 __check_privilege_deinitialize();
130 return VC_ERROR_PERMISSION_DENIED;
132 __check_privilege_deinitialize();
135 g_privilege_allowed = 1;
137 return VC_ERROR_NONE;
140 int vc_cmd_list_create(vc_cmd_list_h* vc_cmd_list)
142 if (0 != __vc_cmd_get_feature_enabled()) {
143 return VC_ERROR_NOT_SUPPORTED;
145 if (0 != __vc_cmd_check_privilege()) {
146 return VC_ERROR_PERMISSION_DENIED;
149 if (NULL == vc_cmd_list) {
150 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Input parameter is NULL");
151 return VC_ERROR_INVALID_PARAMETER;
154 vc_cmd_list_s* list = (vc_cmd_list_s*)calloc(1, sizeof(vc_cmd_list_s));
157 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Not enough memory");
158 return VC_ERROR_OUT_OF_MEMORY;
164 *vc_cmd_list = (vc_cmd_list_h)list;
166 SLOG(LOG_DEBUG, TAG_VCCMD, "[List] list(%p)", *vc_cmd_list);
168 return VC_ERROR_NONE;
171 int vc_cmd_list_destroy(vc_cmd_list_h vc_cmd_list, bool release_command)
173 if (0 != __vc_cmd_get_feature_enabled()) {
174 return VC_ERROR_NOT_SUPPORTED;
176 if (0 != __vc_cmd_check_privilege()) {
177 return VC_ERROR_PERMISSION_DENIED;
180 if (NULL == vc_cmd_list) {
181 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Input parameter is NULL");
182 return VC_ERROR_INVALID_PARAMETER;
185 vc_cmd_list_remove_all(vc_cmd_list, release_command);
187 vc_cmd_list_s* list = NULL;
188 list = (vc_cmd_list_s*)vc_cmd_list;
190 SLOG(LOG_DEBUG, TAG_VCCMD, "[List] list(%p)", list);
197 return VC_ERROR_NONE;
200 int vc_cmd_list_get_count(vc_cmd_list_h vc_cmd_list, int* count)
202 if (0 != __vc_cmd_get_feature_enabled()) {
203 return VC_ERROR_NOT_SUPPORTED;
205 if (0 != __vc_cmd_check_privilege()) {
206 return VC_ERROR_PERMISSION_DENIED;
209 if (NULL == vc_cmd_list || NULL == count) {
210 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Get command count : Input parameter is NULL");
211 return VC_ERROR_INVALID_PARAMETER;
214 vc_cmd_list_s* list = NULL;
215 list = (vc_cmd_list_s*)vc_cmd_list;
217 *count = g_slist_length(list->list);
219 SLOG(LOG_DEBUG, TAG_VCCMD, "[List] list(%p), count(%d)", list, *count);
221 return VC_ERROR_NONE;
224 int vc_cmd_list_add(vc_cmd_list_h vc_cmd_list, vc_cmd_h vc_command)
226 if (0 != __vc_cmd_get_feature_enabled()) {
227 return VC_ERROR_NOT_SUPPORTED;
229 if (0 != __vc_cmd_check_privilege()) {
230 return VC_ERROR_PERMISSION_DENIED;
233 if (NULL == vc_cmd_list || NULL == vc_command) {
234 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Input parameter is NULL");
235 return VC_ERROR_INVALID_PARAMETER;
238 vc_cmd_list_s* list = NULL;
239 list = (vc_cmd_list_s*)vc_cmd_list;
241 vc_cmd_s* cmd = NULL;
242 cmd = (vc_cmd_s*)vc_command;
244 list->list = g_slist_append(list->list, cmd);
246 if (1 == g_slist_length(list->list)) {
250 SLOG(LOG_DEBUG, TAG_VCCMD, "[List] list(%p), command(%p)", list, cmd);
252 return VC_ERROR_NONE;
255 int vc_cmd_list_remove(vc_cmd_list_h vc_cmd_list, vc_cmd_h vc_command)
257 if (0 != __vc_cmd_get_feature_enabled()) {
258 return VC_ERROR_NOT_SUPPORTED;
260 if (0 != __vc_cmd_check_privilege()) {
261 return VC_ERROR_PERMISSION_DENIED;
264 if (NULL == vc_cmd_list || NULL == vc_command) {
265 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Input parameter is NULL");
266 return VC_ERROR_INVALID_PARAMETER;
269 vc_cmd_list_s* list = NULL;
270 list = (vc_cmd_list_s*)vc_cmd_list;
272 vc_cmd_s* cmd = NULL;
273 cmd = (vc_cmd_s*)vc_command;
275 SLOG(LOG_DEBUG, TAG_VCCMD, "[List] list(%p), command(%p)", list, cmd);
277 vc_cmd_s* temp_cmd = NULL;
280 iter = g_slist_nth(list->list, 0);
282 while (NULL != iter) {
283 temp_cmd = iter->data;
285 if (NULL != temp_cmd && cmd == temp_cmd) {
286 list->list = g_slist_remove(list->list, temp_cmd);
288 if (true == release_command) {
289 SLOG(LOG_DEBUG, TAG_VCCMD, "Release command data");
290 if (NULL != temp_cmd->command) free(temp_cmd->command);
291 if (NULL != temp_cmd->parameter) free(temp_cmd->parameter);
298 iter = g_slist_next(iter);
301 int count = g_slist_length(list->list);
305 } else if (list->index == count) {
306 list->index = count - 1;
309 return VC_ERROR_NONE;
312 int vc_cmd_list_remove_all(vc_cmd_list_h vc_cmd_list, bool release_command)
314 if (0 != __vc_cmd_get_feature_enabled()) {
315 return VC_ERROR_NOT_SUPPORTED;
317 if (0 != __vc_cmd_check_privilege()) {
318 return VC_ERROR_PERMISSION_DENIED;
321 SLOG(LOG_DEBUG, TAG_VCCMD, "===== Destroy all command");
323 if (NULL == vc_cmd_list) {
324 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Input parameter is NULL");
325 return VC_ERROR_INVALID_PARAMETER;
328 vc_cmd_list_s* list = NULL;
329 list = (vc_cmd_list_s*)vc_cmd_list;
331 SLOG(LOG_DEBUG, TAG_VCCMD, "[List] list (%p), release command (%s)"
332 , list, release_command ? "true" : "false");
334 int count = g_slist_length(list->list);
339 for (i = 0; i < count ; i++) {
340 temp_cmd = g_slist_nth_data(list->list, 0);
342 if (NULL != temp_cmd) {
343 list->list = g_slist_remove(list->list, temp_cmd);
345 if (true == release_command) {
346 SLOG(LOG_DEBUG, TAG_VCCMD, "Free command(%p)", temp_cmd);
347 if (NULL != temp_cmd->command) free(temp_cmd->command);
348 if (NULL != temp_cmd->parameter) free(temp_cmd->parameter);
357 SLOG(LOG_DEBUG, TAG_VCCMD, "=====");
358 SLOG(LOG_DEBUG, TAG_VCCMD, " ");
360 return VC_ERROR_NONE;
363 int vc_cmd_list_foreach_commands(vc_cmd_list_h vc_cmd_list, vc_cmd_list_cb callback, void* user_data)
365 if (0 != __vc_cmd_get_feature_enabled()) {
366 return VC_ERROR_NOT_SUPPORTED;
368 if (0 != __vc_cmd_check_privilege()) {
369 return VC_ERROR_PERMISSION_DENIED;
372 if (NULL == vc_cmd_list) {
373 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Input parameter is NULL");
374 return VC_ERROR_INVALID_PARAMETER;
377 vc_cmd_list_s* list = NULL;
378 list = (vc_cmd_list_s*)vc_cmd_list;
380 int count = g_slist_length(list->list);
386 iter = g_slist_nth(list->list, 0);
388 for (i = 0; i < count; i++) {
390 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] No command in list");
391 return VC_ERROR_OPERATION_FAILED;
394 temp_cmd = iter->data;
396 if (NULL != temp_cmd) {
397 if (false == callback((vc_cmd_h)temp_cmd, user_data)) {
402 iter = g_slist_next(iter);
405 SLOG(LOG_DEBUG, TAG_VCCMD, "===== Foreach commands Done");
407 return VC_ERROR_NONE;
410 int vc_cmd_list_filter_by_type(vc_cmd_list_h original, int type, vc_cmd_list_h* filtered)
412 SLOG(LOG_DEBUG, TAG_VCCMD, "===== Filter by type");
414 if (0 != __vc_cmd_get_feature_enabled()) {
415 return VC_ERROR_NOT_SUPPORTED;
417 if (0 != __vc_cmd_check_privilege()) {
418 return VC_ERROR_PERMISSION_DENIED;
421 if (NULL == original) {
422 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Input parameter is NULL");
423 return VC_ERROR_INVALID_PARAMETER;
426 if (VC_COMMAND_TYPE_NONE >= type || VC_COMMAND_TYPE_EXCLUSIVE < type) {
427 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Invalid type");
428 return VC_ERROR_INVALID_PARAMETER;
431 vc_cmd_list_s* list = NULL;
432 list = (vc_cmd_list_s*)original;
434 vc_cmd_list_h temp_list;
435 if (0 != vc_cmd_list_create(&temp_list)) {
436 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Fail to list create");
437 return VC_ERROR_OPERATION_FAILED;
440 int count = g_slist_length(list->list);
446 iter = g_slist_nth(list->list, 0);
448 for (i = 0; i < count; i++) {
450 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] No command in list");
451 return VC_ERROR_OPERATION_FAILED;
453 if (NULL != iter->data) {
454 iter_cmd = iter->data;
456 if (NULL != iter_cmd) {
458 if (0 != vc_cmd_get_type((vc_cmd_h)iter_cmd, &iter_type)) {
459 SLOG(LOG_ERROR,TAG_VCCMD, "[ERROR] Fail to get command type");
463 if (iter_type == type) {
465 if (0 != vc_cmd_create(&temp_cmd)) {
466 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Fail to create cmd");
470 memcpy(temp_cmd, iter_cmd, sizeof(vc_cmd_s));
471 if (NULL != iter_cmd->command) {
472 ((vc_cmd_s*)temp_cmd)->command = strdup(iter_cmd->command);
474 if (NULL != iter_cmd->parameter) {
475 ((vc_cmd_s*)temp_cmd)->parameter = strdup(iter_cmd->parameter);
478 if (0 != vc_cmd_list_add(temp_list, temp_cmd)) {
479 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Fail to cmd list add");
480 vc_cmd_destroy(temp_cmd);
486 iter = g_slist_next(iter);
490 if (0 != vc_cmd_list_get_count(temp_list, &count)) {
491 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Fail to get count");
493 SLOG(LOG_DEBUG, TAG_VCCMD, "Filtering result : (%d) command", count);
496 *filtered = temp_list;
498 SLOG(LOG_DEBUG, TAG_VCCMD, "=====");
500 return VC_ERROR_NONE;
503 int vc_cmd_list_first(vc_cmd_list_h vc_cmd_list)
505 if (0 != __vc_cmd_get_feature_enabled()) {
506 return VC_ERROR_NOT_SUPPORTED;
508 if (0 != __vc_cmd_check_privilege()) {
509 return VC_ERROR_PERMISSION_DENIED;
512 if (NULL == vc_cmd_list) {
513 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Input parameter is NULL");
514 return VC_ERROR_INVALID_PARAMETER;
517 vc_cmd_list_s* list = NULL;
518 list = (vc_cmd_list_s*)vc_cmd_list;
520 if (0 == g_slist_length(list->list)) {
521 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] List is empty");
522 return VC_ERROR_EMPTY;
527 return VC_ERROR_NONE;
530 int vc_cmd_list_last(vc_cmd_list_h vc_cmd_list)
532 if (0 != __vc_cmd_get_feature_enabled()) {
533 return VC_ERROR_NOT_SUPPORTED;
535 if (0 != __vc_cmd_check_privilege()) {
536 return VC_ERROR_PERMISSION_DENIED;
539 if (NULL == vc_cmd_list) {
540 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Input parameter is NULL");
541 return VC_ERROR_INVALID_PARAMETER;
544 vc_cmd_list_s* list = NULL;
545 list = (vc_cmd_list_s*)vc_cmd_list;
547 int count = g_slist_length(list->list);
550 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] List is empty");
551 return VC_ERROR_EMPTY;
553 list->index = count - 1;
554 SLOG(LOG_DEBUG, TAG_VCCMD, "[DEBUG] List index : %d", list->index);
557 return VC_ERROR_NONE;
560 int vc_cmd_list_next(vc_cmd_list_h vc_cmd_list)
562 if (0 != __vc_cmd_get_feature_enabled()) {
563 return VC_ERROR_NOT_SUPPORTED;
565 if (0 != __vc_cmd_check_privilege()) {
566 return VC_ERROR_PERMISSION_DENIED;
569 if (NULL == vc_cmd_list) {
570 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Input parameter is NULL");
571 return VC_ERROR_INVALID_PARAMETER;
574 vc_cmd_list_s* list = NULL;
575 list = (vc_cmd_list_s*)vc_cmd_list;
577 int count = g_slist_length(list->list);
579 if (list->index < count - 1) {
580 list->index = list->index + 1;
581 SLOG(LOG_DEBUG, TAG_VCCMD, "[DEBUG] List index : %d", list->index);
583 SLOG(LOG_DEBUG, TAG_VCCMD, "[DEBUG] List index : %d", list->index);
584 return VC_ERROR_ITERATION_END;
587 return VC_ERROR_NONE;
590 int vc_cmd_list_prev(vc_cmd_list_h vc_cmd_list)
592 if (0 != __vc_cmd_get_feature_enabled()) {
593 return VC_ERROR_NOT_SUPPORTED;
595 if (0 != __vc_cmd_check_privilege()) {
596 return VC_ERROR_PERMISSION_DENIED;
599 if (NULL == vc_cmd_list) {
600 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Input parameter is NULL");
601 return VC_ERROR_INVALID_PARAMETER;
604 vc_cmd_list_s* list = NULL;
605 list = (vc_cmd_list_s*)vc_cmd_list;
607 if (list->index > 0) {
608 list->index = list->index - 1;
609 SLOG(LOG_DEBUG, TAG_VCCMD, "[DEBUG] List index : %d", list->index);
611 SLOG(LOG_DEBUG, TAG_VCCMD, "[DEBUG] List index : %d", list->index);
612 return VC_ERROR_ITERATION_END;
615 return VC_ERROR_NONE;
618 int vc_cmd_list_get_current(vc_cmd_list_h vc_cmd_list, vc_cmd_h* vc_command)
620 if (0 != __vc_cmd_get_feature_enabled()) {
621 return VC_ERROR_NOT_SUPPORTED;
623 if (0 != __vc_cmd_check_privilege()) {
624 return VC_ERROR_PERMISSION_DENIED;
627 if (NULL == vc_cmd_list || NULL == vc_command) {
628 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Input parameter is NULL");
629 return VC_ERROR_INVALID_PARAMETER;
632 vc_cmd_list_s* list = NULL;
633 list = (vc_cmd_list_s*)vc_cmd_list;
635 SLOG(LOG_DEBUG, TAG_VCCMD, "[List] list (%p), index (%d)", list, list->index);
637 if (0 == g_slist_length(list->list)) {
638 SLOG(LOG_DEBUG, TAG_VCCMD, "[List] list is empty");
640 return VC_ERROR_EMPTY;
643 vc_cmd_s *temp_cmd = NULL;
644 temp_cmd = g_slist_nth_data(list->list, list->index);
646 *vc_command = (vc_cmd_h)temp_cmd;
648 SLOG(LOG_DEBUG, TAG_VCCMD, "[List] Get current command (%p)", *vc_command);
650 return VC_ERROR_NONE;
654 int vc_cmd_create(vc_cmd_h* vc_command)
656 if (0 != __vc_cmd_get_feature_enabled()) {
657 return VC_ERROR_NOT_SUPPORTED;
659 if (0 != __vc_cmd_check_privilege()) {
660 return VC_ERROR_PERMISSION_DENIED;
663 if (NULL == vc_command) {
664 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Input parameter is NULL");
665 return VC_ERROR_INVALID_PARAMETER;
668 vc_cmd_s* command = (vc_cmd_s*)calloc(1, sizeof(vc_cmd_s));
670 if (NULL == command) {
671 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Not enough memory");
672 return VC_ERROR_OUT_OF_MEMORY;
678 command->type = VC_COMMAND_TYPE_NONE;
679 command->format = VC_CMD_FORMAT_FIXED;
680 command->command = NULL;
681 command->parameter = NULL;
683 command->key = VC_KEY_NONE;
684 command->modifier = VC_MODIFIER_NONE;
686 *vc_command = (vc_cmd_h)command;
688 SLOG(LOG_DEBUG, TAG_VCCMD, "[Create command][%p]", *vc_command);
690 return VC_ERROR_NONE;
693 int vc_cmd_destroy(vc_cmd_h vc_command)
695 if (0 != __vc_cmd_get_feature_enabled()) {
696 return VC_ERROR_NOT_SUPPORTED;
698 if (0 != __vc_cmd_check_privilege()) {
699 return VC_ERROR_PERMISSION_DENIED;
702 if (NULL == vc_command) {
703 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Input parameter is NULL");
704 return VC_ERROR_INVALID_PARAMETER;
707 vc_cmd_s* command = NULL;
708 command = (vc_cmd_s*)vc_command;
710 SLOG(LOG_DEBUG, TAG_VCCMD, "[Destroy command][%p]", command);
712 if (NULL != command) {
713 if (NULL != command->command) free(command->command);
714 if (NULL != command->parameter) free(command->parameter);
719 return VC_ERROR_NONE;
722 int vc_cmd_set_id(vc_cmd_h vc_command, int id)
724 if (0 != __vc_cmd_get_feature_enabled()) {
725 return VC_ERROR_NOT_SUPPORTED;
727 if (0 != __vc_cmd_check_privilege()) {
728 return VC_ERROR_PERMISSION_DENIED;
731 if (NULL == vc_command) {
732 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Invalid parameter ");
733 return VC_ERROR_INVALID_PARAMETER;
736 vc_cmd_s* cmd = NULL;
737 cmd = (vc_cmd_s*)vc_command;
741 SLOG(LOG_DEBUG, TAG_VCCMD, "[Set id][%p] id(%d)", vc_command, cmd->id);
747 int vc_cmd_get_id(vc_cmd_h vc_command, int* id)
749 if (0 != __vc_cmd_get_feature_enabled()) {
750 return VC_ERROR_NOT_SUPPORTED;
752 if (0 != __vc_cmd_check_privilege()) {
753 return VC_ERROR_PERMISSION_DENIED;
756 if (NULL == vc_command || NULL == id) {
757 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Invalid handle ");
758 return VC_ERROR_INVALID_PARAMETER;
761 vc_cmd_s* cmd = NULL;
762 cmd = (vc_cmd_s*)vc_command;
766 SLOG(LOG_DEBUG, TAG_VCCMD, "[Get id][%p] id(%d)", vc_command, *id);
772 int vc_cmd_set_command(vc_cmd_h vc_command, const char* command)
774 if (0 != __vc_cmd_get_feature_enabled()) {
775 return VC_ERROR_NOT_SUPPORTED;
777 if (0 != __vc_cmd_check_privilege()) {
778 return VC_ERROR_PERMISSION_DENIED;
781 if (NULL == vc_command) {
782 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Invalid parameter ");
783 return VC_ERROR_INVALID_PARAMETER;
786 vc_cmd_s* cmd = NULL;
787 cmd = (vc_cmd_s*)vc_command;
789 if (NULL != cmd->command) {
795 if (NULL != command) {
796 cmd->command = strdup(command);
799 SLOG(LOG_DEBUG, TAG_VCCMD, "[Set command][%p] Command(%s)", vc_command, cmd->command);
804 int vc_cmd_get_command(vc_cmd_h vc_command, char** command)
806 if (0 != __vc_cmd_get_feature_enabled()) {
807 return VC_ERROR_NOT_SUPPORTED;
809 if (0 != __vc_cmd_check_privilege()) {
810 return VC_ERROR_PERMISSION_DENIED;
813 if (NULL == vc_command || NULL == command) {
814 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Invalid handle ");
815 return VC_ERROR_INVALID_PARAMETER;
818 vc_cmd_s* cmd = NULL;
819 cmd = (vc_cmd_s*)vc_command;
821 if (NULL != cmd->command) {
822 *command = strdup(gettext(cmd->command));
825 SLOG(LOG_DEBUG, TAG_VCCMD, "[Get command][%p] Command(%s)", vc_command, *command);
830 int vc_cmd_set_unfixed_command(vc_cmd_h vc_command, const char* command)
832 if (0 != __vc_cmd_get_feature_enabled()) {
833 return VC_ERROR_NOT_SUPPORTED;
835 if (0 != __vc_cmd_check_privilege()) {
836 return VC_ERROR_PERMISSION_DENIED;
839 if (NULL == vc_command) {
840 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Invalid parameter ");
841 return VC_ERROR_INVALID_PARAMETER;
844 vc_cmd_s* cmd = NULL;
845 cmd = (vc_cmd_s*)vc_command;
847 if (NULL != cmd->parameter) {
848 free(cmd->parameter);
851 cmd->parameter = NULL;
853 if (NULL != command) {
854 cmd->parameter = strdup(command);
855 SLOG(LOG_DEBUG, TAG_VCCMD, "[Set parameter][%p] parameter(%s)", vc_command, cmd->parameter);
861 int vc_cmd_get_unfixed_command(vc_cmd_h vc_command, char** command)
863 if (0 != __vc_cmd_get_feature_enabled()) {
864 return VC_ERROR_NOT_SUPPORTED;
866 if (0 != __vc_cmd_check_privilege()) {
867 return VC_ERROR_PERMISSION_DENIED;
870 if (NULL == vc_command || NULL == command) {
871 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Invalid handle ");
872 return VC_ERROR_INVALID_PARAMETER;
875 vc_cmd_s* cmd = NULL;
876 cmd = (vc_cmd_s*)vc_command;
878 if (NULL != cmd->parameter) {
879 *command = strdup(gettext(cmd->parameter));
880 SLOG(LOG_DEBUG, TAG_VCCMD, "[Get nonfixed command][%p] nonfixed command(%s)", vc_command, *command);
886 int vc_cmd_set_type(vc_cmd_h vc_command, int type)
888 if (0 != __vc_cmd_get_feature_enabled()) {
889 return VC_ERROR_NOT_SUPPORTED;
891 if (0 != __vc_cmd_check_privilege()) {
892 return VC_ERROR_PERMISSION_DENIED;
895 if (NULL == vc_command) {
896 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Invalid parameter ");
897 return VC_ERROR_INVALID_PARAMETER;
900 vc_cmd_s* cmd = NULL;
901 cmd = (vc_cmd_s*)vc_command;
905 SLOG(LOG_DEBUG, TAG_VCCMD, "[Set type][%p] type(%d)", vc_command, cmd->type);
910 int vc_cmd_get_type(vc_cmd_h vc_command, int* type)
912 if (0 != __vc_cmd_get_feature_enabled()) {
913 return VC_ERROR_NOT_SUPPORTED;
915 if (0 != __vc_cmd_check_privilege()) {
916 return VC_ERROR_PERMISSION_DENIED;
919 if (NULL == vc_command || NULL == type) {
920 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Invalid parameter ");
921 return VC_ERROR_INVALID_PARAMETER;
924 vc_cmd_s* cmd = NULL;
925 cmd = (vc_cmd_s*)vc_command;
929 SLOG(LOG_DEBUG, TAG_VCCMD, "[Get type][%p] type(%d)", vc_command, *type);
934 int vc_cmd_set_format(vc_cmd_h vc_command, vc_cmd_format_e format)
936 if (0 != __vc_cmd_get_feature_enabled()) {
937 return VC_ERROR_NOT_SUPPORTED;
939 if (0 != __vc_cmd_check_privilege()) {
940 return VC_ERROR_PERMISSION_DENIED;
943 if (NULL == vc_command) {
944 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Invalid parameter ");
945 return VC_ERROR_INVALID_PARAMETER;
948 vc_cmd_s* cmd = NULL;
949 cmd = (vc_cmd_s*)vc_command;
951 cmd->format = format;
953 SLOG(LOG_DEBUG, TAG_VCCMD, "[Set format][%p] format(%d)", vc_command, format);
958 int vc_cmd_get_format(vc_cmd_h vc_command, vc_cmd_format_e* format)
960 if (0 != __vc_cmd_get_feature_enabled()) {
961 return VC_ERROR_NOT_SUPPORTED;
963 if (0 != __vc_cmd_check_privilege()) {
964 return VC_ERROR_PERMISSION_DENIED;
967 if (NULL == vc_command || NULL == format) {
968 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Invalid parameter ");
969 return VC_ERROR_INVALID_PARAMETER;
972 vc_cmd_s* cmd = NULL;
973 cmd = (vc_cmd_s*)vc_command;
975 *format = cmd->format;
977 SLOG(LOG_DEBUG, TAG_VCCMD, "[Get format][%p] format(%d)", vc_command, *format);
982 int vc_cmd_set_pid(vc_cmd_h vc_command, int pid)
984 if (0 != __vc_cmd_get_feature_enabled()) {
985 return VC_ERROR_NOT_SUPPORTED;
987 if (0 != __vc_cmd_check_privilege()) {
988 return VC_ERROR_PERMISSION_DENIED;
991 if (NULL == vc_command) {
992 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Invalid parameter ");
993 return VC_ERROR_INVALID_PARAMETER;
996 vc_cmd_s* cmd = NULL;
997 cmd = (vc_cmd_s*)vc_command;
1001 SLOG(LOG_DEBUG, TAG_VCCMD, "[Set pid][%p] pid(%d)", vc_command, cmd->pid);
1006 int vc_cmd_get_pid(vc_cmd_h vc_command, int* pid)
1008 if (0 != __vc_cmd_get_feature_enabled()) {
1009 return VC_ERROR_NOT_SUPPORTED;
1011 if (0 != __vc_cmd_check_privilege()) {
1012 return VC_ERROR_PERMISSION_DENIED;
1015 if (NULL == vc_command || NULL == pid) {
1016 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Invalid parameter ");
1017 return VC_ERROR_INVALID_PARAMETER;
1020 vc_cmd_s* cmd = NULL;
1021 cmd = (vc_cmd_s*)vc_command;
1025 SLOG(LOG_DEBUG, TAG_VCCMD, "[Get pid][%p] pid(%d)", vc_command, *pid);
1030 int vc_cmd_set_domain(vc_cmd_h vc_command, int domain)
1032 if (0 != __vc_cmd_get_feature_enabled()) {
1033 return VC_ERROR_NOT_SUPPORTED;
1035 if (0 != __vc_cmd_check_privilege()) {
1036 return VC_ERROR_PERMISSION_DENIED;
1039 if (NULL == vc_command) {
1040 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Invalid parameter ");
1041 return VC_ERROR_INVALID_PARAMETER;
1044 vc_cmd_s* cmd = NULL;
1045 cmd = (vc_cmd_s*)vc_command;
1047 cmd->domain = domain;
1049 SLOG(LOG_DEBUG, TAG_VCCMD, "[Set domain] domain : %d", domain);
1054 int vc_cmd_get_domain(vc_cmd_h vc_command, int* domain)
1056 if (0 != __vc_cmd_get_feature_enabled()) {
1057 return VC_ERROR_NOT_SUPPORTED;
1059 if (0 != __vc_cmd_check_privilege()) {
1060 return VC_ERROR_PERMISSION_DENIED;
1063 if (NULL == vc_command || NULL == domain) {
1064 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Invalid parameter ");
1065 return VC_ERROR_INVALID_PARAMETER;
1068 vc_cmd_s* cmd = NULL;
1069 cmd = (vc_cmd_s*)vc_command;
1071 *domain = cmd->domain;
1073 SLOG(LOG_DEBUG, TAG_VCCMD, "[Get domain] domain : %d", *domain);
1079 * @brief Sets key value of command.
1081 * @param[in] vc_command Command handle
1082 * @param[in] key key value
1083 * @param[in] modifier modifier value
1085 * @return 0 on success, otherwise a negative error value
1086 * @retval #VC_ERROR_NONE Successful
1087 * @retval #VC_ERROR_INVALID_PARAMETER Invalid parameter
1089 * @see vc_cmd_get_result_key()
1091 int vc_cmd_set_result_key(vc_cmd_h vc_command, int key, int modifier)
1093 SLOG(LOG_DEBUG, TAG_VCCMD, "===== Set result key");
1095 if (NULL == vc_command) {
1096 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Invalid parameter ");
1097 return VC_ERROR_INVALID_PARAMETER;
1100 vc_cmd_s* cmd = NULL;
1101 cmd = (vc_cmd_s*)vc_command;
1103 SLOG(LOG_DEBUG, TAG_VCCMD, "key : %d, modifier : %d", key, modifier);
1106 cmd->modifier = modifier;
1108 SLOG(LOG_DEBUG, TAG_VCCMD, "=====");
1109 SLOG(LOG_DEBUG, TAG_VCCMD, " ");
1115 * @brief Gets key value of command.
1117 * @param[in] vc_command Command handle
1118 * @param[out] key key value
1119 * @param[out] modifier modifier value
1121 * @return 0 on success, otherwise a negative error value
1122 * @retval #VC_ERROR_NONE Successful
1123 * @retval #VC_ERROR_INVALID_PARAMETER Invalid parameter
1125 * @see vc_cmd_add_result_key()
1127 int vc_cmd_get_result_key(vc_cmd_h vc_command, int* key, int* modifier)
1129 SLOG(LOG_DEBUG, TAG_VCCMD, "===== Get result key");
1131 if (NULL == vc_command || NULL == key || NULL == modifier) {
1132 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Invalid parameter ");
1133 return VC_ERROR_INVALID_PARAMETER;
1136 vc_cmd_s* cmd = NULL;
1137 cmd = (vc_cmd_s*)vc_command;
1140 *modifier = cmd->modifier;
1142 SLOG(LOG_DEBUG, TAG_VCCMD, "=====");
1143 SLOG(LOG_DEBUG, TAG_VCCMD, " ");
1148 int vc_cmd_print_list(vc_cmd_list_h vc_cmd_list)
1150 if (NULL == vc_cmd_list) {
1154 vc_cmd_list_s* list = NULL;
1155 list = (vc_cmd_list_s*)vc_cmd_list;
1157 SLOG(LOG_DEBUG, TAG_VCCMD, "=== Command List ===");
1158 SLOG(LOG_DEBUG, TAG_VCCMD, "[List][%p]", list);
1160 int count = g_slist_length(list->list);
1163 vc_cmd_s *temp_cmd = NULL;
1165 for (i = 0; i < count ; i++) {
1166 temp_cmd = g_slist_nth_data(list->list, i);
1168 if (NULL != temp_cmd) {
1169 SLOG(LOG_DEBUG, TAG_VCCMD, " [%d][%p] PID(%d) ID(%d) Type(%d) Format(%d) Domain(%d) Command(%s) Param(%s)",
1170 i, temp_cmd, temp_cmd->pid, temp_cmd->index, temp_cmd->type, temp_cmd->format, temp_cmd->domain, temp_cmd->command, temp_cmd->parameter);
1174 SLOG(LOG_DEBUG, TAG_VCCMD, "==================");
1175 SLOG(LOG_DEBUG, TAG_VCCMD, " ");