VirtualBox

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

Last change on this file since 98103 was 98103, checked in by vboxsync, 23 months ago

Copyright year updates by scm.

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