1 | /* $Id: USBDeviceFilterImpl.h 98103 2023-01-17 14:15:46Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * Declaration of USBDeviceFilter and HostUSBDeviceFilter.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2006-2023 Oracle and/or its affiliates.
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox base platform packages, as
|
---|
10 | * available from https://www.virtualbox.org.
|
---|
11 | *
|
---|
12 | * This program is free software; you can redistribute it and/or
|
---|
13 | * modify it under the terms of the GNU General Public License
|
---|
14 | * as published by the Free Software Foundation, in version 3 of the
|
---|
15 | * License.
|
---|
16 | *
|
---|
17 | * This program is distributed in the hope that it will be useful, but
|
---|
18 | * WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
20 | * General Public License for more details.
|
---|
21 | *
|
---|
22 | * You should have received a copy of the GNU General Public License
|
---|
23 | * along with this program; if not, see <https://www.gnu.org/licenses>.
|
---|
24 | *
|
---|
25 | * SPDX-License-Identifier: GPL-3.0-only
|
---|
26 | */
|
---|
27 |
|
---|
28 | #ifndef MAIN_INCLUDED_USBDeviceFilterImpl_h
|
---|
29 | #define MAIN_INCLUDED_USBDeviceFilterImpl_h
|
---|
30 | #ifndef RT_WITHOUT_PRAGMA_ONCE
|
---|
31 | # pragma once
|
---|
32 | #endif
|
---|
33 |
|
---|
34 | #include <VBox/settings.h>
|
---|
35 | #include "Matching.h"
|
---|
36 | #include <VBox/usbfilter.h>
|
---|
37 | #include "USBDeviceFilterWrap.h"
|
---|
38 |
|
---|
39 | class USBDeviceFilters;
|
---|
40 | class Host;
|
---|
41 | namespace settings
|
---|
42 | {
|
---|
43 | struct USBDeviceFilter;
|
---|
44 | }
|
---|
45 |
|
---|
46 | // USBDeviceFilter
|
---|
47 | ////////////////////////////////////////////////////////////////////////////////
|
---|
48 |
|
---|
49 | class ATL_NO_VTABLE USBDeviceFilter :
|
---|
50 | public USBDeviceFilterWrap
|
---|
51 | {
|
---|
52 | public:
|
---|
53 |
|
---|
54 | struct BackupableUSBDeviceFilterData
|
---|
55 | {
|
---|
56 | typedef matching::Matchable <matching::ParsedBoolFilter> BOOLFilter;
|
---|
57 |
|
---|
58 | BackupableUSBDeviceFilterData() : mId (NULL) {}
|
---|
59 | BackupableUSBDeviceFilterData(const BackupableUSBDeviceFilterData &aThat) :
|
---|
60 | mRemote(aThat.mRemote), mId(aThat.mId)
|
---|
61 | {
|
---|
62 | mData.strName = aThat.mData.strName;
|
---|
63 | mData.fActive = aThat.mData.fActive;
|
---|
64 | mData.ulMaskedInterfaces = aThat.mData.ulMaskedInterfaces;
|
---|
65 | USBFilterClone(&mUSBFilter, &aThat.mUSBFilter);
|
---|
66 | }
|
---|
67 |
|
---|
68 | /** Remote or local matching criterion. */
|
---|
69 | BOOLFilter mRemote;
|
---|
70 |
|
---|
71 | /** The filter data blob. */
|
---|
72 | USBFILTER mUSBFilter;
|
---|
73 |
|
---|
74 | /** Arbitrary ID field (not used by the class itself) */
|
---|
75 | void *mId;
|
---|
76 |
|
---|
77 | settings::USBDeviceFilter mData;
|
---|
78 | };
|
---|
79 |
|
---|
80 | DECLARE_COMMON_CLASS_METHODS(USBDeviceFilter)
|
---|
81 |
|
---|
82 | HRESULT FinalConstruct();
|
---|
83 | void FinalRelease();
|
---|
84 |
|
---|
85 | // public initializer/uninitializer for internal purposes only
|
---|
86 | HRESULT init(USBDeviceFilters *aParent,
|
---|
87 | const settings::USBDeviceFilter &data);
|
---|
88 | HRESULT init(USBDeviceFilters *aParent, IN_BSTR aName);
|
---|
89 | HRESULT init(USBDeviceFilters *aParent, USBDeviceFilter *aThat,
|
---|
90 | bool aReshare = false);
|
---|
91 | HRESULT initCopy(USBDeviceFilters *aParent, USBDeviceFilter *aThat);
|
---|
92 | void uninit();
|
---|
93 |
|
---|
94 | // public methods only for internal purposes
|
---|
95 | bool i_isModified();
|
---|
96 | void i_rollback();
|
---|
97 | void i_commit();
|
---|
98 |
|
---|
99 | void unshare();
|
---|
100 |
|
---|
101 | // public methods for internal purposes only
|
---|
102 | // (ensure there is a caller and a read lock before calling them!)
|
---|
103 | void *& i_getId() { return bd->mId; }
|
---|
104 | const BackupableUSBDeviceFilterData& i_getData() { return *bd.data(); }
|
---|
105 | ComObjPtr<USBDeviceFilter> i_peer() { return mPeer; }
|
---|
106 |
|
---|
107 | // tr() wants to belong to a class it seems, thus this one here.
|
---|
108 | static HRESULT i_usbFilterFieldFromString(PUSBFILTER aFilter,
|
---|
109 | USBFILTERIDX aIdx,
|
---|
110 | const Utf8Str &aValue,
|
---|
111 | Utf8Str &aErrStr);
|
---|
112 |
|
---|
113 | static const char* i_describeUSBFilterIdx(USBFILTERIDX aIdx);
|
---|
114 |
|
---|
115 | private:
|
---|
116 |
|
---|
117 | // wrapped IUSBDeviceFilter properties
|
---|
118 | HRESULT getName(com::Utf8Str &aName);
|
---|
119 | HRESULT setName(const com::Utf8Str &aName);
|
---|
120 | HRESULT getActive(BOOL *aActive);
|
---|
121 | HRESULT setActive(BOOL aActive);
|
---|
122 | HRESULT getVendorId(com::Utf8Str &aVendorId);
|
---|
123 | HRESULT setVendorId(const com::Utf8Str &aVendorId);
|
---|
124 | HRESULT getProductId(com::Utf8Str &aProductId);
|
---|
125 | HRESULT setProductId(const com::Utf8Str &aProductId);
|
---|
126 | HRESULT getRevision(com::Utf8Str &aRevision);
|
---|
127 | HRESULT setRevision(const com::Utf8Str &aRevision);
|
---|
128 | HRESULT getManufacturer(com::Utf8Str &aManufacturer);
|
---|
129 | HRESULT setManufacturer(const com::Utf8Str &aManufacturer);
|
---|
130 | HRESULT getProduct(com::Utf8Str &aProduct);
|
---|
131 | HRESULT setProduct(const com::Utf8Str &aProduct);
|
---|
132 | HRESULT getSerialNumber(com::Utf8Str &aSerialNumber);
|
---|
133 | HRESULT setSerialNumber(const com::Utf8Str &aSerialNumber);
|
---|
134 | HRESULT getPort(com::Utf8Str &aPort);
|
---|
135 | HRESULT setPort(const com::Utf8Str &aPort);
|
---|
136 | HRESULT getRemote(com::Utf8Str &aRemote);
|
---|
137 | HRESULT setRemote(const com::Utf8Str &aRemote);
|
---|
138 | HRESULT getMaskedInterfaces(ULONG *aMaskedInterfaces);
|
---|
139 | HRESULT setMaskedInterfaces(ULONG aMaskedInterfaces);
|
---|
140 |
|
---|
141 | // wrapped IUSBDeviceFilter methods
|
---|
142 | HRESULT i_usbFilterFieldGetter(USBFILTERIDX aIdx, com::Utf8Str &aStr);
|
---|
143 | HRESULT i_usbFilterFieldSetter(USBFILTERIDX aIdx, const com::Utf8Str &strNew);
|
---|
144 |
|
---|
145 | USBDeviceFilters * const mParent;
|
---|
146 | USBDeviceFilter * const mPeer;
|
---|
147 |
|
---|
148 | Backupable<BackupableUSBDeviceFilterData> bd;
|
---|
149 |
|
---|
150 | bool m_fModified;
|
---|
151 |
|
---|
152 | /** Used externally to indicate this filter is in the list
|
---|
153 | (not touched by the class itself except that in init()/uninit()) */
|
---|
154 | bool mInList;
|
---|
155 |
|
---|
156 | friend class USBDeviceFilters;
|
---|
157 | };
|
---|
158 | #include "HostUSBDeviceFilterWrap.h"
|
---|
159 |
|
---|
160 | // HostUSBDeviceFilter
|
---|
161 | ////////////////////////////////////////////////////////////////////////////////
|
---|
162 |
|
---|
163 | class ATL_NO_VTABLE HostUSBDeviceFilter :
|
---|
164 | public HostUSBDeviceFilterWrap
|
---|
165 | {
|
---|
166 | public:
|
---|
167 |
|
---|
168 | struct BackupableUSBDeviceFilterData : public USBDeviceFilter::BackupableUSBDeviceFilterData
|
---|
169 | {
|
---|
170 | BackupableUSBDeviceFilterData() {}
|
---|
171 | };
|
---|
172 |
|
---|
173 | DECLARE_COMMON_CLASS_METHODS (HostUSBDeviceFilter)
|
---|
174 |
|
---|
175 | HRESULT FinalConstruct();
|
---|
176 | void FinalRelease();
|
---|
177 |
|
---|
178 | // public initializer/uninitializer for internal purposes only
|
---|
179 | HRESULT init(Host *aParent,
|
---|
180 | const settings::USBDeviceFilter &data);
|
---|
181 | HRESULT init(Host *aParent, IN_BSTR aName);
|
---|
182 | void uninit();
|
---|
183 |
|
---|
184 | // public methods for internal purposes only
|
---|
185 | // (ensure there is a caller and a read lock before calling them!)
|
---|
186 | void i_saveSettings(settings::USBDeviceFilter &data);
|
---|
187 |
|
---|
188 | void*& i_getId() { return bd.data()->mId; }
|
---|
189 |
|
---|
190 | const BackupableUSBDeviceFilterData& i_getData() { return *bd.data(); }
|
---|
191 |
|
---|
192 | // util::Lockable interface
|
---|
193 | RWLockHandle *lockHandle() const;
|
---|
194 |
|
---|
195 | private:
|
---|
196 |
|
---|
197 | // wrapped IHostUSBDeviceFilter properties
|
---|
198 | HRESULT getName(com::Utf8Str &aName);
|
---|
199 | HRESULT setName(const com::Utf8Str &aName);
|
---|
200 | HRESULT getActive(BOOL *aActive);
|
---|
201 | HRESULT setActive(BOOL aActive);
|
---|
202 | HRESULT getVendorId(com::Utf8Str &aVendorId);
|
---|
203 | HRESULT setVendorId(const com::Utf8Str &aVendorId);
|
---|
204 | HRESULT getProductId(com::Utf8Str &aProductId);
|
---|
205 | HRESULT setProductId(const com::Utf8Str &aProductId);
|
---|
206 | HRESULT getRevision(com::Utf8Str &aRevision);
|
---|
207 | HRESULT setRevision(const com::Utf8Str &aRevision);
|
---|
208 | HRESULT getManufacturer(com::Utf8Str &aManufacturer);
|
---|
209 | HRESULT setManufacturer(const com::Utf8Str &aManufacturer);
|
---|
210 | HRESULT getProduct(com::Utf8Str &aProduct);
|
---|
211 | HRESULT setProduct(const com::Utf8Str &aProduct);
|
---|
212 | HRESULT getSerialNumber(com::Utf8Str &aSerialNumber);
|
---|
213 | HRESULT setSerialNumber(const com::Utf8Str &aSerialNumber);
|
---|
214 | HRESULT getPort(com::Utf8Str &aPort);
|
---|
215 | HRESULT setPort(const com::Utf8Str &aPort);
|
---|
216 | HRESULT getRemote(com::Utf8Str &aRemote);
|
---|
217 | HRESULT setRemote(const com::Utf8Str &aRemote);
|
---|
218 | HRESULT getMaskedInterfaces(ULONG *aMaskedInterfaces);
|
---|
219 | HRESULT setMaskedInterfaces(ULONG aMaskedInterfaces);
|
---|
220 |
|
---|
221 | // wrapped IHostUSBDeviceFilter properties
|
---|
222 | HRESULT getAction(USBDeviceFilterAction_T *aAction);
|
---|
223 | HRESULT setAction(USBDeviceFilterAction_T aAction);
|
---|
224 |
|
---|
225 | HRESULT i_usbFilterFieldGetter(USBFILTERIDX aIdx, com::Utf8Str &aStr);
|
---|
226 | HRESULT i_usbFilterFieldSetter(USBFILTERIDX aIdx, const com::Utf8Str &aStr);
|
---|
227 |
|
---|
228 | Host * const mParent;
|
---|
229 |
|
---|
230 | Backupable<BackupableUSBDeviceFilterData> bd;
|
---|
231 |
|
---|
232 | /** Used externally to indicate this filter is in the list
|
---|
233 | (not touched by the class itself except that in init()/uninit()) */
|
---|
234 | bool mInList;
|
---|
235 |
|
---|
236 | friend class Host;
|
---|
237 | };
|
---|
238 |
|
---|
239 | #endif /* !MAIN_INCLUDED_USBDeviceFilterImpl_h */
|
---|
240 | /* vi: set tabstop=4 shiftwidth=4 expandtab: */
|
---|