4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Jonghyuk Choi <jhchoi.choi@samsung.com>
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
29 #include "mm_attrs_private.h"
32 int mm_attrs_new(MMAttrsConstructInfo *info, int count, const char *name,
33 mm_attrs_commit_callback callback, void *user_param, MMHandleType *attrs)
37 return_val_if_fail(attrs, MM_ERROR_COMMON_INVALID_ARGUMENT);
39 _attrs = mmf_attrs_new_from_data(name, (mmf_attrs_construct_info_t *) info, count, (mmf_attrs_commit_func_t) callback, user_param);
41 return MM_ERROR_COMMON_INTERNAL;
49 void mm_attrs_free(MMHandleType attrs)
51 mmf_attrs_free(attrs);
55 int mm_attrs_commit_all(MMHandleType attrs)
57 return mmf_attrs_commit_all(attrs);
60 int mm_attrs_commit(MMHandleType attrs, int index)
62 return mmf_attrs_commit(attrs, index, NULL);
65 int mm_attrs_get_type(MMHandleType attrs, int index, MMAttrsType *attrtype)
67 mmf_attrs_t *h = (mmf_attrs_t *) attrs;
69 return_val_if_fail(h && index >= 0 && index < h->count && attrtype, MM_ERROR_COMMON_INVALID_ARGUMENT);
71 *attrtype = h->items[index].value.type;
76 int mm_attrs_get_flags(MMHandleType attrs, int index, int *flags)
78 mmf_attrs_t *h = (mmf_attrs_t *) attrs;
80 return_val_if_fail(h && index >= 0 && index < h->count && flags, MM_ERROR_COMMON_INVALID_ARGUMENT);
82 *flags = h->items[index].flags;
87 int mm_attrs_get_valid_type(MMHandleType attrs, int index, MMAttrsValidType *type)
89 mmf_attrs_t *h = (mmf_attrs_t *) attrs;
91 return_val_if_fail(h && index >= 0 && index < h->count && type, MM_ERROR_COMMON_INVALID_ARGUMENT);
93 *type = h->items[index].value_spec.type;
98 int mm_attrs_get_valid_range(MMHandleType attrs, int index, int *min, int *max)
100 mmf_attrs_t *h = (mmf_attrs_t *) attrs;
102 return_val_if_fail(h && index >= 0 && index < h->count && min && max, MM_ERROR_COMMON_INVALID_ARGUMENT);
105 *min = h->items[index].value_spec.spec.int_spec.range.min;
108 *max = h->items[index].value_spec.spec.int_spec.range.max;
110 return MM_ERROR_NONE;
114 int mm_attrs_get_valid_array(MMHandleType attrs, int index, int *count, int **array)
116 mmf_attrs_t *h = (mmf_attrs_t *) attrs;
121 return_val_if_fail(h && count && index >= 0 && index < h->count && array, MM_ERROR_COMMON_INVALID_ARGUMENT);
124 *count = h->items[index].value_spec.spec.int_spec.array.count;
125 *array = h->items[index].value_spec.spec.int_spec.array.array;
126 return MM_ERROR_NONE;
130 int mm_attrs_get_size(MMHandleType attrs, int *size)
132 mmf_attrs_t *h = (mmf_attrs_t *) attrs;
134 return_val_if_fail(h && size, MM_ERROR_COMMON_INVALID_ARGUMENT);
137 return MM_ERROR_NONE;
141 int mm_attrs_get_name(MMHandleType attrs, int index, char **name)
143 mmf_attrs_t *h = (mmf_attrs_t *) attrs;
145 return_val_if_fail(h && index >= 0 && index < h->count && name, MM_ERROR_COMMON_INVALID_ARGUMENT);
147 *name = h->items[index].name;
148 return MM_ERROR_NONE;
152 int mm_attrs_get_index(MMHandleType attrs, const char *attrname, int *index)
154 mmf_attrs_t *h = (mmf_attrs_t *) attrs;
157 return_val_if_fail(h && attrname && index, MM_ERROR_COMMON_INVALID_ARGUMENT);
159 for (i = 0; i < h->count; i++) {
160 if (0 == strcmp(h->items[i].name, attrname)) {
162 return MM_ERROR_NONE;
166 debug_error("failed to get index for [%s]", attrname);
168 return MM_ERROR_COMMON_OUT_OF_ARRAY;
172 int mm_attrs_set_int(MMHandleType attrs, int index, int val)
174 mmf_attrs_t *h = (mmf_attrs_t *) attrs;
175 mmf_attribute_t *item;
177 return_val_if_fail(h && index >= 0 && index < h->count, MM_ERROR_COMMON_INVALID_ARGUMENT);
179 item = &h->items[index];
180 return_val_if_fail(item, MM_ERROR_COMMON_INVALID_ARGUMENT);
182 if (!mmf_attribute_check_flags(item, MM_ATTRS_FLAG_WRITABLE)) {
183 return MM_ERROR_COMMON_INVALID_PERMISSION;
186 if (mmf_attribute_validate_int(item, val)) {
188 ret = mmf_attribute_set_int(item, val);
191 return MM_ERROR_NONE;
193 return MM_ERROR_COMMON_INVALID_ATTRTYPE;
196 if (item->value_spec.type == MMF_VALUE_SPEC_INT_RANGE)
197 return MM_ERROR_COMMON_OUT_OF_RANGE;
198 else if (item->value_spec.type == MMF_VALUE_SPEC_INT_ARRAY)
199 return MM_ERROR_COMMON_OUT_OF_ARRAY;
201 return MM_ERROR_COMMON_INVALID_ARGUMENT;
205 int mm_attrs_get_int(MMHandleType attrs, int index, int *val)
207 mmf_attrs_t *h = (mmf_attrs_t *) attrs;
208 mmf_attribute_t *item;
210 return_val_if_fail(h && index >= 0 && index < h->count && val, MM_ERROR_COMMON_INVALID_ARGUMENT);
212 item = &h->items[index];
213 return_val_if_fail(item, MM_ERROR_COMMON_INVALID_ARGUMENT);
215 if (mmf_attribute_check_flags(item, MM_ATTRS_FLAG_READABLE)) {
216 *val = mmf_value_get_int(&h->items[index].value);
217 return MM_ERROR_NONE;
220 return MM_ERROR_COMMON_INVALID_PERMISSION;
224 int mm_attrs_set_double(MMHandleType attrs, int index, double val)
226 mmf_attrs_t *h = (mmf_attrs_t *) attrs;
227 mmf_attribute_t *item;
229 return_val_if_fail(h && index >= 0 && index < h->count, MM_ERROR_COMMON_INVALID_ARGUMENT);
231 item = &h->items[index];
232 return_val_if_fail(item, MM_ERROR_COMMON_INVALID_ARGUMENT);
234 if (!mmf_attribute_check_flags(item, MM_ATTRS_FLAG_WRITABLE))
235 return MM_ERROR_COMMON_INVALID_PERMISSION;
237 if (mmf_attribute_validate_double(item, val)) {
239 ret = mmf_attribute_set_double(item, val);
242 return MM_ERROR_NONE;
244 return MM_ERROR_COMMON_INVALID_ATTRTYPE;
247 if (item->value_spec.type == MMF_VALUE_SPEC_DOUBLE_RANGE)
248 return MM_ERROR_COMMON_OUT_OF_RANGE;
249 else if (item->value_spec.type == MMF_VALUE_SPEC_DOUBLE_ARRAY)
250 return MM_ERROR_COMMON_OUT_OF_ARRAY;
252 return MM_ERROR_COMMON_INVALID_ARGUMENT;
256 int mm_attrs_get_double(MMHandleType attrs, int index, double *val)
258 mmf_attrs_t *h = (mmf_attrs_t *) attrs;
259 mmf_attribute_t *item;
261 return_val_if_fail(h && index >= 0 && index < h->count && val, MM_ERROR_COMMON_INVALID_ARGUMENT);
263 item = &h->items[index];
264 return_val_if_fail(item, MM_ERROR_COMMON_INVALID_ARGUMENT);
266 if (mmf_attribute_check_flags(item, MM_ATTRS_FLAG_READABLE)) {
267 *val = mmf_value_get_double(&h->items[index].value);
268 return MM_ERROR_NONE;
271 return MM_ERROR_COMMON_INVALID_PERMISSION;
275 int mm_attrs_set_string(MMHandleType attrs, int index, const char *string, int size)
277 mmf_attrs_t *h = (mmf_attrs_t *) attrs;
278 mmf_attribute_t *item;
280 return_val_if_fail(h && index >= 0 && index < h->count, MM_ERROR_COMMON_INVALID_ARGUMENT);
282 item = &h->items[index];
283 return_val_if_fail(item, MM_ERROR_COMMON_INVALID_ARGUMENT);
285 MM_ATTR_ITEM_WRITE_LOCK(item);
287 if (mmf_attribute_check_flags(item, MM_ATTRS_FLAG_WRITABLE)) {
289 ret = mmf_attribute_set_string(item, string, size);
291 MM_ATTR_ITEM_WRITE_UNLOCK(item);
294 return MM_ERROR_NONE;
296 return MM_ERROR_COMMON_INVALID_ARGUMENT;
299 MM_ATTR_ITEM_WRITE_UNLOCK(item);
301 return MM_ERROR_COMMON_INVALID_PERMISSION;
305 int mm_attrs_get_string(MMHandleType attrs, int index, char **sval, int *size)
307 mmf_attrs_t *h = (mmf_attrs_t *) attrs;
308 mmf_attribute_t *item;
310 return_val_if_fail(h && index >= 0 && index < h->count && sval, MM_ERROR_COMMON_INVALID_ARGUMENT);
312 item = &h->items[index];
314 MM_ATTR_ITEM_WRITE_LOCK(item);
316 if (!(item->flags & MM_ATTRS_FLAG_READABLE)) {
317 //mmf_debug(MMF_DEBUG_LOG, "Access denied.\n");
318 MM_ATTR_ITEM_WRITE_UNLOCK(item);
319 return MM_ERROR_COMMON_INVALID_PERMISSION;
322 *sval = mmf_value_get_string(&item->value, size);
324 MM_ATTR_ITEM_WRITE_UNLOCK(item);
326 return MM_ERROR_NONE;
330 int mm_attrs_set_data(MMHandleType attrs, int index, void *data, int size)
332 mmf_attrs_t *h = (mmf_attrs_t *) attrs;
333 mmf_attribute_t *item;
335 return_val_if_fail(h && index >= 0 && index < h->count, MM_ERROR_COMMON_INVALID_ARGUMENT);
337 item = &h->items[index];
338 return_val_if_fail(item, MM_ERROR_COMMON_INVALID_ARGUMENT);
340 if (mmf_attribute_check_flags(item, MM_ATTRS_FLAG_WRITABLE)) {
342 ret = mmf_attribute_set_data(item, data, size);
345 return MM_ERROR_NONE;
347 return MM_ERROR_COMMON_INVALID_ARGUMENT;
350 return MM_ERROR_COMMON_INVALID_ARGUMENT;
354 int mm_attrs_get_data(MMHandleType attrs, int index, void **data, int *size)
356 mmf_attrs_t *h = (mmf_attrs_t *) attrs;
358 return_val_if_fail(h && index >= 0 && index < h->count && data, MM_ERROR_COMMON_INVALID_ARGUMENT);
360 if (!(h->items[index].flags & MM_ATTRS_FLAG_READABLE)) {
361 //mmf_debug(MMF_DEBUG_LOG, "Access denied.\n");
362 return MM_ERROR_COMMON_INVALID_PERMISSION;
364 *data = mmf_value_get_data(&h->items[index].value, size);
365 return MM_ERROR_NONE;
369 int mm_attrs_set_int_by_name(MMHandleType attrs, const char *name, int val)
373 return_val_if_fail(attrs && name, -1);
375 mm_attrs_get_index(attrs, name, &index);
377 return mm_attrs_set_int(attrs, index, val);
383 int mm_attrs_get_int_by_name(MMHandleType attrs, const char *name, int *val)
387 return_val_if_fail(attrs && name && val, MM_ERROR_COMMON_INVALID_ARGUMENT);
389 mm_attrs_get_index(attrs, name, &index);
391 return mm_attrs_get_int(attrs, index, val);
393 return MM_ERROR_COMMON_INVALID_ATTRTYPE;
397 int mm_attrs_set_string_by_name(MMHandleType attrs, const char *name, const char *string)
402 return_val_if_fail(attrs && name, -1);
404 mm_attrs_get_index(attrs, name, &index);
407 size = strlen(string);
413 return mm_attrs_set_string(attrs, index, string, size);
419 int mm_attrs_get_string_by_name(MMHandleType attrs, const char *name, char **string)
424 return_val_if_fail(attrs && name && string, MM_ERROR_COMMON_INVALID_ARGUMENT);
426 mm_attrs_get_index(attrs, name, &index);
428 return mm_attrs_get_string(attrs, index, string, &len);
430 return MM_ERROR_COMMON_INVALID_ATTRTYPE;
434 int mm_attrs_set_data_by_name(MMHandleType attrs, const char *name, void *data, int size)
438 return_val_if_fail(attrs && name, -1);
440 mm_attrs_get_index(attrs, name, &index);
442 return mm_attrs_set_data(attrs, index, data, size);
448 int mm_attrs_get_data_by_name(MMHandleType attrs, const char *name, void **data)
453 return_val_if_fail(attrs && name, MM_ERROR_COMMON_INVALID_ARGUMENT);
455 mm_attrs_get_index(attrs, name, &index);
457 return mm_attrs_get_data(attrs, index, data, &len);
459 return MM_ERROR_COMMON_INVALID_ATTRTYPE;
463 int mm_attrs_set_double_by_name(MMHandleType attrs, const char *name, double val)
467 return_val_if_fail(attrs && name, MM_ERROR_COMMON_INVALID_ARGUMENT);
469 mm_attrs_get_index(attrs, name, &index);
471 return mm_attrs_set_double(attrs, index, val);
473 return MM_ERROR_COMMON_INVALID_ATTRTYPE;
477 int mm_attrs_get_double_by_name(MMHandleType attrs, const char *name, double *val)
481 return_val_if_fail(attrs && name && val, MM_ERROR_COMMON_INVALID_ARGUMENT);
483 mm_attrs_get_index(attrs, name, &index);
485 *val = mm_attrs_get_double(attrs, index, val);
488 return MM_ERROR_COMMON_INVALID_ATTRTYPE;
492 int mm_attrs_set_valist(MMHandleType attrs, char **err_attr_name, const char *attribute_name, va_list var_args)
494 const char *name = NULL;
495 int ret = MM_ERROR_NONE;
497 return_val_if_fail(attrs, MM_ERROR_COMMON_INVALID_ARGUMENT);
498 // return_val_if_fail(err_attr_name, MM_ERROR_COMMON_INVALID_ARGUMENT);
499 return_val_if_fail(attribute_name, MM_ERROR_COMMON_INVALID_ARGUMENT);
502 *err_attr_name = NULL;
503 name = attribute_name;
507 MMAttrsType attr_type = MM_ATTRS_TYPE_INVALID;
510 if ((ret = mm_attrs_get_index(attrs, name, &index)) != MM_ERROR_NONE) {
513 *err_attr_name = strdup(name);
515 if (ret == (int)MM_ERROR_COMMON_OUT_OF_ARRAY) { //to avoid confusing
516 //mmf_debug(MMF_DEBUG_ERROR, "result of mm_attrs_get_index is MM_ERROR_COMMON_OUT_OF_ARRAY so return(ret = %x, name:%s)",ret, name);
517 return MM_ERROR_COMMON_ATTR_NOT_EXIST;
519 //mmf_debug(MMF_DEBUG_ERROR, "result of mm_attrs_get_index is %x so return(name:%s)",ret, name);
525 if ((ret = mm_attrs_get_type(attrs, index, &attr_type)) != MM_ERROR_NONE)
530 case MM_ATTRS_TYPE_INT:
532 int val = va_arg((var_args), int);
533 // mmf_debug(MMF_DEBUG_LOG, "(%s: %d)\n", name, val);
534 ret = mm_attrs_set_int(attrs, index, val);
537 case MM_ATTRS_TYPE_DOUBLE:
539 double val = va_arg((var_args), double);
540 // mmf_debug(MMF_DEBUG_LOG, "(%s: %f)\n", name, val);
541 ret = mm_attrs_set_double(attrs, index, val);
544 case MM_ATTRS_TYPE_STRING:
546 char * val = va_arg((var_args), char*);
547 int size = va_arg((var_args), int);
548 // mmf_debug(MMF_DEBUG_LOG, "(%s: \'%s\', size: %d)\n", name, val, size);
549 ret = mm_attrs_set_string(attrs, index, (const char*)val, size);
552 case MM_ATTRS_TYPE_DATA:
554 void * val = va_arg((var_args), void*);
555 int size = va_arg((var_args), int);
556 // mmf_debug(MMF_DEBUG_LOG, "(%s: %p, size: %d)\n", name, val, size);
557 ret = mm_attrs_set_data(attrs, index, val, size);
560 case MM_ATTRS_TYPE_INVALID:
562 //mmf_debug(MMF_DEBUG_ERROR, "This function doesn't support attribute type(%d, name:%s)\n", attr_type, name);
563 return MM_ERROR_COMMON_INVALID_ARGUMENT;
567 if (ret != MM_ERROR_NONE) {
569 *err_attr_name = strdup(name);
570 //mmf_debug(MMF_DEBUG_ERROR, "Setting failure.(name:%s)\n", name);
575 name = va_arg(var_args, char*);
578 if (mmf_attrs_commit_err(attrs, err_attr_name) == -1) {
579 //mmf_debug(MMF_DEBUG_ERROR, "result of mmf_attrs_commit_err is -1 (name:%s)", name);
580 return MM_ERROR_COMMON_UNKNOWN;
582 return MM_ERROR_NONE;
589 int mm_attrs_get_valist(MMHandleType attrs, char **err_attr_name, const char *attribute_name, va_list var_args)
591 const char *name = NULL;
592 int ret = MM_ERROR_NONE;
594 return_val_if_fail(attrs, MM_ERROR_COMMON_INVALID_ARGUMENT);
595 // return_val_if_fail(err_attr_name, MM_ERROR_COMMON_INVALID_ARGUMENT);
596 return_val_if_fail(attribute_name, MM_ERROR_COMMON_INVALID_ARGUMENT);
599 *err_attr_name = NULL;
600 name = attribute_name;
604 MMAttrsType attr_type = MM_ATTRS_TYPE_INVALID;
607 if ((ret = mm_attrs_get_index(attrs, name, &index)) != MM_ERROR_NONE) {
609 *err_attr_name = strdup(name);
611 if (ret == (int)MM_ERROR_COMMON_OUT_OF_ARRAY) //to avoid confusing
612 return MM_ERROR_COMMON_ATTR_NOT_EXIST;
618 if ((ret = mm_attrs_get_type(attrs, index, &attr_type)) != MM_ERROR_NONE)
623 case MM_ATTRS_TYPE_INT:
625 int * val = va_arg((var_args), int*);
626 // mmf_debug(MMF_DEBUG_LOG, "(%s: %p)\n", name, val);
627 ret = mm_attrs_get_int(attrs, index, val);
630 case MM_ATTRS_TYPE_DOUBLE:
632 double * val = va_arg((var_args), double*);
633 // mmf_debug(MMF_DEBUG_LOG, "(%s: %p)\n", name, val);
634 ret = mm_attrs_get_double(attrs, index, val);
637 case MM_ATTRS_TYPE_STRING:
639 char ** val = va_arg((var_args), char**);
640 int * size = va_arg((var_args), int*);
641 // mmf_debug(MMF_DEBUG_LOG, "(%s: %p, size: %p)\n", name, val, size);
642 ret = mm_attrs_get_string(attrs, index, (char**)val, size);
645 case MM_ATTRS_TYPE_DATA:
647 void ** val = va_arg((var_args), void**);
648 int * size = va_arg((var_args), int*);
649 // mmf_debug(MMF_DEBUG_LOG, "(%s: %p, size: %p)\n", name, val, size);
650 ret = mm_attrs_get_data(attrs, index, val, size);
653 case MM_ATTRS_TYPE_INVALID:
655 // mmf_debug(MMF_DEBUG_ERROR, "This function doesn't support attribute type(%d, name:%s)\n", attr_type, name);
657 // *err_attr_name = strdup(name);
658 ret = MM_ERROR_COMMON_INVALID_ARGUMENT;
662 if (ret != MM_ERROR_NONE) {
664 *err_attr_name = strdup(name);
665 //mmf_debug(MMF_DEBUG_ERROR, "Setting failure.(name:%s)\n", name);
670 name = va_arg(var_args, char*);
677 int mm_attrs_multiple_set(MMHandleType attrs, char **err_attr_name, const char *attribute_name, ...)
680 int ret = MM_ERROR_NONE;
682 return_val_if_fail(attribute_name, MM_ERROR_COMMON_INVALID_ARGUMENT);
684 va_start(var_args, attribute_name);
685 ret = mm_attrs_set_valist(attrs, err_attr_name, attribute_name, var_args);
692 int mm_attrs_multiple_get(MMHandleType attrs, char **err_attr_name, const char *attribute_name, ...)
695 int ret = MM_ERROR_NONE;
697 return_val_if_fail(attribute_name, MM_ERROR_COMMON_INVALID_ARGUMENT);
699 va_start(var_args, attribute_name);
700 ret = mm_attrs_get_valist(attrs, err_attr_name, attribute_name, var_args);
707 int mm_attrs_get_info(MMHandleType attrs, int index, MMAttrsInfo *info)
709 mmf_attrs_t *h = (mmf_attrs_t *) attrs;
711 return_val_if_fail(attrs, MM_ERROR_COMMON_INVALID_ARGUMENT);
712 return_val_if_fail(info, MM_ERROR_COMMON_INVALID_ARGUMENT);
713 return_val_if_fail(0 <= index && index < h->count, MM_ERROR_COMMON_INVALID_ARGUMENT);
715 memset(info, 0x00, sizeof(MMAttrsInfo));
717 info->type = h->items[index].value.type;
718 info->flag = h->items[index].flags;
719 info->validity_type = h->items[index].value_spec.type;
721 switch (info->validity_type) {
722 case MM_ATTRS_VALID_TYPE_INT_ARRAY:
723 info->int_array.array = h->items[index].value_spec.spec.int_spec.array.array;
724 info->int_array.count = h->items[index].value_spec.spec.int_spec.array.count;
725 info->int_array.dval = h->items[index].value_spec.spec.int_spec.array.dval;
727 case MM_ATTRS_VALID_TYPE_INT_RANGE:
728 info->int_range.min = h->items[index].value_spec.spec.int_spec.range.min;
729 info->int_range.max = h->items[index].value_spec.spec.int_spec.range.max;
730 info->int_range.dval = h->items[index].value_spec.spec.int_spec.range.dval;
732 case MM_ATTRS_VALID_TYPE_DOUBLE_ARRAY:
733 info->double_array.array = h->items[index].value_spec.spec.double_spec.array.array;
734 info->double_array.count = h->items[index].value_spec.spec.double_spec.array.count;
735 info->double_array.dval = h->items[index].value_spec.spec.double_spec.array.dval;
737 case MM_ATTRS_VALID_TYPE_DOUBLE_RANGE:
738 info->double_range.min = h->items[index].value_spec.spec.double_spec.range.min;
739 info->double_range.max = h->items[index].value_spec.spec.double_spec.range.max;
740 info->double_range.dval = h->items[index].value_spec.spec.double_spec.range.dval;
742 case MM_ATTRS_VALID_TYPE_NONE:
743 //mmf_debug(MMF_DEBUG_LOG, "Valid type none.\n");
745 case MM_ATTRS_VALID_TYPE_INVALID:
750 return MM_ERROR_NONE;
754 int mm_attrs_get_info_by_name(MMHandleType attrs, const char *attr_name, MMAttrsInfo *info)
757 int ret = MM_ERROR_NONE;
759 return_val_if_fail(attrs, MM_ERROR_COMMON_INVALID_ARGUMENT);
760 return_val_if_fail(info, MM_ERROR_COMMON_INVALID_ARGUMENT);
762 //mmf_debug(MMF_DEBUG_LOG, "(attr_name:%s)\n", attr_name);
764 mm_attrs_get_index(attrs, attr_name, &index);
766 return_val_if_fail(index >= 0, MM_ERROR_COMMON_INVALID_ARGUMENT);
768 ret = mm_attrs_get_info(attrs, index, info);
774 int mm_attrs_set_valid_type(MMHandleType attrs, int index, MMAttrsValidType type)
776 return_val_if_fail(type > MM_ATTRS_VALID_TYPE_INVALID, MM_ERROR_COMMON_INVALID_ARGUMENT);
777 return_val_if_fail(type <= MM_ATTRS_VALID_TYPE_DOUBLE_RANGE, MM_ERROR_COMMON_INVALID_ARGUMENT);
779 return mmf_attrs_set_valid_type(attrs, index, (int)type);
783 int mm_attrs_set_valid_range(MMHandleType attrs, int index, int min, int max, int dval)
785 return mmf_attrs_set_valid_range(attrs, index, min, max, dval);
789 int mm_attrs_set_valid_array(MMHandleType attrs, int index, const int *array, int count, int dval)
791 return mmf_attrs_set_valid_array(attrs, index, array, count, dval);
795 int mm_attrs_set_valid_double_range(MMHandleType attrs, int index, double min, double max, double dval)
797 return mmf_attrs_set_valid_double_range(attrs, index, min, max, dval);
801 int mm_attrs_set_valid_double_array(MMHandleType attrs, int index, const double *array, int count, double dval)
803 return mmf_attrs_set_valid_double_array(attrs, index, array, count, dval);
807 int mm_attrs_is_modified(MMHandleType attrs, int index, bool *modified)
809 mmf_attrs_t *h = (mmf_attrs_t *) attrs;
810 mmf_attribute_t *item;
812 return_val_if_fail(attrs, MM_ERROR_COMMON_INVALID_ARGUMENT);
813 return_val_if_fail(index >= 0, MM_ERROR_COMMON_INVALID_ARGUMENT);
815 item = &h->items[index];
817 MM_ATTR_ITEM_WRITE_LOCK(item);
819 *modified = mmf_attribute_is_modified(item);
821 MM_ATTR_ITEM_WRITE_UNLOCK(item);
823 return MM_ERROR_NONE;
827 int mm_attrs_set_modified(MMHandleType attrs, int index)
829 mmf_attrs_t *h = (mmf_attrs_t *) attrs;
830 mmf_attribute_t *item;
832 return_val_if_fail(attrs, MM_ERROR_COMMON_INVALID_ARGUMENT);
833 return_val_if_fail(index >= 0, MM_ERROR_COMMON_INVALID_ARGUMENT);
835 item = &h->items[index];
837 MM_ATTR_ITEM_WRITE_LOCK(item);
839 mmf_attribute_set_modified(item);
841 MM_ATTR_ITEM_WRITE_UNLOCK(item);
843 return MM_ERROR_NONE;
847 int mm_attrs_set_readonly(MMHandleType attrs, int index)
849 mmf_attrs_t *h = (mmf_attrs_t *) attrs;
850 mmf_attribute_t *item;
852 return_val_if_fail(attrs, MM_ERROR_COMMON_INVALID_ARGUMENT);
853 return_val_if_fail(index >= 0, MM_ERROR_COMMON_INVALID_ARGUMENT);
855 item = &h->items[index];
857 MM_ATTR_ITEM_WRITE_LOCK(item);
859 mmf_attribute_set_readonly(item);
861 MM_ATTR_ITEM_WRITE_UNLOCK(item);
863 return MM_ERROR_NONE;
867 int mm_attrs_set_disabled(MMHandleType attrs, int index)
869 mmf_attrs_t *h = (mmf_attrs_t *) attrs;
870 mmf_attribute_t *item;
872 return_val_if_fail(attrs, MM_ERROR_COMMON_INVALID_ARGUMENT);
873 return_val_if_fail(index >= 0, MM_ERROR_COMMON_INVALID_ARGUMENT);
875 item = &h->items[index];
877 MM_ATTR_ITEM_WRITE_LOCK(item);
879 mmf_attribute_set_disabled(item);
881 MM_ATTR_ITEM_WRITE_UNLOCK(item);
883 return MM_ERROR_NONE;