[1] | 1 | /** @file
|
---|
| 2 | *
|
---|
| 3 | * VirtualBox IHostUSBDevice COM interface implementation
|
---|
| 4 | * for remote (VRDP) USB devices
|
---|
| 5 | */
|
---|
| 6 |
|
---|
| 7 | /*
|
---|
[8155] | 8 | * Copyright (C) 2006-2007 Sun Microsystems, Inc.
|
---|
[1] | 9 | *
|
---|
| 10 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
| 11 | * available from http://www.virtualbox.org. This file is free software;
|
---|
| 12 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
[5999] | 13 | * General Public License (GPL) as published by the Free Software
|
---|
| 14 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
| 15 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
| 16 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
[8155] | 17 | *
|
---|
| 18 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
|
---|
| 19 | * Clara, CA 95054 USA or visit http://www.sun.com if you need
|
---|
| 20 | * additional information or have any questions.
|
---|
[1] | 21 | */
|
---|
| 22 |
|
---|
| 23 | #include "RemoteUSBDeviceImpl.h"
|
---|
| 24 | #include "Logging.h"
|
---|
| 25 |
|
---|
| 26 | #include <VBox/err.h>
|
---|
| 27 |
|
---|
| 28 | #include <VBox/vrdpusb.h>
|
---|
| 29 |
|
---|
| 30 | // constructor / destructor
|
---|
| 31 | /////////////////////////////////////////////////////////////////////////////
|
---|
| 32 |
|
---|
| 33 | DEFINE_EMPTY_CTOR_DTOR (RemoteUSBDevice)
|
---|
| 34 |
|
---|
| 35 | HRESULT RemoteUSBDevice::FinalConstruct()
|
---|
| 36 | {
|
---|
| 37 | return S_OK;
|
---|
| 38 | }
|
---|
| 39 |
|
---|
| 40 | void RemoteUSBDevice::FinalRelease()
|
---|
| 41 | {
|
---|
| 42 | if (isReady())
|
---|
| 43 | uninit();
|
---|
| 44 | }
|
---|
| 45 |
|
---|
| 46 | // public initializer/uninitializer for internal purposes only
|
---|
| 47 | /////////////////////////////////////////////////////////////////////////////
|
---|
| 48 |
|
---|
| 49 | /** @todo (sunlover) REMOTE_USB Device states. */
|
---|
| 50 |
|
---|
| 51 | /**
|
---|
| 52 | * Initializes the remote USB device object.
|
---|
| 53 | */
|
---|
| 54 | HRESULT RemoteUSBDevice::init (uint32_t u32ClientId, VRDPUSBDEVICEDESC *pDevDesc)
|
---|
| 55 | {
|
---|
| 56 | LogFlowMember (("RemoteUSBDevice::init()\n"));
|
---|
| 57 |
|
---|
[8083] | 58 | AutoWriteLock alock (this);
|
---|
[1] | 59 | ComAssertRet (!isReady(), E_UNEXPECTED);
|
---|
| 60 |
|
---|
| 61 | mId.create();
|
---|
| 62 |
|
---|
| 63 | mVendorId = pDevDesc->idVendor;
|
---|
| 64 | mProductId = pDevDesc->idProduct;
|
---|
| 65 | mRevision = pDevDesc->bcdRev;
|
---|
| 66 |
|
---|
| 67 | mManufacturer = pDevDesc->oManufacturer? (char *)pDevDesc + pDevDesc->oManufacturer: "";
|
---|
| 68 | mProduct = pDevDesc->oProduct? (char *)pDevDesc + pDevDesc->oProduct: "";
|
---|
| 69 | mSerialNumber = pDevDesc->oSerialNumber? (char *)pDevDesc + pDevDesc->oSerialNumber: "";
|
---|
| 70 |
|
---|
| 71 | char id[64];
|
---|
| 72 | RTStrPrintf(id, sizeof (id), REMOTE_USB_BACKEND_PREFIX_S "0x%08X&0x%08X", pDevDesc->id, u32ClientId);
|
---|
| 73 | mAddress = id;
|
---|
| 74 |
|
---|
| 75 | mPort = pDevDesc->idPort;
|
---|
[5528] | 76 | mVersion = pDevDesc->bcdUSB >> 8;
|
---|
| 77 | mPortVersion = mVersion; /** @todo fix this */
|
---|
[1] | 78 |
|
---|
[7207] | 79 | mState = USBDeviceState_Available;
|
---|
[1] | 80 |
|
---|
| 81 | mDirty = false;
|
---|
| 82 | mDevId = pDevDesc->id;
|
---|
| 83 |
|
---|
| 84 | mClientId = u32ClientId;
|
---|
| 85 |
|
---|
| 86 | setReady (true);
|
---|
| 87 | return S_OK;
|
---|
| 88 | }
|
---|
| 89 |
|
---|
| 90 |
|
---|
| 91 | /**
|
---|
| 92 | * Uninitializes the instance and sets the ready flag to FALSE.
|
---|
| 93 | * Called either from FinalRelease() or by the parent when it gets destroyed.
|
---|
| 94 | */
|
---|
| 95 | void RemoteUSBDevice::uninit()
|
---|
| 96 | {
|
---|
| 97 | LogFlowMember (("RemoteUSBDevice::uninit()\n"));
|
---|
| 98 |
|
---|
[8083] | 99 | AutoWriteLock alock (this);
|
---|
[1] | 100 | AssertReturn (isReady(), (void) 0);
|
---|
| 101 |
|
---|
| 102 | setReady (false);
|
---|
| 103 | }
|
---|
| 104 |
|
---|
| 105 | // IUSBDevice properties
|
---|
| 106 | /////////////////////////////////////////////////////////////////////////////
|
---|
| 107 |
|
---|
| 108 | STDMETHODIMP RemoteUSBDevice::COMGETTER(Id) (GUIDPARAMOUT aId)
|
---|
| 109 | {
|
---|
| 110 | if (!aId)
|
---|
| 111 | return E_INVALIDARG;
|
---|
| 112 |
|
---|
[8083] | 113 | AutoWriteLock alock (this);
|
---|
[1] | 114 | CHECK_READY();
|
---|
| 115 |
|
---|
| 116 | mId.cloneTo (aId);
|
---|
| 117 | return S_OK;
|
---|
| 118 | }
|
---|
| 119 |
|
---|
| 120 | STDMETHODIMP RemoteUSBDevice::COMGETTER(VendorId) (USHORT *aVendorId)
|
---|
| 121 | {
|
---|
| 122 | if (!aVendorId)
|
---|
| 123 | return E_INVALIDARG;
|
---|
| 124 |
|
---|
[8083] | 125 | AutoWriteLock alock (this);
|
---|
[1] | 126 | CHECK_READY();
|
---|
| 127 |
|
---|
| 128 | *aVendorId = mVendorId;
|
---|
| 129 | return S_OK;
|
---|
| 130 | }
|
---|
| 131 |
|
---|
| 132 | STDMETHODIMP RemoteUSBDevice::COMGETTER(ProductId) (USHORT *aProductId)
|
---|
| 133 | {
|
---|
| 134 | if (!aProductId)
|
---|
| 135 | return E_INVALIDARG;
|
---|
| 136 |
|
---|
[8083] | 137 | AutoWriteLock alock (this);
|
---|
[1] | 138 | CHECK_READY();
|
---|
| 139 |
|
---|
| 140 | *aProductId = mProductId;
|
---|
| 141 | return S_OK;
|
---|
| 142 | }
|
---|
| 143 |
|
---|
| 144 | STDMETHODIMP RemoteUSBDevice::COMGETTER(Revision) (USHORT *aRevision)
|
---|
| 145 | {
|
---|
| 146 | if (!aRevision)
|
---|
| 147 | return E_INVALIDARG;
|
---|
| 148 |
|
---|
[8083] | 149 | AutoWriteLock alock (this);
|
---|
[1] | 150 | CHECK_READY();
|
---|
| 151 |
|
---|
| 152 | *aRevision = mRevision;
|
---|
| 153 | return S_OK;
|
---|
| 154 | }
|
---|
| 155 |
|
---|
| 156 | STDMETHODIMP RemoteUSBDevice::COMGETTER(Manufacturer) (BSTR *aManufacturer)
|
---|
| 157 | {
|
---|
| 158 | if (!aManufacturer)
|
---|
| 159 | return E_INVALIDARG;
|
---|
| 160 |
|
---|
[8083] | 161 | AutoWriteLock alock (this);
|
---|
[1] | 162 | CHECK_READY();
|
---|
| 163 |
|
---|
| 164 | mManufacturer.cloneTo (aManufacturer);
|
---|
| 165 | return S_OK;
|
---|
| 166 | }
|
---|
| 167 |
|
---|
| 168 | STDMETHODIMP RemoteUSBDevice::COMGETTER(Product) (BSTR *aProduct)
|
---|
| 169 | {
|
---|
| 170 | if (!aProduct)
|
---|
| 171 | return E_INVALIDARG;
|
---|
| 172 |
|
---|
[8083] | 173 | AutoWriteLock alock (this);
|
---|
[1] | 174 | CHECK_READY();
|
---|
| 175 |
|
---|
| 176 | mProduct.cloneTo (aProduct);
|
---|
| 177 | return S_OK;
|
---|
| 178 | }
|
---|
| 179 |
|
---|
| 180 | STDMETHODIMP RemoteUSBDevice::COMGETTER(SerialNumber) (BSTR *aSerialNumber)
|
---|
| 181 | {
|
---|
| 182 | if (!aSerialNumber)
|
---|
| 183 | return E_INVALIDARG;
|
---|
| 184 |
|
---|
[8083] | 185 | AutoWriteLock alock (this);
|
---|
[1] | 186 | CHECK_READY();
|
---|
| 187 |
|
---|
| 188 | mSerialNumber.cloneTo (aSerialNumber);
|
---|
| 189 | return S_OK;
|
---|
| 190 | }
|
---|
| 191 |
|
---|
| 192 | STDMETHODIMP RemoteUSBDevice::COMGETTER(Address) (BSTR *aAddress)
|
---|
| 193 | {
|
---|
| 194 | if (!aAddress)
|
---|
| 195 | return E_INVALIDARG;
|
---|
| 196 |
|
---|
[8083] | 197 | AutoWriteLock alock (this);
|
---|
[1] | 198 | CHECK_READY();
|
---|
| 199 |
|
---|
| 200 | mAddress.cloneTo (aAddress);
|
---|
| 201 | return S_OK;
|
---|
| 202 | }
|
---|
| 203 |
|
---|
| 204 | STDMETHODIMP RemoteUSBDevice::COMGETTER(Port) (USHORT *aPort)
|
---|
| 205 | {
|
---|
| 206 | if (!aPort)
|
---|
| 207 | return E_INVALIDARG;
|
---|
| 208 |
|
---|
[8083] | 209 | AutoWriteLock alock (this);
|
---|
[1] | 210 | CHECK_READY();
|
---|
| 211 |
|
---|
| 212 | *aPort = mPort;
|
---|
| 213 | return S_OK;
|
---|
| 214 | }
|
---|
| 215 |
|
---|
[5528] | 216 | STDMETHODIMP RemoteUSBDevice::COMGETTER(Version) (USHORT *aVersion)
|
---|
| 217 | {
|
---|
| 218 | if (!aVersion)
|
---|
| 219 | return E_INVALIDARG;
|
---|
| 220 |
|
---|
[8083] | 221 | AutoWriteLock alock (this);
|
---|
[5528] | 222 | CHECK_READY();
|
---|
| 223 |
|
---|
| 224 | *aVersion = mVersion;
|
---|
| 225 | return S_OK;
|
---|
| 226 | }
|
---|
| 227 |
|
---|
| 228 | STDMETHODIMP RemoteUSBDevice::COMGETTER(PortVersion) (USHORT *aPortVersion)
|
---|
| 229 | {
|
---|
| 230 | if (!aPortVersion)
|
---|
| 231 | return E_INVALIDARG;
|
---|
| 232 |
|
---|
[8083] | 233 | AutoWriteLock alock (this);
|
---|
[5528] | 234 | CHECK_READY();
|
---|
| 235 |
|
---|
| 236 | *aPortVersion = mPortVersion;
|
---|
| 237 | return S_OK;
|
---|
| 238 | }
|
---|
| 239 |
|
---|
[1] | 240 | STDMETHODIMP RemoteUSBDevice::COMGETTER(Remote) (BOOL *aRemote)
|
---|
| 241 | {
|
---|
| 242 | if (!aRemote)
|
---|
| 243 | return E_INVALIDARG;
|
---|
| 244 |
|
---|
[8083] | 245 | AutoWriteLock alock (this);
|
---|
[1] | 246 | CHECK_READY();
|
---|
| 247 |
|
---|
| 248 | /* RemoteUSBDevice is always remote. */
|
---|
| 249 | *aRemote = TRUE;
|
---|
| 250 | return S_OK;
|
---|
| 251 | }
|
---|
| 252 |
|
---|
| 253 | // IHostUSBDevice properties
|
---|
| 254 | /////////////////////////////////////////////////////////////////////////////
|
---|
| 255 |
|
---|
| 256 | STDMETHODIMP RemoteUSBDevice::COMGETTER(State) (USBDeviceState_T *aState)
|
---|
| 257 | {
|
---|
| 258 | if (!aState)
|
---|
| 259 | return E_POINTER;
|
---|
| 260 |
|
---|
[8083] | 261 | AutoWriteLock alock (this);
|
---|
[1] | 262 | CHECK_READY();
|
---|
| 263 |
|
---|
| 264 | *aState = mState;
|
---|
| 265 | return S_OK;
|
---|
| 266 | }
|
---|
| 267 |
|
---|
| 268 | // public methods only for internal purposes
|
---|
| 269 | ////////////////////////////////////////////////////////////////////////////////
|
---|