VirtualBox

source: vbox/trunk/src/VBox/Main/src-client/USBDeviceImpl.cpp@ 103415

Last change on this file since 103415 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.1 KB
Line 
1/* $Id: USBDeviceImpl.cpp 98103 2023-01-17 14:15:46Z vboxsync $ */
2/** @file
3 * VirtualBox COM class implementation
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_USBDEVICE
29#include "LoggingNew.h"
30
31#include "USBDeviceImpl.h"
32
33#include "AutoCaller.h"
34
35#include <iprt/cpp/utils.h>
36
37
38// constructor / destructor
39/////////////////////////////////////////////////////////////////////////////
40
41DEFINE_EMPTY_CTOR_DTOR (OUSBDevice)
42
43HRESULT OUSBDevice::FinalConstruct()
44{
45 return BaseFinalConstruct();
46}
47
48void OUSBDevice::FinalRelease()
49{
50 uninit ();
51 BaseFinalRelease();
52}
53
54// public initializer/uninitializer for internal purposes only
55/////////////////////////////////////////////////////////////////////////////
56
57/**
58 * Initializes the USB device object.
59 *
60 * @returns COM result indicator
61 * @param aUSBDevice The USB device (interface) to clone.
62 */
63HRESULT OUSBDevice::init(IUSBDevice *aUSBDevice)
64{
65 LogFlowThisFunc(("aUSBDevice=%p\n", aUSBDevice));
66
67 ComAssertRet(aUSBDevice, E_INVALIDARG);
68
69 /* Enclose the state transition NotReady->InInit->Ready */
70 AutoInitSpan autoInitSpan(this);
71 AssertReturn(autoInitSpan.isOk(), E_FAIL);
72
73 HRESULT hrc = aUSBDevice->COMGETTER(VendorId)(&unconst(mData.vendorId));
74 ComAssertComRCRet(hrc, hrc);
75 ComAssertRet(mData.vendorId, E_INVALIDARG);
76
77 hrc = aUSBDevice->COMGETTER(ProductId)(&unconst(mData.productId));
78 ComAssertComRCRet(hrc, hrc);
79
80 hrc = aUSBDevice->COMGETTER(Revision)(&unconst(mData.revision));
81 ComAssertComRCRet(hrc, hrc);
82
83 Bstr bstr;
84
85 hrc = aUSBDevice->COMGETTER(Manufacturer)(bstr.asOutParam());
86 ComAssertComRCRet(hrc, hrc);
87 unconst(mData.manufacturer) = bstr;
88
89 hrc = aUSBDevice->COMGETTER(Product)(bstr.asOutParam());
90 ComAssertComRCRet(hrc, hrc);
91 unconst(mData.product) = bstr;
92
93 hrc = aUSBDevice->COMGETTER(SerialNumber)(bstr.asOutParam());
94 ComAssertComRCRet(hrc, hrc);
95 unconst(mData.serialNumber) = bstr;
96
97 hrc = aUSBDevice->COMGETTER(Address)(bstr.asOutParam());
98 ComAssertComRCRet(hrc, hrc);
99 unconst(mData.address) = bstr;
100
101 hrc = aUSBDevice->COMGETTER(Backend)(bstr.asOutParam());
102 ComAssertComRCRet(hrc, hrc);
103 unconst(mData.backend) = bstr;
104
105 hrc = aUSBDevice->COMGETTER(Port)(&unconst(mData.port));
106 ComAssertComRCRet(hrc, hrc);
107
108 hrc = aUSBDevice->COMGETTER(PortPath)(bstr.asOutParam());
109 ComAssertComRCRet(hrc, hrc);
110
111 hrc = aUSBDevice->COMGETTER(Version)(&unconst(mData.version));
112 ComAssertComRCRet(hrc, hrc);
113
114 hrc = aUSBDevice->COMGETTER(Speed)(&unconst(mData.speed));
115 ComAssertComRCRet(hrc, hrc);
116
117 hrc = aUSBDevice->COMGETTER(Remote)(&unconst(mData.remote));
118 ComAssertComRCRet(hrc, hrc);
119
120 Bstr uuid;
121 hrc = aUSBDevice->COMGETTER(Id)(uuid.asOutParam());
122 ComAssertComRCRet(hrc, hrc);
123 unconst(mData.id) = Guid(uuid);
124
125 /* Confirm a successful initialization */
126 autoInitSpan.setSucceeded();
127
128 return S_OK;
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 OUSBDevice::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.portPath).setNull();
159 unconst(mData.version) = 1;
160
161 unconst(mData.remote) = FALSE;
162}
163
164// IUSBDevice properties
165/////////////////////////////////////////////////////////////////////////////
166
167/**
168 * Returns the GUID.
169 *
170 * @returns COM status code
171 * @param aId Address of result variable.
172 */
173HRESULT OUSBDevice::getId(com::Guid &aId)
174{
175 /* this is const, no need to lock */
176 aId = mData.id;
177
178 return S_OK;
179}
180
181
182/**
183 * Returns the vendor Id.
184 *
185 * @returns COM status code
186 * @param aVendorId Where to store the vendor id.
187 */
188HRESULT OUSBDevice::getVendorId(USHORT *aVendorId)
189{
190 /* this is const, no need to lock */
191 *aVendorId = mData.vendorId;
192
193 return S_OK;
194}
195
196
197/**
198 * Returns the product Id.
199 *
200 * @returns COM status code
201 * @param aProductId Where to store the product id.
202 */
203HRESULT OUSBDevice::getProductId(USHORT *aProductId)
204{
205 /* this is const, no need to lock */
206 *aProductId = mData.productId;
207
208 return S_OK;
209}
210
211
212/**
213 * Returns the revision BCD.
214 *
215 * @returns COM status code
216 * @param aRevision Where to store the revision BCD.
217 */
218HRESULT OUSBDevice::getRevision(USHORT *aRevision)
219{
220 /* this is const, no need to lock */
221 *aRevision = mData.revision;
222
223 return S_OK;
224}
225
226/**
227 * Returns the manufacturer string.
228 *
229 * @returns COM status code
230 * @param aManufacturer Where to put the return string.
231 */
232HRESULT OUSBDevice::getManufacturer(com::Utf8Str &aManufacturer)
233{
234 /* this is const, no need to lock */
235 aManufacturer = mData.manufacturer;
236
237 return S_OK;
238}
239
240
241/**
242 * Returns the product string.
243 *
244 * @returns COM status code
245 * @param aProduct Where to put the return string.
246 */
247HRESULT OUSBDevice::getProduct(com::Utf8Str &aProduct)
248{
249 /* this is const, no need to lock */
250 aProduct = mData.product;
251
252 return S_OK;
253}
254
255
256/**
257 * Returns the serial number string.
258 *
259 * @returns COM status code
260 * @param aSerialNumber Where to put the return string.
261 */
262HRESULT OUSBDevice::getSerialNumber(com::Utf8Str &aSerialNumber)
263{
264 /* this is const, no need to lock */
265 aSerialNumber = mData.serialNumber;
266
267 return S_OK;
268}
269
270
271/**
272 * Returns the host specific device address.
273 *
274 * @returns COM status code
275 * @param aAddress Where to put the return string.
276 */
277HRESULT OUSBDevice::getAddress(com::Utf8Str &aAddress)
278{
279 /* this is const, no need to lock */
280 aAddress = mData.address;
281
282 return S_OK;
283}
284
285HRESULT OUSBDevice::getPort(USHORT *aPort)
286{
287 /* this is const, no need to lock */
288 *aPort = mData.port;
289
290 return S_OK;
291}
292
293HRESULT OUSBDevice::getPortPath(com::Utf8Str &aPortPath)
294{
295 /* this is const, no need to lock */
296 aPortPath = mData.portPath;
297
298 return S_OK;
299}
300
301HRESULT OUSBDevice::getVersion(USHORT *aVersion)
302{
303 /* this is const, no need to lock */
304 *aVersion = mData.version;
305
306 return S_OK;
307}
308
309HRESULT OUSBDevice::getSpeed(USBConnectionSpeed_T *aSpeed)
310{
311 /* this is const, no need to lock */
312 *aSpeed = mData.speed;
313
314 return S_OK;
315}
316
317HRESULT OUSBDevice::getRemote(BOOL *aRemote)
318{
319 /* this is const, no need to lock */
320 *aRemote = mData.remote;
321
322 return S_OK;
323}
324
325/**
326 * Returns the device specific backend.
327 *
328 * @returns COM status code
329 * @param aBackend Where to put the return string.
330 */
331HRESULT OUSBDevice::getBackend(com::Utf8Str &aBackend)
332{
333 /* this is const, no need to lock */
334 aBackend = mData.backend;
335
336 return S_OK;
337}
338
339HRESULT OUSBDevice::getDeviceInfo(std::vector<com::Utf8Str> &aInfo)
340{
341 /* this is const, no need to lock */
342 aInfo.resize(2);
343 aInfo[0] = mData.manufacturer;
344 aInfo[1] = mData.product;
345
346 return S_OK;
347}
348
349// private methods
350/////////////////////////////////////////////////////////////////////////////
351/* 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