1 | /** @file
|
---|
2 | *
|
---|
3 | * VirtualBox IHostUSBDevice COM interface implementation
|
---|
4 | * for remote (VRDP) USB devices
|
---|
5 | */
|
---|
6 |
|
---|
7 | /*
|
---|
8 | * Copyright (C) 2006 InnoTek Systemberatung GmbH
|
---|
9 | *
|
---|
10 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
11 | * available from http://www.215389.xyz. This file is free software;
|
---|
12 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
13 | * General Public License as published by the Free Software Foundation,
|
---|
14 | * in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
|
---|
15 | * distribution. VirtualBox OSE is distributed in the hope that it will
|
---|
16 | * be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
17 | *
|
---|
18 | * If you received this file as part of a commercial VirtualBox
|
---|
19 | * distribution, then only the terms of your commercial VirtualBox
|
---|
20 | * license agreement apply instead of the previous paragraph.
|
---|
21 | */
|
---|
22 |
|
---|
23 | #ifndef ____H_REMOTEUSBDEVICEIMPL
|
---|
24 | #define ____H_REMOTEUSBDEVICEIMPL
|
---|
25 |
|
---|
26 | #include "VirtualBoxBase.h"
|
---|
27 | #include "Collection.h"
|
---|
28 | #include <VBox/vrdpapi.h>
|
---|
29 |
|
---|
30 | class ATL_NO_VTABLE RemoteUSBDevice :
|
---|
31 | public VirtualBoxSupportErrorInfoImpl <RemoteUSBDevice, IHostUSBDevice>,
|
---|
32 | public VirtualBoxSupportTranslation <RemoteUSBDevice>,
|
---|
33 | public VirtualBoxBase,
|
---|
34 | public IHostUSBDevice
|
---|
35 | {
|
---|
36 | public:
|
---|
37 |
|
---|
38 | DECLARE_NOT_AGGREGATABLE(RemoteUSBDevice)
|
---|
39 |
|
---|
40 | DECLARE_PROTECT_FINAL_CONSTRUCT()
|
---|
41 |
|
---|
42 | BEGIN_COM_MAP(RemoteUSBDevice)
|
---|
43 | COM_INTERFACE_ENTRY(ISupportErrorInfo)
|
---|
44 | COM_INTERFACE_ENTRY(IHostUSBDevice)
|
---|
45 | COM_INTERFACE_ENTRY(IUSBDevice)
|
---|
46 | END_COM_MAP()
|
---|
47 |
|
---|
48 | NS_DECL_ISUPPORTS
|
---|
49 |
|
---|
50 | DECLARE_EMPTY_CTOR_DTOR (RemoteUSBDevice)
|
---|
51 |
|
---|
52 | HRESULT FinalConstruct();
|
---|
53 | void FinalRelease();
|
---|
54 |
|
---|
55 | // public initializer/uninitializer for internal purposes only
|
---|
56 | #ifdef VRDP_MC
|
---|
57 | HRESULT init(uint32_t u32ClientId, VRDPUSBDEVICEDESC *pDevDesc);
|
---|
58 | #else
|
---|
59 | HRESULT init(VRDPUSBDEVICEDESC *pDevDesc);
|
---|
60 | #endif /* VRDP_MC */
|
---|
61 | void uninit();
|
---|
62 |
|
---|
63 | // IUSBDevice properties
|
---|
64 | STDMETHOD(COMGETTER(Id)) (GUIDPARAMOUT aId);
|
---|
65 | STDMETHOD(COMGETTER(VendorId)) (USHORT *aVendorId);
|
---|
66 | STDMETHOD(COMGETTER(ProductId)) (USHORT *aProductId);
|
---|
67 | STDMETHOD(COMGETTER(Revision)) (USHORT *aRevision);
|
---|
68 | STDMETHOD(COMGETTER(Manufacturer)) (BSTR *aManufacturer);
|
---|
69 | STDMETHOD(COMGETTER(Product)) (BSTR *aProduct);
|
---|
70 | STDMETHOD(COMGETTER(SerialNumber)) (BSTR *aSerialNumber);
|
---|
71 | STDMETHOD(COMGETTER(Address)) (BSTR *aAddress);
|
---|
72 | STDMETHOD(COMGETTER(Port)) (USHORT *aPort);
|
---|
73 | STDMETHOD(COMGETTER(Remote)) (BOOL *aRemote);
|
---|
74 |
|
---|
75 | // IHostUSBDevice properties
|
---|
76 | STDMETHOD(COMGETTER(State)) (USBDeviceState_T *aState);
|
---|
77 |
|
---|
78 | // public methods only for internal purposes
|
---|
79 | bool dirty (void) { return mDirty; }
|
---|
80 | void dirty (bool aDirty) { mDirty = aDirty; }
|
---|
81 |
|
---|
82 | uint16_t devId (void) { return mDevId; }
|
---|
83 | #ifdef VRDP_MC
|
---|
84 | uint32_t clientId (void) { return mClientId; }
|
---|
85 | #endif /* VRDP_MC */
|
---|
86 |
|
---|
87 | bool captured (void) { return mState == USBDeviceState_USBDeviceCaptured; }
|
---|
88 | void captured (bool aCaptured)
|
---|
89 | {
|
---|
90 | if (aCaptured)
|
---|
91 | {
|
---|
92 | Assert(mState == USBDeviceState_USBDeviceAvailable);
|
---|
93 | mState = USBDeviceState_USBDeviceCaptured;
|
---|
94 | }
|
---|
95 | else
|
---|
96 | {
|
---|
97 | Assert(mState == USBDeviceState_USBDeviceCaptured);
|
---|
98 | mState = USBDeviceState_USBDeviceAvailable;
|
---|
99 | }
|
---|
100 | }
|
---|
101 |
|
---|
102 | // for VirtualBoxSupportErrorInfoImpl
|
---|
103 | static const wchar_t *getComponentName() { return L"RemoteUSBDevice"; }
|
---|
104 |
|
---|
105 | private:
|
---|
106 |
|
---|
107 | Guid mId;
|
---|
108 |
|
---|
109 | uint16_t mVendorId;
|
---|
110 | uint16_t mProductId;
|
---|
111 | uint16_t mRevision;
|
---|
112 |
|
---|
113 | Bstr mManufacturer;
|
---|
114 | Bstr mProduct;
|
---|
115 | Bstr mSerialNumber;
|
---|
116 |
|
---|
117 | Bstr mAddress;
|
---|
118 |
|
---|
119 | uint16_t mPort;
|
---|
120 |
|
---|
121 | USBDeviceState_T mState;
|
---|
122 |
|
---|
123 | bool mDirty;
|
---|
124 | uint16_t mDevId;
|
---|
125 | #ifdef VRDP_MC
|
---|
126 | uint32_t mClientId;
|
---|
127 | #endif /* VRDP_MC */
|
---|
128 | };
|
---|
129 |
|
---|
130 |
|
---|
131 | /// @todo (dmik) give a less stupid name and move to Collection.h
|
---|
132 | #define COM_DECL_READONLY_ENUM_AND_COLLECTION_FOR_BEGIN(c, iface) \
|
---|
133 | class c##Enumerator \
|
---|
134 | : public IfaceVectorEnumerator \
|
---|
135 | <iface##Enumerator, iface, ComObjPtr <c>, c##Enumerator> \
|
---|
136 | , public VirtualBoxSupportTranslation <c##Enumerator> \
|
---|
137 | { \
|
---|
138 | NS_DECL_ISUPPORTS \
|
---|
139 | public: static const wchar_t *getComponentName() { \
|
---|
140 | return WSTR_LITERAL (c) L"Enumerator"; \
|
---|
141 | } \
|
---|
142 | }; \
|
---|
143 | class c##Collection \
|
---|
144 | : public ReadonlyIfaceVector \
|
---|
145 | <iface##Collection, iface, iface##Enumerator, ComObjPtr <c>, c##Enumerator, \
|
---|
146 | c##Collection> \
|
---|
147 | , public VirtualBoxSupportTranslation <c##Collection> \
|
---|
148 | { \
|
---|
149 | NS_DECL_ISUPPORTS \
|
---|
150 | public: static const wchar_t *getComponentName() { \
|
---|
151 | return WSTR_LITERAL (c) L"Collection"; \
|
---|
152 | }
|
---|
153 |
|
---|
154 | #define COM_DECL_READONLY_ENUM_AND_COLLECTION_FOR_END(c, iface) \
|
---|
155 | };
|
---|
156 |
|
---|
157 | #ifdef __WIN__
|
---|
158 |
|
---|
159 | #define COM_IMPL_READONLY_ENUM_AND_COLLECTION_FOR(c, iface)
|
---|
160 |
|
---|
161 | #else // !__WIN__
|
---|
162 |
|
---|
163 | #define COM_IMPL_READONLY_ENUM_AND_COLLECTION_FOR(c, iface) \
|
---|
164 | NS_DECL_CLASSINFO(c##Collection) \
|
---|
165 | NS_IMPL_THREADSAFE_ISUPPORTS1_CI(c##Collection, iface##Collection) \
|
---|
166 | NS_DECL_CLASSINFO(c##Enumerator) \
|
---|
167 | NS_IMPL_THREADSAFE_ISUPPORTS1_CI(c##Enumerator, iface##Enumerator)
|
---|
168 |
|
---|
169 | #endif
|
---|
170 |
|
---|
171 | COM_DECL_READONLY_ENUM_AND_COLLECTION_FOR_BEGIN (RemoteUSBDevice, IHostUSBDevice)
|
---|
172 |
|
---|
173 | STDMETHOD(FindById) (INPTR GUIDPARAM aId, IHostUSBDevice **aDevice)
|
---|
174 | {
|
---|
175 | Guid idToFind = aId;
|
---|
176 | if (idToFind.isEmpty())
|
---|
177 | return E_INVALIDARG;
|
---|
178 | if (!aDevice)
|
---|
179 | return E_POINTER;
|
---|
180 |
|
---|
181 | *aDevice = NULL;
|
---|
182 | Vector::value_type found;
|
---|
183 | Vector::iterator it = vec.begin();
|
---|
184 | while (!found && it != vec.end())
|
---|
185 | {
|
---|
186 | Guid id;
|
---|
187 | (*it)->COMGETTER(Id) (id.asOutParam());
|
---|
188 | if (id == idToFind)
|
---|
189 | found = *it;
|
---|
190 | ++ it;
|
---|
191 | }
|
---|
192 |
|
---|
193 | if (!found)
|
---|
194 | return setError (E_INVALIDARG, RemoteUSBDeviceCollection::tr (
|
---|
195 | "Could not find a USB device with UUID {%s}"),
|
---|
196 | idToFind.toString().raw());
|
---|
197 |
|
---|
198 | return found.queryInterfaceTo (aDevice);
|
---|
199 | }
|
---|
200 |
|
---|
201 | STDMETHOD(FindByAddress) (INPTR BSTR aAddress, IHostUSBDevice **aDevice)
|
---|
202 | {
|
---|
203 | if (!aAddress)
|
---|
204 | return E_INVALIDARG;
|
---|
205 | if (!aDevice)
|
---|
206 | return E_POINTER;
|
---|
207 |
|
---|
208 | *aDevice = NULL;
|
---|
209 | Vector::value_type found;
|
---|
210 | Vector::iterator it = vec.begin();
|
---|
211 | while (!found && it != vec.end())
|
---|
212 | {
|
---|
213 | Bstr address;
|
---|
214 | (*it)->COMGETTER(Address) (address.asOutParam());
|
---|
215 | if (address == aAddress)
|
---|
216 | found = *it;
|
---|
217 | ++ it;
|
---|
218 | }
|
---|
219 |
|
---|
220 | if (!found)
|
---|
221 | return setError (E_INVALIDARG, RemoteUSBDeviceCollection::tr (
|
---|
222 | "Could not find a USB device with address '%ls'"),
|
---|
223 | aAddress);
|
---|
224 |
|
---|
225 | return found.queryInterfaceTo (aDevice);
|
---|
226 | }
|
---|
227 |
|
---|
228 | COM_DECL_READONLY_ENUM_AND_COLLECTION_FOR_END (RemoteUSBDevice, IHostUSBDevice)
|
---|
229 |
|
---|
230 |
|
---|
231 | #endif // ____H_REMOTEUSBDEVICEIMPL
|
---|