VirtualBox

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

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

Main: back out r63429

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