VirtualBox

Changeset 27895 in vbox


Ignore:
Timestamp:
Mar 31, 2010 1:30:14 PM (15 years ago)
Author:
vboxsync
Message:

Main/OVF: cleanup: share thread code, fix error code confusion, less task parameters

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

Legend:

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

    r27886 r27895  
    2121 */
    2222
    23 #include <iprt/stream.h>
    2423#include <iprt/path.h>
    25 #include <iprt/dir.h>
    26 #include <iprt/file.h>
    27 #include <iprt/s3.h>
    28 #include <iprt/sha.h>
    29 #include <iprt/manifest.h>
    30 
    31 #include <VBox/param.h>
    32 #include <VBox/version.h>
     24
     25#include <VBox/com/array.h>
    3326
    3427#include "ApplianceImpl.h"
     
    3831#include "ProgressImpl.h"
    3932#include "MachineImpl.h"
    40 #include "MediumImpl.h"
    41 
    42 #include "HostNetworkInterfaceImpl.h"
    4333
    4434#include "AutoCaller.h"
     
    602592     * already */
    603593    /* @todo: Maybe too cost-intensive; try to find a lighter way */
    604     while (RTPathExists(tmpName) ||
    605            mVirtualBox->FindHardDisk(Bstr(tmpName), &harddisk) != VBOX_E_OBJECT_NOT_FOUND)
     594    while (    RTPathExists(tmpName)
     595            || mVirtualBox->FindHardDisk(Bstr(tmpName), &harddisk) != VBOX_E_OBJECT_NOT_FOUND
     596          )
    606597    {
    607598        RTStrFree(tmpName);
     
    914905}
    915906
     907/**
     908 *
     909 * @return
     910 */
     911int Appliance::TaskOVF::startThread()
     912{
     913    int vrc = RTThreadCreate(NULL, Appliance::taskThreadImportOrExport, this,
     914                             0, RTTHREADTYPE_MAIN_HEAVY_WORKER, 0,
     915                             "Appliance::Task");
     916
     917    ComAssertMsgRCRet(vrc,
     918                      ("Could not create OVF task thread (%Rrc)\n", vrc), E_FAIL);
     919
     920    return S_OK;
     921}
     922
     923/**
     924 * Thread function for the thread started in Appliance::readImpl() and Appliance::importImpl()
     925 * and Appliance::writeImpl().
     926 * This will in turn call Appliance::readFS() or Appliance::readS3() or Appliance::importFS()
     927 * or Appliance::importS3() or Appliance::writeFS() or Appliance::writeS3().
     928 *
     929 * @param aThread
     930 * @param pvUser
     931 */
     932/* static */
     933DECLCALLBACK(int) Appliance::taskThreadImportOrExport(RTTHREAD /* aThread */, void *pvUser)
     934{
     935    std::auto_ptr<TaskOVF> task(static_cast<TaskOVF*>(pvUser));
     936    AssertReturn(task.get(), VERR_GENERAL_FAILURE);
     937
     938    Appliance *pAppliance = task->pAppliance;
     939
     940    LogFlowFuncEnter();
     941    LogFlowFunc(("Appliance %p\n", pAppliance));
     942
     943    HRESULT taskrc = S_OK;
     944
     945    switch (task->taskType)
     946    {
     947        case TaskOVF::Read:
     948            if (task->locInfo.storageType == VFSType_File)
     949                taskrc = pAppliance->readFS(task->locInfo);
     950            else if (task->locInfo.storageType == VFSType_S3)
     951                taskrc = pAppliance->readS3(task.get());
     952        break;
     953
     954        case TaskOVF::Import:
     955            if (task->locInfo.storageType == VFSType_File)
     956                taskrc = pAppliance->importFS(task->locInfo, task->pProgress);
     957            else if (task->locInfo.storageType == VFSType_S3)
     958                taskrc = pAppliance->importS3(task.get());
     959        break;
     960
     961        case TaskOVF::Write:
     962            if (task->locInfo.storageType == VFSType_File)
     963                taskrc = pAppliance->writeFS(task->locInfo, task->enFormat, task->pProgress);
     964            else if (task->locInfo.storageType == VFSType_S3)
     965                taskrc = pAppliance->writeS3(task.get());
     966        break;
     967    }
     968
     969    task->rc = taskrc;
     970
     971    if (!task->pProgress.isNull())
     972        task->pProgress->notifyComplete(taskrc);
     973
     974    LogFlowFuncLeave();
     975
     976    return VINF_SUCCESS;
     977}
     978
    916979/* static */
    917980int Appliance::TaskOVF::updateProgress(unsigned uPercent, void *pvUser)
     
    920983
    921984    if (    pTask
    922          && !pTask->progress.isNull())
     985         && !pTask->pProgress.isNull())
    923986    {
    924987        BOOL fCanceled;
    925         pTask->progress->COMGETTER(Canceled)(&fCanceled);
     988        pTask->pProgress->COMGETTER(Canceled)(&fCanceled);
    926989        if (fCanceled)
    927990            return -1;
    928         pTask->progress->SetCurrentOperationProgress(uPercent);
     991        pTask->pProgress->SetCurrentOperationProgress(uPercent);
    929992    }
    930993    return VINF_SUCCESS;
  • trunk/src/VBox/Main/ApplianceImplExport.cpp

    r27886 r27895  
    2121 */
    2222
    23 #include <iprt/stream.h>
    2423#include <iprt/path.h>
    2524#include <iprt/dir.h>
    26 #include <iprt/file.h>
     25#include <iprt/param.h>
    2726#include <iprt/s3.h>
    28 #include <iprt/sha.h>
    2927#include <iprt/manifest.h>
    3028
    31 #include <VBox/param.h>
    3229#include <VBox/version.h>
    3330
    3431#include "ApplianceImpl.h"
    35 #include "VFSExplorerImpl.h"
    3632#include "VirtualBoxImpl.h"
    37 #include "GuestOSTypeImpl.h"
     33
    3834#include "ProgressImpl.h"
    3935#include "MachineImpl.h"
    40 #include "MediumImpl.h"
    41 
    42 #include "HostNetworkInterfaceImpl.h"
    4336
    4437#include "AutoCaller.h"
     
    4841
    4942using namespace std;
    50 
    51 ////////////////////////////////////////////////////////////////////////////////
    52 //
    53 // internal helpers
    54 //
    55 ////////////////////////////////////////////////////////////////////////////////
    5643
    5744////////////////////////////////////////////////////////////////////////////////
     
    619606    try
    620607    {
    621         /* Initialize our worker task */
    622         std::auto_ptr<TaskExportOVF> task(new TaskExportOVF(this));
    623         /* What should the task do */
    624         task->taskType = TaskExportOVF::Write;
    625         /* The OVF version to write */
    626         task->enFormat = aFormat;
    627         /* Copy the current location info to the task */
    628         task->locInfo = aLocInfo;
    629 
    630608        Bstr progressDesc = BstrFmt(tr("Export appliance '%s'"),
    631                                     task->locInfo.strPath.c_str());
     609                                    aLocInfo.strPath.c_str());
    632610
    633611        /* todo: This progress init stuff should be done a little bit more generic */
    634         if (task->locInfo.storageType == VFSType_File)
     612        if (aLocInfo.storageType == VFSType_File)
    635613            rc = setUpProgressFS(aProgress, progressDesc);
    636614        else
    637615            rc = setUpProgressWriteS3(aProgress, progressDesc);
    638616
    639         task->progress = aProgress;
     617        /* Initialize our worker task */
     618        std::auto_ptr<TaskOVF> task(new TaskOVF(this, TaskOVF::Write, aLocInfo, aProgress));
     619        /* The OVF version to write */
     620        task->enFormat = aFormat;
    640621
    641622        rc = task->startThread();
     
    651632
    652633    return rc;
    653 }
    654 
    655 /**
    656  *
    657  * @return
    658  */
    659 int Appliance::TaskExportOVF::startThread()
    660 {
    661     int vrc = RTThreadCreate(NULL, Appliance::taskThreadWriteOVF, this,
    662                              0, RTTHREADTYPE_MAIN_HEAVY_WORKER, 0,
    663                              "Appliance::Task");
    664 
    665     ComAssertMsgRCRet(vrc,
    666                       ("Could not create taskThreadWriteOVF (%Rrc)\n", vrc), E_FAIL);
    667 
    668     return S_OK;
    669 }
    670 
    671 /**
    672  * Thread function for the thread started in Appliance::writeImpl(). This will in turn
    673  * call Appliance::writeFS() or Appliance::writeS3().
    674  * @param
    675  * @param pvUser
    676  * @return
    677  */
    678 DECLCALLBACK(int) Appliance::taskThreadWriteOVF(RTTHREAD /* aThread */, void *pvUser)
    679 {
    680     std::auto_ptr<TaskExportOVF> task(static_cast<TaskExportOVF*>(pvUser));
    681     AssertReturn(task.get(), VERR_GENERAL_FAILURE);
    682 
    683     Appliance *pAppliance = task->pAppliance;
    684 
    685     LogFlowFuncEnter();
    686     LogFlowFunc(("Appliance %p\n", pAppliance));
    687 
    688     HRESULT rc = S_OK;
    689 
    690     switch(task->taskType)
    691     {
    692         case TaskExportOVF::Write:
    693         {
    694             if (task->locInfo.storageType == VFSType_File)
    695                 rc = pAppliance->writeFS(task.get());
    696             else if (task->locInfo.storageType == VFSType_S3)
    697                 rc = pAppliance->writeS3(task.get());
    698             break;
    699         }
    700     }
    701 
    702     LogFlowFunc(("rc=%Rhrc\n", rc));
    703     LogFlowFuncLeave();
    704 
    705     return VINF_SUCCESS;
    706634}
    707635
     
    13241252 * @return
    13251253 */
    1326 int Appliance::writeFS(TaskExportOVF *pTask)
     1254HRESULT Appliance::writeFS(const LocationInfo &locInfo, const OVFFormat enFormat, ComObjPtr<Progress> &pProgress)
    13271255{
    13281256    LogFlowFuncEnter();
     
    13411269        xml::ElementNode *pelmRoot = doc.createRootElement("Envelope");
    13421270
    1343         pelmRoot->setAttribute("ovf:version", (pTask->enFormat == OVF_1_0) ? "1.0" : "0.9");
     1271        pelmRoot->setAttribute("ovf:version", (enFormat == OVF_1_0) ? "1.0" : "0.9");
    13441272        pelmRoot->setAttribute("xml:lang", "en-US");
    13451273
    1346         Utf8Str strNamespace = (pTask->enFormat == OVF_0_9)
     1274        Utf8Str strNamespace = (enFormat == OVF_0_9)
    13471275            ? "http://www.vmware.com/schema/ovf/1/envelope"     // 0.9
    13481276            : "http://schemas.dmtf.org/ovf/envelope/1";         // 1.0
     
    13661294            </DiskSection> */
    13671295        xml::ElementNode *pelmDiskSection;
    1368         if (pTask->enFormat == OVF_0_9)
     1296        if (enFormat == OVF_0_9)
    13691297        {
    13701298            // <Section xsi:type="ovf:DiskSection_Type">
     
    13911319            </NetworkSection> */
    13921320        xml::ElementNode *pelmNetworkSection;
    1393         if (pTask->enFormat == OVF_0_9)
     1321        if (enFormat == OVF_0_9)
    13941322        {
    13951323            // <Section xsi:type="ovf:NetworkSection_Type">
     
    14171345        if (m->virtualSystemDescriptions.size() > 1)
    14181346        {
    1419             if (pTask->enFormat == OVF_0_9)
     1347            if (enFormat == OVF_0_9)
    14201348                throw setError(VBOX_E_FILE_ERROR,
    14211349                               tr("Cannot export more than one virtual system with OVF 0.9, use OVF 1.0"));
     
    14361364            buildXMLForOneVirtualSystem(*pelmToAddVirtualSystemsTo,
    14371365                                        vsdescThis,
    1438                                         pTask->enFormat,
     1366                                        enFormat,
    14391367                                        stack);         // disks and networks stack
    14401368        }
     
    14771405            const Utf8Str &strTargetFileNameOnly = pDiskEntry->strOvf;
    14781406            // target path needs to be composed from where the output OVF is
    1479             Utf8Str strTargetFilePath(pTask->locInfo.strPath);
     1407            Utf8Str strTargetFilePath(locInfo.strPath);
    14801408            strTargetFilePath.stripFilename();
    14811409            strTargetFilePath.append("/");
     
    15081436
    15091437                // advance to the next operation
    1510                 if (!pTask->progress.isNull())
    1511                     pTask->progress->SetNextOperation(BstrFmt(tr("Exporting virtual disk image '%s'"), strSrcFilePath.c_str()),
    1512                                                       pDiskEntry->ulSizeMB);     // operation's weight, as set up with the IProgress originally);
     1438                if (!pProgress.isNull())
     1439                    pProgress->SetNextOperation(BstrFmt(tr("Exporting virtual disk image '%s'"), strSrcFilePath.c_str()),
     1440                                                pDiskEntry->ulSizeMB);     // operation's weight, as set up with the IProgress originally);
    15131441
    15141442                // now wait for the background disk operation to complete; this throws HRESULTs on error
    1515                 waitForAsyncProgress(pTask->progress, pProgress2);
     1443                waitForAsyncProgress(pProgress, pProgress2);
    15161444            }
    15171445            catch (HRESULT rc3)
     
    15581486        // now go write the XML
    15591487        xml::XmlFileWriter writer(doc);
    1560         writer.write(pTask->locInfo.strPath.c_str());
     1488        writer.write(locInfo.strPath.c_str());
    15611489
    15621490        /* Create & write the manifest file */
    15631491        const char** ppManifestFiles = (const char**)RTMemAlloc(sizeof(char*)*diskList.size() + 1);
    1564         ppManifestFiles[0] = pTask->locInfo.strPath.c_str();
     1492        ppManifestFiles[0] = locInfo.strPath.c_str();
    15651493        list<Utf8Str>::const_iterator it1;
    15661494        size_t i = 1;
     
    15691497             ++it1, ++i)
    15701498            ppManifestFiles[i] = (*it1).c_str();
    1571         Utf8Str strMfFile = manifestFileName(pTask->locInfo.strPath.c_str());
     1499        Utf8Str strMfFile = manifestFileName(locInfo.strPath.c_str());
    15721500        int vrc = RTManifestWriteFiles(strMfFile.c_str(), ppManifestFiles, diskList.size()+1);
    15731501        RTMemFree(ppManifestFiles);
     
    15911519    m->state = Data::ApplianceIdle;
    15921520
    1593     pTask->rc = rc;
    1594 
    1595     if (!pTask->progress.isNull())
    1596         pTask->progress->notifyComplete(rc);
    1597 
    15981521    LogFlowFunc(("rc=%Rhrc\n", rc));
    15991522    LogFlowFuncLeave();
    16001523
    1601     return VINF_SUCCESS;
     1524    return rc;
    16021525}
    16031526
     
    16101533 * @return
    16111534 */
    1612 int Appliance::writeS3(TaskExportOVF *pTask)
     1535HRESULT Appliance::writeS3(TaskOVF *pTask)
    16131536{
    16141537    LogFlowFuncEnter();
     
    16641587           caller */
    16651588        ComPtr<IProgress> progressInt(progress);
    1666         waitForAsyncProgress(pTask->progress, progressInt); /* Any errors will be thrown */
     1589        waitForAsyncProgress(pTask->pProgress, progressInt); /* Any errors will be thrown */
    16671590
    16681591        /* Again lock the appliance for the next steps */
     
    17171640            char *pszFilename = RTPathFilename(s.first.c_str());
    17181641            /* Advance to the next operation */
    1719             if (!pTask->progress.isNull())
    1720                 pTask->progress->SetNextOperation(BstrFmt(tr("Uploading file '%s'"), pszFilename), s.second);
     1642            if (!pTask->pProgress.isNull())
     1643                pTask->pProgress->SetNextOperation(BstrFmt(tr("Uploading file '%s'"), pszFilename), s.second);
    17211644            vrc = RTS3PutKey(hS3, bucket.c_str(), pszFilename, s.first.c_str());
    17221645            if (RT_FAILURE(vrc))
     
    17651688        RTStrFree(pszTmpDir);
    17661689
    1767     pTask->rc = rc;
    1768 
    1769     if (!pTask->progress.isNull())
    1770         pTask->progress->notifyComplete(rc);
    1771 
    17721690    LogFlowFunc(("rc=%Rhrc\n", rc));
    17731691    LogFlowFuncLeave();
    17741692
    1775     return VINF_SUCCESS;
     1693    return rc;
    17761694}
    17771695
  • trunk/src/VBox/Main/ApplianceImplImport.cpp

    r27886 r27895  
    2121 */
    2222
    23 #include <iprt/stream.h>
    2423#include <iprt/path.h>
    2524#include <iprt/dir.h>
     
    2928#include <iprt/manifest.h>
    3029
    31 #include <VBox/param.h>
    32 #include <VBox/version.h>
     30#include <VBox/com/array.h>
    3331
    3432#include "ApplianceImpl.h"
    35 #include "VFSExplorerImpl.h"
    3633#include "VirtualBoxImpl.h"
    3734#include "GuestOSTypeImpl.h"
    3835#include "ProgressImpl.h"
    39 #include "MachineImpl.h"
    40 #include "MediumImpl.h"
    41 
    42 #include "HostNetworkInterfaceImpl.h"
    4336
    4437#include "AutoCaller.h"
     
    4639
    4740#include "ApplianceImplPrivate.h"
     41
     42#include <VBox/param.h>
     43#include <VBox/version.h>
    4844
    4945using namespace std;
     
    206202            uint64_t ullMemSizeVBox = vsysThis.ullMemorySize / _1M;
    207203            /* Check for the constrains */
    208             if (ullMemSizeVBox != 0 &&
    209                 (ullMemSizeVBox < MM_RAM_MIN_IN_MB ||
    210                  ullMemSizeVBox > MM_RAM_MAX_IN_MB))
     204            if (    ullMemSizeVBox != 0
     205                 && (    ullMemSizeVBox < MM_RAM_MIN_IN_MB
     206                      || ullMemSizeVBox > MM_RAM_MAX_IN_MB)
     207               )
    211208            {
    212209                addWarning(tr("The virtual system \"%s\" claims support for %llu MB RAM size, but VirtualBox has support for min %u & max %u MB RAM size only."),
     
    576573HRESULT Appliance::readImpl(const LocationInfo &aLocInfo, ComObjPtr<Progress> &aProgress)
    577574{
    578     /* Initialize our worker task */
    579     std::auto_ptr<TaskImportOVF> task(new TaskImportOVF(this));
    580     /* What should the task do */
    581     task->taskType = TaskImportOVF::Read;
    582     /* Copy the current location info to the task */
    583     task->locInfo = aLocInfo;
    584 
    585575    BstrFmt bstrDesc = BstrFmt(tr("Read appliance '%s'"),
    586576                               aLocInfo.strPath.c_str());
     
    588578    /* Create the progress object */
    589579    aProgress.createObject();
    590     if (task->locInfo.storageType == VFSType_File)
    591     {
     580    if (aLocInfo.storageType == VFSType_File)
    592581        /* 1 operation only */
    593582        rc = aProgress->init(mVirtualBox, static_cast<IAppliance*>(this),
    594583                             bstrDesc,
    595584                             TRUE /* aCancelable */);
    596     }
    597585    else
    598     {
    599586        /* 4/5 is downloading, 1/5 is reading */
    600587        rc = aProgress->init(mVirtualBox, static_cast<IAppliance*>(this),
     
    606593                                     aLocInfo.strPath.c_str()), // CBSTR bstrFirstOperationDescription,
    607594                             4); // ULONG ulFirstOperationWeight,
    608     }
    609595    if (FAILED(rc)) throw rc;
    610596
    611     task->progress = aProgress;
     597    /* Initialize our worker task */
     598    std::auto_ptr<TaskOVF> task(new TaskOVF(this, TaskOVF::Read, aLocInfo, aProgress));
    612599
    613600    rc = task->startThread();
     
    618605
    619606    return rc;
    620 }
    621 
    622 /**
    623  *
    624  * @return
    625  */
    626 int Appliance::TaskImportOVF::startThread()
    627 {
    628     int vrc = RTThreadCreate(NULL, Appliance::taskThreadImportOVF, this,
    629                              0, RTTHREADTYPE_MAIN_HEAVY_WORKER, 0,
    630                              "Appliance::Task");
    631 
    632     ComAssertMsgRCRet(vrc,
    633                       ("Could not create taskThreadImportOVF (%Rrc)\n", vrc), E_FAIL);
    634 
    635     return S_OK;
    636 }
    637 
    638 /**
    639  * Thread function for the thread started in Appliance::readImpl() and Appliance::importImpl().
    640  * This will in turn call Appliance::readFS() or Appliance::readS3() or Appliance::importFS()
    641  * or Appliance::importS3().
    642  *
    643  * @param aThread
    644  * @param pvUser
    645  */
    646 /* static */
    647 DECLCALLBACK(int) Appliance::taskThreadImportOVF(RTTHREAD /* aThread */, void *pvUser)
    648 {
    649     std::auto_ptr<TaskImportOVF> task(static_cast<TaskImportOVF*>(pvUser));
    650     AssertReturn(task.get(), VERR_GENERAL_FAILURE);
    651 
    652     Appliance *pAppliance = task->pAppliance;
    653 
    654     LogFlowFuncEnter();
    655     LogFlowFunc(("Appliance %p\n", pAppliance));
    656 
    657     HRESULT taskrc = S_OK;
    658 
    659     switch (task->taskType)
    660     {
    661         case TaskImportOVF::Read:
    662         {
    663             if (task->locInfo.storageType == VFSType_File)
    664                 taskrc = pAppliance->readFS(task.get());
    665             else if (task->locInfo.storageType == VFSType_S3)
    666                 taskrc = pAppliance->readS3(task.get());
    667             break;
    668         }
    669         case TaskImportOVF::Import:
    670         {
    671             if (task->locInfo.storageType == VFSType_File)
    672                 taskrc = pAppliance->importFS(task.get());
    673             else if (task->locInfo.storageType == VFSType_S3)
    674                 taskrc = pAppliance->importS3(task.get());
    675             break;
    676         }
    677     }
    678 
    679     task->rc = taskrc;
    680 
    681     LogFlowFuncLeave();
    682 
    683     return VINF_SUCCESS;
    684607}
    685608
     
    696619 * @return
    697620 */
    698 int Appliance::readFS(TaskImportOVF *pTask)
     621HRESULT Appliance::readFS(const LocationInfo &locInfo)
    699622{
    700623    LogFlowFuncEnter();
     
    711634    {
    712635        /* Read & parse the XML structure of the OVF file */
    713         m->pReader = new OVFReader(pTask->locInfo.strPath);
     636        m->pReader = new OVFReader(locInfo.strPath);
    714637        /* Create the SHA1 sum of the OVF file for later validation */
    715638        char *pszDigest;
    716         int vrc = RTSha1Digest(pTask->locInfo.strPath.c_str(), &pszDigest);
     639        int vrc = RTSha1Digest(locInfo.strPath.c_str(), &pszDigest);
    717640        if (RT_FAILURE(vrc))
    718641            throw setError(VBOX_E_FILE_ERROR,
    719642                           tr("Couldn't calculate SHA1 digest for file '%s' (%Rrc)"),
    720                            RTPathFilename(pTask->locInfo.strPath.c_str()), vrc);
     643                           RTPathFilename(locInfo.strPath.c_str()), vrc);
    721644        m->strOVFSHA1Digest = pszDigest;
    722645        RTStrFree(pszDigest);
     
    732655    }
    733656
    734     pTask->rc = rc;
    735 
    736     if (!pTask->progress.isNull())
    737         pTask->progress->notifyComplete(rc);
    738 
    739657    LogFlowFunc(("rc=%Rhrc\n", rc));
    740658    LogFlowFuncLeave();
    741659
    742     return VINF_SUCCESS;
     660    return rc;
    743661}
    744662
     
    751669 * @return
    752670 */
    753 int Appliance::readS3(TaskImportOVF *pTask)
     671HRESULT Appliance::readS3(TaskOVF *pTask)
    754672{
    755673    LogFlowFuncEnter();
     
    818736        hS3 = NIL_RTS3;
    819737
    820         if (!pTask->progress.isNull())
    821             pTask->progress->SetNextOperation(Bstr(tr("Reading")), 1);
     738        if (!pTask->pProgress.isNull())
     739            pTask->pProgress->SetNextOperation(Bstr(tr("Reading")), 1);
    822740
    823741        /* Prepare the temporary reading of the OVF */
     
    834752           caller */
    835753        ComPtr<IProgress> progressInt(progress);
    836         waitForAsyncProgress(pTask->progress, progressInt); /* Any errors will be thrown */
     754        waitForAsyncProgress(pTask->pProgress, progressInt); /* Any errors will be thrown */
    837755
    838756        /* Again lock the appliance for the next steps */
     
    864782        RTStrFree(pszTmpDir);
    865783
    866     pTask->rc = rc;
    867 
    868     if (!pTask->progress.isNull())
    869         pTask->progress->notifyComplete(rc);
    870 
    871784    LogFlowFunc(("rc=%Rhrc\n", rc));
    872785    LogFlowFuncLeave();
     
    958871HRESULT Appliance::importImpl(const LocationInfo &aLocInfo, ComObjPtr<Progress> &aProgress)
    959872{
    960     /* Initialize our worker task */
    961     std::auto_ptr<TaskImportOVF> task(new TaskImportOVF(this));
    962     /* What should the task do */
    963     task->taskType = TaskImportOVF::Import;
    964     /* Copy the current location info to the task */
    965     task->locInfo = aLocInfo;
    966 
    967873    Bstr progressDesc = BstrFmt(tr("Import appliance '%s'"),
    968874                                aLocInfo.strPath.c_str());
    969 
    970875    HRESULT rc = S_OK;
    971876
    972877    /* todo: This progress init stuff should be done a little bit more generic */
    973     if (task->locInfo.storageType == VFSType_File)
     878    if (aLocInfo.storageType == VFSType_File)
    974879        rc = setUpProgressFS(aProgress, progressDesc);
    975880    else
     
    977882    if (FAILED(rc)) throw rc;
    978883
    979     task->progress = aProgress;
     884    /* Initialize our worker task */
     885    std::auto_ptr<TaskOVF> task(new TaskOVF(this, TaskOVF::Import, aLocInfo, aProgress));
    980886
    981887    rc = task->startThread();
     
    1000906 * @return
    1001907 */
    1002 int Appliance::importFS(TaskImportOVF *pTask)
     908HRESULT Appliance::importFS(const LocationInfo &locInfo, ComObjPtr<Progress> &pProgress)
    1003909{
    1004910    LogFlowFuncEnter();
     
    1011917
    1012918    if (!isApplianceIdle())
    1013         return VERR_ACCESS_DENIED;
     919        return E_ACCESSDENIED;
    1014920
    1015921    // Change the appliance state so we can safely leave the lock while doing time-consuming
     
    1038944    /* If an manifest file exists, verify the content. Therefore we need all
    1039945     * files which are referenced by the OVF & the OVF itself */
    1040     Utf8Str strMfFile = manifestFileName(pTask->locInfo.strPath);
     946    Utf8Str strMfFile = manifestFileName(locInfo.strPath);
    1041947    list<Utf8Str> filesList;
    1042948    if (RTPathExists(strMfFile.c_str()))
    1043949    {
    1044         Utf8Str strSrcDir(pTask->locInfo.strPath);
     950        Utf8Str strSrcDir(locInfo.strPath);
    1045951        strSrcDir.stripFilename();
    1046952        /* Add every disks of every virtual system to an internal list */
     
    1067973        /* Create the test list */
    1068974        PRTMANIFESTTEST pTestList = (PRTMANIFESTTEST)RTMemAllocZ(sizeof(RTMANIFESTTEST)*(filesList.size()+1));
    1069         pTestList[0].pszTestFile = (char*)pTask->locInfo.strPath.c_str();
     975        pTestList[0].pszTestFile = (char*)locInfo.strPath.c_str();
    1070976        pTestList[0].pszTestDigest = (char*)m->strOVFSHA1Digest.c_str();
    1071977        int vrc = VINF_SUCCESS;
     
    10991005            RTStrFree(pTestList[j].pszTestDigest);
    11001006        RTMemFree(pTestList);
    1101         if (FAILED(rc))
    1102         {
    1103             /* Return on error */
    1104             pTask->rc = rc;
    1105 
    1106             if (!pTask->progress.isNull())
    1107                 pTask->progress->notifyComplete(rc);
    1108             return rc;
    1109         }
     1007        if (FAILED(rc)) return rc;
    11101008    }
    11111009
     
    15821480                    /* The disk image has to be on the same place as the OVF file. So
    15831481                     * strip the filename out of the full file path. */
    1584                     Utf8Str strSrcDir(pTask->locInfo.strPath);
     1482                    Utf8Str strSrcDir(locInfo.strPath);
    15851483                    strSrcDir.stripFilename();
    15861484
     
    16441542
    16451543                            /* Advance to the next operation */
    1646                             if (!pTask->progress.isNull())
    1647                                 pTask->progress->SetNextOperation(BstrFmt(tr("Creating virtual disk image '%s'"), vsdeHD->strVbox.c_str()),
    1648                                                                  vsdeHD->ulSizeMB);     // operation's weight, as set up with the IProgress originally
     1544                            if (!pProgress.isNull())
     1545                                pProgress->SetNextOperation(BstrFmt(tr("Creating virtual disk image '%s'"), vsdeHD->strVbox.c_str()),
     1546                                                            vsdeHD->ulSizeMB);     // operation's weight, as set up with the IProgress originally
    16491547                        }
    16501548                        else
     
    16861584
    16871585                            /* Advance to the next operation */
    1688                             if (!pTask->progress.isNull())
    1689                                 pTask->progress->SetNextOperation(BstrFmt(tr("Importing virtual disk image '%s'"), strSrcFilePath.c_str()),
    1690                                                                  vsdeHD->ulSizeMB);     // operation's weight, as set up with the IProgress originally);
     1586                            if (!pProgress.isNull())
     1587                                pProgress->SetNextOperation(BstrFmt(tr("Importing virtual disk image '%s'"), strSrcFilePath.c_str()),
     1588                                                            vsdeHD->ulSizeMB);     // operation's weight, as set up with the IProgress originally);
    16911589                        }
    16921590
    16931591                        // now wait for the background disk operation to complete; this throws HRESULTs on error
    1694                         waitForAsyncProgress(pTask->progress, pProgress2);
     1592                        waitForAsyncProgress(pProgress, pProgress2);
    16951593
    16961594                        if (fSourceHdNeedsClosing)
     
    18021700        {
    18031701            ComPtr<IMedium> pDisk = *itHD;
    1804             ComPtr<IProgress> pProgress;
    1805             rc2 = pDisk->DeleteStorage(pProgress.asOutParam());
    1806             rc2 = pProgress->WaitForCompletion(-1);
     1702            ComPtr<IProgress> pProgress2;
     1703            rc2 = pDisk->DeleteStorage(pProgress2.asOutParam());
     1704            rc2 = pProgress2->WaitForCompletion(-1);
    18071705        }
    18081706
     
    18251723    m->state = Data::ApplianceIdle;
    18261724
    1827     pTask->rc = rc;
    1828 
    1829     if (!pTask->progress.isNull())
    1830         pTask->progress->notifyComplete(rc);
    1831 
    18321725    LogFlowFunc(("rc=%Rhrc\n", rc));
    18331726    LogFlowFuncLeave();
    18341727
    1835     return VINF_SUCCESS;
     1728    return rc;
    18361729}
    18371730
     
    18411734 * @return
    18421735 */
    1843 int Appliance::importS3(TaskImportOVF *pTask)
     1736HRESULT Appliance::importS3(TaskOVF *pTask)
    18441737{
    18451738    LogFlowFuncEnter();
     
    19131806            char *pszFilename = RTPathFilename(strSrcFile.c_str());
    19141807            /* Advance to the next operation */
    1915             if (!pTask->progress.isNull())
    1916                 pTask->progress->SetNextOperation(BstrFmt(tr("Downloading file '%s'"), pszFilename), s.second);
     1808            if (!pTask->pProgress.isNull())
     1809                pTask->pProgress->SetNextOperation(BstrFmt(tr("Downloading file '%s'"), pszFilename), s.second);
    19171810
    19181811            vrc = RTS3GetKey(hS3, bucket.c_str(), pszFilename, strSrcFile.c_str());
     
    19391832        Utf8Str strManifestFile = manifestFileName(strTmpOvf);
    19401833        char *pszFilename = RTPathFilename(strManifestFile.c_str());
    1941         if (!pTask->progress.isNull())
    1942             pTask->progress->SetNextOperation(BstrFmt(tr("Downloading file '%s'"), pszFilename), 1);
     1834        if (!pTask->pProgress.isNull())
     1835            pTask->pProgress->SetNextOperation(BstrFmt(tr("Downloading file '%s'"), pszFilename), 1);
    19431836
    19441837        /* Try to download it. If the error is VERR_S3_NOT_FOUND, it isn't fatal. */
     
    19641857        hS3 = NIL_RTS3;
    19651858
    1966         if (!pTask->progress.isNull())
    1967             pTask->progress->SetNextOperation(BstrFmt(tr("Importing appliance")), m->ulWeightPerOperation);
     1859        if (!pTask->pProgress.isNull())
     1860            pTask->pProgress->SetNextOperation(BstrFmt(tr("Importing appliance")), m->ulWeightPerOperation);
    19681861
    19691862        ComObjPtr<Progress> progress;
     
    19791872           caller */
    19801873        ComPtr<IProgress> progressInt(progress);
    1981         waitForAsyncProgress(pTask->progress, progressInt); /* Any errors will be thrown */
     1874        waitForAsyncProgress(pTask->pProgress, progressInt); /* Any errors will be thrown */
    19821875
    19831876        /* Again lock the appliance for the next steps */
     
    20131906        RTStrFree(pszTmpDir);
    20141907
    2015     pTask->rc = rc;
    2016 
    2017     if (!pTask->progress.isNull())
    2018         pTask->progress->notifyComplete(rc);
    2019 
    20201908    LogFlowFunc(("rc=%Rhrc\n", rc));
    20211909    LogFlowFuncLeave();
    20221910
    2023     return VINF_SUCCESS;
     1911    return rc;
    20241912}
    20251913
  • trunk/src/VBox/Main/include/ApplianceImpl.h

    r27882 r27895  
    118118
    119119    struct TaskOVF;
    120 
    121     struct TaskImportOVF; /* Worker threads for import */
    122     int readFS(TaskImportOVF *pTask);
    123     int readS3(TaskImportOVF *pTask);
     120    static DECLCALLBACK(int) taskThreadImportOrExport(RTTHREAD aThread, void *pvUser);
     121
     122    HRESULT readFS(const LocationInfo &locInfo);
     123    HRESULT readS3(TaskOVF *pTask);
    124124
    125125    void convertDiskAttachmentValues(const HardDiskController &hdc,
     
    131131    HRESULT importImpl(const LocationInfo &aLocInfo, ComObjPtr<Progress> &aProgress);
    132132
    133     static DECLCALLBACK(int) taskThreadImportOVF(RTTHREAD aThread, void *pvUser);
    134 
    135     int importFS(TaskImportOVF *pTask);
    136     int importS3(TaskImportOVF *pTask);
     133    HRESULT importFS(const LocationInfo &locInfo, ComObjPtr<Progress> &aProgress);
     134    HRESULT importS3(TaskOVF *pTask);
    137135
    138136    HRESULT writeImpl(OVFFormat aFormat, const LocationInfo &aLocInfo, ComObjPtr<Progress> &aProgress);
    139 
    140     struct TaskExportOVF; /* Worker threads for export */
    141     static DECLCALLBACK(int) taskThreadWriteOVF(RTTHREAD aThread, void *pvUser);
    142137
    143138    struct XMLStack;
     
    147142                                     XMLStack &stack);
    148143
    149     int writeFS(TaskExportOVF *pTask);
    150     int writeS3(TaskExportOVF *pTask);
     144    HRESULT writeFS(const LocationInfo &locInfo, const OVFFormat enFormat, ComObjPtr<Progress> &pProgress);
     145    HRESULT writeS3(TaskOVF *pTask);
    151146
    152147    friend class Machine;
  • trunk/src/VBox/Main/include/ApplianceImplPrivate.h

    r27836 r27895  
    8989struct Appliance::TaskOVF
    9090{
    91     TaskOVF(Appliance *aThat)
     91    enum TaskType
     92    {
     93        Read,
     94        Import,
     95        Write
     96    };
     97
     98    TaskOVF(Appliance *aThat,
     99            TaskType aType,
     100            LocationInfo aLocInfo,
     101            ComObjPtr<Progress> &aProgress)
    92102      : pAppliance(aThat),
     103        taskType(aType),
     104        locInfo(aLocInfo),
     105        pProgress(aProgress),
     106        enFormat(unspecified),
    93107        rc(S_OK)
    94108    {}
     
    96110    static int updateProgress(unsigned uPercent, void *pvUser);
    97111
    98     LocationInfo locInfo;
    99     Appliance *pAppliance;
    100     ComObjPtr<Progress> progress;
    101     HRESULT rc;
    102 };
    103 
    104 struct Appliance::TaskImportOVF : Appliance::TaskOVF
    105 {
    106     enum TaskType
    107     {
    108         Read,
    109         Import
    110     };
    111 
    112     TaskImportOVF(Appliance *aThat)
    113         : TaskOVF(aThat),
    114           taskType(Read)
    115     {}
    116 
    117112    int startThread();
    118113
     114    Appliance *pAppliance;
    119115    TaskType taskType;
    120 };
     116    const LocationInfo locInfo;
     117    ComObjPtr<Progress> pProgress;
    121118
    122 struct Appliance::TaskExportOVF : Appliance::TaskOVF
    123 {
    124     enum TaskType
    125     {
    126         Write
    127     };
     119    OVFFormat enFormat;
    128120
    129     TaskExportOVF(Appliance *aThat)
    130         : TaskOVF(aThat),
    131           taskType(Write)
    132     {}
    133 
    134     int startThread();
    135 
    136     TaskType taskType;
    137     OVFFormat enFormat;
     121    HRESULT rc;
    138122};
    139123
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