VirtualBox

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

Last change on this file since 18626 was 15051, checked in by vboxsync, 16 years ago

Main: Cleaned up the long standing const BSTR = const (OLECHAR *) on WIn32 vs (const PRunichar) * on XPCOM clash. Cleaned up BSTR/GUID macros (IN_BSTR replaces INPTR BSTR, IN_GUID replaces INPTR GUIDPARAM, OUT_GUID replaces GUIDPARAMOUT).

  • 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 15051 2008-12-05 17:20:00Z 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
27// constructor / destructor
28/////////////////////////////////////////////////////////////////////////////
29
30DEFINE_EMPTY_CTOR_DTOR (OUSBDevice)
31
32HRESULT OUSBDevice::FinalConstruct()
33{
34 return S_OK;
35}
36
37void OUSBDevice::FinalRelease()
38{
39 uninit ();
40}
41
42// public initializer/uninitializer for internal purposes only
43/////////////////////////////////////////////////////////////////////////////
44
45/**
46 * Initializes the USB device object.
47 *
48 * @returns COM result indicator
49 * @param aUSBDevice The USB device (interface) to clone.
50 */
51HRESULT OUSBDevice::init(IUSBDevice *aUSBDevice)
52{
53 LogFlowThisFunc (("aUSBDevice=%p\n", aUSBDevice));
54
55 ComAssertRet (aUSBDevice, E_INVALIDARG);
56
57 /* Enclose the state transition NotReady->InInit->Ready */
58 AutoInitSpan autoInitSpan (this);
59 AssertReturn (autoInitSpan.isOk(), E_FAIL);
60
61 HRESULT hrc = aUSBDevice->COMGETTER(VendorId)(&unconst (mData.vendorId));
62 ComAssertComRCRet (hrc, hrc);
63 ComAssertRet (mData.vendorId, E_INVALIDARG);
64
65 hrc = aUSBDevice->COMGETTER(ProductId)(&unconst (mData.productId));
66 ComAssertComRCRet (hrc, hrc);
67 ComAssertRet (mData.productId, E_INVALIDARG);
68
69 hrc = aUSBDevice->COMGETTER(Revision)(&unconst (mData.revision));
70 ComAssertComRCRet (hrc, hrc);
71
72 hrc = aUSBDevice->COMGETTER(Manufacturer)(unconst (mData.manufacturer).asOutParam());
73 ComAssertComRCRet (hrc, hrc);
74
75 hrc = aUSBDevice->COMGETTER(Product)(unconst (mData.product).asOutParam());
76 ComAssertComRCRet (hrc, hrc);
77
78 hrc = aUSBDevice->COMGETTER(SerialNumber)(unconst (mData.serialNumber).asOutParam());
79 ComAssertComRCRet (hrc, hrc);
80
81 hrc = aUSBDevice->COMGETTER(Address)(unconst (mData.address).asOutParam());
82 ComAssertComRCRet (hrc, hrc);
83
84 hrc = aUSBDevice->COMGETTER(Port)(&unconst (mData.port));
85 ComAssertComRCRet (hrc, hrc);
86
87 hrc = aUSBDevice->COMGETTER(Port)(&unconst (mData.version));
88 ComAssertComRCRet (hrc, hrc);
89
90 hrc = aUSBDevice->COMGETTER(Port)(&unconst (mData.portVersion));
91 ComAssertComRCRet (hrc, hrc);
92
93 hrc = aUSBDevice->COMGETTER(Remote)(&unconst (mData.remote));
94 ComAssertComRCRet (hrc, hrc);
95
96 hrc = aUSBDevice->COMGETTER(Id)(unconst (mData.id).asOutParam());
97 ComAssertComRCRet (hrc, hrc);
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)(OUT_GUID aId)
147{
148 CheckComArgOutPointerValid(aId);
149
150 AutoCaller autoCaller (this);
151 CheckComRCReturnRC (autoCaller.rc());
152
153 /* this is const, no need to lock */
154 mData.id.cloneTo (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 CheckComRCReturnRC (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 CheckComRCReturnRC (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 CheckComRCReturnRC (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 CheckComRCReturnRC (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 CheckComRCReturnRC (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 CheckComRCReturnRC (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 CheckComRCReturnRC (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 CheckComRCReturnRC (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 CheckComRCReturnRC (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 CheckComRCReturnRC (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 CheckComRCReturnRC (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