VirtualBox

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

Last change on this file since 79294 was 77436, checked in by vboxsync, 6 years ago

Main: Eradicate the use of BSTR in regular API code, there were leaks in almost every occurrence. Also do some Bstr->Utf8Str shuffling to reduce the number of conversions.

  • 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 77436 2019-02-22 17:40:00Z 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 bstr;
74
75 hrc = aUSBDevice->COMGETTER(Manufacturer)(bstr.asOutParam());
76 ComAssertComRCRet(hrc, hrc);
77 unconst(mData.manufacturer) = bstr;
78
79 hrc = aUSBDevice->COMGETTER(Product)(bstr.asOutParam());
80 ComAssertComRCRet(hrc, hrc);
81 unconst(mData.product) = bstr;
82
83 hrc = aUSBDevice->COMGETTER(SerialNumber)(bstr.asOutParam());
84 ComAssertComRCRet(hrc, hrc);
85 unconst(mData.serialNumber) = bstr;
86
87 hrc = aUSBDevice->COMGETTER(Address)(bstr.asOutParam());
88 ComAssertComRCRet(hrc, hrc);
89 unconst(mData.address) = bstr;
90
91 hrc = aUSBDevice->COMGETTER(Backend)(bstr.asOutParam());
92 ComAssertComRCRet(hrc, hrc);
93 unconst(mData.backend) = bstr;
94
95 hrc = aUSBDevice->COMGETTER(Port)(&unconst(mData.port));
96 ComAssertComRCRet(hrc, hrc);
97
98 hrc = aUSBDevice->COMGETTER(Version)(&unconst(mData.version));
99 ComAssertComRCRet(hrc, hrc);
100
101 hrc = aUSBDevice->COMGETTER(PortVersion)(&unconst(mData.portVersion));
102 ComAssertComRCRet(hrc, hrc);
103
104 hrc = aUSBDevice->COMGETTER(Speed)(&unconst(mData.speed));
105 ComAssertComRCRet(hrc, hrc);
106
107 hrc = aUSBDevice->COMGETTER(Remote)(&unconst(mData.remote));
108 ComAssertComRCRet(hrc, hrc);
109
110 Bstr uuid;
111 hrc = aUSBDevice->COMGETTER(Id)(uuid.asOutParam());
112 ComAssertComRCRet(hrc, hrc);
113 unconst(mData.id) = Guid(uuid);
114
115 /* Confirm a successful initialization */
116 autoInitSpan.setSucceeded();
117
118 return S_OK;
119}
120
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{
127 LogFlowThisFunc(("\n"));
128
129 /* Enclose the state transition Ready->InUninit->NotReady */
130 AutoUninitSpan autoUninitSpan(this);
131 if (autoUninitSpan.uninitDone())
132 return;
133
134 unconst(mData.id).clear();
135
136 unconst(mData.vendorId) = 0;
137 unconst(mData.productId) = 0;
138 unconst(mData.revision) = 0;
139
140 unconst(mData.manufacturer).setNull();
141 unconst(mData.product).setNull();
142 unconst(mData.serialNumber).setNull();
143
144 unconst(mData.address).setNull();
145 unconst(mData.backend).setNull();
146
147 unconst(mData.port) = 0;
148 unconst(mData.version) = 1;
149 unconst(mData.portVersion) = 1;
150
151 unconst(mData.remote) = FALSE;
152}
153
154// IUSBDevice properties
155/////////////////////////////////////////////////////////////////////////////
156
157/**
158 * Returns the GUID.
159 *
160 * @returns COM status code
161 * @param aId Address of result variable.
162 */
163HRESULT OUSBDevice::getId(com::Guid &aId)
164{
165 /* this is const, no need to lock */
166 aId = mData.id;
167
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 */
178HRESULT OUSBDevice::getVendorId(USHORT *aVendorId)
179{
180 /* this is const, no need to lock */
181 *aVendorId = mData.vendorId;
182
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 */
193HRESULT OUSBDevice::getProductId(USHORT *aProductId)
194{
195 /* this is const, no need to lock */
196 *aProductId = mData.productId;
197
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 */
208HRESULT OUSBDevice::getRevision(USHORT *aRevision)
209{
210 /* this is const, no need to lock */
211 *aRevision = mData.revision;
212
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 */
222HRESULT OUSBDevice::getManufacturer(com::Utf8Str &aManufacturer)
223{
224 /* this is const, no need to lock */
225 aManufacturer = mData.manufacturer;
226
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 */
237HRESULT OUSBDevice::getProduct(com::Utf8Str &aProduct)
238{
239 /* this is const, no need to lock */
240 aProduct = mData.product;
241
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 */
252HRESULT OUSBDevice::getSerialNumber(com::Utf8Str &aSerialNumber)
253{
254 /* this is const, no need to lock */
255 aSerialNumber = mData.serialNumber;
256
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 */
267HRESULT OUSBDevice::getAddress(com::Utf8Str &aAddress)
268{
269 /* this is const, no need to lock */
270 aAddress = mData.address;
271
272 return S_OK;
273}
274
275HRESULT OUSBDevice::getPort(USHORT *aPort)
276{
277 /* this is const, no need to lock */
278 *aPort = mData.port;
279
280 return S_OK;
281}
282
283HRESULT OUSBDevice::getVersion(USHORT *aVersion)
284{
285 /* this is const, no need to lock */
286 *aVersion = mData.version;
287
288 return S_OK;
289}
290
291HRESULT OUSBDevice::getPortVersion(USHORT *aPortVersion)
292{
293 /* this is const, no need to lock */
294 *aPortVersion = mData.portVersion;
295
296 return S_OK;
297}
298
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
307HRESULT OUSBDevice::getRemote(BOOL *aRemote)
308{
309 /* this is const, no need to lock */
310 *aRemote = mData.remote;
311
312 return S_OK;
313}
314
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
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
339// private methods
340/////////////////////////////////////////////////////////////////////////////
341/* 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