diff options
Diffstat (limited to 'src/VBox/Main/src-server/win/USBProxyServiceWindows.cpp')
-rw-r--r-- | src/VBox/Main/src-server/win/USBProxyServiceWindows.cpp | 119 |
1 files changed, 51 insertions, 68 deletions
diff --git a/src/VBox/Main/src-server/win/USBProxyServiceWindows.cpp b/src/VBox/Main/src-server/win/USBProxyServiceWindows.cpp index fbb0c4a78..d763e8eb8 100644 --- a/src/VBox/Main/src-server/win/USBProxyServiceWindows.cpp +++ b/src/VBox/Main/src-server/win/USBProxyServiceWindows.cpp @@ -1,4 +1,4 @@ -/* $Id: USBProxyServiceWindows.cpp $ */ +/* $Id: USBProxyServiceWindows.cpp 37599 2011-06-22 21:06:38Z vboxsync $ */ /** @file * VirtualBox USB Proxy Service, Windows Specialization. */ @@ -52,12 +52,6 @@ USBProxyServiceWindows::USBProxyServiceWindows(Host *aHost) HRESULT USBProxyServiceWindows::init(void) { /* - * Call the superclass method first. - */ - HRESULT hrc = USBProxyService::init(); - AssertComRCReturn(hrc, hrc); - - /* * Create the semaphore (considered fatal). */ mhEventInterrupt = CreateEvent(NULL, FALSE, FALSE, NULL); @@ -142,49 +136,64 @@ void USBProxyServiceWindows::removeFilter(void *aID) int USBProxyServiceWindows::captureDevice(HostUSBDevice *aDevice) { - AssertReturn(aDevice, VERR_GENERAL_FAILURE); - AssertReturn(aDevice->isWriteLockOnCurrentThread(), VERR_GENERAL_FAILURE); - Assert(aDevice->getUnistate() == kHostUSBDeviceState_Capturing); - -/** @todo pass up a one-shot filter like on darwin? */ - USHORT vendorId, productId, revision; - - HRESULT rc; - - rc = aDevice->COMGETTER(VendorId)(&vendorId); - AssertComRCReturn(rc, VERR_INTERNAL_ERROR); - - rc = aDevice->COMGETTER(ProductId)(&productId); - AssertComRCReturn(rc, VERR_INTERNAL_ERROR); + /* + * Create a one-shot ignore filter for the device + * and trigger a re-enumeration of it. + */ + USBFILTER Filter; + USBFilterInit(&Filter, USBFILTERTYPE_ONESHOT_CAPTURE); + initFilterFromDevice(&Filter, aDevice); + Log(("USBFILTERIDX_PORT=%#x\n", USBFilterGetNum(&Filter, USBFILTERIDX_PORT))); + Log(("USBFILTERIDX_BUS=%#x\n", USBFilterGetNum(&Filter, USBFILTERIDX_BUS))); + + void *pvId = USBLibAddFilter(&Filter); + if (!pvId) + { + AssertMsgFailed(("Add one-shot Filter failed\n")); + return VERR_GENERAL_FAILURE; + } - rc = aDevice->COMGETTER(Revision)(&revision); - AssertComRCReturn(rc, VERR_INTERNAL_ERROR); + int rc = USBLibRunFilters(); + if (!RT_SUCCESS(rc)) + { + AssertMsgFailed(("Run Filters failed\n")); + USBLibRemoveFilter(pvId); + return rc; + } - return USBLibCaptureDevice(vendorId, productId, revision); + return VINF_SUCCESS; } int USBProxyServiceWindows::releaseDevice(HostUSBDevice *aDevice) { - AssertReturn(aDevice, VERR_GENERAL_FAILURE); - AssertReturn(aDevice->isWriteLockOnCurrentThread(), VERR_GENERAL_FAILURE); - Assert(aDevice->getUnistate() == kHostUSBDeviceState_ReleasingToHost); - -/** @todo pass up a one-shot filter like on darwin? */ - USHORT vendorId, productId, revision; - HRESULT rc; - - rc = aDevice->COMGETTER(VendorId)(&vendorId); - AssertComRCReturn(rc, VERR_INTERNAL_ERROR); + /* + * Create a one-shot ignore filter for the device + * and trigger a re-enumeration of it. + */ + USBFILTER Filter; + USBFilterInit(&Filter, USBFILTERTYPE_ONESHOT_IGNORE); + initFilterFromDevice(&Filter, aDevice); + Log(("USBFILTERIDX_PORT=%#x\n", USBFilterGetNum(&Filter, USBFILTERIDX_PORT))); + Log(("USBFILTERIDX_BUS=%#x\n", USBFilterGetNum(&Filter, USBFILTERIDX_BUS))); + + void *pvId = USBLibAddFilter(&Filter); + if (!pvId) + { + AssertMsgFailed(("Add one-shot Filter failed\n")); + return VERR_GENERAL_FAILURE; + } - rc = aDevice->COMGETTER(ProductId)(&productId); - AssertComRCReturn(rc, VERR_INTERNAL_ERROR); + int rc = USBLibRunFilters(); + if (!RT_SUCCESS(rc)) + { + AssertMsgFailed(("Run Filters failed\n")); + USBLibRemoveFilter(pvId); + return rc; + } - rc = aDevice->COMGETTER(Revision)(&revision); - AssertComRCReturn(rc, VERR_INTERNAL_ERROR); - Log(("USBProxyServiceWindows::releaseDevice\n")); - return USBLibReleaseDevice(vendorId, productId, revision); + return VINF_SUCCESS; } @@ -222,41 +231,15 @@ bool USBProxyServiceWindows::updateDeviceState(HostUSBDevice *aDevice, PUSBDEVIC int USBProxyServiceWindows::wait(unsigned aMillies) { - DWORD rc; - - /* Not going to do something fancy where we block in the filter - * driver and are woken up when the state has changed. - * Would be better, but this is good enough. - */ - do - { - rc = WaitForSingleObject(mhEventInterrupt, RT_MIN(aMillies, 100)); - if (rc == WAIT_OBJECT_0) - return VINF_SUCCESS; - /** @todo handle WAIT_FAILED here */ - - if (USBLibHasPendingDeviceChanges() == true) - { - Log(("wait thread detected usb change\n")); - return VINF_SUCCESS; - } - - if (aMillies > 100) - aMillies -= 100; - } - while (aMillies > 100); - - return VERR_TIMEOUT; + return USBLibWaitChange(aMillies); } int USBProxyServiceWindows::interruptWait(void) { - SetEvent(mhEventInterrupt); - return VINF_SUCCESS; + return USBLibInterruptWaitChange(); } - /** * Gets a list of all devices the VM can grab */ |