Changeset 16944 in vbox
- Timestamp:
- Feb 19, 2009 12:46:11 PM (16 years ago)
- svn:sync-xref-src-repo-rev:
- 43100
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/VBox/com/assert.h
r16931 r16944 137 137 if (!SUCCEEDED (rc)) { throw rc; } else do {} while (0) 138 138 139 /** 140 * Does the same as CHECK_ERROR(), but throws a com::ErrorInfo on failure. 141 */ 142 #define CHECK_ERROR_THROW(iface, method) \ 143 do { \ 144 rc = iface->method; \ 145 if (FAILED(rc)) \ 146 throw com::ErrorInfo(iface); \ 147 } while (0) 148 #endif 149 139 #endif // ___VBox_com_assert_h -
trunk/src/VBox/Main/ApplianceImpl.cpp
r16932 r16944 1728 1728 /* Now that we know the base system get our internal defaults based on that. */ 1729 1729 ComPtr<IGuestOSType> osType; 1730 CHECK_ERROR_THROW(pVirtualBox, GetGuestOSType(Bstr(strOsTypeVBox), osType.asOutParam())); 1730 rc = pVirtualBox->GetGuestOSType(Bstr(strOsTypeVBox), osType.asOutParam()); 1731 if (rc) throw rc; 1731 1732 1732 1733 /* Create the machine */ … … 1737 1738 tr("Missing VM name")); 1738 1739 const Utf8Str &strNameVBox = vsdeName.front()->strConfig; 1739 CHECK_ERROR_THROW(pVirtualBox, CreateMachine(Bstr(strNameVBox), Bstr(strOsTypeVBox), 1740 Bstr(), Guid(), 1741 pNewMachine.asOutParam())); 1740 rc = pVirtualBox->CreateMachine(Bstr(strNameVBox), Bstr(strOsTypeVBox), 1741 Bstr(), Guid(), 1742 pNewMachine.asOutParam()); 1743 if (rc) throw rc; 1742 1744 1743 1745 if (!task->progress.isNull()) … … 1752 1754 const Utf8Str &memoryVBox = vsdeRAM.front()->strConfig; 1753 1755 ULONG tt = (ULONG)RTStrToUInt64(memoryVBox.c_str()); 1754 CHECK_ERROR_THROW(pNewMachine, COMSETTER(MemorySize)(tt)); 1756 rc = pNewMachine->COMSETTER(MemorySize)(tt); 1757 if (rc) throw rc; 1755 1758 1756 1759 /* VRAM */ 1757 1760 /* Get the recommended VRAM for this guest OS type */ 1758 1761 ULONG vramVBox; 1759 CHECK_ERROR_THROW(osType, COMGETTER(RecommendedVRAM)(&vramVBox)); 1762 rc = osType->COMGETTER(RecommendedVRAM)(&vramVBox); 1763 if (rc) throw rc; 1760 1764 1761 1765 /* Set the VRAM */ 1762 CHECK_ERROR_THROW(pNewMachine, COMSETTER(VRAMSize)(vramVBox)); 1766 rc = pNewMachine->COMSETTER(VRAMSize)(vramVBox); 1767 if (rc) throw rc; 1763 1768 1764 1769 if (!task->progress.isNull()) … … 1775 1780 uint32_t audio = RTStrToUInt32(audioAdapterVBox.c_str()); 1776 1781 ComPtr<IAudioAdapter> audioAdapter; 1777 CHECK_ERROR_THROW(pNewMachine, COMGETTER(AudioAdapter)(audioAdapter.asOutParam())); 1778 CHECK_ERROR_THROW(audioAdapter, COMSETTER(Enabled)(true)); 1779 CHECK_ERROR_THROW(audioAdapter, COMSETTER(AudioController)(static_cast<AudioControllerType_T>(audio))); 1782 rc = pNewMachine->COMGETTER(AudioAdapter)(audioAdapter.asOutParam()); 1783 if (rc) throw rc; 1784 rc = audioAdapter->COMSETTER(Enabled)(true); 1785 if (rc) throw rc; 1786 rc = audioAdapter->COMSETTER(AudioController)(static_cast<AudioControllerType_T>(audio)); 1787 if (rc) throw rc; 1780 1788 } 1781 1789 } … … 1788 1796 1789 1797 ComPtr<IUSBController> usbController; 1790 CHECK_ERROR_THROW(pNewMachine, COMGETTER(USBController)(usbController.asOutParam())); 1791 CHECK_ERROR_THROW(usbController, COMSETTER(Enabled)(fUSBEnabled)); 1798 rc = pNewMachine->COMGETTER(USBController)(usbController.asOutParam()); 1799 if (rc) throw rc; 1800 rc = usbController->COMSETTER(Enabled)(fUSBEnabled); 1801 if (rc) throw rc; 1792 1802 1793 1803 if (!task->progress.isNull()) … … 1800 1810 /* No network adapters, so we have to disable our default one */ 1801 1811 ComPtr<INetworkAdapter> nwVBox; 1802 CHECK_ERROR_THROW(pNewMachine, GetNetworkAdapter(0, nwVBox.asOutParam())); 1803 CHECK_ERROR_THROW(nwVBox, COMSETTER(Enabled)(false)); 1812 rc = pNewMachine->GetNetworkAdapter(0, nwVBox.asOutParam()); 1813 if (rc) throw rc; 1814 rc = nwVBox->COMSETTER(Enabled)(false); 1815 if (rc) throw rc; 1804 1816 } 1805 1817 else … … 1816 1828 uint32_t tt1 = RTStrToUInt32(nwTypeVBox.c_str()); 1817 1829 ComPtr<INetworkAdapter> nwVBox; 1818 CHECK_ERROR_THROW(pNewMachine, GetNetworkAdapter((ULONG)a, nwVBox.asOutParam())); 1830 rc = pNewMachine->GetNetworkAdapter((ULONG)a, nwVBox.asOutParam()); 1831 if (rc) throw rc; 1819 1832 /* Enable the network card & set the adapter type */ 1820 1833 /* NAT is set as default */ 1821 CHECK_ERROR_THROW(nwVBox, COMSETTER(Enabled)(true)); 1822 CHECK_ERROR_THROW(nwVBox, COMSETTER(AdapterType)(static_cast<NetworkAdapterType_T>(tt1))); 1834 rc = nwVBox->COMSETTER(Enabled)(true); 1835 if (rc) throw rc; 1836 rc = nwVBox->COMSETTER(AdapterType)(static_cast<NetworkAdapterType_T>(tt1)); 1837 if (rc) throw rc; 1823 1838 } 1824 1839 } … … 1830 1845 bool fFloppyEnabled = vsdeFloppy.size() > 0; 1831 1846 ComPtr<IFloppyDrive> floppyDrive; 1832 CHECK_ERROR_THROW(pNewMachine, COMGETTER(FloppyDrive)(floppyDrive.asOutParam())); 1833 CHECK_ERROR_THROW(floppyDrive, COMSETTER(Enabled)(fFloppyEnabled)); 1847 rc = pNewMachine->COMGETTER(FloppyDrive)(floppyDrive.asOutParam()); 1848 if (rc) throw rc; 1849 rc = floppyDrive->COMSETTER(Enabled)(fFloppyEnabled); 1850 if (rc) throw rc; 1834 1851 1835 1852 if (!task->progress.isNull()) … … 1847 1864 /* Set the appropriate IDE controller in the virtual BIOS of the VM */ 1848 1865 ComPtr<IBIOSSettings> biosSettings; 1849 CHECK_ERROR_THROW(pNewMachine, COMGETTER(BIOSSettings)(biosSettings.asOutParam())); 1866 rc = pNewMachine->COMGETTER(BIOSSettings)(biosSettings.asOutParam()); 1867 if (rc) throw rc; 1850 1868 1851 1869 const char *pcszIDEType = vsdeHDCIDE.front()->strConfig.c_str(); 1852 1870 if (!strcmp(pcszIDEType, "PIIX3")) 1853 CHECK_ERROR_THROW(biosSettings, COMSETTER(IDEControllerType)(IDEControllerType_PIIX3));1871 rc = biosSettings->COMSETTER(IDEControllerType)(IDEControllerType_PIIX3); 1854 1872 else if (!strcmp(pcszIDEType, "PIIX4")) 1855 CHECK_ERROR_THROW(biosSettings, COMSETTER(IDEControllerType)(IDEControllerType_PIIX4));1873 rc = biosSettings->COMSETTER(IDEControllerType)(IDEControllerType_PIIX4); 1856 1874 else 1857 1875 throw setError(VBOX_E_FILE_ERROR, 1858 1876 tr("Invalid IDE controller type \"%s\""), 1859 1877 pcszIDEType); 1878 if (rc) throw rc; 1860 1879 } 1861 1880 #ifdef VBOX_WITH_AHCI … … 1870 1889 /* For now we have just to enable the AHCI controller. */ 1871 1890 ComPtr<ISATAController> hdcSATAVBox; 1872 CHECK_ERROR_THROW(pNewMachine, COMGETTER(SATAController)(hdcSATAVBox.asOutParam())); 1873 CHECK_ERROR_THROW(hdcSATAVBox, COMSETTER(Enabled)(true)); 1891 rc = pNewMachine->COMGETTER(SATAController)(hdcSATAVBox.asOutParam()); 1892 if (rc) throw rc; 1893 rc = hdcSATAVBox->COMSETTER(Enabled)(true); 1894 if (rc) throw rc; 1874 1895 } 1875 1896 else … … 1891 1912 1892 1913 /* Now its time to register the machine before we add any hard disks */ 1893 CHECK_ERROR_THROW(pVirtualBox, RegisterMachine(pNewMachine)); 1914 rc = pVirtualBox->RegisterMachine(pNewMachine); 1915 if (rc) throw rc; 1894 1916 1895 1917 Guid newMachineId; 1896 CHECK_ERROR_THROW(pNewMachine, COMGETTER(Id)(newMachineId.asOutParam())); 1918 rc = pNewMachine->COMGETTER(Id)(newMachineId.asOutParam()); 1919 if (rc) throw rc; 1897 1920 1898 1921 if (!task->progress.isNull()) … … 1915 1938 /* In order to attach hard disks we need to open a session 1916 1939 * for the new machine */ 1917 CHECK_ERROR_THROW(pVirtualBox, OpenSession(session, newMachineId)); 1940 rc = pVirtualBox->OpenSession(session, newMachineId); 1941 if (rc) throw rc; 1918 1942 fSessionOpen = true; 1919 1943 … … 1974 1998 srcFormat = L"VMDK"; 1975 1999 /* Create an empty hard disk */ 1976 CHECK_ERROR_THROW(pVirtualBox, CreateHardDisk(srcFormat, Bstr(pcszDstFilePath), dstHdVBox.asOutParam())); 2000 rc = pVirtualBox->CreateHardDisk(srcFormat, Bstr(pcszDstFilePath), dstHdVBox.asOutParam()); 2001 if (rc) throw rc; 1977 2002 1978 2003 /* Create a dynamic growing disk image with the given capacity */ 1979 2004 ComPtr<IProgress> progress; 1980 CHECK_ERROR_THROW(dstHdVBox, CreateDynamicStorage(di.iCapacity / _1M, progress.asOutParam())); 2005 rc = dstHdVBox->CreateDynamicStorage(di.iCapacity / _1M, progress.asOutParam()); 2006 if (rc) throw rc; 1981 2007 1982 2008 /* Advance to the next operation */ … … 2000 2026 2001 2027 /* First open the existing disk image */ 2002 CHECK_ERROR_THROW(pVirtualBox, OpenHardDisk(Bstr(strSrcFilePath), srcHdVBox.asOutParam())); 2028 rc = pVirtualBox->OpenHardDisk(Bstr(strSrcFilePath), srcHdVBox.asOutParam()); 2029 if (rc) throw rc; 2003 2030 fSourceHdNeedsClosing = true; 2004 2031 2005 2032 /* We need the format description of the source disk image */ 2006 2033 Bstr srcFormat; 2007 CHECK_ERROR_THROW(srcHdVBox, COMGETTER(Format)(srcFormat.asOutParam())); 2034 rc = srcHdVBox->COMGETTER(Format)(srcFormat.asOutParam()); 2035 if (rc) throw rc; 2008 2036 /* Create a new hard disk interface for the destination disk image */ 2009 CHECK_ERROR_THROW(pVirtualBox, CreateHardDisk(srcFormat, Bstr(pcszDstFilePath), dstHdVBox.asOutParam())); 2037 rc = pVirtualBox->CreateHardDisk(srcFormat, Bstr(pcszDstFilePath), dstHdVBox.asOutParam()); 2038 if (rc) throw rc; 2010 2039 /* Clone the source disk image */ 2011 CHECK_ERROR_THROW(srcHdVBox, CloneTo(dstHdVBox, progress.asOutParam())); 2040 rc = srcHdVBox->CloneTo(dstHdVBox, progress.asOutParam()); 2041 if (rc) throw rc; 2012 2042 2013 2043 /* Advance to the next operation */ … … 2022 2052 while (SUCCEEDED(progress->COMGETTER(Completed(&fCompleted)))) 2023 2053 { 2024 CHECK_ERROR_THROW(progress, COMGETTER(Percent(¤tPercent))); 2025 if (!task->progress.isNull()) 2026 task->progress->notifyProgress(currentPercent); 2027 if (fCompleted) 2028 break; 2029 /* Make sure the loop is not too tight */ 2030 CHECK_ERROR_THROW(progress, WaitForCompletion(100)); 2054 rc = progress->COMGETTER(Percent(¤tPercent)); 2055 if (rc) throw rc; 2056 if (!task->progress.isNull()) 2057 task->progress->notifyProgress(currentPercent); 2058 if (fCompleted) 2059 break; 2060 /* Make sure the loop is not too tight */ 2061 rc = progress->WaitForCompletion(100); 2062 if (rc) throw rc; 2031 2063 } 2032 2064 // report result of asynchronous operation 2033 2065 HRESULT vrc; 2034 CHECK_ERROR_THROW(progress, COMGETTER(ResultCode)(&vrc)); 2035 2036 // if the progress object has an error, then retrieve the error info 2037 // from there, or it'll be lost 2066 rc = progress->COMGETTER(ResultCode)(&vrc); 2067 if (rc) throw rc; 2068 2069 // if the thread of the progress object has an error, then 2070 // retrieve the error info from there, or it'll be lost 2038 2071 if (FAILED(vrc)) 2039 throw com::ErrorInfo(progress); 2072 { 2073 com::ErrorInfo info(progress); 2074 const char *pcsz = Utf8Str(info.getText()).c_str(); 2075 HRESULT rc2 = setError(vrc, 2076 pcsz); 2077 throw rc2; 2078 } 2040 2079 2041 2080 if (fSourceHdNeedsClosing) 2042 2081 { 2043 CHECK_ERROR_THROW(srcHdVBox, Close()); 2082 rc = srcHdVBox->Close(); 2083 if (rc) throw rc; 2044 2084 fSourceHdNeedsClosing = false; 2045 2085 } … … 2049 2089 /* Now use the new uuid to attach the disk image to our new machine */ 2050 2090 ComPtr<IMachine> sMachine; 2051 CHECK_ERROR_THROW(session, COMGETTER(Machine)(sMachine.asOutParam())); 2091 rc = session->COMGETTER(Machine)(sMachine.asOutParam()); 2092 if (rc) throw rc; 2052 2093 Guid hdId; 2053 CHECK_ERROR_THROW(dstHdVBox, COMGETTER(Id)(hdId.asOutParam())); 2094 rc = dstHdVBox->COMGETTER(Id)(hdId.asOutParam()); 2095 if (rc) throw rc; 2054 2096 2055 2097 /* For now we assume we have one controller of every type only */ … … 2072 2114 } 2073 2115 2074 CHECK_ERROR_THROW(sMachine, AttachHardDisk(hdId, 2075 mhda.busType, 2076 mhda.lChannel, 2077 mhda.lDevice)); 2116 rc = sMachine->AttachHardDisk(hdId, 2117 mhda.busType, 2118 mhda.lChannel, 2119 mhda.lDevice); 2120 if (rc) throw rc; 2078 2121 2079 2122 llHardDiskAttachments.push_back(mhda); 2080 2123 2081 CHECK_ERROR_THROW(sMachine, SaveSettings()); 2124 rc = sMachine->SaveSettings(); 2125 if (rc) throw rc; 2082 2126 } // end for (itHD = avsdeHDs.begin(); 2083 2127 2084 2128 // only now that we're done with all disks, close the session 2085 CHECK_ERROR_THROW(session, Close()); 2129 rc = session->Close(); 2130 if (rc) throw rc; 2086 2131 fSessionOpen = false; 2087 }2088 catch(com::ErrorInfo(&info))2089 {2090 if (fSourceHdNeedsClosing)2091 srcHdVBox->Close();2092 2093 if (fSessionOpen)2094 session->Close();2095 2096 throw;2097 2132 } 2098 2133 catch(HRESULT aRC) … … 2107 2142 } 2108 2143 } 2109 }2110 catch(com::ErrorInfo(&info))2111 {2112 // so we've had a COM error info somewhere (either on this task2113 // thread or from another subthread such as CloneHD): now copy2114 // what we have here to the IAppliance object, so our client2115 // gets proper error information2116 app->setError(rc = info.getResultCode(), // return this rc;2117 info.getInterfaceID(),2118 Utf8Str(info.getComponent()).c_str() /*aComponent*/,2119 Utf8Str(info.getText()).c_str() /*aText*/,2120 false /* aWarning */,2121 true /*aLogIt*/);2122 2144 } 2123 2145 catch(HRESULT aRC)
Note:
See TracChangeset
for help on using the changeset viewer.