Changeset 27895 in vbox
- Timestamp:
- Mar 31, 2010 1:30:14 PM (15 years ago)
- Location:
- trunk/src/VBox/Main
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/ApplianceImpl.cpp
r27886 r27895 21 21 */ 22 22 23 #include <iprt/stream.h>24 23 #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> 33 26 34 27 #include "ApplianceImpl.h" … … 38 31 #include "ProgressImpl.h" 39 32 #include "MachineImpl.h" 40 #include "MediumImpl.h"41 42 #include "HostNetworkInterfaceImpl.h"43 33 44 34 #include "AutoCaller.h" … … 602 592 * already */ 603 593 /* @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 ) 606 597 { 607 598 RTStrFree(tmpName); … … 914 905 } 915 906 907 /** 908 * 909 * @return 910 */ 911 int 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 */ 933 DECLCALLBACK(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 916 979 /* static */ 917 980 int Appliance::TaskOVF::updateProgress(unsigned uPercent, void *pvUser) … … 920 983 921 984 if ( pTask 922 && !pTask->p rogress.isNull())985 && !pTask->pProgress.isNull()) 923 986 { 924 987 BOOL fCanceled; 925 pTask->p rogress->COMGETTER(Canceled)(&fCanceled);988 pTask->pProgress->COMGETTER(Canceled)(&fCanceled); 926 989 if (fCanceled) 927 990 return -1; 928 pTask->p rogress->SetCurrentOperationProgress(uPercent);991 pTask->pProgress->SetCurrentOperationProgress(uPercent); 929 992 } 930 993 return VINF_SUCCESS; -
trunk/src/VBox/Main/ApplianceImplExport.cpp
r27886 r27895 21 21 */ 22 22 23 #include <iprt/stream.h>24 23 #include <iprt/path.h> 25 24 #include <iprt/dir.h> 26 #include <iprt/ file.h>25 #include <iprt/param.h> 27 26 #include <iprt/s3.h> 28 #include <iprt/sha.h>29 27 #include <iprt/manifest.h> 30 28 31 #include <VBox/param.h>32 29 #include <VBox/version.h> 33 30 34 31 #include "ApplianceImpl.h" 35 #include "VFSExplorerImpl.h"36 32 #include "VirtualBoxImpl.h" 37 #include "GuestOSTypeImpl.h" 33 38 34 #include "ProgressImpl.h" 39 35 #include "MachineImpl.h" 40 #include "MediumImpl.h"41 42 #include "HostNetworkInterfaceImpl.h"43 36 44 37 #include "AutoCaller.h" … … 48 41 49 42 using namespace std; 50 51 ////////////////////////////////////////////////////////////////////////////////52 //53 // internal helpers54 //55 ////////////////////////////////////////////////////////////////////////////////56 43 57 44 //////////////////////////////////////////////////////////////////////////////// … … 619 606 try 620 607 { 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 630 608 Bstr progressDesc = BstrFmt(tr("Export appliance '%s'"), 631 task->locInfo.strPath.c_str());609 aLocInfo.strPath.c_str()); 632 610 633 611 /* 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) 635 613 rc = setUpProgressFS(aProgress, progressDesc); 636 614 else 637 615 rc = setUpProgressWriteS3(aProgress, progressDesc); 638 616 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; 640 621 641 622 rc = task->startThread(); … … 651 632 652 633 return rc; 653 }654 655 /**656 *657 * @return658 */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 turn673 * call Appliance::writeFS() or Appliance::writeS3().674 * @param675 * @param pvUser676 * @return677 */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;706 634 } 707 635 … … 1324 1252 * @return 1325 1253 */ 1326 int Appliance::writeFS(TaskExportOVF *pTask)1254 HRESULT Appliance::writeFS(const LocationInfo &locInfo, const OVFFormat enFormat, ComObjPtr<Progress> &pProgress) 1327 1255 { 1328 1256 LogFlowFuncEnter(); … … 1341 1269 xml::ElementNode *pelmRoot = doc.createRootElement("Envelope"); 1342 1270 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"); 1344 1272 pelmRoot->setAttribute("xml:lang", "en-US"); 1345 1273 1346 Utf8Str strNamespace = ( pTask->enFormat == OVF_0_9)1274 Utf8Str strNamespace = (enFormat == OVF_0_9) 1347 1275 ? "http://www.vmware.com/schema/ovf/1/envelope" // 0.9 1348 1276 : "http://schemas.dmtf.org/ovf/envelope/1"; // 1.0 … … 1366 1294 </DiskSection> */ 1367 1295 xml::ElementNode *pelmDiskSection; 1368 if ( pTask->enFormat == OVF_0_9)1296 if (enFormat == OVF_0_9) 1369 1297 { 1370 1298 // <Section xsi:type="ovf:DiskSection_Type"> … … 1391 1319 </NetworkSection> */ 1392 1320 xml::ElementNode *pelmNetworkSection; 1393 if ( pTask->enFormat == OVF_0_9)1321 if (enFormat == OVF_0_9) 1394 1322 { 1395 1323 // <Section xsi:type="ovf:NetworkSection_Type"> … … 1417 1345 if (m->virtualSystemDescriptions.size() > 1) 1418 1346 { 1419 if ( pTask->enFormat == OVF_0_9)1347 if (enFormat == OVF_0_9) 1420 1348 throw setError(VBOX_E_FILE_ERROR, 1421 1349 tr("Cannot export more than one virtual system with OVF 0.9, use OVF 1.0")); … … 1436 1364 buildXMLForOneVirtualSystem(*pelmToAddVirtualSystemsTo, 1437 1365 vsdescThis, 1438 pTask->enFormat,1366 enFormat, 1439 1367 stack); // disks and networks stack 1440 1368 } … … 1477 1405 const Utf8Str &strTargetFileNameOnly = pDiskEntry->strOvf; 1478 1406 // target path needs to be composed from where the output OVF is 1479 Utf8Str strTargetFilePath( pTask->locInfo.strPath);1407 Utf8Str strTargetFilePath(locInfo.strPath); 1480 1408 strTargetFilePath.stripFilename(); 1481 1409 strTargetFilePath.append("/"); … … 1508 1436 1509 1437 // advance to the next operation 1510 if (!p Task->progress.isNull())1511 p Task->progress->SetNextOperation(BstrFmt(tr("Exporting virtual disk image '%s'"), strSrcFilePath.c_str()),1512 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); 1513 1441 1514 1442 // now wait for the background disk operation to complete; this throws HRESULTs on error 1515 waitForAsyncProgress(p Task->progress, pProgress2);1443 waitForAsyncProgress(pProgress, pProgress2); 1516 1444 } 1517 1445 catch (HRESULT rc3) … … 1558 1486 // now go write the XML 1559 1487 xml::XmlFileWriter writer(doc); 1560 writer.write( pTask->locInfo.strPath.c_str());1488 writer.write(locInfo.strPath.c_str()); 1561 1489 1562 1490 /* Create & write the manifest file */ 1563 1491 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(); 1565 1493 list<Utf8Str>::const_iterator it1; 1566 1494 size_t i = 1; … … 1569 1497 ++it1, ++i) 1570 1498 ppManifestFiles[i] = (*it1).c_str(); 1571 Utf8Str strMfFile = manifestFileName( pTask->locInfo.strPath.c_str());1499 Utf8Str strMfFile = manifestFileName(locInfo.strPath.c_str()); 1572 1500 int vrc = RTManifestWriteFiles(strMfFile.c_str(), ppManifestFiles, diskList.size()+1); 1573 1501 RTMemFree(ppManifestFiles); … … 1591 1519 m->state = Data::ApplianceIdle; 1592 1520 1593 pTask->rc = rc;1594 1595 if (!pTask->progress.isNull())1596 pTask->progress->notifyComplete(rc);1597 1598 1521 LogFlowFunc(("rc=%Rhrc\n", rc)); 1599 1522 LogFlowFuncLeave(); 1600 1523 1601 return VINF_SUCCESS;1524 return rc; 1602 1525 } 1603 1526 … … 1610 1533 * @return 1611 1534 */ 1612 int Appliance::writeS3(TaskExportOVF *pTask)1535 HRESULT Appliance::writeS3(TaskOVF *pTask) 1613 1536 { 1614 1537 LogFlowFuncEnter(); … … 1664 1587 caller */ 1665 1588 ComPtr<IProgress> progressInt(progress); 1666 waitForAsyncProgress(pTask->p rogress, progressInt); /* Any errors will be thrown */1589 waitForAsyncProgress(pTask->pProgress, progressInt); /* Any errors will be thrown */ 1667 1590 1668 1591 /* Again lock the appliance for the next steps */ … … 1717 1640 char *pszFilename = RTPathFilename(s.first.c_str()); 1718 1641 /* Advance to the next operation */ 1719 if (!pTask->p rogress.isNull())1720 pTask->p rogress->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); 1721 1644 vrc = RTS3PutKey(hS3, bucket.c_str(), pszFilename, s.first.c_str()); 1722 1645 if (RT_FAILURE(vrc)) … … 1765 1688 RTStrFree(pszTmpDir); 1766 1689 1767 pTask->rc = rc;1768 1769 if (!pTask->progress.isNull())1770 pTask->progress->notifyComplete(rc);1771 1772 1690 LogFlowFunc(("rc=%Rhrc\n", rc)); 1773 1691 LogFlowFuncLeave(); 1774 1692 1775 return VINF_SUCCESS;1693 return rc; 1776 1694 } 1777 1695 -
trunk/src/VBox/Main/ApplianceImplImport.cpp
r27886 r27895 21 21 */ 22 22 23 #include <iprt/stream.h>24 23 #include <iprt/path.h> 25 24 #include <iprt/dir.h> … … 29 28 #include <iprt/manifest.h> 30 29 31 #include <VBox/param.h> 32 #include <VBox/version.h> 30 #include <VBox/com/array.h> 33 31 34 32 #include "ApplianceImpl.h" 35 #include "VFSExplorerImpl.h"36 33 #include "VirtualBoxImpl.h" 37 34 #include "GuestOSTypeImpl.h" 38 35 #include "ProgressImpl.h" 39 #include "MachineImpl.h"40 #include "MediumImpl.h"41 42 #include "HostNetworkInterfaceImpl.h"43 36 44 37 #include "AutoCaller.h" … … 46 39 47 40 #include "ApplianceImplPrivate.h" 41 42 #include <VBox/param.h> 43 #include <VBox/version.h> 48 44 49 45 using namespace std; … … 206 202 uint64_t ullMemSizeVBox = vsysThis.ullMemorySize / _1M; 207 203 /* 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 ) 211 208 { 212 209 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."), … … 576 573 HRESULT Appliance::readImpl(const LocationInfo &aLocInfo, ComObjPtr<Progress> &aProgress) 577 574 { 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 585 575 BstrFmt bstrDesc = BstrFmt(tr("Read appliance '%s'"), 586 576 aLocInfo.strPath.c_str()); … … 588 578 /* Create the progress object */ 589 579 aProgress.createObject(); 590 if (task->locInfo.storageType == VFSType_File) 591 { 580 if (aLocInfo.storageType == VFSType_File) 592 581 /* 1 operation only */ 593 582 rc = aProgress->init(mVirtualBox, static_cast<IAppliance*>(this), 594 583 bstrDesc, 595 584 TRUE /* aCancelable */); 596 }597 585 else 598 {599 586 /* 4/5 is downloading, 1/5 is reading */ 600 587 rc = aProgress->init(mVirtualBox, static_cast<IAppliance*>(this), … … 606 593 aLocInfo.strPath.c_str()), // CBSTR bstrFirstOperationDescription, 607 594 4); // ULONG ulFirstOperationWeight, 608 }609 595 if (FAILED(rc)) throw rc; 610 596 611 task->progress = aProgress; 597 /* Initialize our worker task */ 598 std::auto_ptr<TaskOVF> task(new TaskOVF(this, TaskOVF::Read, aLocInfo, aProgress)); 612 599 613 600 rc = task->startThread(); … … 618 605 619 606 return rc; 620 }621 622 /**623 *624 * @return625 */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 aThread644 * @param pvUser645 */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;684 607 } 685 608 … … 696 619 * @return 697 620 */ 698 int Appliance::readFS(TaskImportOVF *pTask)621 HRESULT Appliance::readFS(const LocationInfo &locInfo) 699 622 { 700 623 LogFlowFuncEnter(); … … 711 634 { 712 635 /* Read & parse the XML structure of the OVF file */ 713 m->pReader = new OVFReader( pTask->locInfo.strPath);636 m->pReader = new OVFReader(locInfo.strPath); 714 637 /* Create the SHA1 sum of the OVF file for later validation */ 715 638 char *pszDigest; 716 int vrc = RTSha1Digest( pTask->locInfo.strPath.c_str(), &pszDigest);639 int vrc = RTSha1Digest(locInfo.strPath.c_str(), &pszDigest); 717 640 if (RT_FAILURE(vrc)) 718 641 throw setError(VBOX_E_FILE_ERROR, 719 642 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); 721 644 m->strOVFSHA1Digest = pszDigest; 722 645 RTStrFree(pszDigest); … … 732 655 } 733 656 734 pTask->rc = rc;735 736 if (!pTask->progress.isNull())737 pTask->progress->notifyComplete(rc);738 739 657 LogFlowFunc(("rc=%Rhrc\n", rc)); 740 658 LogFlowFuncLeave(); 741 659 742 return VINF_SUCCESS;660 return rc; 743 661 } 744 662 … … 751 669 * @return 752 670 */ 753 int Appliance::readS3(TaskImportOVF *pTask)671 HRESULT Appliance::readS3(TaskOVF *pTask) 754 672 { 755 673 LogFlowFuncEnter(); … … 818 736 hS3 = NIL_RTS3; 819 737 820 if (!pTask->p rogress.isNull())821 pTask->p rogress->SetNextOperation(Bstr(tr("Reading")), 1);738 if (!pTask->pProgress.isNull()) 739 pTask->pProgress->SetNextOperation(Bstr(tr("Reading")), 1); 822 740 823 741 /* Prepare the temporary reading of the OVF */ … … 834 752 caller */ 835 753 ComPtr<IProgress> progressInt(progress); 836 waitForAsyncProgress(pTask->p rogress, progressInt); /* Any errors will be thrown */754 waitForAsyncProgress(pTask->pProgress, progressInt); /* Any errors will be thrown */ 837 755 838 756 /* Again lock the appliance for the next steps */ … … 864 782 RTStrFree(pszTmpDir); 865 783 866 pTask->rc = rc;867 868 if (!pTask->progress.isNull())869 pTask->progress->notifyComplete(rc);870 871 784 LogFlowFunc(("rc=%Rhrc\n", rc)); 872 785 LogFlowFuncLeave(); … … 958 871 HRESULT Appliance::importImpl(const LocationInfo &aLocInfo, ComObjPtr<Progress> &aProgress) 959 872 { 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 967 873 Bstr progressDesc = BstrFmt(tr("Import appliance '%s'"), 968 874 aLocInfo.strPath.c_str()); 969 970 875 HRESULT rc = S_OK; 971 876 972 877 /* 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) 974 879 rc = setUpProgressFS(aProgress, progressDesc); 975 880 else … … 977 882 if (FAILED(rc)) throw rc; 978 883 979 task->progress = aProgress; 884 /* Initialize our worker task */ 885 std::auto_ptr<TaskOVF> task(new TaskOVF(this, TaskOVF::Import, aLocInfo, aProgress)); 980 886 981 887 rc = task->startThread(); … … 1000 906 * @return 1001 907 */ 1002 int Appliance::importFS(TaskImportOVF *pTask)908 HRESULT Appliance::importFS(const LocationInfo &locInfo, ComObjPtr<Progress> &pProgress) 1003 909 { 1004 910 LogFlowFuncEnter(); … … 1011 917 1012 918 if (!isApplianceIdle()) 1013 return VERR_ACCESS_DENIED;919 return E_ACCESSDENIED; 1014 920 1015 921 // Change the appliance state so we can safely leave the lock while doing time-consuming … … 1038 944 /* If an manifest file exists, verify the content. Therefore we need all 1039 945 * files which are referenced by the OVF & the OVF itself */ 1040 Utf8Str strMfFile = manifestFileName( pTask->locInfo.strPath);946 Utf8Str strMfFile = manifestFileName(locInfo.strPath); 1041 947 list<Utf8Str> filesList; 1042 948 if (RTPathExists(strMfFile.c_str())) 1043 949 { 1044 Utf8Str strSrcDir( pTask->locInfo.strPath);950 Utf8Str strSrcDir(locInfo.strPath); 1045 951 strSrcDir.stripFilename(); 1046 952 /* Add every disks of every virtual system to an internal list */ … … 1067 973 /* Create the test list */ 1068 974 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(); 1070 976 pTestList[0].pszTestDigest = (char*)m->strOVFSHA1Digest.c_str(); 1071 977 int vrc = VINF_SUCCESS; … … 1099 1005 RTStrFree(pTestList[j].pszTestDigest); 1100 1006 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; 1110 1008 } 1111 1009 … … 1582 1480 /* The disk image has to be on the same place as the OVF file. So 1583 1481 * strip the filename out of the full file path. */ 1584 Utf8Str strSrcDir( pTask->locInfo.strPath);1482 Utf8Str strSrcDir(locInfo.strPath); 1585 1483 strSrcDir.stripFilename(); 1586 1484 … … 1644 1542 1645 1543 /* Advance to the next operation */ 1646 if (!p Task->progress.isNull())1647 p Task->progress->SetNextOperation(BstrFmt(tr("Creating virtual disk image '%s'"), vsdeHD->strVbox.c_str()),1648 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 1649 1547 } 1650 1548 else … … 1686 1584 1687 1585 /* Advance to the next operation */ 1688 if (!p Task->progress.isNull())1689 p Task->progress->SetNextOperation(BstrFmt(tr("Importing virtual disk image '%s'"), strSrcFilePath.c_str()),1690 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); 1691 1589 } 1692 1590 1693 1591 // now wait for the background disk operation to complete; this throws HRESULTs on error 1694 waitForAsyncProgress(p Task->progress, pProgress2);1592 waitForAsyncProgress(pProgress, pProgress2); 1695 1593 1696 1594 if (fSourceHdNeedsClosing) … … 1802 1700 { 1803 1701 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); 1807 1705 } 1808 1706 … … 1825 1723 m->state = Data::ApplianceIdle; 1826 1724 1827 pTask->rc = rc;1828 1829 if (!pTask->progress.isNull())1830 pTask->progress->notifyComplete(rc);1831 1832 1725 LogFlowFunc(("rc=%Rhrc\n", rc)); 1833 1726 LogFlowFuncLeave(); 1834 1727 1835 return VINF_SUCCESS;1728 return rc; 1836 1729 } 1837 1730 … … 1841 1734 * @return 1842 1735 */ 1843 int Appliance::importS3(TaskImportOVF *pTask)1736 HRESULT Appliance::importS3(TaskOVF *pTask) 1844 1737 { 1845 1738 LogFlowFuncEnter(); … … 1913 1806 char *pszFilename = RTPathFilename(strSrcFile.c_str()); 1914 1807 /* Advance to the next operation */ 1915 if (!pTask->p rogress.isNull())1916 pTask->p rogress->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); 1917 1810 1918 1811 vrc = RTS3GetKey(hS3, bucket.c_str(), pszFilename, strSrcFile.c_str()); … … 1939 1832 Utf8Str strManifestFile = manifestFileName(strTmpOvf); 1940 1833 char *pszFilename = RTPathFilename(strManifestFile.c_str()); 1941 if (!pTask->p rogress.isNull())1942 pTask->p rogress->SetNextOperation(BstrFmt(tr("Downloading file '%s'"), pszFilename), 1);1834 if (!pTask->pProgress.isNull()) 1835 pTask->pProgress->SetNextOperation(BstrFmt(tr("Downloading file '%s'"), pszFilename), 1); 1943 1836 1944 1837 /* Try to download it. If the error is VERR_S3_NOT_FOUND, it isn't fatal. */ … … 1964 1857 hS3 = NIL_RTS3; 1965 1858 1966 if (!pTask->p rogress.isNull())1967 pTask->p rogress->SetNextOperation(BstrFmt(tr("Importing appliance")), m->ulWeightPerOperation);1859 if (!pTask->pProgress.isNull()) 1860 pTask->pProgress->SetNextOperation(BstrFmt(tr("Importing appliance")), m->ulWeightPerOperation); 1968 1861 1969 1862 ComObjPtr<Progress> progress; … … 1979 1872 caller */ 1980 1873 ComPtr<IProgress> progressInt(progress); 1981 waitForAsyncProgress(pTask->p rogress, progressInt); /* Any errors will be thrown */1874 waitForAsyncProgress(pTask->pProgress, progressInt); /* Any errors will be thrown */ 1982 1875 1983 1876 /* Again lock the appliance for the next steps */ … … 2013 1906 RTStrFree(pszTmpDir); 2014 1907 2015 pTask->rc = rc;2016 2017 if (!pTask->progress.isNull())2018 pTask->progress->notifyComplete(rc);2019 2020 1908 LogFlowFunc(("rc=%Rhrc\n", rc)); 2021 1909 LogFlowFuncLeave(); 2022 1910 2023 return VINF_SUCCESS;1911 return rc; 2024 1912 } 2025 1913 -
trunk/src/VBox/Main/include/ApplianceImpl.h
r27882 r27895 118 118 119 119 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); 124 124 125 125 void convertDiskAttachmentValues(const HardDiskController &hdc, … … 131 131 HRESULT importImpl(const LocationInfo &aLocInfo, ComObjPtr<Progress> &aProgress); 132 132 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); 137 135 138 136 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);142 137 143 138 struct XMLStack; … … 147 142 XMLStack &stack); 148 143 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); 151 146 152 147 friend class Machine; -
trunk/src/VBox/Main/include/ApplianceImplPrivate.h
r27836 r27895 89 89 struct Appliance::TaskOVF 90 90 { 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) 92 102 : pAppliance(aThat), 103 taskType(aType), 104 locInfo(aLocInfo), 105 pProgress(aProgress), 106 enFormat(unspecified), 93 107 rc(S_OK) 94 108 {} … … 96 110 static int updateProgress(unsigned uPercent, void *pvUser); 97 111 98 LocationInfo locInfo;99 Appliance *pAppliance;100 ComObjPtr<Progress> progress;101 HRESULT rc;102 };103 104 struct Appliance::TaskImportOVF : Appliance::TaskOVF105 {106 enum TaskType107 {108 Read,109 Import110 };111 112 TaskImportOVF(Appliance *aThat)113 : TaskOVF(aThat),114 taskType(Read)115 {}116 117 112 int startThread(); 118 113 114 Appliance *pAppliance; 119 115 TaskType taskType; 120 }; 116 const LocationInfo locInfo; 117 ComObjPtr<Progress> pProgress; 121 118 122 struct Appliance::TaskExportOVF : Appliance::TaskOVF 123 { 124 enum TaskType 125 { 126 Write 127 }; 119 OVFFormat enFormat; 128 120 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; 138 122 }; 139 123
Note:
See TracChangeset
for help on using the changeset viewer.