VirtualBox

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

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