VirtualBox

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

Last change on this file since 25414 was 25198, checked in by vboxsync, 15 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
RevLine 
[13659]1/* $Id: USBDeviceImpl.cpp 25198 2009-12-04 17:53:00Z vboxsync $ */
2
[1]3/** @file
4 *
5 * VirtualBox COM class implementation
6 */
7
8/*
[13659]9 * Copyright (C) 2006-2008 Sun Microsystems, Inc.
[1]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
[5999]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.
[8155]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.
[1]22 */
23
24#include "USBDeviceImpl.h"
[25198]25#include "Logging.h"
[1]26
27// constructor / destructor
28/////////////////////////////////////////////////////////////////////////////
29
[13659]30DEFINE_EMPTY_CTOR_DTOR (OUSBDevice)
31
32HRESULT OUSBDevice::FinalConstruct()
[1]33{
[13659]34 return S_OK;
[1]35}
36
[13659]37void OUSBDevice::FinalRelease()
[1]38{
[13659]39 uninit ();
[1]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 */
[436]51HRESULT OUSBDevice::init(IUSBDevice *aUSBDevice)
[1]52{
[21878]53 LogFlowThisFunc(("aUSBDevice=%p\n", aUSBDevice));
[1]54
[13659]55 ComAssertRet (aUSBDevice, E_INVALIDARG);
56
57 /* Enclose the state transition NotReady->InInit->Ready */
[21878]58 AutoInitSpan autoInitSpan(this);
59 AssertReturn(autoInitSpan.isOk(), E_FAIL);
[13659]60
[21878]61 HRESULT hrc = aUSBDevice->COMGETTER(VendorId)(&unconst(mData.vendorId));
[1]62 ComAssertComRCRet (hrc, hrc);
[13659]63 ComAssertRet (mData.vendorId, E_INVALIDARG);
[1]64
[21878]65 hrc = aUSBDevice->COMGETTER(ProductId)(&unconst(mData.productId));
[1]66 ComAssertComRCRet (hrc, hrc);
67
[21878]68 hrc = aUSBDevice->COMGETTER(Revision)(&unconst(mData.revision));
[1]69 ComAssertComRCRet (hrc, hrc);
70
[21878]71 hrc = aUSBDevice->COMGETTER(Manufacturer)(unconst(mData.manufacturer).asOutParam());
[1]72 ComAssertComRCRet (hrc, hrc);
73
[21878]74 hrc = aUSBDevice->COMGETTER(Product)(unconst(mData.product).asOutParam());
[1]75 ComAssertComRCRet (hrc, hrc);
76
[21878]77 hrc = aUSBDevice->COMGETTER(SerialNumber)(unconst(mData.serialNumber).asOutParam());
[1]78 ComAssertComRCRet (hrc, hrc);
79
[21878]80 hrc = aUSBDevice->COMGETTER(Address)(unconst(mData.address).asOutParam());
[1]81 ComAssertComRCRet (hrc, hrc);
82
[21878]83 hrc = aUSBDevice->COMGETTER(Port)(&unconst(mData.port));
[1]84 ComAssertComRCRet (hrc, hrc);
85
[21878]86 hrc = aUSBDevice->COMGETTER(Port)(&unconst(mData.version));
[5528]87 ComAssertComRCRet (hrc, hrc);
88
[21878]89 hrc = aUSBDevice->COMGETTER(Port)(&unconst(mData.portVersion));
[5528]90 ComAssertComRCRet (hrc, hrc);
91
[21878]92 hrc = aUSBDevice->COMGETTER(Remote)(&unconst(mData.remote));
[1]93 ComAssertComRCRet (hrc, hrc);
94
[24989]95 Bstr uuid;
96 hrc = aUSBDevice->COMGETTER(Id)(uuid.asOutParam());
97 ComAssertComRCRet(hrc, hrc);
98 unconst(mData.id) = Guid(uuid);
[1]99
[13659]100 /* Confirm a successful initialization */
101 autoInitSpan.setSucceeded();
102
[1]103 return S_OK;
104}
105
[13659]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{
[21878]112 LogFlowThisFunc(("\n"));
[1]113
[13659]114 /* Enclose the state transition Ready->InUninit->NotReady */
[21878]115 AutoUninitSpan autoUninitSpan(this);
[13659]116 if (autoUninitSpan.uninitDone())
117 return;
118
[21878]119 unconst(mData.id).clear();
[13659]120
[21878]121 unconst(mData.vendorId) = 0;
122 unconst(mData.productId) = 0;
123 unconst(mData.revision) = 0;
[13659]124
[21878]125 unconst(mData.manufacturer).setNull();
126 unconst(mData.product).setNull();
127 unconst(mData.serialNumber).setNull();
[13659]128
[21878]129 unconst(mData.address).setNull();
[13659]130
[21878]131 unconst(mData.port) = 0;
132 unconst(mData.version) = 1;
133 unconst(mData.portVersion) = 1;
[13659]134
[21878]135 unconst(mData.remote) = FALSE;
[13659]136}
137
[1]138// IUSBDevice properties
139/////////////////////////////////////////////////////////////////////////////
140
141/**
142 * Returns the GUID.
143 *
144 * @returns COM status code
145 * @param aId Address of result variable.
146 */
[19239]147STDMETHODIMP OUSBDevice::COMGETTER(Id)(BSTR *aId)
[1]148{
[14972]149 CheckComArgOutPointerValid(aId);
[1]150
[21878]151 AutoCaller autoCaller(this);
[25149]152 if (FAILED(autoCaller.rc())) return autoCaller.rc();
[1]153
[13659]154 /* this is const, no need to lock */
[21878]155 Guid(mData.id).toString().cloneTo(aId);
[13659]156
[1]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 */
[436]167STDMETHODIMP OUSBDevice::COMGETTER(VendorId)(USHORT *aVendorId)
[1]168{
[14972]169 CheckComArgOutPointerValid(aVendorId);
[1]170
[21878]171 AutoCaller autoCaller(this);
[25149]172 if (FAILED(autoCaller.rc())) return autoCaller.rc();
[1]173
[13659]174 /* this is const, no need to lock */
175 *aVendorId = mData.vendorId;
176
[1]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 */
[436]187STDMETHODIMP OUSBDevice::COMGETTER(ProductId)(USHORT *aProductId)
[1]188{
[14972]189 CheckComArgOutPointerValid(aProductId);
[1]190
[21878]191 AutoCaller autoCaller(this);
[25149]192 if (FAILED(autoCaller.rc())) return autoCaller.rc();
[1]193
[13659]194 /* this is const, no need to lock */
195 *aProductId = mData.productId;
196
[1]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 */
[436]207STDMETHODIMP OUSBDevice::COMGETTER(Revision)(USHORT *aRevision)
[1]208{
[14972]209 CheckComArgOutPointerValid(aRevision);
[1]210
[21878]211 AutoCaller autoCaller(this);
[25149]212 if (FAILED(autoCaller.rc())) return autoCaller.rc();
[1]213
[13659]214 /* this is const, no need to lock */
215 *aRevision = mData.revision;
216
[1]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 */
[436]226STDMETHODIMP OUSBDevice::COMGETTER(Manufacturer)(BSTR *aManufacturer)
[1]227{
[14972]228 CheckComArgOutPointerValid(aManufacturer);
[1]229
[21878]230 AutoCaller autoCaller(this);
[25149]231 if (FAILED(autoCaller.rc())) return autoCaller.rc();
[1]232
[13659]233 /* this is const, no need to lock */
[21878]234 mData.manufacturer.cloneTo(aManufacturer);
[13659]235
[1]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 */
[436]246STDMETHODIMP OUSBDevice::COMGETTER(Product)(BSTR *aProduct)
[1]247{
[14972]248 CheckComArgOutPointerValid(aProduct);
[1]249
[21878]250 AutoCaller autoCaller(this);
[25149]251 if (FAILED(autoCaller.rc())) return autoCaller.rc();
[1]252
[13659]253 /* this is const, no need to lock */
[21878]254 mData.product.cloneTo(aProduct);
[13659]255
[1]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 */
[436]266STDMETHODIMP OUSBDevice::COMGETTER(SerialNumber)(BSTR *aSerialNumber)
[1]267{
[14972]268 CheckComArgOutPointerValid(aSerialNumber);
[1]269
[21878]270 AutoCaller autoCaller(this);
[25149]271 if (FAILED(autoCaller.rc())) return autoCaller.rc();
[1]272
[13659]273 /* this is const, no need to lock */
[21878]274 mData.serialNumber.cloneTo(aSerialNumber);
[13659]275
[1]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 */
[436]286STDMETHODIMP OUSBDevice::COMGETTER(Address)(BSTR *aAddress)
[1]287{
[14972]288 CheckComArgOutPointerValid(aAddress);
[1]289
[21878]290 AutoCaller autoCaller(this);
[25149]291 if (FAILED(autoCaller.rc())) return autoCaller.rc();
[1]292
[13659]293 /* this is const, no need to lock */
[21878]294 mData.address.cloneTo(aAddress);
[13659]295
[1]296 return S_OK;
297}
298
[436]299STDMETHODIMP OUSBDevice::COMGETTER(Port)(USHORT *aPort)
[1]300{
[14972]301 CheckComArgOutPointerValid(aPort);
[1]302
[21878]303 AutoCaller autoCaller(this);
[25149]304 if (FAILED(autoCaller.rc())) return autoCaller.rc();
[1]305
[13659]306 /* this is const, no need to lock */
307 *aPort = mData.port;
308
[1]309 return S_OK;
310}
311
[5528]312STDMETHODIMP OUSBDevice::COMGETTER(Version)(USHORT *aVersion)
313{
[14972]314 CheckComArgOutPointerValid(aVersion);
[5528]315
[21878]316 AutoCaller autoCaller(this);
[25149]317 if (FAILED(autoCaller.rc())) return autoCaller.rc();
[5528]318
[13659]319 /* this is const, no need to lock */
320 *aVersion = mData.version;
321
[5528]322 return S_OK;
323}
324
325STDMETHODIMP OUSBDevice::COMGETTER(PortVersion)(USHORT *aPortVersion)
326{
[14972]327 CheckComArgOutPointerValid(aPortVersion);
[5528]328
[21878]329 AutoCaller autoCaller(this);
[25149]330 if (FAILED(autoCaller.rc())) return autoCaller.rc();
[5528]331
[13659]332 /* this is const, no need to lock */
333 *aPortVersion = mData.portVersion;
334
[5528]335 return S_OK;
336}
337
[436]338STDMETHODIMP OUSBDevice::COMGETTER(Remote)(BOOL *aRemote)
[1]339{
[14972]340 CheckComArgOutPointerValid(aRemote);
[1]341
[21878]342 AutoCaller autoCaller(this);
[25149]343 if (FAILED(autoCaller.rc())) return autoCaller.rc();
[1]344
[13659]345 /* this is const, no need to lock */
346 *aRemote = mData.remote;
347
[1]348 return S_OK;
349}
350
351// private methods
352/////////////////////////////////////////////////////////////////////////////
[14772]353/* vi: set tabstop=4 shiftwidth=4 expandtab: */
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use