VirtualBox

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

Last change on this file since 2644 was 1, checked in by vboxsync, 55 years ago

import

  • 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 */
5
6/*
7 * Copyright (C) 2006 InnoTek Systemberatung 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 must include this. */
28#include "Collection.h"
29
30#include <VBox/usb.h>
31
32class SessionMachine;
33class USBProxyService;
34
35/**
36 * Object class used for the Host USBDevices property.
37 */
38class ATL_NO_VTABLE HostUSBDevice :
39 public VirtualBoxSupportErrorInfoImpl <HostUSBDevice, IHostUSBDevice>,
40 public VirtualBoxSupportTranslation <HostUSBDevice>,
41 public VirtualBoxBase,
42 public IHostUSBDevice
43{
44public:
45
46 HostUSBDevice();
47 virtual ~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 // public initializer/uninitializer for internal purposes only
62 HRESULT init(PUSBDEVICE aUsb, USBProxyService *aUSBProxyService);
63
64 // IUSBDevice properties
65 STDMETHOD(COMGETTER(Id))(GUIDPARAMOUT aId);
66 STDMETHOD(COMGETTER(VendorId))(USHORT *aVendorId);
67 STDMETHOD(COMGETTER(ProductId))(USHORT *aProductId);
68 STDMETHOD(COMGETTER(Revision))(USHORT *aRevision);
69 STDMETHOD(COMGETTER(Manufacturer))(BSTR *aManufacturer);
70 STDMETHOD(COMGETTER(Product))(BSTR *aProduct);
71 STDMETHOD(COMGETTER(SerialNumber))(BSTR *aSerialNumber);
72 STDMETHOD(COMGETTER(Address))(BSTR *aAddress);
73 STDMETHOD(COMGETTER(Port))(USHORT *aPort);
74 STDMETHOD(COMGETTER(Remote))(BOOL *aRemote);
75
76 // IHostUSBDevice properties
77 STDMETHOD(COMGETTER(State))(USBDeviceState_T *aState);
78
79 // public methods only for internal purposes
80
81 const Guid &id() { return mId; }
82 USBDeviceState_T state() { return mState; }
83 ComObjPtr <SessionMachine, ComWeakRef> &machine() { return mMachine; }
84 bool isIgnored() { return mIgnored; }
85
86 Utf8Str name();
87
88 void setIgnored();
89 bool setCaptured (SessionMachine *aMachine);
90 int setHostDriven();
91 int reset();
92
93 void setHostState (USBDeviceState_T aState);
94
95 bool isMatch (const USBDeviceFilter::Data &aData);
96
97 int compare (PCUSBDEVICE pDev2);
98 static int compare (PCUSBDEVICE pDev1, PCUSBDEVICE pDev2);
99
100 bool updateState (PCUSBDEVICE aDev);
101
102 // for VirtualBoxSupportErrorInfoImpl
103 static const wchar_t *getComponentName() { return L"HostUSBDevice"; }
104
105private:
106
107 Guid mId;
108 USBDeviceState_T mState;
109 ComObjPtr <SessionMachine, ComWeakRef> mMachine;
110 bool mIgnored;
111 /** Pointer to the USB Proxy Service instance. */
112 USBProxyService *mUSBProxyService;
113
114 /** Pointer to the USB Device structure owned by this device.
115 * Only used for host devices. */
116 PUSBDEVICE m_pUsb;
117};
118
119
120COM_DECL_READONLY_ENUM_AND_COLLECTION_BEGIN (HostUSBDevice)
121
122 STDMETHOD(FindById) (INPTR GUIDPARAM aId, IHostUSBDevice **aDevice)
123 {
124 Guid idToFind = aId;
125 if (idToFind.isEmpty())
126 return E_INVALIDARG;
127 if (!aDevice)
128 return E_POINTER;
129
130 *aDevice = NULL;
131 Vector::value_type found;
132 Vector::iterator it = vec.begin();
133 while (!found && it != vec.end())
134 {
135 Guid id;
136 (*it)->COMGETTER(Id) (id.asOutParam());
137 if (id == idToFind)
138 found = *it;
139 ++ it;
140 }
141
142 if (!found)
143 return setError (E_INVALIDARG, HostUSBDeviceCollection::tr (
144 "Could not find a USB device with UUID {%s}"),
145 idToFind.toString().raw());
146
147 return found.queryInterfaceTo (aDevice);
148 }
149
150 STDMETHOD(FindByAddress) (INPTR BSTR aAddress, IHostUSBDevice **aDevice)
151 {
152 if (!aAddress)
153 return E_INVALIDARG;
154 if (!aDevice)
155 return E_POINTER;
156
157 *aDevice = NULL;
158 Vector::value_type found;
159 Vector::iterator it = vec.begin();
160 while (!found && it != vec.end())
161 {
162 Bstr address;
163 (*it)->COMGETTER(Address) (address.asOutParam());
164 if (address == aAddress)
165 found = *it;
166 ++ it;
167 }
168
169 if (!found)
170 return setError (E_INVALIDARG, HostUSBDeviceCollection::tr (
171 "Could not find a USB device with address '%ls'"),
172 aAddress);
173
174 return found.queryInterfaceTo (aDevice);
175 }
176
177COM_DECL_READONLY_ENUM_AND_COLLECTION_END (HostUSBDevice)
178
179
180#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