VirtualBox

source: vbox/trunk/src/VBox/Main/include/HostUSBDeviceImpl.h@ 3117

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

Main: Fixed async USB (added proper detection of device re-cycle on Win32; changed manual release sequence so that a detach is made in VMM first, the USB proxy is notified afterwards on success; some other small fixes).

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 6.0 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 * 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 /* @note Must be called from under the object read lock. */
94 USBDeviceState_T pendingState() const { return mPendingState; }
95
96 /* @note Must be called from under the object read lock. */
97 ComObjPtr <SessionMachine> &machine() { return mMachine; }
98
99 /* @note Must be called from under the object read lock. */
100 bool isStatePending() const { return mIsStatePending; }
101
102 /* @note Must be called from under the object read lock. */
103 PCUSBDEVICE usbData() const { return mUsb; }
104
105 Utf8Str name();
106
107 bool requestCapture (SessionMachine *aMachine);
108 void requestRelease();
109 void requestHold();
110
111 void setHeld();
112 void reset();
113
114 void handlePendingStateChange();
115 void cancelPendingState();
116
117 bool isMatch (const USBDeviceFilter::Data &aData);
118
119 int compare (PCUSBDEVICE aDev2);
120 static int compare (PCUSBDEVICE aDev1, PCUSBDEVICE aDev2,
121 bool aIsStrict = true);
122
123 bool updateState (PCUSBDEVICE aDev);
124
125 // for VirtualBoxSupportErrorInfoImpl
126 static const wchar_t *getComponentName() { return L"HostUSBDevice"; }
127
128private:
129
130 const Guid mId;
131 USBDeviceState_T mState;
132 USBDeviceState_T mPendingState;
133 ComObjPtr <SessionMachine> mMachine;
134 bool mIsStatePending : 1;
135
136 /** Pointer to the USB Proxy Service instance. */
137 USBProxyService *mUSBProxyService;
138
139 /** Pointer to the USB Device structure owned by this device.
140 * Only used for host devices. */
141 PUSBDEVICE mUsb;
142};
143
144
145COM_DECL_READONLY_ENUM_AND_COLLECTION_BEGIN (HostUSBDevice)
146
147 STDMETHOD(FindById) (INPTR GUIDPARAM aId, IHostUSBDevice **aDevice)
148 {
149 Guid idToFind = aId;
150 if (idToFind.isEmpty())
151 return E_INVALIDARG;
152 if (!aDevice)
153 return E_POINTER;
154
155 *aDevice = NULL;
156 Vector::value_type found;
157 Vector::iterator it = vec.begin();
158 while (!found && it != vec.end())
159 {
160 Guid id;
161 (*it)->COMGETTER(Id) (id.asOutParam());
162 if (id == idToFind)
163 found = *it;
164 ++ it;
165 }
166
167 if (!found)
168 return setError (E_INVALIDARG, HostUSBDeviceCollection::tr (
169 "Could not find a USB device with UUID {%s}"),
170 idToFind.toString().raw());
171
172 return found.queryInterfaceTo (aDevice);
173 }
174
175 STDMETHOD(FindByAddress) (INPTR BSTR aAddress, IHostUSBDevice **aDevice)
176 {
177 if (!aAddress)
178 return E_INVALIDARG;
179 if (!aDevice)
180 return E_POINTER;
181
182 *aDevice = NULL;
183 Vector::value_type found;
184 Vector::iterator it = vec.begin();
185 while (!found && it != vec.end())
186 {
187 Bstr address;
188 (*it)->COMGETTER(Address) (address.asOutParam());
189 if (address == aAddress)
190 found = *it;
191 ++ it;
192 }
193
194 if (!found)
195 return setError (E_INVALIDARG, HostUSBDeviceCollection::tr (
196 "Could not find a USB device with address '%ls'"),
197 aAddress);
198
199 return found.queryInterfaceTo (aDevice);
200 }
201
202COM_DECL_READONLY_ENUM_AND_COLLECTION_END (HostUSBDevice)
203
204
205#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