VirtualBox

source: vbox/trunk/src/VBox/Main/src-client/RemoteUSBDeviceImpl.cpp@ 53517

Last change on this file since 53517 was 53508, checked in by vboxsync, 10 years ago

warning

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 9.4 KB
Line 
1/* $Id: RemoteUSBDeviceImpl.cpp 53508 2014-12-11 12:07:48Z vboxsync $ */
2
3/** @file
4 *
5 * VirtualBox IHostUSBDevice COM interface implementation
6 * for remote (VRDP) USB devices
7 */
8
9/*
10 * Copyright (C) 2006-2011 Oracle Corporation
11 *
12 * This file is part of VirtualBox Open Source Edition (OSE), as
13 * available from http://www.virtualbox.org. This file is free software;
14 * you can redistribute it and/or modify it under the terms of the GNU
15 * General Public License (GPL) as published by the Free Software
16 * Foundation, in version 2 as it comes in the "COPYING" file of the
17 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
18 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
19 */
20
21#include "RemoteUSBDeviceImpl.h"
22
23#include "AutoCaller.h"
24#include "Logging.h"
25
26#include <iprt/cpp/utils.h>
27
28#include <VBox/err.h>
29
30#include <VBox/RemoteDesktop/VRDE.h>
31#include <VBox/vrdpusb.h>
32
33// constructor / destructor
34/////////////////////////////////////////////////////////////////////////////
35
36DEFINE_EMPTY_CTOR_DTOR (RemoteUSBDevice)
37
38HRESULT RemoteUSBDevice::FinalConstruct()
39{
40 return BaseFinalConstruct();
41}
42
43void RemoteUSBDevice::FinalRelease()
44{
45 uninit();
46 BaseFinalRelease();
47}
48
49// public initializer/uninitializer for internal purposes only
50/////////////////////////////////////////////////////////////////////////////
51
52/** @todo (sunlover) REMOTE_USB Device states. */
53
54/**
55 * Initializes the remote USB device object.
56 */
57HRESULT RemoteUSBDevice::init (uint32_t u32ClientId, VRDEUSBDEVICEDESC *pDevDesc, bool fDescExt)
58{
59 LogFlowThisFunc(("u32ClientId=%d,pDevDesc=%p\n", u32ClientId, pDevDesc));
60
61 /* Enclose the state transition NotReady->InInit->Ready */
62 AutoInitSpan autoInitSpan(this);
63 AssertReturn(autoInitSpan.isOk(), E_FAIL);
64
65 unconst(mData.id).create();
66
67 unconst(mData.vendorId) = pDevDesc->idVendor;
68 unconst(mData.productId) = pDevDesc->idProduct;
69 unconst(mData.revision) = pDevDesc->bcdRev;
70
71 unconst(mData.manufacturer) = pDevDesc->oManufacturer? (char *)pDevDesc + pDevDesc->oManufacturer: "";
72 unconst(mData.product) = pDevDesc->oProduct? (char *)pDevDesc + pDevDesc->oProduct: "";
73 unconst(mData.serialNumber) = pDevDesc->oSerialNumber? (char *)pDevDesc + pDevDesc->oSerialNumber: "";
74
75 char id[64];
76 RTStrPrintf(id, sizeof (id), REMOTE_USB_BACKEND_PREFIX_S "0x%08X&0x%08X", pDevDesc->id, u32ClientId);
77 unconst(mData.address) = id;
78
79 unconst(mData.port) = pDevDesc->idPort;
80 unconst(mData.version) = pDevDesc->bcdUSB >> 8;
81 if (fDescExt)
82 {
83 VRDEUSBDEVICEDESCEXT *pDevDescExt = (VRDEUSBDEVICEDESCEXT *)pDevDesc;
84 switch (pDevDescExt->u16DeviceSpeed)
85 {
86 default:
87 case VRDE_USBDEVICESPEED_UNKNOWN:
88 case VRDE_USBDEVICESPEED_LOW:
89 case VRDE_USBDEVICESPEED_FULL:
90 unconst(mData.portVersion) = 1;
91 unconst(mData.speed) = USBConnectionSpeed_Full;
92 break;
93
94 case VRDE_USBDEVICESPEED_HIGH:
95 case VRDE_USBDEVICESPEED_VARIABLE:
96 unconst(mData.portVersion) = 2;
97 unconst(mData.speed) = USBConnectionSpeed_High;
98 break;
99
100 case VRDE_USBDEVICESPEED_SUPERSPEED:
101 unconst(mData.portVersion) = 3;
102 unconst(mData.speed) = USBConnectionSpeed_Super;
103 break;
104 }
105 }
106 else
107 {
108 unconst(mData.portVersion) = mData.version;
109 unconst(mData.speed) = mData.version == 3
110 ? (USBConnectionSpeed_T)USBConnectionSpeed_Super
111 : mData.version == 2 ? (USBConnectionSpeed_T)USBConnectionSpeed_High
112 : (USBConnectionSpeed_T)USBConnectionSpeed_Full;
113 }
114
115 mData.state = USBDeviceState_Available;
116
117 mData.dirty = false;
118 unconst(mData.devId) = pDevDesc->id;
119
120 unconst(mData.clientId) = u32ClientId;
121
122 /* Confirm a successful initialization */
123 autoInitSpan.setSucceeded();
124
125 return S_OK;
126}
127
128
129/**
130 * Uninitializes the instance and sets the ready flag to FALSE.
131 * Called either from FinalRelease() or by the parent when it gets destroyed.
132 */
133void RemoteUSBDevice::uninit()
134{
135 LogFlowThisFunc(("\n"));
136
137 /* Enclose the state transition Ready->InUninit->NotReady */
138 AutoUninitSpan autoUninitSpan(this);
139 if (autoUninitSpan.uninitDone())
140 return;
141
142 unconst(mData.id).clear();
143
144 unconst(mData.vendorId) = 0;
145 unconst(mData.productId) = 0;
146 unconst(mData.revision) = 0;
147
148 unconst(mData.manufacturer).setNull();
149 unconst(mData.product).setNull();
150 unconst(mData.serialNumber).setNull();
151
152 unconst(mData.address).setNull();
153
154 unconst(mData.port) = 0;
155 unconst(mData.version) = 1;
156 unconst(mData.portVersion) = 1;
157
158 unconst(mData.dirty) = FALSE;
159
160 unconst(mData.devId) = 0;
161 unconst(mData.clientId) = 0;
162}
163
164// IUSBDevice properties
165/////////////////////////////////////////////////////////////////////////////
166
167STDMETHODIMP RemoteUSBDevice::COMGETTER(Id) (BSTR *aId)
168{
169 CheckComArgOutPointerValid(aId);
170
171 AutoCaller autoCaller(this);
172 if (FAILED(autoCaller.rc())) return autoCaller.rc();
173
174 /* this is const, no need to lock */
175 mData.id.toUtf16().detachTo(aId);
176
177 return S_OK;
178}
179
180STDMETHODIMP RemoteUSBDevice::COMGETTER(VendorId) (USHORT *aVendorId)
181{
182 CheckComArgOutPointerValid(aVendorId);
183
184 AutoCaller autoCaller(this);
185 if (FAILED(autoCaller.rc())) return autoCaller.rc();
186
187 /* this is const, no need to lock */
188 *aVendorId = mData.vendorId;
189
190 return S_OK;
191}
192
193STDMETHODIMP RemoteUSBDevice::COMGETTER(ProductId) (USHORT *aProductId)
194{
195 CheckComArgOutPointerValid(aProductId);
196
197 AutoCaller autoCaller(this);
198 if (FAILED(autoCaller.rc())) return autoCaller.rc();
199
200 /* this is const, no need to lock */
201 *aProductId = mData.productId;
202
203 return S_OK;
204}
205
206STDMETHODIMP RemoteUSBDevice::COMGETTER(Revision) (USHORT *aRevision)
207{
208 CheckComArgOutPointerValid(aRevision);
209
210 AutoCaller autoCaller(this);
211 if (FAILED(autoCaller.rc())) return autoCaller.rc();
212
213 /* this is const, no need to lock */
214 *aRevision = mData.revision;
215
216 return S_OK;
217}
218
219STDMETHODIMP RemoteUSBDevice::COMGETTER(Manufacturer) (BSTR *aManufacturer)
220{
221 CheckComArgOutPointerValid(aManufacturer);
222
223 AutoCaller autoCaller(this);
224 if (FAILED(autoCaller.rc())) return autoCaller.rc();
225
226 /* this is const, no need to lock */
227 mData.manufacturer.cloneTo(aManufacturer);
228
229 return S_OK;
230}
231
232STDMETHODIMP RemoteUSBDevice::COMGETTER(Product) (BSTR *aProduct)
233{
234 CheckComArgOutPointerValid(aProduct);
235
236 AutoCaller autoCaller(this);
237 if (FAILED(autoCaller.rc())) return autoCaller.rc();
238
239 /* this is const, no need to lock */
240 mData.product.cloneTo(aProduct);
241
242 return S_OK;
243}
244
245STDMETHODIMP RemoteUSBDevice::COMGETTER(SerialNumber) (BSTR *aSerialNumber)
246{
247 CheckComArgOutPointerValid(aSerialNumber);
248
249 AutoCaller autoCaller(this);
250 if (FAILED(autoCaller.rc())) return autoCaller.rc();
251
252 /* this is const, no need to lock */
253 mData.serialNumber.cloneTo(aSerialNumber);
254
255 return S_OK;
256}
257
258STDMETHODIMP RemoteUSBDevice::COMGETTER(Address) (BSTR *aAddress)
259{
260 CheckComArgOutPointerValid(aAddress);
261
262 AutoCaller autoCaller(this);
263 if (FAILED(autoCaller.rc())) return autoCaller.rc();
264
265 /* this is const, no need to lock */
266 mData.address.cloneTo(aAddress);
267
268 return S_OK;
269}
270
271STDMETHODIMP RemoteUSBDevice::COMGETTER(Port) (USHORT *aPort)
272{
273 CheckComArgOutPointerValid(aPort);
274
275 AutoCaller autoCaller(this);
276 if (FAILED(autoCaller.rc())) return autoCaller.rc();
277
278 /* this is const, no need to lock */
279 *aPort = mData.port;
280
281 return S_OK;
282}
283
284STDMETHODIMP RemoteUSBDevice::COMGETTER(Version) (USHORT *aVersion)
285{
286 CheckComArgOutPointerValid(aVersion);
287
288 AutoCaller autoCaller(this);
289 if (FAILED(autoCaller.rc())) return autoCaller.rc();
290
291 /* this is const, no need to lock */
292 *aVersion = mData.version;
293
294 return S_OK;
295}
296
297STDMETHODIMP RemoteUSBDevice::COMGETTER(PortVersion) (USHORT *aPortVersion)
298{
299 CheckComArgOutPointerValid(aPortVersion);
300
301 AutoCaller autoCaller(this);
302 if (FAILED(autoCaller.rc())) return autoCaller.rc();
303
304 /* this is const, no need to lock */
305 *aPortVersion = mData.portVersion;
306
307 return S_OK;
308}
309
310STDMETHODIMP RemoteUSBDevice::COMGETTER(Speed) (USBConnectionSpeed_T *aSpeed)
311{
312 CheckComArgOutPointerValid(aSpeed);
313
314 AutoCaller autoCaller(this);
315 if (FAILED(autoCaller.rc())) return autoCaller.rc();
316
317 /* this is const, no need to lock */
318 *aSpeed = mData.speed;
319
320 return S_OK;
321}
322
323STDMETHODIMP RemoteUSBDevice::COMGETTER(Remote) (BOOL *aRemote)
324{
325 CheckComArgOutPointerValid(aRemote);
326
327 AutoCaller autoCaller(this);
328 if (FAILED(autoCaller.rc())) return autoCaller.rc();
329
330 /* RemoteUSBDevice is always remote. */
331 /* this is const, no need to lock */
332 *aRemote = TRUE;
333
334 return S_OK;
335}
336
337// IHostUSBDevice properties
338////////////////////////////////////////////////////////////////////////////////
339
340STDMETHODIMP RemoteUSBDevice::COMGETTER(State) (USBDeviceState_T *aState)
341{
342 CheckComArgOutPointerValid(aState);
343
344 AutoCaller autoCaller(this);
345 if (FAILED(autoCaller.rc())) return autoCaller.rc();
346
347 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
348
349 *aState = mData.state;
350
351 return S_OK;
352}
353
354// public methods only for internal purposes
355////////////////////////////////////////////////////////////////////////////////
356/* vi: set tabstop=4 shiftwidth=4 expandtab: */
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