- Timestamp:
- May 7, 2008 3:24:57 PM (17 years ago)
- Location:
- trunk/src/VBox/Main
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/HostImpl.cpp
r8566 r8666 187 187 #ifdef VBOX_WITH_USB 188 188 mUSBDeviceFilters.clear(); 189 mUSBDevices.clear();190 189 #endif 191 190 … … 589 588 CheckComRCReturnRC (rc); 590 589 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 597 592 #else 598 593 /* Note: The GUI depends on this method returning E_NOTIMPL with no … … 1220 1215 1221 1216 #ifdef VBOX_WITH_USB 1222 1223 1217 /** 1224 1218 * Called by setter methods of all USB device filters. … … 1265 1259 return S_OK; 1266 1260 } 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 given1274 * 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 device1305 */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 is1317 * up to so it doesn't get confused and create a new USB host device object1318 * (a Darwin issue).1319 *1320 * When \a aDone = true we replay all filters against the given USB device1321 * excluding filters of the machine the device is currently marked as1322 * captured by.1323 *1324 * When the \a aDone = true request is completed,1325 * IInternalSessionControl::onUSBDeviceDetach() will be called on the given1326 * 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 devices1374 * that match filters of the given machine.1375 *1376 * When the request is completed,1377 * IInternalSessionControl::onUSBDeviceDetach() will be called on the given1378 * 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 switched1384 * 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_HeldByProxy1400 || device->unistate() == kHostUSBDeviceState_Unused1401 || 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 captured1410 * 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 abnormal1414 * VM termination (from under the Machine/SessionMachine lock).1415 *1416 * @note Locks this object for reading (@todo for writing now, until switched1417 * 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 1452 1261 #endif /* VBOX_HOST_USB */ 1453 1262 … … 2088 1897 aDevice, aDevice->name().raw(), aDevice->stateName(), aDevice->id().raw())); 2089 1898 2090 /* add to the collecion */2091 mUSBDevices.push_back (aDevice);2092 2093 1899 /* apply all filters */ 2094 1900 ComObjPtr <HostUSBDevice> device (aDevice); … … 2115 1921 2116 1922 /* 2117 * Remove from the list. 1923 * Detach the device from any machine currently using it, 1924 * reset all data and uninitialize the device object. 2118 1925 */ 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(); 2141 1927 } 2142 1928 -
trunk/src/VBox/Main/MachineImpl.cpp
r8603 r8666 7460 7460 NOREF (rc); 7461 7461 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 */); 7463 7465 } 7464 7466 #endif /* VBOX_WITH_USB */ … … 7662 7664 7663 7665 #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); 7666 7673 #else 7667 7674 return E_FAIL; … … 7680 7687 7681 7688 #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); 7683 7692 #else 7684 7693 return E_FAIL; … … 7706 7715 NOREF (rc); 7707 7716 7708 return mParent->host()->autoCaptureUSBDevices (this); 7717 USBProxyService *service = mParent->host()->usbProxyService(); 7718 AssertReturn (service, E_FAIL); 7719 return service->autoCaptureDevicesForVM (this); 7709 7720 #else 7710 7721 return S_OK; … … 7734 7745 NOREF (rc); 7735 7746 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 */); 7737 7750 #else 7738 7751 return S_OK; -
trunk/src/VBox/Main/include/HostImpl.h
r8547 r8666 106 106 107 107 #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 * @{ */ 121 110 void onUSBDeviceAttached (HostUSBDevice *aDevice); 122 111 void onUSBDeviceDetached (HostUSBDevice *aDevice); 123 112 void onUSBDeviceStateChanged(HostUSBDevice *aDevice, bool aRunFilters, SessionMachine *aIgnoreMachine); 113 /** @} */ 114 115 HRESULT onUSBDeviceFilterChange (HostUSBDeviceFilter *aFilter, BOOL aActiveChanged = FALSE); 124 116 125 117 /* must be called from under this object's lock */ … … 160 152 } 161 153 154 public: //temporary - will be moved soon. 162 155 HRESULT applyAllUSBFilters (ComObjPtr <HostUSBDevice> &aDevice, 163 156 SessionMachine *aMachine = NULL); … … 165 158 bool applyMachineUSBFilters (SessionMachine *aMachine, 166 159 ComObjPtr <HostUSBDevice> &aDevice); 160 private: //temporary 167 161 #endif /* VBOX_WITH_USB */ 168 162 … … 182 176 183 177 #ifdef VBOX_WITH_USB 184 typedef std::list <ComObjPtr <HostUSBDevice> > USBDeviceList;185 USBDeviceList mUSBDevices; /**< @todo remove this, use the one maintained by USBProxyService. */186 187 178 typedef std::list <ComObjPtr <HostUSBDeviceFilter> > USBDeviceFilterList; 188 179 USBDeviceFilterList mUSBDeviceFilters;
Note:
See TracChangeset
for help on using the changeset viewer.