VirtualBox

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

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

Removed some obsolete VRDP code.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 5.3 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 HRESULT init(uint32_t u32ClientId, VRDPUSBDEVICEDESC *pDevDesc);
57 void uninit();
58
59 // IUSBDevice properties
60 STDMETHOD(COMGETTER(Id)) (GUIDPARAMOUT aId);
61 STDMETHOD(COMGETTER(VendorId)) (USHORT *aVendorId);
62 STDMETHOD(COMGETTER(ProductId)) (USHORT *aProductId);
63 STDMETHOD(COMGETTER(Revision)) (USHORT *aRevision);
64 STDMETHOD(COMGETTER(Manufacturer)) (BSTR *aManufacturer);
65 STDMETHOD(COMGETTER(Product)) (BSTR *aProduct);
66 STDMETHOD(COMGETTER(SerialNumber)) (BSTR *aSerialNumber);
67 STDMETHOD(COMGETTER(Address)) (BSTR *aAddress);
68 STDMETHOD(COMGETTER(Port)) (USHORT *aPort);
69 STDMETHOD(COMGETTER(Remote)) (BOOL *aRemote);
70
71 // IHostUSBDevice properties
72 STDMETHOD(COMGETTER(State)) (USBDeviceState_T *aState);
73
74 // public methods only for internal purposes
75 bool dirty (void) { return mDirty; }
76 void dirty (bool aDirty) { mDirty = aDirty; }
77
78 uint16_t devId (void) { return mDevId; }
79 uint32_t clientId (void) { return mClientId; }
80
81 bool captured (void) { return mState == USBDeviceState_USBDeviceCaptured; }
82 void captured (bool aCaptured)
83 {
84 if (aCaptured)
85 {
86 Assert(mState == USBDeviceState_USBDeviceAvailable);
87 mState = USBDeviceState_USBDeviceCaptured;
88 }
89 else
90 {
91 Assert(mState == USBDeviceState_USBDeviceCaptured);
92 mState = USBDeviceState_USBDeviceAvailable;
93 }
94 }
95
96 // for VirtualBoxSupportErrorInfoImpl
97 static const wchar_t *getComponentName() { return L"RemoteUSBDevice"; }
98
99private:
100
101 Guid mId;
102
103 uint16_t mVendorId;
104 uint16_t mProductId;
105 uint16_t mRevision;
106
107 Bstr mManufacturer;
108 Bstr mProduct;
109 Bstr mSerialNumber;
110
111 Bstr mAddress;
112
113 uint16_t mPort;
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