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