VirtualBox

Ignore:
Timestamp:
Mar 9, 2009 9:34:22 AM (16 years ago)
Author:
vboxsync
Message:

#3551: “Main: Replace remaining collections with safe arrays”
Replaced IUSBDeviceCollection. Reviewed by Christian.

File:
1 edited

Legend:

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

    r17360 r17553  
    12651265}
    12661266
    1267 STDMETHODIMP Console::COMGETTER(USBDevices) (IUSBDeviceCollection **aUSBDevices)
    1268 {
    1269     CheckComArgOutPointerValid(aUSBDevices);
     1267STDMETHODIMP Console::COMGETTER(USBDevices) (ComSafeArrayOut (IUSBDevice *, aUSBDevices))
     1268{
     1269    CheckComArgOutSafeArrayPointerValid(aUSBDevices);
    12701270
    12711271    AutoCaller autoCaller (this);
     
    12741274    AutoReadLock alock (this);
    12751275
    1276     ComObjPtr <OUSBDeviceCollection> collection;
    1277     collection.createObject();
    1278     collection->init (mUSBDevices);
    1279     collection.queryInterfaceTo (aUSBDevices);
     1276    SafeIfaceArray <IUSBDevice> collection (mUSBDevices);
     1277    collection.detachTo (ComSafeArrayOutArg(aUSBDevices));
    12801278
    12811279    return S_OK;
     
    13331331}
    13341332
     1333
    13351334// IConsole methods
    13361335/////////////////////////////////////////////////////////////////////////////
     1336
    13371337
    13381338STDMETHODIMP Console::PowerUp (IProgress **aProgress)
     
    20732073    return setError (VBOX_E_PDM_ERROR,
    20742074        tr ("The virtual machine does not have a USB controller"));
     2075#endif  /* !VBOX_WITH_USB */
     2076}
     2077
     2078STDMETHODIMP Console::FindUSBDeviceByAddress(IN_BSTR aAddress, IUSBDevice **aDevice)
     2079{
     2080#ifdef VBOX_WITH_USB
     2081    CheckComArgNotNull(aAddress);
     2082    CheckComArgOutPointerValid(aDevice);
     2083
     2084    *aDevice = NULL;
     2085
     2086    SafeIfaceArray <IUSBDevice> devsvec;
     2087    HRESULT rc = COMGETTER(USBDevices) (ComSafeArrayAsOutParam(devsvec));
     2088    CheckComRCReturnRC (rc);
     2089
     2090    for (size_t i = 0; i < devsvec.size(); ++i)
     2091    {
     2092        Bstr address;
     2093        rc = devsvec[i]->COMGETTER(Address) (address.asOutParam());
     2094        CheckComRCReturnRC (rc);
     2095        if (address == aAddress)
     2096        {
     2097            ComObjPtr<OUSBDevice> found;
     2098            found.createObject();
     2099            found->init (devsvec[i]);
     2100            return found.queryInterfaceTo (aDevice);
     2101        }
     2102    }
     2103
     2104    return setErrorNoLog (VBOX_E_OBJECT_NOT_FOUND, tr (
     2105        "Could not find a USB device with address '%ls'"),
     2106        aAddress);
     2107
     2108#else   /* !VBOX_WITH_USB */
     2109    return E_NOTIMPL;
     2110#endif  /* !VBOX_WITH_USB */
     2111}
     2112
     2113STDMETHODIMP Console::FindUSBDeviceById(IN_GUID aId, IUSBDevice **aDevice)
     2114{
     2115#ifdef VBOX_WITH_USB
     2116    CheckComArgExpr(aId, Guid (aId).isEmpty() == false);
     2117    CheckComArgOutPointerValid(aDevice);
     2118
     2119    *aDevice = NULL;
     2120
     2121    SafeIfaceArray <IUSBDevice> devsvec;
     2122    HRESULT rc = COMGETTER(USBDevices) (ComSafeArrayAsOutParam(devsvec));
     2123    CheckComRCReturnRC (rc);
     2124
     2125    for (size_t i = 0; i < devsvec.size(); ++i)
     2126    {
     2127        Guid id;
     2128        rc = devsvec[i]->COMGETTER(Id) (id.asOutParam());
     2129        CheckComRCReturnRC (rc);
     2130        if (id == aId)
     2131        {
     2132            ComObjPtr<OUSBDevice> found;
     2133            found.createObject();
     2134            found->init(devsvec[i]);
     2135            return found.queryInterfaceTo (aDevice);
     2136        }
     2137    }
     2138
     2139    return setErrorNoLog (VBOX_E_OBJECT_NOT_FOUND, tr (
     2140        "Could not find a USB device with uuid {%RTuuid}"),
     2141        Guid (aId).raw());
     2142
     2143#else   /* !VBOX_WITH_USB */
     2144    return E_NOTIMPL;
    20752145#endif  /* !VBOX_WITH_USB */
    20762146}
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