VirtualBox

source: vbox/trunk/src/VBox/Main/include/HostUSBDeviceImpl.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: 7.7 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.virtualbox.org. 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
18#ifndef ____H_HOSTUSBDEVICEIMPL
19#define ____H_HOSTUSBDEVICEIMPL
20
21#include "VirtualBoxBase.h"
22#include "USBDeviceFilterImpl.h"
23/* #include "USBProxyService.h" circular on Host/HostUSBDevice, the includer
24 * must include this. */
25#include "Collection.h"
26
27#include <VBox/usb.h>
28
29class SessionMachine;
30class USBProxyService;
31
32/**
33 * Object class used to hold Host USB Device properties.
34 */
35class ATL_NO_VTABLE HostUSBDevice :
36 public VirtualBoxBaseNEXT,
37 public VirtualBoxSupportErrorInfoImpl <HostUSBDevice, IHostUSBDevice>,
38 public VirtualBoxSupportTranslation <HostUSBDevice>,
39 public IHostUSBDevice
40{
41public:
42
43 VIRTUALBOXBASE_ADD_ERRORINFO_SUPPORT (HostUSBDevice)
44
45 DECLARE_NOT_AGGREGATABLE(HostUSBDevice)
46
47 DECLARE_PROTECT_FINAL_CONSTRUCT()
48
49 BEGIN_COM_MAP(HostUSBDevice)
50 COM_INTERFACE_ENTRY(ISupportErrorInfo)
51 COM_INTERFACE_ENTRY(IHostUSBDevice)
52 COM_INTERFACE_ENTRY(IUSBDevice)
53 END_COM_MAP()
54
55 NS_DECL_ISUPPORTS
56
57 DECLARE_EMPTY_CTOR_DTOR (HostUSBDevice)
58
59 HRESULT FinalConstruct();
60 void FinalRelease();
61
62 // public initializer/uninitializer for internal purposes only
63 HRESULT init(PUSBDEVICE aUsb, USBProxyService *aUSBProxyService);
64 void uninit();
65
66 // IUSBDevice properties
67 STDMETHOD(COMGETTER(Id))(GUIDPARAMOUT aId);
68 STDMETHOD(COMGETTER(VendorId))(USHORT *aVendorId);
69 STDMETHOD(COMGETTER(ProductId))(USHORT *aProductId);
70 STDMETHOD(COMGETTER(Revision))(USHORT *aRevision);
71 STDMETHOD(COMGETTER(Manufacturer))(BSTR *aManufacturer);
72 STDMETHOD(COMGETTER(Product))(BSTR *aProduct);
73 STDMETHOD(COMGETTER(SerialNumber))(BSTR *aSerialNumber);
74 STDMETHOD(COMGETTER(Address))(BSTR *aAddress);
75 STDMETHOD(COMGETTER(Port))(USHORT *aPort);
76 STDMETHOD(COMGETTER(Version))(USHORT *aVersion);
77 STDMETHOD(COMGETTER(PortVersion))(USHORT *aPortVersion);
78 STDMETHOD(COMGETTER(Remote))(BOOL *aRemote);
79
80 // IHostUSBDevice properties
81 STDMETHOD(COMGETTER(State))(USBDeviceState_T *aState);
82
83 /** Additional internal states.
84 * The async detach stuff for Darwin is a two stage journey with a variation
85 * (filters) depending on who won the race to lock the Host object.
86 *
87 * @remark Trying out mac os x style enum naming convention here. nice or what?
88 */
89 typedef enum
90 {
91 /** Nothing is pending here, check mPendingState. */
92 kNothingPending,
93 /** 1st stage of the detch, waiting for the logical detach notification. */
94 kDetachingPendingDetach,
95 /** 1st stage of the detch, waiting for the logical detach notification - re-run filters.
96 * Prev: kDetachingPendingDetach */
97 kDetachingPendingDetachFilters,
98 /** 2nd stage of the detach, waiting for the logical attach notification.
99 * Prev: kDetachingPendingDetach */
100 kDetachingPendingAttach,
101 /** 2nd stage of the detach, waiting for the logical attach notification - re-run filters.
102 * Prev: kDetachingPendingDetachFilters */
103 kDetachingPendingAttachFilters
104 } InternalState;
105
106 // public methods only for internal purposes
107
108 /** @note Must be called from under the object read lock. */
109 const Guid &id() const { return mId; }
110
111 /** @note Must be called from under the object read lock. */
112 USBDeviceState_T state() const { return mState; }
113
114 /** @note Must be called from under the object read lock. */
115 USBDeviceState_T pendingState() const { return mPendingState; }
116
117 /** @note Must be called from under the object read lock. */
118 InternalState pendingStateEx() const { return mPendingStateEx; }
119
120 /** @note Must be called from under the object read lock. */
121 ComObjPtr <SessionMachine> &machine() { return mMachine; }
122
123 /** @note Must be called from under the object read lock. */
124 bool isStatePending() const { return mIsStatePending; }
125
126 /** @note Must be called from under the object read lock. */
127 PCUSBDEVICE usbData() const { return mUsb; }
128
129 Utf8Str name();
130
131 bool requestCapture (SessionMachine *aMachine);
132 void requestRelease();
133 void requestHold();
134
135 void setHeld();
136 void onDetachedPhys();
137
138 void handlePendingStateChange();
139 void cancelPendingState(bool aTimeout = false);
140
141 bool isMatch (const USBDeviceFilter::Data &aData);
142
143 int compare (PCUSBDEVICE aDev2);
144 static int compare (PCUSBDEVICE aDev1, PCUSBDEVICE aDev2,
145 bool aIsStrict = true);
146
147 bool updateState (PCUSBDEVICE aDev);
148
149 void checkForAsyncTimeout();
150
151 bool setLogicalReconnect (InternalState aStage);
152
153 // for VirtualBoxSupportErrorInfoImpl
154 static const wchar_t *getComponentName() { return L"HostUSBDevice"; }
155
156private:
157
158 const Guid mId;
159 USBDeviceState_T mState;
160 USBDeviceState_T mPendingState;
161 /** Same as mPendingState but for the internal states. */
162 InternalState mPendingStateEx;
163 /** RTTimeNanoTS() of when mIsStatePending was set or mDetaching changed
164 * from kNotDetaching. For operations that cannot be cancelled it's 0. */
165 uint64_t mPendingSince;
166 ComObjPtr <SessionMachine> mMachine;
167 bool mIsStatePending : 1;
168
169 /** Pointer to the USB Proxy Service instance. */
170 USBProxyService *mUSBProxyService;
171
172 /** Pointer to the USB Device structure owned by this device.
173 * Only used for host devices. */
174 PUSBDEVICE mUsb;
175
176 friend class USBProxyService;
177#ifdef RT_OS_LINUX
178 friend class USBProxyServiceLinux;
179#endif
180#ifdef RT_OS_DARWIN
181 /** One-shot filter id. */
182 void *mOneShotId;
183
184 friend class USBProxyServiceDarwin;
185#endif
186};
187
188
189COM_DECL_READONLY_ENUM_AND_COLLECTION_BEGIN (HostUSBDevice)
190
191 STDMETHOD(FindById) (INPTR GUIDPARAM aId, IHostUSBDevice **aDevice)
192 {
193 Guid idToFind = aId;
194 if (idToFind.isEmpty())
195 return E_INVALIDARG;
196 if (!aDevice)
197 return E_POINTER;
198
199 *aDevice = NULL;
200 Vector::value_type found;
201 Vector::iterator it = vec.begin();
202 while (!found && it != vec.end())
203 {
204 Guid id;
205 (*it)->COMGETTER(Id) (id.asOutParam());
206 if (id == idToFind)
207 found = *it;
208 ++ it;
209 }
210
211 if (!found)
212 return setError (E_INVALIDARG, HostUSBDeviceCollection::tr (
213 "Could not find a USB device with UUID {%s}"),
214 idToFind.toString().raw());
215
216 return found.queryInterfaceTo (aDevice);
217 }
218
219 STDMETHOD(FindByAddress) (INPTR BSTR aAddress, IHostUSBDevice **aDevice)
220 {
221 if (!aAddress)
222 return E_INVALIDARG;
223 if (!aDevice)
224 return E_POINTER;
225
226 *aDevice = NULL;
227 Vector::value_type found;
228 Vector::iterator it = vec.begin();
229 while (!found && it != vec.end())
230 {
231 Bstr address;
232 (*it)->COMGETTER(Address) (address.asOutParam());
233 if (address == aAddress)
234 found = *it;
235 ++ it;
236 }
237
238 if (!found)
239 return setError (E_INVALIDARG, HostUSBDeviceCollection::tr (
240 "Could not find a USB device with address '%ls'"),
241 aAddress);
242
243 return found.queryInterfaceTo (aDevice);
244 }
245
246COM_DECL_READONLY_ENUM_AND_COLLECTION_END (HostUSBDevice)
247
248
249#endif // ____H_HOSTUSBDEVICEIMPL
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