VirtualBox

Changeset 9321 in vbox


Ignore:
Timestamp:
Jun 2, 2008 8:15:46 PM (16 years ago)
Author:
vboxsync
Message:

Added CFGM methods taking default values for the VERR_CFMG_VALUE_NOT_FOUND and VERR_CFGM_NO_PARENT cases. (finally)

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/VBox/cfgm.h

    r8155 r9321  
    9393typedef FNCFGMCONSTRUCTOR *PFNCFGMCONSTRUCTOR;
    9494
    95 
    96 /**
    97  * Constructs the configuration for the VM.
    98  *
    99  * @returns VBox status code.
    100  * @param   pVM                 Pointer to VM which configuration has not yet been loaded.
    101  * @param   pfnCFGMConstructor  Pointer to callback function for constructing the VM configuration tree.
    102  *                              This is called in the EM.
    103  * @param   pvUser              The user argument passed to pfnCFGMConstructor.
    104  */
    105 CFGMR3DECL(int) CFGMR3Init(PVM pVM, PFNCFGMCONSTRUCTOR pfnCFGMConstructor, void *pvUser);
    106 
    107 /**
    108  * Terminates the configuration manager.
    109  *
    110  * @returns VBox status code.
    111  * @param   pVM             VM handle.
    112  */
    113 CFGMR3DECL(int) CFGMR3Term(PVM pVM);
     95CFGMR3DECL(int)         CFGMR3Init(PVM pVM, PFNCFGMCONSTRUCTOR pfnCFGMConstructor, void *pvUser);
     96CFGMR3DECL(int)         CFGMR3Term(PVM pVM);
    11497
    11598
    116 /** Tree Navigation and Enumeration.
     99CFGMR3DECL(PCFGMNODE)   CFGMR3CreateTree(PVM pVM);
     100CFGMR3DECL(void)        CFGMR3Dump(PCFGMNODE pRoot);
     101CFGMR3DECL(int)         CFGMR3InsertSubTree(PCFGMNODE pNode, const char *pszName, PCFGMNODE pSubTree, PCFGMNODE *ppChild);
     102CFGMR3DECL(int)         CFGMR3InsertNode(PCFGMNODE pNode, const char *pszName, PCFGMNODE *ppChild);
     103CFGMR3DECL(int)         CFGMR3InsertNodeF(PCFGMNODE pNode, PCFGMNODE *ppChild, const char *pszNameFormat, ...);
     104CFGMR3DECL(int)         CFGMR3InsertNodeFV(PCFGMNODE pNode, PCFGMNODE *ppChild, const char *pszNameFormat, va_list Args);
     105CFGMR3DECL(void)        CFGMR3SetRestrictedRoot(PCFGMNODE pNode);
     106CFGMR3DECL(void)        CFGMR3RemoveNode(PCFGMNODE pNode);
     107CFGMR3DECL(int)         CFGMR3InsertInteger(PCFGMNODE pNode, const char *pszName, uint64_t u64Integer);
     108CFGMR3DECL(int)         CFGMR3InsertString(PCFGMNODE pNode, const char *pszName, const char *pszString);
     109CFGMR3DECL(int)         CFGMR3InsertBytes(PCFGMNODE pNode, const char *pszName, const void *pvBytes, size_t cbBytes);
     110CFGMR3DECL(int)         CFGMR3RemoveValue(PCFGMNODE pNode, const char *pszName);
     111
     112CFGMR3DECL(int)         CFGMR3QueryType(        PCFGMNODE pNode, const char *pszName, PCFGMVALUETYPE penmType);
     113CFGMR3DECL(int)         CFGMR3QuerySize(        PCFGMNODE pNode, const char *pszName, size_t *pcb);
     114CFGMR3DECL(int)         CFGMR3QueryInteger(     PCFGMNODE pNode, const char *pszName, uint64_t *pu64);
     115CFGMR3DECL(int)         CFGMR3QueryIntegerDef(  PCFGMNODE pNode, const char *pszName, uint64_t *pu64, uint64_t u64Def);
     116CFGMR3DECL(int)         CFGMR3QueryString(      PCFGMNODE pNode, const char *pszName, char *pszString, size_t cchString);
     117CFGMR3DECL(int)         CFGMR3QueryStringDef(   PCFGMNODE pNode, const char *pszName, char *pszString, size_t cchString, const char *pszDef);
     118CFGMR3DECL(int)         CFGMR3QueryBytes(       PCFGMNODE pNode, const char *pszName, void *pvData, size_t cbData);
     119
     120
     121/** @name Helpers
    117122 * @{
    118123 */
    119 
    120 /**
    121  * Gets the root node for the VM.
    122  *
    123  * @returns Pointer to root node.
    124  * @param   pVM             VM handle.
    125  */
    126 CFGMR3DECL(PCFGMNODE) CFGMR3GetRoot(PVM pVM);
    127 
    128 /**
    129  * Gets the parent of a CFGM node.
    130  *
    131  * @returns Pointer to the parent node.
    132  * @returns NULL if pNode is Root or pNode is the start of a
    133  *          restricted subtree (use CFGMr3GetParentEx() for that).
    134  *
    135  * @param   pNode           The node which parent we query.
    136  */
    137 CFGMR3DECL(PCFGMNODE) CFGMR3GetParent(PCFGMNODE pNode);
    138 
    139 /**
    140  * Gets the parent of a CFGM node.
    141  *
    142  * @returns Pointer to the parent node.
    143  * @returns NULL if pNode is Root or pVM is not correct.
    144  *
    145  * @param   pVM             The VM handle, used as token that the caller is trusted.
    146  * @param   pNode           The node which parent we query.
    147  */
    148 CFGMR3DECL(PCFGMNODE) CFGMR3GetParentEx(PVM pVM, PCFGMNODE pNode);
    149 
    150 /**
    151  * Query a child node.
    152  *
    153  * @returns Pointer to the specified node.
    154  * @returns NULL if node was not found or pNode is NULL.
    155  * @param   pNode           Node pszPath is relative to.
    156  * @param   pszPath         Path to the child node or pNode.
    157  *                          It's good style to end this with '/'.
    158  */
    159 CFGMR3DECL(PCFGMNODE) CFGMR3GetChild(PCFGMNODE pNode, const char *pszPath);
    160 
    161 /**
    162  * Query a child node by a format string.
    163  *
    164  * @returns Pointer to the specified node.
    165  * @returns NULL if node was not found or pNode is NULL.
    166  * @param   pNode           Node pszPath is relative to.
    167  * @param   pszPathFormat   Path to the child node or pNode.
    168  *                          It's good style to end this with '/'.
    169  * @param   ...             Arguments to pszPathFormat.
    170  */
    171 CFGMR3DECL(PCFGMNODE) CFGMR3GetChildF(PCFGMNODE pNode, const char *pszPathFormat, ...);
    172 
    173 /**
    174  * Query a child node by a format string.
    175  *
    176  * @returns Pointer to the specified node.
    177  * @returns NULL if node was not found or pNode is NULL.
    178  * @param   pNode           Node pszPath is relative to.
    179  * @param   pszPathFormat   Path to the child node or pNode.
    180  *                          It's good style to end this with '/'.
    181  * @param   Args            Arguments to pszPathFormat.
    182  */
    183 CFGMR3DECL(PCFGMNODE) CFGMR3GetChildFV(PCFGMNODE pNode, const char *pszPathFormat, va_list Args);
    184 
    185 /**
    186  * Gets the first child node.
    187  * Use this to start an enumeration of child nodes.
    188  *
    189  * @returns Pointer to the first child.
    190  * @returns NULL if no children.
    191  * @param   pNode           Node to enumerate children for.
    192  */
    193 CFGMR3DECL(PCFGMNODE) CFGMR3GetFirstChild(PCFGMNODE pNode);
    194 
    195 /**
    196  * Gets the next sibling node.
    197  * Use this to continue an enumeration.
    198  *
    199  * @returns Pointer to the first child.
    200  * @returns NULL if no children.
    201  * @param   pCur            Node to returned by a call to CFGMR3GetFirstChild()
    202  *                          or successive calls to this function.
    203  */
    204 CFGMR3DECL(PCFGMNODE) CFGMR3GetNextChild(PCFGMNODE pCur);
    205 
    206 /**
    207  * Gets the name of the current node.
    208  * (Needed for enumeration.)
    209  *
    210  * @returns VBox status code.
    211  * @param   pCur            Node to returned by a call to CFGMR3GetFirstChild()
    212  *                          or successive calls to CFGMR3GetNextChild().
    213  * @param   pszName         Where to store the node name.
    214  * @param   cchName         Size of the buffer pointed to by pszName (with terminator).
    215  */
    216 CFGMR3DECL(int) CFGMR3GetName(PCFGMNODE pCur, char *pszName, size_t cchName);
    217 
    218 /**
    219  * Gets the length of the current node's name.
    220  * (Needed for enumeration.)
    221  *
    222  * @returns Node name length in bytes including the terminating null char.
    223  * @returns 0 if pCur is NULL.
    224  * @param   pCur            Node returned by a call to CFGMR3GetFirstChild()
    225  *                          or successive calls to CFGMR3GetNextChild().
    226  */
    227 CFGMR3DECL(int) CFGMR3GetNameLen(PCFGMNODE pCur);
    228 
    229 /**
    230  * Validates that the child nodes are within a set of valid names.
    231  *
    232  * @returns true if all names are found in pszzAllowed.
    233  * @returns false if not.
    234  * @param   pNode           The node which values should be examined.
    235  * @param   pszzValid       List of valid names separated by '\\0' and ending with
    236  *                          a double '\\0'.
    237  */
    238 CFGMR3DECL(bool) CFGMR3AreChildrenValid(PCFGMNODE pNode, const char *pszzValid);
    239 
    240 
    241 /**
    242  * Gets the first value of a node.
    243  * Use this to start an enumeration of values.
    244  *
    245  * @returns Pointer to the first value.
    246  * @param   pCur            The node (Key) which values to enumerate.
    247  */
    248 CFGMR3DECL(PCFGMLEAF) CFGMR3GetFirstValue(PCFGMNODE pCur);
    249 
    250 /**
    251  * Gets the next value in enumeration.
    252  *
    253  * @returns Pointer to the next value.
    254  * @param   pCur            The current value as returned by this function or CFGMR3GetFirstValue().
    255  */
    256 CFGMR3DECL(PCFGMLEAF) CFGMR3GetNextValue(PCFGMLEAF pCur);
    257 
    258 /**
    259  * Get the value name.
    260  * (Needed for enumeration.)
    261  *
    262  * @returns VBox status code.
    263  * @param   pCur            Value returned by a call to CFGMR3GetFirstValue()
    264  *                          or successive calls to CFGMR3GetNextValue().
    265  * @param   pszName         Where to store the value name.
    266  * @param   cchName         Size of the buffer pointed to by pszName (with terminator).
    267  */
    268 CFGMR3DECL(int) CFGMR3GetValueName(PCFGMLEAF pCur, char *pszName, size_t cchName);
    269 
    270 /**
    271  * Gets the length of the current node's name.
    272  * (Needed for enumeration.)
    273  *
    274  * @returns Value name length in bytes including the terminating null char.
    275  * @returns 0 if pCur is NULL.
    276  * @param   pCur            Value returned by a call to CFGMR3GetFirstValue()
    277  *                          or successive calls to CFGMR3GetNextValue().
    278  */
    279 CFGMR3DECL(int) CFGMR3GetValueNameLen(PCFGMLEAF pCur);
    280 
    281 /**
    282  * Gets the value type.
    283  * (For enumeration.)
    284  *
    285  * @returns VBox status code.
    286  * @param   pCur            Value returned by a call to CFGMR3GetFirstValue()
    287  *                          or successive calls to CFGMR3GetNextValue().
    288  */
    289 CFGMR3DECL(CFGMVALUETYPE) CFGMR3GetValueType(PCFGMLEAF pCur);
    290 
    291 /**
    292  * Validates that the values are within a set of valid names.
    293  *
    294  * @returns true if all names are found in pszzAllowed.
    295  * @returns false if not.
    296  * @param   pNode           The node which values should be examined.
    297  * @param   pszzValid       List of valid names separated by '\\0' and ending with
    298  *                          a double '\\0'.
    299  */
    300 CFGMR3DECL(bool) CFGMR3AreValuesValid(PCFGMNODE pNode, const char *pszzValid);
     124CFGMR3DECL(int)         CFGMR3QueryU64(         PCFGMNODE pNode, const char *pszName, uint64_t *pu64);
     125CFGMR3DECL(int)         CFGMR3QueryU64Def(      PCFGMNODE pNode, const char *pszName, uint64_t *pu64, uint64_t u64Def);
     126CFGMR3DECL(int)         CFGMR3QueryS64(         PCFGMNODE pNode, const char *pszName, int64_t *pi64);
     127CFGMR3DECL(int)         CFGMR3QueryS64Def(      PCFGMNODE pNode, const char *pszName, int64_t *pi64, int64_t i64Def);
     128CFGMR3DECL(int)         CFGMR3QueryU32(         PCFGMNODE pNode, const char *pszName, uint32_t *pu32);
     129CFGMR3DECL(int)         CFGMR3QueryU32Def(      PCFGMNODE pNode, const char *pszName, uint32_t *pu32, uint32_t u32Def);
     130CFGMR3DECL(int)         CFGMR3QueryS32(         PCFGMNODE pNode, const char *pszName, int32_t *pi32);
     131CFGMR3DECL(int)         CFGMR3QueryS32Def(      PCFGMNODE pNode, const char *pszName, int32_t *pi32, int32_t i32Def);
     132CFGMR3DECL(int)         CFGMR3QueryU16(         PCFGMNODE pNode, const char *pszName, uint16_t *pu16);
     133CFGMR3DECL(int)         CFGMR3QueryU16Def(      PCFGMNODE pNode, const char *pszName, uint16_t *pu16, uint16_t u16Def);
     134CFGMR3DECL(int)         CFGMR3QueryS16(         PCFGMNODE pNode, const char *pszName, int16_t *pi16);
     135CFGMR3DECL(int)         CFGMR3QueryS16Def(      PCFGMNODE pNode, const char *pszName, int16_t *pi16, int16_t i16Def);
     136CFGMR3DECL(int)         CFGMR3QueryU8(          PCFGMNODE pNode, const char *pszName, uint8_t *pu8);
     137CFGMR3DECL(int)         CFGMR3QueryU8Def(       PCFGMNODE pNode, const char *pszName, uint8_t *pu8, uint8_t u8Def);
     138CFGMR3DECL(int)         CFGMR3QueryS8(          PCFGMNODE pNode, const char *pszName, int8_t *pi8);
     139CFGMR3DECL(int)         CFGMR3QueryS8Def(       PCFGMNODE pNode, const char *pszName, int8_t *pi8, int8_t i8Def);
     140CFGMR3DECL(int)         CFGMR3QueryBool(        PCFGMNODE pNode, const char *pszName, bool *pf);
     141CFGMR3DECL(int)         CFGMR3QueryBoolDef(     PCFGMNODE pNode, const char *pszName, bool *pf, bool fDef);
     142CFGMR3DECL(int)         CFGMR3QueryPort(        PCFGMNODE pNode, const char *pszName, PRTIOPORT pPort);
     143CFGMR3DECL(int)         CFGMR3QueryPortDef(     PCFGMNODE pNode, const char *pszName, PRTIOPORT pPort, RTIOPORT PortDef);
     144CFGMR3DECL(int)         CFGMR3QueryPtr(         PCFGMNODE pNode, const char *pszName, void **ppv);
     145CFGMR3DECL(int)         CFGMR3QueryPtrDef(      PCFGMNODE pNode, const char *pszName, void **ppv, void *pvDef);
     146CFGMR3DECL(int)         CFGMR3QueryGCPtr(       PCFGMNODE pNode, const char *pszName, PRTGCPTR pGCPtr);
     147CFGMR3DECL(int)         CFGMR3QueryGCPtrDef(    PCFGMNODE pNode, const char *pszName, PRTGCPTR pGCPtr, RTGCPTR GCPtrDef);
     148CFGMR3DECL(int)         CFGMR3QueryGCPtrU(      PCFGMNODE pNode, const char *pszName, PRTGCUINTPTR pGCPtr);
     149CFGMR3DECL(int)         CFGMR3QueryGCPtrUDef(   PCFGMNODE pNode, const char *pszName, PRTGCUINTPTR pGCPtr, RTGCUINTPTR GCPtrDef);
     150CFGMR3DECL(int)         CFGMR3QueryGCPtrS(      PCFGMNODE pNode, const char *pszName, PRTGCINTPTR pGCPtr);
     151CFGMR3DECL(int)         CFGMR3QueryGCPtrSDef(   PCFGMNODE pNode, const char *pszName, PRTGCINTPTR pGCPtr, RTGCINTPTR GCPtrDef);
     152CFGMR3DECL(int)         CFGMR3QueryStringAlloc( PCFGMNODE pNode, const char *pszName, char **ppszString);
     153CFGMR3DECL(int)         CFGMR3QueryStringAllocDef(PCFGMNODE pNode, const char *pszName, char **ppszString, const char *pszDef);
    301154
    302155/** @} */
    303156
    304 /**
    305  * Query value type.
    306  *
    307  * @returns VBox status code.
    308  * @param   pNode           Which node to search for pszName in.
    309  * @param   pszName         Name of an integer value.
    310  * @param   penmType        Where to store the type.
    311  */
    312 CFGMR3DECL(int) CFGMR3QueryType(PCFGMNODE pNode, const char *pszName, PCFGMVALUETYPE penmType);
    313 
    314 /**
    315  * Query value size.
    316  * This works on all types of values.
    317  *
    318  * @returns VBox status code.
    319  * @param   pNode           Which node to search for pszName in.
    320  * @param   pszName         Name of an integer value.
    321  * @param   pcb             Where to store the value size.
    322  */
    323 CFGMR3DECL(int) CFGMR3QuerySize(PCFGMNODE pNode, const char *pszName, size_t *pcb);
    324 
    325 /**
    326  * Query integer value.
    327  *
    328  * @returns VBox status code.
    329  * @param   pNode           Which node to search for pszName in.
    330  * @param   pszName         Name of an integer value.
    331  * @param   pu64            Where to store the integer value.
    332  */
    333 CFGMR3DECL(int) CFGMR3QueryInteger(PCFGMNODE pNode, const char *pszName, uint64_t *pu64);
    334 
    335 /**
    336  * Query zero terminated character value.
    337  *
    338  * @returns VBox status code.
    339  * @param   pNode           Which node to search for pszName in.
    340  * @param   pszName         Name of a zero terminate character value.
    341  * @param   pszString       Where to store the string.
    342  * @param   cchString       Size of the string buffer. (Includes terminator.)
    343  */
    344 CFGMR3DECL(int) CFGMR3QueryString(PCFGMNODE pNode, const char *pszName, char *pszString, size_t cchString);
    345 
    346 /**
    347  * Query byte string value.
    348  *
    349  * @returns VBox status code.
    350  * @param   pNode           Which node to search for pszName in.
    351  * @param   pszName         Name of a byte string value.
    352  * @param   pvData          Where to store the binary data.
    353  * @param   cbData          Size of buffer pvData points too.
    354  */
    355 CFGMR3DECL(int) CFGMR3QueryBytes(PCFGMNODE pNode, const char *pszName, void *pvData, size_t cbData);
    356 
    357 
    358 /**
    359  * Creates a CFGM tree.
    360  *
    361  * This is intended for creating device/driver configs can be
    362  * passed around and later attached to the main tree in the
    363  * correct location.
    364  *
    365  * @returns Pointer to the root node.
    366  * @param   pVM         The VM handle.
    367  */
    368 CFGMR3DECL(PCFGMNODE) CFGMR3CreateTree(PVM pVM);
    369 
    370 /**
    371  * Insert subtree.
    372  *
    373  * This function inserts (no duplication) a tree created by CFGMR3CreateTree()
    374  * into the main tree.
    375  *
    376  * The root node of the inserted subtree will need to be reallocated, which
    377  * effectually means that the passed in pSubTree handle becomes invalid
    378  * upon successful return. Use the value returned in ppChild instead
    379  * of pSubTree.
    380  *
    381  * @returns VBox status code.
    382  * @returns VERR_CFGM_NODE_EXISTS if the final child node name component exists.
    383  * @param   pNode       Parent node.
    384  * @param   pszName     Name or path of the new child node.
    385  * @param   pSubTree    The subtree to insert. Must be returned by CFGMR3CreateTree().
    386  * @param   ppChild     Where to store the address of the new child node. (optional)
    387  */
    388 CFGMR3DECL(int) CFGMR3InsertSubTree(PCFGMNODE pNode, const char *pszName, PCFGMNODE pSubTree, PCFGMNODE *ppChild);
    389 
    390 /**
    391  * Insert a node.
    392  *
    393  * @returns VBox status code.
    394  * @returns VERR_CFGM_NODE_EXISTS if the final child node name component exists.
    395  * @param   pNode       Parent node.
    396  * @param   pszName     Name or path of the new child node.
    397  * @param   ppChild     Where to store the address of the new child node. (optional)
    398  */
    399 CFGMR3DECL(int) CFGMR3InsertNode(PCFGMNODE pNode, const char *pszName, PCFGMNODE *ppChild);
    400 
    401 /**
    402  * Insert a node, format string name.
    403  *
    404  * @returns VBox status     code.
    405  * @param   pNode           Parent node.
    406  * @param   ppChild         Where to store the address of the new child node. (optional)
    407  * @param   pszNameFormat   Name or path of the new child node.
    408  * @param   ...             Name format arguments.
    409  */
    410 CFGMR3DECL(int) CFGMR3InsertNodeF(PCFGMNODE pNode, PCFGMNODE *ppChild, const char *pszNameFormat, ...);
    411 
    412 /**
    413  * Insert a node, format string name.
    414  *
    415  * @returns VBox status code.
    416  * @param   pNode           Parent node.
    417  * @param   ppChild         Where to store the address of the new child node. (optional)
    418  * @param   pszNameFormat   Name or path of the new child node.
    419  * @param   Args            Name format arguments.
    420  */
    421 CFGMR3DECL(int) CFGMR3InsertNodeFV(PCFGMNODE pNode, PCFGMNODE *ppChild, const char *pszNameFormat, va_list Args);
    422 
    423 /**
    424  * Marks the node as the root of a restricted subtree, i.e. the end of
    425  * a CFGMR3GetParent() journey.
    426  *
    427  * @param   pNode       The node to mark.
    428  */
    429 CFGMR3DECL(void) CFGMR3SetRestrictedRoot(PCFGMNODE pNode);
    430 
    431 /**
    432  * Remove a node.
    433  *
    434  * @param   pNode       Parent node.
    435  */
    436 CFGMR3DECL(void) CFGMR3RemoveNode(PCFGMNODE pNode);
    437 
    438 
    439 /**
    440  * Inserts a new integer value.
    441  *
    442  * @returns VBox status code.
    443  * @param   pNode           Parent node.
    444  * @param   pszName         Value name.
    445  * @param   u64Integer      The value.
    446  */
    447 CFGMR3DECL(int) CFGMR3InsertInteger(PCFGMNODE pNode, const char *pszName, uint64_t u64Integer);
    448 
    449 /**
    450  * Inserts a new string value.
    451  *
    452  * @returns VBox status code.
    453  * @param   pNode           Parent node.
    454  * @param   pszName         Value name.
    455  * @param   pszString       The value.
    456  */
    457 CFGMR3DECL(int) CFGMR3InsertString(PCFGMNODE pNode, const char *pszName, const char *pszString);
    458 
    459 /**
    460  * Inserts a new integer value.
    461  *
    462  * @returns VBox status code.
    463  * @param   pNode           Parent node.
    464  * @param   pszName         Value name.
    465  * @param   pvBytes         The value.
    466  * @param   cbBytes         The value size.
    467  */
    468 CFGMR3DECL(int) CFGMR3InsertBytes(PCFGMNODE pNode, const char *pszName, const void *pvBytes, size_t cbBytes);
    469 
    470 /**
    471  * Remove a value.
    472  *
    473  * @returns VBox status code.
    474  * @param   pNode       Parent node.
    475  * @param   pszName     Name of the new child node.
    476  */
    477 CFGMR3DECL(int) CFGMR3RemoveValue(PCFGMNODE pNode, const char *pszName);
    478 
    479 
    480 
    481 /** Helpers
     157/** @name Tree Navigation and Enumeration.
    482158 * @{
    483159 */
    484 /**
    485  * Query unsigned 64-bit integer value.
    486  *
    487  * @returns VBox status code.
    488  * @param   pNode           Which node to search for pszName in.
    489  * @param   pszName         Name of an integer value.
    490  * @param   pu64            Where to store the integer value.
    491  */
    492 CFGMR3DECL(int) CFGMR3QueryU64(PCFGMNODE pNode, const char *pszName, uint64_t *pu64);
    493 
    494 /**
    495  * Query signed 64-bit integer value.
    496  *
    497  * @returns VBox status code.
    498  * @param   pNode           Which node to search for pszName in.
    499  * @param   pszName         Name of an integer value.
    500  * @param   pi64            Where to store the value.
    501  */
    502 CFGMR3DECL(int) CFGMR3QueryS64(PCFGMNODE pNode, const char *pszName, int64_t *pi64);
    503 
    504 /**
    505  * Query unsigned 32-bit integer value.
    506  *
    507  * @returns VBox status code.
    508  * @param   pNode           Which node to search for pszName in.
    509  * @param   pszName         Name of an integer value.
    510  * @param   pu32            Where to store the value.
    511  */
    512 CFGMR3DECL(int) CFGMR3QueryU32(PCFGMNODE pNode, const char *pszName, uint32_t *pu32);
    513 
    514 /**
    515  * Query signed 32-bit integer value.
    516  *
    517  * @returns VBox status code.
    518  * @param   pNode           Which node to search for pszName in.
    519  * @param   pszName         Name of an integer value.
    520  * @param   pi32            Where to store the value.
    521  */
    522 CFGMR3DECL(int) CFGMR3QueryS32(PCFGMNODE pNode, const char *pszName, int32_t *pi32);
    523 
    524 /**
    525  * Query unsigned 16-bit integer value.
    526  *
    527  * @returns VBox status code.
    528  * @param   pNode           Which node to search for pszName in.
    529  * @param   pszName         Name of an integer value.
    530  * @param   pu16            Where to store the value.
    531  */
    532 CFGMR3DECL(int) CFGMR3QueryU16(PCFGMNODE pNode, const char *pszName, uint16_t *pu16);
    533 
    534 /**
    535  * Query signed 16-bit integer value.
    536  *
    537  * @returns VBox status code.
    538  * @param   pNode           Which node to search for pszName in.
    539  * @param   pszName         Name of an integer value.
    540  * @param   pi16            Where to store the value.
    541  */
    542 CFGMR3DECL(int) CFGMR3QueryS16(PCFGMNODE pNode, const char *pszName, int16_t *pi16);
    543 
    544 /**
    545  * Query unsigned 8-bit integer value.
    546  *
    547  * @returns VBox status code.
    548  * @param   pNode           Which node to search for pszName in.
    549  * @param   pszName         Name of an integer value.
    550  * @param   pu8             Where to store the value.
    551  */
    552 CFGMR3DECL(int) CFGMR3QueryU8(PCFGMNODE pNode, const char *pszName, uint8_t *pu8);
    553 
    554 /**
    555  * Query signed 8-bit integer value.
    556  *
    557  * @returns VBox status code.
    558  * @param   pNode           Which node to search for pszName in.
    559  * @param   pszName         Name of an integer value.
    560  * @param   pi8             Where to store the value.
    561  */
    562 CFGMR3DECL(int) CFGMR3QueryS8(PCFGMNODE pNode, const char *pszName, int8_t *pi8);
    563 
    564 /**
    565  * Query boolean integer value.
    566  *
    567  * @returns VBox status code.
    568  * @param   pNode           Which node to search for pszName in.
    569  * @param   pszName         Name of an integer value.
    570  * @param   pf              Where to store the value.
    571  * @remark  This function will interpret any non-zero value as true.
    572  */
    573 CFGMR3DECL(int) CFGMR3QueryBool(PCFGMNODE pNode, const char *pszName, bool *pf);
    574 
    575 /**
    576  * Query pointer integer value.
    577  *
    578  * @returns VBox status code.
    579  * @param   pNode           Which node to search for pszName in.
    580  * @param   pszName         Name of an integer value.
    581  * @param   ppv             Where to store the value.
    582  */
    583 CFGMR3DECL(int) CFGMR3QueryPtr(PCFGMNODE pNode, const char *pszName, void **ppv);
    584 
    585 /**
    586  * Query Guest Context pointer integer value.
    587  *
    588  * @returns VBox status code.
    589  * @param   pNode           Which node to search for pszName in.
    590  * @param   pszName         Name of an integer value.
    591  * @param   pGCPtr          Where to store the value.
    592  */
    593 CFGMR3DECL(int) CFGMR3QueryGCPtr(PCFGMNODE pNode, const char *pszName, PRTGCPTR pGCPtr);
    594 
    595 /**
    596  * Query Guest Context unsigned pointer value.
    597  *
    598  * @returns VBox status code.
    599  * @param   pNode           Which node to search for pszName in.
    600  * @param   pszName         Name of an integer value.
    601  * @param   pGCPtr          Where to store the value.
    602  */
    603 CFGMR3DECL(int) CFGMR3QueryGCPtrU(PCFGMNODE pNode, const char *pszName, PRTGCUINTPTR pGCPtr);
    604 
    605 /**
    606  * Query Guest Context signed pointer value.
    607  *
    608  * @returns VBox status code.
    609  * @param   pNode           Which node to search for pszName in.
    610  * @param   pszName         Name of an integer value.
    611  * @param   pGCPtr          Where to store the value.
    612  */
    613 CFGMR3DECL(int) CFGMR3QueryGCPtrS(PCFGMNODE pNode, const char *pszName, PRTGCINTPTR pGCPtr);
    614 
    615 /**
    616  * Query boolean integer value.
    617  *
    618  * @returns VBox status code.
    619  * @param   pNode           Which node to search for pszName in.
    620  * @param   pszName         Name of an integer value.
    621  * @param   pvValue         Where to store the value.
    622  * @param   cbValue         The size of the integer value (in bytes).
    623  * @param   fSigned         Whether the integer is signed (true) or not (false).
    624  * @remark  This function will interpret any non-zero value as true.
    625  */
    626 DECLINLINE(int) CFGMR3QueryIntegerBySize(PCFGMNODE pNode, const char *pszName, void *pvValue, size_t cbValue, bool fSigned)
    627 {
    628     int rc;
    629     if (fSigned)
    630     {
    631         switch (cbValue)
    632         {
    633             case  8: rc = CFGMR3QueryS8(pNode, pszName, (int8_t *)pvValue);   break;
    634             case 16: rc = CFGMR3QueryS16(pNode, pszName, (int16_t *)pvValue); break;
    635             case 32: rc = CFGMR3QueryS32(pNode, pszName, (int32_t *)pvValue); break;
    636             case 64: rc = CFGMR3QueryS64(pNode, pszName, (int64_t *)pvValue); break;
    637             default: rc = -1 /* VERR_GENERAL_FAILURE*/; break;
    638         }
    639     }
    640     else
    641     {
    642         switch (cbValue)
    643         {
    644             case  8: rc = CFGMR3QueryU8(pNode, pszName, (uint8_t *)pvValue);   break;
    645             case 16: rc = CFGMR3QueryU16(pNode, pszName, (uint16_t *)pvValue); break;
    646             case 32: rc = CFGMR3QueryU32(pNode, pszName, (uint32_t *)pvValue); break;
    647             case 64: rc = CFGMR3QueryU64(pNode, pszName, (uint64_t *)pvValue); break;
    648             default: rc = -1 /* VERR_GENERAL_FAILURE*/; break;
    649         }
    650     }
    651     return rc;
    652 }
    653 
    654 
    655 /**
    656  * Query I/O port address value (integer).
    657  *
    658  * @returns VBox status code.
    659  * @param   pNode           Which node to search for pszName in.
    660  * @param   pszName         Name of an integer value.
    661  * @param   pPort           Where to store the value.
    662  */
    663 DECLINLINE(int) CFGMR3QueryPort(PCFGMNODE pNode, const char *pszName, PRTIOPORT pPort)
    664 {
    665     return CFGMR3QueryIntegerBySize(pNode, pszName, pPort, sizeof(*pPort), false);
    666 }
    667 
    668 
    669 
    670 /**
    671  * Query zero terminated character value storing it in a
    672  * buffer allocated from the MM heap.
    673  *
    674  * @returns VBox status code.
    675  * @param   pNode           Which node to search for pszName in.
    676  * @param   pszName         Value name. This value must be of zero terminated character string type.
    677  * @param   ppszString      Where to store the string pointer.
    678  *                          Free this using MMR3HeapFree().
    679  */
    680 CFGMR3DECL(int) CFGMR3QueryStringAlloc(PCFGMNODE pNode, const char *pszName, char **ppszString);
    681 
     160CFGMR3DECL(PCFGMNODE)   CFGMR3GetRoot(PVM pVM);
     161CFGMR3DECL(PCFGMNODE)   CFGMR3GetParent(PCFGMNODE pNode);
     162CFGMR3DECL(PCFGMNODE)   CFGMR3GetParentEx(PVM pVM, PCFGMNODE pNode);
     163CFGMR3DECL(PCFGMNODE)   CFGMR3GetChild(PCFGMNODE pNode, const char *pszPath);
     164CFGMR3DECL(PCFGMNODE)   CFGMR3GetChildF(PCFGMNODE pNode, const char *pszPathFormat, ...);
     165CFGMR3DECL(PCFGMNODE)   CFGMR3GetChildFV(PCFGMNODE pNode, const char *pszPathFormat, va_list Args);
     166CFGMR3DECL(PCFGMNODE)   CFGMR3GetFirstChild(PCFGMNODE pNode);
     167CFGMR3DECL(PCFGMNODE)   CFGMR3GetNextChild(PCFGMNODE pCur);
     168CFGMR3DECL(int)         CFGMR3GetName(PCFGMNODE pCur, char *pszName, size_t cchName);
     169CFGMR3DECL(int)         CFGMR3GetNameLen(PCFGMNODE pCur);
     170CFGMR3DECL(bool)        CFGMR3AreChildrenValid(PCFGMNODE pNode, const char *pszzValid);
     171CFGMR3DECL(PCFGMLEAF)   CFGMR3GetFirstValue(PCFGMNODE pCur);
     172CFGMR3DECL(PCFGMLEAF)   CFGMR3GetNextValue(PCFGMLEAF pCur);
     173CFGMR3DECL(int)         CFGMR3GetValueName(PCFGMLEAF pCur, char *pszName, size_t cchName);
     174CFGMR3DECL(int)         CFGMR3GetValueNameLen(PCFGMLEAF pCur);
     175CFGMR3DECL(CFGMVALUETYPE) CFGMR3GetValueType(PCFGMLEAF pCur);
     176CFGMR3DECL(bool)        CFGMR3AreValuesValid(PCFGMNODE pNode, const char *pszzValid);
    682177/** @} */
    683178
    684 
    685 /**
    686  * Dumps the configuration (sub)tree.
    687  *
    688  * @param   pRoot   The root node of the dump.
    689  */
    690 CFGMR3DECL(void) CFGMR3Dump(PCFGMNODE pRoot);
    691179
    692180/** @} */
     
    699187
    700188#endif
     189
  • trunk/src/VBox/VMM/CFGM.cpp

    r8564 r9321  
    596596
    597597/**
     598 * Query integer value with default.
     599 *
     600 * @returns VBox status code.
     601 * @param   pNode           Which node to search for pszName in.
     602 * @param   pszName         Name of an integer value.
     603 * @param   pu64            Where to store the integer value.
     604 * @param   u64Def          The default value.
     605 */
     606CFGMR3DECL(int) CFGMR3QueryIntegerDef(PCFGMNODE pNode, const char *pszName, uint64_t *pu64, uint64_t u64Def)
     607{
     608    PCFGMLEAF pLeaf;
     609    int rc = cfgmR3ResolveLeaf(pNode, pszName, &pLeaf);
     610    if (VBOX_SUCCESS(rc))
     611    {
     612        if (pLeaf->enmType == CFGMVALUETYPE_INTEGER)
     613            *pu64 = pLeaf->Value.Integer.u64;
     614        else
     615            rc = VERR_CFGM_NOT_INTEGER;
     616    }
     617    else if (rc == VERR_CFGM_VALUE_NOT_FOUND || rc == VERR_CFGM_NO_PARENT)
     618    {
     619        *pu64 = u64Def;
     620        rc = VINF_SUCCESS;
     621    }
     622    return rc;
     623}
     624
     625
     626/**
    598627 * Query zero terminated character value.
    599628 *
     
    622651        else
    623652            rc = VERR_CFGM_NOT_STRING;
     653    }
     654    return rc;
     655}
     656
     657
     658/**
     659 * Query zero terminated character value with default.
     660 *
     661 * @returns VBox status code.
     662 * @param   pNode           Which node to search for pszName in.
     663 * @param   pszName         Name of a zero terminate character value.
     664 * @param   pszString       Where to store the string.
     665 * @param   cchString       Size of the string buffer. (Includes terminator.)
     666 * @param   pszDef          The default value.
     667 */
     668CFGMR3DECL(int) CFGMR3QueryStringDef(PCFGMNODE pNode, const char *pszName, char *pszString, size_t cchString, const char *pszDef)
     669{
     670    PCFGMLEAF pLeaf;
     671    int rc = cfgmR3ResolveLeaf(pNode, pszName, &pLeaf);
     672    if (VBOX_SUCCESS(rc))
     673    {
     674        if (pLeaf->enmType == CFGMVALUETYPE_STRING)
     675        {
     676            if (cchString >= pLeaf->Value.String.cch)
     677            {
     678                memcpy(pszString, pLeaf->Value.String.psz, pLeaf->Value.String.cch);
     679                memset(pszString + pLeaf->Value.String.cch, 0, cchString - pLeaf->Value.String.cch);
     680            }
     681            else
     682                rc = VERR_CFGM_NOT_ENOUGH_SPACE;
     683        }
     684        else
     685            rc = VERR_CFGM_NOT_STRING;
     686    }
     687    else if (rc == VERR_CFGM_VALUE_NOT_FOUND || rc == VERR_CFGM_NO_PARENT)
     688    {
     689        size_t cchDef = strlen(pszDef);
     690        if (cchString > cchDef)
     691        {
     692            memcpy(pszString, pszDef, cchDef);
     693            memset(pszString + cchDef, 0, cchString - cchDef);
     694            rc = VINF_SUCCESS;
     695        }
     696        else
     697            rc = VERR_CFGM_NOT_ENOUGH_SPACE;
    624698    }
    625699    return rc;
     
    16281702
    16291703/**
     1704 * Query unsigned 64-bit integer value with default.
     1705 *
     1706 * @returns VBox status code.
     1707 * @param   pNode           Which node to search for pszName in.
     1708 * @param   pszName         Name of an integer value.
     1709 * @param   pu64            Where to store the integer value.
     1710 * @param   u64Def          The default value.
     1711 */
     1712CFGMR3DECL(int) CFGMR3QueryU64Def(PCFGMNODE pNode, const char *pszName, uint64_t *pu64, uint64_t u64Def)
     1713{
     1714    return CFGMR3QueryIntegerDef(pNode, pszName, pu64, u64Def);
     1715}
     1716
     1717
     1718/**
    16301719 * Query signed 64-bit integer value.
    16311720 *
     
    16461735
    16471736/**
     1737 * Query signed 64-bit integer value with default.
     1738 *
     1739 * @returns VBox status code.
     1740 * @param   pNode           Which node to search for pszName in.
     1741 * @param   pszName         Name of an integer value.
     1742 * @param   pi64            Where to store the value.
     1743 * @param   i64Def          The default value.
     1744 */
     1745CFGMR3DECL(int) CFGMR3QueryS64Def(PCFGMNODE pNode, const char *pszName, int64_t *pi64, int64_t i64Def)
     1746{
     1747    uint64_t u64;
     1748    int rc = CFGMR3QueryIntegerDef(pNode, pszName, &u64, i64Def);
     1749    if (VBOX_SUCCESS(rc))
     1750        *pi64 = (int64_t)u64;
     1751    return rc;
     1752}
     1753
     1754
     1755/**
    16481756 * Query unsigned 32-bit integer value.
    16491757 *
     
    16591767    if (VBOX_SUCCESS(rc))
    16601768    {
    1661         if (!(u64 & 0xffffffff00000000ULL))
     1769        if (!(u64 & UINT64_C(0xffffffff00000000)))
     1770            *pu32 = (uint32_t)u64;
     1771        else
     1772            rc = VERR_CFGM_INTEGER_TOO_BIG;
     1773    }
     1774    return rc;
     1775}
     1776
     1777
     1778/**
     1779 * Query unsigned 32-bit integer value with default.
     1780 *
     1781 * @returns VBox status code.
     1782 * @param   pNode           Which node to search for pszName in.
     1783 * @param   pszName         Name of an integer value.
     1784 * @param   pu32            Where to store the value.
     1785 * @param   u32Def          The default value.
     1786 */
     1787CFGMR3DECL(int) CFGMR3QueryU32Def(PCFGMNODE pNode, const char *pszName, uint32_t *pu32, uint32_t u32Def)
     1788{
     1789    uint64_t u64;
     1790    int rc = CFGMR3QueryIntegerDef(pNode, pszName, &u64, u32Def);
     1791    if (VBOX_SUCCESS(rc))
     1792    {
     1793        if (!(u64 & UINT64_C(0xffffffff00000000)))
    16621794            *pu32 = (uint32_t)u64;
    16631795        else
     
    16821814    if (VBOX_SUCCESS(rc))
    16831815    {
    1684         if (   !(u64 & 0xffffffff80000000ULL)
    1685             ||  (u64 & 0xffffffff80000000ULL) == 0xffffffff80000000ULL)
     1816        if (   !(u64 & UINT64_C(0xffffffff80000000))
     1817            ||  (u64 & UINT64_C(0xffffffff80000000)) == UINT64_C(0xffffffff80000000))
     1818            *pi32 = (int32_t)u64;
     1819        else
     1820            rc = VERR_CFGM_INTEGER_TOO_BIG;
     1821    }
     1822    return rc;
     1823}
     1824
     1825
     1826/**
     1827 * Query signed 32-bit integer value with default.
     1828 *
     1829 * @returns VBox status code.
     1830 * @param   pNode           Which node to search for pszName in.
     1831 * @param   pszName         Name of an integer value.
     1832 * @param   pi32            Where to store the value.
     1833 * @param   i32Def          The default value.
     1834 */
     1835CFGMR3DECL(int) CFGMR3QueryS32Def(PCFGMNODE pNode, const char *pszName, int32_t *pi32, int32_t i32Def)
     1836{
     1837    uint64_t u64;
     1838    int rc = CFGMR3QueryIntegerDef(pNode, pszName, &u64, i32Def);
     1839    if (VBOX_SUCCESS(rc))
     1840    {
     1841        if (   !(u64 & UINT64_C(0xffffffff80000000))
     1842            ||  (u64 & UINT64_C(0xffffffff80000000)) == UINT64_C(0xffffffff80000000))
    16861843            *pi32 = (int32_t)u64;
    16871844        else
     
    17061863    if (VBOX_SUCCESS(rc))
    17071864    {
    1708         if (!(u64 & 0xffffffffffff0000ULL))
     1865        if (!(u64 & UINT64_C(0xffffffffffff0000)))
     1866            *pu16 = (int16_t)u64;
     1867        else
     1868            rc = VERR_CFGM_INTEGER_TOO_BIG;
     1869    }
     1870    return rc;
     1871}
     1872
     1873
     1874/**
     1875 * Query unsigned 16-bit integer value with default.
     1876 *
     1877 * @returns VBox status code.
     1878 * @param   pNode           Which node to search for pszName in.
     1879 * @param   pszName         Name of an integer value.
     1880 * @param   pu16            Where to store the value.
     1881 * @param   i16Def          The default value.
     1882 */
     1883CFGMR3DECL(int) CFGMR3QueryU16Def(PCFGMNODE pNode, const char *pszName, uint16_t *pu16, uint16_t u16Def)
     1884{
     1885    uint64_t u64;
     1886    int rc = CFGMR3QueryIntegerDef(pNode, pszName, &u64, u16Def);
     1887    if (VBOX_SUCCESS(rc))
     1888    {
     1889        if (!(u64 & UINT64_C(0xffffffffffff0000)))
    17091890            *pu16 = (int16_t)u64;
    17101891        else
     
    17291910    if (VBOX_SUCCESS(rc))
    17301911    {
    1731         if (   !(u64 & 0xffffffffffff8000ULL)
    1732             ||  (u64 & 0xffffffffffff8000ULL) == 0xffffffffffff8000ULL)
     1912        if (   !(u64 & UINT64_C(0xffffffffffff8000))
     1913            ||  (u64 & UINT64_C(0xffffffffffff8000)) == UINT64_C(0xffffffffffff8000))
     1914            *pi16 = (int16_t)u64;
     1915        else
     1916            rc = VERR_CFGM_INTEGER_TOO_BIG;
     1917    }
     1918    return rc;
     1919}
     1920
     1921
     1922/**
     1923 * Query signed 16-bit integer value with default.
     1924 *
     1925 * @returns VBox status code.
     1926 * @param   pNode           Which node to search for pszName in.
     1927 * @param   pszName         Name of an integer value.
     1928 * @param   pi16            Where to store the value.
     1929 * @param   i16Def          The default value.
     1930 */
     1931CFGMR3DECL(int) CFGMR3QueryS16Def(PCFGMNODE pNode, const char *pszName, int16_t *pi16, int16_t i16Def)
     1932{
     1933    uint64_t u64;
     1934    int rc = CFGMR3QueryIntegerDef(pNode, pszName, &u64, i16Def);
     1935    if (VBOX_SUCCESS(rc))
     1936    {
     1937        if (   !(u64 & UINT64_C(0xffffffffffff8000))
     1938            ||  (u64 & UINT64_C(0xffffffffffff8000)) == UINT64_C(0xffffffffffff8000))
    17331939            *pi16 = (int16_t)u64;
    17341940        else
     
    17531959    if (VBOX_SUCCESS(rc))
    17541960    {
    1755         if (!(u64 & 0xffffffffffffff00ULL))
     1961        if (!(u64 & UINT64_C(0xffffffffffffff00)))
     1962            *pu8 = (uint8_t)u64;
     1963        else
     1964            rc = VERR_CFGM_INTEGER_TOO_BIG;
     1965    }
     1966    return rc;
     1967}
     1968
     1969
     1970/**
     1971 * Query unsigned 8-bit integer value with default.
     1972 *
     1973 * @returns VBox status code.
     1974 * @param   pNode           Which node to search for pszName in.
     1975 * @param   pszName         Name of an integer value.
     1976 * @param   pu8             Where to store the value.
     1977 * @param   u8Def           The default value.
     1978 */
     1979CFGMR3DECL(int) CFGMR3QueryU8Def(PCFGMNODE pNode, const char *pszName, uint8_t *pu8, uint8_t u8Def)
     1980{
     1981    uint64_t u64;
     1982    int rc = CFGMR3QueryIntegerDef(pNode, pszName, &u64, u8Def);
     1983    if (VBOX_SUCCESS(rc))
     1984    {
     1985        if (!(u64 & UINT64_C(0xffffffffffffff00)))
    17561986            *pu8 = (uint8_t)u64;
    17571987        else
     
    17762006    if (VBOX_SUCCESS(rc))
    17772007    {
    1778         if (   !(u64 & 0xffffffffffffff80ULL)
    1779             ||  (u64 & 0xffffffffffffff80ULL) == 0xffffffffffffff80ULL)
     2008        if (   !(u64 & UINT64_C(0xffffffffffffff80))
     2009            ||  (u64 & UINT64_C(0xffffffffffffff80)) == UINT64_C(0xffffffffffffff80))
     2010            *pi8 = (int8_t)u64;
     2011        else
     2012            rc = VERR_CFGM_INTEGER_TOO_BIG;
     2013    }
     2014    return rc;
     2015}
     2016
     2017
     2018/**
     2019 * Query signed 8-bit integer value with default.
     2020 *
     2021 * @returns VBox status code.
     2022 * @param   pNode           Which node to search for pszName in.
     2023 * @param   pszName         Name of an integer value.
     2024 * @param   pi8             Where to store the value.
     2025 * @param   i8Def           The default value.
     2026 */
     2027CFGMR3DECL(int) CFGMR3QueryS8Def(PCFGMNODE pNode, const char *pszName, int8_t *pi8, int8_t i8Def)
     2028{
     2029    uint64_t u64;
     2030    int rc = CFGMR3QueryIntegerDef(pNode, pszName, &u64, i8Def);
     2031    if (VBOX_SUCCESS(rc))
     2032    {
     2033        if (   !(u64 & UINT64_C(0xffffffffffffff80))
     2034            ||  (u64 & UINT64_C(0xffffffffffffff80)) == UINT64_C(0xffffffffffffff80))
    17802035            *pi8 = (int8_t)u64;
    17812036        else
     
    18022057        *pf = u64 ? true : false;
    18032058    return rc;
     2059}
     2060
     2061
     2062/**
     2063 * Query boolean integer value with default.
     2064 *
     2065 * @returns VBox status code.
     2066 * @param   pNode           Which node to search for pszName in.
     2067 * @param   pszName         Name of an integer value.
     2068 * @param   pf              Where to store the value.
     2069 * @param   fDef            The default value.
     2070 * @remark  This function will interpret any non-zero value as true.
     2071 */
     2072CFGMR3DECL(int) CFGMR3QueryBoolDef(PCFGMNODE pNode, const char *pszName, bool *pf, bool fDef)
     2073{
     2074    uint64_t u64;
     2075    int rc = CFGMR3QueryIntegerDef(pNode, pszName, &u64, fDef);
     2076    if (VBOX_SUCCESS(rc))
     2077        *pf = u64 ? true : false;
     2078    return rc;
     2079}
     2080
     2081
     2082/**
     2083 * Query I/O port address value.
     2084 *
     2085 * @returns VBox status code.
     2086 * @param   pNode           Which node to search for pszName in.
     2087 * @param   pszName         Name of an integer value.
     2088 * @param   pPort           Where to store the value.
     2089 */
     2090CFGMR3DECL(int) CFGMR3QueryPort(PCFGMNODE pNode, const char *pszName, PRTIOPORT pPort)
     2091{
     2092    AssertCompileSize(RTIOPORT, 2);
     2093    return CFGMR3QueryU16(pNode, pszName, pPort);
     2094}
     2095
     2096
     2097/**
     2098 * Query I/O port address value with default.
     2099 *
     2100 * @returns VBox status code.
     2101 * @param   pNode           Which node to search for pszName in.
     2102 * @param   pszName         Name of an integer value.
     2103 * @param   pPort           Where to store the value.
     2104 * @param   PortDef         The default value.
     2105 */
     2106CFGMR3DECL(int) CFGMR3QueryPortDef(PCFGMNODE pNode, const char *pszName, PRTIOPORT pPort, RTIOPORT PortDef)
     2107{
     2108    AssertCompileSize(RTIOPORT, 2);
     2109    return CFGMR3QueryU16Def(pNode, pszName, pPort, PortDef);
    18042110}
    18052111
     
    18302136
    18312137/**
     2138 * Query pointer integer value with default.
     2139 *
     2140 * @returns VBox status code.
     2141 * @param   pNode           Which node to search for pszName in.
     2142 * @param   pszName         Name of an integer value.
     2143 * @param   ppv             Where to store the value.
     2144 * @param   pvDef           The default value.
     2145 */
     2146CFGMR3DECL(int) CFGMR3QueryPtrDef(PCFGMNODE pNode, const char *pszName, void **ppv, void *pvDef)
     2147{
     2148    uint64_t u64;
     2149    int rc = CFGMR3QueryIntegerDef(pNode, pszName, &u64, (uintptr_t)pvDef);
     2150    if (VBOX_SUCCESS(rc))
     2151    {
     2152        uintptr_t u = (uintptr_t)u64;
     2153        if (u64 == u)
     2154            *ppv = (void *)u;
     2155        else
     2156            rc = VERR_CFGM_INTEGER_TOO_BIG;
     2157    }
     2158    return rc;
     2159}
     2160
     2161
     2162/**
    18322163 * Query Guest Context pointer integer value.
    18332164 *
     
    18542185
    18552186/**
     2187 * Query Guest Context pointer integer value with default.
     2188 *
     2189 * @returns VBox status code.
     2190 * @param   pNode           Which node to search for pszName in.
     2191 * @param   pszName         Name of an integer value.
     2192 * @param   pGCPtr          Where to store the value.
     2193 * @param   GCPtrDef        The default value.
     2194 */
     2195CFGMR3DECL(int) CFGMR3QueryGCPtrDef(PCFGMNODE pNode, const char *pszName, PRTGCPTR pGCPtr, RTGCPTR GCPtrDef)
     2196{
     2197    uint64_t u64;
     2198    int rc = CFGMR3QueryIntegerDef(pNode, pszName, &u64, GCPtrDef);
     2199    if (VBOX_SUCCESS(rc))
     2200    {
     2201        RTGCPTR u = (RTGCPTR)u64;
     2202        if (u64 == u)
     2203            *pGCPtr = u;
     2204        else
     2205            rc = VERR_CFGM_INTEGER_TOO_BIG;
     2206    }
     2207    return rc;
     2208}
     2209
     2210
     2211/**
    18562212 * Query Guest Context unsigned pointer value.
    18572213 *
     
    18782234
    18792235/**
     2236 * Query Guest Context unsigned pointer value with default.
     2237 *
     2238 * @returns VBox status code.
     2239 * @param   pNode           Which node to search for pszName in.
     2240 * @param   pszName         Name of an integer value.
     2241 * @param   pGCPtr          Where to store the value.
     2242 * @param   GCPtrDef        The default value.
     2243 */
     2244CFGMR3DECL(int) CFGMR3QueryGCPtrUDef(PCFGMNODE pNode, const char *pszName, PRTGCUINTPTR pGCPtr, RTGCUINTPTR GCPtrDef)
     2245{
     2246    uint64_t u64;
     2247    int rc = CFGMR3QueryIntegerDef(pNode, pszName, &u64, GCPtrDef);
     2248    if (VBOX_SUCCESS(rc))
     2249    {
     2250        RTGCUINTPTR u = (RTGCUINTPTR)u64;
     2251        if (u64 == u)
     2252            *pGCPtr = u;
     2253        else
     2254            rc = VERR_CFGM_INTEGER_TOO_BIG;
     2255    }
     2256    return rc;
     2257}
     2258
     2259
     2260/**
    18802261 * Query Guest Context signed pointer value.
    18812262 *
     
    18892270    uint64_t u64;
    18902271    int rc = CFGMR3QueryInteger(pNode, pszName, &u64);
     2272    if (VBOX_SUCCESS(rc))
     2273    {
     2274        RTGCINTPTR u = (RTGCINTPTR)u64;
     2275        if (u64 == (uint64_t)u)
     2276            *pGCPtr = u;
     2277        else
     2278            rc = VERR_CFGM_INTEGER_TOO_BIG;
     2279    }
     2280    return rc;
     2281}
     2282
     2283
     2284/**
     2285 * Query Guest Context signed pointer value with default.
     2286 *
     2287 * @returns VBox status code.
     2288 * @param   pNode           Which node to search for pszName in.
     2289 * @param   pszName         Name of an integer value.
     2290 * @param   pGCPtr          Where to store the value.
     2291 * @param   GCPtrDef        The default value.
     2292 */
     2293CFGMR3DECL(int) CFGMR3QueryGCPtrSDef(PCFGMNODE pNode, const char *pszName, PRTGCINTPTR pGCPtr, RTGCINTPTR GCPtrDef)
     2294{
     2295    uint64_t u64;
     2296    int rc = CFGMR3QueryIntegerDef(pNode, pszName, &u64, GCPtrDef);
    18912297    if (VBOX_SUCCESS(rc))
    18922298    {
     
    19332339
    19342340
     2341/**
     2342 * Query zero terminated character value storing it in a
     2343 * buffer allocated from the MM heap.
     2344 *
     2345 * @returns VBox status code.
     2346 * @param   pNode           Which node to search for pszName in.
     2347 * @param   pszName         Value name. This value must be of zero terminated character string type.
     2348 * @param   ppszString      Where to store the string pointer.
     2349 *                          Free this using MMR3HeapFree().
     2350 */
     2351CFGMR3DECL(int) CFGMR3QueryStringAllocDef(PCFGMNODE pNode, const char *pszName, char **ppszString, const char *pszDef)
     2352{
     2353    size_t cch;
     2354    int rc = CFGMR3QuerySize(pNode, pszName, &cch);
     2355    if (rc == VERR_CFGM_VALUE_NOT_FOUND || rc == VERR_CFGM_NO_PARENT)
     2356    {
     2357        cch = strlen(pszDef) + 1;
     2358        rc = VINF_SUCCESS;
     2359    }
     2360    if (VBOX_SUCCESS(rc))
     2361    {
     2362        char *pszString = (char *)MMR3HeapAlloc(pNode->pVM, MM_TAG_CFGM_USER, cch);
     2363        if (pszString)
     2364        {
     2365            rc = CFGMR3QueryStringDef(pNode, pszName, pszString, cch, pszDef);
     2366            if (VBOX_SUCCESS(rc))
     2367                *ppszString = pszString;
     2368            else
     2369                MMR3HeapFree(pszString);
     2370        }
     2371        else
     2372            rc = VERR_NO_MEMORY;
     2373    }
     2374    return rc;
     2375}
     2376
    19352377
    19362378/**
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette