VirtualBox

Ignore:
Timestamp:
Apr 11, 2010 12:44:21 PM (15 years ago)
Author:
vboxsync
Message:

Main/OVF: isolate disk import code from other import code; clean up progress handling

File:
1 edited

Legend:

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

    r27918 r28162  
    628628}
    629629
    630 void Appliance::disksWeight(uint32_t &ulTotalMB, uint32_t &cDisks) const
    631 {
    632     ulTotalMB = 0;
    633     cDisks = 0;
    634     /* Weigh the disk images according to their sizes */
     630/**
     631 * Refreshes the cDisks and ulTotalDisksMB members in the instance data.
     632 * Requires that virtual system descriptions are present.
     633 */
     634void Appliance::disksWeight()
     635{
     636    m->ulTotalDisksMB = 0;
     637    m->cDisks = 0;
     638    // weigh the disk images according to their sizes
    635639    list< ComObjPtr<VirtualSystemDescription> >::const_iterator it;
    636640    for (it = m->virtualSystemDescriptions.begin();
     
    647651        {
    648652            const VirtualSystemDescriptionEntry *pHD = *itH;
    649             ulTotalMB += pHD->ulSizeMB;
    650             ++cDisks;
     653            m->ulTotalDisksMB += pHD->ulSizeMB;
     654            ++m->cDisks;
    651655        }
    652656    }
     
    654658}
    655659
    656 HRESULT Appliance::setUpProgressFS(ComObjPtr<Progress> &pProgress, const Bstr &bstrDescription)
     660HRESULT Appliance::setUpProgress(ComObjPtr<Progress> &pProgress,
     661                                 const Bstr &bstrDescription,
     662                                 SetUpProgressMode mode)
    657663{
    658664    HRESULT rc;
     
    661667    pProgress.createObject();
    662668
    663     /* Weigh the disk images according to their sizes */
    664     uint32_t ulTotalMB;
    665     uint32_t cDisks;
    666     disksWeight(ulTotalMB, cDisks);
    667 
    668     ULONG cOperations = 1 + cDisks;     // one op per disk plus 1 for the XML
    669 
     669    // compute the disks weight (this sets ulTotalDisksMB and cDisks in the instance data)
     670    disksWeight();
     671
     672    ULONG cOperations;
    670673    ULONG ulTotalOperationsWeight;
    671     if (ulTotalMB)
    672     {
    673         m->ulWeightPerOperation = (ULONG)((double)ulTotalMB * 1  / 100);    // use 1% of the progress for the XML
    674         ulTotalOperationsWeight = ulTotalMB + m->ulWeightPerOperation;
     674
     675    cOperations =   1               // one for XML setup
     676                  + m->cDisks;      // plus one per disk
     677    if (m->ulTotalDisksMB)
     678    {
     679        m->ulWeightPerOperation = (ULONG)((double)m->ulTotalDisksMB * 1 / 100);    // use 1% of the progress for the XML
     680        ulTotalOperationsWeight = m->ulTotalDisksMB + m->ulWeightPerOperation;
    675681    }
    676682    else
    677683    {
    678684        // no disks to export:
     685        m->ulWeightPerOperation = 1;
    679686        ulTotalOperationsWeight = 1;
    680         m->ulWeightPerOperation = 1;
     687    }
     688
     689    switch (mode)
     690    {
     691        case Regular:
     692        break;
     693
     694        case ImportS3:
     695        {
     696            cOperations += 1 + 1;     // another one for the manifest file & another one for the import
     697            ulTotalOperationsWeight = m->ulTotalDisksMB;
     698            if (!m->ulTotalDisksMB)
     699                // no disks to export:
     700                ulTotalOperationsWeight = 1;
     701
     702            ULONG ulImportWeight = (ULONG)((double)ulTotalOperationsWeight * 50  / 100);  // use 50% for import
     703            ulTotalOperationsWeight += ulImportWeight;
     704
     705            m->ulWeightPerOperation = ulImportWeight; /* save for using later */
     706
     707            ULONG ulInitWeight = (ULONG)((double)ulTotalOperationsWeight * 0.1  / 100);  // use 0.1% for init
     708            ulTotalOperationsWeight += ulInitWeight;
     709        }
     710        break;
     711
     712        case WriteS3:
     713        {
     714            cOperations += 1 + 1;     // another one for the mf & another one for temporary creation
     715
     716            if (m->ulTotalDisksMB)
     717            {
     718                m->ulWeightPerOperation = (ULONG)((double)m->ulTotalDisksMB * 1  / 100);    // use 1% of the progress for OVF file upload (we didn't know the size at this point)
     719                ulTotalOperationsWeight = m->ulTotalDisksMB + m->ulWeightPerOperation;
     720            }
     721            else
     722            {
     723                // no disks to export:
     724                ulTotalOperationsWeight = 1;
     725                m->ulWeightPerOperation = 1;
     726            }
     727            ULONG ulOVFCreationWeight = (ULONG)((double)ulTotalOperationsWeight * 50.0 / 100.0); /* Use 50% for the creation of the OVF & the disks */
     728            ulTotalOperationsWeight += ulOVFCreationWeight;
     729        }
     730        break;
    681731    }
    682732
    683733    Log(("Setting up progress object: ulTotalMB = %d, cDisks = %d, => cOperations = %d, ulTotalOperationsWeight = %d, m->ulWeightPerOperation = %d\n",
    684          ulTotalMB, cDisks, cOperations, ulTotalOperationsWeight, m->ulWeightPerOperation));
     734         m->ulTotalDisksMB, m->cDisks, cOperations, ulTotalOperationsWeight, m->ulWeightPerOperation));
    685735
    686736    rc = pProgress->init(mVirtualBox, static_cast<IAppliance*>(this),
     
    691741                         bstrDescription, // CBSTR bstrFirstOperationDescription,
    692742                         m->ulWeightPerOperation); // ULONG ulFirstOperationWeight,
    693     return rc;
    694 }
    695 
    696 HRESULT Appliance::setUpProgressImportS3(ComObjPtr<Progress> &pProgress, const Bstr &bstrDescription)
    697 {
    698     HRESULT rc;
    699 
    700     /* Create the progress object */
    701     pProgress.createObject();
    702 
    703     /* Weigh the disk images according to their sizes */
    704     uint32_t ulTotalMB;
    705     uint32_t cDisks;
    706     disksWeight(ulTotalMB, cDisks);
    707 
    708     ULONG cOperations = 1 + 1 + 1 + cDisks;     // one op per disk plus 1 for init, plus 1 for the manifest file & 1 plus for the import */
    709 
    710     ULONG ulTotalOperationsWeight = ulTotalMB;
    711     if (!ulTotalOperationsWeight)
    712         // no disks to export:
    713         ulTotalOperationsWeight = 1;
    714 
    715     ULONG ulImportWeight = (ULONG)((double)ulTotalOperationsWeight * 50  / 100);  // use 50% for import
    716     ulTotalOperationsWeight += ulImportWeight;
    717 
    718     m->ulWeightPerOperation = ulImportWeight; /* save for using later */
    719 
    720     ULONG ulInitWeight = (ULONG)((double)ulTotalOperationsWeight * 0.1  / 100);  // use 0.1% for init
    721     ulTotalOperationsWeight += ulInitWeight;
    722 
    723     Log(("Setting up progress object: ulTotalMB = %d, cDisks = %d, => cOperations = %d, ulTotalOperationsWeight = %d, m->ulWeightPerOperation = %d\n",
    724          ulTotalMB, cDisks, cOperations, ulTotalOperationsWeight, m->ulWeightPerOperation));
    725 
    726     rc = pProgress->init(mVirtualBox, static_cast<IAppliance*>(this),
    727                          bstrDescription,
    728                          TRUE /* aCancelable */,
    729                          cOperations, // ULONG cOperations,
    730                          ulTotalOperationsWeight, // ULONG ulTotalOperationsWeight,
    731                          Bstr(tr("Init")), // CBSTR bstrFirstOperationDescription,
    732                          ulInitWeight); // ULONG ulFirstOperationWeight,
    733     return rc;
    734 }
    735 
    736 HRESULT Appliance::setUpProgressWriteS3(ComObjPtr<Progress> &pProgress, const Bstr &bstrDescription)
    737 {
    738     HRESULT rc;
    739 
    740     /* Create the progress object */
    741     pProgress.createObject();
    742 
    743     /* Weigh the disk images according to their sizes */
    744     uint32_t ulTotalMB;
    745     uint32_t cDisks;
    746     disksWeight(ulTotalMB, cDisks);
    747 
    748     ULONG cOperations = 1 + 1 + 1 + cDisks;     // one op per disk plus 1 for the OVF, plus 1 for the mf & 1 plus to the temporary creation */
    749 
    750     ULONG ulTotalOperationsWeight;
    751     if (ulTotalMB)
    752     {
    753         m->ulWeightPerOperation = (ULONG)((double)ulTotalMB * 1  / 100);    // use 1% of the progress for OVF file upload (we didn't know the size at this point)
    754         ulTotalOperationsWeight = ulTotalMB + m->ulWeightPerOperation;
    755     }
    756     else
    757     {
    758         // no disks to export:
    759         ulTotalOperationsWeight = 1;
    760         m->ulWeightPerOperation = 1;
    761     }
    762     ULONG ulOVFCreationWeight = (ULONG)((double)ulTotalOperationsWeight * 50.0 / 100.0); /* Use 50% for the creation of the OVF & the disks */
    763     ulTotalOperationsWeight += ulOVFCreationWeight;
    764 
    765     Log(("Setting up progress object: ulTotalMB = %d, cDisks = %d, => cOperations = %d, ulTotalOperationsWeight = %d, m->ulWeightPerOperation = %d\n",
    766          ulTotalMB, cDisks, cOperations, ulTotalOperationsWeight, m->ulWeightPerOperation));
    767 
    768     rc = pProgress->init(mVirtualBox, static_cast<IAppliance*>(this),
    769                          bstrDescription,
    770                          TRUE /* aCancelable */,
    771                          cOperations, // ULONG cOperations,
    772                          ulTotalOperationsWeight, // ULONG ulTotalOperationsWeight,
    773                          bstrDescription, // CBSTR bstrFirstOperationDescription,
    774                          ulOVFCreationWeight); // ULONG ulFirstOperationWeight,
    775743    return rc;
    776744}
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