VirtualBox

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

Last change on this file since 39895 was 38911, checked in by vboxsync, 13 years ago

RemoteUSB: support the extended device description.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 8.5 KB
Line 
1/* $Id: RemoteUSBDeviceImpl.cpp 38911 2011-09-30 09:52:40Z vboxsync $ */
2
3/** @file
4 *
5 * VirtualBox IHostUSBDevice COM interface implementation
6 * for remote (VRDP) USB devices
7 */
8
9/*
10 * Copyright (C) 2006-2008 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 break;
92
93 case VRDE_USBDEVICESPEED_HIGH:
94 case VRDE_USBDEVICESPEED_VARIABLE:
95 case VRDE_USBDEVICESPEED_SUPERSPEED:
96 unconst(mData.portVersion) = 2;
97 break;
98 }
99 }
100 else
101 {
102 unconst(mData.portVersion) = mData.version;
103 }
104
105 mData.state = USBDeviceState_Available;
106
107 mData.dirty = false;
108 unconst(mData.devId) = pDevDesc->id;
109
110 unconst(mData.clientId) = u32ClientId;
111
112 /* Confirm a successful initialization */
113 autoInitSpan.setSucceeded();
114
115 return S_OK;
116}
117
118
119/**
120 * Uninitializes the instance and sets the ready flag to FALSE.
121 * Called either from FinalRelease() or by the parent when it gets destroyed.
122 */
123void RemoteUSBDevice::uninit()
124{
125 LogFlowThisFunc(("\n"));
126
127 /* Enclose the state transition Ready->InUninit->NotReady */
128 AutoUninitSpan autoUninitSpan(this);
129 if (autoUninitSpan.uninitDone())
130 return;
131
132 unconst(mData.id).clear();
133
134 unconst(mData.vendorId) = 0;
135 unconst(mData.productId) = 0;
136 unconst(mData.revision) = 0;
137
138 unconst(mData.manufacturer).setNull();
139 unconst(mData.product).setNull();
140 unconst(mData.serialNumber).setNull();
141
142 unconst(mData.address).setNull();
143
144 unconst(mData.port) = 0;
145 unconst(mData.version) = 1;
146 unconst(mData.portVersion) = 1;
147
148 unconst(mData.dirty) = FALSE;
149
150 unconst(mData.devId) = 0;
151 unconst(mData.clientId) = 0;
152}
153
154// IUSBDevice properties
155/////////////////////////////////////////////////////////////////////////////
156
157STDMETHODIMP RemoteUSBDevice::COMGETTER(Id) (BSTR *aId)
158{
159 CheckComArgOutPointerValid(aId);
160
161 AutoCaller autoCaller(this);
162 if (FAILED(autoCaller.rc())) return autoCaller.rc();
163
164 /* this is const, no need to lock */
165 mData.id.toUtf16().detachTo(aId);
166
167 return S_OK;
168}
169
170STDMETHODIMP RemoteUSBDevice::COMGETTER(VendorId) (USHORT *aVendorId)
171{
172 CheckComArgOutPointerValid(aVendorId);
173
174 AutoCaller autoCaller(this);
175 if (FAILED(autoCaller.rc())) return autoCaller.rc();
176
177 /* this is const, no need to lock */
178 *aVendorId = mData.vendorId;
179
180 return S_OK;
181}
182
183STDMETHODIMP RemoteUSBDevice::COMGETTER(ProductId) (USHORT *aProductId)
184{
185 CheckComArgOutPointerValid(aProductId);
186
187 AutoCaller autoCaller(this);
188 if (FAILED(autoCaller.rc())) return autoCaller.rc();
189
190 /* this is const, no need to lock */
191 *aProductId = mData.productId;
192
193 return S_OK;
194}
195
196STDMETHODIMP RemoteUSBDevice::COMGETTER(Revision) (USHORT *aRevision)
197{
198 CheckComArgOutPointerValid(aRevision);
199
200 AutoCaller autoCaller(this);
201 if (FAILED(autoCaller.rc())) return autoCaller.rc();
202
203 /* this is const, no need to lock */
204 *aRevision = mData.revision;
205
206 return S_OK;
207}
208
209STDMETHODIMP RemoteUSBDevice::COMGETTER(Manufacturer) (BSTR *aManufacturer)
210{
211 CheckComArgOutPointerValid(aManufacturer);
212
213 AutoCaller autoCaller(this);
214 if (FAILED(autoCaller.rc())) return autoCaller.rc();
215
216 /* this is const, no need to lock */
217 mData.manufacturer.cloneTo(aManufacturer);
218
219 return S_OK;
220}
221
222STDMETHODIMP RemoteUSBDevice::COMGETTER(Product) (BSTR *aProduct)
223{
224 CheckComArgOutPointerValid(aProduct);
225
226 AutoCaller autoCaller(this);
227 if (FAILED(autoCaller.rc())) return autoCaller.rc();
228
229 /* this is const, no need to lock */
230 mData.product.cloneTo(aProduct);
231
232 return S_OK;
233}
234
235STDMETHODIMP RemoteUSBDevice::COMGETTER(SerialNumber) (BSTR *aSerialNumber)
236{
237 CheckComArgOutPointerValid(aSerialNumber);
238
239 AutoCaller autoCaller(this);
240 if (FAILED(autoCaller.rc())) return autoCaller.rc();
241
242 /* this is const, no need to lock */
243 mData.serialNumber.cloneTo(aSerialNumber);
244
245 return S_OK;
246}
247
248STDMETHODIMP RemoteUSBDevice::COMGETTER(Address) (BSTR *aAddress)
249{
250 CheckComArgOutPointerValid(aAddress);
251
252 AutoCaller autoCaller(this);
253 if (FAILED(autoCaller.rc())) return autoCaller.rc();
254
255 /* this is const, no need to lock */
256 mData.address.cloneTo(aAddress);
257
258 return S_OK;
259}
260
261STDMETHODIMP RemoteUSBDevice::COMGETTER(Port) (USHORT *aPort)
262{
263 CheckComArgOutPointerValid(aPort);
264
265 AutoCaller autoCaller(this);
266 if (FAILED(autoCaller.rc())) return autoCaller.rc();
267
268 /* this is const, no need to lock */
269 *aPort = mData.port;
270
271 return S_OK;
272}
273
274STDMETHODIMP RemoteUSBDevice::COMGETTER(Version) (USHORT *aVersion)
275{
276 CheckComArgOutPointerValid(aVersion);
277
278 AutoCaller autoCaller(this);
279 if (FAILED(autoCaller.rc())) return autoCaller.rc();
280
281 /* this is const, no need to lock */
282 *aVersion = mData.version;
283
284 return S_OK;
285}
286
287STDMETHODIMP RemoteUSBDevice::COMGETTER(PortVersion) (USHORT *aPortVersion)
288{
289 CheckComArgOutPointerValid(aPortVersion);
290
291 AutoCaller autoCaller(this);
292 if (FAILED(autoCaller.rc())) return autoCaller.rc();
293
294 /* this is const, no need to lock */
295 *aPortVersion = mData.portVersion;
296
297 return S_OK;
298}
299
300STDMETHODIMP RemoteUSBDevice::COMGETTER(Remote) (BOOL *aRemote)
301{
302 CheckComArgOutPointerValid(aRemote);
303
304 AutoCaller autoCaller(this);
305 if (FAILED(autoCaller.rc())) return autoCaller.rc();
306
307 /* RemoteUSBDevice is always remote. */
308 /* this is const, no need to lock */
309 *aRemote = TRUE;
310
311 return S_OK;
312}
313
314// IHostUSBDevice properties
315////////////////////////////////////////////////////////////////////////////////
316
317STDMETHODIMP RemoteUSBDevice::COMGETTER(State) (USBDeviceState_T *aState)
318{
319 CheckComArgOutPointerValid(aState);
320
321 AutoCaller autoCaller(this);
322 if (FAILED(autoCaller.rc())) return autoCaller.rc();
323
324 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
325
326 *aState = mData.state;
327
328 return S_OK;
329}
330
331// public methods only for internal purposes
332////////////////////////////////////////////////////////////////////////////////
333/* 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