VirtualBox

source: vbox/trunk/src/VBox/Main/include/HostUSBDeviceImpl.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: 6.8 KB
Line 
1/** @file
2 *
3 * VirtualBox IHostUSBDevice COM interface implementation
4 */
5
6/*
7 * Copyright (C) 2006-2007 innotek GmbH
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.215389.xyz. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License as published by the Free Software Foundation,
13 * in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
14 * distribution. VirtualBox OSE is distributed in the hope that it will
15 * be useful, but WITHOUT ANY WARRANTY of any kind.
16 *
17 * If you received this file as part of a commercial VirtualBox
18 * distribution, then only the terms of your commercial VirtualBox
19 * license agreement apply instead of the previous paragraph.
20 */
21
22#ifndef ____H_HOSTUSBDEVICEIMPL
23#define ____H_HOSTUSBDEVICEIMPL
24
25#include "VirtualBoxBase.h"
26#include "USBDeviceFilterImpl.h"
27/* #include "USBProxyService.h" circular on Host/HostUSBDevice, the includer
28 * must include this. */
29#include "Collection.h"
30
31#include <VBox/usb.h>
32
33class SessionMachine;
34class USBProxyService;
35
36/**
37 * Object class used to hold Host USB Device properties.
38 */
39class ATL_NO_VTABLE HostUSBDevice :
40 public VirtualBoxBaseNEXT,
41 public VirtualBoxSupportErrorInfoImpl <HostUSBDevice, IHostUSBDevice>,
42 public VirtualBoxSupportTranslation <HostUSBDevice>,
43 public IHostUSBDevice
44{
45public:
46
47 VIRTUALBOXBASE_ADD_ERRORINFO_SUPPORT (HostUSBDevice)
48
49 DECLARE_NOT_AGGREGATABLE(HostUSBDevice)
50
51 DECLARE_PROTECT_FINAL_CONSTRUCT()
52
53 BEGIN_COM_MAP(HostUSBDevice)
54 COM_INTERFACE_ENTRY(ISupportErrorInfo)
55 COM_INTERFACE_ENTRY(IHostUSBDevice)
56 COM_INTERFACE_ENTRY(IUSBDevice)
57 END_COM_MAP()
58
59 NS_DECL_ISUPPORTS
60
61 DECLARE_EMPTY_CTOR_DTOR (HostUSBDevice)
62
63 HRESULT FinalConstruct();
64 void FinalRelease();
65
66 // public initializer/uninitializer for internal purposes only
67 HRESULT init(PUSBDEVICE aUsb, USBProxyService *aUSBProxyService);
68 void uninit();
69
70 // IUSBDevice properties
71 STDMETHOD(COMGETTER(Id))(GUIDPARAMOUT aId);
72 STDMETHOD(COMGETTER(VendorId))(USHORT *aVendorId);
73 STDMETHOD(COMGETTER(ProductId))(USHORT *aProductId);
74 STDMETHOD(COMGETTER(Revision))(USHORT *aRevision);
75 STDMETHOD(COMGETTER(Manufacturer))(BSTR *aManufacturer);
76 STDMETHOD(COMGETTER(Product))(BSTR *aProduct);
77 STDMETHOD(COMGETTER(SerialNumber))(BSTR *aSerialNumber);
78 STDMETHOD(COMGETTER(Address))(BSTR *aAddress);
79 STDMETHOD(COMGETTER(Port))(USHORT *aPort);
80 STDMETHOD(COMGETTER(Remote))(BOOL *aRemote);
81
82 // IHostUSBDevice properties
83 STDMETHOD(COMGETTER(State))(USBDeviceState_T *aState);
84
85 // public methods only for internal purposes
86
87 /* @note Must be called from under the object read lock. */
88 const Guid &id() const { return mId; }
89
90 /* @note Must be called from under the object read lock. */
91 USBDeviceState_T state() const { return mState; }
92
93 /** Same as state() except you don't need to lock any thing. */
94 USBDeviceState_T stateUnlocked() const
95 {
96 AutoReaderLock (this);
97 return state();
98 }
99
100 /* @note Must be called from under the object read lock. */
101 USBDeviceState_T pendingState() const { return mPendingState; }
102
103 /** Same as pendingState() except you don't need to lock any thing. */
104 USBDeviceState_T pendingStateUnlocked() const
105 {
106 AutoReaderLock (this);
107 return pendingState();
108 }
109
110 /* @note Must be called from under the object read lock. */
111 ComObjPtr <SessionMachine, ComWeakRef> &machine() { return mMachine; }
112
113/// @todo remove
114#if 0
115 /* @note Must be called from under the object read lock. */
116 bool isIgnored() { return mIgnored; }
117#endif
118
119 /* @note Must be called from under the object read lock. */
120 bool isStatePending() const { return mIsStatePending; }
121
122 /** Same as isStatePending() except you don't need to lock any thing. */
123 bool isStatePendingUnlocked() const
124 {
125 AutoReaderLock (this);
126 return isStatePending();
127 }
128
129 /* @note Must be called from under the object read lock. */
130 PCUSBDEVICE usbData() const { return mUsb; }
131
132 Utf8Str name();
133
134/// @todo remove
135#if 0
136 void setIgnored();
137#endif
138
139 bool setCaptured (SessionMachine *aMachine);
140 int setHostDriven();
141 int reset();
142
143/// @todo remove
144#if 0
145 void setHostState (USBDeviceState_T aState);
146#endif
147
148 bool isMatch (const USBDeviceFilter::Data &aData);
149
150 int compare (PCUSBDEVICE pDev2);
151 static int compare (PCUSBDEVICE pDev1, PCUSBDEVICE pDev2);
152
153 bool updateState (PCUSBDEVICE aDev);
154
155 // for VirtualBoxSupportErrorInfoImpl
156 static const wchar_t *getComponentName() { return L"HostUSBDevice"; }
157
158private:
159
160 const Guid mId;
161 USBDeviceState_T mState;
162 USBDeviceState_T mPendingState;
163 ComObjPtr <SessionMachine, ComWeakRef> mMachine;
164 bool mIsStatePending : 1;
165/// @todo remove
166#if 0
167 bool mIgnored : 1;
168#endif
169
170 /** Pointer to the USB Proxy Service instance. */
171 USBProxyService *mUSBProxyService;
172
173 /** Pointer to the USB Device structure owned by this device.
174 * Only used for host devices. */
175 PUSBDEVICE mUsb;
176};
177
178
179COM_DECL_READONLY_ENUM_AND_COLLECTION_BEGIN (HostUSBDevice)
180
181 STDMETHOD(FindById) (INPTR GUIDPARAM aId, IHostUSBDevice **aDevice)
182 {
183 Guid idToFind = aId;
184 if (idToFind.isEmpty())
185 return E_INVALIDARG;
186 if (!aDevice)
187 return E_POINTER;
188
189 *aDevice = NULL;
190 Vector::value_type found;
191 Vector::iterator it = vec.begin();
192 while (!found && it != vec.end())
193 {
194 Guid id;
195 (*it)->COMGETTER(Id) (id.asOutParam());
196 if (id == idToFind)
197 found = *it;
198 ++ it;
199 }
200
201 if (!found)
202 return setError (E_INVALIDARG, HostUSBDeviceCollection::tr (
203 "Could not find a USB device with UUID {%s}"),
204 idToFind.toString().raw());
205
206 return found.queryInterfaceTo (aDevice);
207 }
208
209 STDMETHOD(FindByAddress) (INPTR BSTR aAddress, IHostUSBDevice **aDevice)
210 {
211 if (!aAddress)
212 return E_INVALIDARG;
213 if (!aDevice)
214 return E_POINTER;
215
216 *aDevice = NULL;
217 Vector::value_type found;
218 Vector::iterator it = vec.begin();
219 while (!found && it != vec.end())
220 {
221 Bstr address;
222 (*it)->COMGETTER(Address) (address.asOutParam());
223 if (address == aAddress)
224 found = *it;
225 ++ it;
226 }
227
228 if (!found)
229 return setError (E_INVALIDARG, HostUSBDeviceCollection::tr (
230 "Could not find a USB device with address '%ls'"),
231 aAddress);
232
233 return found.queryInterfaceTo (aDevice);
234 }
235
236COM_DECL_READONLY_ENUM_AND_COLLECTION_END (HostUSBDevice)
237
238
239#endif // ____H_HOSTUSBDEVICEIMPL
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