4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Jonghyuk Choi <jhchoi.choi@samsung.com>
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
24 #ifndef __MM_ATTRS_H__
25 #define __MM_ATTRS_H__
41 * @brief This file declares data structures and functions of attribute library.
44 This part describes the APIs with respect to Multimedia Attribute Library.
45 The Attribute Library is a set of attribute. An attribute contains a value,
46 access flags and it's validation information. This document explains how to
47 manipulate an attribute in the Attribute Library.
52 * Enumeration for attribute values types.
55 MM_ATTRS_TYPE_INVALID = -1, /**< Type is invalid */
56 MM_ATTRS_TYPE_INT, /**< Integer type attribute */
57 MM_ATTRS_TYPE_DOUBLE, /**< Double type attribute */
58 MM_ATTRS_TYPE_STRING, /**< UTF-8 String type attribute */
59 MM_ATTRS_TYPE_DATA, /**< Pointer type attribute */
60 MM_ATTRS_TYPE_NUM, /**< Number of attribute type */
64 * Enumeration for attribute validation type.
67 MM_ATTRS_VALID_TYPE_INVALID = -1, /**< Invalid validation type */
68 MM_ATTRS_VALID_TYPE_NONE, /**< Do not check validity */
69 MM_ATTRS_VALID_TYPE_INT_ARRAY, /**< validity checking type of integer array */
70 MM_ATTRS_VALID_TYPE_INT_RANGE, /**< validity checking type of integer range */
71 MM_ATTRS_VALID_TYPE_DOUBLE_ARRAY, /**< validity checking type of double array */
72 MM_ATTRS_VALID_TYPE_DOUBLE_RANGE, /**< validity checking type of double range */
76 * Enumeration for attribute access flag.
79 MM_ATTRS_FLAG_NONE = 0, /**< None flag is set */
80 MM_ATTRS_FLAG_READABLE = 1 << 0, /**< Readable */
81 MM_ATTRS_FLAG_WRITABLE = 1 << 1, /**< Writable */
82 MM_ATTRS_FLAG_MODIFIED = 1 << 2, /**< Modified */
84 MM_ATTRS_FLAG_RW = MM_ATTRS_FLAG_READABLE | MM_ATTRS_FLAG_WRITABLE, /**< Readable and Writable */
94 MMAttrsValidType validity_type;
97 * a union that describes validity of the attribute.
98 * Only when type is 'MM_ATTRS_TYPE_INT' or 'MM_ATTRS_TYPE_DOUBLE',
99 * the attribute can have validity.
103 * Validity structure for integer array.
106 int *array; /**< a pointer of array */
107 int count; /**< size of array */
108 int dval; /**< default value */
112 * Validity structure for integer range.
115 int min; /**< minimum range */
116 int max; /**< maximum range */
117 int dval; /**< default value */
121 * Validity structure for double array.
124 double *array; /**< a pointer of array */
125 int count; /**< size of array */
126 double dval; /**< default value */
130 * Validity structure for double range.
133 double min; /**< minimum range */
134 double max; /**< maximum range */
135 double dval; /**< default value */
155 * Construction information structure.
159 MMAttrsType value_type;
162 } MMAttrsConstructInfo;
165 * Attributes commit callback function type.
167 * @param index [in] Index of attribute
168 * @param name [in] Name of attribute
169 * @param value [in] Value of attribute
170 * @param user_param [in] User parameter
172 * @return This callback function should return true on success, or false on failure.
175 typedef bool (*mm_attrs_commit_callback) (int index, const char *name, const MMAttrsValue *value, void *user_param);
178 #define __NULL_TERMINATED __attribute__((__sentinel__))
180 #define __NULL_TERMINATED
184 * This function is to create handle of attributes list and register the commit callback.
186 * @param info [in] Attributes construction information
187 * @param count [in] The number of attributes
188 * @param name [in] Name of the attributes list (optional, this can be NULL)
189 * @param callback [in] Commit callback (optional, this can be NULL)
190 * @param user_param [in] User param of the commit callback (optional, this can be NULL)
191 * @param attrs [out] Handle of attributes list
193 * @return This function returns MM_ERROR_NONE on success, or negative value with error code.
194 * @see mm_attrs_commit_all
195 * @see mm_attrs_commit
198 int mm_attrs_new(MMAttrsConstructInfo *info, int count, const char *name,
199 mm_attrs_commit_callback callback, void *user_param, MMHandleType *attrs);
203 * This function releases resources and destroy the attributes handle created by mm_attrs_new.
205 * @param attrs [in] Handle of attributes list
208 void mm_attrs_free(MMHandleType attrs);
212 * This function is to commit all the attributes.
214 * @param attrs [in] Handle of attributes list
216 * @return This function returns MM_ERROR_NONE on success, or negative value with error code.
218 * @see mm_attrs_commit
220 int mm_attrs_commit_all(MMHandleType attrs);
224 * This function is to commit the attribute.
226 * @param attrs [in] Handle of attributes list
227 * @param index [in] Index of attribute
229 * @return This function returns MM_ERROR_NONE on success, or negative value with error code.
231 * @see mm_attrs_commit_all
233 int mm_attrs_commit(MMHandleType attrs, int index);
237 * This function is to set the integer value to the attribute by name.
239 * @param attrs [in] Handle of attributes list
240 * @param attr_name [in] Name of attribute
241 * @param val [in] Integer value to set
243 * @return This function returns MM_ERROR_NONE on success, or negative value with error code.
245 int mm_attrs_set_int_by_name(MMHandleType attrs, const char *attr_name, int val);
249 * This function is to get the number of attribute in the MMAttrs.
251 * @param attrs [in] Handle of attributes list
252 * @param size [out] Number of attributes
254 * @return This function returns the number of attributes in the attribute list.
256 int mm_attrs_get_size(MMHandleType attrs, int *size);
260 * This function is to get the name of attribute at the given index.
262 * @param attrs [in] Handle of attributes list
263 * @param index [in] Index of attribute
264 * @param name [out] Name of attribute
266 * @return This function returns the name of attribute on success, or NULL
269 int mm_attrs_get_name(MMHandleType attrs, int index, char **name);
273 * This function is to get the index of attribute at the given name.
275 * @param attrs [in] Handle of attributes list
276 * @param attr_name [in] Name of attribute
277 * @param index [out] Index of attribute
279 * @return This function returns the index of the attribute on success,
280 * or negative value on failure.
282 int mm_attrs_get_index(MMHandleType attrs, const char *attr_name, int *index);
286 * This function is to get the integer value from the attribute by name.
288 * @param attrs [in] Handle of attributes list
289 * @param attr_name [in] Name of attribute
290 * @param val [out] Value of attribute
292 * @return This function returns attribute value
294 int mm_attrs_get_int_by_name(MMHandleType attrs, const char *attr_name, int *val);
298 * This function is to set the string to attribute by name.
300 * @param attrs [in] MMAttrs handle
301 * @param attr_name [in] Name of attribute
302 * @param string [in] String value to set
304 * @return This function returns MM_ERROR_NONE on success, or negative value with error code.
306 int mm_attrs_set_string_by_name(MMHandleType attrs, const char *attr_name, const char *string);
310 * This function is to get the string from the attribute by name.
312 * @param attrs [in] Handle of attributes list
313 * @param attr_name [in] Name of attribute
314 * @param val [out] Value of attribute
316 * @return This function returns the string value of attribute on success,
319 int mm_attrs_get_string_by_name(MMHandleType attrs, const char *attr_name, char **val);
323 * This function is to set the data to the attribute by name.
325 * @param attrs [in] Handle of attributes list
326 * @param attr_name [in] Name of attribute
327 * @param data [in] Data pointer to set
328 * @param size [in] Data size to set
330 * @return This function returns MM_ERROR_NONE on success, or negative value with error code.
332 int mm_attrs_set_data_by_name(MMHandleType attrs, const char *attr_name, void *data, int size);
336 * This function is to get the data from the attribute by name.
338 * @param attrs [in] Handle of attributes list
339 * @param attr_name [in] Name of attribute
340 * @param data [out] Data pointer to set
342 * @return This function returns user defined value on success, or NULL
345 int mm_attrs_get_data_by_name(MMHandleType attrs, const char *attr_name, void **data);
349 * This function is to retrieve type of attribute.
351 * @param attrs [in] List of attributes
352 * @param index [in] Index of attribute
353 * @param attrtype [out] Type of attribute
355 * @return This function returns MM_ERROR_NONE.
358 int mm_attrs_get_type(MMHandleType attrs, int index, MMAttrsType *attrtype);
362 * This function is to get flags of attribute with given index.
364 * @param attrs [in] List of attributes
365 * @param index [in] Index of attribute
366 * @param flags [out] Flags of attribute
368 * @return This function returns MM_ERROR_NONE on success, or negative value with error code.
371 int mm_attrs_get_flags(MMHandleType attrs, int index, int *flags);
375 * This function is to get valid value type of attribute with given index.
377 * @param attrs [in] List of attributes
378 * @param index [in] Index of attribute
379 * @param type [out] Valid value type of attribute
381 * @return This function returns MM_ERROR_NONE on success, or negative value with error code.
384 int mm_attrs_get_valid_type(MMHandleType attrs, int index, MMAttrsValidType *type);
388 * This function is to get valid range of attribute with given index.
390 * @param attrs [in] List of attributes
391 * @param index [in] Index of attribute
392 * @param min [out] Minimum value of the valid range
393 * @param max [out] Maximum value of the valid range
395 * @return This function returns MM_ERROR_NONE on success, or negative value with error code.
397 int mm_attrs_get_valid_range(MMHandleType attrs, int index, int *min, int *max);
401 * This function is to get valid array of attribute with given index.
403 * @param attrs [in] List of attributes
404 * @param index [in] Index of attribute
405 * @param count [out] The number of array
406 * @param array [out] Valid array of attribute
408 * @return This function returns MM_ERROR_NONE on success, or negative value with error code.
410 int mm_attrs_get_valid_array(MMHandleType attrs, int index, int *count, int **array);
414 * This function is to set integer value to attribute with given index.
416 * @param attrs [in] List of attributes
417 * @param index [in] Index of attribute
418 * @param val [in] Integer value to set
420 * @return This function returns MM_ERROR_NONE on success, or negative value with error code.
421 * @see mm_attrs_get_int
423 int mm_attrs_set_int(MMHandleType attrs, int index, int val);
427 * This function is to get integer value to attribute with given index.
429 * @param attrs [in] List of attributes
430 * @param index [in] Index of attribute
431 * @param val [out] Integer value of attribute
433 * @return This function returns MM_ERROR_NONE on success, or negative value with error code.
434 * @remarks If type of attributes is not an integer type, the value which is returned by this function is meaningless.
435 * @see mm_attrs_get_int
437 int mm_attrs_get_int(MMHandleType attrs, int index, int *val);
441 * This function is to set double value to attribute with given index.
443 * @param attrs [in] List of attributes
444 * @param index [in] Index of attribute
445 * @param val [in] Integer value to set
447 * @return This function returns MM_ERROR_NONE on success, or negative value with error code.
448 * @see mm_attrs_get_double
450 int mm_attrs_set_double(MMHandleType attrs, int index, double val);
454 * This function is to set the double value to the attribute by name.
456 * @param attrs [in] Handle of attributes list
457 * @param attr_name [in] Name of attribute
458 * @param val [in] Integer value to set
460 * @return This function returns MM_ERROR_NONE on success, or negative value with error code.
462 int mm_attrs_set_double_by_name(MMHandleType attrs, const char *attr_name, double val);
466 * This function is to get double value to attribute with given index.
468 * @param attrs [in] List of attributes
469 * @param index [in] Index of attribute
470 * @param attrval [out] Double value of attribute on success, or invalid value
472 * @return This function returns MM_ERROR_NONE on success, or negative value with error code.
473 * @see mm_attrs_set_double
475 int mm_attrs_get_double(MMHandleType attrs, int index, double *attrval);
479 * This function is to get the double value from the attribute by name.
481 * @param attrs [in] Handle of attributes list
482 * @param attr_name [in] Name of attribute
483 * @param val [out] Double value to set
485 * @return This function returns attribute value
487 int mm_attrs_get_double_by_name(MMHandleType attrs, const char *attr_name, double *val);
491 * This function is to set string to attribute with given index.
493 * @param attrs [in] Handle of attributes list
494 * @param index [in] Index of attribute
495 * @param string [in] String to set
496 * @param size [in] Length of string to set
498 * @return This function returns MM_ERROR_NONE on success, or negative value with error code.
499 * @see mm_attrs_get_string
501 int mm_attrs_set_string(MMHandleType attrs, int index, const char *string, int size);
505 * This function is to get string to attribute with given index.
507 * @param attrs [in] Handle of attributes list
508 * @param index [in] Index of attribute
509 * @param sval [in] Placeholder to output string buffer
510 * @param size [in] The field contains number of characters filled in the buffer
512 * @return This function returns MM_ERROR_NONE on success, or negative value with error code.
513 * @remarks Application would be responsible for managing/releasing the string
514 * @see mm_attrs_set_string
516 int mm_attrs_get_string(MMHandleType attrs, int index, char **sval, int *size);
520 * This function is to set pointer to attribute with given index.
522 * @param attrs [in] Handle of attributes list
523 * @param index [in] Index of attribute
524 * @param data [in] Data to set
525 * @param size [in] Length of input data
527 * @return This function returns MM_ERROR_NONE on success, or negative value with error code.
528 * @remarks Data type is the reference to memory which is allocated by user. The allocated memory must be freed by user.
529 * @see mm_attrs_get_data
531 int mm_attrs_set_data(MMHandleType attrs, int index, void *data, int size);
535 * This function is to get pointer to attribute with given index.
537 * @param attrs [in] Handle of attributes list
538 * @param index [in] Index of attribute
539 * @param data [out] Placeholder to output data buffer
540 * @param size [out] The field contains number of bytes filled in the buffer
542 * @return This function returns MM_ERROR_NONE on success, or negative value with error code.
543 * @remarks Application would be responsible for managing/releasing data
544 * @see mm_attrs_set_data
546 int mm_attrs_get_data(MMHandleType attrs, int index, void **data, int *size);
550 * A function to get information of the attribute
552 * @param attrs [in] Handle of attributes list
553 * @param index [in] Index of attribute
554 * @param info [out] Information of the attribute
556 * @return This function returns MM_ERROR_NONE on success, or negative value with error code.
558 int mm_attrs_get_info(MMHandleType attrs, int index, MMAttrsInfo *info);
562 * This function is to get array of attribute with given name.
564 * @param attrs [in] Handle of attributes list
565 * @param attr_name [in] Name of attribute
566 * @param info [out] Information of the attribute
568 * @return This function returns MM_ERROR_NONE on success, or negative value with error code.
570 int mm_attrs_get_info_by_name(MMHandleType attrs, const char *attr_name, MMAttrsInfo *info);
574 * Sets properties on an object.
576 * @param attrs [in] Handle of attributes list
577 * @param err_attr_name [out] Name of attributes that occurs error. Free this variable after use
578 * @param attribute_name [in] Name of the first property to set
579 * @param ... [in] Value for the first property, followed optionally by more
580 * name/value pairs, followed by %NULL
582 * @return This function returns MM_ERROR_NONE on success, or negative value with error code.
583 * @remarks Multiple setter of attribute
584 * @see mm_attrs_set_int, mm_attrs_set_string, ...
586 int mm_attrs_multiple_set(MMHandleType attrs, char **err_attr_name, const char *attribute_name, ...) __NULL_TERMINATED;
590 * Gets properties on an object.
592 * @param attrs [in] Handle of attributes list
593 * @param err_attr_name [out] Name of attributes that occurs error. Free this variable after use
594 * @param attribute_name [in] Name of the first property to set
595 * @param ... [in] Value for the first property, followed optionally by more
596 * name/value pairs, followed by %NULL
598 * @return This function returns MM_ERROR_NONE on success, or negative value with error code.
599 * @remarks Multiple setter of attribute
600 * @see mm_attrs_set_int, mm_attrs_set_string, ...
602 int mm_attrs_multiple_get(MMHandleType attrs, char **err_attr_name, const char *attribute_name, ...) __NULL_TERMINATED;
606 * Sets properties on an object with va_list param.
608 * @param attrs [in] Handle of attributes list
609 * @param err_attr_name [out] Name of attributes that occurs error. Free this variable after use
610 * @param attribute_name [in] Name of the first property to set
611 * @param var_args [in] Variable arguments
613 * @return This function returns MM_ERROR_NONE on success, or negative value with error code.
614 * @remarks Multiple setter of attribute
615 * @see mm_attrs_multiple_set
617 int mm_attrs_set_valist(MMHandleType attrs, char **err_attr_name, const char *attribute_name, va_list var_args);
621 * Gets properties on an object with va_list param.
623 * @param attrs [in] Handle of attributes list
624 * @param err_attr_name [out] Name of attributes that occurs error. Free this variable after use
625 * @param attribute_name [in] Name of the first property to set
626 * @param var_args [in] Variable arguments
628 * @return This function returns MM_ERROR_NONE on success, or negative value with error code.
629 * @remarks Multiple setter of attribute
630 * @see mm_attrs_multiple_get
632 int mm_attrs_get_valist(MMHandleType attrs, char **err_attr_name, const char *attribute_name, va_list var_args);
636 * This function is to set the valid attribute type.
638 * @param attrs [in] Handle of attributes list
639 * @param index [in] Index of attribute
640 * @param type [in] Type of attribute
642 * @return This function returns MM_ERROR_NONE on success, or negative value with error code.
644 int mm_attrs_set_valid_type(MMHandleType attrs, int index, MMAttrsValidType type);
648 * This function is to set the valid integer range to the attribute.
650 * @param attrs [in] Handle of attributes list
651 * @param index [in] Index of attribute
652 * @param min [in] Minimum value of the valid range
653 * @param max [in] Maximum value of the valid range
654 * @param dval [in] Default value
656 * @return This function returns MM_ERROR_NONE on success, or negative value with error code.
658 int mm_attrs_set_valid_range(MMHandleType attrs, int index, int min, int max, int dval);
662 * This function is to set the valid integer array to the attribute.
664 * @param attrs [in] Handle of attributes list
665 * @param index [in] Index of attribute
666 * @param array [in] Array contains integer values to set
667 * @param count [in] The number of items in array
668 * @param dval [in] Default value
670 * @return This function returns MM_ERROR_NONE on success, or negative value with error code.
672 int mm_attrs_set_valid_array(MMHandleType attrs, int index, const int *array, int count, int dval);
676 * This function is to set the valid double range to the attribute.
678 * @param attrs [in] Handle of attributes list
679 * @param index [in] Index of attribute
680 * @param min [in] Minimum value of the valid range
681 * @param max [in] Maximum value of the valid range
682 * @param dval [in] Default value
684 * @return This function returns MM_ERROR_NONE on success, or negative value with error code.
686 int mm_attrs_set_valid_double_range(MMHandleType attrs, int index, double min, double max, double dval);
690 * This function is to set the valid double array to the attribute.
692 * @param attrs [in] Handle of attributes list
693 * @param index [in] Index of attribute
694 * @param array [in] Array contains double values to set
695 * @param count [in] The number of items in array
696 * @param dval [in] Default value
698 * @return This function returns MM_ERROR_NONE on success, or negative value with error code.
700 int mm_attrs_set_valid_double_array(MMHandleType attrs, int index, const double *array, int count, double dval);
704 * This function is to check whether the attribute is modified
706 * @param attrs [in] Handle of attributes list
707 * @param index [in] Index of attribute
708 * @param modified [out] Modified or not (true = modified, false = not modified)
710 * @return This function returns MM_ERROR_NONE on success, or negative value with error code.
712 int mm_attrs_is_modified(MMHandleType attrs, int index, bool *modified);
716 * This function is to set the attribute to modified
718 * @param attrs [in] Handle of attributes list
719 * @param index [in] Index of attribute
721 * @return This function returns MM_ERROR_NONE on success, or negative value with error code.
723 int mm_attrs_set_modified(MMHandleType attrs, int index);
727 * This function is to set the attribute to read-only
729 * @param attrs [in] Handle of attributes list
730 * @param index [in] Index of attribute
732 * @return This function returns MM_ERROR_NONE on success, or negative value with error code.
734 int mm_attrs_set_readonly(MMHandleType attrs, int index);
738 * This function is to set the attribute to disabled
740 * @param attrs [in] Handle of attributes list
741 * @param index [in] Index of attribute
743 * @return This function returns MM_ERROR_NONE on success, or negative value with error code.
745 int mm_attrs_set_disabled(MMHandleType attrs, int index);
757 #endif /* __MM_ATTRS_H__ */