Changeset 8744 in vbox for trunk/src/VBox
- Timestamp:
- May 9, 2008 2:51:58 PM (17 years ago)
- Location:
- trunk/src/VBox/Main
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/HostImpl.cpp
r8725 r8744 144 144 mParent = parent; 145 145 146 #if defined (RT_OS_DARWIN) && defined (VBOX_WITH_USB) 146 #ifdef VBOX_WITH_USB 147 /* 148 * Create and initialize the USB Proxy Service. 149 */ 150 # if defined (RT_OS_DARWIN) 147 151 mUSBProxyService = new USBProxyServiceDarwin (this); 148 # elif defined (RT_OS_LINUX) && defined (VBOX_WITH_USB)152 # elif defined (RT_OS_LINUX) 149 153 mUSBProxyService = new USBProxyServiceLinux (this); 150 # elif defined (RT_OS_OS2) && defined (VBOX_WITH_USB)154 # elif defined (RT_OS_OS2) 151 155 mUSBProxyService = new USBProxyServiceOs2 (this); 152 # elif defined (RT_OS_WINDOWS) && defined (VBOX_WITH_USB)156 # elif defined (RT_OS_WINDOWS) 153 157 mUSBProxyService = new USBProxyServiceWin32 (this); 154 # elif defined (VBOX_WITH_USB)158 # elif 155 159 mUSBProxyService = new USBProxyService (this); 156 # endif157 /** @todo handle !mUSBProxySerivce->isActive() and mUSBProxyService->getLastError()158 * and somehow report or whatever that the proxy failed to startup.159 * Also, there might be init order issues...*/160 # endif 161 HRESULT hrc = mUSBProxyService->init(); 162 AssertComRCReturn(hrc, hrc); 163 #endif /* VBOX_WITH_USB */ 160 164 161 165 setReady(true); … … 1261 1265 return S_OK; 1262 1266 } 1263 #endif /* VBOX_HOST_USB */ 1267 1268 1269 /** 1270 * Interface for obtaining a copy of the USBDeviceFilterList, 1271 * used by the USBProxyService. 1272 * 1273 * @param aGlobalFilters Where to put the global filter list copy. 1274 * @param aMachines Where to put the machine vector. 1275 */ 1276 void Host::getUSBFilters(Host::USBDeviceFilterList *aGlobalFilters, VirtualBox::SessionMachineVector *aMachines) 1277 { 1278 AutoWriteLock alock (this); 1279 1280 mParent->getOpenedMachines (*aMachines); 1281 *aGlobalFilters = mUSBDeviceFilters; 1282 } 1283 1284 #endif /* VBOX_WITH_USB */ 1264 1285 1265 1286 // private methods … … 1746 1767 1747 1768 #ifdef VBOX_WITH_USB 1748 1749 /**1750 * Applies all (golbal and VM) filters to the given USB device. The device1751 * must be either a newly attached device or a device released by a VM.1752 *1753 * This method will request the USB proxy service to release the device (give1754 * it back to the host) if none of the global or VM filters want to capture1755 * the device.1756 *1757 * @param aDevice USB device to apply filters to.1758 * @param aMachine Machine the device was released by or @c NULL.1759 *1760 * @note the method must be called from under this object's write lock and1761 * from the aDevice's write lock.1762 */1763 HRESULT Host::applyAllUSBFilters (ComObjPtr <HostUSBDevice> &aDevice,1764 SessionMachine *aMachine /* = NULL */)1765 {1766 LogFlowThisFunc(("{%s}\n", aDevice->name().raw()));1767 1768 /*1769 * Verify preconditions.1770 */1771 /// @todo must check for read lock, it's enough here1772 AssertReturn(isWriteLockOnCurrentThread(), E_FAIL);1773 AssertReturn(aDevice->isWriteLockOnCurrentThread(), E_FAIL);1774 /* Quietly ignore unsupported and unavailable device. */1775 if ( aDevice->unistate() == kHostUSBDeviceState_UsedByHost1776 || aDevice->unistate() == kHostUSBDeviceState_Unsupported) /** @todo !aDevice->isCapturable() or something */1777 {1778 LogFlowThisFunc(("{%s} %s - quietly ignored\n", aDevice->name().raw(), aDevice->stateName()));1779 return S_OK;1780 }1781 1782 VirtualBox::SessionMachineVector machines;1783 mParent->getOpenedMachines (machines);1784 1785 /// @todo it may be better to take a copy of filters to iterate and leave1786 /// the host lock before calling HostUSBDevice:requestCaptureForVM() (which1787 /// may call the VM process).1788 /// Moving this matching into USBProxyService at the same time would be1789 /// nice too, that'll simplify the locking a bit more.1790 1791 /* apply global filters */1792 USBDeviceFilterList::const_iterator it = mUSBDeviceFilters.begin();1793 for (; it != mUSBDeviceFilters.end(); ++ it)1794 {1795 AutoWriteLock filterLock (*it);1796 const HostUSBDeviceFilter::Data &data = (*it)->data();1797 if (aDevice->isMatch (data))1798 {1799 USBDeviceFilterAction_T action = USBDeviceFilterAction_Null;1800 (*it)->COMGETTER (Action) (&action);1801 if (action == USBDeviceFilterAction_Ignore)1802 {1803 /* request to give the device back to the host */1804 aDevice->requestReleaseToHost();1805 /* nothing to do any more */1806 return S_OK;1807 }1808 if (action == USBDeviceFilterAction_Hold)1809 break;1810 }1811 }1812 1813 /* apply machine filters */1814 size_t i = 0;1815 for (; i < machines.size(); ++ i)1816 {1817 /* skip the machine the device was just detached from */1818 if (aMachine && machines [i] == aMachine)1819 continue;1820 1821 if (applyMachineUSBFilters (machines [i], aDevice))1822 break;1823 }1824 1825 if (i == machines.size())1826 {1827 /* no matched machine filters, check what to do */1828 if (it == mUSBDeviceFilters.end())1829 {1830 /* no any filter matched at all */1831 /* request to give the device back to the host */1832 aDevice->requestReleaseToHost();1833 }1834 else1835 {1836 /* there was a global Hold filter */1837 aDevice->requestHold();1838 }1839 }1840 1841 return S_OK;1842 }1843 1844 /**1845 * Runs through filters of the given machine and asks the USB proxy service1846 * to capture the given USB device when there is a match.1847 *1848 * @param aMachine Machine whose filters are to be run.1849 * @param aDevice USB device, a candidate for auto-capturing.1850 * @return @c true if there was a match and @c false otherwise.1851 *1852 * @note the method must be called from under this object's write lock and1853 * from the aDevice's write lock.1854 *1855 * @note Locks aMachine for reading.1856 */1857 bool Host::applyMachineUSBFilters (SessionMachine *aMachine,1858 ComObjPtr <HostUSBDevice> &aDevice)1859 {1860 LogFlowThisFunc(("{%s}\n", aDevice->name().raw()));1861 1862 /*1863 * Validate preconditions.1864 */1865 AssertReturn(aMachine, false);1866 /// @todo must check for read lock, it's enough here1867 AssertReturn(isWriteLockOnCurrentThread(), false);1868 AssertReturn(aDevice->isWriteLockOnCurrentThread(), false);1869 /* Let HostUSBDevice::requestCaptureToVM() validate the state. */1870 1871 ULONG maskedIfs;1872 bool hasMatch = aMachine->hasMatchingUSBFilter (aDevice, &maskedIfs);1873 if (hasMatch)1874 {1875 /** @todo r=bird: this is wrong as requestAttachToVM may return false for different reasons that we. */1876 /* try to capture the device */1877 HRESULT hrc = aDevice->requestCaptureForVM (aMachine, false /* aSetError */, maskedIfs);1878 return SUCCEEDED (hrc);1879 }1880 1881 return hasMatch;1882 }1883 1884 /**1885 * Called by USB proxy service when a new device is physically attached1886 * to the host.1887 *1888 * @param aDevice Pointer to the device which has been attached.1889 */1890 void Host::onUSBDeviceAttached (HostUSBDevice *aDevice)1891 {1892 /*1893 * Validate precoditions.1894 */1895 AssertReturnVoid(aDevice);1896 AssertReturnVoid(isWriteLockOnCurrentThread());1897 AssertReturnVoid(aDevice->isWriteLockOnCurrentThread());1898 LogFlowThisFunc(("aDevice=%p name={%s} state=%s id={%RTuuid}\n",1899 aDevice, aDevice->name().raw(), aDevice->stateName(), aDevice->id().raw()));1900 1901 /* apply all filters */1902 ComObjPtr <HostUSBDevice> device (aDevice);1903 HRESULT rc = applyAllUSBFilters (device);1904 AssertComRC (rc);1905 }1906 1907 /**1908 * Called by USB proxy service when the device is physically detached1909 * from the host.1910 *1911 * @param aDevice Pointer to the device which has been detached.1912 */1913 void Host::onUSBDeviceDetached (HostUSBDevice *aDevice)1914 {1915 /*1916 * Validate preconditions.1917 */1918 AssertReturnVoid(aDevice);1919 AssertReturnVoid(isWriteLockOnCurrentThread());1920 AssertReturnVoid(aDevice->isWriteLockOnCurrentThread());1921 LogFlowThisFunc(("aDevice=%p name={%s} state=%s id={%RTuuid}\n",1922 aDevice, aDevice->name().raw(), aDevice->stateName(), aDevice->id().raw()));1923 1924 /*1925 * Detach the device from any machine currently using it,1926 * reset all data and uninitialize the device object.1927 */1928 aDevice->onPhysicalDetached();1929 }1930 1931 /**1932 * Called by USB proxy service when the state of the device has changed1933 * either because of the state change request or because of some external1934 * interaction.1935 *1936 * @param aDevice The device in question.1937 * @param aRunFilters Whether to run filters.1938 * @param aIgnoreMachine The machine to ignore when running filters.1939 */1940 void Host::onUSBDeviceStateChanged (HostUSBDevice *aDevice, bool aRunFilters, SessionMachine *aIgnoreMachine)1941 {1942 /*1943 * Validate preconditions.1944 */1945 LogFlowThisFunc(("aDevice=%p\n", aDevice));1946 AssertReturnVoid(aDevice);1947 AssertReturnVoid(isWriteLockOnCurrentThread());1948 AssertReturnVoid(aDevice->isWriteLockOnCurrentThread());1949 LogFlowThisFunc(("aDevice=%p name={%s} state=%s id={%RTuuid}\n",1950 aDevice, aDevice->name().raw(), aDevice->stateName(), aDevice->id().raw()));1951 1952 /*1953 * Run filters if requested to do so.1954 */1955 if (aRunFilters)1956 {1957 ComObjPtr<HostUSBDevice> device(aDevice);1958 HRESULT rc = applyAllUSBFilters(device, aIgnoreMachine);1959 AssertComRC(rc);1960 }1961 }1962 #endif /* VBOX_WITH_USB */1963 1964 1769 /** 1965 1770 * Checks for the presense and status of the USB Proxy Service. … … 1975 1780 HRESULT Host::checkUSBProxyService() 1976 1781 { 1977 #ifdef VBOX_WITH_USB1978 1782 AutoWriteLock alock (this); 1979 1783 CHECK_READY(); … … 1999 1803 2000 1804 return S_OK; 2001 #else 2002 return E_NOTIMPL; 2003 #endif 2004 } 1805 } 1806 #endif /* VBOX_WITH_USB */ 2005 1807 2006 1808 #ifdef RT_OS_WINDOWS -
trunk/src/VBox/Main/MachineImpl.cpp
r8682 r8744 8682 8682 8683 8683 #ifdef VBOX_WITH_USB 8684 return mUSBController->hasMatchingFilter (aDevice, aMaskedIfs); 8685 #else 8684 switch (mData->mMachineState) 8685 { 8686 case MachineState_Starting: 8687 case MachineState_Restoring: 8688 case MachineState_Paused: 8689 case MachineState_Running: 8690 return mUSBController->hasMatchingFilter (aDevice, aMaskedIfs); 8691 default: break; 8692 } 8693 #endif 8686 8694 return false; 8687 #endif8688 8695 } 8689 8696 -
trunk/src/VBox/Main/include/HostImpl.h
r8666 r8744 28 28 # include "USBDeviceFilterImpl.h" 29 29 # include "USBProxyService.h" 30 # include "VirtualBoxImpl.h" 30 31 #else 31 32 class USBProxyService; … … 106 107 107 108 #ifdef VBOX_WITH_USB 108 /** @name To be moved, they don't belong here. 109 * @{ */ 110 void onUSBDeviceAttached (HostUSBDevice *aDevice); 111 void onUSBDeviceDetached (HostUSBDevice *aDevice); 112 void onUSBDeviceStateChanged(HostUSBDevice *aDevice, bool aRunFilters, SessionMachine *aIgnoreMachine); 113 /** @} */ 109 typedef std::list <ComObjPtr <HostUSBDeviceFilter> > USBDeviceFilterList; 110 111 /** Must be called from under this object's lock. */ 112 USBProxyService *usbProxyService() { return mUSBProxyService; } 114 113 115 114 HRESULT onUSBDeviceFilterChange (HostUSBDeviceFilter *aFilter, BOOL aActiveChanged = FALSE); 116 117 /* must be called from under this object's lock */ 118 USBProxyService *usbProxyService() { return mUSBProxyService; } 119 #else /* !VBOX_WITH_USB */ 120 USBProxyService *usbProxyService() { return NULL; } 115 void getUSBFilters(USBDeviceFilterList *aGlobalFiltes, VirtualBox::SessionMachineVector *aMachines); 116 HRESULT checkUSBProxyService(); 121 117 #endif /* !VBOX_WITH_USB */ 122 123 HRESULT checkUSBProxyService();124 118 125 119 #ifdef RT_OS_WINDOWS … … 151 145 : NULL; 152 146 } 153 154 public: //temporary - will be moved soon.155 HRESULT applyAllUSBFilters (ComObjPtr <HostUSBDevice> &aDevice,156 SessionMachine *aMachine = NULL);157 158 bool applyMachineUSBFilters (SessionMachine *aMachine,159 ComObjPtr <HostUSBDevice> &aDevice);160 private: //temporary161 147 #endif /* VBOX_WITH_USB */ 162 148 … … 176 162 177 163 #ifdef VBOX_WITH_USB 178 typedef std::list <ComObjPtr <HostUSBDeviceFilter> > USBDeviceFilterList;179 164 USBDeviceFilterList mUSBDeviceFilters; 180 165 -
trunk/src/VBox/Main/include/VirtualBoxBase.h
r8709 r8744 1686 1686 // child's uninit() from under the children map lock should not produce 1687 1687 // dead-locks any more). 1688 Assert (!child->isWriteLockOnCurrentThread() );1688 Assert (!child->isWriteLockOnCurrentThread() || child->lockHandle() == lockHandle()); 1689 1689 removeDependentChild (ComPtr <IUnknown> (child)); 1690 1690 }
Note:
See TracChangeset
for help on using the changeset viewer.