VirtualBox

Changeset 39853 in vbox for trunk/src/VBox/VMM


Ignore:
Timestamp:
Jan 24, 2012 4:38:14 PM (13 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
75878
Message:

CFGM: Added CFGMR3InsertValue and CFGMR3CopyTree; changed CFGMR3DuplicateSubTree; bugfixed CFGMR3InsertSubTree and CFGMR3ReplaceSubTree.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/VMM/VMMR3/CFGM.cpp

    r39838 r39853  
    12081208 *          input parameter is NULL.
    12091209 * @param   pRoot       The root of the tree to duplicate.
    1210  */
    1211 VMMR3DECL(PCFGMNODE) CFGMR3DuplicateSubTree(PCFGMNODE pRoot)
    1212 {
    1213     AssertPtrReturn(pRoot, NULL);
     1210 * @param   ppCopy      Where to return the root of the duplicate.
     1211 */
     1212VMMR3DECL(int) CFGMR3DuplicateSubTree(PCFGMNODE pRoot, PCFGMNODE *ppCopy)
     1213{
     1214    AssertPtrReturn(pRoot, VERR_INVALID_POINTER);
    12141215
    12151216    /*
     
    12181219    PCFGMNODE pNewRoot = CFGMR3CreateTree(pRoot->pVM);
    12191220    if (!pNewRoot)
    1220         return pNewRoot;
     1221        return VERR_NO_MEMORY;
    12211222
    12221223    /*
     
    12361237            /** @todo this isn't the most efficient way to do it. */
    12371238            for (PCFGMLEAF pLeaf = pSrcCur->pFirstLeaf; pLeaf && RT_SUCCESS(rc); pLeaf = pLeaf->pNext)
    1238             {
    1239                 switch (pLeaf->enmType)
    1240                 {
    1241                     case CFGMVALUETYPE_INTEGER:
    1242                         rc = CFGMR3InsertInteger(pDstCur, pLeaf->szName, pLeaf->Value.Integer.u64);
    1243                         break;
    1244 
    1245                     case CFGMVALUETYPE_BYTES:
    1246                         rc = CFGMR3InsertBytes(pDstCur, pLeaf->szName, pLeaf->Value.Bytes.pau8, pLeaf->Value.Bytes.cb);
    1247                         break;
    1248 
    1249                     case CFGMVALUETYPE_STRING:
    1250                         rc = CFGMR3InsertStringN(pDstCur, pLeaf->szName, pLeaf->Value.String.psz, pLeaf->Value.String.cb - 1);
    1251                         break;
    1252 
    1253                     default:
    1254                         rc = VERR_CFGM_IPE_1;
    1255                         AssertMsgFailed(("Invalid value type %d\n", pLeaf->enmType));
    1256                         break;
    1257                 }
    1258             }
     1239                rc = CFGMR3InsertValue(pDstCur, pLeaf);
    12591240
    12601241            /*
     
    13111292    {
    13121293        CFGMR3RemoveNode(pNewRoot);
    1313         return NULL;
    1314     }
    1315 
    1316     return pNewRoot;
     1294        return rc;
     1295    }
     1296
     1297    *ppCopy = pNewRoot;
     1298    return VINF_SUCCESS;
    13171299}
    13181300
     
    13411323     * Validate input.
    13421324     */
     1325    AssertPtrReturn(pNode, VERR_INVALID_POINTER);
    13431326    AssertPtrReturn(pSubTree, VERR_INVALID_POINTER);
     1327    AssertReturn(pNode != pSubTree, VERR_INVALID_PARAMETER);
    13441328    AssertReturn(!pSubTree->pParent, VERR_INVALID_PARAMETER);
    13451329    AssertReturn(pSubTree->pVM, VERR_INVALID_PARAMETER);
     
    13561340    {
    13571341        Assert(!pNewChild->pFirstChild);
     1342        Assert(!pNewChild->pFirstLeaf);
     1343
    13581344        pNewChild->pFirstChild = pSubTree->pFirstChild;
    1359         Assert(!pNewChild->pFirstLeaf);
    13601345        pNewChild->pFirstLeaf = pSubTree->pFirstLeaf;
     1346        for (PCFGMNODE pChild = pNewChild->pFirstChild; pChild; pChild = pChild->pNext)
     1347            pChild->pParent = pNewChild;
     1348
    13611349        if (ppChild)
    13621350            *ppChild = pNewChild;
     
    13921380    AssertPtrReturn(pRoot, VERR_INVALID_POINTER);
    13931381    AssertPtrReturn(pNewRoot, VERR_INVALID_POINTER);
     1382    AssertReturn(pRoot != pNewRoot, VERR_INVALID_PARAMETER);
    13941383    AssertReturn(!pNewRoot->pParent, VERR_INVALID_PARAMETER);
    13951384    AssertReturn(pNewRoot->pVM, VERR_INVALID_PARAMETER);
     
    14121401    pRoot->pFirstLeaf       = pNewRoot->pFirstLeaf;
    14131402    pRoot->pFirstChild      = pNewRoot->pFirstChild;
     1403    for (PCFGMNODE pChild = pRoot->pFirstChild; pChild; pChild = pChild->pNext)
     1404        pChild->pParent     = pRoot;
    14141405
    14151406    pNewRoot->pFirstLeaf    = NULL;
     
    14201411    return VINF_SUCCESS;
    14211412}
     1413
     1414
     1415VMMR3DECL(int) CFGMR3CopyTree(PCFGMNODE pDstTree, PCFGMNODE pSrcTree, uint32_t fFlags)
     1416{
     1417    /*
     1418     * Input validation.
     1419     */
     1420    AssertPtrReturn(pSrcTree, VERR_INVALID_POINTER);
     1421    AssertPtrReturn(pDstTree, VERR_INVALID_POINTER);
     1422    AssertReturn(pDstTree != pDstTree, VERR_INVALID_PARAMETER);
     1423    AssertReturn(!(fFlags & ~(CFGM_COPY_FLAGS_VALUE_DISP_MASK | CFGM_COPY_FLAGS_KEY_DISP_MASK)), VERR_INVALID_PARAMETER);
     1424    AssertReturn(   (fFlags & CFGM_COPY_FLAGS_VALUE_DISP_MASK) != CFGM_COPY_FLAGS_RESERVED_VALUE_DISP_0
     1425                 && (fFlags & CFGM_COPY_FLAGS_VALUE_DISP_MASK) != CFGM_COPY_FLAGS_RESERVED_VALUE_DISP_1,
     1426                 VERR_INVALID_PARAMETER);
     1427    AssertReturn((fFlags & CFGM_COPY_FLAGS_KEY_DISP_MASK) != CFGM_COPY_FLAGS_RESERVED_KEY_DISP,
     1428                 VERR_INVALID_PARAMETER);
     1429
     1430    /*
     1431     * Copy the values.
     1432     */
     1433    int rc;
     1434    for (PCFGMLEAF pValue = CFGMR3GetFirstValue(pSrcTree); pValue; pValue = CFGMR3GetNextValue(pValue))
     1435    {
     1436        rc = CFGMR3InsertValue(pDstTree, pValue);
     1437        if (rc == VERR_CFGM_LEAF_EXISTS)
     1438        {
     1439            if ((fFlags & CFGM_COPY_FLAGS_VALUE_DISP_MASK) == CFGM_COPY_FLAGS_REPLACE_VALUES)
     1440            {
     1441                rc = CFGMR3RemoveValue(pDstTree, pValue->szName);
     1442                if (RT_FAILURE(rc))
     1443                    break;
     1444                rc = CFGMR3InsertValue(pDstTree, pValue);
     1445            }
     1446            else
     1447                rc = VINF_SUCCESS;
     1448        }
     1449        AssertRCReturn(rc, rc);
     1450    }
     1451
     1452    /*
     1453     * Copy/merge the keys - merging results in recursion.
     1454     */
     1455    for (PCFGMNODE pSrcChild = CFGMR3GetFirstChild(pSrcTree); pSrcChild; pSrcChild = CFGMR3GetNextChild(pSrcChild))
     1456    {
     1457        PCFGMNODE pDstChild = CFGMR3GetChild(pDstTree, pSrcChild->szName);
     1458        if (   pDstChild
     1459            && (fFlags & CFGM_COPY_FLAGS_KEY_DISP_MASK) == CFGM_COPY_FLAGS_REPLACE_KEYS)
     1460        {
     1461            CFGMR3RemoveNode(pDstChild);
     1462            pDstChild = NULL;
     1463        }
     1464        if (!pDstChild)
     1465        {
     1466            PCFGMNODE pChildCopy;
     1467            rc = CFGMR3DuplicateSubTree(pSrcChild, &pChildCopy);
     1468            AssertRCReturn(rc, rc);
     1469            rc = CFGMR3InsertSubTree(pDstTree, pSrcChild->szName, pChildCopy, NULL);
     1470            AssertRCReturnStmt(rc, CFGMR3RemoveNode(pChildCopy), rc);
     1471        }
     1472        else if ((fFlags & CFGM_COPY_FLAGS_KEY_DISP_MASK) == CFGM_COPY_FLAGS_MERGE_KEYS)
     1473        {
     1474            rc = CFGMR3CopyTree(pDstChild, pSrcChild, fFlags);
     1475            AssertRCReturn(rc, rc);
     1476        }
     1477    }
     1478
     1479    return VINF_SUCCESS;
     1480}
     1481
    14221482
    14231483
     
    20592119
    20602120/**
     2121 * Make a copy of the specified value under the given node.
     2122 *
     2123 * @returns VBox status code.
     2124 * @param   pNode               Parent node.
     2125 * @param   pValue              The value to copy and insert.
     2126 */
     2127VMMR3DECL(int) CFGMR3InsertValue(PCFGMNODE pNode, PCFGMLEAF pValue)
     2128{
     2129    int rc;
     2130    switch (pValue->enmType)
     2131    {
     2132        case CFGMVALUETYPE_INTEGER:
     2133            rc = CFGMR3InsertInteger(pNode, pValue->szName, pValue->Value.Integer.u64);
     2134            break;
     2135
     2136        case CFGMVALUETYPE_BYTES:
     2137            rc = CFGMR3InsertBytes(pNode, pValue->szName, pValue->Value.Bytes.pau8, pValue->Value.Bytes.cb);
     2138            break;
     2139
     2140        case CFGMVALUETYPE_STRING:
     2141            rc = CFGMR3InsertStringN(pNode, pValue->szName, pValue->Value.String.psz, pValue->Value.String.cb - 1);
     2142            break;
     2143
     2144        default:
     2145            rc = VERR_CFGM_IPE_1;
     2146            AssertMsgFailed(("Invalid value type %d\n", pValue->enmType));
     2147            break;
     2148    }
     2149    return rc;
     2150}
     2151
     2152
     2153/**
    20612154 * Remove a value.
    20622155 *
     
    29733066        Assert(pChild->pPrev != pChild->pNext || !pChild->pPrev);
    29743067        Assert(pChild->pFirstChild != pChild);
    2975         Assert(pChild->pParent != pChild);
     3068        Assert(pChild->pParent == pRoot);
    29763069        cfgmR3Dump(pChild, iLevel + 1, pHlp);
    29773070    }
Note: See TracChangeset for help on using the changeset viewer.

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