VirtualBox

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

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

Biggest check-in ever. New source code headers for all (C) innotek files.

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