VirtualBox

source: vbox/trunk/src/VBox/Main/include/RemoteUSBDeviceImpl.h@ 5528

Last change on this file since 5528 was 5528, checked in by vboxsync, 17 years ago

Added PortVersion and Version attributes for obtaining the major USB version of the port and the device respectively.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 5.2 KB
Line 
1/** @file
2 *
3 * VirtualBox IHostUSBDevice COM interface implementation
4 * for remote (VRDP) USB devices
5 */
6
7/*
8 * Copyright (C) 2006-2007 innotek GmbH
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
13 * General Public License as published by the Free Software Foundation,
14 * in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
15 * distribution. VirtualBox OSE is distributed in the hope that it will
16 * be useful, but WITHOUT ANY WARRANTY of any kind.
17 */
18
19#ifndef ____H_REMOTEUSBDEVICEIMPL
20#define ____H_REMOTEUSBDEVICEIMPL
21
22#include "VirtualBoxBase.h"
23#include "Collection.h"
24#include <VBox/vrdpapi.h>
25
26class ATL_NO_VTABLE RemoteUSBDevice :
27 public VirtualBoxSupportErrorInfoImpl <RemoteUSBDevice, IHostUSBDevice>,
28 public VirtualBoxSupportTranslation <RemoteUSBDevice>,
29 public VirtualBoxBase,
30 public IHostUSBDevice
31{
32public:
33
34 DECLARE_NOT_AGGREGATABLE(RemoteUSBDevice)
35
36 DECLARE_PROTECT_FINAL_CONSTRUCT()
37
38 BEGIN_COM_MAP(RemoteUSBDevice)
39 COM_INTERFACE_ENTRY(ISupportErrorInfo)
40 COM_INTERFACE_ENTRY(IHostUSBDevice)
41 COM_INTERFACE_ENTRY(IUSBDevice)
42 END_COM_MAP()
43
44 NS_DECL_ISUPPORTS
45
46 DECLARE_EMPTY_CTOR_DTOR (RemoteUSBDevice)
47
48 HRESULT FinalConstruct();
49 void FinalRelease();
50
51 // public initializer/uninitializer for internal purposes only
52 HRESULT init(uint32_t u32ClientId, VRDPUSBDEVICEDESC *pDevDesc);
53 void uninit();
54
55 // IUSBDevice properties
56 STDMETHOD(COMGETTER(Id)) (GUIDPARAMOUT aId);
57 STDMETHOD(COMGETTER(VendorId)) (USHORT *aVendorId);
58 STDMETHOD(COMGETTER(ProductId)) (USHORT *aProductId);
59 STDMETHOD(COMGETTER(Revision)) (USHORT *aRevision);
60 STDMETHOD(COMGETTER(Manufacturer)) (BSTR *aManufacturer);
61 STDMETHOD(COMGETTER(Product)) (BSTR *aProduct);
62 STDMETHOD(COMGETTER(SerialNumber)) (BSTR *aSerialNumber);
63 STDMETHOD(COMGETTER(Address)) (BSTR *aAddress);
64 STDMETHOD(COMGETTER(Port)) (USHORT *aPort);
65 STDMETHOD(COMGETTER(Version)) (USHORT *aVersion);
66 STDMETHOD(COMGETTER(PortVersion)) (USHORT *aPortVersion);
67 STDMETHOD(COMGETTER(Remote)) (BOOL *aRemote);
68
69 // IHostUSBDevice properties
70 STDMETHOD(COMGETTER(State)) (USBDeviceState_T *aState);
71
72 // public methods only for internal purposes
73 bool dirty (void) { return mDirty; }
74 void dirty (bool aDirty) { mDirty = aDirty; }
75
76 uint16_t devId (void) { return mDevId; }
77 uint32_t clientId (void) { return mClientId; }
78
79 bool captured (void) { return mState == USBDeviceState_USBDeviceCaptured; }
80 void captured (bool aCaptured)
81 {
82 if (aCaptured)
83 {
84 Assert(mState == USBDeviceState_USBDeviceAvailable);
85 mState = USBDeviceState_USBDeviceCaptured;
86 }
87 else
88 {
89 Assert(mState == USBDeviceState_USBDeviceCaptured);
90 mState = USBDeviceState_USBDeviceAvailable;
91 }
92 }
93
94 // for VirtualBoxSupportErrorInfoImpl
95 static const wchar_t *getComponentName() { return L"RemoteUSBDevice"; }
96
97private:
98
99 Guid mId;
100
101 uint16_t mVendorId;
102 uint16_t mProductId;
103 uint16_t mRevision;
104
105 Bstr mManufacturer;
106 Bstr mProduct;
107 Bstr mSerialNumber;
108
109 Bstr mAddress;
110
111 uint16_t mPort;
112 uint16_t mVersion;
113 uint16_t mPortVersion;
114
115 USBDeviceState_T mState;
116
117 bool mDirty;
118 uint16_t mDevId;
119 uint32_t mClientId;
120};
121
122COM_DECL_READONLY_ENUM_AND_COLLECTION_EX_BEGIN (ComObjPtr <RemoteUSBDevice>, IHostUSBDevice, RemoteUSBDevice)
123
124 STDMETHOD(FindById) (INPTR GUIDPARAM aId, IHostUSBDevice **aDevice)
125 {
126 Guid idToFind = aId;
127 if (idToFind.isEmpty())
128 return E_INVALIDARG;
129 if (!aDevice)
130 return E_POINTER;
131
132 *aDevice = NULL;
133 Vector::value_type found;
134 Vector::iterator it = vec.begin();
135 while (!found && it != vec.end())
136 {
137 Guid id;
138 (*it)->COMGETTER(Id) (id.asOutParam());
139 if (id == idToFind)
140 found = *it;
141 ++ it;
142 }
143
144 if (!found)
145 return setError (E_INVALIDARG, RemoteUSBDeviceCollection::tr (
146 "Could not find a USB device with UUID {%s}"),
147 idToFind.toString().raw());
148
149 return found.queryInterfaceTo (aDevice);
150 }
151
152 STDMETHOD(FindByAddress) (INPTR BSTR aAddress, IHostUSBDevice **aDevice)
153 {
154 if (!aAddress)
155 return E_INVALIDARG;
156 if (!aDevice)
157 return E_POINTER;
158
159 *aDevice = NULL;
160 Vector::value_type found;
161 Vector::iterator it = vec.begin();
162 while (!found && it != vec.end())
163 {
164 Bstr address;
165 (*it)->COMGETTER(Address) (address.asOutParam());
166 if (address == aAddress)
167 found = *it;
168 ++ it;
169 }
170
171 if (!found)
172 return setError (E_INVALIDARG, RemoteUSBDeviceCollection::tr (
173 "Could not find a USB device with address '%ls'"),
174 aAddress);
175
176 return found.queryInterfaceTo (aDevice);
177 }
178
179COM_DECL_READONLY_ENUM_AND_COLLECTION_EX_END (ComObjPtr <RemoteUSBDevice>, IHostUSBDevice, RemoteUSBDevice)
180
181
182#endif // ____H_REMOTEUSBDEVICEIMPL
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette