VirtualBox

Changeset 17343 in vbox


Ignore:
Timestamp:
Mar 4, 2009 12:57:43 PM (16 years ago)
Author:
vboxsync
Message:

OVF: preparations for export thread

Location:
trunk/src/VBox/Main
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/ApplianceImpl.cpp

    r17313 r17343  
    202202{
    203203    TaskImportMachines(Appliance *aThat, Progress *aProgress)
    204         : that(aThat)
     204        : pAppliance(aThat)
    205205        , progress(aProgress)
    206206        , rc(S_OK)
     
    210210    HRESULT startThread();
    211211
    212     Appliance *that;
     212    Appliance *pAppliance;
     213    ComObjPtr<Progress> progress;
     214    HRESULT rc;
     215};
     216
     217struct 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;
    213229    ComObjPtr<Progress> progress;
    214230    HRESULT rc;
     
    269285                             "Appliance::Task");
    270286    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
     292HRESULT 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);
    272299
    273300    return S_OK;
     
    16261653    try
    16271654    {
    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();
    16431656        Bstr progressDesc = BstrFmt(tr("Import appliance '%ls'"),
    16441657                                    m->bstrPath.raw());
    16451658        /* Create the progress object */
    16461659        progress.createObject();
    1647         rc = progress->init(mVirtualBox, static_cast<IAppliance *>(this),
     1660        rc = progress->init(mVirtualBox, static_cast<IAppliance*>(this),
    16481661                            progressDesc,
    16491662                            FALSE /* aCancelable */,
    16501663                            opCount,
    16511664                            progressDesc);
    1652         CheckComRCThrowRC(rc);
     1665        if (FAILED(rc)) throw rc;
    16531666
    16541667        /* Initialize our worker task */
     
    16571670
    16581671        rc = task->startThread();
    1659         CheckComRCThrowRC(rc);
     1672        if (FAILED(rc)) throw rc;
    16601673
    16611674        task.release();
     
    16761689{
    16771690    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
    16781732    return rc;
    16791733}
     
    17251779}
    17261780
     1781/**
     1782 * Calculates the maximum progress value for importMachines() and write().
     1783 * @return
     1784 */
     1785uint32_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
    17271806struct MyHardDiskAttachment
    17281807{
     
    17451824    AssertReturn(task.get(), VERR_GENERAL_FAILURE);
    17461825
    1747     Appliance *app = task->that;
     1826    Appliance *pAppliance = task->pAppliance;
    17481827
    17491828    LogFlowFuncEnter();
    1750     LogFlowFunc(("Appliance %p\n", app));
    1751 
    1752     AutoCaller autoCaller(app);
     1829    LogFlowFunc(("Appliance %p\n", pAppliance));
     1830
     1831    AutoCaller autoCaller(pAppliance);
    17531832    CheckComRCReturnRC(autoCaller.rc());
    17541833
    1755     AutoWriteLock appLock(app);
     1834    AutoWriteLock appLock(pAppliance);
    17561835
    17571836    HRESULT rc = S_OK;
    17581837
    1759     ComPtr<IVirtualBox> pVirtualBox(app->mVirtualBox);
     1838    ComPtr<IVirtualBox> pVirtualBox(pAppliance->mVirtualBox);
    17601839
    17611840    // rollback for errors:
     
    17741853    /* Iterate through all virtual systems of that appliance */
    17751854    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();
    17791858         ++it, ++it1, ++i)
    17801859    {
     
    20242103                    /* The disk image has to be on the same place as the OVF file. So
    20252104                     * 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());
    20272106
    20282107                    /* Iterate over all given disk images */
     
    20462125
    20472126                        /* 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);
    20492128                        /* vsdeHD->strRef contains the disk identifier (e.g. "vmdisk1"), which should exist
    20502129                           in the virtual system's disks map under that ID and also in the global images map. */
    20512130                        VirtualDisksMap::const_iterator itVirtualDisk = vsysThis.mapVirtualDisks.find(vsdeHD->strRef);
    20522131
    2053                         if (    itDiskImage == app->m->mapDisks.end()
     2132                        if (    itDiskImage == pAppliance->m->mapDisks.end()
    20542133                             || itVirtualDisk == vsysThis.mapVirtualDisks.end()
    20552134                           )
     
    22702349            break;
    22712350
    2272     } // for (it = app->m->llVirtualSystems.begin(),
     2351    } // for (it = pAppliance->m->llVirtualSystems.begin(),
    22732352
    22742353    if (FAILED(rc))
     
    23372416}
    23382417
     2418/**
     2419 * Worker thread implementation for ImportMachines().
     2420 * @param aThread
     2421 * @param pvUser
     2422 */
     2423/* static */
     2424DECLCALLBACK(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#
    23392463////////////////////////////////////////////////////////////////////////////////
    23402464//
  • trunk/src/VBox/Main/include/ApplianceImpl.h

    r17291 r17343  
    8585    const ComObjPtr <VirtualBox, ComWeakRef> mVirtualBox;
    8686
    87     struct TaskImportMachines; /* Worker thread for import */
    88     struct TaskExportOVF; /* Worker thread for import */
    89 
    9087    struct Data;            // obscure, defined in AppliannceImpl.cpp
    9188    Data *m;
     
    9895    HRESULT searchUniqueVMName(Utf8Str& aName) const;
    9996    HRESULT searchUniqueDiskImageFilePath(Utf8Str& aName) const;
     97    uint32_t calcMaxProgress();
    10098
     99    struct TaskImportMachines;  /* Worker thread for import */
    101100    static DECLCALLBACK(int) taskThreadImportMachines(RTTHREAD thread, void *pvUser);
     101
     102    struct TaskExportOVF;       /* Worker thread for export */
    102103    static DECLCALLBACK(int) taskThreadExportOVF(RTTHREAD thread, void *pvUser);
    103104
Note: See TracChangeset for help on using the changeset viewer.

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