VirtualBox

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

Last change on this file since 76690 was 76553, checked in by vboxsync, 6 years ago

scm --update-copyright-year

  • 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 76553 2019-01-01 01:45:53Z vboxsync $ */
2/** @file
3 * VirtualBox IHostUSBDevice COM interface implementation for remote (VRDP) USB devices.
4 */
5
6/*
7 * Copyright (C) 2006-2019 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 */
17
18#define LOG_GROUP LOG_GROUP_MAIN_HOSTUSBDEVICE
19#include "LoggingNew.h"
20
21#include "RemoteUSBDeviceImpl.h"
22
23#include "AutoCaller.h"
24
25#include <iprt/cpp/utils.h>
26
27#include <iprt/errcore.h>
28
29#include <VBox/RemoteDesktop/VRDE.h>
30#include <VBox/vrdpusb.h>
31
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 ? USBConnectionSpeed_Super
111 : mData.version == 2 ? USBConnectionSpeed_High
112 : USBConnectionSpeed_Full;
113 }
114
115 mData.state = USBDeviceState_Available;
116
117 mData.dirty = false;
118 unconst(mData.devId) = (uint16_t)pDevDesc->id;
119
120 unconst(mData.clientId) = u32ClientId;
121
122 /* Confirm a successful initialization */
123 autoInitSpan.setSucceeded();
124
125 return S_OK;
126}
127
128
129/**
130 * Uninitializes the instance and sets the ready flag to FALSE.
131 * Called either from FinalRelease() or by the parent when it gets destroyed.
132 */
133void RemoteUSBDevice::uninit()
134{
135 LogFlowThisFunc(("\n"));
136
137 /* Enclose the state transition Ready->InUninit->NotReady */
138 AutoUninitSpan autoUninitSpan(this);
139 if (autoUninitSpan.uninitDone())
140 return;
141
142 unconst(mData.id).clear();
143
144 unconst(mData.vendorId) = 0;
145 unconst(mData.productId) = 0;
146 unconst(mData.revision) = 0;
147
148 unconst(mData.manufacturer).setNull();
149 unconst(mData.product).setNull();
150 unconst(mData.serialNumber).setNull();
151
152 unconst(mData.address).setNull();
153 unconst(mData.backend).setNull();
154
155 unconst(mData.port) = 0;
156 unconst(mData.version) = 1;
157 unconst(mData.portVersion) = 1;
158
159 unconst(mData.dirty) = FALSE;
160
161 unconst(mData.devId) = 0;
162 unconst(mData.clientId) = 0;
163}
164
165// IUSBDevice properties
166/////////////////////////////////////////////////////////////////////////////
167
168HRESULT RemoteUSBDevice::getId(com::Guid &aId)
169{
170 aId = mData.id;
171
172 return S_OK;
173}
174
175HRESULT RemoteUSBDevice::getVendorId(USHORT *aVendorId)
176{
177 /* this is const, no need to lock */
178 *aVendorId = mData.vendorId;
179
180 return S_OK;
181}
182
183HRESULT RemoteUSBDevice::getProductId(USHORT *aProductId)
184{
185 /* this is const, no need to lock */
186 *aProductId = mData.productId;
187
188 return S_OK;
189}
190
191HRESULT RemoteUSBDevice::getRevision(USHORT *aRevision)
192{
193 /* this is const, no need to lock */
194 *aRevision = mData.revision;
195
196 return S_OK;
197}
198
199HRESULT RemoteUSBDevice::getManufacturer(com::Utf8Str &aManufacturer)
200{
201 /* this is const, no need to lock */
202 aManufacturer = mData.manufacturer;
203
204 return S_OK;
205}
206
207HRESULT RemoteUSBDevice::getProduct(com::Utf8Str &aProduct)
208{
209 /* this is const, no need to lock */
210 aProduct = mData.product;
211
212 return S_OK;
213}
214
215HRESULT RemoteUSBDevice::getSerialNumber(com::Utf8Str &aSerialNumber)
216{
217 /* this is const, no need to lock */
218 aSerialNumber = mData.serialNumber;
219
220 return S_OK;
221}
222
223HRESULT RemoteUSBDevice::getAddress(com::Utf8Str &aAddress)
224{
225 /* this is const, no need to lock */
226 aAddress = mData.address;
227
228 return S_OK;
229}
230
231HRESULT RemoteUSBDevice::getPort(USHORT *aPort)
232{
233 /* this is const, no need to lock */
234 *aPort = mData.port;
235
236 return S_OK;
237}
238
239HRESULT RemoteUSBDevice::getVersion(USHORT *aVersion)
240{
241 /* this is const, no need to lock */
242 *aVersion = mData.version;
243
244 return S_OK;
245}
246
247HRESULT RemoteUSBDevice::getPortVersion(USHORT *aPortVersion)
248{
249 /* this is const, no need to lock */
250 *aPortVersion = mData.portVersion;
251
252 return S_OK;
253}
254
255HRESULT RemoteUSBDevice::getSpeed(USBConnectionSpeed_T *aSpeed)
256{
257 /* this is const, no need to lock */
258 *aSpeed = mData.speed;
259
260 return S_OK;
261}
262
263HRESULT RemoteUSBDevice::getRemote(BOOL *aRemote)
264{
265 /* RemoteUSBDevice is always remote. */
266 /* this is const, no need to lock */
267 *aRemote = TRUE;
268
269 return S_OK;
270}
271
272HRESULT RemoteUSBDevice::getBackend(com::Utf8Str &aBackend)
273{
274 /* this is const, no need to lock */
275 aBackend = mData.backend;
276
277 return S_OK;
278}
279
280HRESULT RemoteUSBDevice::getDeviceInfo(std::vector<com::Utf8Str> &aInfo)
281{
282 /* this is const, no need to lock */
283 aInfo.resize(2);
284 aInfo[0] = mData.manufacturer;
285 aInfo[1] = mData.product;
286
287 return S_OK;
288}
289
290// IHostUSBDevice properties
291////////////////////////////////////////////////////////////////////////////////
292
293HRESULT RemoteUSBDevice::getState(USBDeviceState_T *aState)
294{
295 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
296
297 *aState = mData.state;
298
299 return S_OK;
300}
301
302// public methods only for internal purposes
303////////////////////////////////////////////////////////////////////////////////
304/* 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