Changeset 30881 in vbox
- Timestamp:
- Jul 16, 2010 2:34:31 PM (15 years ago)
- svn:sync-xref-src-repo-rev:
- 63716
- Location:
- trunk/src/VBox/Main
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/ApplianceImpl.cpp
r30764 r30881 454 454 } 455 455 456 /** 457 * Public method implementation. 458 * @param aDisks 459 * @return 460 */ 461 STDMETHODIMP Appliance::COMGETTER(Machines)(ComSafeArrayOut(BSTR, aMachines)) 462 { 463 CheckComArgOutSafeArrayPointerValid(aMachines); 464 465 AutoCaller autoCaller(this); 466 if (FAILED(autoCaller.rc())) return autoCaller.rc(); 467 468 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS); 469 470 if (!isApplianceIdle()) 471 return E_ACCESSDENIED; 472 473 com::SafeArray<BSTR> sfaMachines(m->llGuidsMachinesCreated.size()); 474 size_t u = 0; 475 for (std::list<Guid>::const_iterator it = m->llGuidsMachinesCreated.begin(); 476 it != m->llGuidsMachinesCreated.end(); 477 ++it) 478 { 479 const Guid &uuid = *it; 480 Bstr bstr(uuid.toUtf16()); 481 bstr.detachTo(&sfaMachines[u]); 482 ++u; 483 } 484 485 sfaMachines.detachTo(ComSafeArrayOutArg(aMachines)); 486 487 return S_OK; 488 } 489 456 490 STDMETHODIMP Appliance::CreateVFSExplorer(IN_BSTR aURI, IVFSExplorer **aExplorer) 457 491 { -
trunk/src/VBox/Main/ApplianceImplImport.cpp
r30876 r30881 1114 1114 ImportStack stack(locInfo, reader.m_mapDisks, pProgress); 1115 1115 1116 // clear the list of imported machines, if any 1117 m->llGuidsMachinesCreated.clear(); 1118 1116 1119 try 1117 1120 { … … 1259 1262 1260 1263 // finally, deregister and remove all machines 1261 list<Bstr>::iterator itID; 1262 for (itID = stack.llMachinesRegistered.begin(); 1263 itID != stack.llMachinesRegistered.end(); 1264 for (list<Guid>::iterator itID = m->llGuidsMachinesCreated.begin(); 1265 itID != m->llGuidsMachinesCreated.end(); 1264 1266 ++itID) 1265 1267 { 1266 Bstr bstrGuid = *itID; // make a copy, Windows can't handle const Bstr 1268 Guid guid = *itID; 1269 Bstr bstrGuid = guid.toUtf16(); 1267 1270 ComPtr<IMachine> failedMachine; 1268 1271 rc2 = mVirtualBox->UnregisterMachine(bstrGuid, failedMachine.asOutParam()); … … 1738 1741 rc = pNewMachine->COMGETTER(Id)(bstrNewMachineId.asOutParam()); 1739 1742 if (FAILED(rc)) DebugBreakThrow(rc); 1740 stack.llMachinesRegistered.push_back(bstrNewMachineId);1743 m->llGuidsMachinesCreated.push_back(Guid(bstrNewMachineId)); 1741 1744 1742 1745 // Add floppies and CD-ROMs to the appropriate controllers. … … 2153 2156 rc = pNewMachine->COMGETTER(Id)(bstrNewMachineId.asOutParam()); 2154 2157 if (FAILED(rc)) DebugBreakThrow(rc); 2155 stack.llMachinesRegistered.push_back(bstrNewMachineId);2158 m->llGuidsMachinesCreated.push_back(Guid(bstrNewMachineId)); 2156 2159 } 2157 2160 -
trunk/src/VBox/Main/VirtualBoxImpl.cpp
r30871 r30881 1392 1392 /* save the global registry */ 1393 1393 rc = saveSettings(); 1394 1395 alock.release(); 1394 1396 1395 1397 /* return the unregistered machine to the caller */ -
trunk/src/VBox/Main/idl/VirtualBox.xidl
r30871 r30881 1316 1316 <interface 1317 1317 name="IVirtualBox" extends="$unknown" 1318 uuid=" f0c2e058-8c72-4d56-95e7-3107627aba6e"1318 uuid="2275c97d-31b0-41c7-a138-c77d3c28406e" 1319 1319 wsmap="managed" 1320 1320 > … … 1710 1710 <method name="unregisterMachine"> 1711 1711 <desc> 1712 1713 1712 Unregisters the machine previously registered using 1714 1713 <link to="#registerMachine"/>. After successful method invocation, the … … 2894 2893 <interface 2895 2894 name="IAppliance" extends="$unknown" 2896 uuid=" e3ba9ab9-ac2c-4266-8bd2-91c4bf721ceb"2895 uuid="fb61a4fc-57e7-48d6-859b-71f37d484cf2" 2897 2896 wsmap="managed" 2898 2897 > … … 2946 2945 <li>Finally, call <link to="#importMachines" /> to create virtual machines in 2947 2946 VirtualBox as instances of <link to="IMachine" /> that match the information in the 2948 virtual system descriptions. 2947 virtual system descriptions. After this call suceeded, the UUIDs of the machines created 2948 can be found in the <link to="#machines" /> array attribute. 2949 2949 </li> 2950 2950 </ol> … … 3027 3027 </attribute> 3028 3028 3029 <attribute name="machines" type="wstring" readonly="yes" safearray="yes"> 3030 <desc> 3031 Contains the UUIDs of the machines created from the information in this appliances. This is only 3032 relevant for the import case, and will only contain data after a call to <link to="#importMachines" /> 3033 succeeded. 3034 </desc> 3035 </attribute> 3036 3029 3037 <method name="read"> 3030 3038 <desc> … … 3076 3084 disk images, which can take a long time, this method operates asynchronously and 3077 3085 returns an IProgress object to allow the caller to monitor the progress. 3086 3087 After the import succeeded, the UUIDs of the IMachine instances created can be 3088 retrieved from the <link to="#machines" /> array attribute. 3078 3089 </desc> 3079 3090 -
trunk/src/VBox/Main/include/ApplianceImpl.h
r30764 r30881 84 84 STDMETHOD(COMGETTER(Disks))(ComSafeArrayOut(BSTR, aDisks)); 85 85 STDMETHOD(COMGETTER(VirtualSystemDescriptions))(ComSafeArrayOut(IVirtualSystemDescription*, aVirtualSystemDescriptions)); 86 STDMETHOD(COMGETTER(Machines))(ComSafeArrayOut(BSTR, aMachines)); 86 87 87 88 /* IAppliance methods */ -
trunk/src/VBox/Main/include/ApplianceImplPrivate.h
r30764 r30881 80 80 ULONG cDisks; 81 81 Utf8Str strOVFSHA1Digest; 82 83 std::list<Guid> llGuidsMachinesCreated; 82 84 }; 83 85 … … 166 168 std::list<MyHardDiskAttachment> llHardDiskAttachments; // disks that were attached 167 169 std::list< ComPtr<IMedium> > llHardDisksCreated; // media that were created 168 std::list<Bstr> llMachinesRegistered; // machines that were registered; list of string UUIDs169 170 170 171 ImportStack(const LocationInfo &aLocInfo, -
trunk/src/VBox/Main/testcase/tstOVF.cpp
r30876 r30881 75 75 * Imports the given OVF file, with all bells and whistles. 76 76 * Throws MyError on errors. 77 * @param pcszPrefix Descriptive short prefix string for console output. 77 78 * @param pVirtualBox VirtualBox instance. 78 * @param pcszOVF File to import. 79 * @param pcszOVF0 File to import. 80 * @param llMachinesCreated out: UUIDs of machines that were created so that caller can clean up. 79 81 */ 80 82 void importOVF(const char *pcszPrefix, 81 83 ComPtr<IVirtualBox> &pVirtualBox, 82 const char *pcszOVF0) 84 const char *pcszOVF0, 85 std::list<Guid> &llMachinesCreated) 83 86 { 84 87 char szAbsOVF[RTPATH_MAX]; … … 88 91 ComPtr<IAppliance> pAppl; 89 92 HRESULT rc = pVirtualBox->CreateAppliance(pAppl.asOutParam()); 90 if (FAILED(rc)) 91 throw MyError(rc, "failed to create appliance\n"); 93 if (FAILED(rc)) throw MyError(rc, "failed to create appliance\n"); 92 94 93 95 ComPtr<IProgress> pProgress; 94 96 rc = pAppl->Read(Bstr(szAbsOVF), pProgress.asOutParam()); 95 if (FAILED(rc)) 96 throw MyError(rc, "Appliance::Read() failed\n"); 97 if (FAILED(rc)) throw MyError(rc, "Appliance::Read() failed\n"); 97 98 rc = pProgress->WaitForCompletion(-1); 98 if (FAILED(rc)) 99 throw MyError(rc, "Progress::WaitForCompletion() failed\n"); 99 if (FAILED(rc)) throw MyError(rc, "Progress::WaitForCompletion() failed\n"); 100 100 LONG rc2; 101 101 pProgress->COMGETTER(ResultCode)(&rc2); 102 if (FAILED(rc2)) 103 throw MyError(rc2, "Appliance::Read() failed\n", pProgress); 102 if (FAILED(rc2)) throw MyError(rc2, "Appliance::Read() failed\n", pProgress); 104 103 105 104 RTPrintf("%s: interpreting appliance \"%s\"...\n", pcszPrefix, szAbsOVF); 106 105 rc = pAppl->Interpret(); 107 if (FAILED(rc)) 108 throw MyError(rc, "Appliance::Interpret() failed\n"); 106 if (FAILED(rc)) throw MyError(rc, "Appliance::Interpret() failed\n"); 109 107 110 108 com::SafeIfaceArray<IVirtualSystemDescription> aDescriptions; … … 126 124 ComSafeArrayAsOutParam(aVboxValues), 127 125 ComSafeArrayAsOutParam(aExtraConfigValues)); 126 if (FAILED(rc)) throw MyError(rc, "VirtualSystemDescription::GetDescription() failed\n"); 127 128 128 for (uint32_t u2 = 0; 129 129 u2 < aTypes.size(); … … 234 234 RTPrintf("%s: importing %d machine(s)...\n", pcszPrefix, aDescriptions.size()); 235 235 rc = pAppl->ImportMachines(pProgress.asOutParam()); 236 if (FAILED(rc)) 237 throw MyError(rc, "Appliance::ImportMachines() failed\n"); 236 if (FAILED(rc)) throw MyError(rc, "Appliance::ImportMachines() failed\n"); 238 237 rc = pProgress->WaitForCompletion(-1); 239 if (FAILED(rc)) 240 throw MyError(rc, "Progress::WaitForCompletion() failed\n"); 238 if (FAILED(rc)) throw MyError(rc, "Progress::WaitForCompletion() failed\n"); 241 239 pProgress->COMGETTER(ResultCode)(&rc2); 242 if (FAILED(rc2)) 243 throw MyError(rc2, "Progress::GetResultCode() failed\n"); 240 if (FAILED(rc2)) throw MyError(rc2, "Progress::GetResultCode() failed\n"); 241 242 com::SafeArray<BSTR> aMachineUUIDs; 243 rc = pAppl->COMGETTER(Machines)(ComSafeArrayAsOutParam(aMachineUUIDs)); 244 if (FAILED(rc)) throw MyError(rc, "Appliance::GetMachines() failed\n"); 245 246 for (size_t u = 0; 247 u < aMachineUUIDs.size(); 248 ++u) 249 { 250 RTPrintf("%s: created machine %u: %ls\n", pcszPrefix, u, aMachineUUIDs[u]); 251 llMachinesCreated.push_back(Guid(Bstr(aMachineUUIDs[u]))); 252 } 253 244 254 RTPrintf("%s: success!\n", pcszPrefix); 245 255 } … … 255 265 { 256 266 int vrc = RTFileCopy("ovf-testcases/ovf-dummy.vmdk", pcszDest); 257 if (RT_FAILURE(vrc)) 258 throw MyError(0, Utf8StrFmt("Cannot copy ovf-dummy.vmdk to %s: %Rra\n", pcszDest, vrc).c_str()); 267 if (RT_FAILURE(vrc)) throw MyError(0, Utf8StrFmt("Cannot copy ovf-dummy.vmdk to %s: %Rra\n", pcszDest, vrc).c_str()); 259 268 llFiles2Delete.push_back(pcszDest); 260 269 } … … 273 282 274 283 std::list<Utf8Str> llFiles2Delete; 284 std::list<Guid> llMachinesCreated; 285 286 ComPtr<IVirtualBox> pVirtualBox; 275 287 276 288 try … … 278 290 RTPrintf("Initializing COM...\n"); 279 291 rc = com::Initialize(); 280 if (FAILED(rc)) 281 throw MyError(rc, "failed to initialize COM!\n"); 282 283 ComPtr<IVirtualBox> pVirtualBox; 292 if (FAILED(rc)) throw MyError(rc, "failed to initialize COM!\n"); 293 284 294 ComPtr<ISession> pSession; 285 295 286 296 RTPrintf("Creating VirtualBox object...\n"); 287 297 rc = pVirtualBox.createLocalObject(CLSID_VirtualBox); 288 if (FAILED(rc)) 289 throw MyError(rc, "failed to create the VirtualBox object!\n"); 298 if (FAILED(rc)) throw MyError(rc, "failed to create the VirtualBox object!\n"); 290 299 291 300 rc = pSession.createInprocObject(CLSID_Session); 292 if (FAILED(rc)) 293 throw MyError(rc, "failed to create a session object!\n"); 301 if (FAILED(rc)) throw MyError(rc, "failed to create a session object!\n"); 294 302 295 303 // create the event queue … … 298 306 299 307 // testcase 1: import ovf-joomla-0.9/joomla-1.1.4-ovf.ovf 300 //copyDummyDiskImage(llFiles2Delete, "ovf-testcases/ovf-joomla-0.9/joomla-1.1.4-ovf-0.vmdk");301 //copyDummyDiskImage(llFiles2Delete, "ovf-testcases/ovf-joomla-0.9/joomla-1.1.4-ovf-1.vmdk");302 // importOVF("joomla-0.9", pVirtualBox, "ovf-testcases/ovf-joomla-0.9/joomla-1.1.4-ovf.ovf");308 copyDummyDiskImage(llFiles2Delete, "ovf-testcases/ovf-joomla-0.9/joomla-1.1.4-ovf-0.vmdk"); 309 copyDummyDiskImage(llFiles2Delete, "ovf-testcases/ovf-joomla-0.9/joomla-1.1.4-ovf-1.vmdk"); 310 importOVF("joomla-0.9", pVirtualBox, "ovf-testcases/ovf-joomla-0.9/joomla-1.1.4-ovf.ovf", llMachinesCreated); 303 311 304 312 // testcase 2: import ovf-winxp-vbox-sharedfolders/winxp.ovf 305 313 copyDummyDiskImage(llFiles2Delete, "ovf-testcases/ovf-winxp-vbox-sharedfolders/Windows 5.1 XP 1 merged.vmdk"); 306 314 copyDummyDiskImage(llFiles2Delete, "ovf-testcases/ovf-winxp-vbox-sharedfolders/smallvdi.vmdk"); 307 importOVF("winxp-vbox-sharedfolders", pVirtualBox, "ovf-testcases/ovf-winxp-vbox-sharedfolders/winxp.ovf"); 308 309 RTPrintf ("tstOVF all done, no errors.\n"); 310 311 // todo: cleanup created machines, created disk images 315 importOVF("winxp-vbox-sharedfolders", pVirtualBox, "ovf-testcases/ovf-winxp-vbox-sharedfolders/winxp.ovf", llMachinesCreated); 316 317 RTPrintf("Machine imports done, no errors. Cleaning up...\n"); 312 318 } 313 319 catch (MyError &e) … … 317 323 } 318 324 319 // clean up 325 try 326 { 327 // clean up the machines created 328 for (std::list<Guid>::const_iterator it = llMachinesCreated.begin(); 329 it != llMachinesCreated.end(); 330 ++it) 331 { 332 // const Guid &uuid = *it; 333 // Bstr bstrUUID(uuid.toUtf16()); 334 // ComPtr<IMachine> pMachine; 335 // rc = pVirtualBox->GetMachine(bstrUUID, pMachine.asOutParam()); 336 // if (FAILED(rc)) throw MyError(rc, "VirtualBox::FindMachine() failed\n"); 337 // 338 // SafeIfaceArray<IMediumAttachment> aMediumAttachments; 339 // rc = pMachine->COMGETTER(MediumAttachments)(ComSafeArrayAsOutParam(aMediumAttachments)); 340 // if (FAILED(rc)) throw MyError(rc, "Machine::MediumAttachments() failed\n"); 341 // 342 // for (size_t u2 = 0; 343 // u2 < aMediumAttachments.size(); 344 // ++u2) 345 // { 346 // ComPtr<IMediumAttachment> pMediumAttachment(aMediumAttachments[u2]); 347 // ComPtr<IMedium> pMedium; 348 // rc = pMediumAttachment->COMGETTER(Medium)(pMedium.asOutParam()); 349 // if (FAILED(rc)) throw MyError(rc, "MediumAttachment::GetMedium() failed\n"); 350 // 351 // if (!pMedium.isNull()) 352 // { 353 // Bstr bstrLocation; 354 // rc = pMedium->COMGETTER(Location)(bstrLocation.asOutParam()); 355 // if (FAILED(rc)) throw MyError(rc, "Medium::GetLocation() failed\n"); 356 // 357 // llFiles2Delete.push_back(bstrLocation); 358 // } 359 // } 360 361 RTPrintf(" Deleting machine %ls...\n", bstrUUID.raw()); 362 pVirtualBox->UnregisterMachine(bstrUUID, pMachine.asOutParam()); 363 if (FAILED(rc)) throw MyError(rc, "VirtualBox::UnregisterMachine() failed\n"); 364 365 if (!pMachine.isNull()) 366 { 367 rc = pMachine->DeleteSettings(); 368 if (FAILED(rc)) throw MyError(rc, "Machine::DeleteSettings() failed\n"); 369 } 370 } 371 } 372 catch (MyError &e) 373 { 374 rc = e.m_rc; 375 RTPrintf("%s", e.m_str.c_str()); 376 } 377 378 // clean up the VMDK copies that we made in copyDummyDiskImage() 320 379 for (std::list<Utf8Str>::const_iterator it = llFiles2Delete.begin(); 321 380 it != llFiles2Delete.end(); … … 326 385 } 327 386 387 pVirtualBox.setNull(); 388 328 389 RTPrintf("Shutting down COM...\n"); 329 390 com::Shutdown(); 391 RTPrintf ("tstOVF all done!\n"); 330 392 331 393 return rc;
Note:
See TracChangeset
for help on using the changeset viewer.