Changeset 17343 in vbox
- Timestamp:
- Mar 4, 2009 12:57:43 PM (16 years ago)
- Location:
- trunk/src/VBox/Main
- Files:
-
- 2 edited
-
ApplianceImpl.cpp (modified) (13 diffs)
-
include/ApplianceImpl.h (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/ApplianceImpl.cpp
r17313 r17343 202 202 { 203 203 TaskImportMachines(Appliance *aThat, Progress *aProgress) 204 : that(aThat)204 : pAppliance(aThat) 205 205 , progress(aProgress) 206 206 , rc(S_OK) … … 210 210 HRESULT startThread(); 211 211 212 Appliance *that; 212 Appliance *pAppliance; 213 ComObjPtr<Progress> progress; 214 HRESULT rc; 215 }; 216 217 struct Appliance::TaskExportOVF 218 { 219 TaskExportOVF(Appliance *aThat, Progress *aProgress) 220 : pAppliance(aThat) 221 , progress(aProgress) 222 , rc(S_OK) 223 {} 224 ~TaskExportOVF() {} 225 226 HRESULT startThread(); 227 228 Appliance *pAppliance; 213 229 ComObjPtr<Progress> progress; 214 230 HRESULT rc; … … 269 285 "Appliance::Task"); 270 286 ComAssertMsgRCRet(vrc, 271 ("Could not create Appliance::Task thread (%Rrc)\n", vrc), E_FAIL); 287 ("Could not create taskThreadImportMachines (%Rrc)\n", vrc), E_FAIL); 288 289 return S_OK; 290 } 291 292 HRESULT Appliance::TaskExportOVF::startThread() 293 { 294 int vrc = RTThreadCreate(NULL, Appliance::taskThreadExportOVF, this, 295 0, RTTHREADTYPE_MAIN_HEAVY_WORKER, 0, 296 "Appliance::Task"); 297 ComAssertMsgRCRet(vrc, 298 ("Could not create taskThreadExportOVF (%Rrc)\n", vrc), E_FAIL); 272 299 273 300 return S_OK; … … 1626 1653 try 1627 1654 { 1628 /* Figure out how many sub operation the import will need */ 1629 /* One for the appliance */ 1630 uint32_t opCount = 1; 1631 list< ComObjPtr<VirtualSystemDescription> >::const_iterator it; 1632 for (it = m->virtualSystemDescriptions.begin(); 1633 it != m->virtualSystemDescriptions.end(); 1634 ++it) 1635 { 1636 /* One for every Virtual System */ 1637 ++opCount; 1638 ComObjPtr<VirtualSystemDescription> vsdescThis = (*it); 1639 /* One for every hard disk of the Virtual System */ 1640 std::list<VirtualSystemDescriptionEntry*> avsdeHDs = vsdescThis->findByType(VirtualSystemDescriptionType_HardDiskImage); 1641 opCount += (uint32_t)avsdeHDs.size(); 1642 } 1655 uint32_t opCount = calcMaxProgress(); 1643 1656 Bstr progressDesc = BstrFmt(tr("Import appliance '%ls'"), 1644 1657 m->bstrPath.raw()); 1645 1658 /* Create the progress object */ 1646 1659 progress.createObject(); 1647 rc = progress->init(mVirtualBox, static_cast<IAppliance *>(this),1660 rc = progress->init(mVirtualBox, static_cast<IAppliance*>(this), 1648 1661 progressDesc, 1649 1662 FALSE /* aCancelable */, 1650 1663 opCount, 1651 1664 progressDesc); 1652 CheckComRCThrowRC(rc);1665 if (FAILED(rc)) throw rc; 1653 1666 1654 1667 /* Initialize our worker task */ … … 1657 1670 1658 1671 rc = task->startThread(); 1659 CheckComRCThrowRC(rc);1672 if (FAILED(rc)) throw rc; 1660 1673 1661 1674 task.release(); … … 1676 1689 { 1677 1690 HRESULT rc = S_OK; 1691 1692 CheckComArgOutPointerValid(aProgress); 1693 1694 AutoCaller autoCaller(this); 1695 if (FAILED(rc = autoCaller.rc())) return rc; 1696 1697 AutoReadLock(this); 1698 1699 ComObjPtr<Progress> progress; 1700 try 1701 { 1702 uint32_t opCount = calcMaxProgress(); 1703 Bstr progressDesc = BstrFmt(tr("Write appliance '%ls'"), 1704 m->bstrPath.raw()); 1705 /* Create the progress object */ 1706 progress.createObject(); 1707 rc = progress->init(mVirtualBox, static_cast<IAppliance*>(this), 1708 progressDesc, 1709 FALSE /* aCancelable */, 1710 opCount, 1711 progressDesc); 1712 CheckComRCThrowRC(rc); 1713 1714 /* Initialize our worker task */ 1715 std::auto_ptr<TaskExportOVF> task(new TaskExportOVF(this, progress)); 1716 //AssertComRCThrowRC (task->autoCaller.rc()); 1717 1718 rc = task->startThread(); 1719 CheckComRCThrowRC(rc); 1720 1721 task.release(); 1722 } 1723 catch (HRESULT aRC) 1724 { 1725 rc = aRC; 1726 } 1727 1728 if (SUCCEEDED(rc)) 1729 /* Return progress to the caller */ 1730 progress.queryInterfaceTo(aProgress); 1731 1678 1732 return rc; 1679 1733 } … … 1725 1779 } 1726 1780 1781 /** 1782 * Calculates the maximum progress value for importMachines() and write(). 1783 * @return 1784 */ 1785 uint32_t Appliance::calcMaxProgress() 1786 { 1787 /* Figure out how many sub operation the import will need */ 1788 /* One for the appliance */ 1789 uint32_t opCount = 1; 1790 list< ComObjPtr<VirtualSystemDescription> >::const_iterator it; 1791 for (it = m->virtualSystemDescriptions.begin(); 1792 it != m->virtualSystemDescriptions.end(); 1793 ++it) 1794 { 1795 /* One for every Virtual System */ 1796 ++opCount; 1797 ComObjPtr<VirtualSystemDescription> vsdescThis = (*it); 1798 /* One for every hard disk of the Virtual System */ 1799 std::list<VirtualSystemDescriptionEntry*> avsdeHDs = vsdescThis->findByType(VirtualSystemDescriptionType_HardDiskImage); 1800 opCount += (uint32_t)avsdeHDs.size(); 1801 } 1802 1803 return opCount; 1804 } 1805 1727 1806 struct MyHardDiskAttachment 1728 1807 { … … 1745 1824 AssertReturn(task.get(), VERR_GENERAL_FAILURE); 1746 1825 1747 Appliance * app = task->that;1826 Appliance *pAppliance = task->pAppliance; 1748 1827 1749 1828 LogFlowFuncEnter(); 1750 LogFlowFunc(("Appliance %p\n", app));1751 1752 AutoCaller autoCaller( app);1829 LogFlowFunc(("Appliance %p\n", pAppliance)); 1830 1831 AutoCaller autoCaller(pAppliance); 1753 1832 CheckComRCReturnRC(autoCaller.rc()); 1754 1833 1755 AutoWriteLock appLock( app);1834 AutoWriteLock appLock(pAppliance); 1756 1835 1757 1836 HRESULT rc = S_OK; 1758 1837 1759 ComPtr<IVirtualBox> pVirtualBox( app->mVirtualBox);1838 ComPtr<IVirtualBox> pVirtualBox(pAppliance->mVirtualBox); 1760 1839 1761 1840 // rollback for errors: … … 1774 1853 /* Iterate through all virtual systems of that appliance */ 1775 1854 size_t i = 0; 1776 for (it = app->m->llVirtualSystems.begin(),1777 it1 = app->m->virtualSystemDescriptions.begin();1778 it != app->m->llVirtualSystems.end();1855 for (it = pAppliance->m->llVirtualSystems.begin(), 1856 it1 = pAppliance->m->virtualSystemDescriptions.begin(); 1857 it != pAppliance->m->llVirtualSystems.end(); 1779 1858 ++it, ++it1, ++i) 1780 1859 { … … 2024 2103 /* The disk image has to be on the same place as the OVF file. So 2025 2104 * strip the filename out of the full file path. */ 2026 Utf8Str strSrcDir = stripFilename(Utf8Str( app->m->bstrPath).raw());2105 Utf8Str strSrcDir = stripFilename(Utf8Str(pAppliance->m->bstrPath).raw()); 2027 2106 2028 2107 /* Iterate over all given disk images */ … … 2046 2125 2047 2126 /* Find the disk from the OVF's disk list */ 2048 DiskImagesMap::const_iterator itDiskImage = app->m->mapDisks.find(vsdeHD->strRef);2127 DiskImagesMap::const_iterator itDiskImage = pAppliance->m->mapDisks.find(vsdeHD->strRef); 2049 2128 /* vsdeHD->strRef contains the disk identifier (e.g. "vmdisk1"), which should exist 2050 2129 in the virtual system's disks map under that ID and also in the global images map. */ 2051 2130 VirtualDisksMap::const_iterator itVirtualDisk = vsysThis.mapVirtualDisks.find(vsdeHD->strRef); 2052 2131 2053 if ( itDiskImage == app->m->mapDisks.end()2132 if ( itDiskImage == pAppliance->m->mapDisks.end() 2054 2133 || itVirtualDisk == vsysThis.mapVirtualDisks.end() 2055 2134 ) … … 2270 2349 break; 2271 2350 2272 } // for (it = app->m->llVirtualSystems.begin(),2351 } // for (it = pAppliance->m->llVirtualSystems.begin(), 2273 2352 2274 2353 if (FAILED(rc)) … … 2337 2416 } 2338 2417 2418 /** 2419 * Worker thread implementation for ImportMachines(). 2420 * @param aThread 2421 * @param pvUser 2422 */ 2423 /* static */ 2424 DECLCALLBACK(int) Appliance::taskThreadExportOVF(RTTHREAD aThread, void *pvUser) 2425 { 2426 std::auto_ptr<TaskImportMachines> task(static_cast<TaskImportMachines*>(pvUser)); 2427 AssertReturn(task.get(), VERR_GENERAL_FAILURE); 2428 2429 Appliance *pAppliance = task->pAppliance; 2430 2431 LogFlowFuncEnter(); 2432 LogFlowFunc(("Appliance %p\n", pAppliance)); 2433 2434 AutoCaller autoCaller(pAppliance); 2435 CheckComRCReturnRC(autoCaller.rc()); 2436 2437 AutoWriteLock appLock(pAppliance); 2438 2439 HRESULT rc = S_OK; 2440 2441 ComPtr<IVirtualBox> pVirtualBox(pAppliance->mVirtualBox); 2442 2443 try 2444 { 2445 } 2446 catch(HRESULT aRC) 2447 { 2448 rc = aRC; 2449 } 2450 2451 task->rc = rc; 2452 2453 if (!task->progress.isNull()) 2454 task->progress->notifyComplete(rc); 2455 2456 LogFlowFunc(("rc=%Rhrc\n", rc)); 2457 LogFlowFuncLeave(); 2458 2459 return VINF_SUCCESS; 2460 } 2461 2462 # 2339 2463 //////////////////////////////////////////////////////////////////////////////// 2340 2464 // -
trunk/src/VBox/Main/include/ApplianceImpl.h
r17291 r17343 85 85 const ComObjPtr <VirtualBox, ComWeakRef> mVirtualBox; 86 86 87 struct TaskImportMachines; /* Worker thread for import */88 struct TaskExportOVF; /* Worker thread for import */89 90 87 struct Data; // obscure, defined in AppliannceImpl.cpp 91 88 Data *m; … … 98 95 HRESULT searchUniqueVMName(Utf8Str& aName) const; 99 96 HRESULT searchUniqueDiskImageFilePath(Utf8Str& aName) const; 97 uint32_t calcMaxProgress(); 100 98 99 struct TaskImportMachines; /* Worker thread for import */ 101 100 static DECLCALLBACK(int) taskThreadImportMachines(RTTHREAD thread, void *pvUser); 101 102 struct TaskExportOVF; /* Worker thread for export */ 102 103 static DECLCALLBACK(int) taskThreadExportOVF(RTTHREAD thread, void *pvUser); 103 104
Note:
See TracChangeset
for help on using the changeset viewer.

