VirtualBox

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

Last change on this file since 44029 was 35638, checked in by vboxsync, 14 years ago

Main. QT/FE: fix long standing COM issue

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