[13659] | 1 | /* $Id: RemoteUSBDeviceImpl.h 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 | #ifndef ____H_REMOTEUSBDEVICEIMPL
|
---|
| 26 | #define ____H_REMOTEUSBDEVICEIMPL
|
---|
| 27 |
|
---|
| 28 | #include "VirtualBoxBase.h"
|
---|
| 29 | #include "Collection.h"
|
---|
| 30 |
|
---|
[13659] | 31 | struct _VRDPUSBDEVICEDESC;
|
---|
| 32 | typedef _VRDPUSBDEVICEDESC VRDPUSBDEVICEDESC;
|
---|
| 33 |
|
---|
[1] | 34 | class ATL_NO_VTABLE RemoteUSBDevice :
|
---|
[13659] | 35 | public VirtualBoxBaseNEXT,
|
---|
[1] | 36 | public VirtualBoxSupportErrorInfoImpl <RemoteUSBDevice, IHostUSBDevice>,
|
---|
| 37 | public VirtualBoxSupportTranslation <RemoteUSBDevice>,
|
---|
| 38 | public IHostUSBDevice
|
---|
| 39 | {
|
---|
| 40 | public:
|
---|
| 41 |
|
---|
[13659] | 42 | VIRTUALBOXBASE_ADD_ERRORINFO_SUPPORT (OUSBDevice)
|
---|
[1] | 43 |
|
---|
[13659] | 44 | DECLARE_NOT_AGGREGATABLE (RemoteUSBDevice)
|
---|
| 45 |
|
---|
[1] | 46 | DECLARE_PROTECT_FINAL_CONSTRUCT()
|
---|
| 47 |
|
---|
[13659] | 48 | BEGIN_COM_MAP (RemoteUSBDevice)
|
---|
| 49 | COM_INTERFACE_ENTRY (ISupportErrorInfo)
|
---|
| 50 | COM_INTERFACE_ENTRY (IHostUSBDevice)
|
---|
| 51 | COM_INTERFACE_ENTRY (IUSBDevice)
|
---|
[1] | 52 | END_COM_MAP()
|
---|
| 53 |
|
---|
| 54 | NS_DECL_ISUPPORTS
|
---|
| 55 |
|
---|
| 56 | DECLARE_EMPTY_CTOR_DTOR (RemoteUSBDevice)
|
---|
| 57 |
|
---|
| 58 | HRESULT FinalConstruct();
|
---|
| 59 | void FinalRelease();
|
---|
| 60 |
|
---|
| 61 | // public initializer/uninitializer for internal purposes only
|
---|
| 62 | HRESULT init(uint32_t u32ClientId, VRDPUSBDEVICEDESC *pDevDesc);
|
---|
| 63 | void uninit();
|
---|
| 64 |
|
---|
| 65 | // IUSBDevice properties
|
---|
[15051] | 66 | STDMETHOD(COMGETTER(Id)) (OUT_GUID aId);
|
---|
[1] | 67 | STDMETHOD(COMGETTER(VendorId)) (USHORT *aVendorId);
|
---|
| 68 | STDMETHOD(COMGETTER(ProductId)) (USHORT *aProductId);
|
---|
| 69 | STDMETHOD(COMGETTER(Revision)) (USHORT *aRevision);
|
---|
| 70 | STDMETHOD(COMGETTER(Manufacturer)) (BSTR *aManufacturer);
|
---|
| 71 | STDMETHOD(COMGETTER(Product)) (BSTR *aProduct);
|
---|
| 72 | STDMETHOD(COMGETTER(SerialNumber)) (BSTR *aSerialNumber);
|
---|
| 73 | STDMETHOD(COMGETTER(Address)) (BSTR *aAddress);
|
---|
| 74 | STDMETHOD(COMGETTER(Port)) (USHORT *aPort);
|
---|
[5528] | 75 | STDMETHOD(COMGETTER(Version)) (USHORT *aVersion);
|
---|
| 76 | STDMETHOD(COMGETTER(PortVersion)) (USHORT *aPortVersion);
|
---|
[1] | 77 | STDMETHOD(COMGETTER(Remote)) (BOOL *aRemote);
|
---|
| 78 |
|
---|
| 79 | // IHostUSBDevice properties
|
---|
| 80 | STDMETHOD(COMGETTER(State)) (USBDeviceState_T *aState);
|
---|
| 81 |
|
---|
| 82 | // public methods only for internal purposes
|
---|
[13659] | 83 | bool dirty (void) const { return mData.dirty; }
|
---|
| 84 | void dirty (bool aDirty) { mData.dirty = aDirty; }
|
---|
[1] | 85 |
|
---|
[13659] | 86 | uint16_t devId (void) const { return mData.devId; }
|
---|
| 87 | uint32_t clientId (void) { return mData.clientId; }
|
---|
[1] | 88 |
|
---|
[13659] | 89 | bool captured (void) const { return mData.state == USBDeviceState_Captured; }
|
---|
[1] | 90 | void captured (bool aCaptured)
|
---|
| 91 | {
|
---|
| 92 | if (aCaptured)
|
---|
| 93 | {
|
---|
[13659] | 94 | Assert(mData.state == USBDeviceState_Available);
|
---|
| 95 | mData.state = USBDeviceState_Captured;
|
---|
[1] | 96 | }
|
---|
| 97 | else
|
---|
| 98 | {
|
---|
[13659] | 99 | Assert(mData.state == USBDeviceState_Captured);
|
---|
| 100 | mData.state = USBDeviceState_Available;
|
---|
[1] | 101 | }
|
---|
| 102 | }
|
---|
| 103 |
|
---|
| 104 | // for VirtualBoxSupportErrorInfoImpl
|
---|
| 105 | static const wchar_t *getComponentName() { return L"RemoteUSBDevice"; }
|
---|
| 106 |
|
---|
| 107 | private:
|
---|
| 108 |
|
---|
[13659] | 109 | struct Data
|
---|
| 110 | {
|
---|
| 111 | Data() : vendorId (0), productId (0), revision (0), port (0), version (1),
|
---|
| 112 | portVersion (1), dirty (FALSE), devId (0), clientId (0) {}
|
---|
[1] | 113 |
|
---|
[13659] | 114 | const Guid id;
|
---|
[1] | 115 |
|
---|
[13659] | 116 | const uint16_t vendorId;
|
---|
| 117 | const uint16_t productId;
|
---|
| 118 | const uint16_t revision;
|
---|
[1] | 119 |
|
---|
[13659] | 120 | const Bstr manufacturer;
|
---|
| 121 | const Bstr product;
|
---|
| 122 | const Bstr serialNumber;
|
---|
[1] | 123 |
|
---|
[13659] | 124 | const Bstr address;
|
---|
[1] | 125 |
|
---|
[13659] | 126 | const uint16_t port;
|
---|
| 127 | const uint16_t version;
|
---|
| 128 | const uint16_t portVersion;
|
---|
[1] | 129 |
|
---|
[13659] | 130 | USBDeviceState_T state;
|
---|
| 131 | bool dirty;
|
---|
| 132 |
|
---|
| 133 | const uint16_t devId;
|
---|
| 134 | const uint32_t clientId;
|
---|
| 135 | };
|
---|
| 136 |
|
---|
| 137 | Data mData;
|
---|
[1] | 138 | };
|
---|
| 139 |
|
---|
[436] | 140 | COM_DECL_READONLY_ENUM_AND_COLLECTION_EX_BEGIN (ComObjPtr <RemoteUSBDevice>, IHostUSBDevice, RemoteUSBDevice)
|
---|
[1] | 141 |
|
---|
[15051] | 142 | STDMETHOD(FindById) (IN_GUID aId, IHostUSBDevice **aDevice)
|
---|
[1] | 143 | {
|
---|
| 144 | Guid idToFind = aId;
|
---|
| 145 | if (idToFind.isEmpty())
|
---|
| 146 | return E_INVALIDARG;
|
---|
| 147 | if (!aDevice)
|
---|
| 148 | return E_POINTER;
|
---|
| 149 |
|
---|
| 150 | *aDevice = NULL;
|
---|
| 151 | Vector::value_type found;
|
---|
| 152 | Vector::iterator it = vec.begin();
|
---|
| 153 | while (!found && it != vec.end())
|
---|
| 154 | {
|
---|
| 155 | Guid id;
|
---|
| 156 | (*it)->COMGETTER(Id) (id.asOutParam());
|
---|
| 157 | if (id == idToFind)
|
---|
| 158 | found = *it;
|
---|
| 159 | ++ it;
|
---|
| 160 | }
|
---|
| 161 |
|
---|
| 162 | if (!found)
|
---|
| 163 | return setError (E_INVALIDARG, RemoteUSBDeviceCollection::tr (
|
---|
| 164 | "Could not find a USB device with UUID {%s}"),
|
---|
| 165 | idToFind.toString().raw());
|
---|
| 166 |
|
---|
| 167 | return found.queryInterfaceTo (aDevice);
|
---|
| 168 | }
|
---|
| 169 |
|
---|
[15051] | 170 | STDMETHOD(FindByAddress) (IN_BSTR aAddress, IHostUSBDevice **aDevice)
|
---|
[1] | 171 | {
|
---|
| 172 | if (!aAddress)
|
---|
| 173 | return E_INVALIDARG;
|
---|
| 174 | if (!aDevice)
|
---|
| 175 | return E_POINTER;
|
---|
| 176 |
|
---|
| 177 | *aDevice = NULL;
|
---|
| 178 | Vector::value_type found;
|
---|
| 179 | Vector::iterator it = vec.begin();
|
---|
| 180 | while (!found && it != vec.end())
|
---|
| 181 | {
|
---|
| 182 | Bstr address;
|
---|
| 183 | (*it)->COMGETTER(Address) (address.asOutParam());
|
---|
| 184 | if (address == aAddress)
|
---|
| 185 | found = *it;
|
---|
| 186 | ++ it;
|
---|
| 187 | }
|
---|
| 188 |
|
---|
| 189 | if (!found)
|
---|
| 190 | return setError (E_INVALIDARG, RemoteUSBDeviceCollection::tr (
|
---|
| 191 | "Could not find a USB device with address '%ls'"),
|
---|
| 192 | aAddress);
|
---|
| 193 |
|
---|
| 194 | return found.queryInterfaceTo (aDevice);
|
---|
| 195 | }
|
---|
| 196 |
|
---|
[436] | 197 | COM_DECL_READONLY_ENUM_AND_COLLECTION_EX_END (ComObjPtr <RemoteUSBDevice>, IHostUSBDevice, RemoteUSBDevice)
|
---|
[1] | 198 |
|
---|
| 199 |
|
---|
| 200 | #endif // ____H_REMOTEUSBDEVICEIMPL
|
---|
[14949] | 201 | /* vi: set tabstop=4 shiftwidth=4 expandtab: */
|
---|