Changeset 41528 in vbox for trunk/src/VBox/Main
- Timestamp:
- May 31, 2012 4:48:33 PM (13 years ago)
- Location:
- trunk/src/VBox/Main
- Files:
-
- 15 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/glue/AutoLock.cpp
r40452 r41528 66 66 } aClasses[] = 67 67 { 68 { LOCKCLASS_VIRTUALBOXOBJECT, " 1-VIRTUALBOXOBJECT" },68 { LOCKCLASS_VIRTUALBOXOBJECT, "2-VIRTUALBOXOBJECT" }, 69 69 { LOCKCLASS_HOSTOBJECT, "3-HOSTOBJECT" }, 70 70 { LOCKCLASS_LISTOFMACHINES, "4-LISTOFMACHINES" }, … … 75 75 { LOCKCLASS_LISTOFOTHEROBJECTS, "9-LISTOFOTHEROBJECTS" }, 76 76 { LOCKCLASS_OTHEROBJECT, "10-OTHEROBJECT" }, 77 { LOCKCLASS_USBLIST, "11-USBLIST" }, 78 { LOCKCLASS_PROGRESSLIST, "12-PROGRESSLIST" }, 79 { LOCKCLASS_OBJECTSTATE, "13-OBJECTSTATE" } 77 { LOCKCLASS_PROGRESSLIST, "11-PROGRESSLIST" }, 78 { LOCKCLASS_OBJECTSTATE, "12-OBJECTSTATE" } 80 79 }; 81 80 -
trunk/src/VBox/Main/include/ConsoleImpl.h
r41352 r41528 5 5 6 6 /* 7 * Copyright (C) 200 6-2011Oracle Corporation7 * Copyright (C) 2005-2012 Oracle Corporation 8 8 * 9 9 * This file is part of VirtualBox Open Source Edition (OSE), as … … 602 602 #ifdef VBOX_WITH_USB 603 603 HRESULT attachUSBDevice(IUSBDevice *aHostDevice, ULONG aMaskedIfs); 604 HRESULT detachUSBDevice( USBDeviceList::iterator &aIt);604 HRESULT detachUSBDevice(const ComObjPtr<OUSBDevice> &aHostDevice); 605 605 606 606 static DECLCALLBACK(int) usbAttachCallback(Console *that, PVM pVM, IUSBDevice *aHostDevice, PCRTUUID aUuid, 607 bool aRemote, const char *aAddress, ULONG aMaskedIfs);608 static DECLCALLBACK(int) usbDetachCallback(Console *that, PVM pVM, USBDeviceList::iterator *aIt,PCRTUUID aUuid);607 bool aRemote, const char *aAddress, void *pvRemoteBackend, USHORT aPortVersion, ULONG aMaskedIfs); 608 static DECLCALLBACK(int) usbDetachCallback(Console *that, PVM pVM, PCRTUUID aUuid); 609 609 #endif 610 610 -
trunk/src/VBox/Main/include/USBProxyService.h
r37618 r41528 5 5 6 6 /* 7 * Copyright (C) 200 6-2007Oracle Corporation7 * Copyright (C) 2005-2012 Oracle Corporation 8 8 * 9 9 * This file is part of VirtualBox Open Source Edition (OSE), as … … 79 79 virtual int captureDevice(HostUSBDevice *aDevice); 80 80 virtual void captureDeviceCompleted(HostUSBDevice *aDevice, bool aSuccess); 81 /** @todo unused */ 81 82 virtual void detachingDevice(HostUSBDevice *aDevice); 82 83 virtual int releaseDevice(HostUSBDevice *aDevice); … … 160 161 virtual int captureDevice(HostUSBDevice *aDevice); 161 162 virtual void captureDeviceCompleted(HostUSBDevice *aDevice, bool aSuccess); 163 /** @todo unused */ 162 164 virtual void detachingDevice(HostUSBDevice *aDevice); 163 165 virtual int releaseDevice(HostUSBDevice *aDevice); -
trunk/src/VBox/Main/src-client/ConsoleImpl.cpp
r41474 r41528 3009 3009 Guid(aId).raw()); 3010 3010 3011 /* Remove the device from the collection, it is re-added below for failures */ 3012 mUSBDevices.erase(it); 3013 3011 3014 /* 3012 3015 * Inform the USB device and USB proxy about what's cooking. 3013 3016 */ 3014 3017 alock.release(); 3015 HRESULT rc2 = mControl->DetachUSBDevice(aId, false /* aDone */); 3016 if (FAILED(rc2)) 3017 return rc2; 3018 alock.acquire(); 3018 HRESULT rc = mControl->DetachUSBDevice(aId, false /* aDone */); 3019 if (FAILED(rc)) 3020 { 3021 /* Re-add the device to the collection */ 3022 alock.acquire(); 3023 mUSBDevices.push_back(pUSBDevice); 3024 return rc; 3025 } 3019 3026 3020 3027 /* Request the PDM to detach the USB device. */ 3021 HRESULT rc = detachUSBDevice(it); 3022 3028 rc = detachUSBDevice(pUSBDevice); 3023 3029 if (SUCCEEDED(rc)) 3024 3030 { 3025 /* release the lock since we don't need it any more (note though that3026 * the USB Proxy service must not call us back here) */3027 alock.release();3028 3029 3031 /* Request the device release. Even if it fails, the device will 3030 3032 * remain as held by proxy, which is OK for us (the VM process). */ 3031 3033 rc = mControl->DetachUSBDevice(aId, true /* aDone */); 3034 } 3035 else 3036 { 3037 /* Re-add the device to the collection */ 3038 alock.acquire(); 3039 mUSBDevices.push_back(pUSBDevice); 3032 3040 } 3033 3041 … … 4996 5004 if (aError != NULL) 4997 5005 { 5006 /* notify callbacks about the error */ 4998 5007 alock.release(); 4999 /* notify callbacks about the error */5000 5008 onUSBDeviceStateChange(aDevice, true /* aAttached */, aError); 5001 5009 return S_OK; … … 5010 5018 5011 5019 alock.release(); 5012 5013 5020 HRESULT rc = attachUSBDevice(aDevice, aMaskedIfs); 5014 5021 if (FAILED(rc)) … … 5087 5094 } 5088 5095 5089 alock.release();5090 5091 5096 if (aError != NULL) 5092 5097 { 5093 5098 /* notify callback about an error */ 5099 alock.release(); 5094 5100 onUSBDeviceStateChange(pUSBDevice, false /* aAttached */, aError); 5095 5101 return S_OK; 5096 5102 } 5097 5103 5098 HRESULT rc = detachUSBDevice(it); 5099 5104 /* Remove the device from the collection, it is re-added below for failures */ 5105 mUSBDevices.erase(it); 5106 5107 alock.release(); 5108 HRESULT rc = detachUSBDevice(pUSBDevice); 5100 5109 if (FAILED(rc)) 5101 5110 { 5111 /* Re-add the device to the collection */ 5112 alock.acquire(); 5113 mUSBDevices.push_back(pUSBDevice); 5114 alock.release(); 5102 5115 /* take the current error info */ 5103 5116 com::ErrorInfoKeeper eik; … … 7625 7638 * 7626 7639 * @note Synchronously calls EMT. 7627 * @note Must be called from under this object's lock.7628 7640 */ 7629 7641 HRESULT Console::attachUSBDevice(IUSBDevice *aHostDevice, ULONG aMaskedIfs) 7630 7642 { 7631 7643 AssertReturn(aHostDevice, E_FAIL); 7632 AssertReturn( isWriteLockOnCurrentThread(), E_FAIL);7644 AssertReturn(!isWriteLockOnCurrentThread(), E_FAIL); 7633 7645 7634 7646 HRESULT hrc; … … 7661 7673 Address.c_str(), uuid.raw())); 7662 7674 7663 /** @todo just do everything here and only wrap the PDMR3Usb call. That'll offload some notification stuff from the EMT thread. */ 7675 void *pvRemoteBackend = NULL; 7676 if (fRemote) 7677 { 7678 RemoteUSBDevice *pRemoteUSBDevice = static_cast<RemoteUSBDevice *>(aHostDevice); 7679 pvRemoteBackend = consoleVRDPServer()->USBBackendRequestPointer(pRemoteUSBDevice->clientId(), &uuid); 7680 if (!pvRemoteBackend) 7681 return E_INVALIDARG; /* The clientId is invalid then. */ 7682 } 7683 7684 USHORT portVersion = 1; 7685 hrc = aHostDevice->COMGETTER(PortVersion)(&portVersion); 7686 AssertComRCReturnRC(hrc); 7687 Assert(portVersion == 1 || portVersion == 2); 7688 7664 7689 int vrc = VMR3ReqCallWait(ptrVM, VMCPUID_ANY, 7665 (PFNRT)usbAttachCallback, 7, 7666 this, ptrVM.raw(), aHostDevice, uuid.raw(), fRemote, Address.c_str(), aMaskedIfs); 7667 7668 /* hrc is S_OK here */ 7669 7670 if (RT_FAILURE(vrc)) 7690 (PFNRT)usbAttachCallback, 9, 7691 this, ptrVM.raw(), aHostDevice, uuid.raw(), fRemote, Address.c_str(), pvRemoteBackend, portVersion, aMaskedIfs); 7692 7693 if (RT_SUCCESS(vrc)) 7694 { 7695 /* Create a OUSBDevice and add it to the device list */ 7696 ComObjPtr<OUSBDevice> pUSBDevice; 7697 pUSBDevice.createObject(); 7698 hrc = pUSBDevice->init(aHostDevice); 7699 AssertComRC(hrc); 7700 7701 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS); 7702 mUSBDevices.push_back(pUSBDevice); 7703 LogFlowFunc(("Attached device {%RTuuid}\n", pUSBDevice->id().raw())); 7704 7705 /* notify callbacks */ 7706 alock.release(); 7707 onUSBDeviceStateChange(pUSBDevice, true /* aAttached */, NULL); 7708 } 7709 else 7671 7710 { 7672 7711 LogWarningThisFunc(("Failed to create proxy device for '%s' {%RTuuid} (%Rrc)\n", … … 7705 7744 //static 7706 7745 DECLCALLBACK(int) 7707 Console::usbAttachCallback(Console *that, PVM pVM, IUSBDevice *aHostDevice, PCRTUUID aUuid, bool aRemote, const char *aAddress, ULONG aMaskedIfs)7746 Console::usbAttachCallback(Console *that, PVM pVM, IUSBDevice *aHostDevice, PCRTUUID aUuid, bool aRemote, const char *aAddress, void *pvRemoteBackend, USHORT aPortVersion, ULONG aMaskedIfs) 7708 7747 { 7709 7748 LogFlowFuncEnter(); 7710 LogFlowFunc(("that={%p} \n", that));7749 LogFlowFunc(("that={%p} aUuid={%RTuuid}\n", that, aUuid)); 7711 7750 7712 7751 AssertReturn(that && aUuid, VERR_INVALID_PARAMETER); 7713 7714 void *pvRemoteBackend = NULL; 7715 if (aRemote) 7716 { 7717 RemoteUSBDevice *pRemoteUSBDevice = static_cast<RemoteUSBDevice *>(aHostDevice); 7718 Guid guid(*aUuid); 7719 7720 pvRemoteBackend = that->consoleVRDPServer()->USBBackendRequestPointer(pRemoteUSBDevice->clientId(), &guid); 7721 if (!pvRemoteBackend) 7722 return VERR_INVALID_PARAMETER; /* The clientId is invalid then. */ 7723 } 7724 7725 USHORT portVersion = 1; 7726 HRESULT hrc = aHostDevice->COMGETTER(PortVersion)(&portVersion); 7727 AssertComRCReturn(hrc, VERR_GENERAL_FAILURE); 7728 Assert(portVersion == 1 || portVersion == 2); 7752 AssertReturn(!that->isWriteLockOnCurrentThread(), VERR_GENERAL_FAILURE); 7729 7753 7730 7754 int vrc = PDMR3USBCreateProxyDevice(pVM, aUuid, aRemote, aAddress, pvRemoteBackend, 7731 portVersion == 1 ? VUSB_STDVER_11 : VUSB_STDVER_20, aMaskedIfs); 7732 if (RT_SUCCESS(vrc)) 7733 { 7734 /* Create a OUSBDevice and add it to the device list */ 7735 ComObjPtr<OUSBDevice> pUSBDevice; 7736 pUSBDevice.createObject(); 7737 hrc = pUSBDevice->init(aHostDevice); 7738 AssertComRC(hrc); 7739 7740 AutoWriteLock alock(that COMMA_LOCKVAL_SRC_POS); 7741 that->mUSBDevices.push_back(pUSBDevice); 7742 LogFlowFunc(("Attached device {%RTuuid}\n", pUSBDevice->id().raw())); 7743 7744 alock.release(); 7745 7746 /* notify callbacks */ 7747 that->onUSBDeviceStateChange(pUSBDevice, true /* aAttached */, NULL); 7748 } 7749 7755 aPortVersion == 1 ? VUSB_STDVER_11 : VUSB_STDVER_20, aMaskedIfs); 7750 7756 LogFlowFunc(("vrc=%Rrc\n", vrc)); 7751 7757 LogFlowFuncLeave(); … … 7758 7764 * collection. 7759 7765 * 7760 * @param a It Iterator pointing to the device to detach.7766 * @param aHostDevice device to attach 7761 7767 * 7762 7768 * @note Synchronously calls EMT. 7763 * @note Must be called from under this object's lock.7764 7769 */ 7765 HRESULT Console::detachUSBDevice( USBDeviceList::iterator &aIt)7766 { 7767 AssertReturn( isWriteLockOnCurrentThread(), E_FAIL);7770 HRESULT Console::detachUSBDevice(const ComObjPtr<OUSBDevice> &aHostDevice) 7771 { 7772 AssertReturn(!isWriteLockOnCurrentThread(), E_FAIL); 7768 7773 7769 7774 /* Get the VM handle. */ … … 7775 7780 AssertReturn(PDMR3USBHasHub(ptrVM), E_FAIL); 7776 7781 7782 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS); 7777 7783 LogFlowThisFunc(("Detaching USB proxy device {%RTuuid}...\n", 7778 (*aIt)->id().raw())); 7779 7780 /** @todo just do everything here and only wrap the PDMR3Usb call. That'll offload some notification stuff from the EMT thread. */ 7784 aHostDevice->id().raw())); 7785 7786 /* 7787 * If this was a remote device, release the backend pointer. 7788 * The pointer was requested in usbAttachCallback. 7789 */ 7790 BOOL fRemote = FALSE; 7791 7792 HRESULT hrc2 = aHostDevice->COMGETTER(Remote)(&fRemote); 7793 if (FAILED(hrc2)) 7794 setErrorStatic(hrc2, "GetRemote() failed"); 7795 7796 PCRTUUID pUuid = aHostDevice->id().raw(); 7797 if (fRemote) 7798 { 7799 Guid guid(*pUuid); 7800 consoleVRDPServer()->USBBackendReleasePointer(&guid); 7801 } 7802 7803 alock.release(); 7781 7804 int vrc = VMR3ReqCallWait(ptrVM, VMCPUID_ANY, 7782 7805 (PFNRT)usbDetachCallback, 5, 7783 this, ptrVM.raw(), &aIt, (*aIt)->id().raw()); 7806 this, ptrVM.raw(), pUuid); 7807 if (RT_SUCCESS(vrc)) 7808 { 7809 LogFlowFunc(("Detached device {%RTuuid}\n", pUuid)); 7810 7811 /* notify callbacks */ 7812 onUSBDeviceStateChange(aHostDevice, false /* aAttached */, NULL); 7813 } 7814 7784 7815 ComAssertRCRet(vrc, E_FAIL); 7785 7816 … … 7794 7825 * 7795 7826 * @thread EMT 7796 * @note Locks the console object for writing.7797 7827 */ 7798 7828 //static 7799 7829 DECLCALLBACK(int) 7800 Console::usbDetachCallback(Console *that, PVM pVM, USBDeviceList::iterator *aIt,PCRTUUID aUuid)7830 Console::usbDetachCallback(Console *that, PVM pVM, PCRTUUID aUuid) 7801 7831 { 7802 7832 LogFlowFuncEnter(); 7803 LogFlowFunc(("that={%p} \n", that));7833 LogFlowFunc(("that={%p} aUuid={%RTuuid}\n", that, aUuid)); 7804 7834 7805 7835 AssertReturn(that && aUuid, VERR_INVALID_PARAMETER); 7806 ComObjPtr<OUSBDevice> pUSBDevice = **aIt; 7807 7808 /* 7809 * If that was a remote device, release the backend pointer. 7810 * The pointer was requested in usbAttachCallback. 7811 */ 7812 BOOL fRemote = FALSE; 7813 7814 HRESULT hrc2 = (**aIt)->COMGETTER(Remote)(&fRemote); 7815 if (FAILED(hrc2)) 7816 setErrorStatic(hrc2, "GetRemote() failed"); 7817 7818 if (fRemote) 7819 { 7820 Guid guid(*aUuid); 7821 that->consoleVRDPServer()->USBBackendReleasePointer(&guid); 7822 } 7836 AssertReturn(!that->isWriteLockOnCurrentThread(), VERR_GENERAL_FAILURE); 7823 7837 7824 7838 int vrc = PDMR3USBDetachDevice(pVM, aUuid); 7825 7826 if (RT_SUCCESS(vrc))7827 {7828 AutoWriteLock alock(that COMMA_LOCKVAL_SRC_POS);7829 7830 /* Remove the device from the collection */7831 that->mUSBDevices.erase(*aIt);7832 LogFlowFunc(("Detached device {%RTuuid}\n", pUSBDevice->id().raw()));7833 7834 alock.release();7835 7836 /* notify callbacks */7837 that->onUSBDeviceStateChange(pUSBDevice, false /* aAttached */, NULL);7838 }7839 7839 7840 7840 LogFlowFunc(("vrc=%Rrc\n", vrc)); -
trunk/src/VBox/Main/src-server/HostImpl.cpp
r41174 r41528 5 5 6 6 /* 7 * Copyright (C) 200 6-2011Oracle Corporation7 * Copyright (C) 2004-2012 Oracle Corporation 8 8 * 9 9 * This file is part of VirtualBox Open Source Edition (OSE), as … … 173 173 Data() 174 174 : 175 #ifdef VBOX_WITH_USB176 usbListsLock(LOCKCLASS_USBLIST),177 #endif178 175 fDVDDrivesListBuilt(false), 179 176 fFloppyDrivesListBuilt(false) … … 183 180 184 181 #ifdef VBOX_WITH_USB 185 WriteLockHandle usbListsLock; // protects the below two lists186 187 182 USBDeviceFilterList llChildren; // all USB device filters 188 183 USBDeviceFilterList llUSBDeviceFilters; // USB device filters in use by the USB proxy service … … 779 774 if (FAILED(autoCaller.rc())) return autoCaller.rc(); 780 775 781 Auto MultiWriteLock2 alock(this->lockHandle(), &m->usbListsLockCOMMA_LOCKVAL_SRC_POS);776 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS); 782 777 783 778 HRESULT rc = checkUSBProxyService(); … … 1229 1224 if (FAILED(autoCaller.rc())) return autoCaller.rc(); 1230 1225 1231 Auto MultiWriteLock2 alock(this->lockHandle(), &m->usbListsLockCOMMA_LOCKVAL_SRC_POS);1226 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS); 1232 1227 1233 1228 clearError(); … … 1291 1286 if (FAILED(autoCaller.rc())) return autoCaller.rc(); 1292 1287 1293 Auto MultiWriteLock2 alock(this->lockHandle(), &m->usbListsLockCOMMA_LOCKVAL_SRC_POS);1288 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS); 1294 1289 1295 1290 clearError(); … … 1568 1563 if (FAILED(autoCaller.rc())) return autoCaller.rc(); 1569 1564 1570 Auto MultiWriteLock2 alock(this->lockHandle(), &m->usbListsLockCOMMA_LOCKVAL_SRC_POS);1565 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS); 1571 1566 1572 1567 for (settings::USBDeviceFiltersList::const_iterator it = data.llUSBDeviceFilters.begin(); … … 1602 1597 if (FAILED(autoCaller.rc())) return autoCaller.rc(); 1603 1598 1604 AutoReadLock alock1(this COMMA_LOCKVAL_SRC_POS); 1605 AutoReadLock alock2(&m->usbListsLock COMMA_LOCKVAL_SRC_POS); 1599 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS); 1606 1600 1607 1601 data.llUSBDeviceFilters.clear(); … … 2010 2004 if (FAILED(autoCaller.rc())) return autoCaller.rc(); 2011 2005 2012 AutoWriteLock alock( &m->usbListsLockCOMMA_LOCKVAL_SRC_POS);2006 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS); 2013 2007 2014 2008 m->llChildren.push_back(pChild); … … 2022 2016 if (FAILED(autoCaller.rc())) return autoCaller.rc(); 2023 2017 2024 AutoWriteLock alock( &m->usbListsLockCOMMA_LOCKVAL_SRC_POS);2018 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS); 2025 2019 2026 2020 for (USBDeviceFilterList::iterator it = m->llChildren.begin(); … … 2102 2096 void Host::getUSBFilters(Host::USBDeviceFilterList *aGlobalFilters) 2103 2097 { 2104 AutoReadLock alock( &m->usbListsLockCOMMA_LOCKVAL_SRC_POS);2098 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS); 2105 2099 2106 2100 *aGlobalFilters = m->llUSBDeviceFilters; -
trunk/src/VBox/Main/src-server/HostUSBDeviceImpl.cpp
r40257 r41528 5 5 6 6 /* 7 * Copyright (C) 200 6-2012 Oracle Corporation7 * Copyright (C) 2005-2012 Oracle Corporation 8 8 * 9 9 * This file is part of VirtualBox Open Source Edition (OSE), as … … 33 33 ///////////////////////////////////////////////////////////////////////////// 34 34 35 DEFINE_EMPTY_CTOR_DTOR 35 DEFINE_EMPTY_CTOR_DTOR(HostUSBDevice) 36 36 37 37 HRESULT HostUSBDevice::FinalConstruct() … … 114 114 if (mUsb != NULL) 115 115 { 116 USBProxyService::freeDevice 116 USBProxyService::freeDevice(mUsb); 117 117 mUsb = NULL; 118 118 } … … 189 189 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS); 190 190 191 Bstr 191 Bstr(mUsb->pszManufacturer).cloneTo(aManufacturer); 192 192 193 193 return S_OK; … … 203 203 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS); 204 204 205 Bstr 205 Bstr(mUsb->pszProduct).cloneTo(aProduct); 206 206 207 207 return S_OK; … … 217 217 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS); 218 218 219 Bstr 219 Bstr(mUsb->pszSerialNumber).cloneTo(aSerialNumber); 220 220 221 221 return S_OK; … … 231 231 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS); 232 232 233 Bstr 233 Bstr(mUsb->pszAddress).cloneTo(aAddress); 234 234 235 235 return S_OK; … … 305 305 ///////////////////////////////////////////////////////////////////////////// 306 306 307 STDMETHODIMP HostUSBDevice::COMGETTER(State) 307 STDMETHODIMP HostUSBDevice::COMGETTER(State)(USBDeviceState_T *aState) 308 308 { 309 309 CheckComArgOutPointerValid(aState); … … 331 331 332 332 AutoCaller autoCaller(this); 333 AssertComRCReturn 333 AssertComRCReturn(autoCaller.rc(), name); 334 334 335 335 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS); … … 338 338 bool haveProduct = mUsb->pszProduct && *mUsb->pszProduct; 339 339 if (haveManufacturer && haveProduct) 340 name = Utf8StrFmt 340 name = Utf8StrFmt("%s %s", mUsb->pszManufacturer, mUsb->pszProduct); 341 341 else if (haveManufacturer) 342 name = Utf8StrFmt 342 name = Utf8StrFmt("%s", mUsb->pszManufacturer); 343 343 else if (haveProduct) 344 name = Utf8StrFmt 344 name = Utf8StrFmt("%s", mUsb->pszProduct); 345 345 else 346 346 name = "<unknown>"; … … 365 365 * @retval E_UNEXPECTED if the device state doesn't permit for any attaching. 366 366 * @retval E_* as appropriate. 367 *368 * @note Must be called from under the object write lock.369 * @note May lock the given machine object for reading.370 367 */ 371 368 HRESULT HostUSBDevice::requestCaptureForVM(SessionMachine *aMachine, bool aSetError, ULONG aMaskedIfs /* = 0*/) 372 369 { 370 /* 371 * Validate preconditions and input. 372 */ 373 AssertReturn(aMachine, E_INVALIDARG); 374 AssertReturn(!isWriteLockOnCurrentThread(), E_FAIL); 375 AssertReturn(!aMachine->isWriteLockOnCurrentThread(), E_FAIL); 376 377 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS); 373 378 LogFlowThisFunc(("{%s} aMachine=%p aMaskedIfs=%#x\n", mName, aMachine, aMaskedIfs)); 374 379 375 /*376 * Validate preconditions and input.377 */378 AssertReturn(aMachine, E_INVALIDARG);379 AssertReturn(isWriteLockOnCurrentThread(), E_FAIL);380 380 if (aSetError) 381 381 { … … 391 391 { 392 392 /* Machine::name() requires a read lock */ 393 alock.release(); 393 394 AutoReadLock machLock(mMachine COMMA_LOCKVAL_SRC_POS); 394 395 return setError(E_INVALIDARG, … … 420 421 if (mUniState == kHostUSBDeviceState_HeldByProxy) 421 422 { 423 alock.release(); 422 424 HRESULT hrc = attachToVM(aMachine, aMaskedIfs); 423 425 return SUCCEEDED(hrc); … … 439 441 mMachine = aMachine; 440 442 mMaskedIfs = aMaskedIfs; 443 alock.release(); 441 444 int rc = mUSBProxyService->captureDevice(this); 442 445 if (RT_FAILURE(rc)) 443 446 { 447 alock.acquire(); 444 448 failTransition(); 445 449 mMachine.setNull(); … … 473 477 HRESULT HostUSBDevice::attachToVM(SessionMachine *aMachine, ULONG aMaskedIfs /* = 0*/) 474 478 { 479 AssertReturn(!isWriteLockOnCurrentThread(), E_FAIL); 480 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS); 475 481 /* 476 482 * Validate and update the state. … … 487 493 ComPtr<IUSBDevice> d = this; 488 494 489 AutoWriteLock alockSelf(this COMMA_LOCKVAL_SRC_POS);490 alockSelf.release();491 AutoWriteLock alockProxy(mUSBProxyService COMMA_LOCKVAL_SRC_POS);492 alockProxy.release();493 494 495 /* 495 496 * Call the VM process (IPC) and request it to attach the device. … … 500 501 */ 501 502 LogFlowThisFunc(("{%s} Calling machine->onUSBDeviceAttach()...\n", mName)); 502 HRESULT hrc = aMachine->onUSBDeviceAttach (d, NULL, aMaskedIfs); 503 alock.release(); 504 HRESULT hrc = aMachine->onUSBDeviceAttach(d, NULL, aMaskedIfs); 503 505 LogFlowThisFunc(("{%s} Done machine->onUSBDeviceAttach()=%08X\n", mName, hrc)); 504 506 … … 507 509 * physically detached while we were busy. 508 510 */ 509 alockProxy.acquire(); 510 alockSelf.acquire(); 511 alock.acquire(); 511 512 512 513 if (SUCCEEDED(hrc)) … … 517 518 else 518 519 { 520 alock.release(); 519 521 detachFromVM(kHostUSBDeviceState_PhysDetached); 520 522 hrc = E_UNEXPECTED; … … 532 534 else 533 535 { 536 alock.release(); 534 537 onPhysicalDetachedInternal(); 535 538 hrc = E_UNEXPECTED; … … 556 559 */ 557 560 Assert(aFinalState == kHostUSBDeviceState_PhysDetached); 561 AssertReturnVoid(!isWriteLockOnCurrentThread()); 562 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS); 558 563 Assert( mUniState == kHostUSBDeviceState_AttachingToVM 559 564 || mUniState == kHostUSBDeviceState_UsedByVM); … … 566 571 */ 567 572 setState(kHostUSBDeviceState_PhysDetachingFromVM, kHostUSBDeviceState_PhysDetached); 568 AutoWriteLock alockSelf(this COMMA_LOCKVAL_SRC_POS);569 alockSelf.release();570 AutoWriteLock alockProxy(mUSBProxyService COMMA_LOCKVAL_SRC_POS);571 alockProxy.release();572 573 573 574 /* … … 578 579 * out of people. 579 580 */ 581 alock.release(); 580 582 LogFlowThisFunc(("{%s} Calling machine->onUSBDeviceDetach()...\n", mName)); 581 583 HRESULT hrc = mMachine->onUSBDeviceDetach(mId.toUtf16().raw(), NULL); … … 586 588 * Re-acquire the locks and complete the transition. 587 589 */ 588 alockProxy.acquire(); 589 alockSelf.acquire(); 590 alock.acquire(); 590 591 advanceTransition(); 591 592 } … … 672 673 * @retval E_* as appropriate. 673 674 * 674 * @note Must be called from under the object writelock.675 * @note Must be called without holding the object lock. 675 676 */ 676 677 HRESULT HostUSBDevice::requestReleaseToHost() 677 678 { 679 /* 680 * Validate preconditions. 681 */ 682 AssertReturn(!isWriteLockOnCurrentThread(), E_FAIL); 683 Assert(mMachine.isNull()); 684 685 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS); 678 686 LogFlowThisFunc(("{%s}\n", mName)); 679 680 /*681 * Validate preconditions.682 */683 AssertReturn(isWriteLockOnCurrentThread(), E_FAIL);684 Assert(mMachine.isNull());685 687 if ( mUniState == kHostUSBDeviceState_Unused 686 688 || mUniState == kHostUSBDeviceState_Capturable) … … 697 699 startTransition(kHostUSBDeviceState_ReleasingToHost, kHostUSBDeviceState_Unused); 698 700 #endif 701 alock.release(); 699 702 int rc = mUSBProxyService->releaseDevice(this); 700 703 if (RT_FAILURE(rc)) 701 704 { 705 alock.acquire(); 702 706 failTransition(); 703 707 return E_FAIL; … … 718 722 * @retval E_* as appropriate. 719 723 * 720 * @note Must be called from under the object writelock.724 * @note Must be called without holding the object lock. 721 725 */ 722 726 HRESULT HostUSBDevice::requestHold() 723 727 { 728 /* 729 * Validate preconditions. 730 */ 731 AssertReturn(!isWriteLockOnCurrentThread(), E_FAIL); 732 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS); 724 733 LogFlowThisFunc(("{%s}\n", mName)); 725 726 /*727 * Validate preconditions.728 */729 AssertReturn(isWriteLockOnCurrentThread(), E_FAIL);730 734 AssertMsgReturn( mUniState == kHostUSBDeviceState_Unused 731 735 || mUniState == kHostUSBDeviceState_Capturable … … 749 753 startTransition(kHostUSBDeviceState_Capturing, kHostUSBDeviceState_HeldByProxy); 750 754 #endif 755 alock.release(); 751 756 int rc = mUSBProxyService->captureDevice(this); 752 757 if (RT_FAILURE(rc)) 753 758 { 759 alock.acquire(); 754 760 failTransition(); 755 761 return E_FAIL; … … 796 802 #ifndef RT_OS_WINDOWS /* check the implementation details here. */ 797 803 uint64_t elapsedNanoseconds = RTTimeNanoTS() - mLastStateChangeTS; 798 if (elapsedNanoseconds > UINT64_C (60000000000)) /* 60 seconds */804 if (elapsedNanoseconds > UINT64_C(60000000000)) /* 60 seconds */ 799 805 { 800 LogRel 806 LogRel(("USB: Async operation timed out for device %s (state: %s)\n", mName, getStateName())); 801 807 failTransition(); 802 808 } … … 823 829 824 830 default: 825 AssertLogRelMsgFailed 831 AssertLogRelMsgFailed(("this=%p %s\n", this, getStateName())); 826 832 break; 827 833 } … … 838 844 * 839 845 * Otherwise the device will be detached from any VM currently using it - this 840 * involves IPC and will temporarily abandon dlocks - and all the device data846 * involves IPC and will temporarily abandon locks - and all the device data 841 847 * reset. 842 *843 * @note Must be called from under the object write lock.844 848 */ 845 849 void HostUSBDevice::onPhysicalDetached() 846 850 { 851 AssertReturnVoid(!isWriteLockOnCurrentThread()); 852 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS); 847 853 LogFlowThisFunc(("{%s}\n", mName)); 848 AssertReturnVoid(isWriteLockOnCurrentThread());849 854 850 855 mIsPhysicallyDetached = true; 851 856 if (mUniState < kHostUSBDeviceState_FirstTransitional) 857 { 858 alock.release(); 852 859 onPhysicalDetachedInternal(); 860 } 853 861 } 854 862 … … 859 867 * 860 868 * See onPhysicalDetach() for details. 861 *862 * @note Must be called from under the object write lock.863 869 */ 864 870 void HostUSBDevice::onPhysicalDetachedInternal() 865 871 { 872 AssertReturnVoid(!isWriteLockOnCurrentThread()); 873 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS); 866 874 LogFlowThisFunc(("{%s}\n", mName)); 867 AssertReturnVoid(isWriteLockOnCurrentThread());868 875 Assert(mIsPhysicallyDetached); 869 876 … … 874 881 && ( mUniState == kHostUSBDeviceState_UsedByVM 875 882 || mUniState == kHostUSBDeviceState_AttachingToVM)) 883 { 884 alock.release(); 876 885 detachFromVM(kHostUSBDeviceState_PhysDetached); 886 alock.acquire(); 887 } 877 888 else 878 889 AssertMsg(mMachine.isNull(), ("%s\n", getStateName())); … … 1061 1072 * @returns Whether the Host object should be bothered with this state change. 1062 1073 * 1063 * @note Locks this object for writing.1064 *1065 1074 * @todo Just do everything here, that is, call filter runners and everything that 1066 1075 * works by state change. Using 3 return codes/parameters is just plain ugly. … … 1074 1083 * Locking. 1075 1084 */ 1076 AssertReturn( isWriteLockOnCurrentThread(), false);1085 AssertReturn(!isWriteLockOnCurrentThread(), false); 1077 1086 AutoCaller autoCaller(this); 1078 1087 AssertComRCReturn(autoCaller.rc(), false); 1079 1088 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS); 1080 1081 1089 1082 1090 /* … … 1138 1146 aDev->pNext = mUsb->pNext; 1139 1147 aDev->pPrev = mUsb->pPrev; 1140 USBProxyService::freeDevice 1148 USBProxyService::freeDevice(mUsb); 1141 1149 mUsb = aDev; 1142 1150 } … … 1474 1482 * 1475 1483 * @returns See HostUSBDevice::updateState() 1476 *1477 * @note Caller must write lock the object.1478 1484 */ 1479 1485 bool HostUSBDevice::updateStateFake(PCUSBDEVICE aDev, bool *aRunFilters, SessionMachine **aIgnoreMachine) 1480 1486 { 1487 Assert(!isWriteLockOnCurrentThread()); 1488 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS); 1481 1489 const HostUSBDeviceState enmState = mUniState; 1482 1490 switch (enmState) … … 1485 1493 case kHostUSBDeviceState_ReleasingToHost: 1486 1494 { 1487 Assert(isWriteLockOnCurrentThread());1488 1489 1495 *aIgnoreMachine = mUniState == kHostUSBDeviceState_ReleasingToHost ? mMachine : NULL; 1490 1496 *aRunFilters = advanceTransition(); … … 1507 1513 /* Take action if we're supposed to attach it to a VM. */ 1508 1514 if (mUniState == kHostUSBDeviceState_AttachingToVM) 1515 { 1516 alock.release(); 1509 1517 attachToVM(mMachine, mMaskedIfs); 1518 } 1510 1519 return true; 1511 1520 } 1512 1521 1513 1522 default: 1523 alock.release(); 1514 1524 return updateState(aDev, aRunFilters, aIgnoreMachine); 1515 1525 } … … 1807 1817 break; 1808 1818 default: 1809 AssertLogRelMsgFailedReturn 1810 1819 AssertLogRelMsgFailedReturn(("this=%p %s -X-> %s\n", this, getStateName(), 1820 stateName(aNewState, aNewPendingState, aNewSubState)), false); 1811 1821 } 1812 1822 break; … … 1835 1845 break; 1836 1846 default: 1837 AssertLogRelMsgFailedReturn 1838 1847 AssertLogRelMsgFailedReturn(("this=%p %s -X-> %s\n", this, getStateName(), 1848 stateName(aNewState, aNewPendingState, aNewSubState)), false); 1839 1849 } 1840 1850 break; 1841 1851 default: 1842 AssertLogRelMsgFailedReturn 1843 1852 AssertLogRelMsgFailedReturn(("this=%p %s -X-> %s\n", this, getStateName(), 1853 stateName(aNewState, aNewPendingState, aNewSubState)), false); 1844 1854 } 1845 1855 break; … … 1864 1874 break; 1865 1875 default: 1866 AssertLogRelMsgFailedReturn 1867 1876 AssertLogRelMsgFailedReturn(("this=%p %s -X-> %s\n", this, getStateName(), 1877 stateName(aNewState, aNewPendingState, aNewSubState)), false); 1868 1878 } 1869 1879 break; 1870 1880 default: 1871 AssertLogRelMsgFailedReturn 1872 1881 AssertLogRelMsgFailedReturn(("this=%p %s -X-> %s\n", this, getStateName(), 1882 stateName(aNewState, aNewPendingState, aNewSubState)), false); 1873 1883 } 1874 1884 break; … … 1893 1903 break; 1894 1904 default: 1895 AssertLogRelMsgFailedReturn 1896 1905 AssertLogRelMsgFailedReturn(("this=%p %s -X-> %s\n", this, getStateName(), 1906 stateName(aNewState, aNewPendingState, aNewSubState)), false); 1897 1907 } 1898 1908 break; … … 1903 1913 break; 1904 1914 default: 1905 AssertLogRelMsgFailedReturn 1906 1915 AssertLogRelMsgFailedReturn(("this=%p %s -X-> %s\n", this, getStateName(), 1916 stateName(aNewState, aNewPendingState, aNewSubState)), false); 1907 1917 } 1908 1918 break; 1909 1919 default: 1910 AssertLogRelMsgFailedReturn 1911 1920 AssertLogRelMsgFailedReturn(("this=%p %s -X-> %s\n", this, getStateName(), 1921 stateName(aNewState, aNewPendingState, aNewSubState)), false); 1912 1922 } 1913 1923 break; … … 1931 1941 break; 1932 1942 default: 1933 AssertLogRelMsgFailedReturn 1934 1943 AssertLogRelMsgFailedReturn(("this=%p %s -X-> %s\n", this, getStateName(), 1944 stateName(aNewState, aNewPendingState, aNewSubState)), false); 1935 1945 } 1936 1946 break; 1937 1947 default: 1938 AssertLogRelMsgFailedReturn 1939 1948 AssertLogRelMsgFailedReturn(("this=%p %s -X-> %s\n", this, getStateName(), 1949 stateName(aNewState, aNewPendingState, aNewSubState)), false); 1940 1950 } 1941 1951 break; … … 1961 1971 case kHostUSBDeviceState_UsedByVM: 1962 1972 default: 1963 AssertLogRelMsgFailedReturn 1964 1973 AssertLogRelMsgFailedReturn(("this=%p %s -X-> %s\n", this, getStateName(), 1974 stateName(aNewState, aNewPendingState, aNewSubState)), false); 1965 1975 } 1966 1976 break; … … 2013 2023 2014 2024 default: 2015 AssertLogRelMsgFailedReturn 2016 2025 AssertLogRelMsgFailedReturn(("this=%p %s -X-> %s\n", this, getStateName(), 2026 stateName(aNewState, aNewPendingState, aNewSubState)), false); 2017 2027 } 2018 2028 break; … … 2057 2067 2058 2068 default: 2059 AssertLogRelMsgFailedReturn 2060 2069 AssertLogRelMsgFailedReturn(("this=%p %s -X-> %s\n", this, getStateName(), 2070 stateName(aNewState, aNewPendingState, aNewSubState)), false); 2061 2071 } 2062 2072 break; … … 2086 2096 2087 2097 default: 2088 AssertLogRelMsgFailedReturn 2089 2098 AssertLogRelMsgFailedReturn(("this=%p %s -X-> %s\n", this, getStateName(), 2099 stateName(aNewState, aNewPendingState, aNewSubState)), false); 2090 2100 } 2091 2101 break; … … 2122 2132 2123 2133 default: 2124 AssertLogRelMsgFailedReturn 2125 2134 AssertLogRelMsgFailedReturn(("this=%p %s -X-> %s\n", this, getStateName(), 2135 stateName(aNewState, aNewPendingState, aNewSubState)), false); 2126 2136 } 2127 2137 break; … … 2139 2149 break; 2140 2150 default: 2141 AssertLogRelMsgFailedReturn 2142 2151 AssertLogRelMsgFailedReturn(("this=%p %s -X-> %s\n", this, getStateName(), 2152 stateName(aNewState, aNewPendingState, aNewSubState)), false); 2143 2153 } 2144 2154 break; 2145 2155 2146 2156 default: 2147 AssertReleaseMsgFailedReturn 2157 AssertReleaseMsgFailedReturn(("this=%p mUniState=%d\n", this, mUniState), false); 2148 2158 } 2149 2159 … … 2168 2178 2169 2179 2170 2171 2180 /** 2172 2181 * A convenience for entering a transitional state. … … 2180 2189 * @note The caller must own the write lock for this object. 2181 2190 */ 2182 bool HostUSBDevice::startTransition (HostUSBDeviceState aNewState, HostUSBDeviceState aFinalState, 2183 HostUSBDeviceSubState aNewSubState /*= kHostUSBDeviceSubState_Default*/) 2184 { 2191 bool HostUSBDevice::startTransition(HostUSBDeviceState aNewState, HostUSBDeviceState aFinalState, 2192 HostUSBDeviceSubState aNewSubState /*= kHostUSBDeviceSubState_Default*/) 2193 { 2194 AssertReturn(isWriteLockOnCurrentThread(), false); 2185 2195 /* 2186 2196 * A quick prevalidation thing. Not really necessary since setState … … 2202 2212 case kHostUSBDeviceState_AttachingToVM: 2203 2213 case kHostUSBDeviceState_PhysDetachingFromVM: 2204 AssertMsgFailedReturn 2214 AssertMsgFailedReturn(("this=%p %s is a transitional state.\n", this, getStateName()), false); 2205 2215 2206 2216 case kHostUSBDeviceState_PhysDetached: 2207 2217 default: 2208 AssertReleaseMsgFailedReturn 2209 } 2210 2211 return setState 2218 AssertReleaseMsgFailedReturn(("this=%p mUniState=%d\n", this, mUniState), false); 2219 } 2220 2221 return setState(aNewState, aFinalState, aNewSubState); 2212 2222 } 2213 2223 … … 2225 2235 bool HostUSBDevice::advanceTransition(bool aSkipReAttach /* = false */) 2226 2236 { 2237 AssertReturn(isWriteLockOnCurrentThread(), false); 2227 2238 HostUSBDeviceState enmPending = mPendingUniState; 2228 2239 HostUSBDeviceSubState enmSub = mUniSubState; … … 2386 2397 bool HostUSBDevice::failTransition() 2387 2398 { 2399 AssertReturn(isWriteLockOnCurrentThread(), false); 2388 2400 HostUSBDeviceSubState enmSub = mUniSubState; 2389 2401 HostUSBDeviceState enmState = mUniState; … … 2412 2424 break; 2413 2425 default: 2414 AssertReleaseMsgFailedReturn 2426 AssertReleaseMsgFailedReturn(("this=%p mUniState=%d\n", this, mUniState), false); 2415 2427 } 2416 2428 break; 2417 2429 2418 2430 case kHostUSBDeviceState_PhysDetachingFromVM: 2419 AssertMsgFailedReturn 2431 AssertMsgFailedReturn(("this=%p %s shall not fail\n", this, getStateName()), false); 2420 2432 2421 2433 case kHostUSBDeviceState_Unsupported: … … 2425 2437 case kHostUSBDeviceState_HeldByProxy: 2426 2438 case kHostUSBDeviceState_UsedByVM: 2427 AssertMsgFailedReturn 2439 AssertMsgFailedReturn(("this=%p %s is not transitional\n", this, getStateName()), false); 2428 2440 case kHostUSBDeviceState_PhysDetached: 2429 2441 default: 2430 AssertReleaseMsgFailedReturn 2442 AssertReleaseMsgFailedReturn(("this=%p mUniState=%d\n", this, mUniState), false); 2431 2443 2432 2444 } … … 2502 2514 case kHostUSBDeviceState_PhysDetached: 2503 2515 default: 2504 AssertReleaseMsgFailedReturn 2516 AssertReleaseMsgFailedReturn(("this=%p mUniState=%d\n", this, mUniState), USBDeviceState_NotSupported); 2505 2517 } 2506 2518 /* won't ever get here. */ -
trunk/src/VBox/Main/src-server/MachineImpl.cpp
r41371 r41528 5 5 6 6 /* 7 * Copyright (C) 200 6-2012 Oracle Corporation7 * Copyright (C) 2004-2012 Oracle Corporation 8 8 * 9 9 * This file is part of VirtualBox Open Source Edition (OSE), as … … 12673 12673 * filter for the given USB device and @c false otherwise. 12674 12674 * 12675 * @note Caller must have requested machine read lock.12675 * @note locks this object for reading. 12676 12676 */ 12677 12677 bool SessionMachine::hasMatchingUSBFilter(const ComObjPtr<HostUSBDevice> &aDevice, ULONG *aMaskedIfs) … … 12683 12683 return false; 12684 12684 12685 12686 12685 #ifdef VBOX_WITH_USB 12686 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS); 12687 12687 12688 switch (mData->mMachineState) 12688 12689 { … … 12694 12695 /** @todo Live Migration: snapshoting & teleporting. Need to fend things of 12695 12696 * elsewhere... */ 12697 alock.release(); 12696 12698 return mUSBController->hasMatchingFilter(aDevice, aMaskedIfs); 12697 12699 default: break; -
trunk/src/VBox/Main/src-server/USBProxyService.cpp
r37599 r41528 5 5 6 6 /* 7 * Copyright (C) 2006-20 07Oracle Corporation7 * Copyright (C) 2006-2012 Oracle Corporation 8 8 * 9 9 * This file is part of VirtualBox Open Source Edition (OSE), as … … 140 140 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS); 141 141 142 SafeIfaceArray<IHostUSBDevice> Collection 142 SafeIfaceArray<IHostUSBDevice> Collection(mDevices); 143 143 Collection.detachTo(ComSafeArrayOutArg(aUSBDevices)); 144 144 … … 181 181 * Try to capture the device 182 182 */ 183 AutoWriteLock DevLock(pHostDevice COMMA_LOCKVAL_SRC_POS);183 alock.release(); 184 184 return pHostDevice->requestCaptureForVM(aMachine, true /* aSetError */); 185 185 } … … 224 224 ComObjPtr<HostUSBDevice> pHostDevice = findDeviceById(aId); 225 225 ComAssertRet(!pHostDevice.isNull(), E_FAIL); 226 AutoWriteLock DevLock(pHostDevice COMMA_LOCKVAL_SRC_POS);226 AutoWriteLock devLock(pHostDevice COMMA_LOCKVAL_SRC_POS); 227 227 228 228 /* … … 241 241 { 242 242 Assert(aDone && pHostDevice->getUnistate() == kHostUSBDeviceState_HeldByProxy && pHostDevice->getMachine().isNull()); 243 devLock.release(); 244 alock.release(); 243 245 HRESULT hrc2 = runAllFiltersOnDevice(pHostDevice, llOpenedMachines, aMachine); 244 246 ComAssertComRC(hrc2); … … 265 267 * @returns COM status code, perhaps with error info. 266 268 * 267 * @remarks Write locks the host object and may temporarily abandon268 * its locks to perform IPC.269 * @remarks Temporarily locks this object, the machine object and some USB 270 * device, and the called methods will lock similar objects. 269 271 */ 270 272 HRESULT USBProxyService::autoCaptureDevicesForVM(SessionMachine *aMachine) … … 273 275 aMachine, 274 276 aMachine->getName().c_str())); 275 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS); 276 AutoWriteLock mlock(aMachine COMMA_LOCKVAL_SRC_POS); 277 278 /* 279 * Make a copy of the list because we might have to exit and 280 * re-enter the lock protecting it. (This will not make copies 281 * of any HostUSBDevice objects, only reference them.) 282 */ 277 278 /* 279 * Make a copy of the list because we cannot hold the lock protecting it. 280 * (This will not make copies of any HostUSBDevice objects, only reference them.) 281 */ 282 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS); 283 283 HostUSBDeviceList ListCopy = mDevices; 284 alock.release(); 284 285 285 286 for (HostUSBDeviceList::iterator it = ListCopy.begin(); … … 288 289 { 289 290 ComObjPtr<HostUSBDevice> device = *it; 290 Auto WriteLock devLock(device COMMA_LOCKVAL_SRC_POS);291 AutoReadLock devLock(device COMMA_LOCKVAL_SRC_POS); 291 292 if ( device->getUnistate() == kHostUSBDeviceState_HeldByProxy 292 293 || device->getUnistate() == kHostUSBDeviceState_Unused 293 294 || device->getUnistate() == kHostUSBDeviceState_Capturable) 295 { 296 devLock.release(); 294 297 runMachineFilters(aMachine, device); 298 } 295 299 } 296 300 … … 323 327 { 324 328 // get a list of all running machines while we're outside the lock 325 // (getOpenedMachines requests locks which are incompatible with the lock of the machines list)329 // (getOpenedMachines requests locks which are incompatible with the host object lock) 326 330 SessionMachinesList llOpenedMachines; 327 331 mHost->parent()->getOpenedMachines(llOpenedMachines); … … 336 340 HostUSBDeviceList ListCopy = mDevices; 337 341 338 for (HostUSBDeviceList::iterator It = ListCopy.begin();339 It != ListCopy.end();340 ++ It)341 { 342 ComObjPtr<HostUSBDevice> pHostDevice = * It;342 for (HostUSBDeviceList::iterator it = ListCopy.begin(); 343 it != ListCopy.end(); 344 ++it) 345 { 346 ComObjPtr<HostUSBDevice> pHostDevice = *it; 343 347 AutoWriteLock devLock(pHostDevice COMMA_LOCKVAL_SRC_POS); 344 348 if (pHostDevice->getMachine() == aMachine) … … 353 357 { 354 358 Assert(aDone && pHostDevice->getUnistate() == kHostUSBDeviceState_HeldByProxy && pHostDevice->getMachine().isNull()); 359 devLock.release(); 360 alock.release(); 355 361 HRESULT hrc2 = runAllFiltersOnDevice(pHostDevice, llOpenedMachines, aMachine); 356 362 ComAssertComRC(hrc2); 363 alock.acquire(); 357 364 } 358 365 } … … 382 389 * detached the device from this machine). 383 390 * 384 * @note The caller is expected to own both the device and Host write locks, 385 * and be prepared that these locks may be abandond temporarily. 391 * @note The caller is expected to own no locks. 386 392 */ 387 393 HRESULT USBProxyService::runAllFiltersOnDevice(ComObjPtr<HostUSBDevice> &aDevice, … … 394 400 * Verify preconditions. 395 401 */ 396 AssertReturn(isWriteLockOnCurrentThread(), E_FAIL); 397 AssertReturn(aDevice->isWriteLockOnCurrentThread(), E_FAIL); 402 AssertReturn(!isWriteLockOnCurrentThread(), E_FAIL); 403 AssertReturn(!aDevice->isWriteLockOnCurrentThread(), E_FAIL); 404 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS); 405 AutoWriteLock devLock(aDevice COMMA_LOCKVAL_SRC_POS); 398 406 AssertMsgReturn(aDevice->isCapturableOrHeld(), ("{%s} %s\n", aDevice->getName().c_str(), aDevice->getStateName()), E_FAIL); 399 407 … … 406 414 407 415 /* 408 * Run global filters fil erts first.416 * Run global filters filters first. 409 417 */ 410 418 bool fHoldIt = false; … … 424 432 * Release the device to the host and we're done. 425 433 */ 434 filterLock.release(); 435 devLock.release(); 436 alock.release(); 426 437 aDevice->requestReleaseToHost(); 427 438 return S_OK; … … 456 467 457 468 /* runMachineFilters takes care of checking the machine state. */ 469 devLock.release(); 470 alock.release(); 458 471 if (runMachineFilters(pMachine, aDevice)) 459 472 { … … 461 474 return S_OK; 462 475 } 476 alock.acquire(); 477 devLock.acquire(); 463 478 } 464 479 … … 467 482 * on global filter match. 468 483 */ 484 devLock.release(); 485 alock.release(); 469 486 if (fHoldIt) 470 487 aDevice->requestHold(); … … 485 502 * @returns @c true if the device has been or is being attached to the VM, @c false otherwise. 486 503 * 487 * @note Caller must own the USB and device locks for writing. 488 * @note Locks aMachine for reading. 504 * @note Locks several objects temporarily for reading or writing. 489 505 */ 490 506 bool USBProxyService::runMachineFilters(SessionMachine *aMachine, ComObjPtr<HostUSBDevice> &aDevice) … … 496 512 */ 497 513 AssertReturn(aMachine, false); 498 AssertReturn(isWriteLockOnCurrentThread(), false); 499 AssertReturn(aDevice->isWriteLockOnCurrentThread(), false); 514 AssertReturn(!isWriteLockOnCurrentThread(), false); 515 AssertReturn(!aMachine->isWriteLockOnCurrentThread(), false); 516 AssertReturn(!aDevice->isWriteLockOnCurrentThread(), false); 500 517 /* Let HostUSBDevice::requestCaptureToVM() validate the state. */ 501 518 … … 574 591 * 575 592 * @param aDevice The device in question. 593 * 594 * @todo unused 576 595 */ 577 596 void USBProxyService::detachingDevice(HostUSBDevice *aDevice) … … 820 839 } 821 840 841 LogFlowFuncLeave(); 822 842 return pHead; 823 843 } … … 840 860 841 861 // get a list of all running machines while we're outside the lock 842 // (getOpenedMachines requests locks which are incompatible with the lock of the machines list)862 // (getOpenedMachines requests higher priority locks) 843 863 SessionMachinesList llOpenedMachines; 844 864 mHost->parent()->getOpenedMachines(llOpenedMachines); … … 847 867 848 868 /* 849 * Compare previous list with the previouslist of devices869 * Compare previous list with the new list of devices 850 870 * and merge in any changes while notifying Host. 851 871 */ 852 HostUSBDeviceList::iterator It = this->mDevices.begin();853 while ( It != mDevices.end()872 HostUSBDeviceList::iterator it = this->mDevices.begin(); 873 while ( it != mDevices.end() 854 874 || pDevices) 855 875 { 856 876 ComObjPtr<HostUSBDevice> pHostDevice; 857 877 858 if ( It != mDevices.end())859 pHostDevice = * It;878 if (it != mDevices.end()) 879 pHostDevice = *it; 860 880 861 881 /* … … 898 918 bool fRunFilters = false; 899 919 SessionMachine *pIgnoreMachine = NULL; 920 devLock.release(); 921 alock.release(); 900 922 if (updateDeviceState(pHostDevice, pCur, &fRunFilters, &pIgnoreMachine)) 901 923 deviceChanged(pHostDevice, 902 924 (fRunFilters ? &llOpenedMachines : NULL), 903 925 pIgnoreMachine); 904 It++; 926 alock.acquire(); 927 it++; 905 928 } 906 929 else … … 928 951 pNew->pszManufacturer)); 929 952 930 mDevices.insert( It, NewObj);931 932 /* Not really necessary to lock here, but make Assert checks happy. */933 AutoWriteLock newDevLock(NewObj COMMA_LOCKVAL_SRC_POS);953 mDevices.insert(it, NewObj); 954 955 devLock.release(); 956 alock.release(); 934 957 deviceAdded(NewObj, llOpenedMachines, pNew); 958 alock.acquire(); 935 959 } 936 960 else … … 941 965 */ 942 966 if (!pHostDevice->wasActuallyDetached()) 943 It++;967 it++; 944 968 else 945 969 { 946 It = mDevices.erase(It); 970 it = mDevices.erase(it); 971 devLock.release(); 972 alock.release(); 947 973 deviceRemoved(pHostDevice); 948 974 Log(("USBProxyService::processChanges: detached %p {%s}\n", … … 954 980 devCaller.release(); 955 981 pHostDevice->uninit(); 982 alock.acquire(); 956 983 } 957 984 } … … 993 1020 * Validate preconditions. 994 1021 */ 995 AssertReturnVoid(isWriteLockOnCurrentThread()); 996 AssertReturnVoid(aDevice->isWriteLockOnCurrentThread()); 1022 AssertReturnVoid(!isWriteLockOnCurrentThread()); 1023 AssertReturnVoid(!aDevice->isWriteLockOnCurrentThread()); 1024 AutoReadLock devLock(aDevice COMMA_LOCKVAL_SRC_POS); 997 1025 LogFlowThisFunc(("aDevice=%p name={%s} state=%s id={%RTuuid}\n", 998 1026 (HostUSBDevice *)aDevice, … … 1006 1034 if (aDevice->isCapturableOrHeld()) 1007 1035 { 1036 devLock.release(); 1008 1037 HRESULT rc = runAllFiltersOnDevice(aDevice, llOpenedMachines, NULL /* aIgnoreMachine */); 1009 1038 AssertComRC(rc); … … 1026 1055 * Validate preconditions. 1027 1056 */ 1028 AssertReturnVoid(isWriteLockOnCurrentThread()); 1029 AssertReturnVoid(aDevice->isWriteLockOnCurrentThread()); 1057 AssertReturnVoid(!isWriteLockOnCurrentThread()); 1058 AssertReturnVoid(!aDevice->isWriteLockOnCurrentThread()); 1059 AutoWriteLock devLock(aDevice COMMA_LOCKVAL_SRC_POS); 1030 1060 LogFlowThisFunc(("aDevice=%p name={%s} state=%s id={%RTuuid}\n", 1031 1061 (HostUSBDevice *)aDevice, … … 1038 1068 * reset all data and uninitialize the device object. 1039 1069 */ 1070 devLock.release(); 1040 1071 aDevice->onPhysicalDetached(); 1041 1072 } … … 1055 1086 *aIgnoreMachine = NULL; 1056 1087 AssertReturn(aDevice, false); 1057 AssertReturn( aDevice->isWriteLockOnCurrentThread(), false);1088 AssertReturn(!aDevice->isWriteLockOnCurrentThread(), false); 1058 1089 1059 1090 /* … … 1078 1109 { 1079 1110 AssertReturn(aDevice, false); 1080 AssertReturn( aDevice->isWriteLockOnCurrentThread(), false);1111 AssertReturn(!aDevice->isWriteLockOnCurrentThread(), false); 1081 1112 1082 1113 return aDevice->updateState(aUSBDevice, aRunFilters, aIgnoreMachine); … … 1099 1130 * Validate preconditions. 1100 1131 */ 1101 AssertReturnVoid(isWriteLockOnCurrentThread()); 1102 AssertReturnVoid(aDevice->isWriteLockOnCurrentThread()); 1132 AssertReturnVoid(!isWriteLockOnCurrentThread()); 1133 AssertReturnVoid(!aDevice->isWriteLockOnCurrentThread()); 1134 AutoReadLock devLock(aDevice COMMA_LOCKVAL_SRC_POS); 1103 1135 LogFlowThisFunc(("aDevice=%p name={%s} state=%s id={%RTuuid} aRunFilters=%RTbool aIgnoreMachine=%p\n", 1104 1136 (HostUSBDevice *)aDevice, … … 1108 1140 (pllOpenedMachines != NULL), // used to be "bool aRunFilters" 1109 1141 aIgnoreMachine)); 1142 devLock.release(); 1110 1143 1111 1144 /* … … 1212 1245 Guid Id(aId); 1213 1246 ComObjPtr<HostUSBDevice> Dev; 1214 for (HostUSBDeviceList::iterator It = mDevices.begin();1215 It != mDevices.end();1216 ++ It)1217 if ((* It)->getId() == Id)1247 for (HostUSBDeviceList::iterator it = mDevices.begin(); 1248 it != mDevices.end(); 1249 ++it) 1250 if ((*it)->getId() == Id) 1218 1251 { 1219 Dev = (* It);1252 Dev = (*it); 1220 1253 break; 1221 1254 } -
trunk/src/VBox/Main/src-server/darwin/USBProxyServiceDarwin.cpp
r37599 r41528 5 5 6 6 /* 7 * Copyright (C) 200 6-2010Oracle Corporation7 * Copyright (C) 2005-2012 Oracle Corporation 8 8 * 9 9 * This file is part of VirtualBox Open Source Edition (OSE), as … … 39 39 * Initialize data members. 40 40 */ 41 USBProxyServiceDarwin::USBProxyServiceDarwin 42 : USBProxyService (aHost), mServiceRunLoopRef (NULL), mNotifyOpaque (NULL), mWaitABitNextTime (false), mUSBLibInitialized(false)41 USBProxyServiceDarwin::USBProxyServiceDarwin(Host *aHost) 42 : USBProxyService(aHost), mServiceRunLoopRef(NULL), mNotifyOpaque(NULL), mWaitABitNextTime(false), mUSBLibInitialized(false) 43 43 { 44 44 LogFlowThisFunc(("aHost=%p\n", aHost)); … … 101 101 102 102 #ifdef VBOX_WITH_NEW_USB_CODE_ON_DARWIN 103 void *USBProxyServiceDarwin::insertFilter 104 { 105 return USBLibAddFilter 106 } 107 108 109 void USBProxyServiceDarwin::removeFilter 110 { 111 USBLibRemoveFilter 103 void *USBProxyServiceDarwin::insertFilter(PCUSBFILTER aFilter) 104 { 105 return USBLibAddFilter(aFilter); 106 } 107 108 109 void USBProxyServiceDarwin::removeFilter(void *aId) 110 { 111 USBLibRemoveFilter(aId); 112 112 } 113 113 #endif /* VBOX_WITH_NEW_USB_CODE_ON_DARWIN */ … … 120 120 */ 121 121 AssertReturn(aDevice, VERR_GENERAL_FAILURE); 122 AssertReturn(!aDevice->isWriteLockOnCurrentThread(), VERR_GENERAL_FAILURE); 123 124 AutoReadLock devLock(aDevice COMMA_LOCKVAL_SRC_POS); 122 125 LogFlowThisFunc(("aDevice=%s\n", aDevice->getName().c_str())); 123 AssertReturn(aDevice->isWriteLockOnCurrentThread(), VERR_GENERAL_FAILURE); 126 124 127 Assert(aDevice->getUnistate() == kHostUSBDeviceState_Capturing); 125 128 … … 129 132 */ 130 133 ASMAtomicWriteBool(&mFakeAsync, true); 134 devLock.release(); 131 135 interruptWait(); 132 136 return VINF_SUCCESS; … … 161 165 void USBProxyServiceDarwin::captureDeviceCompleted(HostUSBDevice *aDevice, bool aSuccess) 162 166 { 167 AssertReturnVoid(aDevice->isWriteLockOnCurrentThread()); 163 168 #ifdef VBOX_WITH_NEW_USB_CODE_ON_DARWIN 164 169 /* … … 179 184 */ 180 185 AssertReturn(aDevice, VERR_GENERAL_FAILURE); 186 AssertReturn(!aDevice->isWriteLockOnCurrentThread(), VERR_GENERAL_FAILURE); 187 188 AutoReadLock devLock(aDevice COMMA_LOCKVAL_SRC_POS); 181 189 LogFlowThisFunc(("aDevice=%s\n", aDevice->getName().c_str())); 182 AssertReturn(aDevice->isWriteLockOnCurrentThread(), VERR_GENERAL_FAILURE); 190 183 191 Assert(aDevice->getUnistate() == kHostUSBDeviceState_ReleasingToHost); 184 192 … … 188 196 */ 189 197 ASMAtomicWriteBool(&mFakeAsync, true); 198 devLock.release(); 190 199 interruptWait(); 191 200 return VINF_SUCCESS; … … 222 231 void USBProxyServiceDarwin::releaseDeviceCompleted(HostUSBDevice *aDevice, bool aSuccess) 223 232 { 233 AssertReturnVoid(aDevice->isWriteLockOnCurrentThread()); 224 234 #ifdef VBOX_WITH_NEW_USB_CODE_ON_DARWIN 225 235 /* … … 234 244 235 245 246 /** @todo unused */ 236 247 void USBProxyServiceDarwin::detachingDevice(HostUSBDevice *aDevice) 237 248 { 238 249 #ifndef VBOX_WITH_NEW_USB_CODE_ON_DARWIN 239 aDevice->setLogicalReconnect 250 aDevice->setLogicalReconnect(HostUSBDevice::kDetachingPendingDetach); 240 251 #else 241 252 NOREF(aDevice); … … 246 257 bool USBProxyServiceDarwin::updateDeviceState(HostUSBDevice *aDevice, PUSBDEVICE aUSBDevice, bool *aRunFilters, SessionMachine **aIgnoreMachine) 247 258 { 259 AssertReturn(aDevice, false); 260 AssertReturn(!aDevice->isWriteLockOnCurrentThread(), false); 248 261 #ifndef VBOX_WITH_NEW_USB_CODE_ON_DARWIN 249 262 /* We're faking async state stuff. */ … … 264 277 #endif 265 278 266 SInt32 rc = CFRunLoopRunInMode(CFSTR 279 SInt32 rc = CFRunLoopRunInMode(CFSTR(VBOX_IOKIT_MODE_STRING), 267 280 mWaitABitNextTime && aMillies >= 1000 268 281 ? 1.0 /* seconds */ … … 277 290 278 291 279 int USBProxyServiceDarwin::interruptWait 292 int USBProxyServiceDarwin::interruptWait(void) 280 293 { 281 294 if (mServiceRunLoopRef) 282 CFRunLoopStop 295 CFRunLoopStop(mServiceRunLoopRef); 283 296 return 0; 284 297 } 285 298 286 299 287 PUSBDEVICE USBProxyServiceDarwin::getDevices 300 PUSBDEVICE USBProxyServiceDarwin::getDevices(void) 288 301 { 289 302 /* call iokit.cpp */ … … 292 305 293 306 294 void USBProxyServiceDarwin::serviceThreadInit 307 void USBProxyServiceDarwin::serviceThreadInit(void) 295 308 { 296 309 mServiceRunLoopRef = CFRunLoopGetCurrent(); … … 299 312 300 313 301 void USBProxyServiceDarwin::serviceThreadTerm 302 { 303 DarwinUnsubscribeUSBNotifications 314 void USBProxyServiceDarwin::serviceThreadTerm(void) 315 { 316 DarwinUnsubscribeUSBNotifications(mNotifyOpaque); 304 317 mServiceRunLoopRef = NULL; 305 318 } … … 311 324 * @param pCur The USB device to free. 312 325 */ 313 void DarwinFreeUSBDeviceFromIOKit 314 { 315 USBProxyService::freeDevice 316 } 317 326 void DarwinFreeUSBDeviceFromIOKit(PUSBDEVICE pCur) 327 { 328 USBProxyService::freeDevice(pCur); 329 } 330 -
trunk/src/VBox/Main/src-server/freebsd/USBProxyServiceFreeBSD.cpp
r37599 r41528 5 5 6 6 /* 7 * Copyright (C) 200 6-2010Oracle Corporation7 * Copyright (C) 2005-2012 Oracle Corporation 8 8 * 9 9 * This file is part of VirtualBox Open Source Edition (OSE), as … … 111 111 int USBProxyServiceFreeBSD::captureDevice(HostUSBDevice *aDevice) 112 112 { 113 Log(("USBProxyServiceFreeBSD::captureDevice: %p {%s}\n", aDevice, aDevice->getName().c_str()));114 113 AssertReturn(aDevice, VERR_GENERAL_FAILURE); 115 AssertReturn(aDevice->isWriteLockOnCurrentThread(), VERR_GENERAL_FAILURE); 114 AssertReturn(!aDevice->isWriteLockOnCurrentThread(), VERR_GENERAL_FAILURE); 115 116 AutoReadLock devLock(aDevice COMMA_LOCKVAL_SRC_POS); 117 LogFlowThisFunc(("aDevice=%s\n", aDevice->getName().c_str())); 116 118 117 119 /* … … 119 121 */ 120 122 Assert(aDevice->getUnistate() == kHostUSBDeviceState_Capturing); 123 devLock.release(); 121 124 interruptWait(); 122 125 … … 127 130 int USBProxyServiceFreeBSD::releaseDevice(HostUSBDevice *aDevice) 128 131 { 129 Log(("USBProxyServiceFreeBSD::releaseDevice: %p\n", aDevice));130 132 AssertReturn(aDevice, VERR_GENERAL_FAILURE); 131 AssertReturn(aDevice->isWriteLockOnCurrentThread(), VERR_GENERAL_FAILURE); 133 AssertReturn(!aDevice->isWriteLockOnCurrentThread(), VERR_GENERAL_FAILURE); 134 135 AutoReadLock devLock(aDevice COMMA_LOCKVAL_SRC_POS); 136 LogFlowThisFunc(("aDevice=%s\n", aDevice->getName().c_str())); 132 137 133 138 /* … … 135 140 */ 136 141 Assert(aDevice->getUnistate() == kHostUSBDeviceState_ReleasingToHost); 142 devLock.release(); 137 143 interruptWait(); 138 144 … … 143 149 bool USBProxyServiceFreeBSD::updateDeviceState(HostUSBDevice *aDevice, PUSBDEVICE aUSBDevice, bool *aRunFilters, SessionMachine **aIgnoreMachine) 144 150 { 151 AssertReturn(aDevice, false); 152 AssertReturn(!aDevice->isWriteLockOnCurrentThread(), false); 153 145 154 return updateDeviceStateFake(aDevice, aUSBDevice, aRunFilters, aIgnoreMachine); 146 155 } … … 148 157 149 158 /** 150 * A device was added , we need to adjust mUdevPolls.159 * A device was added 151 160 * 152 161 * See USBProxyService::deviceAdded for details. -
trunk/src/VBox/Main/src-server/linux/USBProxyServiceLinux.cpp
r37618 r41528 5 5 6 6 /* 7 * Copyright (C) 200 6-2011Oracle Corporation7 * Copyright (C) 2005-2012 Oracle Corporation 8 8 * 9 9 * This file is part of VirtualBox Open Source Edition (OSE), as … … 222 222 int USBProxyServiceLinux::captureDevice(HostUSBDevice *aDevice) 223 223 { 224 Log(("USBProxyServiceLinux::captureDevice: %p {%s}\n", aDevice, aDevice->getName().c_str()));225 224 AssertReturn(aDevice, VERR_GENERAL_FAILURE); 226 AssertReturn(aDevice->isWriteLockOnCurrentThread(), VERR_GENERAL_FAILURE); 225 AssertReturn(!aDevice->isWriteLockOnCurrentThread(), VERR_GENERAL_FAILURE); 226 227 AutoReadLock devLock(aDevice COMMA_LOCKVAL_SRC_POS); 228 LogFlowThisFunc(("aDevice=%s\n", aDevice->getName().c_str())); 227 229 228 230 /* … … 230 232 */ 231 233 Assert(aDevice->getUnistate() == kHostUSBDeviceState_Capturing); 234 devLock.release(); 232 235 interruptWait(); 233 236 … … 238 241 int USBProxyServiceLinux::releaseDevice(HostUSBDevice *aDevice) 239 242 { 240 Log(("USBProxyServiceLinux::releaseDevice: %p\n", aDevice));241 243 AssertReturn(aDevice, VERR_GENERAL_FAILURE); 242 AssertReturn(aDevice->isWriteLockOnCurrentThread(), VERR_GENERAL_FAILURE); 244 AssertReturn(!aDevice->isWriteLockOnCurrentThread(), VERR_GENERAL_FAILURE); 245 246 AutoReadLock devLock(aDevice COMMA_LOCKVAL_SRC_POS); 247 LogFlowThisFunc(("aDevice=%s\n", aDevice->getName().c_str())); 243 248 244 249 /* … … 246 251 */ 247 252 Assert(aDevice->getUnistate() == kHostUSBDeviceState_ReleasingToHost); 253 devLock.release(); 248 254 interruptWait(); 249 255 … … 254 260 bool USBProxyServiceLinux::updateDeviceState(HostUSBDevice *aDevice, PUSBDEVICE aUSBDevice, bool *aRunFilters, SessionMachine **aIgnoreMachine) 255 261 { 262 AssertReturn(aDevice, false); 263 AssertReturn(!aDevice->isWriteLockOnCurrentThread(), false); 264 AutoReadLock devLock(aDevice COMMA_LOCKVAL_SRC_POS); 256 265 if ( aUSBDevice->enmState == USBDEVICESTATE_USED_BY_HOST_CAPTURABLE 257 266 && aDevice->mUsb->enmState == USBDEVICESTATE_USED_BY_HOST) 258 267 LogRel(("USBProxy: Device %04x:%04x (%s) has become accessible.\n", 259 268 aUSBDevice->idVendor, aUSBDevice->idProduct, aUSBDevice->pszAddress)); 269 devLock.release(); 260 270 return updateDeviceStateFake(aDevice, aUSBDevice, aRunFilters, aIgnoreMachine); 261 271 } … … 269 279 void USBProxyServiceLinux::deviceAdded(ComObjPtr<HostUSBDevice> &aDevice, SessionMachinesList &llOpenedMachines, PUSBDEVICE aUSBDevice) 270 280 { 281 AssertReturnVoid(aDevice); 282 AssertReturnVoid(!aDevice->isWriteLockOnCurrentThread()); 283 AutoReadLock devLock(aDevice COMMA_LOCKVAL_SRC_POS); 271 284 if (aUSBDevice->enmState == USBDEVICESTATE_USED_BY_HOST) 272 285 { … … 276 289 } 277 290 291 devLock.release(); 278 292 USBProxyService::deviceAdded(aDevice, llOpenedMachines, aUSBDevice); 279 293 } … … 349 363 int USBProxyServiceLinux::interruptWait(void) 350 364 { 365 AssertReturn(!isWriteLockOnCurrentThread(), VERR_GENERAL_FAILURE); 366 367 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS); 351 368 #ifdef VBOX_USB_WITH_SYSFS 352 369 LogFlowFunc(("mUsingUsbfsDevices=%d\n", mUsingUsbfsDevices)); -
trunk/src/VBox/Main/src-server/os2/USBProxyServiceOs2.cpp
r31892 r41528 5 5 6 6 /* 7 * Copyright (C) 200 6-2010Oracle Corporation7 * Copyright (C) 2005-2012 Oracle Corporation 8 8 * 9 9 * This file is part of VirtualBox Open Source Edition (OSE), as … … 38 38 * Initialize data members. 39 39 */ 40 USBProxyServiceOs2::USBProxyServiceOs2 41 : USBProxyService (aHost), mhev (NULLHANDLE), mhmod(NULLHANDLE),42 mpfnUsbRegisterChangeNotification (NULL), mpfnUsbDeregisterNotification(NULL),43 mpfnUsbQueryNumberDevices (NULL), mpfnUsbQueryDeviceReport(NULL)40 USBProxyServiceOs2::USBProxyServiceOs2(Host *aHost) 41 : USBProxyService(aHost), mhev(NULLHANDLE), mhmod(NULLHANDLE), 42 mpfnUsbRegisterChangeNotification(NULL), mpfnUsbDeregisterNotification(NULL), 43 mpfnUsbQueryNumberDevices(NULL), mpfnUsbQueryDeviceReport(NULL) 44 44 { 45 45 LogFlowThisFunc(("aHost=%p\n", aHost)); … … 48 48 * Try initialize the usbcalls stuff. 49 49 */ 50 int rc = DosCreateEventSem 51 rc = RTErrConvertFromOS2 50 int rc = DosCreateEventSem(NULL, &mhev, 0, FALSE); 51 rc = RTErrConvertFromOS2(rc); 52 52 if (RT_SUCCESS(rc)) 53 53 { 54 rc = DosLoadModule 55 rc = RTErrConvertFromOS2 54 rc = DosLoadModule(NULL, 0, (PCSZ)"usbcalls", &mhmod); 55 rc = RTErrConvertFromOS2(rc); 56 56 if (RT_SUCCESS(rc)) 57 57 { 58 if ( (rc = DosQueryProcAddr (mhmod, 0, (PCSZ)"UsbQueryNumberDevices",(PPFN)&mpfnUsbQueryNumberDevices)) == NO_ERROR59 && (rc = DosQueryProcAddr (mhmod, 0, (PCSZ)"UsbQueryDeviceReport",(PPFN)&mpfnUsbQueryDeviceReport)) == NO_ERROR60 && (rc = DosQueryProcAddr (mhmod, 0, (PCSZ)"UsbRegisterChangeNotification",(PPFN)&mpfnUsbRegisterChangeNotification)) == NO_ERROR61 && (rc = DosQueryProcAddr (mhmod, 0, (PCSZ)"UsbDeregisterNotification",(PPFN)&mpfnUsbDeregisterNotification)) == NO_ERROR58 if ( (rc = DosQueryProcAddr(mhmod, 0, (PCSZ)"UsbQueryNumberDevices", (PPFN)&mpfnUsbQueryNumberDevices)) == NO_ERROR 59 && (rc = DosQueryProcAddr(mhmod, 0, (PCSZ)"UsbQueryDeviceReport", (PPFN)&mpfnUsbQueryDeviceReport)) == NO_ERROR 60 && (rc = DosQueryProcAddr(mhmod, 0, (PCSZ)"UsbRegisterChangeNotification", (PPFN)&mpfnUsbRegisterChangeNotification)) == NO_ERROR 61 && (rc = DosQueryProcAddr(mhmod, 0, (PCSZ)"UsbDeregisterNotification", (PPFN)&mpfnUsbDeregisterNotification)) == NO_ERROR 62 62 ) 63 63 { 64 rc = mpfnUsbRegisterChangeNotification 64 rc = mpfnUsbRegisterChangeNotification(&mNotifyId, mhev, mhev); 65 65 if (!rc) 66 66 { … … 77 77 } 78 78 79 LogRel 79 LogRel(("USBProxyServiceOs2: failed to register change notification, rc=%d\n", rc)); 80 80 } 81 81 else 82 LogRel 83 84 DosFreeModule 82 LogRel(("USBProxyServiceOs2: failed to load usbcalls\n")); 83 84 DosFreeModule(mhmod); 85 85 } 86 86 else 87 LogRel 87 LogRel(("USBProxyServiceOs2: failed to load usbcalls, rc=%d\n", rc)); 88 88 mhmod = NULLHANDLE; 89 89 } … … 115 115 { 116 116 if (mpfnUsbDeregisterNotification) 117 mpfnUsbDeregisterNotification 117 mpfnUsbDeregisterNotification(mNotifyId); 118 118 119 119 mpfnUsbRegisterChangeNotification = NULL; … … 122 122 mpfnUsbQueryDeviceReport = NULL; 123 123 124 DosFreeModule 124 DosFreeModule(mhmod); 125 125 mhmod = NULLHANDLE; 126 126 } … … 128 128 129 129 130 int USBProxyServiceOs2::captureDevice (HostUSBDevice *aDevice) 131 { 132 Log (("USBProxyServiceOs2::captureDevice: %p\n", aDevice)); 130 int USBProxyServiceOs2::captureDevice(HostUSBDevice *aDevice) 131 { 133 132 AssertReturn(aDevice, VERR_GENERAL_FAILURE); 134 AssertReturn(aDevice->isWriteLockOnCurrentThread(), VERR_GENERAL_FAILURE); 133 AssertReturn(!aDevice->isWriteLockOnCurrentThread(), VERR_GENERAL_FAILURE); 134 135 AutoReadLock devLock(aDevice COMMA_LOCKVAL_SRC_POS); 136 LogFlowThisFunc(("aDevice=%s\n", aDevice->getName().c_str())); 135 137 136 138 /* … … 138 140 */ 139 141 Assert(aDevice->isStatePending()); 142 devLock.release(); 140 143 interruptWait(); 141 144 … … 144 147 145 148 146 int USBProxyServiceOs2::releaseDevice (HostUSBDevice *aDevice) 147 { 148 Log (("USBProxyServiceOs2::releaseDevice: %p\n", aDevice)); 149 int USBProxyServiceOs2::releaseDevice(HostUSBDevice *aDevice) 150 { 149 151 AssertReturn(aDevice, VERR_GENERAL_FAILURE); 150 AssertReturn(aDevice->isWriteLockOnCurrentThread(), VERR_GENERAL_FAILURE); 152 AssertReturn(!aDevice->isWriteLockOnCurrentThread(), VERR_GENERAL_FAILURE); 153 154 AutoReadLock devLock(aDevice COMMA_LOCKVAL_SRC_POS); 155 LogFlowThisFunc(("aDevice=%s\n", aDevice->getName().c_str())); 151 156 152 157 /* … … 154 159 */ 155 160 Assert(aDevice->isStatePending()); 161 devLock.release(); 156 162 interruptWait(); 157 163 … … 162 168 bool USBProxyServiceOs2::updateDeviceState(HostUSBDevice *aDevice, PUSBDEVICE aUSBDevice, bool *aRunFilters, SessionMachine **aIgnoreMachine) 163 169 { 170 AssertReturn(aDevice, false); 171 AssertReturn(!aDevice->isWriteLockOnCurrentThread(), false); 164 172 return updateDeviceStateFake(aDevice, aUSBDevice, aRunFilters, aIgnoreMachine); 165 173 } … … 174 182 175 183 176 int USBProxyServiceOs2::interruptWait 177 { 178 int rc = DosPostEventSem 184 int USBProxyServiceOs2::interruptWait(void) 185 { 186 int rc = DosPostEventSem(mhev); 179 187 return rc == NO_ERROR || rc == ERROR_ALREADY_POSTED 180 188 ? VINF_SUCCESS 181 : RTErrConvertFromOS2 189 : RTErrConvertFromOS2(rc); 182 190 } 183 191 184 192 #include <stdio.h> 185 193 186 PUSBDEVICE USBProxyServiceOs2::getDevices 194 PUSBDEVICE USBProxyServiceOs2::getDevices(void) 187 195 { 188 196 /* … … 190 198 */ 191 199 ULONG cDevices = 0; 192 int rc = mpfnUsbQueryNumberDevices 200 int rc = mpfnUsbQueryNumberDevices((PULONG)&cDevices); /* Thanks to com/xpcom, PULONG and ULONG * aren't the same. */ 193 201 if (rc) 194 202 return NULL; -
trunk/src/VBox/Main/src-server/solaris/USBProxyServiceSolaris.cpp
r38016 r41528 5 5 6 6 /* 7 * Copyright (C) 200 6-2007Oracle Corporation7 * Copyright (C) 2005-2012 Oracle Corporation 8 8 * 9 9 * This file is part of VirtualBox Open Source Edition (OSE), as … … 54 54 * Initialize data members. 55 55 */ 56 USBProxyServiceSolaris::USBProxyServiceSolaris 57 : USBProxyService 56 USBProxyServiceSolaris::USBProxyServiceSolaris(Host *aHost) 57 : USBProxyService(aHost), mUSBLibInitialized(false) 58 58 { 59 59 LogFlowThisFunc(("aHost=%p\n", aHost)); … … 337 337 */ 338 338 AssertReturn(aDevice, VERR_GENERAL_FAILURE); 339 AssertReturn(!aDevice->isWriteLockOnCurrentThread(), VERR_GENERAL_FAILURE); 340 341 AutoReadLock devLock(aDevice COMMA_LOCKVAL_SRC_POS); 339 342 LogFlowThisFunc(("aDevice=%s\n", aDevice->getName().c_str())); 340 AssertReturn(aDevice->isWriteLockOnCurrentThread(), VERR_GENERAL_FAILURE); 343 341 344 Assert(aDevice->getUnistate() == kHostUSBDeviceState_Capturing); 342 345 AssertReturn(aDevice->mUsb, VERR_INVALID_POINTER); … … 372 375 void USBProxyServiceSolaris::captureDeviceCompleted(HostUSBDevice *aDevice, bool aSuccess) 373 376 { 377 AssertReturnVoid(aDevice->isWriteLockOnCurrentThread()); 374 378 /* 375 379 * Remove the one-shot filter if necessary. … … 388 392 */ 389 393 AssertReturn(aDevice, VERR_GENERAL_FAILURE); 394 AssertReturn(!aDevice->isWriteLockOnCurrentThread(), VERR_GENERAL_FAILURE); 395 396 AutoReadLock devLock(aDevice COMMA_LOCKVAL_SRC_POS); 390 397 LogFlowThisFunc(("aDevice=%s\n", aDevice->getName().c_str())); 391 AssertReturn(aDevice->isWriteLockOnCurrentThread(), VERR_GENERAL_FAILURE); 398 392 399 Assert(aDevice->getUnistate() == kHostUSBDeviceState_ReleasingToHost); 393 400 AssertReturn(aDevice->mUsb, VERR_INVALID_POINTER); … … 423 430 void USBProxyServiceSolaris::releaseDeviceCompleted(HostUSBDevice *aDevice, bool aSuccess) 424 431 { 432 AssertReturnVoid(aDevice->isWriteLockOnCurrentThread()); 425 433 /* 426 434 * Remove the one-shot filter if necessary. … … 435 443 bool USBProxyServiceSolaris::updateDeviceState(HostUSBDevice *aDevice, PUSBDEVICE aUSBDevice, bool *aRunFilters, SessionMachine **aIgnoreMachine) 436 444 { 445 AssertReturn(aDevice, false); 446 AssertReturn(!aDevice->isWriteLockOnCurrentThread(), false) 437 447 return USBProxyService::updateDeviceState(aDevice, aUSBDevice, aRunFilters, aIgnoreMachine); 438 448 } -
trunk/src/VBox/Main/src-server/win/USBProxyServiceWindows.cpp
r37599 r41528 5 5 6 6 /* 7 * Copyright (C) 200 6-2010Oracle Corporation7 * Copyright (C) 2005-2012 Oracle Corporation 8 8 * 9 9 * This file is part of VirtualBox Open Source Edition (OSE), as … … 138 138 { 139 139 /* 140 * Check preconditions. 141 */ 142 AssertReturn(aDevice, VERR_GENERAL_FAILURE); 143 AssertReturn(!aDevice->isWriteLockOnCurrentThread(), VERR_GENERAL_FAILURE); 144 145 AutoReadLock devLock(aDevice COMMA_LOCKVAL_SRC_POS); 146 LogFlowThisFunc(("aDevice=%s\n", aDevice->getName().c_str())); 147 148 Assert(aDevice->getUnistate() == kHostUSBDeviceState_Capturing); 149 150 /* 140 151 * Create a one-shot ignore filter for the device 141 152 * and trigger a re-enumeration of it. … … 169 180 { 170 181 /* 182 * Check preconditions. 183 */ 184 AssertReturn(aDevice, VERR_GENERAL_FAILURE); 185 AssertReturn(!aDevice->isWriteLockOnCurrentThread(), VERR_GENERAL_FAILURE); 186 187 AutoReadLock devLock(aDevice COMMA_LOCKVAL_SRC_POS); 188 LogFlowThisFunc(("aDevice=%s\n", aDevice->getName().c_str())); 189 190 Assert(aDevice->getUnistate() == kHostUSBDeviceState_Capturing); 191 192 /* 171 193 * Create a one-shot ignore filter for the device 172 194 * and trigger a re-enumeration of it. … … 200 222 bool USBProxyServiceWindows::updateDeviceState(HostUSBDevice *aDevice, PUSBDEVICE aUSBDevice, bool *aRunFilters, SessionMachine **aIgnoreMachine) 201 223 { 224 AssertReturn(aDevice, false); 225 AssertReturn(!aDevice->isWriteLockOnCurrentThread(), false); 202 226 /* Nothing special here so far, so fall back on parent */ 203 227 return USBProxyService::updateDeviceState(aDevice, aUSBDevice, aRunFilters, aIgnoreMachine); … … 205 229 /// @todo remove? 206 230 #if 0 207 AssertReturn(aDevice, false);208 AssertReturn(aDevice->isWriteLockOnCurrentThread(), false);209 231 210 232 /* -
trunk/src/VBox/Main/testcase/Makefile.kmk
r41477 r41528 5 5 6 6 # 7 # Copyright (C) 200 6-2012 Oracle Corporation7 # Copyright (C) 2004-2012 Oracle Corporation 8 8 # 9 9 # This file is part of VirtualBox Open Source Edition (OSE), as … … 184 184 $(VBOX_PATH_SDK)/bindings/xpcom/include/VirtualBox_XPCOM.h 185 185 tstUSBProxyLinux_LIBS += \ 186 $(PATH_OUT)/lib/USBLib.a 186 $(PATH_OUT)/lib/USBLib.a \ 187 $(PATH_OUT)/lib/VBoxCOM.a 187 188 188 189
Note:
See TracChangeset
for help on using the changeset viewer.