VirtualBox

source: vbox/trunk/src/VBox/Main/USBDeviceImpl.cpp@ 28205

Last change on this file since 28205 was 26753, checked in by vboxsync, 15 years ago

Main: Bstr makeover (third attempt) -- make Bstr(NULL) and Bstr() behave the same; resulting cleanup; make some more internal methods use Utf8Str instead of Bstr; fix a lot of CheckComArgNotNull??() usage

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 8.6 KB
Line 
1/* $Id: USBDeviceImpl.cpp 26753 2010-02-24 16:24:33Z vboxsync $ */
2
3/** @file
4 *
5 * VirtualBox COM class implementation
6 */
7
8/*
9 * Copyright (C) 2006-2008 Sun Microsystems, Inc.
10 *
11 * This file is part of VirtualBox Open Source Edition (OSE), as
12 * available from http://www.virtualbox.org. This file is free software;
13 * you can redistribute it and/or modify it under the terms of the GNU
14 * General Public License (GPL) as published by the Free Software
15 * Foundation, in version 2 as it comes in the "COPYING" file of the
16 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
17 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
18 *
19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
20 * Clara, CA 95054 USA or visit http://www.sun.com if you need
21 * additional information or have any questions.
22 */
23
24#include "USBDeviceImpl.h"
25
26#include "AutoCaller.h"
27#include "Logging.h"
28
29// constructor / destructor
30/////////////////////////////////////////////////////////////////////////////
31
32DEFINE_EMPTY_CTOR_DTOR (OUSBDevice)
33
34HRESULT OUSBDevice::FinalConstruct()
35{
36 return S_OK;
37}
38
39void OUSBDevice::FinalRelease()
40{
41 uninit ();
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 hrc = aUSBDevice->COMGETTER(Manufacturer)(unconst(mData.manufacturer).asOutParam());
74 ComAssertComRCRet(hrc, hrc);
75
76 hrc = aUSBDevice->COMGETTER(Product)(unconst(mData.product).asOutParam());
77 ComAssertComRCRet(hrc, hrc);
78
79 hrc = aUSBDevice->COMGETTER(SerialNumber)(unconst(mData.serialNumber).asOutParam());
80 ComAssertComRCRet(hrc, hrc);
81
82 hrc = aUSBDevice->COMGETTER(Address)(unconst(mData.address).asOutParam());
83 ComAssertComRCRet(hrc, hrc);
84
85 hrc = aUSBDevice->COMGETTER(Port)(&unconst(mData.port));
86 ComAssertComRCRet(hrc, hrc);
87
88 hrc = aUSBDevice->COMGETTER(Port)(&unconst(mData.version));
89 ComAssertComRCRet(hrc, hrc);
90
91 hrc = aUSBDevice->COMGETTER(Port)(&unconst(mData.portVersion));
92 ComAssertComRCRet(hrc, hrc);
93
94 hrc = aUSBDevice->COMGETTER(Remote)(&unconst(mData.remote));
95 ComAssertComRCRet(hrc, hrc);
96
97 Bstr uuid;
98 hrc = aUSBDevice->COMGETTER(Id)(uuid.asOutParam());
99 ComAssertComRCRet(hrc, hrc);
100 unconst(mData.id) = Guid(uuid);
101
102 /* Confirm a successful initialization */
103 autoInitSpan.setSucceeded();
104
105 return S_OK;
106}
107
108/**
109 * Uninitializes the instance and sets the ready flag to FALSE.
110 * Called either from FinalRelease() or by the parent when it gets destroyed.
111 */
112void OUSBDevice::uninit()
113{
114 LogFlowThisFunc(("\n"));
115
116 /* Enclose the state transition Ready->InUninit->NotReady */
117 AutoUninitSpan autoUninitSpan(this);
118 if (autoUninitSpan.uninitDone())
119 return;
120
121 unconst(mData.id).clear();
122
123 unconst(mData.vendorId) = 0;
124 unconst(mData.productId) = 0;
125 unconst(mData.revision) = 0;
126
127 unconst(mData.manufacturer).setNull();
128 unconst(mData.product).setNull();
129 unconst(mData.serialNumber).setNull();
130
131 unconst(mData.address).setNull();
132
133 unconst(mData.port) = 0;
134 unconst(mData.version) = 1;
135 unconst(mData.portVersion) = 1;
136
137 unconst(mData.remote) = FALSE;
138}
139
140// IUSBDevice properties
141/////////////////////////////////////////////////////////////////////////////
142
143/**
144 * Returns the GUID.
145 *
146 * @returns COM status code
147 * @param aId Address of result variable.
148 */
149STDMETHODIMP OUSBDevice::COMGETTER(Id)(BSTR *aId)
150{
151 CheckComArgOutPointerValid(aId);
152
153 AutoCaller autoCaller(this);
154 if (FAILED(autoCaller.rc())) return autoCaller.rc();
155
156 /* this is const, no need to lock */
157 Guid(mData.id).toUtf16().detachTo(aId);
158
159 return S_OK;
160}
161
162
163/**
164 * Returns the vendor Id.
165 *
166 * @returns COM status code
167 * @param aVendorId Where to store the vendor id.
168 */
169STDMETHODIMP OUSBDevice::COMGETTER(VendorId)(USHORT *aVendorId)
170{
171 CheckComArgOutPointerValid(aVendorId);
172
173 AutoCaller autoCaller(this);
174 if (FAILED(autoCaller.rc())) return autoCaller.rc();
175
176 /* this is const, no need to lock */
177 *aVendorId = mData.vendorId;
178
179 return S_OK;
180}
181
182
183/**
184 * Returns the product Id.
185 *
186 * @returns COM status code
187 * @param aProductId Where to store the product id.
188 */
189STDMETHODIMP OUSBDevice::COMGETTER(ProductId)(USHORT *aProductId)
190{
191 CheckComArgOutPointerValid(aProductId);
192
193 AutoCaller autoCaller(this);
194 if (FAILED(autoCaller.rc())) return autoCaller.rc();
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 */
209STDMETHODIMP OUSBDevice::COMGETTER(Revision)(USHORT *aRevision)
210{
211 CheckComArgOutPointerValid(aRevision);
212
213 AutoCaller autoCaller(this);
214 if (FAILED(autoCaller.rc())) return autoCaller.rc();
215
216 /* this is const, no need to lock */
217 *aRevision = mData.revision;
218
219 return S_OK;
220}
221
222/**
223 * Returns the manufacturer string.
224 *
225 * @returns COM status code
226 * @param aManufacturer Where to put the return string.
227 */
228STDMETHODIMP OUSBDevice::COMGETTER(Manufacturer)(BSTR *aManufacturer)
229{
230 CheckComArgOutPointerValid(aManufacturer);
231
232 AutoCaller autoCaller(this);
233 if (FAILED(autoCaller.rc())) return autoCaller.rc();
234
235 /* this is const, no need to lock */
236 mData.manufacturer.cloneTo(aManufacturer);
237
238 return S_OK;
239}
240
241
242/**
243 * Returns the product string.
244 *
245 * @returns COM status code
246 * @param aProduct Where to put the return string.
247 */
248STDMETHODIMP OUSBDevice::COMGETTER(Product)(BSTR *aProduct)
249{
250 CheckComArgOutPointerValid(aProduct);
251
252 AutoCaller autoCaller(this);
253 if (FAILED(autoCaller.rc())) return autoCaller.rc();
254
255 /* this is const, no need to lock */
256 mData.product.cloneTo(aProduct);
257
258 return S_OK;
259}
260
261
262/**
263 * Returns the serial number string.
264 *
265 * @returns COM status code
266 * @param aSerialNumber Where to put the return string.
267 */
268STDMETHODIMP OUSBDevice::COMGETTER(SerialNumber)(BSTR *aSerialNumber)
269{
270 CheckComArgOutPointerValid(aSerialNumber);
271
272 AutoCaller autoCaller(this);
273 if (FAILED(autoCaller.rc())) return autoCaller.rc();
274
275 /* this is const, no need to lock */
276 mData.serialNumber.cloneTo(aSerialNumber);
277
278 return S_OK;
279}
280
281
282/**
283 * Returns the host specific device address.
284 *
285 * @returns COM status code
286 * @param aAddress Where to put the return string.
287 */
288STDMETHODIMP OUSBDevice::COMGETTER(Address)(BSTR *aAddress)
289{
290 CheckComArgOutPointerValid(aAddress);
291
292 AutoCaller autoCaller(this);
293 if (FAILED(autoCaller.rc())) return autoCaller.rc();
294
295 /* this is const, no need to lock */
296 mData.address.cloneTo(aAddress);
297
298 return S_OK;
299}
300
301STDMETHODIMP OUSBDevice::COMGETTER(Port)(USHORT *aPort)
302{
303 CheckComArgOutPointerValid(aPort);
304
305 AutoCaller autoCaller(this);
306 if (FAILED(autoCaller.rc())) return autoCaller.rc();
307
308 /* this is const, no need to lock */
309 *aPort = mData.port;
310
311 return S_OK;
312}
313
314STDMETHODIMP OUSBDevice::COMGETTER(Version)(USHORT *aVersion)
315{
316 CheckComArgOutPointerValid(aVersion);
317
318 AutoCaller autoCaller(this);
319 if (FAILED(autoCaller.rc())) return autoCaller.rc();
320
321 /* this is const, no need to lock */
322 *aVersion = mData.version;
323
324 return S_OK;
325}
326
327STDMETHODIMP OUSBDevice::COMGETTER(PortVersion)(USHORT *aPortVersion)
328{
329 CheckComArgOutPointerValid(aPortVersion);
330
331 AutoCaller autoCaller(this);
332 if (FAILED(autoCaller.rc())) return autoCaller.rc();
333
334 /* this is const, no need to lock */
335 *aPortVersion = mData.portVersion;
336
337 return S_OK;
338}
339
340STDMETHODIMP OUSBDevice::COMGETTER(Remote)(BOOL *aRemote)
341{
342 CheckComArgOutPointerValid(aRemote);
343
344 AutoCaller autoCaller(this);
345 if (FAILED(autoCaller.rc())) return autoCaller.rc();
346
347 /* this is const, no need to lock */
348 *aRemote = mData.remote;
349
350 return S_OK;
351}
352
353// private methods
354/////////////////////////////////////////////////////////////////////////////
355/* 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