Changeset 39853 in vbox for trunk/src/VBox/VMM
- Timestamp:
- Jan 24, 2012 4:38:14 PM (13 years ago)
- svn:sync-xref-src-repo-rev:
- 75878
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/VMM/VMMR3/CFGM.cpp
r39838 r39853 1208 1208 * input parameter is NULL. 1209 1209 * @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 */ 1212 VMMR3DECL(int) CFGMR3DuplicateSubTree(PCFGMNODE pRoot, PCFGMNODE *ppCopy) 1213 { 1214 AssertPtrReturn(pRoot, VERR_INVALID_POINTER); 1214 1215 1215 1216 /* … … 1218 1219 PCFGMNODE pNewRoot = CFGMR3CreateTree(pRoot->pVM); 1219 1220 if (!pNewRoot) 1220 return pNewRoot;1221 return VERR_NO_MEMORY; 1221 1222 1222 1223 /* … … 1236 1237 /** @todo this isn't the most efficient way to do it. */ 1237 1238 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); 1259 1240 1260 1241 /* … … 1311 1292 { 1312 1293 CFGMR3RemoveNode(pNewRoot); 1313 return NULL; 1314 } 1315 1316 return pNewRoot; 1294 return rc; 1295 } 1296 1297 *ppCopy = pNewRoot; 1298 return VINF_SUCCESS; 1317 1299 } 1318 1300 … … 1341 1323 * Validate input. 1342 1324 */ 1325 AssertPtrReturn(pNode, VERR_INVALID_POINTER); 1343 1326 AssertPtrReturn(pSubTree, VERR_INVALID_POINTER); 1327 AssertReturn(pNode != pSubTree, VERR_INVALID_PARAMETER); 1344 1328 AssertReturn(!pSubTree->pParent, VERR_INVALID_PARAMETER); 1345 1329 AssertReturn(pSubTree->pVM, VERR_INVALID_PARAMETER); … … 1356 1340 { 1357 1341 Assert(!pNewChild->pFirstChild); 1342 Assert(!pNewChild->pFirstLeaf); 1343 1358 1344 pNewChild->pFirstChild = pSubTree->pFirstChild; 1359 Assert(!pNewChild->pFirstLeaf);1360 1345 pNewChild->pFirstLeaf = pSubTree->pFirstLeaf; 1346 for (PCFGMNODE pChild = pNewChild->pFirstChild; pChild; pChild = pChild->pNext) 1347 pChild->pParent = pNewChild; 1348 1361 1349 if (ppChild) 1362 1350 *ppChild = pNewChild; … … 1392 1380 AssertPtrReturn(pRoot, VERR_INVALID_POINTER); 1393 1381 AssertPtrReturn(pNewRoot, VERR_INVALID_POINTER); 1382 AssertReturn(pRoot != pNewRoot, VERR_INVALID_PARAMETER); 1394 1383 AssertReturn(!pNewRoot->pParent, VERR_INVALID_PARAMETER); 1395 1384 AssertReturn(pNewRoot->pVM, VERR_INVALID_PARAMETER); … … 1412 1401 pRoot->pFirstLeaf = pNewRoot->pFirstLeaf; 1413 1402 pRoot->pFirstChild = pNewRoot->pFirstChild; 1403 for (PCFGMNODE pChild = pRoot->pFirstChild; pChild; pChild = pChild->pNext) 1404 pChild->pParent = pRoot; 1414 1405 1415 1406 pNewRoot->pFirstLeaf = NULL; … … 1420 1411 return VINF_SUCCESS; 1421 1412 } 1413 1414 1415 VMMR3DECL(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 1422 1482 1423 1483 … … 2059 2119 2060 2120 /** 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 */ 2127 VMMR3DECL(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 /** 2061 2154 * Remove a value. 2062 2155 * … … 2973 3066 Assert(pChild->pPrev != pChild->pNext || !pChild->pPrev); 2974 3067 Assert(pChild->pFirstChild != pChild); 2975 Assert(pChild->pParent != pChild);3068 Assert(pChild->pParent == pRoot); 2976 3069 cfgmR3Dump(pChild, iLevel + 1, pHlp); 2977 3070 }
Note:
See TracChangeset
for help on using the changeset viewer.