VirtualBox

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

Last change on this file since 14290 was 13659, checked in by vboxsync, 16 years ago

Main: Moved last USB classes to the new locking scheme.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 7.9 KB
Line 
1/* $Id: RemoteUSBDeviceImpl.cpp 13659 2008-10-29 15:45:03Z 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_UNEXPECTED);
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) (GUIDPARAMOUT aId)
135{
136 if (!aId)
137 return E_INVALIDARG;
138
139 AutoCaller autoCaller (this);
140 CheckComRCReturnRC (autoCaller.rc());
141
142 /* this is const, no need to lock */
143 mData.id.cloneTo (aId);
144
145 return S_OK;
146}
147
148STDMETHODIMP RemoteUSBDevice::COMGETTER(VendorId) (USHORT *aVendorId)
149{
150 if (!aVendorId)
151 return E_INVALIDARG;
152
153 AutoCaller autoCaller (this);
154 CheckComRCReturnRC (autoCaller.rc());
155
156 /* this is const, no need to lock */
157 *aVendorId = mData.vendorId;
158
159 return S_OK;
160}
161
162STDMETHODIMP RemoteUSBDevice::COMGETTER(ProductId) (USHORT *aProductId)
163{
164 if (!aProductId)
165 return E_INVALIDARG;
166
167 AutoCaller autoCaller (this);
168 CheckComRCReturnRC (autoCaller.rc());
169
170 /* this is const, no need to lock */
171 *aProductId = mData.productId;
172
173 return S_OK;
174}
175
176STDMETHODIMP RemoteUSBDevice::COMGETTER(Revision) (USHORT *aRevision)
177{
178 if (!aRevision)
179 return E_INVALIDARG;
180
181 AutoCaller autoCaller (this);
182 CheckComRCReturnRC (autoCaller.rc());
183
184 /* this is const, no need to lock */
185 *aRevision = mData.revision;
186
187 return S_OK;
188}
189
190STDMETHODIMP RemoteUSBDevice::COMGETTER(Manufacturer) (BSTR *aManufacturer)
191{
192 if (!aManufacturer)
193 return E_INVALIDARG;
194
195 AutoCaller autoCaller (this);
196 CheckComRCReturnRC (autoCaller.rc());
197
198 /* this is const, no need to lock */
199 mData.manufacturer.cloneTo (aManufacturer);
200
201 return S_OK;
202}
203
204STDMETHODIMP RemoteUSBDevice::COMGETTER(Product) (BSTR *aProduct)
205{
206 if (!aProduct)
207 return E_INVALIDARG;
208
209 AutoCaller autoCaller (this);
210 CheckComRCReturnRC (autoCaller.rc());
211
212 /* this is const, no need to lock */
213 mData.product.cloneTo (aProduct);
214
215 return S_OK;
216}
217
218STDMETHODIMP RemoteUSBDevice::COMGETTER(SerialNumber) (BSTR *aSerialNumber)
219{
220 if (!aSerialNumber)
221 return E_INVALIDARG;
222
223 AutoCaller autoCaller (this);
224 CheckComRCReturnRC (autoCaller.rc());
225
226 /* this is const, no need to lock */
227 mData.serialNumber.cloneTo (aSerialNumber);
228
229 return S_OK;
230}
231
232STDMETHODIMP RemoteUSBDevice::COMGETTER(Address) (BSTR *aAddress)
233{
234 if (!aAddress)
235 return E_INVALIDARG;
236
237 AutoCaller autoCaller (this);
238 CheckComRCReturnRC (autoCaller.rc());
239
240 /* this is const, no need to lock */
241 mData.address.cloneTo (aAddress);
242
243 return S_OK;
244}
245
246STDMETHODIMP RemoteUSBDevice::COMGETTER(Port) (USHORT *aPort)
247{
248 if (!aPort)
249 return E_INVALIDARG;
250
251 AutoCaller autoCaller (this);
252 CheckComRCReturnRC (autoCaller.rc());
253
254 /* this is const, no need to lock */
255 *aPort = mData.port;
256
257 return S_OK;
258}
259
260STDMETHODIMP RemoteUSBDevice::COMGETTER(Version) (USHORT *aVersion)
261{
262 if (!aVersion)
263 return E_INVALIDARG;
264
265 AutoCaller autoCaller (this);
266 CheckComRCReturnRC (autoCaller.rc());
267
268 /* this is const, no need to lock */
269 *aVersion = mData.version;
270
271 return S_OK;
272}
273
274STDMETHODIMP RemoteUSBDevice::COMGETTER(PortVersion) (USHORT *aPortVersion)
275{
276 if (!aPortVersion)
277 return E_INVALIDARG;
278
279 AutoCaller autoCaller (this);
280 CheckComRCReturnRC (autoCaller.rc());
281
282 /* this is const, no need to lock */
283 *aPortVersion = mData.portVersion;
284
285 return S_OK;
286}
287
288STDMETHODIMP RemoteUSBDevice::COMGETTER(Remote) (BOOL *aRemote)
289{
290 if (!aRemote)
291 return E_INVALIDARG;
292
293 AutoCaller autoCaller (this);
294 CheckComRCReturnRC (autoCaller.rc());
295
296 /* RemoteUSBDevice is always remote. */
297 /* this is const, no need to lock */
298 *aRemote = TRUE;
299
300 return S_OK;
301}
302
303// IHostUSBDevice properties
304/////////////////////////////////////////////////////////////////////////////
305
306STDMETHODIMP RemoteUSBDevice::COMGETTER(State) (USBDeviceState_T *aState)
307{
308 if (!aState)
309 return E_POINTER;
310
311 AutoCaller autoCaller (this);
312 CheckComRCReturnRC (autoCaller.rc());
313
314 AutoReadLock alock (this);
315
316 *aState = mData.state;
317
318 return S_OK;
319}
320
321// public methods only for internal purposes
322////////////////////////////////////////////////////////////////////////////////
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