[13659] | 1 | /* $Id: RemoteUSBDeviceImpl.cpp 15051 2008-12-05 17:20:00Z vboxsync $ */
|
---|
| 2 |
|
---|
[1] | 3 | /** @file
|
---|
| 4 | *
|
---|
| 5 | * VirtualBox IHostUSBDevice COM interface implementation
|
---|
| 6 | * for remote (VRDP) USB devices
|
---|
| 7 | */
|
---|
| 8 |
|
---|
| 9 | /*
|
---|
[13659] | 10 | * Copyright (C) 2006-2008 Sun Microsystems, Inc.
|
---|
[1] | 11 | *
|
---|
| 12 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
| 13 | * available from http://www.virtualbox.org. This file is free software;
|
---|
| 14 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
[5999] | 15 | * General Public License (GPL) as published by the Free Software
|
---|
| 16 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
| 17 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
| 18 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
[8155] | 19 | *
|
---|
| 20 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
|
---|
| 21 | * Clara, CA 95054 USA or visit http://www.sun.com if you need
|
---|
| 22 | * additional information or have any questions.
|
---|
[1] | 23 | */
|
---|
| 24 |
|
---|
| 25 | #include "RemoteUSBDeviceImpl.h"
|
---|
| 26 | #include "Logging.h"
|
---|
| 27 |
|
---|
| 28 | #include <VBox/err.h>
|
---|
| 29 |
|
---|
[13659] | 30 | #include <VBox/vrdpapi.h>
|
---|
[1] | 31 | #include <VBox/vrdpusb.h>
|
---|
| 32 |
|
---|
| 33 | // constructor / destructor
|
---|
| 34 | /////////////////////////////////////////////////////////////////////////////
|
---|
| 35 |
|
---|
| 36 | DEFINE_EMPTY_CTOR_DTOR (RemoteUSBDevice)
|
---|
| 37 |
|
---|
| 38 | HRESULT RemoteUSBDevice::FinalConstruct()
|
---|
| 39 | {
|
---|
| 40 | return S_OK;
|
---|
| 41 | }
|
---|
| 42 |
|
---|
| 43 | void RemoteUSBDevice::FinalRelease()
|
---|
| 44 | {
|
---|
[13659] | 45 | uninit();
|
---|
[1] | 46 | }
|
---|
| 47 |
|
---|
| 48 | // public initializer/uninitializer for internal purposes only
|
---|
| 49 | /////////////////////////////////////////////////////////////////////////////
|
---|
| 50 |
|
---|
| 51 | /** @todo (sunlover) REMOTE_USB Device states. */
|
---|
| 52 |
|
---|
| 53 | /**
|
---|
| 54 | * Initializes the remote USB device object.
|
---|
| 55 | */
|
---|
| 56 | HRESULT RemoteUSBDevice::init (uint32_t u32ClientId, VRDPUSBDEVICEDESC *pDevDesc)
|
---|
| 57 | {
|
---|
[13659] | 58 | LogFlowThisFunc (("u32ClientId=%d,pDevDesc=%p\n", u32ClientId, pDevDesc));
|
---|
[1] | 59 |
|
---|
[13659] | 60 | /* Enclose the state transition NotReady->InInit->Ready */
|
---|
| 61 | AutoInitSpan autoInitSpan (this);
|
---|
[14579] | 62 | AssertReturn (autoInitSpan.isOk(), E_FAIL);
|
---|
[1] | 63 |
|
---|
[13659] | 64 | unconst (mData.id).create();
|
---|
[1] | 65 |
|
---|
[13659] | 66 | unconst (mData.vendorId) = pDevDesc->idVendor;
|
---|
| 67 | unconst (mData.productId) = pDevDesc->idProduct;
|
---|
| 68 | unconst (mData.revision) = pDevDesc->bcdRev;
|
---|
[1] | 69 |
|
---|
[13659] | 70 | unconst (mData.manufacturer) = pDevDesc->oManufacturer? (char *)pDevDesc + pDevDesc->oManufacturer: "";
|
---|
| 71 | unconst (mData.product) = pDevDesc->oProduct? (char *)pDevDesc + pDevDesc->oProduct: "";
|
---|
| 72 | unconst (mData.serialNumber) = pDevDesc->oSerialNumber? (char *)pDevDesc + pDevDesc->oSerialNumber: "";
|
---|
[1] | 73 |
|
---|
| 74 | char id[64];
|
---|
| 75 | RTStrPrintf(id, sizeof (id), REMOTE_USB_BACKEND_PREFIX_S "0x%08X&0x%08X", pDevDesc->id, u32ClientId);
|
---|
[13659] | 76 | unconst (mData.address) = id;
|
---|
[1] | 77 |
|
---|
[13659] | 78 | unconst (mData.port) = pDevDesc->idPort;
|
---|
| 79 | unconst (mData.version) = pDevDesc->bcdUSB >> 8;
|
---|
| 80 | unconst (mData.portVersion) = mData.version; /** @todo fix this */
|
---|
[1] | 81 |
|
---|
[13659] | 82 | mData.state = USBDeviceState_Available;
|
---|
[1] | 83 |
|
---|
[13659] | 84 | mData.dirty = false;
|
---|
| 85 | unconst (mData.devId) = pDevDesc->id;
|
---|
[1] | 86 |
|
---|
[13659] | 87 | unconst (mData.clientId) = u32ClientId;
|
---|
[1] | 88 |
|
---|
[13659] | 89 | /* Confirm a successful initialization */
|
---|
| 90 | autoInitSpan.setSucceeded();
|
---|
| 91 |
|
---|
[1] | 92 | return S_OK;
|
---|
| 93 | }
|
---|
| 94 |
|
---|
| 95 |
|
---|
| 96 | /**
|
---|
| 97 | * Uninitializes the instance and sets the ready flag to FALSE.
|
---|
| 98 | * Called either from FinalRelease() or by the parent when it gets destroyed.
|
---|
| 99 | */
|
---|
| 100 | void RemoteUSBDevice::uninit()
|
---|
| 101 | {
|
---|
[13659] | 102 | LogFlowThisFunc (("\n"));
|
---|
[1] | 103 |
|
---|
[13659] | 104 | /* Enclose the state transition Ready->InUninit->NotReady */
|
---|
| 105 | AutoUninitSpan autoUninitSpan (this);
|
---|
| 106 | if (autoUninitSpan.uninitDone())
|
---|
| 107 | return;
|
---|
[1] | 108 |
|
---|
[13659] | 109 | unconst (mData.id).clear();
|
---|
| 110 |
|
---|
| 111 | unconst (mData.vendorId) = 0;
|
---|
| 112 | unconst (mData.productId) = 0;
|
---|
| 113 | unconst (mData.revision) = 0;
|
---|
| 114 |
|
---|
| 115 | unconst (mData.manufacturer).setNull();
|
---|
| 116 | unconst (mData.product).setNull();
|
---|
| 117 | unconst (mData.serialNumber).setNull();
|
---|
| 118 |
|
---|
| 119 | unconst (mData.address).setNull();
|
---|
| 120 |
|
---|
| 121 | unconst (mData.port) = 0;
|
---|
| 122 | unconst (mData.version) = 1;
|
---|
| 123 | unconst (mData.portVersion) = 1;
|
---|
| 124 |
|
---|
| 125 | unconst (mData.dirty) = FALSE;
|
---|
| 126 |
|
---|
| 127 | unconst (mData.devId) = 0;
|
---|
| 128 | unconst (mData.clientId) = 0;
|
---|
[1] | 129 | }
|
---|
| 130 |
|
---|
| 131 | // IUSBDevice properties
|
---|
| 132 | /////////////////////////////////////////////////////////////////////////////
|
---|
| 133 |
|
---|
[15051] | 134 | STDMETHODIMP RemoteUSBDevice::COMGETTER(Id) (OUT_GUID aId)
|
---|
[1] | 135 | {
|
---|
[14972] | 136 | CheckComArgOutPointerValid(aId);
|
---|
[1] | 137 |
|
---|
[13659] | 138 | AutoCaller autoCaller (this);
|
---|
| 139 | CheckComRCReturnRC (autoCaller.rc());
|
---|
[1] | 140 |
|
---|
[13659] | 141 | /* this is const, no need to lock */
|
---|
| 142 | mData.id.cloneTo (aId);
|
---|
| 143 |
|
---|
[1] | 144 | return S_OK;
|
---|
| 145 | }
|
---|
| 146 |
|
---|
| 147 | STDMETHODIMP RemoteUSBDevice::COMGETTER(VendorId) (USHORT *aVendorId)
|
---|
| 148 | {
|
---|
[14972] | 149 | CheckComArgOutPointerValid(aVendorId);
|
---|
[1] | 150 |
|
---|
[13659] | 151 | AutoCaller autoCaller (this);
|
---|
| 152 | CheckComRCReturnRC (autoCaller.rc());
|
---|
[1] | 153 |
|
---|
[13659] | 154 | /* this is const, no need to lock */
|
---|
| 155 | *aVendorId = mData.vendorId;
|
---|
| 156 |
|
---|
[1] | 157 | return S_OK;
|
---|
| 158 | }
|
---|
| 159 |
|
---|
| 160 | STDMETHODIMP RemoteUSBDevice::COMGETTER(ProductId) (USHORT *aProductId)
|
---|
| 161 | {
|
---|
[14972] | 162 | CheckComArgOutPointerValid(aProductId);
|
---|
[1] | 163 |
|
---|
[13659] | 164 | AutoCaller autoCaller (this);
|
---|
| 165 | CheckComRCReturnRC (autoCaller.rc());
|
---|
[1] | 166 |
|
---|
[13659] | 167 | /* this is const, no need to lock */
|
---|
| 168 | *aProductId = mData.productId;
|
---|
| 169 |
|
---|
[1] | 170 | return S_OK;
|
---|
| 171 | }
|
---|
| 172 |
|
---|
| 173 | STDMETHODIMP RemoteUSBDevice::COMGETTER(Revision) (USHORT *aRevision)
|
---|
| 174 | {
|
---|
[14972] | 175 | CheckComArgOutPointerValid(aRevision);
|
---|
[1] | 176 |
|
---|
[13659] | 177 | AutoCaller autoCaller (this);
|
---|
| 178 | CheckComRCReturnRC (autoCaller.rc());
|
---|
[1] | 179 |
|
---|
[13659] | 180 | /* this is const, no need to lock */
|
---|
| 181 | *aRevision = mData.revision;
|
---|
| 182 |
|
---|
[1] | 183 | return S_OK;
|
---|
| 184 | }
|
---|
| 185 |
|
---|
| 186 | STDMETHODIMP RemoteUSBDevice::COMGETTER(Manufacturer) (BSTR *aManufacturer)
|
---|
| 187 | {
|
---|
[14972] | 188 | CheckComArgOutPointerValid(aManufacturer);
|
---|
[1] | 189 |
|
---|
[13659] | 190 | AutoCaller autoCaller (this);
|
---|
| 191 | CheckComRCReturnRC (autoCaller.rc());
|
---|
[1] | 192 |
|
---|
[13659] | 193 | /* this is const, no need to lock */
|
---|
| 194 | mData.manufacturer.cloneTo (aManufacturer);
|
---|
| 195 |
|
---|
[1] | 196 | return S_OK;
|
---|
| 197 | }
|
---|
| 198 |
|
---|
| 199 | STDMETHODIMP RemoteUSBDevice::COMGETTER(Product) (BSTR *aProduct)
|
---|
| 200 | {
|
---|
[14972] | 201 | CheckComArgOutPointerValid(aProduct);
|
---|
[1] | 202 |
|
---|
[13659] | 203 | AutoCaller autoCaller (this);
|
---|
| 204 | CheckComRCReturnRC (autoCaller.rc());
|
---|
[1] | 205 |
|
---|
[13659] | 206 | /* this is const, no need to lock */
|
---|
| 207 | mData.product.cloneTo (aProduct);
|
---|
| 208 |
|
---|
[1] | 209 | return S_OK;
|
---|
| 210 | }
|
---|
| 211 |
|
---|
| 212 | STDMETHODIMP RemoteUSBDevice::COMGETTER(SerialNumber) (BSTR *aSerialNumber)
|
---|
| 213 | {
|
---|
[14972] | 214 | CheckComArgOutPointerValid(aSerialNumber);
|
---|
[1] | 215 |
|
---|
[13659] | 216 | AutoCaller autoCaller (this);
|
---|
| 217 | CheckComRCReturnRC (autoCaller.rc());
|
---|
[1] | 218 |
|
---|
[13659] | 219 | /* this is const, no need to lock */
|
---|
| 220 | mData.serialNumber.cloneTo (aSerialNumber);
|
---|
| 221 |
|
---|
[1] | 222 | return S_OK;
|
---|
| 223 | }
|
---|
| 224 |
|
---|
| 225 | STDMETHODIMP RemoteUSBDevice::COMGETTER(Address) (BSTR *aAddress)
|
---|
| 226 | {
|
---|
[14972] | 227 | CheckComArgOutPointerValid(aAddress);
|
---|
[1] | 228 |
|
---|
[13659] | 229 | AutoCaller autoCaller (this);
|
---|
| 230 | CheckComRCReturnRC (autoCaller.rc());
|
---|
[1] | 231 |
|
---|
[13659] | 232 | /* this is const, no need to lock */
|
---|
| 233 | mData.address.cloneTo (aAddress);
|
---|
| 234 |
|
---|
[1] | 235 | return S_OK;
|
---|
| 236 | }
|
---|
| 237 |
|
---|
| 238 | STDMETHODIMP RemoteUSBDevice::COMGETTER(Port) (USHORT *aPort)
|
---|
| 239 | {
|
---|
[14972] | 240 | CheckComArgOutPointerValid(aPort);
|
---|
[1] | 241 |
|
---|
[13659] | 242 | AutoCaller autoCaller (this);
|
---|
| 243 | CheckComRCReturnRC (autoCaller.rc());
|
---|
[1] | 244 |
|
---|
[13659] | 245 | /* this is const, no need to lock */
|
---|
| 246 | *aPort = mData.port;
|
---|
| 247 |
|
---|
[1] | 248 | return S_OK;
|
---|
| 249 | }
|
---|
| 250 |
|
---|
[5528] | 251 | STDMETHODIMP RemoteUSBDevice::COMGETTER(Version) (USHORT *aVersion)
|
---|
| 252 | {
|
---|
[14972] | 253 | CheckComArgOutPointerValid(aVersion);
|
---|
[5528] | 254 |
|
---|
[13659] | 255 | AutoCaller autoCaller (this);
|
---|
| 256 | CheckComRCReturnRC (autoCaller.rc());
|
---|
[5528] | 257 |
|
---|
[13659] | 258 | /* this is const, no need to lock */
|
---|
| 259 | *aVersion = mData.version;
|
---|
| 260 |
|
---|
[5528] | 261 | return S_OK;
|
---|
| 262 | }
|
---|
| 263 |
|
---|
| 264 | STDMETHODIMP RemoteUSBDevice::COMGETTER(PortVersion) (USHORT *aPortVersion)
|
---|
| 265 | {
|
---|
[14972] | 266 | CheckComArgOutPointerValid(aPortVersion);
|
---|
[5528] | 267 |
|
---|
[13659] | 268 | AutoCaller autoCaller (this);
|
---|
| 269 | CheckComRCReturnRC (autoCaller.rc());
|
---|
[5528] | 270 |
|
---|
[13659] | 271 | /* this is const, no need to lock */
|
---|
| 272 | *aPortVersion = mData.portVersion;
|
---|
| 273 |
|
---|
[5528] | 274 | return S_OK;
|
---|
| 275 | }
|
---|
| 276 |
|
---|
[1] | 277 | STDMETHODIMP RemoteUSBDevice::COMGETTER(Remote) (BOOL *aRemote)
|
---|
| 278 | {
|
---|
[14972] | 279 | CheckComArgOutPointerValid(aRemote);
|
---|
[1] | 280 |
|
---|
[13659] | 281 | AutoCaller autoCaller (this);
|
---|
| 282 | CheckComRCReturnRC (autoCaller.rc());
|
---|
[1] | 283 |
|
---|
| 284 | /* RemoteUSBDevice is always remote. */
|
---|
[13659] | 285 | /* this is const, no need to lock */
|
---|
[1] | 286 | *aRemote = TRUE;
|
---|
[13659] | 287 |
|
---|
[1] | 288 | return S_OK;
|
---|
| 289 | }
|
---|
| 290 |
|
---|
| 291 | // IHostUSBDevice properties
|
---|
[14972] | 292 | ////////////////////////////////////////////////////////////////////////////////
|
---|
[1] | 293 |
|
---|
| 294 | STDMETHODIMP RemoteUSBDevice::COMGETTER(State) (USBDeviceState_T *aState)
|
---|
| 295 | {
|
---|
[14972] | 296 | CheckComArgOutPointerValid(aState);
|
---|
[1] | 297 |
|
---|
[13659] | 298 | AutoCaller autoCaller (this);
|
---|
| 299 | CheckComRCReturnRC (autoCaller.rc());
|
---|
[1] | 300 |
|
---|
[13659] | 301 | AutoReadLock alock (this);
|
---|
| 302 |
|
---|
| 303 | *aState = mData.state;
|
---|
| 304 |
|
---|
[1] | 305 | return S_OK;
|
---|
| 306 | }
|
---|
| 307 |
|
---|
| 308 | // public methods only for internal purposes
|
---|
| 309 | ////////////////////////////////////////////////////////////////////////////////
|
---|
[14772] | 310 | /* vi: set tabstop=4 shiftwidth=4 expandtab: */
|
---|