Changeset 47376 in vbox
- Timestamp:
- Jul 24, 2013 3:13:52 PM (11 years ago)
- Location:
- trunk
- Files:
-
- 16 edited
- 2 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/VBox/log.h
r47218 r47376 492 492 /** Main group, IUSBDeviceFilter. */ 493 493 LOG_GROUP_MAIN_USBDEVICEFILTER, 494 /** Main group, IUSBDeviceFilters. */ 495 LOG_GROUP_MAIN_USBDEVICEFILTERS, 494 496 /** Main group, IUSBDeviceStateChangedEvent. */ 495 497 LOG_GROUP_MAIN_USBDEVICESTATECHANGEDEVENT, … … 893 895 "MAIN_USBDEVICE", \ 894 896 "MAIN_USBDEVICEFILTER", \ 897 "MAIN_USBDEVICEFILTERS", \ 895 898 "MAIN_USBDEVICESTATECHANGEDEVENT", \ 896 899 "MAIN_VBOXSVCAVAILABILITYCHANGEDEVENT", \ -
trunk/src/VBox/Frontends/VBoxManage/VBoxManageInfo.cpp
r47246 r47376 1770 1770 else 1771 1771 RTPrintf("EHCI: %s\n", fEHCIEnabled ? "enabled" : "disabled"); 1772 1772 } 1773 1774 ComPtr<IUSBDeviceFilters> USBFlts; 1775 rc = machine->COMGETTER(USBDeviceFilters)(USBFlts.asOutParam()); 1776 if (SUCCEEDED(rc)) 1777 { 1773 1778 SafeIfaceArray <IUSBDeviceFilter> Coll; 1774 rc = USB Ctl->COMGETTER(DeviceFilters)(ComSafeArrayAsOutParam(Coll));1779 rc = USBFlts->COMGETTER(DeviceFilters)(ComSafeArrayAsOutParam(Coll)); 1775 1780 if (SUCCEEDED(rc)) 1776 1781 { -
trunk/src/VBox/Frontends/VBoxManage/VBoxManageUSB.cpp
r46658 r47376 400 400 401 401 ComPtr <IHost> host; 402 ComPtr <IUSB Controller> ctl;402 ComPtr <IUSBDeviceFilters> flts; 403 403 if (cmd.mGlobal) 404 404 CHECK_ERROR_RET(a->virtualBox, COMGETTER(Host)(host.asOutParam()), 1); … … 409 409 /* get the mutable session machine */ 410 410 a->session->COMGETTER(Machine)(cmd.mMachine.asOutParam()); 411 /* and get the USB controller*/412 CHECK_ERROR_RET(cmd.mMachine, COMGETTER(USB Controller)(ctl.asOutParam()), 1);411 /* and get the USB device filters */ 412 CHECK_ERROR_RET(cmd.mMachine, COMGETTER(USBDeviceFilters)(flts.asOutParam()), 1); 413 413 } 414 414 … … 446 446 { 447 447 ComPtr <IUSBDeviceFilter> flt; 448 CHECK_ERROR_BREAK( ctl, CreateDeviceFilter(f.mName.raw(),448 CHECK_ERROR_BREAK(flts, CreateDeviceFilter(f.mName.raw(), 449 449 flt.asOutParam())); 450 450 … … 466 466 CHECK_ERROR_BREAK(flt, COMSETTER(MaskedInterfaces)(f.mMaskedInterfaces)); 467 467 468 CHECK_ERROR_BREAK( ctl, InsertDeviceFilter(cmd.mIndex, flt));468 CHECK_ERROR_BREAK(flts, InsertDeviceFilter(cmd.mIndex, flt)); 469 469 } 470 470 break; … … 502 502 { 503 503 SafeIfaceArray <IUSBDeviceFilter> coll; 504 CHECK_ERROR_BREAK( ctl, COMGETTER(DeviceFilters)(ComSafeArrayAsOutParam(coll)));504 CHECK_ERROR_BREAK(flts, COMGETTER(DeviceFilters)(ComSafeArrayAsOutParam(coll))); 505 505 506 506 ComPtr <IUSBDeviceFilter> flt = coll[cmd.mIndex]; … … 537 537 { 538 538 ComPtr <IUSBDeviceFilter> flt; 539 CHECK_ERROR_BREAK( ctl, RemoveDeviceFilter(cmd.mIndex, flt.asOutParam()));539 CHECK_ERROR_BREAK(flts, RemoveDeviceFilter(cmd.mIndex, flt.asOutParam())); 540 540 } 541 541 break; -
trunk/src/VBox/Frontends/VirtualBox/src/globals/VBoxGlobal.cpp
r47170 r47376 93 93 #include "CSystemProperties.h" 94 94 #include "CUSBDevice.h" 95 #include "CUSBDeviceFilters.h" 95 96 #include "CUSBDeviceFilter.h" 96 97 #include "CBIOSSettings.h" … … 1512 1513 1513 1514 CUSBController ctl = aMachine.GetUSBController(); 1515 CUSBDeviceFilters flts = aMachine.GetUSBDeviceFilters(); 1514 1516 if ( !ctl.isNull() 1517 && !flts.isNull() 1515 1518 && ctl.GetProxyAvailable()) 1516 1519 { … … 1519 1522 if (ctl.GetEnabled()) 1520 1523 { 1521 CUSBDeviceFilterVector coll = ctl.GetDeviceFilters();1524 CUSBDeviceFilterVector coll = flts.GetDeviceFilters(); 1522 1525 uint active = 0; 1523 1526 for (int i = 0; i < coll.size(); ++i) -
trunk/src/VBox/Frontends/VirtualBox/src/selector/graphics/details/UIGDetailsElements.cpp
r47355 r47376 42 42 #include "CParallelPort.h" 43 43 #include "CUSBController.h" 44 #include "CUSBDeviceFilters.h" 44 45 #include "CUSBDeviceFilter.h" 45 46 #include "CSharedFolder.h" … … 891 892 if (!ctl.isNull() && ctl.GetProxyAvailable()) 892 893 { 893 if (ctl.GetEnabled()) 894 const CUSBDeviceFilters &flts = machine().GetUSBDeviceFilters(); 895 if (!flts.isNull() && ctl.GetEnabled()) 894 896 { 895 const CUSBDeviceFilterVector &coll = ctl.GetDeviceFilters();897 const CUSBDeviceFilterVector &coll = flts.GetDeviceFilters(); 896 898 uint uActive = 0; 897 899 for (int i = 0; i < coll.size(); ++i) -
trunk/src/VBox/Frontends/VirtualBox/src/settings/machine/UIMachineSettingsUSB.cpp
r45358 r47376 36 36 #include "CConsole.h" 37 37 #include "CUSBController.h" 38 #include "CUSBDeviceFilters.h" 38 39 #include "CUSBDevice.h" 39 40 #include "CUSBDeviceFilter.h" … … 301 302 302 303 /* For each USB filter: */ 303 const CUSBDeviceFilter Vector &filters = controller.GetDeviceFilters();304 for (int iFilterIndex = 0; iFilterIndex < filters.size(); ++iFilterIndex)304 const CUSBDeviceFilters &filters = m_machine.GetUSBDeviceFilters(); 305 if (!filters.isNull()) 305 306 { 306 /* Prepare USB filter data: */ 307 UIDataSettingsMachineUSBFilter usbFilterData; 308 309 /* Check if filter is valid: */ 310 const CUSBDeviceFilter &filter = filters[iFilterIndex]; 311 if (!filter.isNull()) 307 const CUSBDeviceFilterVector &coll = filters.GetDeviceFilters(); 308 for (int iFilterIndex = 0; iFilterIndex < coll.size(); ++iFilterIndex) 312 309 { 313 usbFilterData.m_fActive = filter.GetActive(); 314 usbFilterData.m_strName = filter.GetName(); 315 usbFilterData.m_strVendorId = filter.GetVendorId(); 316 usbFilterData.m_strProductId = filter.GetProductId(); 317 usbFilterData.m_strRevision = filter.GetRevision(); 318 usbFilterData.m_strManufacturer = filter.GetManufacturer(); 319 usbFilterData.m_strProduct = filter.GetProduct(); 320 usbFilterData.m_strSerialNumber = filter.GetSerialNumber(); 321 usbFilterData.m_strPort = filter.GetPort(); 322 usbFilterData.m_strRemote = filter.GetRemote(); 310 /* Prepare USB filter data: */ 311 UIDataSettingsMachineUSBFilter usbFilterData; 312 313 /* Check if filter is valid: */ 314 const CUSBDeviceFilter &filter = coll[iFilterIndex]; 315 if (!filter.isNull()) 316 { 317 usbFilterData.m_fActive = filter.GetActive(); 318 usbFilterData.m_strName = filter.GetName(); 319 usbFilterData.m_strVendorId = filter.GetVendorId(); 320 usbFilterData.m_strProductId = filter.GetProductId(); 321 usbFilterData.m_strRevision = filter.GetRevision(); 322 usbFilterData.m_strManufacturer = filter.GetManufacturer(); 323 usbFilterData.m_strProduct = filter.GetProduct(); 324 usbFilterData.m_strSerialNumber = filter.GetSerialNumber(); 325 usbFilterData.m_strPort = filter.GetPort(); 326 usbFilterData.m_strRemote = filter.GetRemote(); 327 } 328 329 /* Cache USB filter data: */ 330 m_cache.child(iFilterIndex).cacheInitialData(usbFilterData); 323 331 } 324 325 /* Cache USB filter data: */326 m_cache.child(iFilterIndex).cacheInitialData(usbFilterData);327 332 } 328 333 } … … 490 495 { 491 496 /* Get USB data from cache: */ 497 CUSBDeviceFilters filters = m_machine.GetUSBDeviceFilters(); 492 498 const UIDataSettingsMachineUSB &usbData = m_cache.data(); 493 499 /* Store USB data: */ … … 498 504 } 499 505 /* Store USB filters data: */ 500 if (isMachineInValidMode()) 506 if ( isMachineInValidMode() 507 && !filters.isNull()) 501 508 { 502 509 /* For each USB filter data set: */ … … 511 518 if (usbFilterCache.wasRemoved() || usbFilterCache.wasUpdated()) 512 519 { 513 controller.RemoveDeviceFilter(iOperationPosition);520 filters.RemoveDeviceFilter(iOperationPosition); 514 521 if (usbFilterCache.wasRemoved()) 515 522 --iOperationPosition; … … 522 529 const UIDataSettingsMachineUSBFilter &usbFilterData = usbFilterCache.data(); 523 530 /* Store USB filter data: */ 524 CUSBDeviceFilter filter = controller.CreateDeviceFilter(usbFilterData.m_strName);531 CUSBDeviceFilter filter = filters.CreateDeviceFilter(usbFilterData.m_strName); 525 532 filter.SetActive(usbFilterData.m_fActive); 526 533 filter.SetVendorId(usbFilterData.m_strVendorId); … … 532 539 filter.SetPort(usbFilterData.m_strPort); 533 540 filter.SetRemote(usbFilterData.m_strRemote); 534 controller.InsertDeviceFilter(iOperationPosition, filter);541 filters.InsertDeviceFilter(iOperationPosition, filter); 535 542 } 536 543 } -
trunk/src/VBox/Main/Makefile.kmk
r47018 r47376 357 357 src-server/SystemPropertiesImpl.cpp \ 358 358 src-server/USBControllerImpl.cpp \ 359 src-server/USBDeviceFiltersImpl.cpp \ 359 360 src-server/VFSExplorerImpl.cpp \ 360 361 src-server/VirtualBoxImpl.cpp \ -
trunk/src/VBox/Main/idl/VirtualBox.xidl
r47338 r47376 4127 4127 <interface 4128 4128 name="IMachine" extends="$unknown" 4129 uuid=" f6258810-a760-11e2-9e96-0800200c9a66"4129 uuid="00daa773-1d35-40ae-ac06-336aa64959ef" 4130 4130 wsmap="managed" 4131 4131 > … … 4535 4535 </attribute> 4536 4536 4537 <attribute name="USBDeviceFilters" type="IUSBDeviceFilters" readonly="yes"> 4538 <desc> 4539 Associated USB device filters object. 4540 4541 <note> 4542 If USB functionality is not available in the given edition of 4543 VirtualBox, this method will set the result code to @c E_NOTIMPL. 4544 </note> 4545 </desc> 4546 </attribute> 4547 4537 4548 <attribute name="audioAdapter" type="IAudioAdapter" readonly="yes"> 4538 4549 <desc>Associated audio adapter, always present.</desc> … … 7614 7625 be returned if the host computer refuses to release it for some reason. 7615 7626 7616 <see><link to="IUSB Controller::deviceFilters"/>,7627 <see><link to="IUSBDeviceFilters::deviceFilters"/>, 7617 7628 <link to="USBDeviceState"/></see> 7618 7629 <result name="VBOX_E_INVALID_VM_STATE"> … … 7638 7649 a possible automatic re-attachment. 7639 7650 7640 <see><link to="IUSB Controller::deviceFilters"/>,7651 <see><link to="IUSBDeviceFilters::deviceFilters"/>, 7641 7652 <link to="USBDeviceState"/></see> 7642 7653 … … 8224 8235 Unless the device is ignored by these filters, filters of all 8225 8236 currently running virtual machines 8226 (<link to="IUSB Controller::deviceFilters"/>) are applied to it.8237 (<link to="IUSBDeviceFilters::deviceFilters"/>) are applied to it. 8227 8238 8228 8239 <note> … … 16311 16322 16312 16323 <!-- 16313 // IUSB Controller16324 // IUSBDeviceFilters 16314 16325 ///////////////////////////////////////////////////////////////////////// 16315 16326 --> 16316 16327 16317 16328 <interface 16318 name="IUSB Controller" extends="$unknown"16319 uuid=" 01e6f13a-0580-452f-a40f-74e32a5e4921"16329 name="IUSBDeviceFilters" extends="$unknown" 16330 uuid="2ab550b2-53cc-4c2e-ae07-0adf4114e75c" 16320 16331 wsmap="managed" 16321 16332 > 16322 <attribute name="enabled" type="boolean">16323 <desc>16324 Flag whether the USB controller is present in the16325 guest system. If disabled, the virtual guest hardware will16326 not contain any USB controller. Can only be changed when16327 the VM is powered off.16328 </desc>16329 </attribute>16330 16331 <attribute name="enabledEHCI" type="boolean">16332 <desc>16333 Flag whether the USB EHCI controller is present in the16334 guest system. If disabled, the virtual guest hardware will16335 not contain a USB EHCI controller. Can only be changed when16336 the VM is powered off.16337 </desc>16338 </attribute>16339 16340 <attribute name="proxyAvailable" type="boolean" readonly="yes">16341 <desc>16342 Flag whether there is an USB proxy available.16343 </desc>16344 </attribute>16345 16346 <attribute name="USBStandard" type="unsigned short" readonly="yes">16347 <desc>16348 USB standard version which the controller implements.16349 This is a BCD which means that the major version is in the16350 high byte and minor version is in the low byte.16351 </desc>16352 </attribute>16353 16333 16354 16334 <attribute name="deviceFilters" type="IUSBDeviceFilter" readonly="yes" safearray="yes"> … … 16464 16444 </param> 16465 16445 </method> 16446 16447 </interface> 16448 16449 <!-- 16450 // IUSBController 16451 ///////////////////////////////////////////////////////////////////////// 16452 --> 16453 16454 <interface 16455 name="IUSBController" extends="$unknown" 16456 uuid="f12e6dda-2bad-40c4-8f2e-2d08fe8b74d4" 16457 wsmap="managed" 16458 > 16459 <attribute name="enabled" type="boolean"> 16460 <desc> 16461 Flag whether the USB controller is present in the 16462 guest system. If disabled, the virtual guest hardware will 16463 not contain any USB controller. Can only be changed when 16464 the VM is powered off. 16465 </desc> 16466 </attribute> 16467 16468 <attribute name="enabledEHCI" type="boolean"> 16469 <desc> 16470 Flag whether the USB EHCI controller is present in the 16471 guest system. If disabled, the virtual guest hardware will 16472 not contain a USB EHCI controller. Can only be changed when 16473 the VM is powered off. 16474 </desc> 16475 </attribute> 16476 16477 <attribute name="proxyAvailable" type="boolean" readonly="yes"> 16478 <desc> 16479 Flag whether there is an USB proxy available. 16480 </desc> 16481 </attribute> 16482 16483 <attribute name="USBStandard" type="unsigned short" readonly="yes"> 16484 <desc> 16485 USB standard version which the controller implements. 16486 This is a BCD which means that the major version is in the 16487 high byte and minor version is in the low byte. 16488 </desc> 16489 </attribute> 16466 16490 16467 16491 </interface> … … 16632 16656 </note> 16633 16657 16634 <see><link to="IUSB Controller::deviceFilters"/>,16658 <see><link to="IUSBDeviceFilters::deviceFilters"/>, 16635 16659 <link to="IHostUSBDeviceFilter"/></see> 16636 16660 </desc> … … 16747 16771 either ignore the device, or put it to USBDeviceState_Held state, or do 16748 16772 nothing. Unless the device is ignored by global filters, filters of all 16749 currently running guests (<link to="IUSB Controller::deviceFilters"/>) are16773 currently running guests (<link to="IUSBDeviceFilters::deviceFilters"/>) are 16750 16774 activated that can put it to USBDeviceState_Captured state. 16751 16775 … … 16878 16902 The <link to="IUSBDeviceFilter::remote"/> attribute is ignored by this type of 16879 16903 filters, because it makes sense only for 16880 <link to="IUSB Controller::deviceFilters">machine USB filters</link>.16904 <link to="IUSBDeviceFilters::deviceFilters">machine USB filters</link>. 16881 16905 </note> 16882 16906 -
trunk/src/VBox/Main/include/MachineImpl.h
r46667 r47376 65 65 class MachineDebugger; 66 66 class USBController; 67 class USBDeviceFilters; 67 68 class Snapshot; 68 69 class SharedFolder; … … 457 458 STDMETHOD(COMGETTER(AudioAdapter))(IAudioAdapter **audioAdapter); 458 459 STDMETHOD(COMGETTER(USBController))(IUSBController * *aUSBController); 460 STDMETHOD(COMGETTER(USBDeviceFilters))(IUSBDeviceFilters * *aUSBDeviceFilters); 459 461 STDMETHOD(COMGETTER(SettingsFilePath))(BSTR *aFilePath); 460 462 STDMETHOD(COMGETTER(SettingsModified))(BOOL *aModified); … … 755 757 void getDefaultVideoCaptureFile(Utf8Str &strFile); 756 758 759 bool isUSBControllerPresent(); 760 757 761 HRESULT launchVMProcess(IInternalSessionControl *aControl, 758 762 const Utf8Str &strType, … … 990 994 // so they cannot be a part of HWData 991 995 992 const ComObjPtr<VRDEServer> mVRDEServer; 993 const ComObjPtr<SerialPort> mSerialPorts[SchemaDefs::SerialPortCount]; 994 const ComObjPtr<ParallelPort> mParallelPorts[SchemaDefs::ParallelPortCount]; 995 const ComObjPtr<AudioAdapter> mAudioAdapter; 996 const ComObjPtr<USBController> mUSBController; 997 const ComObjPtr<BIOSSettings> mBIOSSettings; 996 const ComObjPtr<VRDEServer> mVRDEServer; 997 const ComObjPtr<SerialPort> mSerialPorts[SchemaDefs::SerialPortCount]; 998 const ComObjPtr<ParallelPort> mParallelPorts[SchemaDefs::ParallelPortCount]; 999 const ComObjPtr<AudioAdapter> mAudioAdapter; 1000 const ComObjPtr<USBController> mUSBController; 1001 const ComObjPtr<USBDeviceFilters> mUSBDeviceFilters; 1002 const ComObjPtr<BIOSSettings> mBIOSSettings; 998 1003 typedef std::vector<ComObjPtr<NetworkAdapter> > NetworkAdapterVector; 999 1004 NetworkAdapterVector mNetworkAdapters; -
trunk/src/VBox/Main/include/USBControllerImpl.h
r42551 r47376 64 64 STDMETHOD(COMGETTER(ProxyAvailable))(BOOL *aEnabled); 65 65 STDMETHOD(COMGETTER(USBStandard))(USHORT *aUSBStandard); 66 STDMETHOD(COMGETTER(DeviceFilters))(ComSafeArrayOut(IUSBDeviceFilter *, aDevicesFilters));67 68 // IUSBController methods69 STDMETHOD(CreateDeviceFilter)(IN_BSTR aName, IUSBDeviceFilter **aFilter);70 STDMETHOD(InsertDeviceFilter)(ULONG aPosition, IUSBDeviceFilter *aFilter);71 STDMETHOD(RemoveDeviceFilter)(ULONG aPosition, IUSBDeviceFilter **aFilter);72 66 73 67 // public methods only for internal purposes … … 79 73 void commit(); 80 74 void copyFrom(USBController *aThat); 81 82 #ifdef VBOX_WITH_USB83 HRESULT onDeviceFilterChange(USBDeviceFilter *aFilter,84 BOOL aActiveChanged = FALSE);85 86 bool hasMatchingFilter(const ComObjPtr<HostUSBDevice> &aDevice, ULONG *aMaskedIfs);87 bool hasMatchingFilter(IUSBDevice *aUSBDevice, ULONG *aMaskedIfs);88 89 HRESULT notifyProxy(bool aInsertFilters);90 #endif /* VBOX_WITH_USB */91 92 // public methods for internal purposes only93 // (ensure there is a caller and a read lock before calling them!)94 Machine* getMachine();95 75 96 76 private: -
trunk/src/VBox/Main/include/USBDeviceFilterImpl.h
r44528 r47376 24 24 #include <VBox/usbfilter.h> 25 25 26 class USB Controller;26 class USBDeviceFilters; 27 27 class Host; 28 28 namespace settings … … 83 83 84 84 // public initializer/uninitializer for internal purposes only 85 HRESULT init(USB Controller*aParent,85 HRESULT init(USBDeviceFilters *aParent, 86 86 const settings::USBDeviceFilter &data); 87 HRESULT init(USB Controller*aParent, IN_BSTR aName);88 HRESULT init(USB Controller*aParent, USBDeviceFilter *aThat,87 HRESULT init(USBDeviceFilters *aParent, IN_BSTR aName); 88 HRESULT init(USBDeviceFilters *aParent, USBDeviceFilter *aThat, 89 89 bool aReshare = false); 90 HRESULT initCopy(USB Controller*aParent, USBDeviceFilter *aThat);90 HRESULT initCopy(USBDeviceFilters *aParent, USBDeviceFilter *aThat); 91 91 void uninit(); 92 92 … … 143 143 HRESULT usbFilterFieldSetter(USBFILTERIDX aIdx, const Utf8Str &strNew); 144 144 145 USB Controller * constmParent;146 USBDeviceFilter * const mPeer;145 USBDeviceFilters * const mParent; 146 USBDeviceFilter * const mPeer; 147 147 148 148 Backupable<Data> mData; … … 154 154 bool mInList; 155 155 156 friend class USB Controller;156 friend class USBDeviceFilters; 157 157 }; 158 158 -
trunk/src/VBox/Main/include/USBDeviceFiltersImpl.h
r47360 r47376 3 3 /** @file 4 4 * 5 * VBox USB ControllerCOM Class declaration.5 * VBox USBDeviceFilters COM Class declaration. 6 6 */ 7 7 8 8 /* 9 * Copyright (C) 20 05-2012Oracle Corporation9 * Copyright (C) 2013 Oracle Corporation 10 10 * 11 11 * This file is part of VirtualBox Open Source Edition (OSE), as … … 18 18 */ 19 19 20 #ifndef ____H_USB CONTROLLERIMPL21 #define ____H_USB CONTROLLERIMPL20 #ifndef ____H_USBDEVICEFILTERSIMPL 21 #define ____H_USBDEVICEFILTERSIMPL 22 22 23 23 #include "VirtualBoxBase.h" … … 31 31 } 32 32 33 class ATL_NO_VTABLE USB Controller:33 class ATL_NO_VTABLE USBDeviceFilters : 34 34 public VirtualBoxBase, 35 VBOX_SCRIPTABLE_IMPL(IUSB Controller)35 VBOX_SCRIPTABLE_IMPL(IUSBDeviceFilters) 36 36 { 37 37 public: 38 VIRTUALBOXBASE_ADD_ERRORINFO_SUPPORT(USB Controller, IUSBController)38 VIRTUALBOXBASE_ADD_ERRORINFO_SUPPORT(USBDeviceFilters, IUSBDeviceFilters) 39 39 40 DECLARE_NOT_AGGREGATABLE(USB Controller)40 DECLARE_NOT_AGGREGATABLE(USBDeviceFilters) 41 41 42 42 DECLARE_PROTECT_FINAL_CONSTRUCT() 43 43 44 44 BEGIN_COM_MAP(USBController) 45 VBOX_DEFAULT_INTERFACE_ENTRIES(IUSB Controller)45 VBOX_DEFAULT_INTERFACE_ENTRIES(IUSBDeviceFilters) 46 46 END_COM_MAP() 47 47 48 DECLARE_EMPTY_CTOR_DTOR(USB Controller)48 DECLARE_EMPTY_CTOR_DTOR(USBDeviceFilters) 49 49 50 50 HRESULT FinalConstruct(); … … 53 53 // public initializer/uninitializer for internal purposes only 54 54 HRESULT init(Machine *aParent); 55 HRESULT init(Machine *aParent, USB Controller*aThat);56 HRESULT initCopy(Machine *aParent, USB Controller*aThat);55 HRESULT init(Machine *aParent, USBDeviceFilters *aThat); 56 HRESULT initCopy(Machine *aParent, USBDeviceFilters *aThat); 57 57 void uninit(); 58 58 59 // IUSBController properties 60 STDMETHOD(COMGETTER(Enabled))(BOOL *aEnabled); 61 STDMETHOD(COMSETTER(Enabled))(BOOL aEnabled); 62 STDMETHOD(COMGETTER(EnabledEHCI))(BOOL *aEnabled); 63 STDMETHOD(COMSETTER(EnabledEHCI))(BOOL aEnabled); 64 STDMETHOD(COMGETTER(ProxyAvailable))(BOOL *aEnabled); 65 STDMETHOD(COMGETTER(USBStandard))(USHORT *aUSBStandard); 59 // IUSBDeviceFilters attributes 66 60 STDMETHOD(COMGETTER(DeviceFilters))(ComSafeArrayOut(IUSBDeviceFilter *, aDevicesFilters)); 67 61 68 // IUSB Controllermethods62 // IUSBDeviceFilters methods 69 63 STDMETHOD(CreateDeviceFilter)(IN_BSTR aName, IUSBDeviceFilter **aFilter); 70 64 STDMETHOD(InsertDeviceFilter)(ULONG aPosition, IUSBDeviceFilter *aFilter); … … 78 72 void rollback(); 79 73 void commit(); 80 void copyFrom(USB Controller*aThat);74 void copyFrom(USBDeviceFilters *aThat); 81 75 82 76 #ifdef VBOX_WITH_USB … … 102 96 }; 103 97 104 #endif //!____H_USB CONTROLLERIMPL98 #endif //!____H_USBDEVICEFILTERSIMPL 105 99 /* vi: set tabstop=4 shiftwidth=4 expandtab: */ -
trunk/src/VBox/Main/src-server/MachineImpl.cpp
r46825 r47376 41 41 #include "MediumLock.h" 42 42 #include "USBControllerImpl.h" 43 #include "USBDeviceFiltersImpl.h" 43 44 #include "HostImpl.h" 44 45 #include "SharedFolderImpl.h" … … 49 50 #include "DisplayImpl.h" 50 51 #include "DisplayUtils.h" 51 #include "BandwidthControlImpl.h"52 52 #include "MachineImplCloneVM.h" 53 53 #include "AutostartDb.h" … … 2765 2765 * (w/o treating it as a failure), for example, as in OSE */ 2766 2766 NOREF(aUSBController); 2767 ReturnComNotImplemented(); 2768 #endif /* VBOX_WITH_VUSB */ 2769 } 2770 2771 STDMETHODIMP Machine::COMGETTER(USBDeviceFilters)(IUSBDeviceFilters **aUSBDeviceFilters) 2772 { 2773 #ifdef VBOX_WITH_VUSB 2774 CheckComArgOutPointerValid(aUSBDeviceFilters); 2775 2776 AutoCaller autoCaller(this); 2777 if (FAILED(autoCaller.rc())) return autoCaller.rc(); 2778 2779 clearError(); 2780 MultiResult rc(S_OK); 2781 2782 # ifdef VBOX_WITH_USB 2783 rc = mParent->host()->checkUSBProxyService(); 2784 if (FAILED(rc)) return rc; 2785 # endif 2786 2787 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS); 2788 2789 return rc = mUSBDeviceFilters.queryInterfaceTo(aUSBDeviceFilters); 2790 #else 2791 /* Note: The GUI depends on this method returning E_NOTIMPL with no 2792 * extended error info to indicate that USB is simply not available 2793 * (w/o treating it as a failure), for example, as in OSE */ 2794 NOREF(aUSBDeviceFilters); 2767 2795 ReturnComNotImplemented(); 2768 2796 #endif /* VBOX_WITH_VUSB */ … … 7706 7734 strFile.stripExt(); // path/to/machinesfolder/vmname/vmname 7707 7735 strFile.append(".webm"); // path/to/machinesfolder/vmname/vmname.webm 7736 } 7737 7738 /** 7739 * Returns whether at least one USB controller is present for the VM. 7740 */ 7741 bool Machine::isUSBControllerPresent() 7742 { 7743 AutoCaller autoCaller(this); 7744 AssertComRCReturn(autoCaller.rc(), false); 7745 7746 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS); 7747 7748 BOOL fEnabled = FALSE; 7749 HRESULT rc = mUSBController->COMGETTER(Enabled)(&fEnabled); 7750 if (SUCCEEDED(rc)) 7751 return !!fEnabled; 7752 else 7753 return false; 7708 7754 } 7709 7755 … … 8472 8518 mUSBController->init(this); 8473 8519 8520 /* create the USB device filters object (always present) */ 8521 unconst(mUSBDeviceFilters).createObject(); 8522 mUSBDeviceFilters->init(this); 8523 8474 8524 /* create associated network adapter objects */ 8475 8525 mNetworkAdapters.resize(Global::getMaxNetworkAdapters(mHWData->mChipsetType)); … … 8523 8573 mUSBController->uninit(); 8524 8574 unconst(mUSBController).setNull(); 8575 } 8576 8577 if (mUSBDeviceFilters) 8578 { 8579 mUSBDeviceFilters->uninit(); 8580 unconst(mUSBDeviceFilters).setNull(); 8525 8581 } 8526 8582 … … 9120 9176 /* USB Controller */ 9121 9177 rc = mUSBController->loadSettings(data.usbController); 9178 if (FAILED(rc)) return rc; 9179 9180 /* USB device filters */ 9181 rc = mUSBDeviceFilters->loadSettings(data.usbController); 9122 9182 if (FAILED(rc)) return rc; 9123 9183 … … 10359 10419 if (FAILED(rc)) throw rc; 10360 10420 10421 /* USB device filters (required) */ 10422 rc = mUSBDeviceFilters->saveSettings(data.usbController); 10423 if (FAILED(rc)) throw rc; 10424 10361 10425 /* Network adapters (required) */ 10362 10426 uint32_t uMaxNICs = RT_MIN(Global::getMaxNetworkAdapters(mHWData->mChipsetType), mNetworkAdapters.size()); … … 11764 11828 mUSBController->rollback(); 11765 11829 11830 if (mUSBDeviceFilters && (mData->flModifications & IsModified_USB)) 11831 mUSBDeviceFilters->rollback(); 11832 11766 11833 if (mBandwidthControl && (mData->flModifications & IsModified_BandwidthControl)) 11767 11834 mBandwidthControl->rollback(); … … 11868 11935 mAudioAdapter->commit(); 11869 11936 mUSBController->commit(); 11937 mUSBDeviceFilters->commit(); 11870 11938 mBandwidthControl->commit(); 11871 11939 … … 12046 12114 mAudioAdapter->copyFrom(aThat->mAudioAdapter); 12047 12115 mUSBController->copyFrom(aThat->mUSBController); 12116 mUSBDeviceFilters->copyFrom(aThat->mUSBDeviceFilters); 12048 12117 mBandwidthControl->copyFrom(aThat->mBandwidthControl); 12049 12118 … … 12474 12543 mUSBController->init(this, aMachine->mUSBController); 12475 12544 12545 /* create another USB device filters object that will be mutable */ 12546 unconst(mUSBDeviceFilters).createObject(); 12547 mUSBDeviceFilters->init(this, aMachine->mUSBDeviceFilters); 12548 12476 12549 /* create a list of network adapters that will be mutable */ 12477 12550 mNetworkAdapters.resize(aMachine->mNetworkAdapters.size()); … … 12579 12652 * This is identical to SessionMachine::DetachAllUSBDevices except 12580 12653 * for the aAbnormal argument. */ 12581 HRESULT rc = mUSB Controller->notifyProxy(false /* aInsertFilters */);12654 HRESULT rc = mUSBDeviceFilters->notifyProxy(false /* aInsertFilters */); 12582 12655 AssertComRC(rc); 12583 12656 NOREF(rc); … … 13043 13116 13044 13117 #ifdef VBOX_WITH_USB 13045 *aMatched = mUSB Controller->hasMatchingFilter(aUSBDevice, aMaskedIfs);13118 *aMatched = mUSBDeviceFilters->hasMatchingFilter(aUSBDevice, aMaskedIfs); 13046 13119 #else 13047 13120 NOREF(aUSBDevice); … … 13115 13188 13116 13189 #ifdef VBOX_WITH_USB 13117 HRESULT rc = mUSB Controller->notifyProxy(true /* aInsertFilters */);13190 HRESULT rc = mUSBDeviceFilters->notifyProxy(true /* aInsertFilters */); 13118 13191 AssertComRC(rc); 13119 13192 NOREF(rc); … … 13145 13218 13146 13219 #ifdef VBOX_WITH_USB 13147 HRESULT rc = mUSB Controller->notifyProxy(false /* aInsertFilters */);13220 HRESULT rc = mUSBDeviceFilters->notifyProxy(false /* aInsertFilters */); 13148 13221 AssertComRC(rc); 13149 13222 NOREF(rc); … … 14121 14194 * elsewhere... */ 14122 14195 alock.release(); 14123 return mUSB Controller->hasMatchingFilter(aDevice, aMaskedIfs);14196 return mUSBDeviceFilters->hasMatchingFilter(aDevice, aMaskedIfs); 14124 14197 default: break; 14125 14198 } -
trunk/src/VBox/Main/src-server/SnapshotImpl.cpp
r46720 r47376 30 30 #include "SharedFolderImpl.h" 31 31 #include "USBControllerImpl.h" 32 #include "USBDeviceFiltersImpl.h" 32 33 #include "VirtualBoxImpl.h" 33 34 … … 1079 1080 unconst(mUSBController).createObject(); 1080 1081 mUSBController->initCopy(this, pMachine->mUSBController); 1082 1083 unconst(mUSBDeviceFilters).createObject(); 1084 mUSBDeviceFilters->initCopy(this, pMachine->mUSBDeviceFilters); 1081 1085 1082 1086 mNetworkAdapters.resize(pMachine->mNetworkAdapters.size()); … … 1178 1182 unconst(mUSBController).createObject(); 1179 1183 mUSBController->init(this); 1184 1185 unconst(mUSBDeviceFilters).createObject(); 1186 mUSBDeviceFilters->init(this); 1180 1187 1181 1188 mNetworkAdapters.resize(Global::getMaxNetworkAdapters(mHWData->mChipsetType)); -
trunk/src/VBox/Main/src-server/USBControllerImpl.cpp
r46820 r47376 22 22 #include "VirtualBoxImpl.h" 23 23 #include "HostImpl.h" 24 #ifdef VBOX_WITH_USB25 # include "USBDeviceImpl.h"26 # include "HostUSBDeviceImpl.h"27 # include "USBProxyService.h"28 # include "USBDeviceFilterImpl.h"29 #endif30 24 31 25 #include <iprt/string.h> … … 44 38 // defines 45 39 ///////////////////////////////////////////////////////////////////////////// 46 47 typedef std::list< ComObjPtr<USBDeviceFilter> > DeviceFilterList;48 40 49 41 struct BackupableUSBData … … 61 53 { 62 54 Data(Machine *pMachine) 63 : pParent(pMachine), 64 pHost(pMachine->getVirtualBox()->host()) 55 : pParent(pMachine) 65 56 { } 66 57 … … 69 60 70 61 Machine * const pParent; 71 Host * const pHost;72 62 73 63 // peer machine's USB controller … … 75 65 76 66 Backupable<BackupableUSBData> bd; 77 #ifdef VBOX_WITH_USB78 // the following fields need special backup/rollback/commit handling,79 // so they cannot be a part of BackupableData80 Backupable<DeviceFilterList> llDeviceFilters;81 #endif82 67 }; 83 68 … … 124 109 125 110 m->bd.allocate(); 126 #ifdef VBOX_WITH_USB127 m->llDeviceFilters.allocate();128 #endif129 111 130 112 /* Confirm a successful initialization */ … … 163 145 m->bd.share(aPeer->m->bd); 164 146 165 #ifdef VBOX_WITH_USB166 /* create copies of all filters */167 m->llDeviceFilters.allocate();168 DeviceFilterList::const_iterator it = aPeer->m->llDeviceFilters->begin();169 while (it != aPeer->m->llDeviceFilters->end())170 {171 ComObjPtr<USBDeviceFilter> filter;172 filter.createObject();173 filter->init(this, *it);174 m->llDeviceFilters->push_back(filter);175 ++it;176 }177 #endif /* VBOX_WITH_USB */178 179 147 /* Confirm a successful initialization */ 180 148 autoInitSpan.setSucceeded(); … … 205 173 AutoWriteLock thatlock(aPeer COMMA_LOCKVAL_SRC_POS); 206 174 m->bd.attachCopy(aPeer->m->bd); 207 208 #ifdef VBOX_WITH_USB209 /* create private copies of all filters */210 m->llDeviceFilters.allocate();211 DeviceFilterList::const_iterator it = aPeer->m->llDeviceFilters->begin();212 while (it != aPeer->m->llDeviceFilters->end())213 {214 ComObjPtr<USBDeviceFilter> filter;215 filter.createObject();216 filter->initCopy(this, *it);217 m->llDeviceFilters->push_back(filter);218 ++it;219 }220 #endif /* VBOX_WITH_USB */221 175 222 176 /* Confirm a successful initialization */ … … 240 194 return; 241 195 242 #ifdef VBOX_WITH_USB243 // uninit all device filters on the list (it's a standard std::list not an ObjectsList244 // so we must uninit() manually)245 for (DeviceFilterList::iterator it = m->llDeviceFilters->begin();246 it != m->llDeviceFilters->end();247 ++it)248 (*it)->uninit();249 250 m->llDeviceFilters.free();251 #endif252 196 m->bd.free(); 253 197 … … 385 329 386 330 return S_OK; 387 }388 389 #ifndef VBOX_WITH_USB390 /**391 * Fake class for build without USB.392 * We need an empty collection & enum for deviceFilters, that's all.393 */394 class ATL_NO_VTABLE USBDeviceFilter :395 public VirtualBoxBase,396 VBOX_SCRIPTABLE_IMPL(IUSBDeviceFilter)397 {398 public:399 DECLARE_NOT_AGGREGATABLE(USBDeviceFilter)400 DECLARE_PROTECT_FINAL_CONSTRUCT()401 BEGIN_COM_MAP(USBDeviceFilter)402 VBOX_DEFAULT_INTERFACE_ENTRIES(IUSBDeviceFilter)403 END_COM_MAP()404 405 DECLARE_EMPTY_CTOR_DTOR(USBDeviceFilter)406 407 // IUSBDeviceFilter properties408 STDMETHOD(COMGETTER(Name))(BSTR *aName);409 STDMETHOD(COMSETTER(Name))(IN_BSTR aName);410 STDMETHOD(COMGETTER(Active))(BOOL *aActive);411 STDMETHOD(COMSETTER(Active))(BOOL aActive);412 STDMETHOD(COMGETTER(VendorId))(BSTR *aVendorId);413 STDMETHOD(COMSETTER(VendorId))(IN_BSTR aVendorId);414 STDMETHOD(COMGETTER(ProductId))(BSTR *aProductId);415 STDMETHOD(COMSETTER(ProductId))(IN_BSTR aProductId);416 STDMETHOD(COMGETTER(Revision))(BSTR *aRevision);417 STDMETHOD(COMSETTER(Revision))(IN_BSTR aRevision);418 STDMETHOD(COMGETTER(Manufacturer))(BSTR *aManufacturer);419 STDMETHOD(COMSETTER(Manufacturer))(IN_BSTR aManufacturer);420 STDMETHOD(COMGETTER(Product))(BSTR *aProduct);421 STDMETHOD(COMSETTER(Product))(IN_BSTR aProduct);422 STDMETHOD(COMGETTER(SerialNumber))(BSTR *aSerialNumber);423 STDMETHOD(COMSETTER(SerialNumber))(IN_BSTR aSerialNumber);424 STDMETHOD(COMGETTER(Port))(BSTR *aPort);425 STDMETHOD(COMSETTER(Port))(IN_BSTR aPort);426 STDMETHOD(COMGETTER(Remote))(BSTR *aRemote);427 STDMETHOD(COMSETTER(Remote))(IN_BSTR aRemote);428 STDMETHOD(COMGETTER(MaskedInterfaces))(ULONG *aMaskedIfs);429 STDMETHOD(COMSETTER(MaskedInterfaces))(ULONG aMaskedIfs);430 };431 #endif /* !VBOX_WITH_USB */432 433 434 STDMETHODIMP USBController::COMGETTER(DeviceFilters)(ComSafeArrayOut(IUSBDeviceFilter *, aDevicesFilters))435 {436 #ifdef VBOX_WITH_USB437 CheckComArgOutSafeArrayPointerValid(aDevicesFilters);438 439 AutoCaller autoCaller(this);440 if (FAILED(autoCaller.rc())) return autoCaller.rc();441 442 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);443 444 SafeIfaceArray<IUSBDeviceFilter> collection(*m->llDeviceFilters.data());445 collection.detachTo(ComSafeArrayOutArg(aDevicesFilters));446 447 return S_OK;448 #else449 NOREF(aDevicesFilters);450 # ifndef RT_OS_WINDOWS451 NOREF(aDevicesFiltersSize);452 # endif453 ReturnComNotImplemented();454 #endif455 }456 457 // IUSBController methods458 /////////////////////////////////////////////////////////////////////////////459 460 STDMETHODIMP USBController::CreateDeviceFilter(IN_BSTR aName,461 IUSBDeviceFilter **aFilter)462 {463 #ifdef VBOX_WITH_USB464 CheckComArgOutPointerValid(aFilter);465 466 CheckComArgStrNotEmptyOrNull(aName);467 468 AutoCaller autoCaller(this);469 if (FAILED(autoCaller.rc())) return autoCaller.rc();470 471 /* the machine needs to be mutable */472 AutoMutableStateDependency adep(m->pParent);473 if (FAILED(adep.rc())) return adep.rc();474 475 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);476 477 ComObjPtr<USBDeviceFilter> filter;478 filter.createObject();479 HRESULT rc = filter->init(this, aName);480 ComAssertComRCRetRC(rc);481 rc = filter.queryInterfaceTo(aFilter);482 AssertComRCReturnRC(rc);483 484 return S_OK;485 #else486 NOREF(aName);487 NOREF(aFilter);488 ReturnComNotImplemented();489 #endif490 }491 492 STDMETHODIMP USBController::InsertDeviceFilter(ULONG aPosition,493 IUSBDeviceFilter *aFilter)494 {495 #ifdef VBOX_WITH_USB496 497 CheckComArgNotNull(aFilter);498 499 AutoCaller autoCaller(this);500 if (FAILED(autoCaller.rc())) return autoCaller.rc();501 502 /* the machine needs to be mutable */503 AutoMutableStateDependency adep(m->pParent);504 if (FAILED(adep.rc())) return adep.rc();505 506 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);507 508 ComObjPtr<USBDeviceFilter> filter = static_cast<USBDeviceFilter*>(aFilter);509 // @todo r=dj make sure the input object is actually from us510 // if (!filter)511 // return setError(E_INVALIDARG,512 // tr("The given USB device filter is not created within "513 // "this VirtualBox instance"));514 515 if (filter->mInList)516 return setError(VBOX_E_INVALID_OBJECT_STATE,517 tr("The given USB device filter is already in the list"));518 519 /* backup the list before modification */520 m->llDeviceFilters.backup();521 522 /* iterate to the position... */523 DeviceFilterList::iterator it;524 if (aPosition < m->llDeviceFilters->size())525 {526 it = m->llDeviceFilters->begin();527 std::advance(it, aPosition);528 }529 else530 it = m->llDeviceFilters->end();531 /* ...and insert */532 m->llDeviceFilters->insert(it, filter);533 filter->mInList = true;534 535 /* notify the proxy (only when it makes sense) */536 if (filter->getData().mActive && Global::IsOnline(adep.machineState())537 && filter->getData().mRemote.isMatch(false))538 {539 USBProxyService *service = m->pHost->usbProxyService();540 ComAssertRet(service, E_FAIL);541 542 ComAssertRet(filter->getId() == NULL, E_FAIL);543 filter->getId() = service->insertFilter(&filter->getData().mUSBFilter);544 }545 546 alock.release();547 AutoWriteLock mlock(m->pParent COMMA_LOCKVAL_SRC_POS);548 m->pParent->setModified(Machine::IsModified_USB);549 mlock.release();550 551 return S_OK;552 553 #else /* VBOX_WITH_USB */554 555 NOREF(aPosition);556 NOREF(aFilter);557 ReturnComNotImplemented();558 559 #endif /* VBOX_WITH_USB */560 }561 562 STDMETHODIMP USBController::RemoveDeviceFilter(ULONG aPosition,563 IUSBDeviceFilter **aFilter)564 {565 #ifdef VBOX_WITH_USB566 567 CheckComArgOutPointerValid(aFilter);568 569 AutoCaller autoCaller(this);570 if (FAILED(autoCaller.rc())) return autoCaller.rc();571 572 /* the machine needs to be mutable */573 AutoMutableStateDependency adep(m->pParent);574 if (FAILED(adep.rc())) return adep.rc();575 576 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);577 578 if (!m->llDeviceFilters->size())579 return setError(E_INVALIDARG,580 tr("The USB device filter list is empty"));581 582 if (aPosition >= m->llDeviceFilters->size())583 return setError(E_INVALIDARG,584 tr("Invalid position: %lu (must be in range [0, %lu])"),585 aPosition, m->llDeviceFilters->size() - 1);586 587 /* backup the list before modification */588 m->llDeviceFilters.backup();589 590 ComObjPtr<USBDeviceFilter> filter;591 {592 /* iterate to the position... */593 DeviceFilterList::iterator it = m->llDeviceFilters->begin();594 std::advance(it, aPosition);595 /* ...get an element from there... */596 filter = *it;597 /* ...and remove */598 filter->mInList = false;599 m->llDeviceFilters->erase(it);600 }601 602 /* cancel sharing (make an independent copy of data) */603 filter->unshare();604 605 filter.queryInterfaceTo(aFilter);606 607 /* notify the proxy (only when it makes sense) */608 if (filter->getData().mActive && Global::IsOnline(adep.machineState())609 && filter->getData().mRemote.isMatch(false))610 {611 USBProxyService *service = m->pHost->usbProxyService();612 ComAssertRet(service, E_FAIL);613 614 ComAssertRet(filter->getId() != NULL, E_FAIL);615 service->removeFilter(filter->getId());616 filter->getId() = NULL;617 }618 619 alock.release();620 AutoWriteLock mlock(m->pParent COMMA_LOCKVAL_SRC_POS);621 m->pParent->setModified(Machine::IsModified_USB);622 mlock.release();623 624 return S_OK;625 626 #else /* VBOX_WITH_USB */627 628 NOREF(aPosition);629 NOREF(aFilter);630 ReturnComNotImplemented();631 632 #endif /* VBOX_WITH_USB */633 331 } 634 332 … … 663 361 m->bd->fEnabledEHCI = data.fEnabledEHCI; 664 362 665 #ifdef VBOX_WITH_USB666 for (settings::USBDeviceFiltersList::const_iterator it = data.llDeviceFilters.begin();667 it != data.llDeviceFilters.end();668 ++it)669 {670 const settings::USBDeviceFilter &f = *it;671 ComObjPtr<USBDeviceFilter> pFilter;672 pFilter.createObject();673 HRESULT rc = pFilter->init(this, // parent674 f);675 if (FAILED(rc)) return rc;676 677 m->llDeviceFilters->push_back(pFilter);678 pFilter->mInList = true;679 }680 #endif /* VBOX_WITH_USB */681 682 363 return S_OK; 683 364 } … … 699 380 data.fEnabled = !!m->bd->fEnabled; 700 381 data.fEnabledEHCI = !!m->bd->fEnabledEHCI; 701 702 #ifdef VBOX_WITH_USB703 data.llDeviceFilters.clear();704 705 for (DeviceFilterList::const_iterator it = m->llDeviceFilters->begin();706 it != m->llDeviceFilters->end();707 ++it)708 {709 AutoWriteLock filterLock(*it COMMA_LOCKVAL_SRC_POS);710 const USBDeviceFilter::Data &filterData = (*it)->getData();711 712 Bstr str;713 714 settings::USBDeviceFilter f;715 f.strName = filterData.mName;716 f.fActive = !!filterData.mActive;717 (*it)->COMGETTER(VendorId)(str.asOutParam());718 f.strVendorId = str;719 (*it)->COMGETTER(ProductId)(str.asOutParam());720 f.strProductId = str;721 (*it)->COMGETTER(Revision)(str.asOutParam());722 f.strRevision = str;723 (*it)->COMGETTER(Manufacturer)(str.asOutParam());724 f.strManufacturer = str;725 (*it)->COMGETTER(Product)(str.asOutParam());726 f.strProduct = str;727 (*it)->COMGETTER(SerialNumber)(str.asOutParam());728 f.strSerialNumber = str;729 (*it)->COMGETTER(Port)(str.asOutParam());730 f.strPort = str;731 f.strRemote = filterData.mRemote.string();732 f.ulMaskedInterfaces = filterData.mMaskedIfs;733 734 data.llDeviceFilters.push_back(f);735 }736 #endif /* VBOX_WITH_USB */737 382 738 383 return S_OK; … … 752 397 753 398 m->bd.rollback(); 754 755 #ifdef VBOX_WITH_USB756 757 if (m->llDeviceFilters.isBackedUp())758 {759 USBProxyService *service = m->pHost->usbProxyService();760 Assert(service);761 762 /* uninitialize all new filters (absent in the backed up list) */763 DeviceFilterList::const_iterator it = m->llDeviceFilters->begin();764 DeviceFilterList *backedList = m->llDeviceFilters.backedUpData();765 while (it != m->llDeviceFilters->end())766 {767 if (std::find(backedList->begin(), backedList->end(), *it) ==768 backedList->end())769 {770 /* notify the proxy (only when it makes sense) */771 if ((*it)->getData().mActive &&772 Global::IsOnline(adep.machineState())773 && (*it)->getData().mRemote.isMatch(false))774 {775 USBDeviceFilter *filter = *it;776 Assert(filter->getId() != NULL);777 service->removeFilter(filter->getId());778 filter->getId() = NULL;779 }780 781 (*it)->uninit();782 }783 ++it;784 }785 786 if (Global::IsOnline(adep.machineState()))787 {788 /* find all removed old filters (absent in the new list)789 * and insert them back to the USB proxy */790 it = backedList->begin();791 while (it != backedList->end())792 {793 if (std::find(m->llDeviceFilters->begin(), m->llDeviceFilters->end(), *it) ==794 m->llDeviceFilters->end())795 {796 /* notify the proxy (only when necessary) */797 if ((*it)->getData().mActive798 && (*it)->getData().mRemote.isMatch(false))799 {800 USBDeviceFilter *flt = *it; /* resolve ambiguity */801 Assert(flt->getId() == NULL);802 flt->getId() = service->insertFilter(&flt->getData().mUSBFilter);803 }804 }805 ++it;806 }807 }808 809 /* restore the list */810 m->llDeviceFilters.rollback();811 }812 813 /* here we don't depend on the machine state any more */814 adep.release();815 816 /* rollback any changes to filters after restoring the list */817 DeviceFilterList::const_iterator it = m->llDeviceFilters->begin();818 while (it != m->llDeviceFilters->end())819 {820 if ((*it)->isModified())821 {822 (*it)->rollback();823 /* call this to notify the USB proxy about changes */824 onDeviceFilterChange(*it);825 }826 ++it;827 }828 829 #endif /* VBOX_WITH_USB */830 399 } 831 400 … … 858 427 } 859 428 } 860 861 #ifdef VBOX_WITH_USB862 bool commitFilters = false;863 864 if (m->llDeviceFilters.isBackedUp())865 {866 m->llDeviceFilters.commit();867 868 /* apply changes to peer */869 if (m->pPeer)870 {871 AutoWriteLock peerlock(m->pPeer COMMA_LOCKVAL_SRC_POS);872 873 /* commit all changes to new filters (this will reshare data with874 * peers for those who have peers) */875 DeviceFilterList *newList = new DeviceFilterList();876 DeviceFilterList::const_iterator it = m->llDeviceFilters->begin();877 while (it != m->llDeviceFilters->end())878 {879 (*it)->commit();880 881 /* look if this filter has a peer filter */882 ComObjPtr<USBDeviceFilter> peer = (*it)->peer();883 if (!peer)884 {885 /* no peer means the filter is a newly created one;886 * create a peer owning data this filter share it with */887 peer.createObject();888 peer->init(m->pPeer, *it, true /* aReshare */);889 }890 else891 {892 /* remove peer from the old list */893 m->pPeer->m->llDeviceFilters->remove(peer);894 }895 /* and add it to the new list */896 newList->push_back(peer);897 898 ++it;899 }900 901 /* uninit old peer's filters that are left */902 it = m->pPeer->m->llDeviceFilters->begin();903 while (it != m->pPeer->m->llDeviceFilters->end())904 {905 (*it)->uninit();906 ++it;907 }908 909 /* attach new list of filters to our peer */910 m->pPeer->m->llDeviceFilters.attach(newList);911 }912 else913 {914 /* we have no peer (our parent is the newly created machine);915 * just commit changes to filters */916 commitFilters = true;917 }918 }919 else920 {921 /* the list of filters itself is not changed,922 * just commit changes to filters themselves */923 commitFilters = true;924 }925 926 if (commitFilters)927 {928 DeviceFilterList::const_iterator it = m->llDeviceFilters->begin();929 while (it != m->llDeviceFilters->end())930 {931 (*it)->commit();932 ++it;933 }934 }935 #endif /* VBOX_WITH_USB */936 429 } 937 430 … … 965 458 /* this will back up current data */ 966 459 m->bd.assignCopy(aThat->m->bd); 967 968 #ifdef VBOX_WITH_USB 969 970 /* Note that we won't inform the USB proxy about new filters since the VM is 971 * not running when we are here and therefore no need to do so */ 972 973 /* create private copies of all filters */ 974 m->llDeviceFilters.backup(); 975 m->llDeviceFilters->clear(); 976 for (DeviceFilterList::const_iterator it = aThat->m->llDeviceFilters->begin(); 977 it != aThat->m->llDeviceFilters->end(); 978 ++it) 979 { 980 ComObjPtr<USBDeviceFilter> filter; 981 filter.createObject(); 982 filter->initCopy(this, *it); 983 m->llDeviceFilters->push_back(filter); 984 } 985 986 #endif /* VBOX_WITH_USB */ 987 } 988 989 #ifdef VBOX_WITH_USB 990 991 /** 992 * Called by setter methods of all USB device filters. 993 * 994 * @note Locks nothing. 995 */ 996 HRESULT USBController::onDeviceFilterChange(USBDeviceFilter *aFilter, 997 BOOL aActiveChanged /* = FALSE */) 998 { 999 AutoCaller autoCaller(this); 1000 AssertComRCReturnRC(autoCaller.rc()); 1001 1002 /* we need the machine state */ 1003 AutoAnyStateDependency adep(m->pParent); 1004 AssertComRCReturnRC(adep.rc()); 1005 1006 /* nothing to do if the machine isn't running */ 1007 if (!Global::IsOnline(adep.machineState())) 1008 return S_OK; 1009 1010 /* we don't modify our data fields -- no need to lock */ 1011 1012 if ( aFilter->mInList 1013 && m->pParent->isRegistered()) 1014 { 1015 USBProxyService *service = m->pHost->usbProxyService(); 1016 ComAssertRet(service, E_FAIL); 1017 1018 if (aActiveChanged) 1019 { 1020 if (aFilter->getData().mRemote.isMatch(false)) 1021 { 1022 /* insert/remove the filter from the proxy */ 1023 if (aFilter->getData().mActive) 1024 { 1025 ComAssertRet(aFilter->getId() == NULL, E_FAIL); 1026 aFilter->getId() = service->insertFilter(&aFilter->getData().mUSBFilter); 1027 } 1028 else 1029 { 1030 ComAssertRet(aFilter->getId() != NULL, E_FAIL); 1031 service->removeFilter(aFilter->getId()); 1032 aFilter->getId() = NULL; 1033 } 1034 } 1035 } 1036 else 1037 { 1038 if (aFilter->getData().mActive) 1039 { 1040 /* update the filter in the proxy */ 1041 ComAssertRet(aFilter->getId() != NULL, E_FAIL); 1042 service->removeFilter(aFilter->getId()); 1043 if (aFilter->getData().mRemote.isMatch(false)) 1044 { 1045 aFilter->getId() = service->insertFilter(&aFilter->getData().mUSBFilter); 1046 } 1047 } 1048 } 1049 } 1050 1051 return S_OK; 1052 } 1053 1054 /** 1055 * Returns true if the given USB device matches to at least one of 1056 * this controller's USB device filters. 1057 * 1058 * A HostUSBDevice specific version. 1059 * 1060 * @note Locks this object for reading. 1061 */ 1062 bool USBController::hasMatchingFilter(const ComObjPtr<HostUSBDevice> &aDevice, ULONG *aMaskedIfs) 1063 { 1064 AutoCaller autoCaller(this); 1065 AssertComRCReturn(autoCaller.rc(), false); 1066 1067 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS); 1068 1069 /* Disabled USB controllers cannot actually work with USB devices */ 1070 if (!m->bd->fEnabled) 1071 return false; 1072 1073 /* apply self filters */ 1074 for (DeviceFilterList::const_iterator it = m->llDeviceFilters->begin(); 1075 it != m->llDeviceFilters->end(); 1076 ++it) 1077 { 1078 AutoWriteLock filterLock(*it COMMA_LOCKVAL_SRC_POS); 1079 if (aDevice->isMatch((*it)->getData())) 1080 { 1081 *aMaskedIfs = (*it)->getData().mMaskedIfs; 1082 return true; 1083 } 1084 } 1085 1086 return false; 1087 } 1088 1089 /** 1090 * Returns true if the given USB device matches to at least one of 1091 * this controller's USB device filters. 1092 * 1093 * A generic version that accepts any IUSBDevice on input. 1094 * 1095 * @note 1096 * This method MUST correlate with HostUSBDevice::isMatch() 1097 * in the sense of the device matching logic. 1098 * 1099 * @note Locks this object for reading. 1100 */ 1101 bool USBController::hasMatchingFilter(IUSBDevice *aUSBDevice, ULONG *aMaskedIfs) 1102 { 1103 LogFlowThisFuncEnter(); 1104 1105 AutoCaller autoCaller(this); 1106 AssertComRCReturn(autoCaller.rc(), false); 1107 1108 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS); 1109 1110 /* Disabled USB controllers cannot actually work with USB devices */ 1111 if (!m->bd->fEnabled) 1112 return false; 1113 1114 HRESULT rc = S_OK; 1115 1116 /* query fields */ 1117 USBFILTER dev; 1118 USBFilterInit(&dev, USBFILTERTYPE_CAPTURE); 1119 1120 USHORT vendorId = 0; 1121 rc = aUSBDevice->COMGETTER(VendorId)(&vendorId); 1122 ComAssertComRCRet(rc, false); 1123 ComAssertRet(vendorId, false); 1124 int vrc = USBFilterSetNumExact(&dev, USBFILTERIDX_VENDOR_ID, vendorId, true); AssertRC(vrc); 1125 1126 USHORT productId = 0; 1127 rc = aUSBDevice->COMGETTER(ProductId)(&productId); 1128 ComAssertComRCRet(rc, false); 1129 vrc = USBFilterSetNumExact(&dev, USBFILTERIDX_PRODUCT_ID, productId, true); AssertRC(vrc); 1130 1131 USHORT revision; 1132 rc = aUSBDevice->COMGETTER(Revision)(&revision); 1133 ComAssertComRCRet(rc, false); 1134 vrc = USBFilterSetNumExact(&dev, USBFILTERIDX_DEVICE, revision, true); AssertRC(vrc); 1135 1136 Bstr manufacturer; 1137 rc = aUSBDevice->COMGETTER(Manufacturer)(manufacturer.asOutParam()); 1138 ComAssertComRCRet(rc, false); 1139 if (!manufacturer.isEmpty()) 1140 USBFilterSetStringExact(&dev, USBFILTERIDX_MANUFACTURER_STR, Utf8Str(manufacturer).c_str(), true); 1141 1142 Bstr product; 1143 rc = aUSBDevice->COMGETTER(Product)(product.asOutParam()); 1144 ComAssertComRCRet(rc, false); 1145 if (!product.isEmpty()) 1146 USBFilterSetStringExact(&dev, USBFILTERIDX_PRODUCT_STR, Utf8Str(product).c_str(), true); 1147 1148 Bstr serialNumber; 1149 rc = aUSBDevice->COMGETTER(SerialNumber)(serialNumber.asOutParam()); 1150 ComAssertComRCRet(rc, false); 1151 if (!serialNumber.isEmpty()) 1152 USBFilterSetStringExact(&dev, USBFILTERIDX_SERIAL_NUMBER_STR, Utf8Str(serialNumber).c_str(), true); 1153 1154 Bstr address; 1155 rc = aUSBDevice->COMGETTER(Address)(address.asOutParam()); 1156 ComAssertComRCRet(rc, false); 1157 1158 USHORT port = 0; 1159 rc = aUSBDevice->COMGETTER(Port)(&port); 1160 ComAssertComRCRet(rc, false); 1161 USBFilterSetNumExact(&dev, USBFILTERIDX_PORT, port, true); 1162 1163 BOOL remote = FALSE; 1164 rc = aUSBDevice->COMGETTER(Remote)(&remote); 1165 ComAssertComRCRet(rc, false); 1166 ComAssertRet(remote == TRUE, false); 1167 1168 bool match = false; 1169 1170 /* apply self filters */ 1171 for (DeviceFilterList::const_iterator it = m->llDeviceFilters->begin(); 1172 it != m->llDeviceFilters->end(); 1173 ++it) 1174 { 1175 AutoWriteLock filterLock(*it COMMA_LOCKVAL_SRC_POS); 1176 const USBDeviceFilter::Data &aData = (*it)->getData(); 1177 1178 if (!aData.mActive) 1179 continue; 1180 if (!aData.mRemote.isMatch(remote)) 1181 continue; 1182 if (!USBFilterMatch(&aData.mUSBFilter, &dev)) 1183 continue; 1184 1185 match = true; 1186 *aMaskedIfs = aData.mMaskedIfs; 1187 break; 1188 } 1189 1190 LogFlowThisFunc(("returns: %d\n", match)); 1191 LogFlowThisFuncLeave(); 1192 1193 return match; 1194 } 1195 1196 /** 1197 * Notifies the proxy service about all filters as requested by the 1198 * @a aInsertFilters argument. 1199 * 1200 * @param aInsertFilters @c true to insert filters, @c false to remove. 1201 * 1202 * @note Locks this object for reading. 1203 */ 1204 HRESULT USBController::notifyProxy(bool aInsertFilters) 1205 { 1206 LogFlowThisFunc(("aInsertFilters=%RTbool\n", aInsertFilters)); 1207 1208 AutoCaller autoCaller(this); 1209 AssertComRCReturn(autoCaller.rc(), false); 1210 1211 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS); 1212 1213 USBProxyService *service = m->pHost->usbProxyService(); 1214 AssertReturn(service, E_FAIL); 1215 1216 DeviceFilterList::const_iterator it = m->llDeviceFilters->begin(); 1217 while (it != m->llDeviceFilters->end()) 1218 { 1219 USBDeviceFilter *flt = *it; /* resolve ambiguity (for ComPtr below) */ 1220 1221 /* notify the proxy (only if the filter is active) */ 1222 if ( flt->getData().mActive 1223 && flt->getData().mRemote.isMatch(false) /* and if the filter is NOT remote */ 1224 ) 1225 { 1226 if (aInsertFilters) 1227 { 1228 AssertReturn(flt->getId() == NULL, E_FAIL); 1229 flt->getId() = service->insertFilter(&flt->getData().mUSBFilter); 1230 } 1231 else 1232 { 1233 /* It's possible that the given filter was not inserted the proxy 1234 * when this method gets called (as a result of an early VM 1235 * process crash for example. So, don't assert that ID != NULL. */ 1236 if (flt->getId() != NULL) 1237 { 1238 service->removeFilter(flt->getId()); 1239 flt->getId() = NULL; 1240 } 1241 } 1242 } 1243 ++it; 1244 } 1245 1246 return S_OK; 1247 } 1248 1249 Machine* USBController::getMachine() 1250 { 1251 return m->pParent; 1252 } 1253 1254 #endif /* VBOX_WITH_USB */ 460 } 1255 461 1256 462 // private methods -
trunk/src/VBox/Main/src-server/USBDeviceFilterImpl.cpp
r44528 r47376 17 17 18 18 #include "USBDeviceFilterImpl.h" 19 #include "USB ControllerImpl.h"19 #include "USBDeviceFiltersImpl.h" 20 20 #include "MachineImpl.h" 21 21 #include "HostImpl.h" … … 204 204 * @param aParent Handle of the parent object. 205 205 */ 206 HRESULT USBDeviceFilter::init(USB Controller*aParent,206 HRESULT USBDeviceFilter::init(USBDeviceFilters *aParent, 207 207 const settings::USBDeviceFilter &data) 208 208 { … … 278 278 * @param aParent Handle of the parent object. 279 279 */ 280 HRESULT USBDeviceFilter::init(USB Controller*aParent, IN_BSTR aName)280 HRESULT USBDeviceFilter::init(USBDeviceFilters *aParent, IN_BSTR aName) 281 281 { 282 282 LogFlowThisFunc(("aParent=%p\n", aParent)); … … 327 327 * reading if @a aReshare is false. 328 328 */ 329 HRESULT USBDeviceFilter::init (USB Controller*aParent, USBDeviceFilter *aThat,329 HRESULT USBDeviceFilter::init (USBDeviceFilters *aParent, USBDeviceFilter *aThat, 330 330 bool aReshare /* = false */) 331 331 { … … 380 380 * @note Locks @a aThat object for reading. 381 381 */ 382 HRESULT USBDeviceFilter::initCopy (USB Controller*aParent, USBDeviceFilter *aThat)382 HRESULT USBDeviceFilter::initCopy (USBDeviceFilters *aParent, USBDeviceFilter *aThat) 383 383 { 384 384 LogFlowThisFunc(("aParent=%p, aThat=%p\n", aParent, aThat)); -
trunk/src/VBox/Main/src-server/USBDeviceFiltersImpl.cpp
r47360 r47376 16 16 */ 17 17 18 #include "USB ControllerImpl.h"18 #include "USBDeviceFiltersImpl.h" 19 19 20 20 #include "Global.h" … … 47 47 typedef std::list< ComObjPtr<USBDeviceFilter> > DeviceFilterList; 48 48 49 struct BackupableUSBData 50 { 51 BackupableUSBData() 52 : fEnabled(false), 53 fEnabledEHCI(false) 54 { } 55 56 BOOL fEnabled; 57 BOOL fEnabledEHCI; 58 }; 59 60 struct USBController::Data 49 struct USBDeviceFilters::Data 61 50 { 62 51 Data(Machine *pMachine) … … 71 60 Host * const pHost; 72 61 73 // peer machine's USB controller 74 const ComObjPtr<USBController> pPeer; 75 76 Backupable<BackupableUSBData> bd; 77 #ifdef VBOX_WITH_USB 78 // the following fields need special backup/rollback/commit handling, 79 // so they cannot be a part of BackupableData 62 // peer machine's USB device filters list 63 const ComObjPtr<USBDeviceFilters> pPeer; 64 65 #ifdef VBOX_WITH_USB 66 // List of device filters. 80 67 Backupable<DeviceFilterList> llDeviceFilters; 81 68 #endif … … 87 74 ///////////////////////////////////////////////////////////////////////////// 88 75 89 DEFINE_EMPTY_CTOR_DTOR(USB Controller)90 91 HRESULT USB Controller::FinalConstruct()76 DEFINE_EMPTY_CTOR_DTOR(USBDeviceFilters) 77 78 HRESULT USBDeviceFilters::FinalConstruct() 92 79 { 93 80 return BaseFinalConstruct(); 94 81 } 95 82 96 void USB Controller::FinalRelease()83 void USBDeviceFilters::FinalRelease() 97 84 { 98 85 uninit(); … … 109 96 * @param aParent Pointer to our parent object. 110 97 */ 111 HRESULT USB Controller::init(Machine *aParent)98 HRESULT USBDeviceFilters::init(Machine *aParent) 112 99 { 113 100 LogFlowThisFunc(("aParent=%p\n", aParent)); … … 122 109 123 110 /* mPeer is left null */ 124 125 m->bd.allocate();126 111 #ifdef VBOX_WITH_USB 127 112 m->llDeviceFilters.allocate(); … … 135 120 136 121 /** 137 * Initializes the USB controller object given another USB controllerobject122 * Initializes the USB devic filters object given another USB filters object 138 123 * (a kind of copy constructor). This object shares data with 139 124 * the object passed as an argument. … … 146 131 * it shares data with is destroyed. 147 132 */ 148 HRESULT USB Controller::init(Machine *aParent, USBController*aPeer)133 HRESULT USBDeviceFilters::init(Machine *aParent, USBDeviceFilters *aPeer) 149 134 { 150 135 LogFlowThisFunc(("aParent=%p, aPeer=%p\n", aParent, aPeer)); … … 161 146 162 147 AutoWriteLock thatlock(aPeer COMMA_LOCKVAL_SRC_POS); 163 m->bd.share(aPeer->m->bd);164 148 165 149 #ifdef VBOX_WITH_USB … … 169 153 while (it != aPeer->m->llDeviceFilters->end()) 170 154 { 171 ComObjPtr<USBDeviceFilter> filter;172 filter.createObject();173 filter->init(this, *it);174 m->llDeviceFilters->push_back( filter);155 ComObjPtr<USBDeviceFilter> pFilter; 156 pFilter.createObject(); 157 pFilter->init(this, *it); 158 m->llDeviceFilters->push_back(pFilter); 175 159 ++it; 176 160 } … … 189 173 * of the original object passed as an argument. 190 174 */ 191 HRESULT USB Controller::initCopy(Machine *aParent, USBController*aPeer)175 HRESULT USBDeviceFilters::initCopy(Machine *aParent, USBDeviceFilters *aPeer) 192 176 { 193 177 LogFlowThisFunc(("aParent=%p, aPeer=%p\n", aParent, aPeer)); … … 204 188 205 189 AutoWriteLock thatlock(aPeer COMMA_LOCKVAL_SRC_POS); 206 m->bd.attachCopy(aPeer->m->bd);207 190 208 191 #ifdef VBOX_WITH_USB … … 212 195 while (it != aPeer->m->llDeviceFilters->end()) 213 196 { 214 ComObjPtr<USBDeviceFilter> filter;215 filter.createObject();216 filter->initCopy(this, *it);217 m->llDeviceFilters->push_back( filter);197 ComObjPtr<USBDeviceFilter> pFilter; 198 pFilter.createObject(); 199 pFilter->initCopy(this, *it); 200 m->llDeviceFilters->push_back(pFilter); 218 201 ++it; 219 202 } … … 231 214 * Called either from FinalRelease() or by the parent when it gets destroyed. 232 215 */ 233 void USB Controller::uninit()216 void USBDeviceFilters::uninit() 234 217 { 235 218 LogFlowThisFunc(("\n")); … … 250 233 m->llDeviceFilters.free(); 251 234 #endif 252 m->bd.free();253 235 254 236 unconst(m->pPeer) = NULL; … … 260 242 261 243 262 // IUSB Controllerproperties244 // IUSBDeviceFilters properties 263 245 ///////////////////////////////////////////////////////////////////////////// 264 265 STDMETHODIMP USBController::COMGETTER(Enabled)(BOOL *aEnabled)266 {267 CheckComArgOutPointerValid(aEnabled);268 269 AutoCaller autoCaller(this);270 if (FAILED(autoCaller.rc())) return autoCaller.rc();271 272 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);273 274 *aEnabled = m->bd->fEnabled;275 276 return S_OK;277 }278 279 280 STDMETHODIMP USBController::COMSETTER(Enabled)(BOOL aEnabled)281 {282 LogFlowThisFunc(("aEnabled=%RTbool\n", aEnabled));283 284 AutoCaller autoCaller(this);285 if (FAILED(autoCaller.rc())) return autoCaller.rc();286 287 /* the machine needs to be mutable */288 AutoMutableStateDependency adep(m->pParent);289 if (FAILED(adep.rc())) return adep.rc();290 291 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);292 293 if (m->bd->fEnabled != aEnabled)294 {295 m->bd.backup();296 m->bd->fEnabled = aEnabled;297 298 // leave the lock for safety299 alock.release();300 301 AutoWriteLock mlock(m->pParent COMMA_LOCKVAL_SRC_POS);302 m->pParent->setModified(Machine::IsModified_USB);303 mlock.release();304 305 m->pParent->onUSBControllerChange();306 }307 308 return S_OK;309 }310 311 STDMETHODIMP USBController::COMGETTER(EnabledEHCI)(BOOL *aEnabled)312 {313 CheckComArgOutPointerValid(aEnabled);314 315 AutoCaller autoCaller(this);316 if (FAILED(autoCaller.rc())) return autoCaller.rc();317 318 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);319 320 *aEnabled = m->bd->fEnabledEHCI;321 322 return S_OK;323 }324 325 STDMETHODIMP USBController::COMSETTER(EnabledEHCI)(BOOL aEnabled)326 {327 LogFlowThisFunc(("aEnabled=%RTbool\n", aEnabled));328 329 AutoCaller autoCaller(this);330 if (FAILED(autoCaller.rc())) return autoCaller.rc();331 332 /* the machine needs to be mutable */333 AutoMutableStateDependency adep(m->pParent);334 if (FAILED(adep.rc())) return adep.rc();335 336 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);337 338 if (m->bd->fEnabledEHCI != aEnabled)339 {340 m->bd.backup();341 m->bd->fEnabledEHCI = aEnabled;342 343 // leave the lock for safety344 alock.release();345 346 AutoWriteLock mlock(m->pParent COMMA_LOCKVAL_SRC_POS);347 m->pParent->setModified(Machine::IsModified_USB);348 mlock.release();349 350 m->pParent->onUSBControllerChange();351 }352 353 return S_OK;354 }355 356 STDMETHODIMP USBController::COMGETTER(ProxyAvailable)(BOOL *aEnabled)357 {358 CheckComArgOutPointerValid(aEnabled);359 360 AutoCaller autoCaller(this);361 if (FAILED(autoCaller.rc())) return autoCaller.rc();362 363 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);364 365 #ifdef VBOX_WITH_USB366 *aEnabled = true;367 #else368 *aEnabled = false;369 #endif370 371 return S_OK;372 }373 374 STDMETHODIMP USBController::COMGETTER(USBStandard)(USHORT *aUSBStandard)375 {376 CheckComArgOutPointerValid(aUSBStandard);377 378 AutoCaller autoCaller(this);379 if (FAILED(autoCaller.rc())) return autoCaller.rc();380 381 /* not accessing data -- no need to lock */382 383 /** @todo This is no longer correct */384 *aUSBStandard = 0x0101;385 386 return S_OK;387 }388 246 389 247 #ifndef VBOX_WITH_USB … … 432 290 433 291 434 STDMETHODIMP USB Controller::COMGETTER(DeviceFilters)(ComSafeArrayOut(IUSBDeviceFilter *, aDevicesFilters))292 STDMETHODIMP USBDeviceFilters::COMGETTER(DeviceFilters)(ComSafeArrayOut(IUSBDeviceFilter *, aDevicesFilters)) 435 293 { 436 294 #ifdef VBOX_WITH_USB … … 455 313 } 456 314 457 // IUSB Controllermethods315 // IUSBDeviceFilters methods 458 316 ///////////////////////////////////////////////////////////////////////////// 459 317 460 STDMETHODIMP USB Controller::CreateDeviceFilter(IN_BSTR aName,461 IUSBDeviceFilter **aFilter)318 STDMETHODIMP USBDeviceFilters::CreateDeviceFilter(IN_BSTR aName, 319 IUSBDeviceFilter **aFilter) 462 320 { 463 321 #ifdef VBOX_WITH_USB … … 475 333 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS); 476 334 477 ComObjPtr<USBDeviceFilter> filter;478 filter.createObject();479 HRESULT rc = filter->init(this, aName);335 ComObjPtr<USBDeviceFilter> pFilter; 336 pFilter.createObject(); 337 HRESULT rc = pFilter->init(this, aName); 480 338 ComAssertComRCRetRC(rc); 481 rc = filter.queryInterfaceTo(aFilter);339 rc = pFilter.queryInterfaceTo(aFilter); 482 340 AssertComRCReturnRC(rc); 483 341 … … 490 348 } 491 349 492 STDMETHODIMP USB Controller::InsertDeviceFilter(ULONG aPosition,493 IUSBDeviceFilter *aFilter)350 STDMETHODIMP USBDeviceFilters::InsertDeviceFilter(ULONG aPosition, 351 IUSBDeviceFilter *aFilter) 494 352 { 495 353 #ifdef VBOX_WITH_USB … … 506 364 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS); 507 365 508 ComObjPtr<USBDeviceFilter> filter = static_cast<USBDeviceFilter*>(aFilter); 509 // @todo r=dj make sure the input object is actually from us 510 // if (!filter) 511 // return setError(E_INVALIDARG, 512 // tr("The given USB device filter is not created within " 513 // "this VirtualBox instance")); 514 515 if (filter->mInList) 366 ComObjPtr<USBDeviceFilter> pFilter = static_cast<USBDeviceFilter*>(aFilter); 367 368 if (pFilter->mInList) 516 369 return setError(VBOX_E_INVALID_OBJECT_STATE, 517 tr("The given USB device filter is already in the list"));370 tr("The given USB device pFilter is already in the list")); 518 371 519 372 /* backup the list before modification */ … … 530 383 it = m->llDeviceFilters->end(); 531 384 /* ...and insert */ 532 m->llDeviceFilters->insert(it, filter);533 filter->mInList = true;385 m->llDeviceFilters->insert(it, pFilter); 386 pFilter->mInList = true; 534 387 535 388 /* notify the proxy (only when it makes sense) */ 536 if ( filter->getData().mActive && Global::IsOnline(adep.machineState())537 && filter->getData().mRemote.isMatch(false))538 { 539 USBProxyService * service= m->pHost->usbProxyService();540 ComAssertRet( service, E_FAIL);541 542 ComAssertRet( filter->getId() == NULL, E_FAIL);543 filter->getId() = service->insertFilter(&filter->getData().mUSBFilter);389 if (pFilter->getData().mActive && Global::IsOnline(adep.machineState()) 390 && pFilter->getData().mRemote.isMatch(false)) 391 { 392 USBProxyService *pProxySvc = m->pHost->usbProxyService(); 393 ComAssertRet(pProxySvc, E_FAIL); 394 395 ComAssertRet(pFilter->getId() == NULL, E_FAIL); 396 pFilter->getId() = pProxySvc->insertFilter(&pFilter->getData().mUSBFilter); 544 397 } 545 398 … … 560 413 } 561 414 562 STDMETHODIMP USB Controller::RemoveDeviceFilter(ULONG aPosition,563 IUSBDeviceFilter **aFilter)415 STDMETHODIMP USBDeviceFilters::RemoveDeviceFilter(ULONG aPosition, 416 IUSBDeviceFilter **aFilter) 564 417 { 565 418 #ifdef VBOX_WITH_USB … … 578 431 if (!m->llDeviceFilters->size()) 579 432 return setError(E_INVALIDARG, 580 tr("The USB device filter list is empty"));433 tr("The USB device pFilter list is empty")); 581 434 582 435 if (aPosition >= m->llDeviceFilters->size()) … … 588 441 m->llDeviceFilters.backup(); 589 442 590 ComObjPtr<USBDeviceFilter> filter;443 ComObjPtr<USBDeviceFilter> pFilter; 591 444 { 592 445 /* iterate to the position... */ … … 594 447 std::advance(it, aPosition); 595 448 /* ...get an element from there... */ 596 filter = *it;449 pFilter = *it; 597 450 /* ...and remove */ 598 filter->mInList = false;451 pFilter->mInList = false; 599 452 m->llDeviceFilters->erase(it); 600 453 } 601 454 602 455 /* cancel sharing (make an independent copy of data) */ 603 filter->unshare();604 605 filter.queryInterfaceTo(aFilter);456 pFilter->unshare(); 457 458 pFilter.queryInterfaceTo(aFilter); 606 459 607 460 /* notify the proxy (only when it makes sense) */ 608 if ( filter->getData().mActive && Global::IsOnline(adep.machineState())609 && filter->getData().mRemote.isMatch(false))610 { 611 USBProxyService * service= m->pHost->usbProxyService();612 ComAssertRet( service, E_FAIL);613 614 ComAssertRet( filter->getId() != NULL, E_FAIL);615 service->removeFilter(filter->getId());616 filter->getId() = NULL;461 if (pFilter->getData().mActive && Global::IsOnline(adep.machineState()) 462 && pFilter->getData().mRemote.isMatch(false)) 463 { 464 USBProxyService *pProxySvc = m->pHost->usbProxyService(); 465 ComAssertRet(pProxySvc, E_FAIL); 466 467 ComAssertRet(pFilter->getId() != NULL, E_FAIL); 468 pProxySvc->removeFilter(pFilter->getId()); 469 pFilter->getId() = NULL; 617 470 } 618 471 … … 644 497 * @note Does not lock "this" as Machine::loadHardware, which calls this, does not lock either. 645 498 */ 646 HRESULT USB Controller::loadSettings(const settings::USBController &data)499 HRESULT USBDeviceFilters::loadSettings(const settings::USBController &data) 647 500 { 648 501 AutoCaller autoCaller(this); … … 652 505 * nodes are assigned in the Data::Data() constructor and don't do it 653 506 * here. It implies that this method may only be called after constructing 654 * a new BIOSSettings object while all its data fields are in the default507 * a new USBDeviceFilters object while all its data fields are in the default 655 508 * values. Exceptions are fields whose creation time defaults don't match 656 509 * values that should be applied when these fields are not explicitly set … … 660 513 * default to B. */ 661 514 662 m->bd->fEnabled = data.fEnabled;663 m->bd->fEnabledEHCI = data.fEnabledEHCI;664 665 515 #ifdef VBOX_WITH_USB 666 516 for (settings::USBDeviceFiltersList::const_iterator it = data.llDeviceFilters.begin(); … … 690 540 * @note Locks this object for reading. 691 541 */ 692 HRESULT USB Controller::saveSettings(settings::USBController &data)542 HRESULT USBDeviceFilters::saveSettings(settings::USBController &data) 693 543 { 694 544 AutoCaller autoCaller(this); … … 696 546 697 547 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS); 698 699 data.fEnabled = !!m->bd->fEnabled;700 data.fEnabledEHCI = !!m->bd->fEnabledEHCI;701 548 702 549 #ifdef VBOX_WITH_USB … … 740 587 741 588 /** @note Locks objects for writing! */ 742 void USB Controller::rollback()589 void USBDeviceFilters::rollback() 743 590 { 744 591 AutoCaller autoCaller(this); … … 751 598 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS); 752 599 753 m->bd.rollback();754 755 600 #ifdef VBOX_WITH_USB 756 601 757 602 if (m->llDeviceFilters.isBackedUp()) 758 603 { 759 USBProxyService * service= m->pHost->usbProxyService();760 Assert( service);604 USBProxyService *pProxySvc = m->pHost->usbProxyService(); 605 Assert(pProxySvc); 761 606 762 607 /* uninitialize all new filters (absent in the backed up list) */ … … 773 618 && (*it)->getData().mRemote.isMatch(false)) 774 619 { 775 USBDeviceFilter * filter = *it;776 Assert( filter->getId() != NULL);777 service->removeFilter(filter->getId());778 filter->getId() = NULL;620 USBDeviceFilter *pFilter = *it; 621 Assert(pFilter->getId() != NULL); 622 pProxySvc->removeFilter(pFilter->getId()); 623 pFilter->getId() = NULL; 779 624 } 780 625 … … 798 643 && (*it)->getData().mRemote.isMatch(false)) 799 644 { 800 USBDeviceFilter * flt= *it; /* resolve ambiguity */801 Assert( flt->getId() == NULL);802 flt->getId() = service->insertFilter(&flt->getData().mUSBFilter);645 USBDeviceFilter *pFilter = *it; /* resolve ambiguity */ 646 Assert(pFilter->getId() == NULL); 647 pFilter->getId() = pProxySvc->insertFilter(&pFilter->getData().mUSBFilter); 803 648 } 804 649 } … … 834 679 * for writing) if there is one. 835 680 */ 836 void USB Controller::commit()681 void USBDeviceFilters::commit() 837 682 { 838 683 /* sanity */ … … 847 692 * first) */ 848 693 AutoMultiWriteLock2 alock(m->pPeer, this COMMA_LOCKVAL_SRC_POS); 849 850 if (m->bd.isBackedUp())851 {852 m->bd.commit();853 if (m->pPeer)854 {855 /* attach new data to the peer and reshare it */856 AutoWriteLock peerlock(m->pPeer COMMA_LOCKVAL_SRC_POS);857 m->pPeer->m->bd.attach(m->bd);858 }859 }860 694 861 695 #ifdef VBOX_WITH_USB … … 940 774 * represented by @a aThat (locked for reading). 941 775 */ 942 void USB Controller::copyFrom(USBController*aThat)776 void USBDeviceFilters::copyFrom(USBDeviceFilters *aThat) 943 777 { 944 778 AssertReturnVoid(aThat != NULL); … … 962 796 AutoReadLock rl(aThat COMMA_LOCKVAL_SRC_POS); 963 797 AutoWriteLock wl(this COMMA_LOCKVAL_SRC_POS); 964 965 /* this will back up current data */966 m->bd.assignCopy(aThat->m->bd);967 798 968 799 #ifdef VBOX_WITH_USB … … 978 809 ++it) 979 810 { 980 ComObjPtr<USBDeviceFilter> filter;981 filter.createObject();982 filter->initCopy(this, *it);983 m->llDeviceFilters->push_back( filter);811 ComObjPtr<USBDeviceFilter> pFilter; 812 pFilter.createObject(); 813 pFilter->initCopy(this, *it); 814 m->llDeviceFilters->push_back(pFilter); 984 815 } 985 816 … … 994 825 * @note Locks nothing. 995 826 */ 996 HRESULT USB Controller::onDeviceFilterChange(USBDeviceFilter *aFilter,997 BOOL aActiveChanged /* = FALSE */)827 HRESULT USBDeviceFilters::onDeviceFilterChange(USBDeviceFilter *aFilter, 828 BOOL aActiveChanged /* = FALSE */) 998 829 { 999 830 AutoCaller autoCaller(this); … … 1013 844 && m->pParent->isRegistered()) 1014 845 { 1015 USBProxyService * service= m->pHost->usbProxyService();1016 ComAssertRet( service, E_FAIL);846 USBProxyService *pProxySvc = m->pHost->usbProxyService(); 847 ComAssertRet(pProxySvc, E_FAIL); 1017 848 1018 849 if (aActiveChanged) … … 1024 855 { 1025 856 ComAssertRet(aFilter->getId() == NULL, E_FAIL); 1026 aFilter->getId() = service->insertFilter(&aFilter->getData().mUSBFilter);857 aFilter->getId() = pProxySvc->insertFilter(&aFilter->getData().mUSBFilter); 1027 858 } 1028 859 else 1029 860 { 1030 861 ComAssertRet(aFilter->getId() != NULL, E_FAIL); 1031 service->removeFilter(aFilter->getId());862 pProxySvc->removeFilter(aFilter->getId()); 1032 863 aFilter->getId() = NULL; 1033 864 } … … 1040 871 /* update the filter in the proxy */ 1041 872 ComAssertRet(aFilter->getId() != NULL, E_FAIL); 1042 service->removeFilter(aFilter->getId());873 pProxySvc->removeFilter(aFilter->getId()); 1043 874 if (aFilter->getData().mRemote.isMatch(false)) 1044 875 { 1045 aFilter->getId() = service->insertFilter(&aFilter->getData().mUSBFilter);876 aFilter->getId() = pProxySvc->insertFilter(&aFilter->getData().mUSBFilter); 1046 877 } 1047 878 } … … 1060 891 * @note Locks this object for reading. 1061 892 */ 1062 bool USB Controller::hasMatchingFilter(const ComObjPtr<HostUSBDevice> &aDevice, ULONG *aMaskedIfs)893 bool USBDeviceFilters::hasMatchingFilter(const ComObjPtr<HostUSBDevice> &aDevice, ULONG *aMaskedIfs) 1063 894 { 1064 895 AutoCaller autoCaller(this); … … 1067 898 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS); 1068 899 1069 /* Disabled USB controllers cannot actually work with USB devices*/1070 if (!m-> bd->fEnabled)900 /* It is not possible to work with USB device if there is no USB controller present. */ 901 if (!m->pParent->isUSBControllerPresent()) 1071 902 return false; 1072 903 … … 1099 930 * @note Locks this object for reading. 1100 931 */ 1101 bool USB Controller::hasMatchingFilter(IUSBDevice *aUSBDevice, ULONG *aMaskedIfs)932 bool USBDeviceFilters::hasMatchingFilter(IUSBDevice *aUSBDevice, ULONG *aMaskedIfs) 1102 933 { 1103 934 LogFlowThisFuncEnter(); … … 1108 939 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS); 1109 940 1110 /* Disabled USB controllers cannot actually work with USB devices*/1111 if (!m-> bd->fEnabled)941 /* It is not possible to work with USB device if there is no USB controller present. */ 942 if (!m->pParent->isUSBControllerPresent()) 1112 943 return false; 1113 944 … … 1195 1026 1196 1027 /** 1197 * Notifies the proxy serviceabout all filters as requested by the1028 * Notifies the proxy pProxySvc about all filters as requested by the 1198 1029 * @a aInsertFilters argument. 1199 1030 * … … 1202 1033 * @note Locks this object for reading. 1203 1034 */ 1204 HRESULT USB Controller::notifyProxy(bool aInsertFilters)1035 HRESULT USBDeviceFilters::notifyProxy(bool aInsertFilters) 1205 1036 { 1206 1037 LogFlowThisFunc(("aInsertFilters=%RTbool\n", aInsertFilters)); … … 1211 1042 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS); 1212 1043 1213 USBProxyService * service= m->pHost->usbProxyService();1214 AssertReturn( service, E_FAIL);1044 USBProxyService *pProxySvc = m->pHost->usbProxyService(); 1045 AssertReturn(pProxySvc, E_FAIL); 1215 1046 1216 1047 DeviceFilterList::const_iterator it = m->llDeviceFilters->begin(); 1217 1048 while (it != m->llDeviceFilters->end()) 1218 1049 { 1219 USBDeviceFilter * flt= *it; /* resolve ambiguity (for ComPtr below) */1050 USBDeviceFilter *pFilter = *it; /* resolve ambiguity (for ComPtr below) */ 1220 1051 1221 1052 /* notify the proxy (only if the filter is active) */ 1222 if ( flt->getData().mActive1223 && flt->getData().mRemote.isMatch(false) /* and if the filter is NOT remote */1053 if ( pFilter->getData().mActive 1054 && pFilter->getData().mRemote.isMatch(false) /* and if the filter is NOT remote */ 1224 1055 ) 1225 1056 { 1226 1057 if (aInsertFilters) 1227 1058 { 1228 AssertReturn( flt->getId() == NULL, E_FAIL);1229 flt->getId() = service->insertFilter(&flt->getData().mUSBFilter);1059 AssertReturn(pFilter->getId() == NULL, E_FAIL); 1060 pFilter->getId() = pProxySvc->insertFilter(&pFilter->getData().mUSBFilter); 1230 1061 } 1231 1062 else … … 1234 1065 * when this method gets called (as a result of an early VM 1235 1066 * process crash for example. So, don't assert that ID != NULL. */ 1236 if ( flt->getId() != NULL)1067 if (pFilter->getId() != NULL) 1237 1068 { 1238 service->removeFilter(flt->getId());1239 flt->getId() = NULL;1069 pProxySvc->removeFilter(pFilter->getId()); 1070 pFilter->getId() = NULL; 1240 1071 } 1241 1072 } … … 1247 1078 } 1248 1079 1249 Machine* USB Controller::getMachine()1080 Machine* USBDeviceFilters::getMachine() 1250 1081 { 1251 1082 return m->pParent; -
trunk/src/VBox/Main/src-server/xpcom/server.cpp
r47018 r47376 85 85 #include "SystemPropertiesImpl.h" 86 86 #include "USBControllerImpl.h" 87 #include "USBDeviceFiltersImpl.h" 87 88 #include "VFSExplorerImpl.h" 88 89 #include "VirtualBoxImpl.h" … … 173 174 NS_DECL_CLASSINFO(USBController) 174 175 NS_IMPL_THREADSAFE_ISUPPORTS1_CI(USBController, IUSBController) 176 177 NS_DECL_CLASSINFO(USBDeviceFilters) 178 NS_IMPL_THREADSAFE_ISUPPORTS1_CI(USBDeviceFilters, IUSBDeviceFilters) 175 179 176 180 NS_DECL_CLASSINFO(StorageController)
Note:
See TracChangeset
for help on using the changeset viewer.