[0.2.116] mm_attrs: Export API set located in mm_attrs_private.h
[platform/core/multimedia/libmm-common.git] / mm_attrs.c
index f78dcc4..aba8394 100644 (file)
@@ -19,8 +19,6 @@
  *
  */
 
-
-
 #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;
 }
@@ -43,6 +90,7 @@ int mm_attrs_get_type(MMHandleType attrs, int index, MMAttrsType *attrtype)
 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;
@@ -50,10 +98,12 @@ int mm_attrs_get_flags(MMHandleType attrs, int index, int *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;
 }
@@ -62,6 +112,7 @@ int mm_attrs_get_valid_type(MMHandleType attrs, int index, int *type)
 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) {
@@ -77,9 +128,12 @@ int mm_attrs_get_valid_range(MMHandleType attrs, int index, int *min, int *max)
 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;
@@ -90,7 +144,9 @@ int mm_attrs_get_valid_array(MMHandleType attrs, int index, int *count,  int **a
 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;
 }
@@ -99,7 +155,9 @@ int mm_attrs_get_size(MMHandleType attrs, int *size)
 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;
 }
@@ -128,9 +186,11 @@ int mm_attrs_get_index(MMHandleType attrs, const char *attrname, int *index)
 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)) {
@@ -159,8 +219,11 @@ int mm_attrs_set_int(MMHandleType attrs, int index, int val)
 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)) {
@@ -175,9 +238,11 @@ int mm_attrs_get_int(MMHandleType attrs, int index,  int *val)
 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))
@@ -205,8 +270,11 @@ int mm_attrs_set_double(MMHandleType attrs, int index, double val)
 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)) {
@@ -221,10 +289,11 @@ int mm_attrs_get_double(MMHandleType attrs, int index, double *val)
 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);
@@ -250,7 +319,8 @@ int mm_attrs_set_string(MMHandleType attrs, int index, const char *string, int s
 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];
@@ -274,9 +344,11 @@ int mm_attrs_get_string(MMHandleType attrs, int index, char **sval, int *size)
 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)) {
@@ -296,6 +368,7 @@ int mm_attrs_set_data(MMHandleType attrs, int index, void *data, int size)
 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)) {
@@ -309,8 +382,10 @@ int mm_attrs_get_data(MMHandleType attrs, int index, void **data, int *size)
 
 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);
@@ -322,7 +397,9 @@ int mm_attrs_set_int_by_name(MMHandleType attrs, const char *name, int 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);
@@ -333,10 +410,11 @@ int mm_attrs_get_int_by_name(MMHandleType attrs, const char *name, int *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) {
@@ -356,6 +434,7 @@ int mm_attrs_get_string_by_name(MMHandleType attrs, const char *name, char **str
 {
        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);
@@ -368,10 +447,11 @@ int mm_attrs_get_string_by_name(MMHandleType attrs, const char *name, char **str
 
 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);
        }
@@ -397,6 +477,7 @@ int mm_attrs_get_data_by_name(MMHandleType attrs, const char *name, void **data)
 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);
@@ -410,6 +491,7 @@ int mm_attrs_set_double_by_name(MMHandleType attrs, const char *name, double val
 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);
@@ -701,3 +783,116 @@ int mm_attrs_get_info_by_name(MMHandleType attrs, const char *attr_name, MMAttrs
 
        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;
+}