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
RevLine 
[13659]1/* $Id: RemoteUSBDeviceImpl.cpp 25310 2009-12-10 17:06:44Z vboxsync $ */
2
[1]3/** @file
4 *
5 * VirtualBox IHostUSBDevice COM interface implementation
6 * for remote (VRDP) USB devices
7 */
8
9/*
[13659]10 * Copyright (C) 2006-2008 Sun Microsystems, Inc.
[1]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
[5999]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.
[8155]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.
[1]23 */
24
25#include "RemoteUSBDeviceImpl.h"
26#include "Logging.h"
27
28#include <VBox/err.h>
29
[13659]30#include <VBox/vrdpapi.h>
[1]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{
[13659]45 uninit();
[1]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{
[21878]58 LogFlowThisFunc(("u32ClientId=%d,pDevDesc=%p\n", u32ClientId, pDevDesc));
[1]59
[13659]60 /* Enclose the state transition NotReady->InInit->Ready */
[21878]61 AutoInitSpan autoInitSpan(this);
62 AssertReturn(autoInitSpan.isOk(), E_FAIL);
[1]63
[21878]64 unconst(mData.id).create();
[1]65
[21878]66 unconst(mData.vendorId) = pDevDesc->idVendor;
67 unconst(mData.productId) = pDevDesc->idProduct;
68 unconst(mData.revision) = pDevDesc->bcdRev;
[1]69
[21878]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: "";
[1]73
74 char id[64];
75 RTStrPrintf(id, sizeof (id), REMOTE_USB_BACKEND_PREFIX_S "0x%08X&0x%08X", pDevDesc->id, u32ClientId);
[21878]76 unconst(mData.address) = id;
[1]77
[21878]78 unconst(mData.port) = pDevDesc->idPort;
79 unconst(mData.version) = pDevDesc->bcdUSB >> 8;
80 unconst(mData.portVersion) = mData.version; /** @todo fix this */
[1]81
[13659]82 mData.state = USBDeviceState_Available;
[1]83
[13659]84 mData.dirty = false;
[21878]85 unconst(mData.devId) = pDevDesc->id;
[1]86
[21878]87 unconst(mData.clientId) = u32ClientId;
[1]88
[13659]89 /* Confirm a successful initialization */
90 autoInitSpan.setSucceeded();
91
[1]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{
[21878]102 LogFlowThisFunc(("\n"));
[1]103
[13659]104 /* Enclose the state transition Ready->InUninit->NotReady */
[21878]105 AutoUninitSpan autoUninitSpan(this);
[13659]106 if (autoUninitSpan.uninitDone())
107 return;
[1]108
[21878]109 unconst(mData.id).clear();
[13659]110
[21878]111 unconst(mData.vendorId) = 0;
112 unconst(mData.productId) = 0;
113 unconst(mData.revision) = 0;
[13659]114
[21878]115 unconst(mData.manufacturer).setNull();
116 unconst(mData.product).setNull();
117 unconst(mData.serialNumber).setNull();
[13659]118
[21878]119 unconst(mData.address).setNull();
[13659]120
[21878]121 unconst(mData.port) = 0;
122 unconst(mData.version) = 1;
123 unconst(mData.portVersion) = 1;
[13659]124
[21878]125 unconst(mData.dirty) = FALSE;
[13659]126
[21878]127 unconst(mData.devId) = 0;
128 unconst(mData.clientId) = 0;
[1]129}
130
131// IUSBDevice properties
132/////////////////////////////////////////////////////////////////////////////
133
[19239]134STDMETHODIMP RemoteUSBDevice::COMGETTER(Id) (BSTR *aId)
[1]135{
[14972]136 CheckComArgOutPointerValid(aId);
[1]137
[21878]138 AutoCaller autoCaller(this);
[25149]139 if (FAILED(autoCaller.rc())) return autoCaller.rc();
[1]140
[13659]141 /* this is const, no need to lock */
[21878]142 Bstr(mData.id).cloneTo(aId);
[13659]143
[1]144 return S_OK;
145}
146
147STDMETHODIMP RemoteUSBDevice::COMGETTER(VendorId) (USHORT *aVendorId)
148{
[14972]149 CheckComArgOutPointerValid(aVendorId);
[1]150
[21878]151 AutoCaller autoCaller(this);
[25149]152 if (FAILED(autoCaller.rc())) return autoCaller.rc();
[1]153
[13659]154 /* this is const, no need to lock */
155 *aVendorId = mData.vendorId;
156
[1]157 return S_OK;
158}
159
160STDMETHODIMP RemoteUSBDevice::COMGETTER(ProductId) (USHORT *aProductId)
161{
[14972]162 CheckComArgOutPointerValid(aProductId);
[1]163
[21878]164 AutoCaller autoCaller(this);
[25149]165 if (FAILED(autoCaller.rc())) return autoCaller.rc();
[1]166
[13659]167 /* this is const, no need to lock */
168 *aProductId = mData.productId;
169
[1]170 return S_OK;
171}
172
173STDMETHODIMP RemoteUSBDevice::COMGETTER(Revision) (USHORT *aRevision)
174{
[14972]175 CheckComArgOutPointerValid(aRevision);
[1]176
[21878]177 AutoCaller autoCaller(this);
[25149]178 if (FAILED(autoCaller.rc())) return autoCaller.rc();
[1]179
[13659]180 /* this is const, no need to lock */
181 *aRevision = mData.revision;
182
[1]183 return S_OK;
184}
185
186STDMETHODIMP RemoteUSBDevice::COMGETTER(Manufacturer) (BSTR *aManufacturer)
187{
[14972]188 CheckComArgOutPointerValid(aManufacturer);
[1]189
[21878]190 AutoCaller autoCaller(this);
[25149]191 if (FAILED(autoCaller.rc())) return autoCaller.rc();
[1]192
[13659]193 /* this is const, no need to lock */
[21878]194 mData.manufacturer.cloneTo(aManufacturer);
[13659]195
[1]196 return S_OK;
197}
198
199STDMETHODIMP RemoteUSBDevice::COMGETTER(Product) (BSTR *aProduct)
200{
[14972]201 CheckComArgOutPointerValid(aProduct);
[1]202
[21878]203 AutoCaller autoCaller(this);
[25149]204 if (FAILED(autoCaller.rc())) return autoCaller.rc();
[1]205
[13659]206 /* this is const, no need to lock */
[21878]207 mData.product.cloneTo(aProduct);
[13659]208
[1]209 return S_OK;
210}
211
212STDMETHODIMP RemoteUSBDevice::COMGETTER(SerialNumber) (BSTR *aSerialNumber)
213{
[14972]214 CheckComArgOutPointerValid(aSerialNumber);
[1]215
[21878]216 AutoCaller autoCaller(this);
[25149]217 if (FAILED(autoCaller.rc())) return autoCaller.rc();
[1]218
[13659]219 /* this is const, no need to lock */
[21878]220 mData.serialNumber.cloneTo(aSerialNumber);
[13659]221
[1]222 return S_OK;
223}
224
225STDMETHODIMP RemoteUSBDevice::COMGETTER(Address) (BSTR *aAddress)
226{
[14972]227 CheckComArgOutPointerValid(aAddress);
[1]228
[21878]229 AutoCaller autoCaller(this);
[25149]230 if (FAILED(autoCaller.rc())) return autoCaller.rc();
[1]231
[13659]232 /* this is const, no need to lock */
[21878]233 mData.address.cloneTo(aAddress);
[13659]234
[1]235 return S_OK;
236}
237
238STDMETHODIMP RemoteUSBDevice::COMGETTER(Port) (USHORT *aPort)
239{
[14972]240 CheckComArgOutPointerValid(aPort);
[1]241
[21878]242 AutoCaller autoCaller(this);
[25149]243 if (FAILED(autoCaller.rc())) return autoCaller.rc();
[1]244
[13659]245 /* this is const, no need to lock */
246 *aPort = mData.port;
247
[1]248 return S_OK;
249}
250
[5528]251STDMETHODIMP RemoteUSBDevice::COMGETTER(Version) (USHORT *aVersion)
252{
[14972]253 CheckComArgOutPointerValid(aVersion);
[5528]254
[21878]255 AutoCaller autoCaller(this);
[25149]256 if (FAILED(autoCaller.rc())) return autoCaller.rc();
[5528]257
[13659]258 /* this is const, no need to lock */
259 *aVersion = mData.version;
260
[5528]261 return S_OK;
262}
263
264STDMETHODIMP RemoteUSBDevice::COMGETTER(PortVersion) (USHORT *aPortVersion)
265{
[14972]266 CheckComArgOutPointerValid(aPortVersion);
[5528]267
[21878]268 AutoCaller autoCaller(this);
[25149]269 if (FAILED(autoCaller.rc())) return autoCaller.rc();
[5528]270
[13659]271 /* this is const, no need to lock */
272 *aPortVersion = mData.portVersion;
273
[5528]274 return S_OK;
275}
276
[1]277STDMETHODIMP RemoteUSBDevice::COMGETTER(Remote) (BOOL *aRemote)
278{
[14972]279 CheckComArgOutPointerValid(aRemote);
[1]280
[21878]281 AutoCaller autoCaller(this);
[25149]282 if (FAILED(autoCaller.rc())) return autoCaller.rc();
[1]283
284 /* RemoteUSBDevice is always remote. */
[13659]285 /* this is const, no need to lock */
[1]286 *aRemote = TRUE;
[13659]287
[1]288 return S_OK;
289}
290
291// IHostUSBDevice properties
[14972]292////////////////////////////////////////////////////////////////////////////////
[1]293
294STDMETHODIMP RemoteUSBDevice::COMGETTER(State) (USBDeviceState_T *aState)
295{
[14972]296 CheckComArgOutPointerValid(aState);
[1]297
[21878]298 AutoCaller autoCaller(this);
[25149]299 if (FAILED(autoCaller.rc())) return autoCaller.rc();
[1]300
[25310]301 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
[13659]302
303 *aState = mData.state;
304
[1]305 return S_OK;
306}
307
308// public methods only for internal purposes
309////////////////////////////////////////////////////////////////////////////////
[14772]310/* vi: set tabstop=4 shiftwidth=4 expandtab: */
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use