VirtualBox

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

Last change on this file since 25414 was 25198, checked in by vboxsync, 14 years ago

Main: make StorageController instance data private

  • 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 25198 2009-12-04 17:53: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#include "Logging.h"
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
68 hrc = aUSBDevice->COMGETTER(Revision)(&unconst(mData.revision));
69 ComAssertComRCRet (hrc, hrc);
70
71 hrc = aUSBDevice->COMGETTER(Manufacturer)(unconst(mData.manufacturer).asOutParam());
72 ComAssertComRCRet (hrc, hrc);
73
74 hrc = aUSBDevice->COMGETTER(Product)(unconst(mData.product).asOutParam());
75 ComAssertComRCRet (hrc, hrc);
76
77 hrc = aUSBDevice->COMGETTER(SerialNumber)(unconst(mData.serialNumber).asOutParam());
78 ComAssertComRCRet (hrc, hrc);
79
80 hrc = aUSBDevice->COMGETTER(Address)(unconst(mData.address).asOutParam());
81 ComAssertComRCRet (hrc, hrc);
82
83 hrc = aUSBDevice->COMGETTER(Port)(&unconst(mData.port));
84 ComAssertComRCRet (hrc, hrc);
85
86 hrc = aUSBDevice->COMGETTER(Port)(&unconst(mData.version));
87 ComAssertComRCRet (hrc, hrc);
88
89 hrc = aUSBDevice->COMGETTER(Port)(&unconst(mData.portVersion));
90 ComAssertComRCRet (hrc, hrc);
91
92 hrc = aUSBDevice->COMGETTER(Remote)(&unconst(mData.remote));
93 ComAssertComRCRet (hrc, hrc);
94
95 Bstr uuid;
96 hrc = aUSBDevice->COMGETTER(Id)(uuid.asOutParam());
97 ComAssertComRCRet(hrc, hrc);
98 unconst(mData.id) = Guid(uuid);
99
100 /* Confirm a successful initialization */
101 autoInitSpan.setSucceeded();
102
103 return S_OK;
104}
105
106/**
107 * Uninitializes the instance and sets the ready flag to FALSE.
108 * Called either from FinalRelease() or by the parent when it gets destroyed.
109 */
110void OUSBDevice::uninit()
111{
112 LogFlowThisFunc(("\n"));
113
114 /* Enclose the state transition Ready->InUninit->NotReady */
115 AutoUninitSpan autoUninitSpan(this);
116 if (autoUninitSpan.uninitDone())
117 return;
118
119 unconst(mData.id).clear();
120
121 unconst(mData.vendorId) = 0;
122 unconst(mData.productId) = 0;
123 unconst(mData.revision) = 0;
124
125 unconst(mData.manufacturer).setNull();
126 unconst(mData.product).setNull();
127 unconst(mData.serialNumber).setNull();
128
129 unconst(mData.address).setNull();
130
131 unconst(mData.port) = 0;
132 unconst(mData.version) = 1;
133 unconst(mData.portVersion) = 1;
134
135 unconst(mData.remote) = FALSE;
136}
137
138// IUSBDevice properties
139/////////////////////////////////////////////////////////////////////////////
140
141/**
142 * Returns the GUID.
143 *
144 * @returns COM status code
145 * @param aId Address of result variable.
146 */
147STDMETHODIMP OUSBDevice::COMGETTER(Id)(BSTR *aId)
148{
149 CheckComArgOutPointerValid(aId);
150
151 AutoCaller autoCaller(this);
152 if (FAILED(autoCaller.rc())) return autoCaller.rc();
153
154 /* this is const, no need to lock */
155 Guid(mData.id).toString().cloneTo(aId);
156
157 return S_OK;
158}
159
160
161/**
162 * Returns the vendor Id.
163 *
164 * @returns COM status code
165 * @param aVendorId Where to store the vendor id.
166 */
167STDMETHODIMP OUSBDevice::COMGETTER(VendorId)(USHORT *aVendorId)
168{
169 CheckComArgOutPointerValid(aVendorId);
170
171 AutoCaller autoCaller(this);
172 if (FAILED(autoCaller.rc())) return autoCaller.rc();
173
174 /* this is const, no need to lock */
175 *aVendorId = mData.vendorId;
176
177 return S_OK;
178}
179
180
181/**
182 * Returns the product Id.
183 *
184 * @returns COM status code
185 * @param aProductId Where to store the product id.
186 */
187STDMETHODIMP OUSBDevice::COMGETTER(ProductId)(USHORT *aProductId)
188{
189 CheckComArgOutPointerValid(aProductId);
190
191 AutoCaller autoCaller(this);
192 if (FAILED(autoCaller.rc())) return autoCaller.rc();
193
194 /* this is const, no need to lock */
195 *aProductId = mData.productId;
196
197 return S_OK;
198}
199
200
201/**
202 * Returns the revision BCD.
203 *
204 * @returns COM status code
205 * @param aRevision Where to store the revision BCD.
206 */
207STDMETHODIMP OUSBDevice::COMGETTER(Revision)(USHORT *aRevision)
208{
209 CheckComArgOutPointerValid(aRevision);
210
211 AutoCaller autoCaller(this);
212 if (FAILED(autoCaller.rc())) return autoCaller.rc();
213
214 /* this is const, no need to lock */
215 *aRevision = mData.revision;
216
217 return S_OK;
218}
219
220/**
221 * Returns the manufacturer string.
222 *
223 * @returns COM status code
224 * @param aManufacturer Where to put the return string.
225 */
226STDMETHODIMP OUSBDevice::COMGETTER(Manufacturer)(BSTR *aManufacturer)
227{
228 CheckComArgOutPointerValid(aManufacturer);
229
230 AutoCaller autoCaller(this);
231 if (FAILED(autoCaller.rc())) return autoCaller.rc();
232
233 /* this is const, no need to lock */
234 mData.manufacturer.cloneTo(aManufacturer);
235
236 return S_OK;
237}
238
239
240/**
241 * Returns the product string.
242 *
243 * @returns COM status code
244 * @param aProduct Where to put the return string.
245 */
246STDMETHODIMP OUSBDevice::COMGETTER(Product)(BSTR *aProduct)
247{
248 CheckComArgOutPointerValid(aProduct);
249
250 AutoCaller autoCaller(this);
251 if (FAILED(autoCaller.rc())) return autoCaller.rc();
252
253 /* this is const, no need to lock */
254 mData.product.cloneTo(aProduct);
255
256 return S_OK;
257}
258
259
260/**
261 * Returns the serial number string.
262 *
263 * @returns COM status code
264 * @param aSerialNumber Where to put the return string.
265 */
266STDMETHODIMP OUSBDevice::COMGETTER(SerialNumber)(BSTR *aSerialNumber)
267{
268 CheckComArgOutPointerValid(aSerialNumber);
269
270 AutoCaller autoCaller(this);
271 if (FAILED(autoCaller.rc())) return autoCaller.rc();
272
273 /* this is const, no need to lock */
274 mData.serialNumber.cloneTo(aSerialNumber);
275
276 return S_OK;
277}
278
279
280/**
281 * Returns the host specific device address.
282 *
283 * @returns COM status code
284 * @param aAddress Where to put the return string.
285 */
286STDMETHODIMP OUSBDevice::COMGETTER(Address)(BSTR *aAddress)
287{
288 CheckComArgOutPointerValid(aAddress);
289
290 AutoCaller autoCaller(this);
291 if (FAILED(autoCaller.rc())) return autoCaller.rc();
292
293 /* this is const, no need to lock */
294 mData.address.cloneTo(aAddress);
295
296 return S_OK;
297}
298
299STDMETHODIMP OUSBDevice::COMGETTER(Port)(USHORT *aPort)
300{
301 CheckComArgOutPointerValid(aPort);
302
303 AutoCaller autoCaller(this);
304 if (FAILED(autoCaller.rc())) return autoCaller.rc();
305
306 /* this is const, no need to lock */
307 *aPort = mData.port;
308
309 return S_OK;
310}
311
312STDMETHODIMP OUSBDevice::COMGETTER(Version)(USHORT *aVersion)
313{
314 CheckComArgOutPointerValid(aVersion);
315
316 AutoCaller autoCaller(this);
317 if (FAILED(autoCaller.rc())) return autoCaller.rc();
318
319 /* this is const, no need to lock */
320 *aVersion = mData.version;
321
322 return S_OK;
323}
324
325STDMETHODIMP OUSBDevice::COMGETTER(PortVersion)(USHORT *aPortVersion)
326{
327 CheckComArgOutPointerValid(aPortVersion);
328
329 AutoCaller autoCaller(this);
330 if (FAILED(autoCaller.rc())) return autoCaller.rc();
331
332 /* this is const, no need to lock */
333 *aPortVersion = mData.portVersion;
334
335 return S_OK;
336}
337
338STDMETHODIMP OUSBDevice::COMGETTER(Remote)(BOOL *aRemote)
339{
340 CheckComArgOutPointerValid(aRemote);
341
342 AutoCaller autoCaller(this);
343 if (FAILED(autoCaller.rc())) return autoCaller.rc();
344
345 /* this is const, no need to lock */
346 *aRemote = mData.remote;
347
348 return S_OK;
349}
350
351// private methods
352/////////////////////////////////////////////////////////////////////////////
353/* vi: set tabstop=4 shiftwidth=4 expandtab: */
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use