Changeset 41184 in vbox for trunk/src/VBox/Main/src-server
- Timestamp:
- May 7, 2012 1:28:04 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/src-server/USBControllerImpl.cpp
r38441 r41184 5 5 6 6 /* 7 * Copyright (C) 2006-201 0Oracle Corporation7 * Copyright (C) 2006-2012 Oracle Corporation 8 8 * 9 9 * This file is part of VirtualBox Open Source Edition (OSE), as … … 86 86 ///////////////////////////////////////////////////////////////////////////// 87 87 88 DEFINE_EMPTY_CTOR_DTOR 88 DEFINE_EMPTY_CTOR_DTOR(USBController) 89 89 90 90 HRESULT USBController::FinalConstruct() … … 262 262 ///////////////////////////////////////////////////////////////////////////// 263 263 264 STDMETHODIMP USBController::COMGETTER(Enabled) 264 STDMETHODIMP USBController::COMGETTER(Enabled)(BOOL *aEnabled) 265 265 { 266 266 CheckComArgOutPointerValid(aEnabled); … … 277 277 278 278 279 STDMETHODIMP USBController::COMSETTER(Enabled) 279 STDMETHODIMP USBController::COMSETTER(Enabled)(BOOL aEnabled) 280 280 { 281 281 LogFlowThisFunc(("aEnabled=%RTbool\n", aEnabled)); … … 308 308 } 309 309 310 STDMETHODIMP USBController::COMGETTER(EnabledEhci) 310 STDMETHODIMP USBController::COMGETTER(EnabledEhci)(BOOL *aEnabled) 311 311 { 312 312 CheckComArgOutPointerValid(aEnabled); … … 322 322 } 323 323 324 STDMETHODIMP USBController::COMSETTER(EnabledEhci) 324 STDMETHODIMP USBController::COMSETTER(EnabledEhci)(BOOL aEnabled) 325 325 { 326 326 LogFlowThisFunc(("aEnabled=%RTbool\n", aEnabled)); … … 353 353 } 354 354 355 STDMETHODIMP USBController::COMGETTER(ProxyAvailable) 355 STDMETHODIMP USBController::COMGETTER(ProxyAvailable)(BOOL *aEnabled) 356 356 { 357 357 CheckComArgOutPointerValid(aEnabled); … … 371 371 } 372 372 373 STDMETHODIMP USBController::COMGETTER(USBStandard) 373 STDMETHODIMP USBController::COMGETTER(USBStandard)(USHORT *aUSBStandard) 374 374 { 375 375 CheckComArgOutPointerValid(aUSBStandard); … … 399 399 DECLARE_PROTECT_FINAL_CONSTRUCT() 400 400 BEGIN_COM_MAP(USBDeviceFilter) 401 COM_INTERFACE_ENTRY(ISupportErrorInfo) 402 COM_INTERFACE_ENTRY(IUSBDeviceFilter) 401 VBOX_DEFAULT_INTERFACE_ENTRIES(IUSBDeviceFilter) 403 402 END_COM_MAP() 404 403 405 DECLARE_EMPTY_CTOR_DTOR 404 DECLARE_EMPTY_CTOR_DTOR(USBDeviceFilter) 406 405 407 406 // IUSBDeviceFilter properties 408 STDMETHOD(COMGETTER(Name)) 409 STDMETHOD(COMSETTER(Name)) 410 STDMETHOD(COMGETTER(Active)) 411 STDMETHOD(COMSETTER(Active)) 412 STDMETHOD(COMGETTER(VendorId)) 413 STDMETHOD(COMSETTER(VendorId)) 414 STDMETHOD(COMGETTER(ProductId)) 415 STDMETHOD(COMSETTER(ProductId)) 416 STDMETHOD(COMGETTER(Revision)) 417 STDMETHOD(COMSETTER(Revision)) 418 STDMETHOD(COMGETTER(Manufacturer)) 419 STDMETHOD(COMSETTER(Manufacturer)) 420 STDMETHOD(COMGETTER(Product)) 421 STDMETHOD(COMSETTER(Product)) 422 STDMETHOD(COMGETTER(SerialNumber)) 423 STDMETHOD(COMSETTER(SerialNumber)) 424 STDMETHOD(COMGETTER(Port)) 425 STDMETHOD(COMSETTER(Port)) 426 STDMETHOD(COMGETTER(Remote)) 427 STDMETHOD(COMSETTER(Remote)) 428 STDMETHOD(COMGETTER(MaskedInterfaces)) 429 STDMETHOD(COMSETTER(MaskedInterfaces)) 407 STDMETHOD(COMGETTER(Name))(BSTR *aName); 408 STDMETHOD(COMSETTER(Name))(IN_BSTR aName); 409 STDMETHOD(COMGETTER(Active))(BOOL *aActive); 410 STDMETHOD(COMSETTER(Active))(BOOL aActive); 411 STDMETHOD(COMGETTER(VendorId))(BSTR *aVendorId); 412 STDMETHOD(COMSETTER(VendorId))(IN_BSTR aVendorId); 413 STDMETHOD(COMGETTER(ProductId))(BSTR *aProductId); 414 STDMETHOD(COMSETTER(ProductId))(IN_BSTR aProductId); 415 STDMETHOD(COMGETTER(Revision))(BSTR *aRevision); 416 STDMETHOD(COMSETTER(Revision))(IN_BSTR aRevision); 417 STDMETHOD(COMGETTER(Manufacturer))(BSTR *aManufacturer); 418 STDMETHOD(COMSETTER(Manufacturer))(IN_BSTR aManufacturer); 419 STDMETHOD(COMGETTER(Product))(BSTR *aProduct); 420 STDMETHOD(COMSETTER(Product))(IN_BSTR aProduct); 421 STDMETHOD(COMGETTER(SerialNumber))(BSTR *aSerialNumber); 422 STDMETHOD(COMSETTER(SerialNumber))(IN_BSTR aSerialNumber); 423 STDMETHOD(COMGETTER(Port))(BSTR *aPort); 424 STDMETHOD(COMSETTER(Port))(IN_BSTR aPort); 425 STDMETHOD(COMGETTER(Remote))(BSTR *aRemote); 426 STDMETHOD(COMSETTER(Remote))(IN_BSTR aRemote); 427 STDMETHOD(COMGETTER(MaskedInterfaces))(ULONG *aMaskedIfs); 428 STDMETHOD(COMSETTER(MaskedInterfaces))(ULONG aMaskedIfs); 430 429 }; 431 430 #endif /* !VBOX_WITH_USB */ 432 431 433 432 434 STDMETHODIMP USBController::COMGETTER(DeviceFilters) 433 STDMETHODIMP USBController::COMGETTER(DeviceFilters)(ComSafeArrayOut(IUSBDeviceFilter *, aDevicesFilters)) 435 434 { 436 435 #ifdef VBOX_WITH_USB … … 438 437 439 438 AutoCaller autoCaller(this); 440 if 439 if(FAILED(autoCaller.rc())) return autoCaller.rc(); 441 440 442 441 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS); 443 442 444 SafeIfaceArray<IUSBDeviceFilter> collection 443 SafeIfaceArray<IUSBDeviceFilter> collection(*m->llDeviceFilters.data()); 445 444 collection.detachTo(ComSafeArrayOutArg(aDevicesFilters)); 446 445 … … 458 457 ///////////////////////////////////////////////////////////////////////////// 459 458 460 STDMETHODIMP USBController::CreateDeviceFilter 461 459 STDMETHODIMP USBController::CreateDeviceFilter(IN_BSTR aName, 460 IUSBDeviceFilter **aFilter) 462 461 { 463 462 #ifdef VBOX_WITH_USB … … 477 476 ComObjPtr<USBDeviceFilter> filter; 478 477 filter.createObject(); 479 HRESULT rc = filter->init 480 ComAssertComRCRetRC 478 HRESULT rc = filter->init(this, aName); 479 ComAssertComRCRetRC(rc); 481 480 rc = filter.queryInterfaceTo(aFilter); 482 481 AssertComRCReturnRC(rc); … … 509 508 // @todo r=dj make sure the input object is actually from us 510 509 // if (!filter) 511 // return setError 512 // tr 510 // return setError(E_INVALIDARG, 511 // tr("The given USB device filter is not created within " 513 512 // "this VirtualBox instance")); 514 513 … … 525 524 { 526 525 it = m->llDeviceFilters->begin(); 527 std::advance 526 std::advance(it, aPosition); 528 527 } 529 528 else 530 529 it = m->llDeviceFilters->end(); 531 530 /* ...and insert */ 532 m->llDeviceFilters->insert 531 m->llDeviceFilters->insert(it, filter); 533 532 filter->mInList = true; 534 533 535 534 /* notify the proxy (only when it makes sense) */ 536 535 if (filter->getData().mActive && Global::IsOnline(adep.machineState()) 537 && filter->getData().mRemote.isMatch 536 && filter->getData().mRemote.isMatch(false)) 538 537 { 539 538 USBProxyService *service = m->pHost->usbProxyService(); … … 541 540 542 541 ComAssertRet(filter->getId() == NULL, E_FAIL); 543 filter->getId() = service->insertFilter 542 filter->getId() = service->insertFilter(&filter->getData().mUSBFilter); 544 543 } 545 544 … … 592 591 /* iterate to the position... */ 593 592 DeviceFilterList::iterator it = m->llDeviceFilters->begin(); 594 std::advance 593 std::advance(it, aPosition); 595 594 /* ...get an element from there... */ 596 595 filter = *it; 597 596 /* ...and remove */ 598 597 filter->mInList = false; 599 m->llDeviceFilters->erase 598 m->llDeviceFilters->erase(it); 600 599 } 601 600 … … 607 606 /* notify the proxy (only when it makes sense) */ 608 607 if (filter->getData().mActive && Global::IsOnline(adep.machineState()) 609 && filter->getData().mRemote.isMatch 608 && filter->getData().mRemote.isMatch(false)) 610 609 { 611 610 USBProxyService *service = m->pHost->usbProxyService(); … … 719 718 (*it)->COMGETTER(ProductId)(str.asOutParam()); 720 719 f.strProductId = str; 721 (*it)->COMGETTER (Revision)(str.asOutParam());720 (*it)->COMGETTER(Revision)(str.asOutParam()); 722 721 f.strRevision = str; 723 (*it)->COMGETTER (Manufacturer)(str.asOutParam());722 (*it)->COMGETTER(Manufacturer)(str.asOutParam()); 724 723 f.strManufacturer = str; 725 (*it)->COMGETTER (Product)(str.asOutParam());724 (*it)->COMGETTER(Product)(str.asOutParam()); 726 725 f.strProduct = str; 727 (*it)->COMGETTER (SerialNumber)(str.asOutParam());726 (*it)->COMGETTER(SerialNumber)(str.asOutParam()); 728 727 f.strSerialNumber = str; 729 (*it)->COMGETTER (Port)(str.asOutParam());728 (*it)->COMGETTER(Port)(str.asOutParam()); 730 729 f.strPort = str; 731 730 f.strRemote = filterData.mRemote.string(); … … 765 764 while (it != m->llDeviceFilters->end()) 766 765 { 767 if (std::find 766 if (std::find(backedList->begin(), backedList->end(), *it) == 768 767 backedList->end()) 769 768 { 770 769 /* notify the proxy (only when it makes sense) */ 771 770 if ((*it)->getData().mActive && 772 Global::IsOnline 773 && (*it)->getData().mRemote.isMatch 771 Global::IsOnline(adep.machineState()) 772 && (*it)->getData().mRemote.isMatch(false)) 774 773 { 775 774 USBDeviceFilter *filter = *it; … … 784 783 } 785 784 786 if (Global::IsOnline 785 if (Global::IsOnline(adep.machineState())) 787 786 { 788 787 /* find all removed old filters (absent in the new list) … … 791 790 while (it != backedList->end()) 792 791 { 793 if (std::find 792 if (std::find(m->llDeviceFilters->begin(), m->llDeviceFilters->end(), *it) == 794 793 m->llDeviceFilters->end()) 795 794 { 796 795 /* notify the proxy (only when necessary) */ 797 796 if ((*it)->getData().mActive 798 && (*it)->getData().mRemote.isMatch 797 && (*it)->getData().mRemote.isMatch(false)) 799 798 { 800 799 USBDeviceFilter *flt = *it; /* resolve ambiguity */ … … 838 837 /* sanity */ 839 838 AutoCaller autoCaller(this); 840 AssertComRCReturnVoid 839 AssertComRCReturnVoid(autoCaller.rc()); 841 840 842 841 /* sanity too */ 843 842 AutoCaller peerCaller(m->pPeer); 844 AssertComRCReturnVoid 843 AssertComRCReturnVoid(peerCaller.rc()); 845 844 846 845 /* lock both for writing since we modify both (mPeer is "master" so locked … … 894 893 } 895 894 /* and add it to the new list */ 896 newList->push_back 895 newList->push_back(peer); 897 896 898 897 ++ it; … … 940 939 * represented by @a aThat (locked for reading). 941 940 */ 942 void USBController::copyFrom 943 { 944 AssertReturnVoid 941 void USBController::copyFrom(USBController *aThat) 942 { 943 AssertReturnVoid(aThat != NULL); 945 944 946 945 /* sanity */ 947 946 AutoCaller autoCaller(this); 948 AssertComRCReturnVoid 947 AssertComRCReturnVoid(autoCaller.rc()); 949 948 950 949 /* sanity too */ 951 AutoCaller thatCaller 952 AssertComRCReturnVoid 950 AutoCaller thatCaller(aThat); 951 AssertComRCReturnVoid(thatCaller.rc()); 953 952 954 953 /* even more sanity */ 955 954 AutoAnyStateDependency adep(m->pParent); 956 AssertComRCReturnVoid 955 AssertComRCReturnVoid(adep.rc()); 957 956 /* Machine::copyFrom() may not be called when the VM is running */ 958 AssertReturnVoid (!Global::IsOnline(adep.machineState()));957 AssertReturnVoid(!Global::IsOnline(adep.machineState())); 959 958 960 959 /* peer is not modified, lock it for reading (aThat is "master" so locked … … 980 979 ComObjPtr<USBDeviceFilter> filter; 981 980 filter.createObject(); 982 filter->initCopy 983 m->llDeviceFilters->push_back 981 filter->initCopy(this, *it); 982 m->llDeviceFilters->push_back(filter); 984 983 } 985 984 … … 994 993 * @note Locks nothing. 995 994 */ 996 HRESULT USBController::onDeviceFilterChange 997 995 HRESULT USBController::onDeviceFilterChange(USBDeviceFilter *aFilter, 996 BOOL aActiveChanged /* = FALSE */) 998 997 { 999 998 AutoCaller autoCaller(this); … … 1005 1004 1006 1005 /* nothing to do if the machine isn't running */ 1007 if (!Global::IsOnline 1006 if (!Global::IsOnline(adep.machineState())) 1008 1007 return S_OK; 1009 1008 … … 1018 1017 if (aActiveChanged) 1019 1018 { 1020 if (aFilter->getData().mRemote.isMatch 1019 if (aFilter->getData().mRemote.isMatch(false)) 1021 1020 { 1022 1021 /* insert/remove the filter from the proxy */ … … 1041 1040 ComAssertRet(aFilter->getId() != NULL, E_FAIL); 1042 1041 service->removeFilter(aFilter->getId()); 1043 if (aFilter->getData().mRemote.isMatch 1042 if (aFilter->getData().mRemote.isMatch(false)) 1044 1043 { 1045 1044 aFilter->getId() = service->insertFilter(&aFilter->getData().mUSBFilter); … … 1060 1059 * @note Locks this object for reading. 1061 1060 */ 1062 bool USBController::hasMatchingFilter 1063 { 1064 AutoCaller autoCaller(this); 1065 AssertComRCReturn 1061 bool USBController::hasMatchingFilter(const ComObjPtr<HostUSBDevice> &aDevice, ULONG *aMaskedIfs) 1062 { 1063 AutoCaller autoCaller(this); 1064 AssertComRCReturn(autoCaller.rc(), false); 1066 1065 1067 1066 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS); … … 1099 1098 * @note Locks this object for reading. 1100 1099 */ 1101 bool USBController::hasMatchingFilter 1100 bool USBController::hasMatchingFilter(IUSBDevice *aUSBDevice, ULONG *aMaskedIfs) 1102 1101 { 1103 1102 LogFlowThisFuncEnter(); 1104 1103 1105 1104 AutoCaller autoCaller(this); 1106 AssertComRCReturn 1105 AssertComRCReturn(autoCaller.rc(), false); 1107 1106 1108 1107 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS); … … 1116 1115 /* query fields */ 1117 1116 USBFILTER dev; 1118 USBFilterInit 1117 USBFilterInit(&dev, USBFILTERTYPE_CAPTURE); 1119 1118 1120 1119 USHORT vendorId = 0; 1121 rc = aUSBDevice->COMGETTER(VendorId) 1120 rc = aUSBDevice->COMGETTER(VendorId)(&vendorId); 1122 1121 ComAssertComRCRet(rc, false); 1123 1122 ComAssertRet(vendorId, false); 1124 int vrc = USBFilterSetNumExact 1123 int vrc = USBFilterSetNumExact(&dev, USBFILTERIDX_VENDOR_ID, vendorId, true); AssertRC(vrc); 1125 1124 1126 1125 USHORT productId = 0; 1127 rc = aUSBDevice->COMGETTER(ProductId) 1126 rc = aUSBDevice->COMGETTER(ProductId)(&productId); 1128 1127 ComAssertComRCRet(rc, false); 1129 vrc = USBFilterSetNumExact 1128 vrc = USBFilterSetNumExact(&dev, USBFILTERIDX_PRODUCT_ID, productId, true); AssertRC(vrc); 1130 1129 1131 1130 USHORT revision; 1132 rc = aUSBDevice->COMGETTER(Revision) 1131 rc = aUSBDevice->COMGETTER(Revision)(&revision); 1133 1132 ComAssertComRCRet(rc, false); 1134 vrc = USBFilterSetNumExact 1133 vrc = USBFilterSetNumExact(&dev, USBFILTERIDX_DEVICE, revision, true); AssertRC(vrc); 1135 1134 1136 1135 Bstr manufacturer; 1137 rc = aUSBDevice->COMGETTER(Manufacturer) 1136 rc = aUSBDevice->COMGETTER(Manufacturer)(manufacturer.asOutParam()); 1138 1137 ComAssertComRCRet(rc, false); 1139 1138 if (!manufacturer.isEmpty()) 1140 USBFilterSetStringExact 1139 USBFilterSetStringExact(&dev, USBFILTERIDX_MANUFACTURER_STR, Utf8Str(manufacturer).c_str(), true); 1141 1140 1142 1141 Bstr product; 1143 rc = aUSBDevice->COMGETTER(Product) 1142 rc = aUSBDevice->COMGETTER(Product)(product.asOutParam()); 1144 1143 ComAssertComRCRet(rc, false); 1145 1144 if (!product.isEmpty()) 1146 USBFilterSetStringExact 1145 USBFilterSetStringExact(&dev, USBFILTERIDX_PRODUCT_STR, Utf8Str(product).c_str(), true); 1147 1146 1148 1147 Bstr serialNumber; 1149 rc = aUSBDevice->COMGETTER(SerialNumber) 1148 rc = aUSBDevice->COMGETTER(SerialNumber)(serialNumber.asOutParam()); 1150 1149 ComAssertComRCRet(rc, false); 1151 1150 if (!serialNumber.isEmpty()) 1152 USBFilterSetStringExact 1151 USBFilterSetStringExact(&dev, USBFILTERIDX_SERIAL_NUMBER_STR, Utf8Str(serialNumber).c_str(), true); 1153 1152 1154 1153 Bstr address; 1155 rc = aUSBDevice->COMGETTER(Address) 1154 rc = aUSBDevice->COMGETTER(Address)(address.asOutParam()); 1156 1155 ComAssertComRCRet(rc, false); 1157 1156 … … 1159 1158 rc = aUSBDevice->COMGETTER(Port)(&port); 1160 1159 ComAssertComRCRet(rc, false); 1161 USBFilterSetNumExact 1160 USBFilterSetNumExact(&dev, USBFILTERIDX_PORT, port, true); 1162 1161 1163 1162 BOOL remote = FALSE; … … 1178 1177 if (!aData.mActive) 1179 1178 continue; 1180 if (!aData.mRemote.isMatch 1179 if (!aData.mRemote.isMatch(remote)) 1181 1180 continue; 1182 if (!USBFilterMatch 1181 if (!USBFilterMatch(&aData.mUSBFilter, &dev)) 1183 1182 continue; 1184 1183 … … 1202 1201 * @note Locks this object for reading. 1203 1202 */ 1204 HRESULT USBController::notifyProxy 1203 HRESULT USBController::notifyProxy(bool aInsertFilters) 1205 1204 { 1206 1205 LogFlowThisFunc(("aInsertFilters=%RTbool\n", aInsertFilters)); 1207 1206 1208 1207 AutoCaller autoCaller(this); 1209 AssertComRCReturn 1208 AssertComRCReturn(autoCaller.rc(), false); 1210 1209 1211 1210 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS); … … 1221 1220 /* notify the proxy (only if the filter is active) */ 1222 1221 if (flt->getData().mActive 1223 && flt->getData().mRemote.isMatch 1222 && flt->getData().mRemote.isMatch(false) /* and if the filter is NOT remote */ 1224 1223 ) 1225 1224 {
Note:
See TracChangeset
for help on using the changeset viewer.