VirtualBox

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

Last change on this file since 94521 was 93115, checked in by vboxsync, 2 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
RevLine 
[13659]1/* $Id: USBDeviceImpl.cpp 93115 2022-01-01 11:31:46Z vboxsync $ */
[1]2/** @file
3 * VirtualBox COM class implementation
4 */
5
6/*
[93115]7 * Copyright (C) 2006-2022 Oracle Corporation
[1]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
[5999]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.
[1]16 */
17
[67914]18#define LOG_GROUP LOG_GROUP_MAIN_USBDEVICE
19#include "LoggingNew.h"
20
[1]21#include "USBDeviceImpl.h"
[25860]22
23#include "AutoCaller.h"
[1]24
[30681]25#include <iprt/cpp/utils.h>
26
[67914]27
[1]28// constructor / destructor
29/////////////////////////////////////////////////////////////////////////////
30
[13659]31DEFINE_EMPTY_CTOR_DTOR (OUSBDevice)
32
33HRESULT OUSBDevice::FinalConstruct()
[1]34{
[35638]35 return BaseFinalConstruct();
[1]36}
37
[13659]38void OUSBDevice::FinalRelease()
[1]39{
[13659]40 uninit ();
[35638]41 BaseFinalRelease();
[1]42}
43
44// public initializer/uninitializer for internal purposes only
45/////////////////////////////////////////////////////////////////////////////
46
47/**
48 * Initializes the USB device object.
49 *
50 * @returns COM result indicator
51 * @param aUSBDevice The USB device (interface) to clone.
52 */
[436]53HRESULT OUSBDevice::init(IUSBDevice *aUSBDevice)
[1]54{
[21878]55 LogFlowThisFunc(("aUSBDevice=%p\n", aUSBDevice));
[1]56
[26235]57 ComAssertRet(aUSBDevice, E_INVALIDARG);
[13659]58
59 /* Enclose the state transition NotReady->InInit->Ready */
[21878]60 AutoInitSpan autoInitSpan(this);
61 AssertReturn(autoInitSpan.isOk(), E_FAIL);
[13659]62
[21878]63 HRESULT hrc = aUSBDevice->COMGETTER(VendorId)(&unconst(mData.vendorId));
[26235]64 ComAssertComRCRet(hrc, hrc);
65 ComAssertRet(mData.vendorId, E_INVALIDARG);
[1]66
[21878]67 hrc = aUSBDevice->COMGETTER(ProductId)(&unconst(mData.productId));
[26235]68 ComAssertComRCRet(hrc, hrc);
[1]69
[21878]70 hrc = aUSBDevice->COMGETTER(Revision)(&unconst(mData.revision));
[26235]71 ComAssertComRCRet(hrc, hrc);
[1]72
[77436]73 Bstr bstr;
[50403]74
[77436]75 hrc = aUSBDevice->COMGETTER(Manufacturer)(bstr.asOutParam());
[26235]76 ComAssertComRCRet(hrc, hrc);
[77436]77 unconst(mData.manufacturer) = bstr;
[1]78
[77436]79 hrc = aUSBDevice->COMGETTER(Product)(bstr.asOutParam());
[26235]80 ComAssertComRCRet(hrc, hrc);
[77436]81 unconst(mData.product) = bstr;
[1]82
[77436]83 hrc = aUSBDevice->COMGETTER(SerialNumber)(bstr.asOutParam());
[26235]84 ComAssertComRCRet(hrc, hrc);
[77436]85 unconst(mData.serialNumber) = bstr;
[1]86
[77436]87 hrc = aUSBDevice->COMGETTER(Address)(bstr.asOutParam());
[26235]88 ComAssertComRCRet(hrc, hrc);
[77436]89 unconst(mData.address) = bstr;
[1]90
[77436]91 hrc = aUSBDevice->COMGETTER(Backend)(bstr.asOutParam());
[59117]92 ComAssertComRCRet(hrc, hrc);
[77436]93 unconst(mData.backend) = bstr;
[59117]94
[21878]95 hrc = aUSBDevice->COMGETTER(Port)(&unconst(mData.port));
[26235]96 ComAssertComRCRet(hrc, hrc);
[1]97
[81667]98 hrc = aUSBDevice->COMGETTER(PortPath)(bstr.asOutParam());
99 ComAssertComRCRet(hrc, hrc);
100
[50411]101 hrc = aUSBDevice->COMGETTER(Version)(&unconst(mData.version));
[26235]102 ComAssertComRCRet(hrc, hrc);
[5528]103
[53297]104 hrc = aUSBDevice->COMGETTER(Speed)(&unconst(mData.speed));
105 ComAssertComRCRet(hrc, hrc);
106
[21878]107 hrc = aUSBDevice->COMGETTER(Remote)(&unconst(mData.remote));
[26235]108 ComAssertComRCRet(hrc, hrc);
[1]109
[24989]110 Bstr uuid;
111 hrc = aUSBDevice->COMGETTER(Id)(uuid.asOutParam());
112 ComAssertComRCRet(hrc, hrc);
113 unconst(mData.id) = Guid(uuid);
[1]114
[13659]115 /* Confirm a successful initialization */
116 autoInitSpan.setSucceeded();
117
[1]118 return S_OK;
119}
120
[13659]121/**
122 * Uninitializes the instance and sets the ready flag to FALSE.
123 * Called either from FinalRelease() or by the parent when it gets destroyed.
124 */
125void OUSBDevice::uninit()
126{
[21878]127 LogFlowThisFunc(("\n"));
[1]128
[13659]129 /* Enclose the state transition Ready->InUninit->NotReady */
[21878]130 AutoUninitSpan autoUninitSpan(this);
[13659]131 if (autoUninitSpan.uninitDone())
132 return;
133
[21878]134 unconst(mData.id).clear();
[13659]135
[21878]136 unconst(mData.vendorId) = 0;
137 unconst(mData.productId) = 0;
138 unconst(mData.revision) = 0;
[13659]139
[21878]140 unconst(mData.manufacturer).setNull();
141 unconst(mData.product).setNull();
142 unconst(mData.serialNumber).setNull();
[13659]143
[21878]144 unconst(mData.address).setNull();
[59117]145 unconst(mData.backend).setNull();
[13659]146
[21878]147 unconst(mData.port) = 0;
[81667]148 unconst(mData.portPath).setNull();
[21878]149 unconst(mData.version) = 1;
[13659]150
[21878]151 unconst(mData.remote) = FALSE;
[13659]152}
153
[1]154// IUSBDevice properties
155/////////////////////////////////////////////////////////////////////////////
156
157/**
158 * Returns the GUID.
159 *
160 * @returns COM status code
161 * @param aId Address of result variable.
162 */
[50403]163HRESULT OUSBDevice::getId(com::Guid &aId)
[1]164{
[13659]165 /* this is const, no need to lock */
[50403]166 aId = mData.id;
[13659]167
[1]168 return S_OK;
169}
170
171
172/**
173 * Returns the vendor Id.
174 *
175 * @returns COM status code
176 * @param aVendorId Where to store the vendor id.
177 */
[50403]178HRESULT OUSBDevice::getVendorId(USHORT *aVendorId)
[1]179{
[13659]180 /* this is const, no need to lock */
181 *aVendorId = mData.vendorId;
182
[1]183 return S_OK;
184}
185
186
187/**
188 * Returns the product Id.
189 *
190 * @returns COM status code
191 * @param aProductId Where to store the product id.
192 */
[50403]193HRESULT OUSBDevice::getProductId(USHORT *aProductId)
[1]194{
[13659]195 /* this is const, no need to lock */
196 *aProductId = mData.productId;
197
[1]198 return S_OK;
199}
200
201
202/**
203 * Returns the revision BCD.
204 *
205 * @returns COM status code
206 * @param aRevision Where to store the revision BCD.
207 */
[50403]208HRESULT OUSBDevice::getRevision(USHORT *aRevision)
[1]209{
[13659]210 /* this is const, no need to lock */
211 *aRevision = mData.revision;
212
[1]213 return S_OK;
214}
215
216/**
217 * Returns the manufacturer string.
218 *
219 * @returns COM status code
220 * @param aManufacturer Where to put the return string.
221 */
[50403]222HRESULT OUSBDevice::getManufacturer(com::Utf8Str &aManufacturer)
[1]223{
[13659]224 /* this is const, no need to lock */
[50403]225 aManufacturer = mData.manufacturer;
[13659]226
[1]227 return S_OK;
228}
229
230
231/**
232 * Returns the product string.
233 *
234 * @returns COM status code
235 * @param aProduct Where to put the return string.
236 */
[50403]237HRESULT OUSBDevice::getProduct(com::Utf8Str &aProduct)
[1]238{
[13659]239 /* this is const, no need to lock */
[50403]240 aProduct = mData.product;
[13659]241
[1]242 return S_OK;
243}
244
245
246/**
247 * Returns the serial number string.
248 *
249 * @returns COM status code
250 * @param aSerialNumber Where to put the return string.
251 */
[50403]252HRESULT OUSBDevice::getSerialNumber(com::Utf8Str &aSerialNumber)
[1]253{
[13659]254 /* this is const, no need to lock */
[50403]255 aSerialNumber = mData.serialNumber;
[13659]256
[1]257 return S_OK;
258}
259
260
261/**
262 * Returns the host specific device address.
263 *
264 * @returns COM status code
265 * @param aAddress Where to put the return string.
266 */
[50403]267HRESULT OUSBDevice::getAddress(com::Utf8Str &aAddress)
[1]268{
[13659]269 /* this is const, no need to lock */
[50403]270 aAddress = mData.address;
[13659]271
[1]272 return S_OK;
273}
274
[50403]275HRESULT OUSBDevice::getPort(USHORT *aPort)
[1]276{
[13659]277 /* this is const, no need to lock */
278 *aPort = mData.port;
279
[1]280 return S_OK;
281}
282
[81667]283HRESULT OUSBDevice::getPortPath(com::Utf8Str &aPortPath)
284{
285 /* this is const, no need to lock */
286 aPortPath = mData.portPath;
287
288 return S_OK;
289}
290
[50403]291HRESULT OUSBDevice::getVersion(USHORT *aVersion)
[5528]292{
[13659]293 /* this is const, no need to lock */
294 *aVersion = mData.version;
295
[5528]296 return S_OK;
297}
298
[53297]299HRESULT OUSBDevice::getSpeed(USBConnectionSpeed_T *aSpeed)
300{
301 /* this is const, no need to lock */
302 *aSpeed = mData.speed;
303
304 return S_OK;
305}
306
[50403]307HRESULT OUSBDevice::getRemote(BOOL *aRemote)
[1]308{
[13659]309 /* this is const, no need to lock */
310 *aRemote = mData.remote;
311
[1]312 return S_OK;
313}
314
[59117]315/**
316 * Returns the device specific backend.
317 *
318 * @returns COM status code
319 * @param aBackend Where to put the return string.
320 */
321HRESULT OUSBDevice::getBackend(com::Utf8Str &aBackend)
322{
323 /* this is const, no need to lock */
324 aBackend = mData.backend;
325
326 return S_OK;
327}
328
[59381]329HRESULT OUSBDevice::getDeviceInfo(std::vector<com::Utf8Str> &aInfo)
330{
331 /* this is const, no need to lock */
332 aInfo.resize(2);
333 aInfo[0] = mData.manufacturer;
334 aInfo[1] = mData.product;
335
336 return S_OK;
337}
338
[1]339// private methods
340/////////////////////////////////////////////////////////////////////////////
[14772]341/* vi: set tabstop=4 shiftwidth=4 expandtab: */
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use