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