sl@0: /* Copyright (c) 2009 The Khronos Group Inc. sl@0: * Portions copyright (c) 2009-2010 Nokia Corporation and/or its subsidiary(-ies) sl@0: * sl@0: * Permission is hereby granted, free of charge, to any person obtaining a sl@0: * copy of this software and/or associated documentation files (the sl@0: * "Materials"), to deal in the Materials without restriction, including sl@0: * without limitation the rights to use, copy, modify, merge, publish, sl@0: * distribute, sublicense, and/or sell copies of the Materials, and to sl@0: * permit persons to whom the Materials are furnished to do so, subject to sl@0: * the following conditions: sl@0: * sl@0: * The above copyright notice and this permission notice shall be included sl@0: * in all copies or substantial portions of the Materials. sl@0: * sl@0: * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, sl@0: * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF sl@0: * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. sl@0: * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY sl@0: * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, sl@0: * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE sl@0: * MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. sl@0: */ sl@0: sl@0: #ifndef OWFATTRIBUTES_H_ sl@0: #define OWFATTRIBUTES_H_ sl@0: sl@0: #include "owftypes.h" sl@0: #include "owfutils.h" sl@0: sl@0: sl@0: #ifdef __cplusplus sl@0: extern "C" sl@0: { sl@0: #endif sl@0: sl@0: sl@0: /*! sl@0: * \file Attribute interface sl@0: * sl@0: * Attribute interface provides mechanism for controlled reading/writing sl@0: * access of different object properties in WFC and WFD APIs by proxying sl@0: * object instances' properties. sl@0: * sl@0: */ sl@0: #define RANGE_UNDEFINED 0xFFFFFFFF sl@0: #define ATTR_LENGTH_BITS 20 sl@0: #define MAX_ATTR_LENGTH (1 << ATTR_LENGTH_BITS)-1 sl@0: #define NUM_ATTR_VALUE_COPIES 3 sl@0: #define COMMITTED_ATTR_VALUE_INDEX 0 sl@0: #define WORKING_ATTR_VALUE_INDEX 1 sl@0: #define SNAPSHOT_ATTR_VALUE_INDEX 2 sl@0: #define COMMIT_ATTR_DIRECT_FROM_WORKING -1 sl@0: sl@0: typedef enum { sl@0: ATTR_ERROR_NONE = 0, sl@0: ATTR_ERROR_NOT_FOUND = -1, sl@0: ATTR_ERROR_ALREADY_IN_USE = -2, sl@0: ATTR_ERROR_INVALID_ATTRIBUTE= -3, sl@0: ATTR_ERROR_INVALID_VALUE = -4, sl@0: ATTR_ERROR_INVALID_ARGUMENT = -5, sl@0: ATTR_ERROR_INVALID_CONTEXT = -6, sl@0: ATTR_ERROR_NO_MEMORY = -7, sl@0: ATTR_ERROR_INSANE = -8, sl@0: ATTR_ERROR_ACCESS_DENIED = -9, sl@0: ATTR_ERROR_INVALID_TYPE = -10, sl@0: ATTR_ERROR_CANT_HANDLE = -11 sl@0: } OWF_ATTRIBUTE_LIST_STATUS; sl@0: sl@0: /* Attribute value element types */ sl@0: typedef enum { sl@0: AT_UNDEFINED = 0, sl@0: AT_INTEGER = 1, sl@0: AT_FLOAT = 2, sl@0: AT_BOOLEAN = 3 sl@0: } OWF_ATTRIBUTE_TYPE; sl@0: sl@0: sl@0: /* sl@0: * Attribute information (header) sl@0: * sl@0: * Dirty field is internal. Do not fiddle with it. sl@0: * sl@0: * Comment on use of bitfields: sl@0: * 1: It stops generic use of split dirty flag sl@0: * 2: Some compilers will not reorder members to merge length into earier fields. sl@0: */ sl@0: typedef struct { sl@0: OWFuint type: 2; sl@0: OWFuint dirty: 1; sl@0: OWFuint dirtysnapshot: 1; sl@0: OWFuint readonly: 1; sl@0: OWFuint size; /* Size of one primitive */ sl@0: OWFuint length: ATTR_LENGTH_BITS; /* Number of primitives in vector */ sl@0: } OWF_ATTRIBUTE_INFO; sl@0: sl@0: /* sl@0: * Attribute may be a scalar (1-element) or vector (n-element), sl@0: * containing a reference to either integer, boolean or float value(s). sl@0: * Attribute type cannot be changed after it has been initialized. sl@0: * sl@0: * Attributes don't own the data they refer to; attributes only sl@0: * control the reading and writing of the data they refer to. sl@0: */ sl@0: sl@0: typedef OWFfloat* OWF_FLOAT_REF; sl@0: typedef OWFint* OWF_INT_REF; sl@0: typedef OWFboolean* OWF_BOOL_REF; sl@0: typedef OWFfloat* OWF_FLOAT_VECTOR_REF; sl@0: typedef OWFint* OWF_INT_VECTOR_REF; sl@0: sl@0: typedef struct { sl@0: OWF_ATTRIBUTE_INFO attr_info; sl@0: union { sl@0: OWF_INT_REF int_value; sl@0: OWF_FLOAT_REF float_value; sl@0: void* gen_ptr; sl@0: /* sl@0: OWF_INT_VECTOR_REF int_vector_value; sl@0: OWF_FLOAT_VECTOR_REF float_vector_value; sl@0: */ sl@0: } attr_value[NUM_ATTR_VALUE_COPIES]; sl@0: } OWF_ATTRIBUTE; sl@0: sl@0: /* sl@0: * Attribute list/context. Container for attributes. sl@0: * sl@0: * One list/context can contain constant number of sl@0: * attributes (amount of which is defined at construction sl@0: * time) sl@0: */ sl@0: typedef struct { sl@0: OWFint range_start; sl@0: OWFint range_end; sl@0: OWF_ATTRIBUTE* attributes; sl@0: OWF_ATTRIBUTE_LIST_STATUS last_error; sl@0: } OWF_ATTRIBUTE_LIST; sl@0: sl@0: /* sl@0: * \brief Initializes attribute context sl@0: * sl@0: * \param aContext Attribute context to initialize sl@0: * \param aStart Attribute range start sl@0: * \param aEnd Attribute range end. Must be greater than range start. sl@0: * sl@0: * \return ERR_INVALID_ARGUMENT sl@0: * ERR_NO_MEMORY sl@0: */ sl@0: OWF_API_CALL void sl@0: OWF_AttributeList_Create(OWF_ATTRIBUTE_LIST* aContext, sl@0: OWFint aStart, sl@0: OWFint aEnd); sl@0: sl@0: /* sl@0: * \brief Destroy attribute context and free any resources (memory sl@0: * blocks) allocated to it. All attributes are destroyed. sl@0: * sl@0: * \param aContext Attribute context to destroy sl@0: * sl@0: * \return ERR_INVALID_ARGUMENT sl@0: * ERR_INVALID_CONTEXT sl@0: */ sl@0: OWF_API_CALL void sl@0: OWF_AttributeList_Destroy(OWF_ATTRIBUTE_LIST* aContext); sl@0: sl@0: /* sl@0: * \brief Gets the last error from the attribute. sl@0: * Resets the error state. sl@0: * sl@0: * \return Error code. sl@0: * sl@0: */ sl@0: OWF_API_CALL OWF_ATTRIBUTE_LIST_STATUS sl@0: OWF_AttributeList_GetError(OWF_ATTRIBUTE_LIST* aContext); sl@0: sl@0: /* sl@0: * \brief Intialize integer attribute sl@0: * sl@0: * \param aContext Attibute context sl@0: * \param aName Attribute name sl@0: * \param aValue Attribute initial value sl@0: * \param aRdOnly Read-only flag sl@0: * sl@0: * \return ERR_INVALID_ARGUMENT sl@0: * ERR_INVALID_ATTRIBUTE sl@0: * ERR_INVALID_CONTEXT sl@0: */ sl@0: OWF_API_CALL void sl@0: OWF_Attribute_Initi(OWF_ATTRIBUTE_LIST* aContext, sl@0: OWFint aName, sl@0: OWF_INT_REF aValue, sl@0: OWFboolean aRdOnly); sl@0: sl@0: /* sl@0: * \brief Initialize float attribute sl@0: * sl@0: * \param aContext Attribute context sl@0: * \param aName Attribute name sl@0: * \param aValue Initial value for attribute sl@0: * \param aRdOnly Read-only flag sl@0: * sl@0: * \return ERR_INVALID_ARGUMENT sl@0: * ERR_INVALID_ATTRIBUTE sl@0: * ERR_INVALID_CONTEXT sl@0: */ sl@0: OWF_API_CALL void sl@0: OWF_Attribute_Initf(OWF_ATTRIBUTE_LIST* aContext, sl@0: OWFint aName, sl@0: OWF_FLOAT_REF aValue, sl@0: OWFboolean aRdOnly); sl@0: sl@0: /* sl@0: * \brief Initialize boolean attribute sl@0: * sl@0: * \param aContext Attribute context sl@0: * \param aName Attribute name sl@0: * \param aValue Initial value for attribute sl@0: * \param aRdOnly Read-only flag sl@0: * sl@0: * \return ERR_INVALID_ARGUMENT sl@0: * ERR_INVALID_ATTRIBUTE sl@0: * ERR_INVALID_CONTEXT sl@0: */ sl@0: OWF_API_CALL void sl@0: OWF_Attribute_Initb(OWF_ATTRIBUTE_LIST* aContext, sl@0: OWFint aName, sl@0: OWF_BOOL_REF aValue, sl@0: OWFboolean aRdOnly); sl@0: sl@0: /* sl@0: * \brief Initialize vector attribute sl@0: * sl@0: * \param aContext Attribute context sl@0: * \param aName Attribute name sl@0: * \param aLength Attribute (vector) length sl@0: * \param aValues Initial value(s) for attribute sl@0: * \param aRdOnly Read-only flag sl@0: * sl@0: * \return ERR_INVALID_ARGUMENT sl@0: * ERR_INVALID_ATTRIBUTE sl@0: * ERR_INVALID_CONTEXT sl@0: * ERR_CANT_HANDLE sl@0: */ sl@0: OWF_API_CALL void sl@0: OWF_Attribute_Initiv(OWF_ATTRIBUTE_LIST* aContext, sl@0: OWFint aName, sl@0: OWFint aLength, sl@0: OWF_INT_VECTOR_REF aValues, sl@0: OWFboolean aRdOnly); sl@0: sl@0: /* sl@0: * \brief Initialize vector attribute sl@0: * sl@0: * \param aContext Attribute context sl@0: * \param aName Attribute name sl@0: * \param aLength Attribute (vector) length sl@0: * \param aValues Initial value(s) for attributes sl@0: * \param aRdOnly Read-only flag sl@0: * sl@0: * \return sl@0: */ sl@0: OWF_API_CALL void sl@0: OWF_Attribute_Initfv(OWF_ATTRIBUTE_LIST* aContext, sl@0: OWFint aName, sl@0: OWFint aLength, sl@0: OWF_FLOAT_VECTOR_REF aValues, sl@0: OWFboolean aRdOnly); sl@0: sl@0: /* sl@0: * \brief Get attribute integer value. sl@0: * sl@0: * \param aContext Attribute context sl@0: * \param aName Attribute name sl@0: * sl@0: * \return Attribute integer value (floats are floor()ed). For vector sl@0: * attributes the return value will be error ERR_INVALID_TYPE. sl@0: * ERR_INVALID_ATTRIBUTE sl@0: * ERR_INVALID_CONTEXT sl@0: */ sl@0: OWF_API_CALL OWFint sl@0: OWF_Attribute_GetValuei(OWF_ATTRIBUTE_LIST* aContext, sl@0: OWFint aName); sl@0: sl@0: /* sl@0: * \brief Return boolean attribute value sl@0: * sl@0: * \param aContext Attribute context sl@0: * \param aName Attribute name sl@0: * sl@0: * \return Attribute value sl@0: * ERR_INVALID_ATTRIBUTE sl@0: * ERR_INVALID_TYPE sl@0: */ sl@0: OWF_API_CALL OWFboolean sl@0: OWF_Attribute_GetValueb(OWF_ATTRIBUTE_LIST* aContext, sl@0: OWFint aName); sl@0: sl@0: /* sl@0: * \brief Get attribute float value sl@0: * sl@0: * \param aContext sl@0: * \param aName sl@0: * \param aValue sl@0: * sl@0: * \return Attribute sl@0: */ sl@0: OWF_API_CALL OWFfloat sl@0: OWF_Attribute_GetValuef(OWF_ATTRIBUTE_LIST* aContext, sl@0: OWFint aName); sl@0: sl@0: /* sl@0: * \brief sl@0: * sl@0: * \param aContext sl@0: * \param aName sl@0: * \param aSize sl@0: * \param aValue sl@0: * sl@0: * \return sl@0: */ sl@0: OWF_API_CALL OWFint sl@0: OWF_Attribute_GetValueiv(OWF_ATTRIBUTE_LIST* aContext, sl@0: OWFint aName, sl@0: OWFint aLength, sl@0: OWFint* aValue); sl@0: sl@0: /* sl@0: * \brief sl@0: * sl@0: * \param aContext sl@0: * \param aName sl@0: * \param aSize sl@0: * \param aValue sl@0: * sl@0: * \return sl@0: */ sl@0: OWF_API_CALL OWFint sl@0: OWF_Attribute_GetValuefv(OWF_ATTRIBUTE_LIST* aContext, sl@0: OWFint aName, sl@0: OWFint aLength, sl@0: OWFfloat* aValue); sl@0: sl@0: /* sl@0: * \brief sl@0: * sl@0: * \param aContext sl@0: * \param aName sl@0: * \param aValue sl@0: * sl@0: * \return sl@0: */ sl@0: OWF_API_CALL void sl@0: OWF_Attribute_SetValuei(OWF_ATTRIBUTE_LIST* aContext, sl@0: OWFint aName, sl@0: OWFint aValue); sl@0: sl@0: /* sl@0: * \brief sl@0: * sl@0: * \param aContext sl@0: * \param aName sl@0: * \param aValue sl@0: * sl@0: * \return sl@0: */ sl@0: OWF_API_CALL void sl@0: OWF_Attribute_SetValuef(OWF_ATTRIBUTE_LIST* aContext, sl@0: OWFint aName, sl@0: OWFfloat aValue); sl@0: sl@0: /* sl@0: * \brief sl@0: * sl@0: * \param sl@0: * \param sl@0: * \param sl@0: * sl@0: * \return sl@0: */ sl@0: OWF_API_CALL void sl@0: OWF_Attribute_SetValueb(OWF_ATTRIBUTE_LIST* aContext, sl@0: OWFint aName, sl@0: OWFboolean aValue); sl@0: sl@0: /* sl@0: * \brief sl@0: * sl@0: * \param sl@0: * \param sl@0: * \param sl@0: * sl@0: * \return sl@0: */ sl@0: OWF_API_CALL void sl@0: OWF_Attribute_SetValueiv(OWF_ATTRIBUTE_LIST* aContext, sl@0: OWFint aName, sl@0: OWFint aLength, sl@0: const OWFint* aValue); sl@0: sl@0: /* sl@0: * \brief sl@0: * sl@0: * \param sl@0: * \param sl@0: * \param sl@0: * sl@0: * \return sl@0: */ sl@0: OWF_API_CALL void sl@0: OWF_Attribute_SetValuefv(OWF_ATTRIBUTE_LIST* aContext, sl@0: OWFint aName, sl@0: OWFint aLength, sl@0: const OWFfloat* aValue); sl@0: sl@0: sl@0: OWF_API_CALL void sl@0: OWF_AttributeList_Commit(OWF_ATTRIBUTE_LIST* aContext, OWFint aStart, OWFint aEnd, OWFint aCopyTo ); sl@0: sl@0: sl@0: #ifdef __cplusplus sl@0: } sl@0: #endif sl@0: sl@0: #endif /* ATTRIBUTES_H_ */