VirtualBox

Changeset 16944 in vbox


Ignore:
Timestamp:
Feb 19, 2009 12:46:11 PM (16 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
43100
Message:

OVF: nuke CHECK_ERROR_THROW macro again, go back to throwing HRESULT

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/VBox/com/assert.h

    r16931 r16944  
    137137    if (!SUCCEEDED (rc)) { throw rc; } else do {} while (0)
    138138
    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  
    17281728            /* Now that we know the base system get our internal defaults based on that. */
    17291729            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;
    17311732
    17321733            /* Create the machine */
     
    17371738                               tr("Missing VM name"));
    17381739            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;
    17421744
    17431745            if (!task->progress.isNull())
     
    17521754            const Utf8Str &memoryVBox = vsdeRAM.front()->strConfig;
    17531755            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;
    17551758
    17561759            /* VRAM */
    17571760            /* Get the recommended VRAM for this guest OS type */
    17581761            ULONG vramVBox;
    1759             CHECK_ERROR_THROW(osType, COMGETTER(RecommendedVRAM)(&vramVBox));
     1762            rc = osType->COMGETTER(RecommendedVRAM)(&vramVBox);
     1763            if (rc) throw rc;
    17601764
    17611765            /* Set the VRAM */
    1762             CHECK_ERROR_THROW(pNewMachine, COMSETTER(VRAMSize)(vramVBox));
     1766            rc = pNewMachine->COMSETTER(VRAMSize)(vramVBox);
     1767            if (rc) throw rc;
    17631768
    17641769            if (!task->progress.isNull())
     
    17751780                    uint32_t audio = RTStrToUInt32(audioAdapterVBox.c_str());
    17761781                    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;
    17801788                }
    17811789            }
     
    17881796
    17891797            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;
    17921802
    17931803            if (!task->progress.isNull())
     
    18001810                /* No network adapters, so we have to disable our default one */
    18011811                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;
    18041816            }
    18051817            else
     
    18161828                    uint32_t tt1 = RTStrToUInt32(nwTypeVBox.c_str());
    18171829                    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;
    18191832                    /* Enable the network card & set the adapter type */
    18201833                    /* 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;
    18231838                }
    18241839            }
     
    18301845            bool fFloppyEnabled = vsdeFloppy.size() > 0;
    18311846            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;
    18341851
    18351852            if (!task->progress.isNull())
     
    18471864                /* Set the appropriate IDE controller in the virtual BIOS of the VM */
    18481865                ComPtr<IBIOSSettings> biosSettings;
    1849                 CHECK_ERROR_THROW(pNewMachine, COMGETTER(BIOSSettings)(biosSettings.asOutParam()));
     1866                rc = pNewMachine->COMGETTER(BIOSSettings)(biosSettings.asOutParam());
     1867                if (rc) throw rc;
    18501868
    18511869                const char *pcszIDEType = vsdeHDCIDE.front()->strConfig.c_str();
    18521870                if (!strcmp(pcszIDEType, "PIIX3"))
    1853                     CHECK_ERROR_THROW(biosSettings, COMSETTER(IDEControllerType)(IDEControllerType_PIIX3));
     1871                    rc = biosSettings->COMSETTER(IDEControllerType)(IDEControllerType_PIIX3);
    18541872                else if (!strcmp(pcszIDEType, "PIIX4"))
    1855                     CHECK_ERROR_THROW(biosSettings, COMSETTER(IDEControllerType)(IDEControllerType_PIIX4));
     1873                    rc = biosSettings->COMSETTER(IDEControllerType)(IDEControllerType_PIIX4);
    18561874                else
    18571875                    throw setError(VBOX_E_FILE_ERROR,
    18581876                                   tr("Invalid IDE controller type \"%s\""),
    18591877                                   pcszIDEType);
     1878                if (rc) throw rc;
    18601879            }
    18611880#ifdef VBOX_WITH_AHCI
     
    18701889                    /* For now we have just to enable the AHCI controller. */
    18711890                    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;
    18741895                }
    18751896                else
     
    18911912
    18921913            /* 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;
    18941916
    18951917            Guid newMachineId;
    1896             CHECK_ERROR_THROW(pNewMachine, COMGETTER(Id)(newMachineId.asOutParam()));
     1918            rc = pNewMachine->COMGETTER(Id)(newMachineId.asOutParam());
     1919            if (rc) throw rc;
    18971920
    18981921            if (!task->progress.isNull())
     
    19151938                    /* In order to attach hard disks we need to open a session
    19161939                     * for the new machine */
    1917                     CHECK_ERROR_THROW(pVirtualBox, OpenSession(session, newMachineId));
     1940                    rc = pVirtualBox->OpenSession(session, newMachineId);
     1941                    if (rc) throw rc;
    19181942                    fSessionOpen = true;
    19191943
     
    19741998                                srcFormat = L"VMDK";
    19751999                            /* 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;
    19772002
    19782003                            /* Create a dynamic growing disk image with the given capacity */
    19792004                            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;
    19812007
    19822008                            /* Advance to the next operation */
     
    20002026
    20012027                            /* 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;
    20032030                            fSourceHdNeedsClosing = true;
    20042031
    20052032                            /* We need the format description of the source disk image */
    20062033                            Bstr srcFormat;
    2007                             CHECK_ERROR_THROW(srcHdVBox, COMGETTER(Format)(srcFormat.asOutParam()));
     2034                            rc = srcHdVBox->COMGETTER(Format)(srcFormat.asOutParam());
     2035                            if (rc) throw rc;
    20082036                            /* 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;
    20102039                            /* 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;
    20122042
    20132043                            /* Advance to the next operation */
     
    20222052                        while (SUCCEEDED(progress->COMGETTER(Completed(&fCompleted))))
    20232053                        {
    2024                                 CHECK_ERROR_THROW(progress, COMGETTER(Percent(&currentPercent)));
    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(&currentPercent));
     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;
    20312063                        }
    20322064                        // report result of asynchronous operation
    20332065                        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
    20382071                        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                        }
    20402079
    20412080                        if (fSourceHdNeedsClosing)
    20422081                        {
    2043                             CHECK_ERROR_THROW(srcHdVBox, Close());
     2082                            rc = srcHdVBox->Close();
     2083                            if (rc) throw rc;
    20442084                            fSourceHdNeedsClosing = false;
    20452085                        }
     
    20492089                        /* Now use the new uuid to attach the disk image to our new machine */
    20502090                        ComPtr<IMachine> sMachine;
    2051                         CHECK_ERROR_THROW(session, COMGETTER(Machine)(sMachine.asOutParam()));
     2091                        rc = session->COMGETTER(Machine)(sMachine.asOutParam());
     2092                        if (rc) throw rc;
    20522093                        Guid hdId;
    2053                         CHECK_ERROR_THROW(dstHdVBox, COMGETTER(Id)(hdId.asOutParam()));
     2094                        rc = dstHdVBox->COMGETTER(Id)(hdId.asOutParam());
     2095                        if (rc) throw rc;
    20542096
    20552097                        /* For now we assume we have one controller of every type only */
     
    20722114                        }
    20732115
    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;
    20782121
    20792122                        llHardDiskAttachments.push_back(mhda);
    20802123
    2081                         CHECK_ERROR_THROW(sMachine, SaveSettings());
     2124                        rc = sMachine->SaveSettings();
     2125                        if (rc) throw rc;
    20822126                    } // end for (itHD = avsdeHDs.begin();
    20832127
    20842128                    // 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;
    20862131                    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;
    20972132                }
    20982133                catch(HRESULT aRC)
     
    21072142                }
    21082143            }
    2109         }
    2110         catch(com::ErrorInfo(&info))
    2111         {
    2112             // so we've had a COM error info somewhere (either on this task
    2113             // thread or from another subthread such as CloneHD): now copy
    2114             // what we have here to the IAppliance object, so our client
    2115             // gets proper error information
    2116             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*/);
    21222144        }
    21232145        catch(HRESULT aRC)
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette