VirtualBox

source: vbox/trunk/src/VBox/Main/src-client/RemoteUSBDeviceImpl.cpp@ 66512

Last change on this file since 66512 was 62485, checked in by vboxsync, 8 years ago

(C) 2016

  • 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 62485 2016-07-22 18:36:43Z vboxsync $ */
2
3/** @file
4 *
5 * VirtualBox IHostUSBDevice COM interface implementation
6 * for remote (VRDP) USB devices
7 */
8
9/*
10 * Copyright (C) 2006-2016 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 <iprt/cpp/utils.h>
27
28#include <VBox/err.h>
29
30#include <VBox/RemoteDesktop/VRDE.h>
31#include <VBox/vrdpusb.h>
32
33// constructor / destructor
34/////////////////////////////////////////////////////////////////////////////
35
36DEFINE_EMPTY_CTOR_DTOR(RemoteUSBDevice)
37
38HRESULT RemoteUSBDevice::FinalConstruct()
39{
40 return BaseFinalConstruct();
41}
42
43void RemoteUSBDevice::FinalRelease()
44{
45 uninit();
46 BaseFinalRelease();
47}
48
49// public initializer/uninitializer for internal purposes only
50/////////////////////////////////////////////////////////////////////////////
51
52/** @todo (sunlover) REMOTE_USB Device states. */
53
54/**
55 * Initializes the remote USB device object.
56 */
57HRESULT RemoteUSBDevice::init(uint32_t u32ClientId, VRDEUSBDEVICEDESC *pDevDesc, bool fDescExt)
58{
59 LogFlowThisFunc(("u32ClientId=%d,pDevDesc=%p\n", u32ClientId, pDevDesc));
60
61 /* Enclose the state transition NotReady->InInit->Ready */
62 AutoInitSpan autoInitSpan(this);
63 AssertReturn(autoInitSpan.isOk(), E_FAIL);
64
65 unconst(mData.id).create();
66
67 unconst(mData.vendorId) = pDevDesc->idVendor;
68 unconst(mData.productId) = pDevDesc->idProduct;
69 unconst(mData.revision) = pDevDesc->bcdRev;
70
71 unconst(mData.manufacturer) = pDevDesc->oManufacturer ? (char *)pDevDesc + pDevDesc->oManufacturer : "";
72 unconst(mData.product) = pDevDesc->oProduct ? (char *)pDevDesc + pDevDesc->oProduct : "";
73 unconst(mData.serialNumber) = pDevDesc->oSerialNumber ? (char *)pDevDesc + pDevDesc->oSerialNumber : "";
74
75 char id[64];
76 RTStrPrintf(id, sizeof(id), REMOTE_USB_BACKEND_PREFIX_S "0x%08X&0x%08X", pDevDesc->id, u32ClientId);
77 unconst(mData.address) = id;
78 unconst(mData.backend) = "vrdp";
79
80 unconst(mData.port) = pDevDesc->idPort;
81 unconst(mData.version) = (uint16_t)(pDevDesc->bcdUSB >> 8);
82 if (fDescExt)
83 {
84 VRDEUSBDEVICEDESCEXT *pDevDescExt = (VRDEUSBDEVICEDESCEXT *)pDevDesc;
85 switch (pDevDescExt->u16DeviceSpeed)
86 {
87 default:
88 case VRDE_USBDEVICESPEED_UNKNOWN:
89 case VRDE_USBDEVICESPEED_LOW:
90 case VRDE_USBDEVICESPEED_FULL:
91 unconst(mData.portVersion) = 1;
92 unconst(mData.speed) = USBConnectionSpeed_Full;
93 break;
94
95 case VRDE_USBDEVICESPEED_HIGH:
96 case VRDE_USBDEVICESPEED_VARIABLE:
97 unconst(mData.portVersion) = 2;
98 unconst(mData.speed) = USBConnectionSpeed_High;
99 break;
100
101 case VRDE_USBDEVICESPEED_SUPERSPEED:
102 unconst(mData.portVersion) = 3;
103 unconst(mData.speed) = USBConnectionSpeed_Super;
104 break;
105 }
106 }
107 else
108 {
109 unconst(mData.portVersion) = mData.version;
110 unconst(mData.speed) = mData.version == 3
111 ? (USBConnectionSpeed_T)USBConnectionSpeed_Super
112 : mData.version == 2 ? (USBConnectionSpeed_T)USBConnectionSpeed_High
113 : (USBConnectionSpeed_T)USBConnectionSpeed_Full;
114 }
115
116 mData.state = USBDeviceState_Available;
117
118 mData.dirty = false;
119 unconst(mData.devId) = (uint16_t)pDevDesc->id;
120
121 unconst(mData.clientId) = u32ClientId;
122
123 /* Confirm a successful initialization */
124 autoInitSpan.setSucceeded();
125
126 return S_OK;
127}
128
129
130/**
131 * Uninitializes the instance and sets the ready flag to FALSE.
132 * Called either from FinalRelease() or by the parent when it gets destroyed.
133 */
134void RemoteUSBDevice::uninit()
135{
136 LogFlowThisFunc(("\n"));
137
138 /* Enclose the state transition Ready->InUninit->NotReady */
139 AutoUninitSpan autoUninitSpan(this);
140 if (autoUninitSpan.uninitDone())
141 return;
142
143 unconst(mData.id).clear();
144
145 unconst(mData.vendorId) = 0;
146 unconst(mData.productId) = 0;
147 unconst(mData.revision) = 0;
148
149 unconst(mData.manufacturer).setNull();
150 unconst(mData.product).setNull();
151 unconst(mData.serialNumber).setNull();
152
153 unconst(mData.address).setNull();
154 unconst(mData.backend).setNull();
155
156 unconst(mData.port) = 0;
157 unconst(mData.version) = 1;
158 unconst(mData.portVersion) = 1;
159
160 unconst(mData.dirty) = FALSE;
161
162 unconst(mData.devId) = 0;
163 unconst(mData.clientId) = 0;
164}
165
166// IUSBDevice properties
167/////////////////////////////////////////////////////////////////////////////
168
169HRESULT RemoteUSBDevice::getId(com::Guid &aId)
170{
171 aId = mData.id;
172
173 return S_OK;
174}
175
176HRESULT RemoteUSBDevice::getVendorId(USHORT *aVendorId)
177{
178 /* this is const, no need to lock */
179 *aVendorId = mData.vendorId;
180
181 return S_OK;
182}
183
184HRESULT RemoteUSBDevice::getProductId(USHORT *aProductId)
185{
186 /* this is const, no need to lock */
187 *aProductId = mData.productId;
188
189 return S_OK;
190}
191
192HRESULT RemoteUSBDevice::getRevision(USHORT *aRevision)
193{
194 /* this is const, no need to lock */
195 *aRevision = mData.revision;
196
197 return S_OK;
198}
199
200HRESULT RemoteUSBDevice::getManufacturer(com::Utf8Str &aManufacturer)
201{
202 /* this is const, no need to lock */
203 aManufacturer = mData.manufacturer;
204
205 return S_OK;
206}
207
208HRESULT RemoteUSBDevice::getProduct(com::Utf8Str &aProduct)
209{
210 /* this is const, no need to lock */
211 aProduct = mData.product;
212
213 return S_OK;
214}
215
216HRESULT RemoteUSBDevice::getSerialNumber(com::Utf8Str &aSerialNumber)
217{
218 /* this is const, no need to lock */
219 aSerialNumber = mData.serialNumber;
220
221 return S_OK;
222}
223
224HRESULT RemoteUSBDevice::getAddress(com::Utf8Str &aAddress)
225{
226 /* this is const, no need to lock */
227 aAddress = mData.address;
228
229 return S_OK;
230}
231
232HRESULT RemoteUSBDevice::getPort(USHORT *aPort)
233{
234 /* this is const, no need to lock */
235 *aPort = mData.port;
236
237 return S_OK;
238}
239
240HRESULT RemoteUSBDevice::getVersion(USHORT *aVersion)
241{
242 /* this is const, no need to lock */
243 *aVersion = mData.version;
244
245 return S_OK;
246}
247
248HRESULT RemoteUSBDevice::getPortVersion(USHORT *aPortVersion)
249{
250 /* this is const, no need to lock */
251 *aPortVersion = mData.portVersion;
252
253 return S_OK;
254}
255
256HRESULT RemoteUSBDevice::getSpeed(USBConnectionSpeed_T *aSpeed)
257{
258 /* this is const, no need to lock */
259 *aSpeed = mData.speed;
260
261 return S_OK;
262}
263
264HRESULT RemoteUSBDevice::getRemote(BOOL *aRemote)
265{
266 /* RemoteUSBDevice is always remote. */
267 /* this is const, no need to lock */
268 *aRemote = TRUE;
269
270 return S_OK;
271}
272
273HRESULT RemoteUSBDevice::getBackend(com::Utf8Str &aBackend)
274{
275 /* this is const, no need to lock */
276 aBackend = mData.backend;
277
278 return S_OK;
279}
280
281HRESULT RemoteUSBDevice::getDeviceInfo(std::vector<com::Utf8Str> &aInfo)
282{
283 /* this is const, no need to lock */
284 aInfo.resize(2);
285 aInfo[0] = mData.manufacturer;
286 aInfo[1] = mData.product;
287
288 return S_OK;
289}
290
291// IHostUSBDevice properties
292////////////////////////////////////////////////////////////////////////////////
293
294HRESULT RemoteUSBDevice::getState(USBDeviceState_T *aState)
295{
296 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
297
298 *aState = mData.state;
299
300 return S_OK;
301}
302
303// public methods only for internal purposes
304////////////////////////////////////////////////////////////////////////////////
305/* 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