00001 /* 00002 * The information in this file is 00003 * Copyright(c) 2007 Ball Aerospace & Technologies Corporation 00004 * and is subject to the terms and conditions of the 00005 * GNU Lesser General Public License Version 2.1 00006 * The license text is available from 00007 * http://www.gnu.org/licenses/lgpl.html 00008 */ 00009 00010 #ifndef METADATA_H__ 00011 #define METADATA_H__ 00012 00013 #include "AppConfig.h" 00014 00015 class DataElement; 00016 class DynamicObject; 00017 00018 #ifdef __cplusplus 00019 extern "C" 00020 { 00021 #endif 00022 /** \addtogroup simple_api */ 00023 /*@{*/ 00024 00025 /** 00026 * @file Metadata.h 00027 * This file contains functions and type definitions for manipulating DataElement metadata. 00028 */ 00029 00030 /** 00031 * Create a new, blank DynamicObject. 00032 * 00033 * @return A DynamicObject which the caller owns and must be freed. 00034 * @see freeDynamicObject() 00035 */ 00036 EXPORT_SYMBOL DynamicObject* createDynamicObject(); 00037 00038 /** 00039 * Free a DynamicObject. 00040 * 00041 * Suitable for use as a cleanup callback. 00042 * 00043 * @param pDynamicObject 00044 * The DynamicObject to free. No error checking is performed on this value 00045 * and a \c NULL will cause a NOOP. 00046 */ 00047 EXPORT_SYMBOL void freeDynamicObject(DynamicObject* pDynamicObject); 00048 00049 /** 00050 * Get the metadata for a DataElement. 00051 * 00052 * @param pElement 00053 * The DataElement to access. 00054 * @return Pointer to the metadata object or a \c NULL if an error occurred. 00055 * This is a borrowed reference. 00056 */ 00057 EXPORT_SYMBOL DynamicObject* getDataElementMetadata(DataElement* pElement); 00058 00059 /** 00060 * Get the number of immediate child attributes. 00061 * 00062 * @param pMeta 00063 * The DynamicObject to access. 00064 * @return The number of immediate child elements in the specified DynamicObject. 00065 * @see DynamicObject::getNumAttributes() 00066 */ 00067 EXPORT_SYMBOL uint32_t getMetadataAttributeCount(DynamicObject* pMeta); 00068 00069 /** 00070 * Get the name of the name of a child attribute. 00071 * 00072 * @param pMeta 00073 * The DynamicObject to access. 00074 * @param attributeIndex 00075 * The index of the attribute. 00076 * @param pName 00077 * Buffer to store the name. This will be \c NULL terminated. 00078 * @param nameSize 00079 * The size of the Buffer. If the name is too long, an error 00080 * will be set. 00081 * If this is 0, the minimum size of the buffer including the trailing \c NULL will be returned. 00082 * @return the actual length of the name. 00083 */ 00084 EXPORT_SYMBOL uint32_t getMetadataAttributeName(DynamicObject* pMeta, 00085 uint32_t attributeIndex, char* pName, uint32_t nameSize); 00086 00087 /** 00088 * Get a child attribute. 00089 * 00090 * @param pMeta 00091 * The DynamicObject to access. 00092 * @param pName 00093 * The name of the attribute to access. Should be \c NULL terminated. 00094 * @return The attribute value as a DataVariant or \c NULL if an error occurred. 00095 * @see DynamicObject::getAttribute(const std::string&) 00096 */ 00097 EXPORT_SYMBOL DataVariant* getMetadataAttribute(DynamicObject* pMeta, const char* pName); 00098 00099 /** 00100 * Get an attribute from the entire sub-tree of a DynamicObject. 00101 * 00102 * @param pMeta 00103 * The DynamicObject to access. 00104 * @param pPath 00105 * The full path name of the attribute to access. Should be \c NULL terminated. 00106 * @return The attribute value as a DataVariant or \c NULL if an error occurred. 00107 * @see DynamicObject::getAttributeByPath(const std::string&) 00108 */ 00109 EXPORT_SYMBOL DataVariant* getMetadataAttributeByPath(DynamicObject* pMeta, const char* pPath); 00110 00111 /** 00112 * Set an attribute by taking ownership of a DataVariant. 00113 * 00114 * Will set: 00115 * SIMPLE_BAD_PARAMS any of the input values is \c NULL 00116 * SIMPLE_OTHER_FAILURE if the attribute set fails 00117 * 00118 * @param pMeta 00119 * The DynamicObject to access. 00120 * @param pName 00121 * The name of the attribute to access. Should be \c NULL terminated. 00122 * @param pValue 00123 * The new value of the attribute. This will be modified to contain the previous 00124 * value of the attribute or an invalid DataVariant if no previous value exists. 00125 * @see DynamicObject::adoptAttribute(const std::string&, DataVariant&) 00126 */ 00127 EXPORT_SYMBOL void setMetadataAttribute(DynamicObject* pMeta, const char* pName, DataVariant* pValue); 00128 00129 /** 00130 * Set an attribute by taking ownership of a DataVariant. 00131 * 00132 * Will set: 00133 * SIMPLE_BAD_PARAMS any of the input values is \c NULL 00134 * SIMPLE_OTHER_FAILURE if the attribute set fails 00135 * 00136 * @param pMeta 00137 * The DynamicObject to access. 00138 * @param pPath 00139 * The full path name of the attribute to access. Should be \c NULL terminated. 00140 * @param pValue 00141 * The new value of the attribute. This will be modified to contain the previous 00142 * value of the attribute or an invalid DataVariant if no previous value exists. 00143 * @see DynamicObject::adoptAttributeByPath(const std::string&, DataVariant*) 00144 */ 00145 EXPORT_SYMBOL void setMetadataAttributeByPath(DynamicObject* pMeta, const char* pPath, DataVariant* pValue); 00146 00147 /** 00148 * Remove an immediate child attribute. 00149 * 00150 * Will set: 00151 * SIMPLE_BAD_PARAMS any of the input values is \c NULL 00152 * SIMPLE_OTHER_FAILURE if the attribute remove fails 00153 * 00154 * @param pMeta 00155 * The DynamicObject to access. 00156 * @param pName 00157 * The name of the attribute to remove. Should be \c NULL terminated. 00158 * @see DynamicObject::removeAttribute(const std::string&) 00159 */ 00160 EXPORT_SYMBOL void removeMetadataAttribute(DynamicObject* pMeta, const char* pName); 00161 00162 /** 00163 * Remove an attribute from the sub-tree of a DynamicObject. 00164 * 00165 * Will set: 00166 * SIMPLE_BAD_PARAMS any of the input values is \c NULL 00167 * SIMPLE_OTHER_FAILURE if the attribute remove fails 00168 * 00169 * @param pMeta 00170 * The DynamicObject to access. 00171 * @param pPath 00172 * The full path name of the attribute to remove. Should be \c NULL terminated. 00173 * @see DynamicObject::removeAttributeByPath(const std::string&) 00174 */ 00175 EXPORT_SYMBOL void removeMetadataAttributeByPath(DynamicObject* pMeta, const char* pPath); 00176 00177 /** 00178 * Remove all attributes from a DynamicObject. 00179 * 00180 * @param pMeta 00181 * The DynamicObject to clear. 00182 * @see DynamicObject::clear() 00183 */ 00184 EXPORT_SYMBOL void clearMetadata(DynamicObject* pMeta); 00185 00186 /** 00187 * Access ConfigurationSettings values. 00188 * 00189 * @param pSettingKey 00190 * The \c NULL terminated setting key to access. 00191 * @return A DataVariant with the setting value or \c NULL if there was an error. 00192 * This is a borrowed reference and should be copied if changes will be made. 00193 * @see setConfigurationSetting(), ConfigurationSettings::getSetting() 00194 */ 00195 EXPORT_SYMBOL DataVariant* getConfigurationSetting(const char* pSettingKey); 00196 00197 /** 00198 * Change ConfigurationSettings values. 00199 * 00200 * @param pSettingKey 00201 * The \c NULL terminated setting key to mutate. 00202 * @param pValue 00203 * The value to set. This value will be adopted and after 00204 * this function returned, pValue will contain the previous setting 00205 * or an invalid DataVariant if there was no previous setting. 00206 * @return a zero on success or a non-zero on error. 00207 * @see getConfigurationSetting(), ConfiguationSettings::adoptSetting() 00208 */ 00209 EXPORT_SYMBOL int setConfigurationSetting(const char* pSettingKey, DataVariant* pValue); 00210 00211 /** 00212 * Add the current value of a setting to a DynamicObject for serialization to a defaults file. 00213 * 00214 * @param pSettingKey 00215 * The \c NULL terminated setting key. 00216 * @param pDynamicObject 00217 * The DynamicObject which will hold the copy. 00218 * @return a zero on success or a non-zero on error. 00219 * @see ConfigurationSettings::copySetting() 00220 */ 00221 EXPORT_SYMBOL int copyConfigurationSetting(const char* pSettingKey, DynamicObject* pDynamicObject); 00222 00223 /** 00224 * Serialize a DynamicObject to a file suitable for use as a setting defaults file. 00225 * 00226 * @param pFilename 00227 * The \c NULL terminated filename. If this is relative, the application's current working directory 00228 * will be used as the base path. 00229 * @param pDynamicObject 00230 * The DynamicObject to serialize. 00231 * @return a zero on success or a non-zero on error. 00232 * @see ConfigurationSettings::serializeAsDefaults() 00233 */ 00234 EXPORT_SYMBOL int serializeConfigurationSettingDefaults(const char* pFilename, DynamicObject* pDynamicObject); 00235 00236 /*@}*/ 00237 #ifdef __cplusplus 00238 } 00239 #endif 00240 00241 #endif