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