VirtualBox

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

Last change on this file since 14981 was 14949, checked in by vboxsync, 16 years ago

Appended vim modeline to set tabstop and expand tabs (in the way
suggested by our coding guidelines).

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 5.9 KB
Line 
1/* $Id: RemoteUSBDeviceImpl.h 14949 2008-12-03 15:17:16Z vboxsync $ */
2
3/** @file
4 *
5 * VirtualBox IHostUSBDevice COM interface implementation
6 * for remote (VRDP) USB devices
7 */
8
9/*
10 * Copyright (C) 2006-2008 Sun Microsystems, Inc.
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
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.
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.
23 */
24
25#ifndef ____H_REMOTEUSBDEVICEIMPL
26#define ____H_REMOTEUSBDEVICEIMPL
27
28#include "VirtualBoxBase.h"
29#include "Collection.h"
30
31struct _VRDPUSBDEVICEDESC;
32typedef _VRDPUSBDEVICEDESC VRDPUSBDEVICEDESC;
33
34class ATL_NO_VTABLE RemoteUSBDevice :
35 public VirtualBoxBaseNEXT,
36 public VirtualBoxSupportErrorInfoImpl <RemoteUSBDevice, IHostUSBDevice>,
37 public VirtualBoxSupportTranslation <RemoteUSBDevice>,
38 public IHostUSBDevice
39{
40public:
41
42 VIRTUALBOXBASE_ADD_ERRORINFO_SUPPORT (OUSBDevice)
43
44 DECLARE_NOT_AGGREGATABLE (RemoteUSBDevice)
45
46 DECLARE_PROTECT_FINAL_CONSTRUCT()
47
48 BEGIN_COM_MAP (RemoteUSBDevice)
49 COM_INTERFACE_ENTRY (ISupportErrorInfo)
50 COM_INTERFACE_ENTRY (IHostUSBDevice)
51 COM_INTERFACE_ENTRY (IUSBDevice)
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
66 STDMETHOD(COMGETTER(Id)) (GUIDPARAMOUT aId);
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);
75 STDMETHOD(COMGETTER(Version)) (USHORT *aVersion);
76 STDMETHOD(COMGETTER(PortVersion)) (USHORT *aPortVersion);
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
83 bool dirty (void) const { return mData.dirty; }
84 void dirty (bool aDirty) { mData.dirty = aDirty; }
85
86 uint16_t devId (void) const { return mData.devId; }
87 uint32_t clientId (void) { return mData.clientId; }
88
89 bool captured (void) const { return mData.state == USBDeviceState_Captured; }
90 void captured (bool aCaptured)
91 {
92 if (aCaptured)
93 {
94 Assert(mData.state == USBDeviceState_Available);
95 mData.state = USBDeviceState_Captured;
96 }
97 else
98 {
99 Assert(mData.state == USBDeviceState_Captured);
100 mData.state = USBDeviceState_Available;
101 }
102 }
103
104 // for VirtualBoxSupportErrorInfoImpl
105 static const wchar_t *getComponentName() { return L"RemoteUSBDevice"; }
106
107private:
108
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) {}
113
114 const Guid id;
115
116 const uint16_t vendorId;
117 const uint16_t productId;
118 const uint16_t revision;
119
120 const Bstr manufacturer;
121 const Bstr product;
122 const Bstr serialNumber;
123
124 const Bstr address;
125
126 const uint16_t port;
127 const uint16_t version;
128 const uint16_t portVersion;
129
130 USBDeviceState_T state;
131 bool dirty;
132
133 const uint16_t devId;
134 const uint32_t clientId;
135 };
136
137 Data mData;
138};
139
140COM_DECL_READONLY_ENUM_AND_COLLECTION_EX_BEGIN (ComObjPtr <RemoteUSBDevice>, IHostUSBDevice, RemoteUSBDevice)
141
142 STDMETHOD(FindById) (INPTR GUIDPARAM aId, IHostUSBDevice **aDevice)
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
170 STDMETHOD(FindByAddress) (INPTR BSTR aAddress, IHostUSBDevice **aDevice)
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
197COM_DECL_READONLY_ENUM_AND_COLLECTION_EX_END (ComObjPtr <RemoteUSBDevice>, IHostUSBDevice, RemoteUSBDevice)
198
199
200#endif // ____H_REMOTEUSBDEVICEIMPL
201/* vi: set tabstop=4 shiftwidth=4 expandtab: */
Note: See TracBrowser for help on using the repository browser.

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