Changeset 16234 in vbox
- Timestamp:
- Jan 26, 2009 2:20:26 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/ApplianceImpl.cpp
r16233 r16234 206 206 ComObjPtr<Appliance> appliance; 207 207 appliance.createObject(); 208 rc = appliance->init 208 rc = appliance->init(this, bstrPath); 209 209 // ComAssertComRCThrowRC(rc); 210 210 … … 427 427 VirtualSystem d; 428 428 429 const xml::Node *pIdAttr = pelmVirtualSystem->findAttribute(" type");429 const xml::Node *pIdAttr = pelmVirtualSystem->findAttribute("id"); 430 430 if (pIdAttr) 431 431 d.strName = pIdAttr->getValue(); … … 745 745 */ 746 746 747 HRESULT Appliance::init 747 HRESULT Appliance::init(VirtualBox *aVirtualBox, IN_BSTR &path) 748 748 { 749 749 HRESULT rc; … … 751 751 /* Enclose the state transition NotReady->InInit->Ready */ 752 752 AutoInitSpan autoInitSpan(this); 753 AssertReturn 753 AssertReturn(autoInitSpan.isOk(), E_FAIL); 754 754 755 755 /* Weakly reference to a VirtualBox object */ 756 unconst 756 unconst(mVirtualBox) = aVirtualBox; 757 757 758 758 // initialize data … … 809 809 810 810 rc = construeAppliance(); 811 if (FAILED 811 if (FAILED(rc)) 812 812 return rc; 813 813 … … 893 893 STDMETHODIMP Appliance::COMGETTER(VirtualSystemDescriptions)(ComSafeArrayOut(IVirtualSystemDescription*, aVirtualSystemDescriptions)) 894 894 { 895 CheckComArgOutSafeArrayPointerValid 896 897 AutoCaller autoCaller 898 CheckComRCReturnRC 899 900 AutoReadLock alock 901 902 SafeIfaceArray<IVirtualSystemDescription> sfaVSD 903 sfaVSD.detachTo (ComSafeArrayOutArg(aVirtualSystemDescriptions));895 CheckComArgOutSafeArrayPointerValid(aVirtualSystemDescriptions); 896 897 AutoCaller autoCaller(this); 898 CheckComRCReturnRC(autoCaller.rc()); 899 900 AutoReadLock alock(this); 901 902 SafeIfaceArray<IVirtualSystemDescription> sfaVSD(m->virtualSystemDescriptions); 903 sfaVSD.detachTo(ComSafeArrayOutArg(aVirtualSystemDescriptions)); 904 904 905 905 return S_OK; … … 923 923 924 924 /* Guest OS type */ 925 list<VirtualSystemDescriptionEntry> vsdeOS = vsd->findByType 926 Assert 925 list<VirtualSystemDescriptionEntry> vsdeOS = vsd->findByType(VirtualSystemDescriptionType_OS); 926 Assert(vsdeOS.size() == 1); 927 927 string osTypeVBox = vsdeOS.front().strFinalValue; 928 928 929 929 /* Now that we know the base system get our internal defaults based on that. */ 930 930 IGuestOSType *osType = NULL; 931 rc = mVirtualBox->GetGuestOSType (Bstr (Utf8Str(osTypeVBox.c_str())), &osType);932 ComAssertComRCThrowRC 931 rc = mVirtualBox->GetGuestOSType(Bstr(Utf8Str(osTypeVBox.c_str())), &osType); 932 ComAssertComRCThrowRC(rc); 933 933 934 934 /* Create the machine */ 935 935 /* First get the name */ 936 list<VirtualSystemDescriptionEntry> vsdeName = vsd->findByType 937 Assert 936 list<VirtualSystemDescriptionEntry> vsdeName = vsd->findByType(VirtualSystemDescriptionType_Name); 937 Assert(vsdeName.size() == 1); 938 938 string nameVBox = vsdeName.front().strFinalValue; 939 939 IMachine *newMachine = NULL; 940 rc = mVirtualBox->CreateMachine (Bstr (nameVBox.c_str()), Bstr(osTypeVBox.c_str()),941 Bstr(), Guid(),942 943 ComAssertComRCThrowRC 940 rc = mVirtualBox->CreateMachine(Bstr(nameVBox.c_str()), Bstr(osTypeVBox.c_str()), 941 Bstr(), Guid(), 942 &newMachine); 943 ComAssertComRCThrowRC(rc); 944 944 945 945 /* CPU count (ignored for now) */ … … 949 949 /* RAM */ 950 950 /* @todo: check min/max requirements of VBox (SchemaDefs::Min/MaxGuestRAM) */ 951 list<VirtualSystemDescriptionEntry> vsdeRAM = vsd->findByType 952 Assert 951 list<VirtualSystemDescriptionEntry> vsdeRAM = vsd->findByType(VirtualSystemDescriptionType_Memory); 952 Assert(vsdeRAM.size() == 1); 953 953 string memoryVBox = vsdeRAM.front().strFinalValue; 954 uint64_t tt = RTStrToUInt64 954 uint64_t tt = RTStrToUInt64(memoryVBox.c_str()) / _1M; 955 955 956 956 rc = newMachine->COMSETTER(MemorySize)(tt); 957 ComAssertComRCThrowRC 957 ComAssertComRCThrowRC(rc); 958 958 959 959 /* VRAM */ … … 961 961 /* @todo: check min/max requirements of VBox (SchemaDefs::Min/MaxGuestVRAM) */ 962 962 ULONG vramVBox; 963 rc = osType->COMGETTER(RecommendedVRAM) 964 ComAssertComRCThrowRC 963 rc = osType->COMGETTER(RecommendedVRAM)(&vramVBox); 964 ComAssertComRCThrowRC(rc); 965 965 /* Set the VRAM */ 966 rc = newMachine->COMSETTER(VRAMSize) 967 ComAssertComRCThrowRC 966 rc = newMachine->COMSETTER(VRAMSize)(vramVBox); 967 ComAssertComRCThrowRC(rc); 968 968 969 969 /* Change the network adapters */ 970 list<VirtualSystemDescriptionEntry> vsdeNW = vsd->findByType 970 list<VirtualSystemDescriptionEntry> vsdeNW = vsd->findByType(VirtualSystemDescriptionType_NetworkAdapter); 971 971 if (vsdeNW.size() == 0) 972 972 { 973 973 /* No network adapters, so we have to disable our default one */ 974 974 INetworkAdapter *nwVBox = NULL; 975 rc = newMachine->GetNetworkAdapter 976 ComAssertComRCThrowRC 977 rc = nwVBox->COMSETTER(Enabled) 978 ComAssertComRCThrowRC 975 rc = newMachine->GetNetworkAdapter(0, &nwVBox); 976 ComAssertComRCThrowRC(rc); 977 rc = nwVBox->COMSETTER(Enabled)(false); 978 ComAssertComRCThrowRC(rc); 979 979 } 980 980 else … … 989 989 { 990 990 string nwTypeVBox = nwIt->strFinalValue; 991 uint32_t tt1 = RTStrToUInt32 991 uint32_t tt1 = RTStrToUInt32(nwTypeVBox.c_str()); 992 992 INetworkAdapter *nwVBox = NULL; 993 rc = newMachine->GetNetworkAdapter 994 ComAssertComRCThrowRC 993 rc = newMachine->GetNetworkAdapter((ULONG)a, &nwVBox); 994 ComAssertComRCThrowRC(rc); 995 995 /* Enable the network card & set the adapter type */ 996 996 /* NAT is set as default */ 997 rc = nwVBox->COMSETTER(Enabled) 998 ComAssertComRCThrowRC 999 rc = nwVBox->COMSETTER(AdapterType) (static_cast<NetworkAdapterType_T>(tt1));1000 ComAssertComRCThrowRC 997 rc = nwVBox->COMSETTER(Enabled)(true); 998 ComAssertComRCThrowRC(rc); 999 rc = nwVBox->COMSETTER(AdapterType)(static_cast<NetworkAdapterType_T>(tt1)); 1000 ComAssertComRCThrowRC(rc); 1001 1001 } 1002 1002 } 1003 1003 /* Now its time to register the machine before we add any hard disks */ 1004 rc = mVirtualBox->RegisterMachine 1005 ComAssertComRCThrowRC 1004 rc = mVirtualBox->RegisterMachine(newMachine); 1005 ComAssertComRCThrowRC(rc); 1006 1006 1007 1007 /* @todo: Unregister on failure */ … … 1033 1033 /* We need the default path for storing disk images */ 1034 1034 ISystemProperties *systemProps = NULL; 1035 rc = mVirtualBox->COMGETTER(SystemProperties) 1036 ComAssertComRCThrowRC 1035 rc = mVirtualBox->COMGETTER(SystemProperties)(&systemProps); 1036 ComAssertComRCThrowRC(rc); 1037 1037 BSTR defaultHardDiskLocation; 1038 rc = systemProps->COMGETTER(DefaultHardDiskFolder) 1039 ComAssertComRCThrowRC 1038 rc = systemProps->COMGETTER(DefaultHardDiskFolder)(&defaultHardDiskLocation); 1039 ComAssertComRCThrowRC(rc); 1040 1040 1041 1041 list<VirtualSystem>::const_iterator it; … … 1235 1235 } 1236 1236 } 1237 vsd->addEntry (VirtualSystemDescriptionType_OS, 0, toString<ULONG>(vs.cimos), osTypeVBox);1237 vsd->addEntry(VirtualSystemDescriptionType_OS, 0, toString<ULONG>(vs.cimos), osTypeVBox); 1238 1238 1239 1239 /* VM name */ … … 1243 1243 if (nameVBox == "") 1244 1244 nameVBox = osTypeVBox; 1245 searchUniqueVMName 1246 vsd->addEntry 1245 searchUniqueVMName(nameVBox); 1246 vsd->addEntry(VirtualSystemDescriptionType_Name, 0, vs.strName, nameVBox); 1247 1247 1248 1248 /* Now that we know the base system get our internal defaults based on that. */ 1249 1249 IGuestOSType *osType = NULL; 1250 rc = mVirtualBox->GetGuestOSType (Bstr (Utf8Str(osTypeVBox.c_str())), &osType);1251 ComAssertComRCThrowRC 1250 rc = mVirtualBox->GetGuestOSType(Bstr(Utf8Str(osTypeVBox.c_str())), &osType); 1251 ComAssertComRCThrowRC(rc); 1252 1252 1253 1253 /* CPU count */ … … 1256 1256 if (vs.cCPUs == 0) 1257 1257 cpuCountVBox = 1; 1258 vsd->addEntry (VirtualSystemDescriptionType_CPU, 0, toString<ULONG> (vs.cCPUs), toString<ULONG>(cpuCountVBox));1258 vsd->addEntry(VirtualSystemDescriptionType_CPU, 0, toString<ULONG>(vs.cCPUs), toString<ULONG>(cpuCountVBox)); 1259 1259 1260 1260 /* RAM */ … … 1266 1266 ULONG memSizeVBox2; 1267 1267 rc = osType->COMGETTER(RecommendedRAM)(&memSizeVBox2); 1268 ComAssertComRCThrowRC 1268 ComAssertComRCThrowRC(rc); 1269 1269 /* VBox stores that in MByte */ 1270 1270 ullMemSizeVBox = memSizeVBox2 * _1M; 1271 1271 } 1272 vsd->addEntry (VirtualSystemDescriptionType_Memory, 0, toString<uint64_t> (vs.ullMemorySize), toString<uint64_t>(ullMemSizeVBox));1272 vsd->addEntry(VirtualSystemDescriptionType_Memory, 0, toString<uint64_t>(vs.ullMemorySize), toString<uint64_t>(ullMemSizeVBox)); 1273 1273 1274 1274 /* Hard disk Controller */ … … 1287 1287 /* Use PIIX4 as default */ 1288 1288 IDEControllerType_T hdcController = IDEControllerType_PIIX4; 1289 if (!RTStrICmp 1289 if (!RTStrICmp(hdc.strControllerType.c_str(), "PIIX3")) 1290 1290 hdcController = IDEControllerType_PIIX3; 1291 else if (!RTStrICmp 1291 else if (!RTStrICmp(hdc.strControllerType.c_str(), "PIIX4")) 1292 1292 hdcController = IDEControllerType_PIIX4; 1293 vsd->addEntry (VirtualSystemDescriptionType_HarddiskControllerIDE, hdc.idController, hdc.strControllerType, toString<ULONG>(hdcController));1293 vsd->addEntry(VirtualSystemDescriptionType_HarddiskControllerIDE, hdc.idController, hdc.strControllerType, toString<ULONG>(hdcController)); 1294 1294 break; 1295 1295 } … … 1298 1298 // @todo: figure out the SATA types 1299 1299 /* We only support a plain AHCI controller, so use them always */ 1300 vsd->addEntry 1300 vsd->addEntry(VirtualSystemDescriptionType_HarddiskControllerSATA, hdc.idController, hdc.strControllerType, "AHCI"); 1301 1301 break; 1302 1302 } … … 1305 1305 string hdcController = "LsiLogic"; 1306 1306 // @todo: figure out the SCSI types 1307 if (!RTStrICmp 1307 if (!RTStrICmp(hdc.strControllerType.c_str(), "LsiLogic")) 1308 1308 hdcController = "LsiLogic"; 1309 else if (!RTStrICmp 1309 else if (!RTStrICmp(hdc.strControllerType.c_str(), "BusLogic")) 1310 1310 hdcController = "BusLogic"; 1311 vsd->addEntry 1311 vsd->addEntry(VirtualSystemDescriptionType_HarddiskControllerSCSI, hdc.idController, hdc.strControllerType, hdcController); 1312 1312 break; 1313 1313 } … … 1336 1336 // - figure out if there is a url specifier for vhd already 1337 1337 // - we need a url specifier for the vdi format 1338 if (!RTStrICmp 1338 if (!RTStrICmp(di.strFormat.c_str(), "http://www.vmware.com/specifications/vmdk.html#sparse")) 1339 1339 fSupported = true; 1340 1340 /* enable compressed formats for the first tests also */ 1341 else if (!RTStrICmp 1341 else if (!RTStrICmp(di.strFormat.c_str(), "http://www.vmware.com/specifications/vmdk.html#compressed")) 1342 1342 fSupported = true; 1343 1343 if (fSupported) 1344 1344 { 1345 1345 /* Construct the path */ 1346 string path = Utf8StrFmt 1347 vsd->addEntry 1346 string path = Utf8StrFmt("%ls%c%s", defaultHardDiskLocation, RTPATH_DELIMITER, di.strHref.c_str()).raw(); 1347 vsd->addEntry(VirtualSystemDescriptionType_Harddisk, hd.idController, di.strHref, path); 1348 1348 } 1349 1349 } … … 1356 1356 /* Get the default network adapter type for the selected guest OS */ 1357 1357 NetworkAdapterType_T nwAdapterVBox = NetworkAdapterType_Am79C970A; 1358 rc = osType->COMGETTER(AdapterType) 1359 ComAssertComRCThrowRC 1358 rc = osType->COMGETTER(AdapterType)(&nwAdapterVBox); 1359 ComAssertComRCThrowRC(rc); 1360 1360 list<string>::const_iterator nwIt; 1361 1361 /* Iterate through all abstract networks. We support 8 network … … 1367 1367 { 1368 1368 // string nwController = *nwIt; // @todo: not used yet 1369 vsd->addEntry (VirtualSystemDescriptionType_NetworkAdapter, 0, "", toString<ULONG>(nwAdapterVBox));1369 vsd->addEntry(VirtualSystemDescriptionType_NetworkAdapter, 0, "", toString<ULONG>(nwAdapterVBox)); 1370 1370 } 1371 1371 } 1372 m->virtualSystemDescriptions.push_back 1372 m->virtualSystemDescriptions.push_back(vsd); 1373 1373 } 1374 1374 … … 1376 1376 } 1377 1377 1378 HRESULT Appliance::searchUniqueVMName 1378 HRESULT Appliance::searchUniqueVMName(std::string& aName) 1379 1379 { 1380 1380 IMachine *machine = NULL; 1381 char *tmpName = RTStrDup 1381 char *tmpName = RTStrDup(aName.c_str()); 1382 1382 int i = 1; 1383 1383 /* @todo: Maybe to cost intensive; try to find a lighter way */ 1384 while (mVirtualBox->FindMachine (Bstr(tmpName), &machine) != VBOX_E_OBJECT_NOT_FOUND)1384 while (mVirtualBox->FindMachine(Bstr(tmpName), &machine) != VBOX_E_OBJECT_NOT_FOUND) 1385 1385 { 1386 RTStrFree 1387 RTStrAPrintf 1386 RTStrFree(tmpName); 1387 RTStrAPrintf(&tmpName, "%s_%d", aName.c_str(), i); 1388 1388 ++i; 1389 1389 } 1390 1390 aName = tmpName; 1391 RTStrFree 1391 RTStrFree(tmpName); 1392 1392 1393 1393 return S_OK; … … 1408 1408 { 1409 1409 /* Enclose the state transition NotReady->InInit->Ready */ 1410 AutoInitSpan autoInitSpan 1411 AssertReturn 1410 AutoInitSpan autoInitSpan(this); 1411 AssertReturn(autoInitSpan.isOk(), E_FAIL); 1412 1412 1413 1413 /* Initialize data */ … … 1426 1426 } 1427 1427 1428 STDMETHODIMP VirtualSystemDescription::GetDescription 1429 1430 1431 1432 1433 { 1434 if (ComSafeArrayOutIsNull 1435 ComSafeArrayOutIsNull 1436 ComSafeArrayOutIsNull 1437 ComSafeArrayOutIsNull 1438 ComSafeArrayOutIsNull 1428 STDMETHODIMP VirtualSystemDescription::GetDescription(ComSafeArrayOut(VirtualSystemDescriptionType_T, aTypes), 1429 ComSafeArrayOut(ULONG, aRefs), 1430 ComSafeArrayOut(BSTR, aOrigValues), 1431 ComSafeArrayOut(BSTR, aAutoValues), 1432 ComSafeArrayOut(BSTR, aConfigurations)) 1433 { 1434 if (ComSafeArrayOutIsNull(aTypes) || 1435 ComSafeArrayOutIsNull(aRefs) || 1436 ComSafeArrayOutIsNull(aOrigValues) || 1437 ComSafeArrayOutIsNull(aAutoValues) || 1438 ComSafeArrayOutIsNull(aConfigurations)) 1439 1439 return E_POINTER; 1440 1440 1441 AutoCaller autoCaller 1442 CheckComRCReturnRC 1443 1444 AutoReadLock alock 1441 AutoCaller autoCaller(this); 1442 CheckComRCReturnRC(autoCaller.rc()); 1443 1444 AutoReadLock alock(this); 1445 1445 1446 1446 ULONG c = (ULONG)m->descriptions.size(); 1447 com::SafeArray<VirtualSystemDescriptionType_T> sfaTypes 1448 com::SafeArray<ULONG> sfaRefs 1449 com::SafeArray<BSTR> sfaOrigValues 1450 com::SafeArray<BSTR> sfaAutoValues 1451 com::SafeArray<BSTR> sfaConfigurations 1447 com::SafeArray<VirtualSystemDescriptionType_T> sfaTypes(c); 1448 com::SafeArray<ULONG> sfaRefs(c); 1449 com::SafeArray<BSTR> sfaOrigValues(c); 1450 com::SafeArray<BSTR> sfaAutoValues(c); 1451 com::SafeArray<BSTR> sfaConfigurations(c); 1452 1452 1453 1453 list<VirtualSystemDescriptionEntry>::const_iterator it; … … 1463 1463 sfaRefs [i] = vsde.ref; 1464 1464 /* Original value */ 1465 Bstr bstr = Utf8Str 1466 bstr.cloneTo 1465 Bstr bstr = Utf8Str(vsde.strOriginalValue.c_str()); 1466 bstr.cloneTo(&sfaOrigValues [i]); 1467 1467 /* Auto value */ 1468 bstr = Utf8Str 1469 bstr.cloneTo 1468 bstr = Utf8Str(vsde.strAutoValue.c_str()); 1469 bstr.cloneTo(&sfaAutoValues [i]); 1470 1470 /* Configuration */ 1471 bstr = Utf8Str 1472 bstr.cloneTo 1471 bstr = Utf8Str(vsde.strConfiguration.c_str()); 1472 bstr.cloneTo(&sfaConfigurations [i]); 1473 1473 } 1474 1474 1475 sfaTypes.detachTo (ComSafeArrayOutArg(aTypes));1476 sfaRefs.detachTo (ComSafeArrayOutArg(aRefs));1477 sfaOrigValues.detachTo (ComSafeArrayOutArg(aOrigValues));1478 sfaAutoValues.detachTo (ComSafeArrayOutArg(aAutoValues));1479 sfaConfigurations.detachTo (ComSafeArrayOutArg(aConfigurations));1475 sfaTypes.detachTo(ComSafeArrayOutArg(aTypes)); 1476 sfaRefs.detachTo(ComSafeArrayOutArg(aRefs)); 1477 sfaOrigValues.detachTo(ComSafeArrayOutArg(aOrigValues)); 1478 sfaAutoValues.detachTo(ComSafeArrayOutArg(aAutoValues)); 1479 sfaConfigurations.detachTo(ComSafeArrayOutArg(aConfigurations)); 1480 1480 1481 1481 return S_OK; 1482 1482 } 1483 1483 1484 STDMETHODIMP VirtualSystemDescription::SetFinalValues (ComSafeArrayIn(IN_BSTR, aFinalValues))1485 { 1486 CheckComArgSafeArrayNotNull 1487 1488 AutoCaller autoCaller 1489 CheckComRCReturnRC 1490 1491 AutoWriteLock alock 1492 1493 com::SafeArray <IN_BSTR> values (ComSafeArrayInArg(aFinalValues));1484 STDMETHODIMP VirtualSystemDescription::SetFinalValues(ComSafeArrayIn(IN_BSTR, aFinalValues)) 1485 { 1486 CheckComArgSafeArrayNotNull(aFinalValues); 1487 1488 AutoCaller autoCaller(this); 1489 CheckComRCReturnRC(autoCaller.rc()); 1490 1491 AutoWriteLock alock(this); 1492 1493 com::SafeArray <IN_BSTR> values(ComSafeArrayInArg(aFinalValues)); 1494 1494 if (values.size() != m->descriptions.size()) 1495 1495 return E_INVALIDARG; … … 1502 1502 { 1503 1503 VirtualSystemDescriptionEntry vsde = (*it); 1504 vsde.strFinalValue = Utf8Str (values[i]).raw();1504 vsde.strFinalValue = Utf8Str(values[i]).raw(); 1505 1505 } 1506 1506 … … 1508 1508 } 1509 1509 1510 void VirtualSystemDescription::addEntry 1510 void VirtualSystemDescription::addEntry(VirtualSystemDescriptionType_T aType, ULONG aRef, std::string aOrigValue, std::string aAutoValue) 1511 1511 { 1512 1512 VirtualSystemDescriptionEntry vsde; … … 1518 1518 vsde.strFinalValue = aAutoValue; 1519 1519 1520 m->descriptions.push_back 1521 } 1522 1523 list<VirtualSystemDescriptionEntry> VirtualSystemDescription::findByType 1520 m->descriptions.push_back(vsde); 1521 } 1522 1523 list<VirtualSystemDescriptionEntry> VirtualSystemDescription::findByType(VirtualSystemDescriptionType_T aType) 1524 1524 { 1525 1525 list<VirtualSystemDescriptionEntry> vsd; … … 1530 1530 ++it) 1531 1531 if (it->type == aType) 1532 vsd.push_back 1532 vsd.push_back(*it); 1533 1533 1534 1534 return vsd;
Note:
See TracChangeset
for help on using the changeset viewer.