/* * libmm-common * * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. * * Contact: Jonghyuk Choi * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * */ #include #include #include #include #include #include "mm_debug.h" #include "mm_attrs.h" #include "mm_attrs_private.h" #include "mm_error.h" int mm_attrs_new(MMAttrsConstructInfo *info, int count, const char *name, mm_attrs_commit_callback callback, void *user_param, MMHandleType *attrs) { MMHandleType _attrs; return_val_if_fail(attrs, MM_ERROR_COMMON_INVALID_ARGUMENT); _attrs = mmf_attrs_new_from_data(name, (mmf_attrs_construct_info_t *) info, count, (mmf_attrs_commit_func_t) callback, user_param); if (!_attrs) return MM_ERROR_COMMON_INTERNAL; *attrs = _attrs; return MM_ERROR_NONE; } void mm_attrs_free(MMHandleType attrs) { mmf_attrs_free(attrs); } int mm_attrs_commit_all(MMHandleType attrs) { return mmf_attrs_commit_all(attrs); } int mm_attrs_commit(MMHandleType attrs, int index) { return mmf_attrs_commit(attrs, index, NULL); } int mm_attrs_get_type(MMHandleType attrs, int index, MMAttrsType *attrtype) { mmf_attrs_t *h = (mmf_attrs_t *) attrs; return_val_if_fail(h && index >= 0 && index < h->count && attrtype, MM_ERROR_COMMON_INVALID_ARGUMENT); *attrtype = h->items[index].value.type; return MM_ERROR_NONE; } int mm_attrs_get_flags(MMHandleType attrs, int index, int *flags) { mmf_attrs_t *h = (mmf_attrs_t *) attrs; return_val_if_fail(h && index >= 0 && index < h->count && flags, MM_ERROR_COMMON_INVALID_ARGUMENT); *flags = h->items[index].flags; return MM_ERROR_NONE; } int mm_attrs_get_valid_type(MMHandleType attrs, int index, MMAttrsValidType *type) { mmf_attrs_t *h = (mmf_attrs_t *) attrs; return_val_if_fail(h && index >= 0 && index < h->count && type, MM_ERROR_COMMON_INVALID_ARGUMENT); *type = h->items[index].value_spec.type; return MM_ERROR_NONE; } int mm_attrs_get_valid_range(MMHandleType attrs, int index, int *min, int *max) { mmf_attrs_t *h = (mmf_attrs_t *) attrs; return_val_if_fail(h && index >= 0 && index < h->count && min && max, MM_ERROR_COMMON_INVALID_ARGUMENT); if (min) { *min = h->items[index].value_spec.spec.int_spec.range.min; } if (max) { *max = h->items[index].value_spec.spec.int_spec.range.max; } return MM_ERROR_NONE; } int mm_attrs_get_valid_array(MMHandleType attrs, int index, int *count, int **array) { mmf_attrs_t *h = (mmf_attrs_t *) attrs; if (count) *count = 0; return_val_if_fail(h && count && index >= 0 && index < h->count && array, MM_ERROR_COMMON_INVALID_ARGUMENT); if (count) *count = h->items[index].value_spec.spec.int_spec.array.count; *array = h->items[index].value_spec.spec.int_spec.array.array; return MM_ERROR_NONE; } int mm_attrs_get_size(MMHandleType attrs, int *size) { mmf_attrs_t *h = (mmf_attrs_t *) attrs; return_val_if_fail(h && size, MM_ERROR_COMMON_INVALID_ARGUMENT); *size = h->count; return MM_ERROR_NONE; } int mm_attrs_get_name(MMHandleType attrs, int index, char **name) { mmf_attrs_t *h = (mmf_attrs_t *) attrs; return_val_if_fail(h && index >= 0 && index < h->count && name, MM_ERROR_COMMON_INVALID_ARGUMENT); *name = h->items[index].name; return MM_ERROR_NONE; } int mm_attrs_get_index(MMHandleType attrs, const char *attrname, int *index) { mmf_attrs_t *h = (mmf_attrs_t *) attrs; int i; return_val_if_fail(h && attrname && index, MM_ERROR_COMMON_INVALID_ARGUMENT); for (i = 0; i < h->count; i++) { if (0 == strcmp(h->items[i].name, attrname)) { *index = i; return MM_ERROR_NONE; } } debug_error("failed to get index for [%s]", attrname); return MM_ERROR_COMMON_OUT_OF_ARRAY; } int mm_attrs_set_int(MMHandleType attrs, int index, int val) { mmf_attrs_t *h = (mmf_attrs_t *) attrs; mmf_attribute_t *item; return_val_if_fail(h && index >= 0 && index < h->count, MM_ERROR_COMMON_INVALID_ARGUMENT); item = &h->items[index]; return_val_if_fail(item, MM_ERROR_COMMON_INVALID_ARGUMENT); if (!mmf_attribute_check_flags(item, MM_ATTRS_FLAG_WRITABLE)) { return MM_ERROR_COMMON_INVALID_PERMISSION; } if (mmf_attribute_validate_int(item, val)) { int ret = 0; ret = mmf_attribute_set_int(item, val); if (ret == 0) return MM_ERROR_NONE; else return MM_ERROR_COMMON_INVALID_ATTRTYPE; } if (item->value_spec.type == MMF_VALUE_SPEC_INT_RANGE) return MM_ERROR_COMMON_OUT_OF_RANGE; else if (item->value_spec.type == MMF_VALUE_SPEC_INT_ARRAY) return MM_ERROR_COMMON_OUT_OF_ARRAY; else return MM_ERROR_COMMON_INVALID_ARGUMENT; } int mm_attrs_get_int(MMHandleType attrs, int index, int *val) { mmf_attrs_t *h = (mmf_attrs_t *) attrs; mmf_attribute_t *item; return_val_if_fail(h && index >= 0 && index < h->count && val, MM_ERROR_COMMON_INVALID_ARGUMENT); item = &h->items[index]; return_val_if_fail(item, MM_ERROR_COMMON_INVALID_ARGUMENT); if (mmf_attribute_check_flags(item, MM_ATTRS_FLAG_READABLE)) { *val = mmf_value_get_int(&h->items[index].value); return MM_ERROR_NONE; } return MM_ERROR_COMMON_INVALID_PERMISSION; } int mm_attrs_set_double(MMHandleType attrs, int index, double val) { mmf_attrs_t *h = (mmf_attrs_t *) attrs; mmf_attribute_t *item; return_val_if_fail(h && index >= 0 && index < h->count, MM_ERROR_COMMON_INVALID_ARGUMENT); item = &h->items[index]; return_val_if_fail(item, MM_ERROR_COMMON_INVALID_ARGUMENT); if (!mmf_attribute_check_flags(item, MM_ATTRS_FLAG_WRITABLE)) return MM_ERROR_COMMON_INVALID_PERMISSION; if (mmf_attribute_validate_double(item, val)) { int ret = 0; ret = mmf_attribute_set_double(item, val); if (ret == 0) return MM_ERROR_NONE; else return MM_ERROR_COMMON_INVALID_ATTRTYPE; } if (item->value_spec.type == MMF_VALUE_SPEC_DOUBLE_RANGE) return MM_ERROR_COMMON_OUT_OF_RANGE; else if (item->value_spec.type == MMF_VALUE_SPEC_DOUBLE_ARRAY) return MM_ERROR_COMMON_OUT_OF_ARRAY; else return MM_ERROR_COMMON_INVALID_ARGUMENT; } int mm_attrs_get_double(MMHandleType attrs, int index, double *val) { mmf_attrs_t *h = (mmf_attrs_t *) attrs; mmf_attribute_t *item; return_val_if_fail(h && index >= 0 && index < h->count && val, MM_ERROR_COMMON_INVALID_ARGUMENT); item = &h->items[index]; return_val_if_fail(item, MM_ERROR_COMMON_INVALID_ARGUMENT); if (mmf_attribute_check_flags(item, MM_ATTRS_FLAG_READABLE)) { *val = mmf_value_get_double(&h->items[index].value); return MM_ERROR_NONE; } return MM_ERROR_COMMON_INVALID_PERMISSION; } int mm_attrs_set_string(MMHandleType attrs, int index, const char *string, int size) { mmf_attrs_t *h = (mmf_attrs_t *) attrs; mmf_attribute_t *item; return_val_if_fail(h && index >= 0 && index < h->count, MM_ERROR_COMMON_INVALID_ARGUMENT); item = &h->items[index]; return_val_if_fail(item, MM_ERROR_COMMON_INVALID_ARGUMENT); MM_ATTR_ITEM_WRITE_LOCK(item); if (mmf_attribute_check_flags(item, MM_ATTRS_FLAG_WRITABLE)) { int ret = 0; ret = mmf_attribute_set_string(item, string, size); MM_ATTR_ITEM_WRITE_UNLOCK(item); if (ret == 0) return MM_ERROR_NONE; else return MM_ERROR_COMMON_INVALID_ARGUMENT; } MM_ATTR_ITEM_WRITE_UNLOCK(item); return MM_ERROR_COMMON_INVALID_PERMISSION; } int mm_attrs_get_string(MMHandleType attrs, int index, char **sval, int *size) { mmf_attrs_t *h = (mmf_attrs_t *) attrs; mmf_attribute_t *item; return_val_if_fail(h && index >= 0 && index < h->count && sval, MM_ERROR_COMMON_INVALID_ARGUMENT); item = &h->items[index]; MM_ATTR_ITEM_WRITE_LOCK(item); if (!(item->flags & MM_ATTRS_FLAG_READABLE)) { //mmf_debug(MMF_DEBUG_LOG, "Access denied.\n"); MM_ATTR_ITEM_WRITE_UNLOCK(item); return MM_ERROR_COMMON_INVALID_PERMISSION; } *sval = mmf_value_get_string(&item->value, size); MM_ATTR_ITEM_WRITE_UNLOCK(item); return MM_ERROR_NONE; } int mm_attrs_set_data(MMHandleType attrs, int index, void *data, int size) { mmf_attrs_t *h = (mmf_attrs_t *) attrs; mmf_attribute_t *item; return_val_if_fail(h && index >= 0 && index < h->count, MM_ERROR_COMMON_INVALID_ARGUMENT); item = &h->items[index]; return_val_if_fail(item, MM_ERROR_COMMON_INVALID_ARGUMENT); if (mmf_attribute_check_flags(item, MM_ATTRS_FLAG_WRITABLE)) { int ret = 0; ret = mmf_attribute_set_data(item, data, size); if (ret == 0) return MM_ERROR_NONE; else return MM_ERROR_COMMON_INVALID_ARGUMENT; } return MM_ERROR_COMMON_INVALID_ARGUMENT; } int mm_attrs_get_data(MMHandleType attrs, int index, void **data, int *size) { mmf_attrs_t *h = (mmf_attrs_t *) attrs; return_val_if_fail(h && index >= 0 && index < h->count && data, MM_ERROR_COMMON_INVALID_ARGUMENT); if (!(h->items[index].flags & MM_ATTRS_FLAG_READABLE)) { //mmf_debug(MMF_DEBUG_LOG, "Access denied.\n"); return MM_ERROR_COMMON_INVALID_PERMISSION; } *data = mmf_value_get_data(&h->items[index].value, size); return MM_ERROR_NONE; } int mm_attrs_set_int_by_name(MMHandleType attrs, const char *name, int val) { int index = 0; return_val_if_fail(attrs && name, -1); mm_attrs_get_index(attrs, name, &index); if (index >= 0) { return mm_attrs_set_int(attrs, index, val); } return -1; } int mm_attrs_get_int_by_name(MMHandleType attrs, const char *name, int *val) { int index = -1; return_val_if_fail(attrs && name && val, MM_ERROR_COMMON_INVALID_ARGUMENT); mm_attrs_get_index(attrs, name, &index); if (index >= 0) { return mm_attrs_get_int(attrs, index, val); } return MM_ERROR_COMMON_INVALID_ATTRTYPE; } int mm_attrs_set_string_by_name(MMHandleType attrs, const char *name, const char *string) { int size; int index = 0; return_val_if_fail(attrs && name, -1); mm_attrs_get_index(attrs, name, &index); if (index >= 0) { if (string) { size = strlen(string); } else { string = NULL; size = 0; } return mm_attrs_set_string(attrs, index, string, size); } return -1; } int mm_attrs_get_string_by_name(MMHandleType attrs, const char *name, char **string) { int index = -1; int len = 0; return_val_if_fail(attrs && name && string, MM_ERROR_COMMON_INVALID_ARGUMENT); mm_attrs_get_index(attrs, name, &index); if (index >= 0) { return mm_attrs_get_string(attrs, index, string, &len); } return MM_ERROR_COMMON_INVALID_ATTRTYPE; } int mm_attrs_set_data_by_name(MMHandleType attrs, const char *name, void *data, int size) { int index = 0; return_val_if_fail(attrs && name, -1); mm_attrs_get_index(attrs, name, &index); if (index >= 0) { return mm_attrs_set_data(attrs, index, data, size); } return -1; } int mm_attrs_get_data_by_name(MMHandleType attrs, const char *name, void **data) { int index = -1; int len = 0; return_val_if_fail(attrs && name, MM_ERROR_COMMON_INVALID_ARGUMENT); mm_attrs_get_index(attrs, name, &index); if (index >= 0) { return mm_attrs_get_data(attrs, index, data, &len); } return MM_ERROR_COMMON_INVALID_ATTRTYPE; } int mm_attrs_set_double_by_name(MMHandleType attrs, const char *name, double val) { int index = -1; return_val_if_fail(attrs && name, MM_ERROR_COMMON_INVALID_ARGUMENT); mm_attrs_get_index(attrs, name, &index); if (index >= 0) { return mm_attrs_set_double(attrs, index, val); } return MM_ERROR_COMMON_INVALID_ATTRTYPE; } int mm_attrs_get_double_by_name(MMHandleType attrs, const char *name, double *val) { int index = -1; return_val_if_fail(attrs && name && val, MM_ERROR_COMMON_INVALID_ARGUMENT); mm_attrs_get_index(attrs, name, &index); if (index >= 0) { *val = mm_attrs_get_double(attrs, index, val); return 0; } return MM_ERROR_COMMON_INVALID_ATTRTYPE; } int mm_attrs_set_valist(MMHandleType attrs, char **err_attr_name, const char *attribute_name, va_list var_args) { const char *name = NULL; int ret = MM_ERROR_NONE; return_val_if_fail(attrs, MM_ERROR_COMMON_INVALID_ARGUMENT); // return_val_if_fail(err_attr_name, MM_ERROR_COMMON_INVALID_ARGUMENT); return_val_if_fail(attribute_name, MM_ERROR_COMMON_INVALID_ARGUMENT); if (err_attr_name) *err_attr_name = NULL; name = attribute_name; while (name) { int index = -1; MMAttrsType attr_type = MM_ATTRS_TYPE_INVALID; //name check if ((ret = mm_attrs_get_index(attrs, name, &index)) != MM_ERROR_NONE) { if (err_attr_name) *err_attr_name = strdup(name); if (ret == (int)MM_ERROR_COMMON_OUT_OF_ARRAY) { //to avoid confusing //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); return MM_ERROR_COMMON_ATTR_NOT_EXIST; } else { //mmf_debug(MMF_DEBUG_ERROR, "result of mm_attrs_get_index is %x so return(name:%s)",ret, name); return ret; } } //type check if ((ret = mm_attrs_get_type(attrs, index, &attr_type)) != MM_ERROR_NONE) return ret; //cast and set switch (attr_type) { case MM_ATTRS_TYPE_INT: { int val = va_arg((var_args), int); // mmf_debug(MMF_DEBUG_LOG, "(%s: %d)\n", name, val); ret = mm_attrs_set_int(attrs, index, val); break; } case MM_ATTRS_TYPE_DOUBLE: { double val = va_arg((var_args), double); // mmf_debug(MMF_DEBUG_LOG, "(%s: %f)\n", name, val); ret = mm_attrs_set_double(attrs, index, val); break; } case MM_ATTRS_TYPE_STRING: { char * val = va_arg((var_args), char*); int size = va_arg((var_args), int); // mmf_debug(MMF_DEBUG_LOG, "(%s: \'%s\', size: %d)\n", name, val, size); ret = mm_attrs_set_string(attrs, index, (const char*)val, size); break; } case MM_ATTRS_TYPE_DATA: { void * val = va_arg((var_args), void*); int size = va_arg((var_args), int); // mmf_debug(MMF_DEBUG_LOG, "(%s: %p, size: %d)\n", name, val, size); ret = mm_attrs_set_data(attrs, index, val, size); break; } case MM_ATTRS_TYPE_INVALID: default: //mmf_debug(MMF_DEBUG_ERROR, "This function doesn't support attribute type(%d, name:%s)\n", attr_type, name); return MM_ERROR_COMMON_INVALID_ARGUMENT; break; } if (ret != MM_ERROR_NONE) { if (err_attr_name) *err_attr_name = strdup(name); //mmf_debug(MMF_DEBUG_ERROR, "Setting failure.(name:%s)\n", name); return ret; } //next name name = va_arg(var_args, char*); } if (mmf_attrs_commit_err(attrs, err_attr_name) == -1) { //mmf_debug(MMF_DEBUG_ERROR, "result of mmf_attrs_commit_err is -1 (name:%s)", name); return MM_ERROR_COMMON_UNKNOWN; } else { return MM_ERROR_NONE; } return ret; } int mm_attrs_get_valist(MMHandleType attrs, char **err_attr_name, const char *attribute_name, va_list var_args) { const char *name = NULL; int ret = MM_ERROR_NONE; return_val_if_fail(attrs, MM_ERROR_COMMON_INVALID_ARGUMENT); // return_val_if_fail(err_attr_name, MM_ERROR_COMMON_INVALID_ARGUMENT); return_val_if_fail(attribute_name, MM_ERROR_COMMON_INVALID_ARGUMENT); if (err_attr_name) *err_attr_name = NULL; name = attribute_name; while (name) { int index = -1; MMAttrsType attr_type = MM_ATTRS_TYPE_INVALID; //name check if ((ret = mm_attrs_get_index(attrs, name, &index)) != MM_ERROR_NONE) { if (err_attr_name) *err_attr_name = strdup(name); if (ret == (int)MM_ERROR_COMMON_OUT_OF_ARRAY) //to avoid confusing return MM_ERROR_COMMON_ATTR_NOT_EXIST; else return ret; } //type check if ((ret = mm_attrs_get_type(attrs, index, &attr_type)) != MM_ERROR_NONE) return ret; //cast and set switch (attr_type) { case MM_ATTRS_TYPE_INT: { int * val = va_arg((var_args), int*); // mmf_debug(MMF_DEBUG_LOG, "(%s: %p)\n", name, val); ret = mm_attrs_get_int(attrs, index, val); break; } case MM_ATTRS_TYPE_DOUBLE: { double * val = va_arg((var_args), double*); // mmf_debug(MMF_DEBUG_LOG, "(%s: %p)\n", name, val); ret = mm_attrs_get_double(attrs, index, val); break; } case MM_ATTRS_TYPE_STRING: { char ** val = va_arg((var_args), char**); int * size = va_arg((var_args), int*); // mmf_debug(MMF_DEBUG_LOG, "(%s: %p, size: %p)\n", name, val, size); ret = mm_attrs_get_string(attrs, index, (char**)val, size); break; } case MM_ATTRS_TYPE_DATA: { void ** val = va_arg((var_args), void**); int * size = va_arg((var_args), int*); // mmf_debug(MMF_DEBUG_LOG, "(%s: %p, size: %p)\n", name, val, size); ret = mm_attrs_get_data(attrs, index, val, size); break; } case MM_ATTRS_TYPE_INVALID: default: // mmf_debug(MMF_DEBUG_ERROR, "This function doesn't support attribute type(%d, name:%s)\n", attr_type, name); //if (err_attr_name) // *err_attr_name = strdup(name); ret = MM_ERROR_COMMON_INVALID_ARGUMENT; break; } if (ret != MM_ERROR_NONE) { if (err_attr_name) *err_attr_name = strdup(name); //mmf_debug(MMF_DEBUG_ERROR, "Setting failure.(name:%s)\n", name); return ret; } //next name name = va_arg(var_args, char*); } return ret; } int mm_attrs_multiple_set(MMHandleType attrs, char **err_attr_name, const char *attribute_name, ...) { va_list var_args; int ret = MM_ERROR_NONE; return_val_if_fail(attribute_name, MM_ERROR_COMMON_INVALID_ARGUMENT); va_start(var_args, attribute_name); ret = mm_attrs_set_valist(attrs, err_attr_name, attribute_name, var_args); va_end(var_args); return ret; } int mm_attrs_multiple_get(MMHandleType attrs, char **err_attr_name, const char *attribute_name, ...) { va_list var_args; int ret = MM_ERROR_NONE; return_val_if_fail(attribute_name, MM_ERROR_COMMON_INVALID_ARGUMENT); va_start(var_args, attribute_name); ret = mm_attrs_get_valist(attrs, err_attr_name, attribute_name, var_args); va_end(var_args); return ret; } int mm_attrs_get_info(MMHandleType attrs, int index, MMAttrsInfo *info) { mmf_attrs_t *h = (mmf_attrs_t *) attrs; return_val_if_fail(attrs, MM_ERROR_COMMON_INVALID_ARGUMENT); return_val_if_fail(info, MM_ERROR_COMMON_INVALID_ARGUMENT); return_val_if_fail(0 <= index && index < h->count, MM_ERROR_COMMON_INVALID_ARGUMENT); memset(info, 0x00, sizeof(MMAttrsInfo)); info->type = h->items[index].value.type; info->flag = h->items[index].flags; info->validity_type = h->items[index].value_spec.type; switch (info->validity_type) { case MM_ATTRS_VALID_TYPE_INT_ARRAY: info->int_array.array = h->items[index].value_spec.spec.int_spec.array.array; info->int_array.count = h->items[index].value_spec.spec.int_spec.array.count; info->int_array.dval = h->items[index].value_spec.spec.int_spec.array.dval; break; case MM_ATTRS_VALID_TYPE_INT_RANGE: info->int_range.min = h->items[index].value_spec.spec.int_spec.range.min; info->int_range.max = h->items[index].value_spec.spec.int_spec.range.max; info->int_range.dval = h->items[index].value_spec.spec.int_spec.range.dval; break; case MM_ATTRS_VALID_TYPE_DOUBLE_ARRAY: info->double_array.array = h->items[index].value_spec.spec.double_spec.array.array; info->double_array.count = h->items[index].value_spec.spec.double_spec.array.count; info->double_array.dval = h->items[index].value_spec.spec.double_spec.array.dval; break; case MM_ATTRS_VALID_TYPE_DOUBLE_RANGE: info->double_range.min = h->items[index].value_spec.spec.double_spec.range.min; info->double_range.max = h->items[index].value_spec.spec.double_spec.range.max; info->double_range.dval = h->items[index].value_spec.spec.double_spec.range.dval; break; case MM_ATTRS_VALID_TYPE_NONE: //mmf_debug(MMF_DEBUG_LOG, "Valid type none.\n"); break; case MM_ATTRS_VALID_TYPE_INVALID: default: break; } return MM_ERROR_NONE; } int mm_attrs_get_info_by_name(MMHandleType attrs, const char *attr_name, MMAttrsInfo *info) { int index = -1; int ret = MM_ERROR_NONE; return_val_if_fail(attrs, MM_ERROR_COMMON_INVALID_ARGUMENT); return_val_if_fail(info, MM_ERROR_COMMON_INVALID_ARGUMENT); //mmf_debug(MMF_DEBUG_LOG, "(attr_name:%s)\n", attr_name); mm_attrs_get_index(attrs, attr_name, &index); return_val_if_fail(index >= 0, MM_ERROR_COMMON_INVALID_ARGUMENT); ret = mm_attrs_get_info(attrs, index, info); return ret; } int mm_attrs_set_valid_type(MMHandleType attrs, int index, MMAttrsValidType type) { return_val_if_fail(type > MM_ATTRS_VALID_TYPE_INVALID, MM_ERROR_COMMON_INVALID_ARGUMENT); return_val_if_fail(type <= MM_ATTRS_VALID_TYPE_DOUBLE_RANGE, MM_ERROR_COMMON_INVALID_ARGUMENT); return mmf_attrs_set_valid_type(attrs, index, (int)type); } int mm_attrs_set_valid_range(MMHandleType attrs, int index, int min, int max, int dval) { return mmf_attrs_set_valid_range(attrs, index, min, max, dval); } int mm_attrs_set_valid_array(MMHandleType attrs, int index, const int *array, int count, int dval) { return mmf_attrs_set_valid_array(attrs, index, array, count, dval); } int mm_attrs_set_valid_double_range(MMHandleType attrs, int index, double min, double max, double dval) { return mmf_attrs_set_valid_double_range(attrs, index, min, max, dval); } int mm_attrs_set_valid_double_array(MMHandleType attrs, int index, const double *array, int count, double dval) { return mmf_attrs_set_valid_double_array(attrs, index, array, count, dval); } int mm_attrs_is_modified(MMHandleType attrs, int index, bool *modified) { mmf_attrs_t *h = (mmf_attrs_t *) attrs; mmf_attribute_t *item; return_val_if_fail(attrs, MM_ERROR_COMMON_INVALID_ARGUMENT); return_val_if_fail(index >= 0, MM_ERROR_COMMON_INVALID_ARGUMENT); item = &h->items[index]; MM_ATTR_ITEM_WRITE_LOCK(item); *modified = mmf_attribute_is_modified(item); MM_ATTR_ITEM_WRITE_UNLOCK(item); return MM_ERROR_NONE; } int mm_attrs_set_modified(MMHandleType attrs, int index) { mmf_attrs_t *h = (mmf_attrs_t *) attrs; mmf_attribute_t *item; return_val_if_fail(attrs, MM_ERROR_COMMON_INVALID_ARGUMENT); return_val_if_fail(index >= 0, MM_ERROR_COMMON_INVALID_ARGUMENT); item = &h->items[index]; MM_ATTR_ITEM_WRITE_LOCK(item); mmf_attribute_set_modified(item); MM_ATTR_ITEM_WRITE_UNLOCK(item); return MM_ERROR_NONE; } int mm_attrs_set_readonly(MMHandleType attrs, int index) { mmf_attrs_t *h = (mmf_attrs_t *) attrs; mmf_attribute_t *item; return_val_if_fail(attrs, MM_ERROR_COMMON_INVALID_ARGUMENT); return_val_if_fail(index >= 0, MM_ERROR_COMMON_INVALID_ARGUMENT); item = &h->items[index]; MM_ATTR_ITEM_WRITE_LOCK(item); mmf_attribute_set_readonly(item); MM_ATTR_ITEM_WRITE_UNLOCK(item); return MM_ERROR_NONE; } int mm_attrs_set_disabled(MMHandleType attrs, int index) { mmf_attrs_t *h = (mmf_attrs_t *) attrs; mmf_attribute_t *item; return_val_if_fail(attrs, MM_ERROR_COMMON_INVALID_ARGUMENT); return_val_if_fail(index >= 0, MM_ERROR_COMMON_INVALID_ARGUMENT); item = &h->items[index]; MM_ATTR_ITEM_WRITE_LOCK(item); mmf_attribute_set_disabled(item); MM_ATTR_ITEM_WRITE_UNLOCK(item); return MM_ERROR_NONE; }