VirtualBox

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

Last change on this file since 59117 was 59117, checked in by vboxsync, 9 years ago

USB,Main: Rework USBProxyService. Split it into a USBProxyService and USBProxyBackend class, USBProxyService can use multiple USBProxyBackend instances as sources for USB devices to attach to a VM which will be used for USB/IP support. Change the PDM USB API to contain a backend parameter instead of a remote flag to indicate the USB backend to use for the given device.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 7.6 KB
Line 
1/* $Id: RemoteUSBDeviceImpl.cpp 59117 2015-12-14 14:04:37Z vboxsync $ */
2
3/** @file
4 *
5 * VirtualBox IHostUSBDevice COM interface implementation
6 * for remote (VRDP) USB devices
7 */
8
9/*
10 * Copyright (C) 2006-2015 Oracle Corporation
11 *
12 * This file is part of VirtualBox Open Source Edition (OSE), as
13 * available from http://www.215389.xyz. 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 RTStrPrintf(id, sizeof(id), "vrdp");
79 unconst(mData.backend) = id;
80
81 unconst(mData.port) = pDevDesc->idPort;
82 unconst(mData.version) = pDevDesc->bcdUSB >> 8;
83 if (fDescExt)
84 {
85 VRDEUSBDEVICEDESCEXT *pDevDescExt = (VRDEUSBDEVICEDESCEXT *)pDevDesc;
86 switch (pDevDescExt->u16DeviceSpeed)
87 {
88 default:
89 case VRDE_USBDEVICESPEED_UNKNOWN:
90 case VRDE_USBDEVICESPEED_LOW:
91 case VRDE_USBDEVICESPEED_FULL:
92 unconst(mData.portVersion) = 1;
93 unconst(mData.speed) = USBConnectionSpeed_Full;
94 break;
95
96 case VRDE_USBDEVICESPEED_HIGH:
97 case VRDE_USBDEVICESPEED_VARIABLE:
98 unconst(mData.portVersion) = 2;
99 unconst(mData.speed) = USBConnectionSpeed_High;
100 break;
101
102 case VRDE_USBDEVICESPEED_SUPERSPEED:
103 unconst(mData.portVersion) = 3;
104 unconst(mData.speed) = USBConnectionSpeed_Super;
105 break;
106 }
107 }
108 else
109 {
110 unconst(mData.portVersion) = mData.version;
111 unconst(mData.speed) = mData.version == 3
112 ? (USBConnectionSpeed_T)USBConnectionSpeed_Super
113 : mData.version == 2 ? (USBConnectionSpeed_T)USBConnectionSpeed_High
114 : (USBConnectionSpeed_T)USBConnectionSpeed_Full;
115 }
116
117 mData.state = USBDeviceState_Available;
118
119 mData.dirty = false;
120 unconst(mData.devId) = pDevDesc->id;
121
122 unconst(mData.clientId) = u32ClientId;
123
124 /* Confirm a successful initialization */
125 autoInitSpan.setSucceeded();
126
127 return S_OK;
128}
129
130
131/**
132 * Uninitializes the instance and sets the ready flag to FALSE.
133 * Called either from FinalRelease() or by the parent when it gets destroyed.
134 */
135void RemoteUSBDevice::uninit()
136{
137 LogFlowThisFunc(("\n"));
138
139 /* Enclose the state transition Ready->InUninit->NotReady */
140 AutoUninitSpan autoUninitSpan(this);
141 if (autoUninitSpan.uninitDone())
142 return;
143
144 unconst(mData.id).clear();
145
146 unconst(mData.vendorId) = 0;
147 unconst(mData.productId) = 0;
148 unconst(mData.revision) = 0;
149
150 unconst(mData.manufacturer).setNull();
151 unconst(mData.product).setNull();
152 unconst(mData.serialNumber).setNull();
153
154 unconst(mData.address).setNull();
155 unconst(mData.backend).setNull();
156
157 unconst(mData.port) = 0;
158 unconst(mData.version) = 1;
159 unconst(mData.portVersion) = 1;
160
161 unconst(mData.dirty) = FALSE;
162
163 unconst(mData.devId) = 0;
164 unconst(mData.clientId) = 0;
165}
166
167// IUSBDevice properties
168/////////////////////////////////////////////////////////////////////////////
169
170HRESULT RemoteUSBDevice::getId(com::Guid &aId)
171{
172 aId = mData.id;
173
174 return S_OK;
175}
176
177HRESULT RemoteUSBDevice::getVendorId(USHORT *aVendorId)
178{
179 /* this is const, no need to lock */
180 *aVendorId = mData.vendorId;
181
182 return S_OK;
183}
184
185HRESULT RemoteUSBDevice::getProductId(USHORT *aProductId)
186{
187 /* this is const, no need to lock */
188 *aProductId = mData.productId;
189
190 return S_OK;
191}
192
193HRESULT RemoteUSBDevice::getRevision(USHORT *aRevision)
194{
195 /* this is const, no need to lock */
196 *aRevision = mData.revision;
197
198 return S_OK;
199}
200
201HRESULT RemoteUSBDevice::getManufacturer(com::Utf8Str &aManufacturer)
202{
203 /* this is const, no need to lock */
204 aManufacturer = mData.manufacturer;
205
206 return S_OK;
207}
208
209HRESULT RemoteUSBDevice::getProduct(com::Utf8Str &aProduct)
210{
211 /* this is const, no need to lock */
212 aProduct = mData.product;
213
214 return S_OK;
215}
216
217HRESULT RemoteUSBDevice::getSerialNumber(com::Utf8Str &aSerialNumber)
218{
219 /* this is const, no need to lock */
220 aSerialNumber = mData.serialNumber;
221
222 return S_OK;
223}
224
225HRESULT RemoteUSBDevice::getAddress(com::Utf8Str &aAddress)
226{
227 /* this is const, no need to lock */
228 aAddress = mData.address;
229
230 return S_OK;
231}
232
233HRESULT RemoteUSBDevice::getPort(USHORT *aPort)
234{
235 /* this is const, no need to lock */
236 *aPort = mData.port;
237
238 return S_OK;
239}
240
241HRESULT RemoteUSBDevice::getVersion(USHORT *aVersion)
242{
243 /* this is const, no need to lock */
244 *aVersion = mData.version;
245
246 return S_OK;
247}
248
249HRESULT RemoteUSBDevice::getPortVersion(USHORT *aPortVersion)
250{
251 /* this is const, no need to lock */
252 *aPortVersion = mData.portVersion;
253
254 return S_OK;
255}
256
257HRESULT RemoteUSBDevice::getSpeed(USBConnectionSpeed_T *aSpeed)
258{
259 /* this is const, no need to lock */
260 *aSpeed = mData.speed;
261
262 return S_OK;
263}
264
265HRESULT RemoteUSBDevice::getRemote(BOOL *aRemote)
266{
267 /* RemoteUSBDevice is always remote. */
268 /* this is const, no need to lock */
269 *aRemote = TRUE;
270
271 return S_OK;
272}
273
274HRESULT RemoteUSBDevice::getBackend(com::Utf8Str &aBackend)
275{
276 /* this is const, no need to lock */
277 aBackend = mData.backend;
278
279 return S_OK;
280}
281
282// IHostUSBDevice properties
283////////////////////////////////////////////////////////////////////////////////
284
285HRESULT RemoteUSBDevice::getState(USBDeviceState_T *aState)
286{
287 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
288
289 *aState = mData.state;
290
291 return S_OK;
292}
293
294// public methods only for internal purposes
295////////////////////////////////////////////////////////////////////////////////
296/* vi: set tabstop=4 shiftwidth=4 expandtab: */
Note: See TracBrowser for help on using the repository browser.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette