VirtualBox

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

Last change on this file since 2981 was 2981, checked in by vboxsync, 18 years ago

InnoTek -> innotek: all the headers and comments.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 5.4 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 * If you received this file as part of a commercial VirtualBox
19 * distribution, then only the terms of your commercial VirtualBox
20 * license agreement apply instead of the previous paragraph.
21 */
22
23#ifndef ____H_REMOTEUSBDEVICEIMPL
24#define ____H_REMOTEUSBDEVICEIMPL
25
26#include "VirtualBoxBase.h"
27#include "Collection.h"
28#include <VBox/vrdpapi.h>
29
30class ATL_NO_VTABLE RemoteUSBDevice :
31 public VirtualBoxSupportErrorInfoImpl <RemoteUSBDevice, IHostUSBDevice>,
32 public VirtualBoxSupportTranslation <RemoteUSBDevice>,
33 public VirtualBoxBase,
34 public IHostUSBDevice
35{
36public:
37
38 DECLARE_NOT_AGGREGATABLE(RemoteUSBDevice)
39
40 DECLARE_PROTECT_FINAL_CONSTRUCT()
41
42 BEGIN_COM_MAP(RemoteUSBDevice)
43 COM_INTERFACE_ENTRY(ISupportErrorInfo)
44 COM_INTERFACE_ENTRY(IHostUSBDevice)
45 COM_INTERFACE_ENTRY(IUSBDevice)
46 END_COM_MAP()
47
48 NS_DECL_ISUPPORTS
49
50 DECLARE_EMPTY_CTOR_DTOR (RemoteUSBDevice)
51
52 HRESULT FinalConstruct();
53 void FinalRelease();
54
55 // public initializer/uninitializer for internal purposes only
56#ifdef VRDP_MC
57 HRESULT init(uint32_t u32ClientId, VRDPUSBDEVICEDESC *pDevDesc);
58#else
59 HRESULT init(VRDPUSBDEVICEDESC *pDevDesc);
60#endif /* VRDP_MC */
61 void uninit();
62
63 // IUSBDevice properties
64 STDMETHOD(COMGETTER(Id)) (GUIDPARAMOUT aId);
65 STDMETHOD(COMGETTER(VendorId)) (USHORT *aVendorId);
66 STDMETHOD(COMGETTER(ProductId)) (USHORT *aProductId);
67 STDMETHOD(COMGETTER(Revision)) (USHORT *aRevision);
68 STDMETHOD(COMGETTER(Manufacturer)) (BSTR *aManufacturer);
69 STDMETHOD(COMGETTER(Product)) (BSTR *aProduct);
70 STDMETHOD(COMGETTER(SerialNumber)) (BSTR *aSerialNumber);
71 STDMETHOD(COMGETTER(Address)) (BSTR *aAddress);
72 STDMETHOD(COMGETTER(Port)) (USHORT *aPort);
73 STDMETHOD(COMGETTER(Remote)) (BOOL *aRemote);
74
75 // IHostUSBDevice properties
76 STDMETHOD(COMGETTER(State)) (USBDeviceState_T *aState);
77
78 // public methods only for internal purposes
79 bool dirty (void) { return mDirty; }
80 void dirty (bool aDirty) { mDirty = aDirty; }
81
82 uint16_t devId (void) { return mDevId; }
83#ifdef VRDP_MC
84 uint32_t clientId (void) { return mClientId; }
85#endif /* VRDP_MC */
86
87 bool captured (void) { return mState == USBDeviceState_USBDeviceCaptured; }
88 void captured (bool aCaptured)
89 {
90 if (aCaptured)
91 {
92 Assert(mState == USBDeviceState_USBDeviceAvailable);
93 mState = USBDeviceState_USBDeviceCaptured;
94 }
95 else
96 {
97 Assert(mState == USBDeviceState_USBDeviceCaptured);
98 mState = USBDeviceState_USBDeviceAvailable;
99 }
100 }
101
102 // for VirtualBoxSupportErrorInfoImpl
103 static const wchar_t *getComponentName() { return L"RemoteUSBDevice"; }
104
105private:
106
107 Guid mId;
108
109 uint16_t mVendorId;
110 uint16_t mProductId;
111 uint16_t mRevision;
112
113 Bstr mManufacturer;
114 Bstr mProduct;
115 Bstr mSerialNumber;
116
117 Bstr mAddress;
118
119 uint16_t mPort;
120
121 USBDeviceState_T mState;
122
123 bool mDirty;
124 uint16_t mDevId;
125#ifdef VRDP_MC
126 uint32_t mClientId;
127#endif /* VRDP_MC */
128};
129
130COM_DECL_READONLY_ENUM_AND_COLLECTION_EX_BEGIN (ComObjPtr <RemoteUSBDevice>, IHostUSBDevice, RemoteUSBDevice)
131
132 STDMETHOD(FindById) (INPTR GUIDPARAM aId, IHostUSBDevice **aDevice)
133 {
134 Guid idToFind = aId;
135 if (idToFind.isEmpty())
136 return E_INVALIDARG;
137 if (!aDevice)
138 return E_POINTER;
139
140 *aDevice = NULL;
141 Vector::value_type found;
142 Vector::iterator it = vec.begin();
143 while (!found && it != vec.end())
144 {
145 Guid id;
146 (*it)->COMGETTER(Id) (id.asOutParam());
147 if (id == idToFind)
148 found = *it;
149 ++ it;
150 }
151
152 if (!found)
153 return setError (E_INVALIDARG, RemoteUSBDeviceCollection::tr (
154 "Could not find a USB device with UUID {%s}"),
155 idToFind.toString().raw());
156
157 return found.queryInterfaceTo (aDevice);
158 }
159
160 STDMETHOD(FindByAddress) (INPTR BSTR aAddress, IHostUSBDevice **aDevice)
161 {
162 if (!aAddress)
163 return E_INVALIDARG;
164 if (!aDevice)
165 return E_POINTER;
166
167 *aDevice = NULL;
168 Vector::value_type found;
169 Vector::iterator it = vec.begin();
170 while (!found && it != vec.end())
171 {
172 Bstr address;
173 (*it)->COMGETTER(Address) (address.asOutParam());
174 if (address == aAddress)
175 found = *it;
176 ++ it;
177 }
178
179 if (!found)
180 return setError (E_INVALIDARG, RemoteUSBDeviceCollection::tr (
181 "Could not find a USB device with address '%ls'"),
182 aAddress);
183
184 return found.queryInterfaceTo (aDevice);
185 }
186
187COM_DECL_READONLY_ENUM_AND_COLLECTION_EX_END (ComObjPtr <RemoteUSBDevice>, IHostUSBDevice, RemoteUSBDevice)
188
189
190#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