VirtualBox

Changeset 8471 in vbox for trunk/src/VBox/Main


Ignore:
Timestamp:
Apr 29, 2008 3:20:44 PM (17 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
30336
Message:

More USB stuff.

Location:
trunk/src/VBox/Main
Files:
3 edited

Legend:

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

    r8439 r8471  
    20112011            Guid (aId).raw());
    20122012
    2013 # ifdef RT_OS_DARWIN
    2014     /* Notify the USB Proxy that we're about to detach the device. Since
    2015      * we don't dare do IPC when holding the console lock, so we'll have
    2016      * to revalidate the device when we get back. */
     2013# if defined(RT_OS_DARWIN) || defined(NEW_HOSTUSBDEVICE_STATE)
     2014    /*
     2015     * Inform the USB device and USB proxy about what's cooking.
     2016     */
    20172017    alock.leave();
    20182018    HRESULT rc2 = mControl->DetachUSBDevice (aId, false /* aDone */);
     
    20202020        return rc2;
    20212021    alock.enter();
    2022 
     2022#  ifndef NEW_HOSTUSBDEVICE_STATE
    20232023    for (it = mUSBDevices.begin(); it != mUSBDevices.end(); ++ it)
    20242024        if ((*it)->id() == aId)
     
    20262026    if (it == mUSBDevices.end())
    20272027        return S_OK;
     2028#  endif
    20282029# endif
    20292030
    2030     /* First, request VMM to detach the device */
     2031    /* Request the PDM to detach the USB device. */
    20312032    HRESULT rc = detachUSBDevice (it);
    20322033
  • trunk/src/VBox/Main/HostImpl.cpp

    r8438 r8471  
    13491349    AutoWriteLock devLock (device);
    13501350
     1351#ifdef NEW_HOSTUSBDEVICE_STATE
     1352    /*
     1353     * Work the state machine.
     1354     */
     1355    LogFlowThisFunc(("id={%Vuuid} state=%s aDone=%RTbool name={%s}\n",
     1356                     device->id().raw(), device->stateName(), aDone, device->name().raw()));
     1357    bool fRunFilters = false;
     1358    HRESULT hrc = device->onDetachFromVM(aMachine, aDone, &fRunFilters);
     1359
     1360    /*
     1361     * Run filters if necessary.
     1362     */
     1363    if (    SUCCEEDED(hrc)
     1364        &&  fRunFilters)
     1365    {
     1366        Assert(aDone && device->unistate() == kHostUSBDeviceState_HeldByProxy && device->machine().isNull());
     1367        HRESULT hrc2 = applyAllUSBFilters(device, aMachine);
     1368        ComAssertComRC(hrc2);
     1369    }
     1370    return hrc;
     1371
     1372#else  /* !NEW_HOSTUSBDEVICE_STATE */
     1373
    13511374    LogFlowThisFunc (("id={%Vuuid} state=%d isStatePending=%RTbool pendingState=%d aDone=%RTbool\n",
    13521375                      device->id().raw(), device->state(), device->isStatePending(),
     
    13931416        }
    13941417    }
    1395 
    13961418    return rc;
     1419#endif /* !NEW_HOSTUSBDEVICE_STATE */
    13971420}
    13981421
     
    14231446    {
    14241447        ComObjPtr <HostUSBDevice> device = *it;
    1425 
    14261448        AutoWriteLock devLock (device);
     1449#ifdef NEW_HOSTUSBDEVICE_STATE
     1450        if (   device->unistate() == kHostUSBDeviceState_HeldByProxy
     1451            || device->unistate() == kHostUSBDeviceState_Unused
     1452            || device->unistate() == kHostUSBDeviceState_Capturable)
     1453            applyMachineUSBFilters(aMachine, device);
     1454#else /* !NEW_HOSTUSBDEVICE_STATE */
    14271455
    14281456        /* skip pending devices */
     
    14361464            applyMachineUSBFilters (aMachine, device);
    14371465        }
     1466#endif /* !NEW_HOSTUSBDEVICE_STATE */
    14381467    }
    14391468
     
    14661495        if (device->machine() == aMachine)
    14671496        {
     1497# ifdef NEW_HOSTUSBDEVICE_STATE
     1498            /*
     1499             * Same procedure as in detachUSBDevice().
     1500             */
     1501            bool fRunFilters = false;
     1502            HRESULT hrc = device->onDetachFromVM(aMachine, aDone, &fRunFilters);
     1503            if (    SUCCEEDED(hrc)
     1504                &&  fRunFilters)
     1505            {
     1506                Assert(aDone && device->unistate() == kHostUSBDeviceState_HeldByProxy && device->machine().isNull());
     1507                HRESULT hrc2 = applyAllUSBFilters(device, aMachine);
     1508                ComAssertComRC(hrc2);
     1509            }
     1510# else  /* !NEW_HOSTUSBDEVICE_STATE */
    14681511            if (!aDone)
    14691512            {
     
    14861529                    device->cancelPendingState();
    14871530            }
     1531# endif  /* !NEW_HOSTUSBDEVICE_STATE */
    14881532        }
    14891533        ++ it;
     
    19962040                                  SessionMachine *aMachine /* = NULL */)
    19972041{
    1998     LogFlowThisFunc (("\n"));
    1999 
     2042    LogFlowThisFunc(("{%s}\n", aDevice->name().raw()));
     2043
     2044    /*
     2045     * Verify preconditions.
     2046     */
    20002047    /// @todo must check for read lock, it's enough here
    2001     AssertReturn (isWriteLockOnCurrentThread(), E_FAIL);
    2002 
    2003     AssertReturn (aDevice->isWriteLockOnCurrentThread(), E_FAIL);
    2004 
    2005     AssertReturn (aDevice->state() != USBDeviceState_Captured, E_FAIL);
    2006 
    2007     AssertReturn (aDevice->isStatePending() == false, E_FAIL);
     2048    AssertReturn(isWriteLockOnCurrentThread(), E_FAIL);
     2049    AssertReturn(aDevice->isWriteLockOnCurrentThread(), E_FAIL);
     2050#ifdef NEW_HOSTUSBDEVICE_STATE
     2051    /* Quietly ignore unsupported and unavailable device. */
     2052    if (    aDevice->unistate() == kHostUSBDeviceState_UsedByHost
     2053        ||  aDevice->unistate() == kHostUSBDeviceState_Unsupported) /** @todo !aDevice->isCapturable() or something */
     2054    {
     2055        LogFlowThisFunc(("{%s} %s - quietly ignored\n", aDevice->name().raw(), aDevice->stateName()));
     2056        return S_OK;
     2057    }
     2058
     2059#else  /* !NEW_HOSTUSBDEVICE_STATE */
     2060    AssertReturn(aDevice->state() != USBDeviceState_Captured, E_FAIL);
     2061
     2062    AssertReturn(aDevice->isStatePending() == false, E_FAIL);
    20082063
    20092064    /* ignore unsupported devices */
     
    20132068    if (aDevice->state() == USBDeviceState_Unavailable)
    20142069        return S_OK;
     2070#endif /* !NEW_HOSTUSBDEVICE_STATE */
    20152071
    20162072    VirtualBox::SessionMachineVector machines;
     
    20922148                                   ComObjPtr <HostUSBDevice> &aDevice)
    20932149{
    2094     LogFlowThisFunc (("\n"));
    2095 
    2096     AssertReturn (aMachine, false);
    2097 
     2150    LogFlowThisFunc(("{%s}\n", aDevice->name().raw()));
     2151
     2152    /*
     2153     * Validate preconditions.
     2154     */
     2155    AssertReturn(aMachine, false);
    20982156    /// @todo must check for read lock, it's enough here
    2099     AssertReturn (isWriteLockOnCurrentThread(), false);
    2100 
    2101     AssertReturn (aDevice->isWriteLockOnCurrentThread(), false);
    2102 
     2157    AssertReturn(isWriteLockOnCurrentThread(), false);
     2158    AssertReturn(aDevice->isWriteLockOnCurrentThread(), false);
     2159#ifdef NEW_HOSTUSBDEVICE_STATE
     2160    /* Let HostUSBDevice::requestCaptureToVM() validate the state. */
     2161#else  /* !NEW_HOSTUSBDEVICE_STATE */
    21032162    AssertReturn (aDevice->state() != USBDeviceState_NotSupported, false);
    21042163    AssertReturn (aDevice->state() != USBDeviceState_Unavailable, false);
    2105 
    21062164    AssertReturn (aDevice->isStatePending() == false, false);
     2165#endif /* !NEW_HOSTUSBDEVICE_STATE */
    21072166
    21082167    ULONG maskedIfs;
    21092168    bool hasMatch = aMachine->hasMatchingUSBFilter (aDevice, &maskedIfs);
    2110 
    21112169    if (hasMatch)
    21122170    {
     
    21282186void Host::onUSBDeviceAttached (HostUSBDevice *aDevice)
    21292187{
    2130     LogFlowThisFunc (("aDevice=%p\n", aDevice));
    2131 
    2132     AssertReturnVoid (aDevice);
    2133 
    2134     AssertReturnVoid (isWriteLockOnCurrentThread());
    2135     AssertReturnVoid (aDevice->isWriteLockOnCurrentThread());
    2136 
    2137     LogFlowThisFunc (("id={%Vuuid} state=%d isStatePending=%RTbool pendingState=%d\n",
    2138                       aDevice->id().raw(), aDevice->state(), aDevice->isStatePending(),
     2188    /*
     2189     * Validate precoditions.
     2190     */
     2191    AssertReturnVoid(aDevice);
     2192    AssertReturnVoid(isWriteLockOnCurrentThread());
     2193    AssertReturnVoid(aDevice->isWriteLockOnCurrentThread());
     2194#ifdef NEW_HOSTUSBDEVICE_STATE
     2195    LogFlowThisFunc(("aDevice=%p name={%s} state=%s id={%RTuuid}\n",
     2196                     aDevice, aDevice->name().raw(), aDevice->stateName(), aDevice->id().raw()));
     2197#else
     2198    LogFlowThisFunc (("aDevice=%p id={%Vuuid} state=%d isStatePending=%RTbool pendingState=%d\n",
     2199                      aDevice, aDevice->id().raw(), aDevice->state(), aDevice->isStatePending(),
    21392200                      aDevice->pendingState()));
    2140 
    21412201    Assert (aDevice->isStatePending() == false);
     2202#endif
    21422203
    21432204    /* add to the collecion */
     
    21582219void Host::onUSBDeviceDetached (HostUSBDevice *aDevice)
    21592220{
    2160     LogFlowThisFunc (("aDevice=%p\n", aDevice));
    2161 
    2162     AssertReturnVoid (aDevice);
    2163 
    2164     AssertReturnVoid (isWriteLockOnCurrentThread());
    2165     AssertReturnVoid (aDevice->isWriteLockOnCurrentThread());
    2166 
    2167     LogFlowThisFunc (("id={%Vuuid} state=%d isStatePending=%RTbool pendingState=%d\n",
    2168                       aDevice->id().raw(), aDevice->state(), aDevice->isStatePending(),
     2221    /*
     2222     * Validate preconditions.
     2223     */
     2224    AssertReturnVoid(aDevice);
     2225    AssertReturnVoid(isWriteLockOnCurrentThread());
     2226    AssertReturnVoid(aDevice->isWriteLockOnCurrentThread());
     2227#ifdef NEW_HOSTUSBDEVICE_STATE
     2228    LogFlowThisFunc(("aDevice=%p name={%s} state=%s id={%RTuuid}\n",
     2229                     aDevice, aDevice->name().raw(), aDevice->stateName(), aDevice->id().raw()));
     2230#else
     2231    LogFlowThisFunc (("aDevice=%p id={%Vuuid} state=%d isStatePending=%RTbool pendingState=%d\n",
     2232                      aDevice, aDevice->id().raw(), aDevice->state(), aDevice->isStatePending(),
    21692233                      aDevice->pendingState()));
    2170 
     2234#endif
     2235
     2236    /*
     2237     * Remove from the list.
     2238     */
    21712239    Guid id = aDevice->id();
    21722240
     
    21982266 *  interaction.
    21992267 *
    2200  *  @param  aDevice     The device in question.
     2268 * @param   aDevice         The device in question.
     2269 * @param   aRunFilters     Whether to run filters.
     2270 * @param   aIgnoreMachine  The machine to ignore when running filters.
    22012271 */
     2272#ifdef NEW_HOSTUSBDEVICE_STATE
     2273void Host::onUSBDeviceStateChanged (HostUSBDevice *aDevice, bool aRunFilters, SessionMachine *aIgnoreMachine)
     2274#else
    22022275void Host::onUSBDeviceStateChanged (HostUSBDevice *aDevice)
    2203 {
    2204     LogFlowThisFunc (("aDevice=%p\n", aDevice));
    2205 
    2206     AssertReturnVoid (aDevice);
    2207 
    2208     AssertReturnVoid (isWriteLockOnCurrentThread());
    2209     AssertReturnVoid (aDevice->isWriteLockOnCurrentThread());
    2210 
    2211     LogFlowThisFunc (("id={%Vuuid} state=%d isStatePending=%RTbool pendingState=%d\n",
    2212                       aDevice->id().raw(), aDevice->state(), aDevice->isStatePending(),
     2276#endif
     2277{
     2278    /*
     2279     * Validate preconditions.
     2280     */
     2281    LogFlowThisFunc(("aDevice=%p\n", aDevice));
     2282    AssertReturnVoid(aDevice);
     2283    AssertReturnVoid(isWriteLockOnCurrentThread());
     2284    AssertReturnVoid(aDevice->isWriteLockOnCurrentThread());
     2285#ifdef NEW_HOSTUSBDEVICE_STATE
     2286    LogFlowThisFunc(("aDevice=%p name={%s} state=%s id={%RTuuid}\n",
     2287                     aDevice, aDevice->name().raw(), aDevice->stateName(), aDevice->id().raw()));
     2288#else
     2289    LogFlowThisFunc (("aDevice=%p id={%Vuuid} state=%d isStatePending=%RTbool pendingState=%d\n",
     2290                      aDevice, aDevice->id().raw(), aDevice->state(), aDevice->isStatePending(),
    22132291                      aDevice->pendingState()));
    2214 
    2215 
     2292#endif
     2293
     2294# ifdef NEW_HOSTUSBDEVICE_STATE
     2295    /*
     2296     * Run filters if requested to do so.
     2297     */
     2298    if (aRunFilters)
     2299    {
     2300        ComObjPtr<HostUSBDevice> device(aDevice);
     2301        HRESULT rc = applyAllUSBFilters(device, aIgnoreMachine);
     2302        AssertComRC(rc);
     2303    }
     2304# else  /* !NEW_HOSTUSBDEVICE_STATE */
    22162305    ComObjPtr <HostUSBDevice> device (aDevice);
    22172306    if (device->isStatePending())
     
    22572346        AssertFailed();
    22582347    }
     2348# endif /* !NEW_HOSTUSBDEVICE_STATE */
    22592349}
    22602350#endif /* VBOX_WITH_USB */
  • trunk/src/VBox/Main/include/HostImpl.h

    r8401 r8471  
    121121    void onUSBDeviceAttached (HostUSBDevice *aDevice);
    122122    void onUSBDeviceDetached (HostUSBDevice *aDevice);
    123     void onUSBDeviceStateChanged (HostUSBDevice *aDevice);
     123#ifdef NEW_HOSTUSBDEVICE_STATE
     124    void onUSBDeviceStateChanged(HostUSBDevice *aDevice, bool aRunFilters, SessionMachine *aIgnoreMachine);
     125#else
     126    void onUSBDeviceStateChanged(HostUSBDevice *aDevice);
     127#endif
    124128
    125129    /* must be called from under this object's lock */
     
    183187#ifdef VBOX_WITH_USB
    184188    typedef std::list <ComObjPtr <HostUSBDevice> > USBDeviceList;
    185     USBDeviceList mUSBDevices;
     189    USBDeviceList mUSBDevices; /**< @todo remove this, use the one maintained by USBProxyService. */
    186190
    187191    typedef std::list <ComObjPtr <HostUSBDeviceFilter> > USBDeviceFilterList;
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