VirtualBox

source: vbox/trunk/src/VBox/Main/include/USBControllerImpl.h@ 4044

Last change on this file since 4044 was 3412, checked in by vboxsync, 17 years ago

Main: Converted USBDeviceFilter and HostUSBDeviceFilter to the new locking scheme.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.9 KB
Line 
1/** @file
2 *
3 * VBox USBController COM Class declaration.
4 */
5
6/*
7 * Copyright (C) 2006-2007 innotek GmbH
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License as published by the Free Software Foundation,
13 * in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
14 * distribution. VirtualBox OSE is distributed in the hope that it will
15 * be useful, but WITHOUT ANY WARRANTY of any kind.
16 *
17 * If you received this file as part of a commercial VirtualBox
18 * distribution, then only the terms of your commercial VirtualBox
19 * license agreement apply instead of the previous paragraph.
20 */
21
22#ifndef ____H_USBCONTROLLERIMPL
23#define ____H_USBCONTROLLERIMPL
24
25#include "VirtualBoxBase.h"
26#include "USBDeviceFilterImpl.h"
27
28#include <VBox/cfgldr.h>
29
30#include <list>
31
32class Machine;
33class HostUSBDevice;
34
35/**
36 * @note we cannot use VirtualBoxBaseWithTypedChildren <USBDeviceFilter> as a
37 * base class, because we want a quick (map-based) way of validating
38 * IUSBDeviceFilter pointers passed from outside as method parameters that
39 * VirtualBoxBaseWithChildren::getDependentChild() gives us.
40 */
41
42class ATL_NO_VTABLE USBController :
43 public VirtualBoxBaseWithChildrenNEXT,
44 public VirtualBoxSupportErrorInfoImpl <USBController, IUSBController>,
45 public VirtualBoxSupportTranslation <USBController>,
46 public IUSBController
47{
48private:
49
50 struct Data
51 {
52 /* Constructor. */
53 Data() : mEnabled (FALSE) { }
54
55 bool operator== (const Data &that) const
56 {
57 return this == &that || mEnabled == that.mEnabled;
58 }
59
60 /** Enabled indicator. */
61 BOOL mEnabled;
62 };
63
64public:
65
66 VIRTUALBOXBASE_ADD_ERRORINFO_SUPPORT (USBController)
67
68 DECLARE_NOT_AGGREGATABLE (USBController)
69
70 DECLARE_PROTECT_FINAL_CONSTRUCT()
71
72 BEGIN_COM_MAP(USBController)
73 COM_INTERFACE_ENTRY (ISupportErrorInfo)
74 COM_INTERFACE_ENTRY (IUSBController)
75 END_COM_MAP()
76
77 NS_DECL_ISUPPORTS
78
79 DECLARE_EMPTY_CTOR_DTOR (USBController)
80
81 HRESULT FinalConstruct();
82 void FinalRelease();
83
84 // public initializer/uninitializer for internal purposes only
85 HRESULT init (Machine *aParent);
86 HRESULT init (Machine *aParent, USBController *aThat);
87 HRESULT initCopy (Machine *aParent, USBController *aThat);
88 void uninit();
89
90 // IUSBController properties
91 STDMETHOD(COMGETTER(Enabled)) (BOOL *aEnabled);
92 STDMETHOD(COMSETTER(Enabled)) (BOOL aEnabled);
93 STDMETHOD(COMGETTER(USBStandard)) (USHORT *aUSBStandard);
94 STDMETHOD(COMGETTER(DeviceFilters)) (IUSBDeviceFilterCollection **aDevicesFilters);
95
96 // IUSBController methods
97 STDMETHOD(CreateDeviceFilter) (INPTR BSTR aName, IUSBDeviceFilter **aFilter);
98 STDMETHOD(InsertDeviceFilter) (ULONG aPosition, IUSBDeviceFilter *aFilter);
99 STDMETHOD(RemoveDeviceFilter) (ULONG aPosition, IUSBDeviceFilter **aFilter);
100
101 // public methods only for internal purposes
102
103 HRESULT loadSettings (CFGNODE aMachine);
104 HRESULT saveSettings (CFGNODE aMachine);
105
106 bool isModified();
107 bool isReallyModified();
108 bool rollback();
109 void commit();
110 void copyFrom (USBController *aThat);
111
112 HRESULT onMachineRegistered (BOOL aRegistered);
113
114 HRESULT onDeviceFilterChange (USBDeviceFilter *aFilter,
115 BOOL aActiveChanged = FALSE);
116
117 bool hasMatchingFilter (ComObjPtr <HostUSBDevice> &aDevice);
118 bool hasMatchingFilter (IUSBDevice *aUSBDevice);
119
120 HRESULT notifyProxy (bool aInsertFilters);
121
122 // public methods for internal purposes only
123 // (ensure there is a caller and a read lock before calling them!)
124
125 /** @note this doesn't require a read lock since mParent is constant. */
126 const ComObjPtr <Machine, ComWeakRef> &parent() { return mParent; };
127
128 const Backupable<Data> &data() { return mData; }
129
130 // for VirtualBoxSupportErrorInfoImpl
131 static const wchar_t *getComponentName() { return L"USBController"; }
132
133private:
134
135 /** specialization for IUSBDeviceFilter */
136 ComObjPtr <USBDeviceFilter> getDependentChild (IUSBDeviceFilter *aFilter)
137 {
138 VirtualBoxBase *child = VirtualBoxBaseWithChildren::
139 getDependentChild (ComPtr <IUnknown> (aFilter));
140 return child ? static_cast <USBDeviceFilter *> (child)
141 : NULL;
142 }
143
144 void printList();
145
146 /** Parent object. */
147 const ComObjPtr<Machine, ComWeakRef> mParent;
148 /** Peer object. */
149 const ComObjPtr <USBController> mPeer;
150 /** Data. */
151 Backupable <Data> mData;
152
153 // the following fields need special backup/rollback/commit handling,
154 // so they cannot be a part of Data
155
156 typedef std::list <ComObjPtr <USBDeviceFilter> > DeviceFilterList;
157 Backupable <DeviceFilterList> mDeviceFilters;
158};
159
160#endif //!____H_USBCONTROLLERIMPL
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette