Changeset 23279 in vbox for trunk/src/VBox/Main/HostImpl.cpp
- Timestamp:
- Sep 24, 2009 10:46:57 AM (15 years ago)
- svn:sync-xref-src-repo-rev:
- 52765
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/HostImpl.cpp
r23273 r23279 159 159 160 160 #ifdef VBOX_WITH_USB 161 USBDeviceFilterList llUSBDeviceFilters; 161 WriteLockHandle treeLock; // protects the below two lists 162 163 USBDeviceFilterList llChildren; // all USB device filters 164 USBDeviceFilterList llUSBDeviceFilters; // USB device filters in use by the USB proxy service 162 165 163 166 /** Pointer to the USBProxyService object. */ … … 337 340 delete m->pHostPowerService; 338 341 342 #ifdef VBOX_WITH_USB 339 343 /* uninit all USB device filters still referenced by clients */ 340 uninitDependentChildren(); 341 342 #ifdef VBOX_WITH_USB 344 for (USBDeviceFilterList::iterator it = m->llChildren.begin(); 345 it != m->llChildren.end(); 346 ++it) 347 { 348 ComObjPtr<HostUSBDeviceFilter> &pChild = *it; 349 pChild->uninit(); 350 } 351 352 m->llChildren.clear(); 353 343 354 m->llUSBDeviceFilters.clear(); 344 355 #endif … … 902 913 CheckComRCReturnRC(rc); 903 914 904 return m->pUSBProxyService->getDeviceCollection 915 return m->pUSBProxyService->getDeviceCollection(ComSafeArrayOutArg(aUSBDevices)); 905 916 906 917 #else … … 924 935 CheckComRCReturnRC(autoCaller.rc()); 925 936 926 Auto WriteLock alock(this);937 AutoMultiWriteLock2 alock(this->lockHandle(), &m->treeLock); 927 938 928 939 MultiResult rc = checkUSBProxyService(); 929 940 CheckComRCReturnRC(rc); 930 941 931 SafeIfaceArray<IHostUSBDeviceFilter> collection 942 SafeIfaceArray<IHostUSBDeviceFilter> collection(m->llUSBDeviceFilters); 932 943 collection.detachTo(ComSafeArrayOutArg(aUSBDeviceFilters)); 933 944 … … 1258 1269 CheckComRCReturnRC(autoCaller.rc()); 1259 1270 1260 Auto WriteLock alock(this);1271 AutoMultiWriteLock2 alock(this->lockHandle(), &m->treeLock); 1261 1272 1262 1273 MultiResult rc = checkUSBProxyService(); 1263 1274 CheckComRCReturnRC(rc); 1264 1275 1265 ComObjPtr<HostUSBDeviceFilter> filter = getDependentChild (aFilter); 1266 if (!filter) 1267 return setError (VBOX_E_INVALID_OBJECT_STATE, 1268 tr ("The given USB device filter is not created within " 1269 "this VirtualBox instance")); 1270 1271 if (filter->mInList) 1276 ComObjPtr<HostUSBDeviceFilter> pFilter; 1277 for (USBDeviceFilterList::iterator it = m->llChildren.begin(); 1278 it != m->llChildren.end(); 1279 ++it) 1280 { 1281 if (*it == aFilter) 1282 { 1283 pFilter = *it; 1284 break; 1285 } 1286 } 1287 if (pFilter.isNull()) 1288 return setError(VBOX_E_INVALID_OBJECT_STATE, 1289 tr("The given USB device filter is not created within this VirtualBox instance")); 1290 1291 if (pFilter->mInList) 1272 1292 return setError (E_INVALIDARG, 1273 1293 tr ("The given USB device filter is already in the list")); … … 1277 1297 std::advance (it, aPosition); 1278 1298 /* ...and insert */ 1279 m->llUSBDeviceFilters.insert (it, filter);1280 filter->mInList = true;1299 m->llUSBDeviceFilters.insert(it, pFilter); 1300 pFilter->mInList = true; 1281 1301 1282 1302 /* notify the proxy (only when the filter is active) */ 1283 if (m->pUSBProxyService->isActive() && filter->data().mActive) 1284 { 1285 ComAssertRet (filter->id() == NULL, E_FAIL); 1286 filter->id() = m->pUSBProxyService->insertFilter (&filter->data().mUSBFilter); 1303 if ( m->pUSBProxyService->isActive() 1304 && pFilter->data().mActive) 1305 { 1306 ComAssertRet(pFilter->id() == NULL, E_FAIL); 1307 pFilter->id() = m->pUSBProxyService->insertFilter(&pFilter->data().mUSBFilter); 1287 1308 } 1288 1309 … … 1308 1329 CheckComRCReturnRC(autoCaller.rc()); 1309 1330 1310 Auto WriteLock alock(this);1331 AutoMultiWriteLock2 alock(this->lockHandle(), &m->treeLock); 1311 1332 1312 1333 MultiResult rc = checkUSBProxyService(); … … 1331 1352 /* ...and remove */ 1332 1353 filter->mInList = false; 1333 m->llUSBDeviceFilters.erase 1354 m->llUSBDeviceFilters.erase(it); 1334 1355 } 1335 1356 … … 1591 1612 CheckComRCReturnRC(autoCaller.rc()); 1592 1613 1593 Auto WriteLock alock(this);1614 AutoMultiWriteLock2 alock(this->lockHandle(), &m->treeLock); 1594 1615 1595 1616 HRESULT rc = S_OK; … … 1628 1649 CheckComRCReturnRC(autoCaller.rc()); 1629 1650 1630 Auto WriteLock alock(this);1651 AutoReadLock alock(&m->treeLock); 1631 1652 1632 1653 #ifdef VBOX_WITH_USB … … 1653 1674 { 1654 1675 return m->pUSBProxyService; 1676 } 1677 1678 HRESULT Host::addChild(HostUSBDeviceFilter *pChild) 1679 { 1680 AutoCaller autoCaller(this); 1681 CheckComRCReturnRC(autoCaller.rc()); 1682 1683 AutoWriteLock alock(&m->treeLock); 1684 1685 m->llChildren.push_back(pChild); 1686 1687 return S_OK; 1688 } 1689 1690 HRESULT Host::removeChild(HostUSBDeviceFilter *pChild) 1691 { 1692 AutoCaller autoCaller(this); 1693 CheckComRCReturnRC(autoCaller.rc()); 1694 1695 AutoWriteLock alock(&m->treeLock); 1696 1697 for (USBDeviceFilterList::iterator it = m->llChildren.begin(); 1698 it != m->llChildren.end(); 1699 ++it) 1700 { 1701 if (*it == pChild) 1702 { 1703 m->llChildren.erase(it); 1704 break; 1705 } 1706 } 1707 1708 return S_OK; 1655 1709 } 1656 1710 … … 1717 1771 void Host::getUSBFilters(Host::USBDeviceFilterList *aGlobalFilters) 1718 1772 { 1719 Auto WriteLock alock(this);1773 AutoReadLock alock(&m->treeLock); 1720 1774 1721 1775 *aGlobalFilters = m->llUSBDeviceFilters; … … 2229 2283 2230 2284 #ifdef VBOX_WITH_USB 2231 ComObjPtr<HostUSBDeviceFilter> Host::getDependentChild (IHostUSBDeviceFilter *aFilter)2232 {2233 VirtualBoxBase *child = VirtualBoxBaseWithChildren::getDependentChild(ComPtr<IUnknown>(aFilter));2234 return child2235 ? dynamic_cast<HostUSBDeviceFilter*>(child)2236 : NULL;2237 }2238 2239 2240 2285 /** 2241 2286 * Checks for the presense and status of the USB Proxy Service.
Note:
See TracChangeset
for help on using the changeset viewer.