VirtualBox

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

Last change on this file since 28851 was 28800, checked in by vboxsync, 15 years ago

Automated rebranding to Oracle copyright/license strings via filemuncher

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