Changeset 17646 in vbox
- Timestamp:
- Mar 10, 2009 5:47:31 PM (16 years ago)
- Location:
- trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/VBox/com/string.h
r17634 r17646 409 409 } 410 410 411 void append(const Utf8Str &that) 412 { 413 size_t cbThis = length(); 414 size_t cbThat = that.length(); 415 416 if (cbThat) 417 { 418 size_t cbBoth = cbThis + cbThat + 1; 419 420 // @todo optimize 421 char *pszTemp; 422 #if !defined (VBOX_WITH_XPCOM) 423 pszTemp = (char*)::RTMemTmpAlloc(cbBoth); 424 #else 425 pszTemp = (char*)nsMemory::Alloc(cbBoth); 426 #endif 427 if (str) 428 { 429 memcpy(pszTemp, str, cbThis); 430 setNull(); 431 } 432 if (that.str) 433 memcpy(pszTemp + cbThis, that.str, cbThat); 434 pszTemp[cbThis + cbThat] = '\0'; 435 436 str = pszTemp; 437 } 438 } 439 411 440 int compare (const char *s) const 412 441 { -
trunk/src/VBox/Main/ApplianceImpl.cpp
r17636 r17646 228 228 }; 229 229 230 struct Appliance::Task ExportOVF231 { 232 Task ExportOVF(Appliance *aThat, Progress *aProgress)230 struct Appliance::TaskWriteOVF 231 { 232 TaskWriteOVF(Appliance *aThat, Progress *aProgress) 233 233 : pAppliance(aThat) 234 234 , progress(aProgress) 235 235 , rc(S_OK) 236 236 {} 237 ~Task ExportOVF() {}237 ~TaskWriteOVF() {} 238 238 239 239 HRESULT startThread(); … … 412 412 } 413 413 414 HRESULT Appliance::Task ExportOVF::startThread()415 { 416 int vrc = RTThreadCreate(NULL, Appliance::taskThread ExportOVF, this,414 HRESULT Appliance::TaskWriteOVF::startThread() 415 { 416 int vrc = RTThreadCreate(NULL, Appliance::taskThreadWriteOVF, this, 417 417 0, RTTHREADTYPE_MAIN_HEAVY_WORKER, 0, 418 418 "Appliance::Task"); … … 1647 1647 1648 1648 /* Initialize our worker task */ 1649 std::auto_ptr<Task ExportOVF> task(new TaskExportOVF(this, progress));1649 std::auto_ptr<TaskWriteOVF> task(new TaskWriteOVF(this, progress)); 1650 1650 //AssertComRCThrowRC (task->autoCaller.rc()); 1651 1651 … … 2358 2358 2359 2359 /** 2360 * Worker thread implementation for ImportMachines().2360 * Worker thread implementation for Write() (ovf writer). 2361 2361 * @param aThread 2362 2362 * @param pvUser 2363 2363 */ 2364 2364 /* static */ 2365 DECLCALLBACK(int) Appliance::taskThread ExportOVF(RTTHREAD aThread, void *pvUser)2366 { 2367 std::auto_ptr<Task ImportMachines> task(static_cast<TaskImportMachines*>(pvUser));2365 DECLCALLBACK(int) Appliance::taskThreadWriteOVF(RTTHREAD aThread, void *pvUser) 2366 { 2367 std::auto_ptr<TaskWriteOVF> task(static_cast<TaskWriteOVF*>(pvUser)); 2368 2368 AssertReturn(task.get(), VERR_GENERAL_FAILURE); 2369 2369 … … 2412 2412 // @todo for each disk: 2413 2413 // xml::ElementNode *pelmDisk = pelmDiskSection->createChild("Disk"); 2414 // for now, set up a map so we have a list of unique disk names (to make 2415 // sure the same disk name is only added once) 2416 map<Utf8Str, const VirtualSystemDescriptionEntry*> mapDisks; 2414 2417 2415 2418 /* <Envelope>/<NetworkSection>: … … 2636 2639 if (uLoop == 2) 2637 2640 { 2641 Utf8Str strDiskID = Utf8StrFmt("vmdisk%RI32", ++cDisks); 2642 2638 2643 strDescription = "Disk Image"; 2639 strCaption = Utf8StrFmt("disk% d", ++cDisks);2644 strCaption = Utf8StrFmt("disk%RI32", cDisks); // this is not used for anything else 2640 2645 type = OVFResourceType_HardDisk; // 17 2641 strHostResource = desc.strOvf; 2646 2647 // the following references the "<Disks>" XML block 2648 strHostResource = Utf8StrFmt("/disk/%s", strDiskID.c_str()); 2649 2642 2650 // “controller=<index>;channel=<c>“ 2643 2651 size_t pos1 = desc.strExtraConfig.find("controller="); … … 2662 2670 throw setError(VBOX_E_NOT_SUPPORTED, 2663 2671 tr("Missing or bad extra config string in hard disk image: \"%s\""), desc.strExtraConfig.c_str()); 2672 2673 mapDisks[strDiskID] = &desc; 2664 2674 } 2665 2675 break; … … 2810 2820 pelmNetwork->setAttribute("ovf:name", strNetwork.c_str()); 2811 2821 pelmNetwork->createChild("Description")->addContent("Logical network used by this appliance."); 2822 } 2823 2824 map<Utf8Str, const VirtualSystemDescriptionEntry*>::const_iterator itS; 2825 uint32_t ulFile = 1; 2826 for (itS = mapDisks.begin(); 2827 itS != mapDisks.end(); 2828 ++itS) 2829 { 2830 const Utf8Str &strDiskID = itS->first; 2831 const VirtualSystemDescriptionEntry *pDiskEntry = itS->second; 2832 2833 // source path: where the VBox image is 2834 const Utf8Str &strSrcFilePath = pDiskEntry->strVbox; 2835 const Bstr bstrSrcFilePath(strSrcFilePath); 2836 if (!RTPathExists(strSrcFilePath.c_str())) 2837 /* This isn't allowed */ 2838 throw setError(VBOX_E_FILE_ERROR, 2839 tr("Source virtual disk image file '%s' doesn't exist"), 2840 strSrcFilePath.c_str()); 2841 2842 // output filename 2843 const Utf8Str &strTargetFileNameOnly = pDiskEntry->strOvf; 2844 // target path needs to be composed from where the output OVF is 2845 Utf8Str strTargetFilePath = stripFilename(pAppliance->m->strPath); 2846 strTargetFilePath.append("/"); 2847 strTargetFilePath.append(strTargetFileNameOnly); 2848 2849 // clone the disk: 2850 ComPtr<IHardDisk> pSourceDisk; 2851 ComPtr<IHardDisk> pTargetDisk; 2852 ComPtr<IProgress> pProgress2; 2853 2854 Log(("Finding source disk \"%ls\"\n", bstrSrcFilePath.raw())); 2855 rc = pVirtualBox->FindHardDisk(bstrSrcFilePath, pSourceDisk.asOutParam()); 2856 if (FAILED(rc)) throw rc; 2857 2858 /* We need the format description of the source disk image */ 2859 Bstr bstrSrcFormat; 2860 rc = pSourceDisk->COMGETTER(Format)(bstrSrcFormat.asOutParam()); 2861 if (FAILED(rc)) throw rc; 2862 /* Create a new hard disk interface for the destination disk image */ 2863 Log(("Creating target disk \"%s\"\n", strTargetFilePath.raw())); 2864 rc = pVirtualBox->CreateHardDisk(bstrSrcFormat, Bstr(strTargetFilePath), pTargetDisk.asOutParam()); 2865 if (FAILED(rc)) throw rc; 2866 /* Clone the source disk image */ 2867 rc = pSourceDisk->CloneTo(pTargetDisk, pProgress2.asOutParam()); 2868 if (FAILED(rc)) throw rc; 2869 2870 /* Advance to the next operation */ 2871 if (!task->progress.isNull()) 2872 task->progress->advanceOperation(BstrFmt(tr("Importing virtual disk image '%s'"), strSrcFilePath.c_str())); 2873 2874 // now loop until the asynchronous operation completes and then 2875 // report its result 2876 BOOL fCompleted; 2877 LONG currentPercent; 2878 while (SUCCEEDED(pProgress2->COMGETTER(Completed(&fCompleted)))) 2879 { 2880 rc = pProgress2->COMGETTER(Percent(¤tPercent)); 2881 if (FAILED(rc)) throw rc; 2882 if (!task->progress.isNull()) 2883 task->progress->notifyProgress(currentPercent); 2884 if (fCompleted) 2885 break; 2886 /* Make sure the loop is not too tight */ 2887 rc = pProgress2->WaitForCompletion(100); 2888 if (FAILED(rc)) throw rc; 2889 } 2890 // report result of asynchronous operation 2891 HRESULT vrc; 2892 rc = pProgress2->COMGETTER(ResultCode)(&vrc); 2893 if (FAILED(rc)) throw rc; 2894 2895 // if the thread of the progress object has an error, then 2896 // retrieve the error info from there, or it'll be lost 2897 if (FAILED(vrc)) 2898 { 2899 com::ErrorInfo info(pProgress2); 2900 const char *pcsz = Utf8Str(info.getText()).c_str(); 2901 HRESULT rc2 = setError(vrc, pcsz); 2902 throw rc2; 2903 } 2904 2905 // we need the capacity and actual file size for the XML 2906 uint64_t cbFile = 12345678; // @todo 2907 uint64_t cbCapacity = 2345678; // @todo 2908 2909 // now handle the XML for the disk: 2910 Utf8StrFmt strFileRef("file%RI32", ulFile++); 2911 // <File ovf:href="WindowsXpProfessional-disk1.vmdk" ovf:id="file1" ovf:size="1710381056"/> 2912 xml::ElementNode *pelmFile = pelmReferences->createChild("File"); 2913 pelmFile->setAttribute("ovf:href", strTargetFileNameOnly); 2914 pelmFile->setAttribute("ovf:id", strFileRef); 2915 pelmFile->setAttribute("ovf:size", Utf8StrFmt("%RI64", cbFile).c_str()); // @todo 2916 2917 // add disk to XML Disks section 2918 // <Disk ovf:capacity="8589934592" ovf:diskId="vmdisk1" ovf:fileRef="file1" ovf:format="http://www.vmware.com/specifications/vmdk.html#sparse"/> 2919 xml::ElementNode *pelmDisk = pelmDiskSection->createChild("Disk"); 2920 pelmDisk->setAttribute("ovf:capacity", Utf8StrFmt("%RI64", cbCapacity).c_str()); // @todo 2921 pelmDisk->setAttribute("ovf:diskId", strDiskID); 2922 pelmDisk->setAttribute("ovf:fileRef", strFileRef); 2923 pelmDisk->setAttribute("ovf:format", "http://www.vmware.com/specifications/vmdk.html#sparse"); 2812 2924 } 2813 2925 … … 3352 3464 } 3353 3465 3466 Utf8Str strTargetVmdkName(bstrName); 3467 RTPathStripExt(strTargetVmdkName.mutableRaw()); 3468 strTargetVmdkName.append(".vmdk"); 3469 3354 3470 pNewDesc->addEntry(VirtualSystemDescriptionType_HardDiskImage, 3355 Utf8Str(bstrName),// disk ID: let's use the name3356 "", // OVF value: unknown as of now3471 strTargetVmdkName, // disk ID: let's use the name 3472 strTargetVmdkName, // OVF value: 3357 3473 Utf8Str(bstrLocation), // vbox value: media path 3358 3474 Utf8StrFmt("controller=%RI32;channel=%RI32", lControllerVsys, lChannelVsys)); -
trunk/src/VBox/Main/include/ApplianceImpl.h
r17634 r17646 101 101 static DECLCALLBACK(int) taskThreadImportMachines(RTTHREAD thread, void *pvUser); 102 102 103 struct Task ExportOVF; /* Worker thread for export */104 static DECLCALLBACK(int) taskThread ExportOVF(RTTHREAD thread, void *pvUser);103 struct TaskWriteOVF; /* Worker thread for export */ 104 static DECLCALLBACK(int) taskThreadWriteOVF(RTTHREAD thread, void *pvUser); 105 105 106 106 friend class Machine;
Note:
See TracChangeset
for help on using the changeset viewer.