VirtualBox

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

Last change on this file since 26270 was 25860, checked in by vboxsync, 15 years ago

Main: cleanup: get rid of VirtualBoxBaseProto, move AutoCaller*/*Span* classes out of VirtualBoxBaseProto class scope and into separate header; move CombinedProgress into separate header (it's only used by Console any more)

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