Changeset 2805 in vbox for trunk/src/VBox
- Timestamp:
- May 23, 2007 1:45:31 PM (18 years ago)
- Location:
- trunk/src/VBox/Main
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/ConsoleImpl.cpp
r2672 r2805 3799 3799 } 3800 3800 3801 releaseAllUSBDevices(); 3801 /* If the machine has an USB comtroller, release all USB devices 3802 * (symmectric to the code in captureUSBDevices()) */ 3803 { 3804 PPDMIBASE pBase; 3805 int vrc = PDMR3QueryLun (mpVM, "usb-ohci", 0, 0, &pBase); 3806 if (VBOX_SUCCESS (vrc)) 3807 releaseAllUSBDevices(); 3808 } 3802 3809 3803 3810 /* … … 4288 4295 4289 4296 /** 4290 * USB device attac kcallback used by AttachUSBDevice().4297 * USB device attach callback used by AttachUSBDevice(). 4291 4298 * Note that AttachUSBDevice() doesn't return until this callback is executed, 4292 4299 * so we don't use AutoCaller and don't care about reference counters of … … 4349 4356 4350 4357 /** 4351 * USB device attack callback used by AttachUSBDevice().4352 * Note that AttachUSBDevice() doesn't return until this callback is executed,4358 * USB device detach callback used by DetachUSBDevice(). 4359 * Note that DetachUSBDevice() doesn't return until this callback is executed, 4353 4360 * so we don't use AutoCaller and don't care about reference counters of 4354 4361 * interface pointers passed in. -
trunk/src/VBox/Main/HostImpl.cpp
r2587 r2805 1294 1294 * of IUSBDevice instances. 1295 1295 * 1296 * Called by Console from the VM process (through IInternalMachineControl). 1296 * Called by Console from the VM process (through IInternalMachineControl) 1297 * upon VM startup. 1298 * 1299 * @note Locks this object for reading (@todo for writing now, until switched 1300 * to the new locking scheme). 1297 1301 */ 1298 1302 HRESULT Host::autoCaptureUSBDevices (SessionMachine *aMachine, 1299 1303 IUSBDeviceCollection **aHostDevices) 1300 1304 { 1301 LogFlow Member (("Host::autoCaptureUSBDevices:aMachine=%p\n", aMachine));1305 LogFlowThisFunc (("aMachine=%p\n", aMachine)); 1302 1306 1303 1307 AutoLock lock (this); … … 1321 1325 if (device->state() == USBDeviceState_USBDeviceCaptured) 1322 1326 { 1323 / / put the device to the return list1327 /* put the device to the return list */ 1324 1328 ComPtr <IUSBDevice> d; 1325 1329 device.queryInterfaceTo (d.asOutParam()); … … 1343 1347 * by the given machine (excluding this machine's filters). 1344 1348 * 1345 * Called by Console from the VM process (throug IInternalMachineControl). 1349 * Called by Console from the VM process (throug IInternalMachineControl) 1350 * upon normal VM termination or by SessionMachine::uninit() upon abnormal 1351 * VM termination (from under the Machine/SessionMachine lock). 1352 * 1353 * @note Locks this object for reading (@todo for writing now, until switched 1354 * to the new locking scheme). 1346 1355 */ 1347 1356 HRESULT Host::releaseAllUSBDevices (SessionMachine *aMachine) … … 1356 1365 if (device->machine() == aMachine) 1357 1366 { 1358 / / reset the device and apply filters1367 /* reset the device and apply filters */ 1359 1368 device->reset(); 1360 1369 HRESULT rc = applyAllUSBFilters (device, aMachine); … … 1511 1520 LogFlowMember (("Host::applyAllUSBFilters: \n")); 1512 1521 1513 / / ignore unsupported devices1522 /* ignore unsupported devices */ 1514 1523 if (aDevice->state() == USBDeviceState_USBDeviceNotSupported) 1515 1524 return S_OK; 1516 / / ignore unavailable devices as well1525 /* ignore unavailable devices as well */ 1517 1526 if (aDevice->state() == USBDeviceState_USBDeviceUnavailable) 1518 1527 return S_OK; … … 1521 1530 mParent->getOpenedMachines (machines); 1522 1531 1523 / / apply global filters1532 /* apply global filters */ 1524 1533 USBDeviceFilterList::const_iterator it = mUSBDeviceFilters.begin(); 1525 1534 while (it != mUSBDeviceFilters.end()) … … 1537 1546 } 1538 1547 1539 / / apply machine filters1548 /* apply machine filters */ 1540 1549 for (size_t i = 0; i < machines.size(); i++) 1541 1550 { … … 1559 1568 } 1560 1569 1561 / /no machine filters were matched.1562 //if no global filters were matched as well, release the device1563 // to make it available on the host1570 /* no machine filters were matched. 1571 * if no global filters were matched as well, release the device 1572 * to make it available on the host */ 1564 1573 if ( it == mUSBDeviceFilters.end() 1565 1574 && aDevice->state() == USBDeviceState_USBDeviceHeld) -
trunk/src/VBox/Main/USBControllerImpl.cpp
r1 r2805 295 295 CHECK_READY(); 296 296 297 CHECK_MACHINE_MUTABILITY (m_Parent); 297 /* the machine needs to be mutable */ 298 Machine::AutoStateDependency <Machine::MutableStateDep> adep (m_Parent); 299 CheckComRCReturnRC (adep.rc()); 298 300 299 301 ComObjPtr <USBDeviceFilter> filter = getDependentChild (aFilter); … … 307 309 tr ("The given USB device filter is already in the list")); 308 310 309 / / backup the list before modification311 /* backup the list before modification */ 310 312 m_DeviceFilters.backup(); 311 313 312 / / iterate to the position...314 /* iterate to the position... */ 313 315 DeviceFilterList::iterator it; 314 316 if (aPosition < m_DeviceFilters->size()) … … 319 321 else 320 322 it = m_DeviceFilters->end(); 321 / / ...and insert323 /* ...and insert */ 322 324 m_DeviceFilters->insert (it, filter); 323 325 filter->mInList = true; 324 326 325 // notify the proxy (only when the filter is active) 327 /// @todo After rewriting Win32 USB support, no more necessary; 328 // a candidate for removal. 329 #if 0 330 /* notify the proxy (only when the filter is active) */ 326 331 if (filter->data().mActive) 332 #else 333 /* notify the proxy (only when it makes sense) */ 334 if (filter->data().mActive && adep.machineState() >= MachineState_Running) 335 #endif 327 336 { 328 337 USBProxyService *service = m_Parent->virtualBox()->host()->usbProxyService(); … … 345 354 CHECK_READY(); 346 355 347 CHECK_MACHINE_MUTABILITY (m_Parent); 356 /* the machine needs to be mutable */ 357 Machine::AutoStateDependency <Machine::MutableStateDep> adep (m_Parent); 358 CheckComRCReturnRC (adep.rc()); 348 359 349 360 if (!m_DeviceFilters->size()) … … 356 367 aPosition, m_DeviceFilters->size() - 1); 357 368 358 / / backup the list before modification369 /* backup the list before modification */ 359 370 m_DeviceFilters.backup(); 360 371 361 372 ComObjPtr <USBDeviceFilter> filter; 362 373 { 363 / / iterate to the position...374 /* iterate to the position... */ 364 375 DeviceFilterList::iterator it = m_DeviceFilters->begin(); 365 376 std::advance (it, aPosition); 366 / / ...get an element from there...377 /* ...get an element from there... */ 367 378 filter = *it; 368 / / ...and remove379 /* ...and remove */ 369 380 filter->mInList = false; 370 381 m_DeviceFilters->erase (it); 371 382 } 372 383 373 / / cancel sharing (make an independent copy of data)384 /* cancel sharing (make an independent copy of data) */ 374 385 filter->unshare(); 375 386 376 387 filter.queryInterfaceTo (aFilter); 377 388 378 // notify the proxy (only when the filter is active) 389 /// @todo After rewriting Win32 USB support, no more necessary; 390 // a candidate for removal. 391 #if 0 392 /* notify the proxy (only when the filter is active) */ 379 393 if (filter->data().mActive) 394 #else 395 /* notify the proxy (only when it makes sense) */ 396 if (filter->data().mActive && adep.machineState() >= MachineState_Running) 397 #endif 380 398 { 381 399 USBProxyService *service = m_Parent->virtualBox()->host()->usbProxyService(); … … 607 625 bool USBController::rollback() 608 626 { 609 AutoLock alock(this); 627 AutoLock alock (this); 628 629 /* we need the machine state */ 630 Machine::AutoStateDependency <Machine::MutableStateDep> adep (m_Parent); 631 AssertComRCReturn (adep.rc(), false); 610 632 611 633 bool dataChanged = false; … … 613 635 if (m_Data.isBackedUp()) 614 636 { 615 / /we need to check all data to see whether anything will be changed616 // after rollback637 /* we need to check all data to see whether anything will be changed 638 * after rollback */ 617 639 dataChanged = m_Data.hasActualChanges(); 618 640 m_Data.rollback(); … … 624 646 ComAssertRet (service, false); 625 647 626 / / uninitialize all new filters (absent in the backed up list)648 /* uninitialize all new filters (absent in the backed up list) */ 627 649 DeviceFilterList::const_iterator it = m_DeviceFilters->begin(); 628 650 DeviceFilterList *backedList = m_DeviceFilters.backedUpData(); … … 632 654 backedList->end()) 633 655 { 634 // notify the proxy (only when the filter is active) 656 /// @todo After rewriting Win32 USB support, no more necessary; 657 // a candidate for removal. 658 #if 0 659 /* notify the proxy (only when the filter is active) */ 635 660 if ((*it)->data().mActive) 661 #else 662 /* notify the proxy (only when it makes sense) */ 663 if ((*it)->data().mActive && 664 adep.machineState() >= MachineState_Running) 665 #endif 636 666 { 637 667 USBDeviceFilter *filter = *it; … … 646 676 } 647 677 648 // find all removed old filters (absent in the new list) 649 // and insert them back to the USB proxy 650 it = backedList->begin(); 651 while (it != backedList->end()) 652 { 653 if (std::find (m_DeviceFilters->begin(), m_DeviceFilters->end(), *it) == 654 m_DeviceFilters->end()) 678 /// @todo After rewriting Win32 USB support, no more necessary; 679 // a candidate for removal. 680 #if 0 681 #else 682 if (adep.machineState() >= MachineState_Running) 683 #endif 684 { 685 /* find all removed old filters (absent in the new list) 686 * and insert them back to the USB proxy */ 687 it = backedList->begin(); 688 while (it != backedList->end()) 655 689 { 656 // notify the proxy (only when the filter is active)657 if ((*it)->data().mActive)690 if (std::find (m_DeviceFilters->begin(), m_DeviceFilters->end(), *it) == 691 m_DeviceFilters->end()) 658 692 { 659 USBDeviceFilter *flt = *it; // resolve ambiguity 660 ComAssertRet (flt->id() == NULL, false); 661 flt->id() = service->insertFilter (ComPtr <IUSBDeviceFilter> (flt)); 693 /* notify the proxy (only when necessary) */ 694 if ((*it)->data().mActive) 695 { 696 USBDeviceFilter *flt = *it; /* resolve ambiguity */ 697 ComAssertRet (flt->id() == NULL, false); 698 flt->id() = service->insertFilter 699 (ComPtr <IUSBDeviceFilter> (flt)); 700 } 662 701 } 702 ++ it; 663 703 } 664 ++ it; 665 } 666 667 // restore the list 704 } 705 706 /* restore the list */ 668 707 m_DeviceFilters.rollback(); 669 708 } 670 709 671 // rollback any changes to filters after restoring the list 710 /* here we don't depend on the machine state any more */ 711 adep.release(); 712 713 /* rollback any changes to filters after restoring the list */ 672 714 DeviceFilterList::const_iterator it = m_DeviceFilters->begin(); 673 715 while (it != m_DeviceFilters->end()) … … 676 718 { 677 719 (*it)->rollback(); 678 / / call this to notify the USB proxy about changes720 /* call this to notify the USB proxy about changes */ 679 721 onDeviceFilterChange (*it); 680 722 } … … 821 863 CHECK_READY(); 822 864 823 USBProxyService *service = m_Parent->virtualBox()->host()->usbProxyService(); 824 ComAssertRet (service, E_FAIL); 825 826 // iterate over the filter list and notify the proxy accordingly 827 828 DeviceFilterList::const_iterator it = m_DeviceFilters->begin(); 829 while (it != m_DeviceFilters->end()) 830 { 831 USBDeviceFilter *flt = *it; // resolve ambiguity (for ComPtr below) 832 833 // notify the proxy (only if the filter is active) 834 if (flt->data().mActive) 835 { 836 if (aRegistered) 837 { 838 ComAssertRet (flt->id() == NULL, E_FAIL); 839 flt->id() = service->insertFilter (ComPtr <IUSBDeviceFilter> (flt)); 840 } 841 else 842 { 843 ComAssertRet (flt->id() != NULL, E_FAIL); 844 service->removeFilter (flt->id()); 845 flt->id() = NULL; 846 } 847 } 848 ++ it; 849 } 865 /// @todo After rewriting Win32 USB support, no more necessary; 866 // a candidate for removal. 867 #if 0 868 notifyProxy (!!aRegistered); 869 #endif 850 870 851 871 return S_OK; … … 861 881 CHECK_READY(); 862 882 883 /// @todo After rewriting Win32 USB support, no more necessary; 884 // a candidate for removal. 885 #if 0 886 #else 887 /* we need the machine state */ 888 Machine::AutoStateDependency <Machine::MutableStateDep> adep (m_Parent); 889 AssertComRCReturnRC (adep.rc()); 890 891 /* nothing to do if the machine isn't running */ 892 if (adep.machineState() < MachineState_Running) 893 return S_OK; 894 #endif 895 863 896 if (aFilter->mInList && m_Parent->isRegistered()) 864 897 { … … 868 901 if (aActiveChanged) 869 902 { 870 / / insert/remove the filter from the proxy903 /* insert/remove the filter from the proxy */ 871 904 if (aFilter->data().mActive) 872 905 { 873 906 ComAssertRet (aFilter->id() == NULL, E_FAIL); 874 aFilter->id() = 875 service->insertFilter(ComPtr <IUSBDeviceFilter> (aFilter));907 aFilter->id() = service->insertFilter 908 (ComPtr <IUSBDeviceFilter> (aFilter)); 876 909 } 877 910 else … … 886 919 if (aFilter->data().mActive) 887 920 { 888 / / update the filter in the proxy921 /* update the filter in the proxy */ 889 922 ComAssertRet (aFilter->id() != NULL, E_FAIL); 890 923 service->removeFilter (aFilter->id()); 891 aFilter->id() = 892 service->insertFilter(ComPtr <IUSBDeviceFilter> (aFilter));924 aFilter->id() = service->insertFilter 925 (ComPtr <IUSBDeviceFilter> (aFilter)); 893 926 } 894 927 } … … 936 969 bool USBController::hasMatchingFilter (IUSBDevice *aUSBDevice) 937 970 { 938 LogFlow Member (("USBController::hasMatchingFilter()\n"));971 LogFlowThisFunc (("\n")); 939 972 940 973 AutoLock alock (this); … … 1027 1060 } 1028 1061 1062 HRESULT USBController::notifyProxy (bool aInsertFilters) 1063 { 1064 LogFlowThisFunc (("aInsertFilters=%RTbool\n", aInsertFilters)); 1065 1066 AutoLock alock (this); 1067 if (!isReady()) 1068 return false; 1069 1070 USBProxyService *service = m_Parent->virtualBox()->host()->usbProxyService(); 1071 AssertReturn (service, E_FAIL); 1072 1073 DeviceFilterList::const_iterator it = m_DeviceFilters->begin(); 1074 while (it != m_DeviceFilters->end()) 1075 { 1076 USBDeviceFilter *flt = *it; /* resolve ambiguity (for ComPtr below) */ 1077 1078 /* notify the proxy (only if the filter is active) */ 1079 if (flt->data().mActive) 1080 { 1081 if (aInsertFilters) 1082 { 1083 AssertReturn (flt->id() == NULL, E_FAIL); 1084 flt->id() = service->insertFilter 1085 (ComPtr <IUSBDeviceFilter> (flt)); 1086 } 1087 else 1088 { 1089 AssertReturn (flt->id() != NULL, E_FAIL); 1090 service->removeFilter (flt->id()); 1091 flt->id() = NULL; 1092 } 1093 } 1094 ++ it; 1095 } 1096 1097 return S_OK; 1098 } 1099 1029 1100 // private methods 1030 1101 ///////////////////////////////////////////////////////////////////////////// -
trunk/src/VBox/Main/include/USBControllerImpl.h
r1 r2805 111 111 bool hasMatchingFilter (IUSBDevice *aUSBDevice); 112 112 113 HRESULT notifyProxy (bool aInsertFilters); 114 113 115 // for VirtualBoxSupportErrorInfoImpl 114 116 static const wchar_t *getComponentName() { return L"USBController"; }
Note:
See TracChangeset
for help on using the changeset viewer.