VirtualBox

source: vbox/trunk/src/VBox/Main/RemoteUSBDeviceImpl.cpp@ 25414

Last change on this file since 25414 was 25310, checked in by vboxsync, 14 years ago

Main: lock validator, first batch: implement per-thread stack to trace locking (disabled by default, use VBOX_WITH_LOCK_VALIDATOR, but that WILL FAIL presently)

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 8.0 KB
Line 
1/* $Id: RemoteUSBDeviceImpl.cpp 25310 2009-12-10 17:06:44Z 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 Sun Microsystems, Inc.
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 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
21 * Clara, CA 95054 USA or visit http://www.sun.com if you need
22 * additional information or have any questions.
23 */
24
25#include "RemoteUSBDeviceImpl.h"
26#include "Logging.h"
27
28#include <VBox/err.h>
29
30#include <VBox/vrdpapi.h>
31#include <VBox/vrdpusb.h>
32
33// constructor / destructor
34/////////////////////////////////////////////////////////////////////////////
35
36DEFINE_EMPTY_CTOR_DTOR (RemoteUSBDevice)
37
38HRESULT RemoteUSBDevice::FinalConstruct()
39{
40 return S_OK;
41}
42
43void RemoteUSBDevice::FinalRelease()
44{
45 uninit();
46}
47
48// public initializer/uninitializer for internal purposes only
49/////////////////////////////////////////////////////////////////////////////
50
51/** @todo (sunlover) REMOTE_USB Device states. */
52
53/**
54 * Initializes the remote USB device object.
55 */
56HRESULT RemoteUSBDevice::init (uint32_t u32ClientId, VRDPUSBDEVICEDESC *pDevDesc)
57{
58 LogFlowThisFunc(("u32ClientId=%d,pDevDesc=%p\n", u32ClientId, pDevDesc));
59
60 /* Enclose the state transition NotReady->InInit->Ready */
61 AutoInitSpan autoInitSpan(this);
62 AssertReturn(autoInitSpan.isOk(), E_FAIL);
63
64 unconst(mData.id).create();
65
66 unconst(mData.vendorId) = pDevDesc->idVendor;
67 unconst(mData.productId) = pDevDesc->idProduct;
68 unconst(mData.revision) = pDevDesc->bcdRev;
69
70 unconst(mData.manufacturer) = pDevDesc->oManufacturer? (char *)pDevDesc + pDevDesc->oManufacturer: "";
71 unconst(mData.product) = pDevDesc->oProduct? (char *)pDevDesc + pDevDesc->oProduct: "";
72 unconst(mData.serialNumber) = pDevDesc->oSerialNumber? (char *)pDevDesc + pDevDesc->oSerialNumber: "";
73
74 char id[64];
75 RTStrPrintf(id, sizeof (id), REMOTE_USB_BACKEND_PREFIX_S "0x%08X&0x%08X", pDevDesc->id, u32ClientId);
76 unconst(mData.address) = id;
77
78 unconst(mData.port) = pDevDesc->idPort;
79 unconst(mData.version) = pDevDesc->bcdUSB >> 8;
80 unconst(mData.portVersion) = mData.version; /** @todo fix this */
81
82 mData.state = USBDeviceState_Available;
83
84 mData.dirty = false;
85 unconst(mData.devId) = pDevDesc->id;
86
87 unconst(mData.clientId) = u32ClientId;
88
89 /* Confirm a successful initialization */
90 autoInitSpan.setSucceeded();
91
92 return S_OK;
93}
94
95
96/**
97 * Uninitializes the instance and sets the ready flag to FALSE.
98 * Called either from FinalRelease() or by the parent when it gets destroyed.
99 */
100void RemoteUSBDevice::uninit()
101{
102 LogFlowThisFunc(("\n"));
103
104 /* Enclose the state transition Ready->InUninit->NotReady */
105 AutoUninitSpan autoUninitSpan(this);
106 if (autoUninitSpan.uninitDone())
107 return;
108
109 unconst(mData.id).clear();
110
111 unconst(mData.vendorId) = 0;
112 unconst(mData.productId) = 0;
113 unconst(mData.revision) = 0;
114
115 unconst(mData.manufacturer).setNull();
116 unconst(mData.product).setNull();
117 unconst(mData.serialNumber).setNull();
118
119 unconst(mData.address).setNull();
120
121 unconst(mData.port) = 0;
122 unconst(mData.version) = 1;
123 unconst(mData.portVersion) = 1;
124
125 unconst(mData.dirty) = FALSE;
126
127 unconst(mData.devId) = 0;
128 unconst(mData.clientId) = 0;
129}
130
131// IUSBDevice properties
132/////////////////////////////////////////////////////////////////////////////
133
134STDMETHODIMP RemoteUSBDevice::COMGETTER(Id) (BSTR *aId)
135{
136 CheckComArgOutPointerValid(aId);
137
138 AutoCaller autoCaller(this);
139 if (FAILED(autoCaller.rc())) return autoCaller.rc();
140
141 /* this is const, no need to lock */
142 Bstr(mData.id).cloneTo(aId);
143
144 return S_OK;
145}
146
147STDMETHODIMP RemoteUSBDevice::COMGETTER(VendorId) (USHORT *aVendorId)
148{
149 CheckComArgOutPointerValid(aVendorId);
150
151 AutoCaller autoCaller(this);
152 if (FAILED(autoCaller.rc())) return autoCaller.rc();
153
154 /* this is const, no need to lock */
155 *aVendorId = mData.vendorId;
156
157 return S_OK;
158}
159
160STDMETHODIMP RemoteUSBDevice::COMGETTER(ProductId) (USHORT *aProductId)
161{
162 CheckComArgOutPointerValid(aProductId);
163
164 AutoCaller autoCaller(this);
165 if (FAILED(autoCaller.rc())) return autoCaller.rc();
166
167 /* this is const, no need to lock */
168 *aProductId = mData.productId;
169
170 return S_OK;
171}
172
173STDMETHODIMP RemoteUSBDevice::COMGETTER(Revision) (USHORT *aRevision)
174{
175 CheckComArgOutPointerValid(aRevision);
176
177 AutoCaller autoCaller(this);
178 if (FAILED(autoCaller.rc())) return autoCaller.rc();
179
180 /* this is const, no need to lock */
181 *aRevision = mData.revision;
182
183 return S_OK;
184}
185
186STDMETHODIMP RemoteUSBDevice::COMGETTER(Manufacturer) (BSTR *aManufacturer)
187{
188 CheckComArgOutPointerValid(aManufacturer);
189
190 AutoCaller autoCaller(this);
191 if (FAILED(autoCaller.rc())) return autoCaller.rc();
192
193 /* this is const, no need to lock */
194 mData.manufacturer.cloneTo(aManufacturer);
195
196 return S_OK;
197}
198
199STDMETHODIMP RemoteUSBDevice::COMGETTER(Product) (BSTR *aProduct)
200{
201 CheckComArgOutPointerValid(aProduct);
202
203 AutoCaller autoCaller(this);
204 if (FAILED(autoCaller.rc())) return autoCaller.rc();
205
206 /* this is const, no need to lock */
207 mData.product.cloneTo(aProduct);
208
209 return S_OK;
210}
211
212STDMETHODIMP RemoteUSBDevice::COMGETTER(SerialNumber) (BSTR *aSerialNumber)
213{
214 CheckComArgOutPointerValid(aSerialNumber);
215
216 AutoCaller autoCaller(this);
217 if (FAILED(autoCaller.rc())) return autoCaller.rc();
218
219 /* this is const, no need to lock */
220 mData.serialNumber.cloneTo(aSerialNumber);
221
222 return S_OK;
223}
224
225STDMETHODIMP RemoteUSBDevice::COMGETTER(Address) (BSTR *aAddress)
226{
227 CheckComArgOutPointerValid(aAddress);
228
229 AutoCaller autoCaller(this);
230 if (FAILED(autoCaller.rc())) return autoCaller.rc();
231
232 /* this is const, no need to lock */
233 mData.address.cloneTo(aAddress);
234
235 return S_OK;
236}
237
238STDMETHODIMP RemoteUSBDevice::COMGETTER(Port) (USHORT *aPort)
239{
240 CheckComArgOutPointerValid(aPort);
241
242 AutoCaller autoCaller(this);
243 if (FAILED(autoCaller.rc())) return autoCaller.rc();
244
245 /* this is const, no need to lock */
246 *aPort = mData.port;
247
248 return S_OK;
249}
250
251STDMETHODIMP RemoteUSBDevice::COMGETTER(Version) (USHORT *aVersion)
252{
253 CheckComArgOutPointerValid(aVersion);
254
255 AutoCaller autoCaller(this);
256 if (FAILED(autoCaller.rc())) return autoCaller.rc();
257
258 /* this is const, no need to lock */
259 *aVersion = mData.version;
260
261 return S_OK;
262}
263
264STDMETHODIMP RemoteUSBDevice::COMGETTER(PortVersion) (USHORT *aPortVersion)
265{
266 CheckComArgOutPointerValid(aPortVersion);
267
268 AutoCaller autoCaller(this);
269 if (FAILED(autoCaller.rc())) return autoCaller.rc();
270
271 /* this is const, no need to lock */
272 *aPortVersion = mData.portVersion;
273
274 return S_OK;
275}
276
277STDMETHODIMP RemoteUSBDevice::COMGETTER(Remote) (BOOL *aRemote)
278{
279 CheckComArgOutPointerValid(aRemote);
280
281 AutoCaller autoCaller(this);
282 if (FAILED(autoCaller.rc())) return autoCaller.rc();
283
284 /* RemoteUSBDevice is always remote. */
285 /* this is const, no need to lock */
286 *aRemote = TRUE;
287
288 return S_OK;
289}
290
291// IHostUSBDevice properties
292////////////////////////////////////////////////////////////////////////////////
293
294STDMETHODIMP RemoteUSBDevice::COMGETTER(State) (USBDeviceState_T *aState)
295{
296 CheckComArgOutPointerValid(aState);
297
298 AutoCaller autoCaller(this);
299 if (FAILED(autoCaller.rc())) return autoCaller.rc();
300
301 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
302
303 *aState = mData.state;
304
305 return S_OK;
306}
307
308// public methods only for internal purposes
309////////////////////////////////////////////////////////////////////////////////
310/* vi: set tabstop=4 shiftwidth=4 expandtab: */
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use