From 91b23fc04c0c78215ac71e0b1b60d18d8887dd94 Mon Sep 17 00:00:00 2001 From: Sangchul Lee Date: Wed, 31 Oct 2018 08:55:50 +0900 Subject: [PATCH] [0.2.116] mm_attrs: Export API set located in mm_attrs_private.h libmm-xxx libraries commonly use some functions in mm_attrs_private.h directly. Therefore, it seems there isn't much meaning for the existence of these functions in private header file any more. This patch exports these private API set with 'mm_' prefix to mm_attrs.h. Added to mm_attrs.h as below: MMAttrsValue MMAttrsConstructInfo mm_attrs_commit_callback mm_attrs_new() mm_attrs_free() mm_attrs_commit() mm_attrs_commit_all() mm_attrs_set_valid_type() mm_attrs_set_valid_range() mm_attrs_set_valid_array() mm_attrs_set_valid_double_range() mm_attrs_set_valid_double_array() mm_attrs_is_modified() mm_attrs_set_modified() mm_attrs_set_readonly() mm_attrs_set_disabled() Note that the following patch will hide the private header file from devel package soon after using these new API set instead of former ones in libmm-xxx libraries. Change-Id: I6c60f512a6c34ed1108c44fab5bb820af9570f49 Signed-off-by: Sangchul Lee --- include/mm_attrs.h | 353 +++++++++++++++++++++++++++++++++++--------- include/mm_attrs_private.h | 16 +- include/mm_error.h | 19 +-- mm_attrs.c | 227 ++++++++++++++++++++++++++-- mm_attrs_private.c | 138 ++++++++++------- packaging/libmm-common.spec | 2 +- 6 files changed, 598 insertions(+), 157 deletions(-) diff --git a/include/mm_attrs.h b/include/mm_attrs.h index 2f8b070..5d146e1 100644 --- a/include/mm_attrs.h +++ b/include/mm_attrs.h @@ -86,7 +86,7 @@ typedef enum { /** - * Validity structure + * Validity structure. */ typedef struct { MMAttrsType type; @@ -137,6 +137,42 @@ typedef struct { }; } MMAttrsInfo; +/** + * Value structure. + */ +typedef struct { + MMAttrsType type; + int size; + union { + int i_val; + double d_val; + char *s_val; + void *p_val; + } value; +} MMAttrsValue; + +/** + * Construction information structure. + */ +typedef struct { + char *name; + MMAttrsType value_type; + int flags; + void *default_value; +} MMAttrsConstructInfo; + +/** + * Attributes commit callback function type. + * + * @param index [in] Index of attribute + * @param name [in] Name of attribute + * @param value [in] Value of attribute + * @param user_param [in] User parameter + * + * @return This callback function should return true on success, or false on failure. + * @see mm_attrs_new + */ +typedef bool (*mm_attrs_commit_callback) (int index, const char *name, const MMAttrsValue *value, void *user_param); #if __GNUC__ >= 4 #define __NULL_TERMINATED __attribute__((__sentinel__)) @@ -145,11 +181,64 @@ typedef struct { #endif /** + * This function is to create handle of attributes list and register the commit callback. + * + * @param info [in] Attributes construction information + * @param count [in] The number of attributes + * @param name [in] Name of the attributes list (optional, this can be NULL) + * @param callback [in] Commit callback (optional, this can be NULL) + * @param user_param [in] User param of the commit callback (optional, this can be NULL) + * @param attrs [out] Handle of attributes list + * + * @return This function returns MM_ERROR_NONE on success, or negative value with error code. + * @see mm_attrs_commit_all + * @see mm_attrs_commit + * @see mm_attrs_free + */ +int mm_attrs_new(MMAttrsConstructInfo *info, int count, const char *name, + mm_attrs_commit_callback callback, void *user_param, MMHandleType *attrs); + + +/** + * This function releases resources and destroy the attributes handle created by mm_attrs_new. + * + * @param attrs [in] Handle of attributes list + * @see mm_attrs_new + */ +void mm_attrs_free(MMHandleType attrs); + + +/** + * This function is to commit all the attributes. + * + * @param attrs [in] Handle of attributes list + * + * @return This function returns MM_ERROR_NONE on success, or negative value with error code. + * @see mm_attrs_new + * @see mm_attrs_commit + */ +int mm_attrs_commit_all(MMHandleType attrs); + + +/** + * This function is to commit the attribute. + * + * @param attrs [in] Handle of attributes list + * @param index [in] Index of attribute + * + * @return This function returns MM_ERROR_NONE on success, or negative value with error code. + * @see mm_attrs_new + * @see mm_attrs_commit_all + */ +int mm_attrs_commit(MMHandleType attrs, int index); + + +/** * This function is to set the integer value to the attribute by name. * - * @param attrs [in] MMAttrs handle - * @param attr_name [in] attribute name - * @param val [in] integer value to set + * @param attrs [in] Handle of attributes list + * @param attr_name [in] Name of attribute + * @param val [in] Integer value to set * * @return This function returns MM_ERROR_NONE on success, or negative value with error code. */ @@ -171,7 +260,7 @@ int mm_attrs_get_size(MMHandleType attrs, int *size); * This function is to get the name of attribute at the given index. * * @param attrs [in] Handle of attributes list - * @param index [in] Index of the attribute + * @param index [in] Index of attribute * @param name [out] Name of attribute * * @return This function returns the name of attribute on success, or NULL @@ -208,9 +297,9 @@ int mm_attrs_get_int_by_name(MMHandleType attrs, const char *attr_name, int *val /** * This function is to set the string to attribute by name. * - * @param attrs [in] MMAttrs handle - * @param attr_name [in] attribute name - * @param string [in] string value to set + * @param attrs [in] MMAttrs handle + * @param attr_name [in] Name of attribute + * @param string [in] String value to set * * @return This function returns MM_ERROR_NONE on success, or negative value with error code. */ @@ -233,21 +322,22 @@ int mm_attrs_get_string_by_name(MMHandleType attrs, const char *attr_name, char /** * This function is to set the data to the attribute by name. * - * @param attrs [in] MMAttrs handle - * @param attr_name [in] attribute name - * @param data [in] data pointer to set - * @param size [in] data size to set + * @param attrs [in] Handle of attributes list + * @param attr_name [in] Name of attribute + * @param data [in] Data pointer to set + * @param size [in] Data size to set * * @return This function returns MM_ERROR_NONE on success, or negative value with error code. */ int mm_attrs_set_data_by_name(MMHandleType attrs, const char *attr_name, void *data, int size); + /** * This function is to get the data from the attribute by name. * * @param attrs [in] Handle of attributes list * @param attr_name [in] Name of attribute - * @param data [out] data pointer to set + * @param data [out] Data pointer to set * * @return This function returns user defined value on success, or NULL * on failure @@ -258,9 +348,9 @@ int mm_attrs_get_data_by_name(MMHandleType attrs, const char *attr_name, void ** /** * This function is to retrieve type of attribute. * - * @param attrs [in] List of attributes - * @param index [in] Index of attribute - * @param attrtype [out] On return contains type of attribute + * @param attrs [in] List of attributes + * @param index [in] Index of attribute + * @param attrtype [out] Type of attribute * * @return This function returns MM_ERROR_NONE. * @see MMAttrsType @@ -271,9 +361,9 @@ int mm_attrs_get_type(MMHandleType attrs, int index, MMAttrsType *attrtype); /** * This function is to get flags of attribute with given index. * - * @param attrs [in] List of attributes - * @param index [in] Index of attribute - * @param flags [out] On return contains flags of attribute. + * @param attrs [in] List of attributes + * @param index [in] Index of attribute + * @param flags [out] Flags of attribute * * @return This function returns MM_ERROR_NONE on success, or negative value with error code. * @see MMAttrsFlag @@ -284,23 +374,23 @@ int mm_attrs_get_flags(MMHandleType attrs, int index, int *flags); /** * This function is to get valid value type of attribute with given index. * - * @param attrs [in] List of attributes - * @param index [in] Index of attribute - * @param type [out] On return contains valid value type of attribute + * @param attrs [in] List of attributes + * @param index [in] Index of attribute + * @param type [out] Valid value type of attribute * * @return This function returns MM_ERROR_NONE on success, or negative value with error code. * @see MMAttrsType */ -int mm_attrs_get_valid_type(MMHandleType attrs, int index, int *type); +int mm_attrs_get_valid_type(MMHandleType attrs, int index, MMAttrsValidType *type); /** * This function is to get valid range of attribute with given index. * - * @param attrs [in] List of attributes - * @param index [in] Index of attribute - * @param min [out] minimum value of the valid range - * @param max [out] maximum value of the valid range + * @param attrs [in] List of attributes + * @param index [in] Index of attribute + * @param min [out] Minimum value of the valid range + * @param max [out] Maximum value of the valid range * * @return This function returns MM_ERROR_NONE on success, or negative value with error code. */ @@ -310,10 +400,10 @@ int mm_attrs_get_valid_range(MMHandleType attrs, int index, int *min, int *max); /** * This function is to get valid array of attribute with given index. * - * @param attrs [in] list of attributes - * @param index [in] Index of attribute - * @param count [out] number of array - * @param array [out] on return contains valid array of attribute + * @param attrs [in] List of attributes + * @param index [in] Index of attribute + * @param count [out] The number of array + * @param array [out] Valid array of attribute * * @return This function returns MM_ERROR_NONE on success, or negative value with error code. */ @@ -323,9 +413,9 @@ int mm_attrs_get_valid_array(MMHandleType attrs, int index, int *count, int **a /** * This function is to set integer value to attribute with given index. * - * @param attrs [in] List of attributes - * @param index [in] Index of attribute - * @param val [in] integer value to set + * @param attrs [in] List of attributes + * @param index [in] Index of attribute + * @param val [in] Integer value to set * * @return This function returns MM_ERROR_NONE on success, or negative value with error code. * @see mm_attrs_get_int @@ -336,9 +426,9 @@ int mm_attrs_set_int(MMHandleType attrs, int index, int val); /** * This function is to get integer value to attribute with given index. * - * @param attrs [in] List of attributes - * @param index [in] Index of attribute - * @param val [out] On return contains integer value of attribute + * @param attrs [in] List of attributes + * @param index [in] Index of attribute + * @param val [out] Integer value of attribute * * @return This function returns MM_ERROR_NONE on success, or negative value with error code. * @remarks If type of attributes is not an integer type, the value which is returned by this function is meaningless. @@ -377,7 +467,7 @@ int mm_attrs_set_double_by_name(MMHandleType attrs, const char *attr_name, doubl * * @param attrs [in] List of attributes * @param index [in] Index of attribute - * @param attrval [out] On return contains double value of attribute on success, or invalid value. + * @param attrval [out] Double value of attribute on success, or invalid value * * @return This function returns MM_ERROR_NONE on success, or negative value with error code. * @see mm_attrs_set_double @@ -400,10 +490,10 @@ int mm_attrs_get_double_by_name(MMHandleType attrs, const char *attr_name, doubl /** * This function is to set string to attribute with given index. * - * @param attrs [in] List of attributes - * @param index [in] Index of attribute - * @param string [in] String to set - * @param size [in] length of string to set + * @param attrs [in] Handle of attributes list + * @param index [in] Index of attribute + * @param string [in] String to set + * @param size [in] Length of string to set * * @return This function returns MM_ERROR_NONE on success, or negative value with error code. * @see mm_attrs_get_string @@ -414,10 +504,10 @@ int mm_attrs_set_string(MMHandleType attrs, int index, const char *string, int s /** * This function is to get string to attribute with given index. * - * @param attrs [in] List of attributes - * @param index [in] Index of attribute - * @param sval [in] Placeholder to output string buffer - * @param size [in] The field contains number of characters filled in the buffer + * @param attrs [in] Handle of attributes list + * @param index [in] Index of attribute + * @param sval [in] Placeholder to output string buffer + * @param size [in] The field contains number of characters filled in the buffer * * @return This function returns MM_ERROR_NONE on success, or negative value with error code. * @remarks Application would be responsible for managing/releasing the string @@ -429,24 +519,25 @@ int mm_attrs_get_string(MMHandleType attrs, int index, char **sval, int *size); /** * This function is to set pointer to attribute with given index. * - * @param attrs [in] List of attributes - * @param index [in] Index of attribute - * @param data [in] data to set - * @param size [in] Length of input data - * @return This function returns MM_ERROR_NONE on success, or negative value with error code. + * @param attrs [in] Handle of attributes list + * @param index [in] Index of attribute + * @param data [in] Data to set + * @param size [in] Length of input data * + * @return This function returns MM_ERROR_NONE on success, or negative value with error code. * @remarks Data type is the reference to memory which is allocated by user. The allocated memory must be freed by user. * @see mm_attrs_get_data */ int mm_attrs_set_data(MMHandleType attrs, int index, void *data, int size); + /** * This function is to get pointer to attribute with given index. * - * @param attrs [in] List of attributes - * @param index [in] Index of attribute - * @param data [out] Placeholder to output data buffer - * @param size [out] The field contains number of bytes filled in the buffer + * @param attrs [in] Handle of attributes list + * @param index [in] Index of attribute + * @param data [out] Placeholder to output data buffer + * @param size [out] The field contains number of bytes filled in the buffer * * @return This function returns MM_ERROR_NONE on success, or negative value with error code. * @remarks Application would be responsible for managing/releasing data @@ -458,7 +549,7 @@ int mm_attrs_get_data(MMHandleType attrs, int index, void **data, int *size); /** * A function to get information of the attribute * - * @param attrs [in] List of attributes + * @param attrs [in] Handle of attributes list * @param index [in] Index of attribute * @param info [out] Information of the attribute * @@ -470,7 +561,7 @@ int mm_attrs_get_info(MMHandleType attrs, int index, MMAttrsInfo *info); /** * This function is to get array of attribute with given name. * - * @param attrs [in] List of attributes + * @param attrs [in] Handle of attributes list * @param attr_name [in] Name of attribute * @param info [out] Information of the attribute * @@ -478,13 +569,14 @@ int mm_attrs_get_info(MMHandleType attrs, int index, MMAttrsInfo *info); */ int mm_attrs_get_info_by_name(MMHandleType attrs, const char *attr_name, MMAttrsInfo *info); + /** * Sets properties on an object. * - * @param attrs [in] List of attributes - * @param err_attr_name [out] the name of attributes that occurs error. Free this variable after use. - * @param attribute_name [in] name of the first property to set - * @param ... [in] value for the first property, followed optionally by more + * @param attrs [in] Handle of attributes list + * @param err_attr_name [out] Name of attributes that occurs error. Free this variable after use + * @param attribute_name [in] Name of the first property to set + * @param ... [in] Value for the first property, followed optionally by more * name/value pairs, followed by %NULL * * @return This function returns MM_ERROR_NONE on success, or negative value with error code. @@ -497,10 +589,10 @@ int mm_attrs_multiple_set(MMHandleType attrs, char **err_attr_name, const char /** * Gets properties on an object. * - * @param attrs [in] List of attributes - * @param err_attr_name [out] the name of attributes that occurs error. Free this variable after use. - * @param attribute_name [in] name of the first property to set - * @param ... [in] value for the first property, followed optionally by more + * @param attrs [in] Handle of attributes list + * @param err_attr_name [out] Name of attributes that occurs error. Free this variable after use + * @param attribute_name [in] Name of the first property to set + * @param ... [in] Value for the first property, followed optionally by more * name/value pairs, followed by %NULL * * @return This function returns MM_ERROR_NONE on success, or negative value with error code. @@ -513,10 +605,10 @@ int mm_attrs_multiple_get(MMHandleType attrs, char **err_attr_name, const char /** * Sets properties on an object with va_list param. * - * @param attrs [in] List of attributes - * @param err_attr_name [out] the name of attributes that occurs error. Free this variable after use. - * @param attribute_name [in] name of the first property to set - * @param var_args [in] variable arguments + * @param attrs [in] Handle of attributes list + * @param err_attr_name [out] Name of attributes that occurs error. Free this variable after use + * @param attribute_name [in] Name of the first property to set + * @param var_args [in] Variable arguments * * @return This function returns MM_ERROR_NONE on success, or negative value with error code. * @remarks Multiple setter of attribute @@ -528,10 +620,10 @@ int mm_attrs_set_valist(MMHandleType attrs, char **err_attr_name, const char *at /** * Gets properties on an object with va_list param. * - * @param attrs [in] List of attributes - * @param err_attr_name [out] the name of attributes that occurs error. Free this variable after use. - * @param attribute_name [in] name of the first property to set - * @param var_args [in] variable arguments + * @param attrs [in] Handle of attributes list + * @param err_attr_name [out] Name of attributes that occurs error. Free this variable after use + * @param attribute_name [in] Name of the first property to set + * @param var_args [in] Variable arguments * * @return This function returns MM_ERROR_NONE on success, or negative value with error code. * @remarks Multiple setter of attribute @@ -539,6 +631,121 @@ int mm_attrs_set_valist(MMHandleType attrs, char **err_attr_name, const char *at */ int mm_attrs_get_valist(MMHandleType attrs, char **err_attr_name, const char *attribute_name, va_list var_args); + +/** + * This function is to set the valid attribute type. + * + * @param attrs [in] Handle of attributes list + * @param index [in] Index of attribute + * @param type [in] Type of attribute + * + * @return This function returns MM_ERROR_NONE on success, or negative value with error code. + */ +int mm_attrs_set_valid_type(MMHandleType attrs, int index, MMAttrsValidType type); + + +/** + * This function is to set the valid integer range to the attribute. + * + * @param attrs [in] Handle of attributes list + * @param index [in] Index of attribute + * @param min [in] Minimum value of the valid range + * @param max [in] Maximum value of the valid range + * @param dval [in] Default value + * + * @return This function returns MM_ERROR_NONE on success, or negative value with error code. + */ +int mm_attrs_set_valid_range(MMHandleType attrs, int index, int min, int max, int dval); + + +/** + * This function is to set the valid integer array to the attribute. + * + * @param attrs [in] Handle of attributes list + * @param index [in] Index of attribute + * @param array [in] Array contains integer values to set + * @param count [in] The number of items in array + * @param dval [in] Default value + * + * @return This function returns MM_ERROR_NONE on success, or negative value with error code. + */ +int mm_attrs_set_valid_array(MMHandleType attrs, int index, const int *array, int count, int dval); + + +/** + * This function is to set the valid double range to the attribute. + * + * @param attrs [in] Handle of attributes list + * @param index [in] Index of attribute + * @param min [in] Minimum value of the valid range + * @param max [in] Maximum value of the valid range + * @param dval [in] Default value + * + * @return This function returns MM_ERROR_NONE on success, or negative value with error code. + */ +int mm_attrs_set_valid_double_range(MMHandleType attrs, int index, double min, double max, double dval); + + +/** + * This function is to set the valid double array to the attribute. + * + * @param attrs [in] Handle of attributes list + * @param index [in] Index of attribute + * @param array [in] Array contains double values to set + * @param count [in] The number of items in array + * @param dval [in] Default value + * + * @return This function returns MM_ERROR_NONE on success, or negative value with error code. + */ +int mm_attrs_set_valid_double_array(MMHandleType attrs, int index, const double *array, int count, double dval); + + +/** + * This function is to check whether the attribute is modified + * + * @param attrs [in] Handle of attributes list + * @param index [in] Index of attribute + * @param modified [out] Modified or not (true = modified, false = not modified) + * + * @return This function returns MM_ERROR_NONE on success, or negative value with error code. + */ +int mm_attrs_is_modified(MMHandleType attrs, int index, bool *modified); + + +/** + * This function is to set the attribute to modified + * + * @param attrs [in] Handle of attributes list + * @param index [in] Index of attribute + * + * @return This function returns MM_ERROR_NONE on success, or negative value with error code. + */ +int mm_attrs_set_modified(MMHandleType attrs, int index); + + +/** + * This function is to set the attribute to read-only + * + * @param attrs [in] Handle of attributes list + * @param index [in] Index of attribute + * + * @return This function returns MM_ERROR_NONE on success, or negative value with error code. + */ +int mm_attrs_set_readonly(MMHandleType attrs, int index); + + +/** + * This function is to set the attribute to disabled + * + * @param attrs [in] Handle of attributes list + * @param index [in] Index of attribute + * + * @return This function returns MM_ERROR_NONE on success, or negative value with error code. + */ +int mm_attrs_set_disabled(MMHandleType attrs, int index); + + + /** * @} */ diff --git a/include/mm_attrs_private.h b/include/mm_attrs_private.h index f3364bb..e3a81a5 100644 --- a/include/mm_attrs_private.h +++ b/include/mm_attrs_private.h @@ -145,7 +145,7 @@ struct mmf_attribute_construct_info { void *default_value; }; -int mmf_value_init(mmf_value_t *value, int type); +int mmf_value_init(mmf_value_t *v, int type); int mmf_value_copy(mmf_value_t *dest, const mmf_value_t *src); @@ -217,24 +217,24 @@ int mmf_attribute_set_string(mmf_attribute_t *item, const char *string, int size int mmf_attribute_set_data(mmf_attribute_t *item, void *data, int size); -/* --- Create, Destroy and Initialize MmfAttrs --- */ - MMHandleType mmf_attrs_new(int count); +int mmf_attrs_init(MMHandleType h, mmf_attrs_construct_info_t *info, int count); + +int mmf_attrs_commit_err(MMHandleType h, char **err_attr_name); + +/* Functions that will be moved to mm_attrs.h */ + MMHandleType mmf_attrs_new_from_data(const char *name, mmf_attrs_construct_info_t *info, int count, mmf_attrs_commit_func_t commit_func, void *commit_param); -void mmf_attrs_free(MMHandleType attrs); - -int mmf_attrs_init(MMHandleType h, mmf_attrs_construct_info_t *info, int count); +void mmf_attrs_free(MMHandleType h); int mmf_attrs_commit(MMHandleType h); -int mmf_attrs_commit_err(MMHandleType h, char **err_attr_name); - int mmf_attrs_set_valid_type(MMHandleType h, int idx, int v_type); int mmf_attrs_set_valid_range(MMHandleType h, int idx, int min, int max, int dval); diff --git a/include/mm_error.h b/include/mm_error.h index 6365d45..57a016d 100644 --- a/include/mm_error.h +++ b/include/mm_error.h @@ -73,15 +73,16 @@ /* MM_ERROR_COMMON_CLASS */ -#define MM_ERROR_COMMON_INVALID_ARGUMENT (MM_ERROR_COMMON_CLASS | 1) /**< Invalid argument */ -#define MM_ERROR_COMMON_NO_FREE_SPACE (MM_ERROR_COMMON_CLASS | 2) /**< Out of storage */ -#define MM_ERROR_COMMON_OUT_OF_MEMORY (MM_ERROR_COMMON_CLASS | 3) /**< Out of memory */ -#define MM_ERROR_COMMON_UNKNOWN (MM_ERROR_COMMON_CLASS | 4) /**< Unknown error */ -#define MM_ERROR_COMMON_INVALID_ATTRTYPE (MM_ERROR_COMMON_CLASS | 5) /**< Invalid argument */ -#define MM_ERROR_COMMON_INVALID_PERMISSION (MM_ERROR_COMMON_CLASS | 6) /**< Invalid permission */ -#define MM_ERROR_COMMON_OUT_OF_ARRAY (MM_ERROR_COMMON_CLASS | 7) /**< Out of array */ -#define MM_ERROR_COMMON_OUT_OF_RANGE (MM_ERROR_COMMON_CLASS | 8) /**< Out of value range*/ -#define MM_ERROR_COMMON_ATTR_NOT_EXIST (MM_ERROR_COMMON_CLASS | 9) /**< Attribute doesn't exist. */ +#define MM_ERROR_COMMON_INVALID_ARGUMENT (MM_ERROR_COMMON_CLASS | 0x01) /**< Invalid argument */ +#define MM_ERROR_COMMON_NO_FREE_SPACE (MM_ERROR_COMMON_CLASS | 0x02) /**< Out of storage */ +#define MM_ERROR_COMMON_OUT_OF_MEMORY (MM_ERROR_COMMON_CLASS | 0x03) /**< Out of memory */ +#define MM_ERROR_COMMON_UNKNOWN (MM_ERROR_COMMON_CLASS | 0x04) /**< Unknown error */ +#define MM_ERROR_COMMON_INVALID_ATTRTYPE (MM_ERROR_COMMON_CLASS | 0x05) /**< Invalid argument */ +#define MM_ERROR_COMMON_INVALID_PERMISSION (MM_ERROR_COMMON_CLASS | 0x06) /**< Invalid permission */ +#define MM_ERROR_COMMON_OUT_OF_ARRAY (MM_ERROR_COMMON_CLASS | 0x07) /**< Out of array */ +#define MM_ERROR_COMMON_OUT_OF_RANGE (MM_ERROR_COMMON_CLASS | 0x08) /**< Out of value range*/ +#define MM_ERROR_COMMON_ATTR_NOT_EXIST (MM_ERROR_COMMON_CLASS | 0x09) /**< Attribute doesn't exist. */ +#define MM_ERROR_COMMON_INTERNAL (MM_ERROR_COMMON_CLASS | 0x0a) /**< Internal errors */ /* * MM_ERROR_SOUND_CLASS diff --git a/mm_attrs.c b/mm_attrs.c index f78dcc4..aba8394 100644 --- a/mm_attrs.c +++ b/mm_attrs.c @@ -19,8 +19,6 @@ * */ - - #include #include #include @@ -31,10 +29,59 @@ #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; +} diff --git a/mm_attrs_private.c b/mm_attrs_private.c index 2afd86d..ee41999 100644 --- a/mm_attrs_private.c +++ b/mm_attrs_private.c @@ -30,18 +30,20 @@ #include "mm_debug.h" #include "mm_attrs_private.h" -int mmf_value_init(mmf_value_t *value, int type) +int mmf_value_init(mmf_value_t *v, int type) { - return_val_if_fail(value, -1); + return_val_if_fail(v, -1); return_val_if_fail(MMF_IS_VALUE_TYPE(type), -1); - memset(value, 0, sizeof(*value)); - value->type = type; + + memset(v, 0, sizeof(*v)); + v->type = type; return 0; } int mmf_value_copy(mmf_value_t *dest, const mmf_value_t *src) { return_val_if_fail(dest && src && src->type == dest->type, -1); + switch (src->type) { case MM_ATTRS_TYPE_INT: dest->value.i_val = src->value.i_val; @@ -73,6 +75,7 @@ int mmf_value_copy(mmf_value_t *dest, const mmf_value_t *src) int mmf_value_set_int(mmf_value_t *v, int ival) { return_val_if_fail(v && v->type == MMF_VALUE_TYPE_INT, -1); + v->value.i_val = ival; return 0; } @@ -80,12 +83,14 @@ int mmf_value_set_int(mmf_value_t *v, int ival) int mmf_value_get_int(const mmf_value_t *v) { return_val_if_fail(v && v->type == MMF_VALUE_TYPE_INT, -1); + return v->value.i_val; } int mmf_value_set_double(mmf_value_t *v, double dval) { return_val_if_fail(v && v->type == MMF_VALUE_TYPE_DOUBLE, -1); + v->value.d_val = dval; return 0; } @@ -93,12 +98,14 @@ int mmf_value_set_double(mmf_value_t *v, double dval) double mmf_value_get_double(mmf_value_t *v) { return_val_if_fail(v->type == MMF_VALUE_TYPE_DOUBLE, -1); + return v->value.d_val; } int mmf_value_set_string(mmf_value_t *v, const char *sval, int size) { return_val_if_fail(v && v->type == MMF_VALUE_TYPE_STRING, -1); + if (v->value.s_val != NULL) { free(v->value.s_val); v->value.s_val = NULL; @@ -117,6 +124,7 @@ int mmf_value_set_string(mmf_value_t *v, const char *sval, int size) char* mmf_value_get_string(const mmf_value_t *v, int *size) { return_val_if_fail(v && v->type == MMF_VALUE_TYPE_STRING, NULL); + *size = v->size; return v->value.s_val; } @@ -124,6 +132,7 @@ char* mmf_value_get_string(const mmf_value_t *v, int *size) int mmf_value_set_data(mmf_value_t *v, void *data, int size) { return_val_if_fail(v && v->type == MMF_VALUE_TYPE_DATA, -1); + v->value.p_val = data; v->size = size; return 0; @@ -132,25 +141,27 @@ int mmf_value_set_data(mmf_value_t *v, void *data, int size) void* mmf_value_get_data(const mmf_value_t *v, int *size) { return_val_if_fail(v && v->type == MMF_VALUE_TYPE_DATA, NULL); + *size = v->size; return v->value.p_val; } -void mmf_value_dump(const mmf_value_t *value) +void mmf_value_dump(const mmf_value_t *v) { - return_if_fail(value); - switch (value->type) { + return_if_fail(v); + + switch (v->type) { case MMF_VALUE_TYPE_INT: - //mmf_debug(MMF_DEBUG_LOG, "value[int]: %d\n", value->value.i_val); + //mmf_debug(MMF_DEBUG_LOG, "value[int]: %d\n", v->value.i_val); break; case MMF_VALUE_TYPE_DOUBLE: - //mmf_debug(MMF_DEBUG_LOG, "value[double]: %f\n", value->value.d_val); + //mmf_debug(MMF_DEBUG_LOG, "value[double]: %f\n", v->value.d_val); break; case MMF_VALUE_TYPE_STRING: - //mmf_debug(MMF_DEBUG_LOG, "value[string]: %s\n", value->value.s_val); + //mmf_debug(MMF_DEBUG_LOG, "value[string]: %s\n", v->value.s_val); break; case MMF_VALUE_TYPE_DATA: - //mmf_debug(MMF_DEBUG_LOG, "value[data]: %p\n", value->value.p_val); + //mmf_debug(MMF_DEBUG_LOG, "value[data]: %p\n", v->value.p_val); break; default: //mmf_debug(MMF_DEBUG_LOG, "value invalid!!\n"); @@ -158,14 +169,15 @@ void mmf_value_dump(const mmf_value_t *value) } } -int mmf_value_clear(mmf_value_t *value) +int mmf_value_clear(mmf_value_t *v) { - return_val_if_fail(value, -1); - if (value->type == MMF_VALUE_TYPE_STRING) { - if (value->value.s_val) { - free(value->value.s_val); - value->value.s_val = NULL; - value->size = 0; + return_val_if_fail(v, -1); + + if (v->type == MMF_VALUE_TYPE_STRING) { + if (v->value.s_val) { + free(v->value.s_val); + v->value.s_val = NULL; + v->size = 0; } } return 0; @@ -174,6 +186,7 @@ int mmf_value_clear(mmf_value_t *value) int mmf_value_spec_init(mmf_value_spec_t *vs, int vs_type) { return_val_if_fail(vs, -1); + memset(vs, 0, sizeof(*vs)); vs->type = vs_type; return 0; @@ -288,6 +301,7 @@ int mmf_value_spec_get_double_array(mmf_value_spec_t *vs, double **array, int *c int mmf_value_spec_clear(mmf_value_spec_t *vs) { return_val_if_fail(vs, -1); + switch (vs->type) { case MMF_VALUE_SPEC_INT_ARRAY: if (vs->spec.int_spec.array.array) { @@ -330,17 +344,18 @@ int mmf_attribute_init(mmf_attribute_t *item, const char *name, int value_type, bool mmf_attribute_check_flags(mmf_attribute_t *item, int flags) { return_val_if_fail(item, false); + return item->flags & flags; } bool mmf_attribute_validate_int(mmf_attribute_t *item, int val) { - return_val_if_fail(item, false); - return_val_if_fail(item->value.type == MMF_VALUE_TYPE_INT, false); - bool valid = true; int i = 0; + return_val_if_fail(item, false); + return_val_if_fail(item->value.type == MMF_VALUE_TYPE_INT, false); + switch (item->value_spec.type) { case MMF_VALUE_SPEC_INT_RANGE: if (val < item->value_spec.spec.int_spec.range.min || @@ -376,12 +391,12 @@ bool mmf_attribute_validate_int(mmf_attribute_t *item, int val) bool mmf_attribute_validate_double(mmf_attribute_t *item, double val) { - return_val_if_fail(item, false); - return_val_if_fail(item->value.type == MMF_VALUE_TYPE_DOUBLE, false); - bool valid = true; int i = 0; + return_val_if_fail(item, false); + return_val_if_fail(item->value.type == MMF_VALUE_TYPE_DOUBLE, false); + switch (item->value_spec.type) { case MMF_VALUE_SPEC_DOUBLE_RANGE: if (val < item->value_spec.spec.double_spec.range.min || @@ -412,6 +427,7 @@ bool mmf_attribute_validate_double(mmf_attribute_t *item, double val) void mmf_attribute_clear(mmf_attribute_t *item) { assert(item); + if (item->name) { free(item->name); item->name = NULL; @@ -426,12 +442,14 @@ void mmf_attribute_clear(mmf_attribute_t *item) bool mmf_attribute_is_modified(mmf_attribute_t *item) { return_val_if_fail(item, false); + return (item->flags & MM_ATTRS_FLAG_MODIFIED); } void mmf_attribute_set_modified(mmf_attribute_t *item) { return_if_fail(item); + if (!(item->flags & MM_ATTRS_FLAG_MODIFIED)) { mmf_value_copy(&item->tmpval, &item->value); item->flags |= MM_ATTRS_FLAG_MODIFIED; @@ -441,6 +459,7 @@ void mmf_attribute_set_modified(mmf_attribute_t *item) void mmf_attribute_set_readonly(mmf_attribute_t *item) { return_if_fail(item); + if (item->flags & MM_ATTRS_FLAG_WRITABLE) item->flags -= MM_ATTRS_FLAG_WRITABLE; } @@ -448,6 +467,7 @@ void mmf_attribute_set_readonly(mmf_attribute_t *item) void mmf_attribute_set_disabled(mmf_attribute_t *item) { return_if_fail(item); + if (item->flags & MM_ATTRS_FLAG_WRITABLE) item->flags -= MM_ATTRS_FLAG_WRITABLE; if (item->flags & MM_ATTRS_FLAG_READABLE) @@ -459,6 +479,7 @@ void mmf_attribute_set_disabled(mmf_attribute_t *item) void mmf_attribute_commit(mmf_attribute_t *item) { return_if_fail(item); + if (item->flags & MM_ATTRS_FLAG_MODIFIED) { mmf_value_copy(&item->value, &item->tmpval); mmf_value_clear(&item->tmpval); @@ -469,6 +490,7 @@ void mmf_attribute_commit(mmf_attribute_t *item) int mmf_attribute_set_int(mmf_attribute_t *item, int val) { return_val_if_fail(item, -1); + if (mmf_value_set_int(&item->tmpval, val) == 0) { item->flags |= MM_ATTRS_FLAG_MODIFIED; return 0; @@ -479,6 +501,7 @@ int mmf_attribute_set_int(mmf_attribute_t *item, int val) int mmf_attribute_set_double(mmf_attribute_t *item, double val) { return_val_if_fail(item, -1); + if (mmf_value_set_double(&item->tmpval, val) == 0) { item->flags |= MM_ATTRS_FLAG_MODIFIED; return 0; @@ -510,10 +533,11 @@ int mmf_attribute_set_data(mmf_attribute_t *item, void *data, int size) MMHandleType mmf_attrs_new(int count) { - return_val_if_fail(count > 0, 0); mmf_attrs_t *attrs; - attrs = (mmf_attrs_t *) malloc(sizeof(mmf_attrs_t)); + return_val_if_fail(count > 0, 0); + + attrs = (mmf_attrs_t *) malloc(sizeof(mmf_attrs_t)); if (attrs == NULL) { debug_error("malloc failed"); return 0; @@ -539,13 +563,14 @@ MMHandleType mmf_attrs_new_from_data(const char *name, mmf_attrs_commit_func_t commit_func, void *commit_param) { - return_val_if_fail(info && count > 0, 0); MMHandleType h; mmf_attrs_t *attrs; + return_val_if_fail(info && count > 0, NULL); + h = mmf_attrs_new(count); if (!h) { - return 0; + return NULL; } mmf_attrs_init(h, info, count); attrs = (mmf_attrs_t *) h; @@ -559,33 +584,36 @@ MMHandleType mmf_attrs_new_from_data(const char *name, void mmf_attrs_free(MMHandleType h) { - return_if_fail(h); mmf_attrs_t *attrs = (mmf_attrs_t *) h; - if (attrs) { - if (attrs->name) { - free(attrs->name); - attrs->name = NULL; - } - if (attrs->items) { - int i; - for (i = 0; i < attrs->count; i++) { - mmf_attribute_clear(&attrs->items[i]); - } - free(attrs->items); - attrs->items = NULL; + + return_if_fail(h); + + if (attrs->name) { + free(attrs->name); + attrs->name = NULL; + } + + if (attrs->items) { + int i; + for (i = 0; i < attrs->count; i++) { + mmf_attribute_clear(&attrs->items[i]); } - free(attrs); + free(attrs->items); + attrs->items = NULL; } + + free(attrs); } int mmf_attrs_init(MMHandleType h, mmf_attrs_construct_info_t *info, int count) { - return_val_if_fail(h && info && count > 0, -1); mmf_attrs_t *attrs = (mmf_attrs_t *) h; mmf_attribute_t *item = NULL; int i; int size = 0; + return_val_if_fail(h && info && count > 0, -1); + for (i = 0; i < count; i++) { item = &attrs->items[i]; @@ -637,13 +665,13 @@ int mmf_attrs_init(MMHandleType h, mmf_attrs_construct_info_t *info, int count) int mmf_attrs_commit(MMHandleType h) { - return_val_if_fail(h, -1); - mmf_attrs_t *attrs = (mmf_attrs_t *)h; mmf_attribute_t *item = NULL; int i; int ret = 0; + return_val_if_fail(h, -1); + for (i = 0; i < attrs->count; ++i) { item = &attrs->items[i]; @@ -718,17 +746,21 @@ int mmf_attrs_commit_err(MMHandleType h, char **err_attr_name) int mmf_attrs_set_valid_type(MMHandleType h, int idx, int v_type) { + mmf_attrs_t *attrs = (mmf_attrs_t *) h; + return_val_if_fail(h, -1); return_val_if_fail(idx >= 0, -1); - mmf_attrs_t *attrs = (mmf_attrs_t *) h; + return mmf_value_spec_init(&attrs->items[idx].value_spec, v_type); } int mmf_attrs_set_valid_range(MMHandleType h, int idx, int min, int max, int dval) { + mmf_attrs_t *attrs = (mmf_attrs_t *) h; + return_val_if_fail(h, -1); return_val_if_fail(idx >= 0, -1); - mmf_attrs_t *attrs = (mmf_attrs_t *) h; + mmf_value_spec_clear(&attrs->items[idx].value_spec); assert(attrs->items[idx].value_spec.type == MMF_VALUE_SPEC_INT_RANGE); return mmf_value_spec_set_int_range(&attrs->items[idx].value_spec, min, max, dval); @@ -736,9 +768,11 @@ int mmf_attrs_set_valid_range(MMHandleType h, int idx, int min, int max, int dva int mmf_attrs_set_valid_array(MMHandleType h, int idx, const int *array, int count, int dval) { + mmf_attrs_t *attrs = (mmf_attrs_t *) h; + return_val_if_fail(h, -1); return_val_if_fail(idx >= 0, -1); - mmf_attrs_t *attrs = (mmf_attrs_t *) h; + mmf_value_spec_clear(&attrs->items[idx].value_spec); assert(attrs->items[idx].value_spec.type == MMF_VALUE_SPEC_INT_ARRAY); return mmf_value_spec_set_int_array(&attrs->items[idx].value_spec, array, count, dval); @@ -746,9 +780,11 @@ int mmf_attrs_set_valid_array(MMHandleType h, int idx, const int *array, int cou int mmf_attrs_set_valid_double_range(MMHandleType h, int idx, double min, double max, double dval) { + mmf_attrs_t *attrs = (mmf_attrs_t *) h; + return_val_if_fail(h, -1); return_val_if_fail(idx >= 0, -1); - mmf_attrs_t *attrs = (mmf_attrs_t *) h; + mmf_value_spec_clear(&attrs->items[idx].value_spec); assert(attrs->items[idx].value_spec.type == MMF_VALUE_SPEC_DOUBLE_RANGE); return mmf_value_spec_set_double_range(&attrs->items[idx].value_spec, min, max, dval); @@ -756,9 +792,11 @@ int mmf_attrs_set_valid_double_range(MMHandleType h, int idx, double min, double int mmf_attrs_set_valid_double_array(MMHandleType h, int idx, const double *array, int count, double dval) { + mmf_attrs_t *attrs = (mmf_attrs_t *) h; + return_val_if_fail(h, -1); return_val_if_fail(idx >= 0, -1); - mmf_attrs_t *attrs = (mmf_attrs_t *) h; + mmf_value_spec_clear(&attrs->items[idx].value_spec); assert(attrs->items[idx].value_spec.type == MMF_VALUE_SPEC_DOUBLE_ARRAY); return mmf_value_spec_set_double_array(&attrs->items[idx].value_spec, array, count, dval); diff --git a/packaging/libmm-common.spec b/packaging/libmm-common.spec index c29614f..a7bd339 100644 --- a/packaging/libmm-common.spec +++ b/packaging/libmm-common.spec @@ -1,6 +1,6 @@ Name: libmm-common Summary: Multimedia Framework Common Lib -Version: 0.2.115 +Version: 0.2.116 Release: 0 Group: Multimedia/Libraries License: Apache-2.0 -- 2.7.4