VirtualBox

Changeset 8666 in vbox for trunk


Ignore:
Timestamp:
May 7, 2008 3:24:57 PM (17 years ago)
Author:
vboxsync
Message:

Removed the duplicate USB device list in Host and moved 4 methods over to USBProxyService.

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

Legend:

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

    r8566 r8666  
    187187#ifdef VBOX_WITH_USB
    188188    mUSBDeviceFilters.clear();
    189     mUSBDevices.clear();
    190189#endif
    191190
     
    589588    CheckComRCReturnRC (rc);
    590589
    591     ComObjPtr <HostUSBDeviceCollection> collection;
    592     collection.createObject();
    593     collection->init (mUSBDevices);
    594     collection.queryInterfaceTo (aUSBDevices);
    595 
    596     return rc;
     590    return mUSBProxyService->getDeviceCollection (aUSBDevices);
     591
    597592#else
    598593    /* Note: The GUI depends on this method returning E_NOTIMPL with no
     
    12201215
    12211216#ifdef VBOX_WITH_USB
    1222 
    12231217/**
    12241218 *  Called by setter methods of all USB device filters.
     
    12651259    return S_OK;
    12661260}
    1267 
    1268 
    1269 /**
    1270  *  Requests the USB proxy service to capture the given host USB device.
    1271  *
    1272  *  When the request is completed,
    1273  *  IInternalSessionControl::onUSBDeviceAttach() will be called on the given
    1274  *  machine object.
    1275  *
    1276  *  Called by Console from the VM process (throug IInternalMachineControl).
    1277  *  Must return extended error info in case of errors.
    1278  */
    1279 HRESULT Host::captureUSBDevice (SessionMachine *aMachine, INPTR GUIDPARAM aId)
    1280 {
    1281     ComAssertRet (aMachine, E_INVALIDARG);
    1282 
    1283     AutoWriteLock alock (this);
    1284     CHECK_READY();
    1285 
    1286     /*
    1287      * Translate the device id into a device object.
    1288      */
    1289     Guid id (aId);
    1290     ComObjPtr <HostUSBDevice> device;
    1291     USBDeviceList::iterator it = mUSBDevices.begin();
    1292     while (!device && it != mUSBDevices.end())
    1293     {
    1294         if ((*it)->id() == id)
    1295             device = (*it);
    1296         ++ it;
    1297     }
    1298     if (!device)
    1299         return setError (E_INVALIDARG,
    1300             tr ("USB device with UUID {%Vuuid} is not currently attached to the host"),
    1301             id.raw());
    1302 
    1303     /*
    1304      * Try to capture the device
    1305      */
    1306     AutoWriteLock devLock (device);
    1307     device->requestCaptureForVM (aMachine, true /* aSetError */);
    1308 
    1309     return S_OK;
    1310 }
    1311 
    1312 /**
    1313  *  Notification from the VM process that it is going to detach (\a aDone = false)
    1314  *  or that is has just detach (\a aDone = true) the given USB device.
    1315  *
    1316  *  When \a aDone = false we only inform the USB Proxy about what the vm is
    1317  *  up to so it doesn't get confused and create a new USB host device object
    1318  *  (a Darwin issue).
    1319  *
    1320  *  When \a aDone = true we replay all filters against the given USB device
    1321  *  excluding filters of the machine the device is currently marked as
    1322  *  captured by.
    1323  *
    1324  *  When the \a aDone = true request is completed,
    1325  *  IInternalSessionControl::onUSBDeviceDetach() will be called on the given
    1326  *  machine object.
    1327  *
    1328  *  Called by Console from the VM process (throug IInternalMachineControl).
    1329  *
    1330  */
    1331 HRESULT Host::detachUSBDevice (SessionMachine *aMachine, INPTR GUIDPARAM aId, BOOL aDone)
    1332 {
    1333     LogFlowThisFunc (("aMachine=%p, aId={%Vuuid}\n", aMachine, Guid (aId).raw()));
    1334 
    1335     AutoWriteLock alock (this);
    1336     CHECK_READY();
    1337 
    1338     ComObjPtr <HostUSBDevice> device;
    1339     USBDeviceList::iterator it = mUSBDevices.begin();
    1340     while (!device && it != mUSBDevices.end())
    1341     {
    1342         if ((*it)->id() == aId)
    1343             device = (*it);
    1344         ++ it;
    1345     }
    1346 
    1347     ComAssertRet (!!device, E_FAIL);
    1348 
    1349     AutoWriteLock devLock (device);
    1350 
    1351     /*
    1352      * Work the state machine.
    1353      */
    1354     LogFlowThisFunc(("id={%Vuuid} state=%s aDone=%RTbool name={%s}\n",
    1355                      device->id().raw(), device->stateName(), aDone, device->name().raw()));
    1356     bool fRunFilters = false;
    1357     HRESULT hrc = device->onDetachFromVM(aMachine, aDone, &fRunFilters);
    1358 
    1359     /*
    1360      * Run filters if necessary.
    1361      */
    1362     if (    SUCCEEDED(hrc)
    1363         &&  fRunFilters)
    1364     {
    1365         Assert(aDone && device->unistate() == kHostUSBDeviceState_HeldByProxy && device->machine().isNull());
    1366         HRESULT hrc2 = applyAllUSBFilters(device, aMachine);
    1367         ComAssertComRC(hrc2);
    1368     }
    1369     return hrc;
    1370 }
    1371 
    1372 /**
    1373  *  Asks the USB proxy service to capture all currently available USB devices
    1374  *  that match filters of the given machine.
    1375  *
    1376  *  When the request is completed,
    1377  *  IInternalSessionControl::onUSBDeviceDetach() will be called on the given
    1378  *  machine object per every captured USB device.
    1379  *
    1380  *  Called by Console from the VM process (through IInternalMachineControl)
    1381  *  upon VM startup.
    1382  *
    1383  *  @note Locks this object for reading (@todo for writing now, until switched
    1384  *  to the new locking scheme).
    1385  */
    1386 HRESULT Host::autoCaptureUSBDevices (SessionMachine *aMachine)
    1387 {
    1388     LogFlowThisFunc (("aMachine=%p\n", aMachine));
    1389 
    1390     AutoWriteLock alock (this);
    1391     CHECK_READY();
    1392 
    1393     for (USBDeviceList::iterator it = mUSBDevices.begin();
    1394          it != mUSBDevices.end();
    1395          ++ it)
    1396     {
    1397         ComObjPtr <HostUSBDevice> device = *it;
    1398         AutoWriteLock devLock (device);
    1399         if (   device->unistate() == kHostUSBDeviceState_HeldByProxy
    1400             || device->unistate() == kHostUSBDeviceState_Unused
    1401             || device->unistate() == kHostUSBDeviceState_Capturable)
    1402             applyMachineUSBFilters(aMachine, device);
    1403     }
    1404 
    1405     return S_OK;
    1406 }
    1407 
    1408 /**
    1409  *  Replays all filters against all USB devices currently marked as captured
    1410  *  by the given machine (excluding this machine's filters).
    1411  *
    1412  *  Called by Console from the VM process (throug IInternalMachineControl)
    1413  *  upon normal VM termination or by SessionMachine::uninit() upon abnormal
    1414  *  VM termination (from under the Machine/SessionMachine lock).
    1415  *
    1416  *  @note Locks this object for reading (@todo for writing now, until switched
    1417  *  to the new locking scheme).
    1418  */
    1419 HRESULT Host::detachAllUSBDevices (SessionMachine *aMachine, BOOL aDone, bool aAbnormal)
    1420 {
    1421     AutoWriteLock alock (this);
    1422     CHECK_READY();
    1423 
    1424     USBDeviceList::iterator it = mUSBDevices.begin();
    1425     while (it != mUSBDevices.end())
    1426     {
    1427         ComObjPtr <HostUSBDevice> device = *it;
    1428 
    1429         AutoWriteLock devLock (device);
    1430 
    1431         if (device->machine() == aMachine)
    1432         {
    1433             /*
    1434              * Same procedure as in detachUSBDevice().
    1435              */
    1436             bool fRunFilters = false;
    1437             HRESULT hrc = device->onDetachFromVM(aMachine, aDone, &fRunFilters, aAbnormal);
    1438             if (    SUCCEEDED(hrc)
    1439                 &&  fRunFilters)
    1440             {
    1441                 Assert(aDone && device->unistate() == kHostUSBDeviceState_HeldByProxy && device->machine().isNull());
    1442                 HRESULT hrc2 = applyAllUSBFilters(device, aMachine);
    1443                 ComAssertComRC(hrc2);
    1444             }
    1445         }
    1446         ++ it;
    1447     }
    1448 
    1449     return S_OK;
    1450 }
    1451 
    14521261#endif /* VBOX_HOST_USB */
    14531262
     
    20881897                     aDevice, aDevice->name().raw(), aDevice->stateName(), aDevice->id().raw()));
    20891898
    2090     /* add to the collecion */
    2091     mUSBDevices.push_back (aDevice);
    2092 
    20931899    /* apply all filters */
    20941900    ComObjPtr <HostUSBDevice> device (aDevice);
     
    21151921
    21161922    /*
    2117      * Remove from the list.
     1923     * Detach the device from any machine currently using it,
     1924     * reset all data and uninitialize the device object.
    21181925     */
    2119     Guid id = aDevice->id();
    2120 
    2121     ComObjPtr <HostUSBDevice> device;
    2122     Host::USBDeviceList::iterator it = mUSBDevices.begin();
    2123     while (it != mUSBDevices.end())
    2124     {
    2125         if ((*it)->id() == id)
    2126         {
    2127             device = (*it);
    2128             break;
    2129         }
    2130         ++ it;
    2131     }
    2132 
    2133     AssertReturnVoid (!!device);
    2134 
    2135     /* remove from the collecion */
    2136     mUSBDevices.erase (it);
    2137 
    2138     /* Detach the device from any machine currently using it,
    2139        reset all data and uninitialize the device object. */
    2140     device->onPhysicalDetached();
     1926    aDevice->onPhysicalDetached();
    21411927}
    21421928
  • trunk/src/VBox/Main/MachineImpl.cpp

    r8603 r8666  
    74607460        NOREF (rc);
    74617461
    7462         mParent->host()->detachAllUSBDevices (this, true /* aDone */, true /* aAbnormal */);
     7462        USBProxyService *service = mParent->host()->usbProxyService();
     7463        if (service)
     7464            service->detachAllDevicesFromVM (this, true /* aDone */, true /* aAbnormal */);
    74637465    }
    74647466#endif /* VBOX_WITH_USB */
     
    76627664
    76637665#ifdef VBOX_WITH_USB
    7664     /* if cautureUSBDevice() fails, it must have set extended error info */
    7665     return mParent->host()->captureUSBDevice (this, aId);
     7666    /* if captureDeviceForVM() fails, it must have set extended error info */
     7667    MultiResult rc = mParent->host()->checkUSBProxyService();
     7668    CheckComRCReturnRC (rc);
     7669
     7670    USBProxyService *service = mParent->host()->usbProxyService();
     7671    AssertReturn (service, E_FAIL);
     7672    return service->captureDeviceForVM (this, aId);
    76667673#else
    76677674    return E_FAIL;
     
    76807687
    76817688#ifdef VBOX_WITH_USB
    7682     return mParent->host()->detachUSBDevice (this, aId, aDone);
     7689    USBProxyService *service = mParent->host()->usbProxyService();
     7690    AssertReturn (service, E_FAIL);
     7691    return service->detachDeviceFromVM (this, aId, aDone);
    76837692#else
    76847693    return E_FAIL;
     
    77067715    NOREF (rc);
    77077716
    7708     return mParent->host()->autoCaptureUSBDevices (this);
     7717    USBProxyService *service = mParent->host()->usbProxyService();
     7718    AssertReturn (service, E_FAIL);
     7719    return service->autoCaptureDevicesForVM (this);
    77097720#else
    77107721    return S_OK;
     
    77347745    NOREF (rc);
    77357746
    7736     return mParent->host()->detachAllUSBDevices (this, aDone, false /* aAbnormal */);
     7747    USBProxyService *service = mParent->host()->usbProxyService();
     7748    AssertReturn (service, E_FAIL);
     7749    return service->detachAllDevicesFromVM (this, aDone, false /* aAbnormal */);
    77377750#else
    77387751    return S_OK;
  • trunk/src/VBox/Main/include/HostImpl.h

    r8547 r8666  
    106106
    107107#ifdef VBOX_WITH_USB
    108     /** @todo We could benefit from moving all this USB management into USBProxyService
    109      * instead of spreading out like this. Host only needs to keep the host filter list and make
    110      * it available to the proxy service. Then only the proxy needs to be intimate friends
    111      * with HostUSBDevice, which would simplify the overall picture a bit.
    112      * But, I don't dare move anything about this right now though, as I have no time nor any
    113      * wishes to provoke the deadlock troll so close to a release... */
    114     HRESULT onUSBDeviceFilterChange (HostUSBDeviceFilter *aFilter,
    115                                      BOOL aActiveChanged = FALSE);
    116     HRESULT captureUSBDevice (SessionMachine *aMachine, INPTR GUIDPARAM aId);
    117     HRESULT detachUSBDevice (SessionMachine *aMachine, INPTR GUIDPARAM aId, BOOL aDone);
    118     HRESULT autoCaptureUSBDevices (SessionMachine *aMachine);
    119     HRESULT detachAllUSBDevices (SessionMachine *aMachine, BOOL aDone, bool aAbnormal);
    120 
     108    /** @name To be moved, they don't belong here.
     109     * @{ */
    121110    void onUSBDeviceAttached (HostUSBDevice *aDevice);
    122111    void onUSBDeviceDetached (HostUSBDevice *aDevice);
    123112    void onUSBDeviceStateChanged(HostUSBDevice *aDevice, bool aRunFilters, SessionMachine *aIgnoreMachine);
     113    /** @} */
     114
     115    HRESULT onUSBDeviceFilterChange (HostUSBDeviceFilter *aFilter, BOOL aActiveChanged = FALSE);
    124116
    125117    /* must be called from under this object's lock */
     
    160152    }
    161153
     154public:  //temporary - will be moved soon.
    162155    HRESULT applyAllUSBFilters (ComObjPtr <HostUSBDevice> &aDevice,
    163156                                SessionMachine *aMachine = NULL);
     
    165158    bool applyMachineUSBFilters (SessionMachine *aMachine,
    166159                                 ComObjPtr <HostUSBDevice> &aDevice);
     160private: //temporary
    167161#endif /* VBOX_WITH_USB */
    168162
     
    182176
    183177#ifdef VBOX_WITH_USB
    184     typedef std::list <ComObjPtr <HostUSBDevice> > USBDeviceList;
    185     USBDeviceList mUSBDevices; /**< @todo remove this, use the one maintained by USBProxyService. */
    186 
    187178    typedef std::list <ComObjPtr <HostUSBDeviceFilter> > USBDeviceFilterList;
    188179    USBDeviceFilterList mUSBDeviceFilters;
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