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