*
*/
-
-
#include <stdio.h>
#include <stdbool.h>
#include <malloc.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(attrs);
+}
+
+int mm_attrs_commit(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_commit(item);
+
+ MM_ATTR_ITEM_WRITE_UNLOCK(item);
+
+ return MM_ERROR_NONE;
+}
+
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;
}
-int mm_attrs_get_valid_type(MMHandleType attrs, int index, int *type)
+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) {
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;
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_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);
- mmf_attribute_t *item = &h->items[index];
+ 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 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);
- mmf_attribute_t *item = &h->items[index];
+
+ item = &h->items[index];
return_val_if_fail(item, MM_ERROR_COMMON_INVALID_ARGUMENT);
if (mmf_attribute_check_flags(item, MM_ATTRS_FLAG_READABLE)) {
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);
- mmf_attribute_t *item = &h->items[index];
+ 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 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);
- mmf_attribute_t *item = &h->items[index];
+
+ item = &h->items[index];
return_val_if_fail(item, MM_ERROR_COMMON_INVALID_ARGUMENT);
if (mmf_attribute_check_flags(item, MM_ATTRS_FLAG_READABLE)) {
int mm_attrs_set_string(MMHandleType attrs, int index, const char *string, int size)
{
mmf_attrs_t *h = (mmf_attrs_t *) attrs;
- return_val_if_fail(h && index >= 0 && index < h->count, MM_ERROR_COMMON_INVALID_ARGUMENT);
+ mmf_attribute_t *item;
- mmf_attribute_t *item = &h->items[index];
+ 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);
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 = NULL;
+ mmf_attribute_t *item;
+
return_val_if_fail(h && index >= 0 && index < h->count && sval, MM_ERROR_COMMON_INVALID_ARGUMENT);
item = &h->items[index];
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);
- mmf_attribute_t *item = &h->items[index];
+ 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 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)) {
int mm_attrs_set_int_by_name(MMHandleType attrs, const char *name, int val)
{
- return_val_if_fail(attrs && name, -1);
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);
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);
int mm_attrs_set_string_by_name(MMHandleType attrs, const char *name, const char *string)
{
- return_val_if_fail(attrs && name, -1);
-
int size;
int index = 0;
+
+ return_val_if_fail(attrs && name, -1);
+
mm_attrs_get_index(attrs, name, &index);
if (index >= 0) {
if (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);
int mm_attrs_set_data_by_name(MMHandleType attrs, const char *name, void *data, int size)
{
- return_val_if_fail(attrs && name, -1);
int index = 0;
- mm_attrs_get_index(attrs, name, &index);
+ 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);
}
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);
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);
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;
+}