VirtualBox

source: vbox/trunk/src/VBox/Main/include/USBProxyService.h@ 1313

Last change on this file since 1313 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: 6.8 KB
Line 
1/** @file
2 * VirtualBox USB Proxy Service (base) class.
3 */
4
5/*
6 * Copyright (C) 2006 InnoTek Systemberatung GmbH
7 *
8 * This file is part of VirtualBox Open Source Edition (OSE), as
9 * available from http://www.virtualbox.org. This file is free software;
10 * you can redistribute it and/or modify it under the terms of the GNU
11 * General Public License as published by the Free Software Foundation,
12 * in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
13 * distribution. VirtualBox OSE is distributed in the hope that it will
14 * be useful, but WITHOUT ANY WARRANTY of any kind.
15 *
16 * If you received this file as part of a commercial VirtualBox
17 * distribution, then only the terms of your commercial VirtualBox
18 * license agreement apply instead of the previous paragraph.
19 */
20
21
22#ifndef ____H_USBPROXYSERVICE
23#define ____H_USBPROXYSERVICE
24
25#include "HostImpl.h"
26#include "HostUSBDeviceImpl.h"
27
28/**
29 * Base class for the USB Proxy service.
30 */
31class USBProxyService
32{
33public:
34 USBProxyService (Host *aHost);
35 virtual ~USBProxyService();
36
37 /**
38 * A filter was inserted / loaded.
39 *
40 * @param aFilter Pointer to the inserted filter.
41 * @return ID of the inserted filter
42 */
43 virtual void *insertFilter (IUSBDeviceFilter *aFilter);
44
45 /**
46 * A filter was removed.
47 *
48 * @param aID ID of the filter to remove
49 */
50 virtual void removeFilter (void *aID);
51
52 /**
53 * A VM is trying to capture a device, do necessary preperations.
54 *
55 * @returns VBox status code.
56 * @param pDevice The device in question.
57 */
58 virtual int captureDevice (HostUSBDevice *pDevice);
59
60 /**
61 * The device is to be held so that the host OS will not start using it.
62 *
63 * @returns VBox status code.
64 * @param pDevice The device in question.
65 */
66 virtual int holdDevice (HostUSBDevice *pDevice);
67
68 /**
69 * A VM is releasing a device back to the host.
70 *
71 * @returns VBox status code.
72 * @param pDevice The device in question.
73 */
74 virtual int releaseDevice (HostUSBDevice *pDevice);
75
76 /**
77 * A VM is releaseing a device back to be held or assigned to another VM.
78 * A port reset should be performed.
79 *
80 * @returns VBox status code.
81 * @param pDevice The device in question.
82 */
83 virtual int resetDevice (HostUSBDevice *pDevice);
84
85 /**
86 * Query if the service is active and working.
87 *
88 * @returns true if the service is up running.
89 * @returns false if the service isn't running.
90 */
91 bool isActive (void);
92
93 /**
94 * Get last error.
95 * Can be used to check why the proxy !isActive() upon construction.
96 *
97 * @returns VBox status code.
98 */
99 int getLastError (void);
100
101 /**
102 * Calculate the hash of the serial string.
103 *
104 * 64bit FNV1a, chosen because it is designed to hash in to a power of two
105 * space, and is much quicker and simpler than, say, a half MD4.
106 *
107 * @returns the hash.
108 * @param aSerial The serial string.
109 */
110 static uint64_t calcSerialHash (const char *aSerial);
111
112protected:
113
114 /**
115 * Starts the service.
116 *
117 * @returns VBox status.
118 */
119 int start (void);
120
121 /**
122 * Stops the service.
123 *
124 * @returns VBox status.
125 */
126 int stop (void);
127
128 /**
129 * Wait for a change in the USB devices attached to the host.
130 *
131 * @returns VBox status (ignored).
132 * @param aMillies Number of milliseconds to wait.
133 */
134 virtual int wait (unsigned aMillies);
135
136 /**
137 * Interrupt any wait() call in progress.
138 *
139 * @returns VBox status.
140 */
141 virtual int interruptWait (void);
142
143 /**
144 * Get a list of USB device currently attached to the host.
145 *
146 * @returns Pointer to a list of USB devices.
147 * The list nodes are freed individually by calling freeDevice().
148 */
149 virtual PUSBDEVICE getDevices (void);
150
151public:
152 /**
153 * Free one USB device returned by getDevice().
154 *
155 * @param pDevice Pointer to the device.
156 */
157 static void freeDevice (PUSBDEVICE pDevice);
158
159private:
160 /**
161 * Process any relevant changes in the attached USB devices.
162 */
163 void processChanges (void);
164
165 /**
166 * The service thread created by start().
167 *
168 * @param Thread The thread handle.
169 * @param pvUser Pointer to the USBProxyService instance.
170 */
171 static DECLCALLBACK (int) serviceThread (RTTHREAD Thread, void *pvUser);
172
173protected:
174 /** Pointer to the Host object. */
175 Host *mHost;
176 /** Thread handle of the service thread. */
177 RTTHREAD mThread;
178 /** Flag which stop() sets to cause serviceThread to return. */
179 bool volatile mTerminate;
180 /** List of smart HostUSBDevice pointers. */
181 typedef std::list <ComObjPtr <HostUSBDevice> > HostUSBDeviceList;
182 /** List of the known USB devices. */
183 HostUSBDeviceList mDevices;
184 /** VBox status code of the last failure.
185 * (Only used by start(), stop() and the child constructors.) */
186 int mLastError;
187};
188
189
190#ifdef VBOX_WITH_USB
191
192# ifdef __LINUX__
193# include <stdio.h>
194
195/**
196 * The Linux hosted USB Proxy Service.
197 */
198class USBProxyServiceLinux : public USBProxyService
199{
200public:
201 USBProxyServiceLinux (Host *aHost, const char *aUsbfsRoot = "/proc/bus/usb");
202 ~USBProxyServiceLinux();
203
204 virtual int captureDevice (HostUSBDevice *aDevice);
205 virtual int holdDevice (HostUSBDevice *aDevice);
206 virtual int releaseDevice (HostUSBDevice *aDevice);
207 virtual int resetDevice (HostUSBDevice *aDevice);
208
209protected:
210 virtual int wait (unsigned aMillies);
211 virtual int interruptWait (void);
212 virtual PUSBDEVICE getDevices (void);
213
214private:
215 /** File handle to the '/proc/bus/usb/devices' file. */
216 RTFILE mFile;
217 /** Stream for mFile. */
218 FILE *mStream;
219 /** Pipe used to interrupt wait(), the read end. */
220 RTFILE mWakeupPipeR;
221 /** Pipe used to interrupt wait(), the write end. */
222 RTFILE mWakeupPipeW;
223 /** The root of usbfs. */
224 Utf8Str mUsbfsRoot;
225};
226# endif /* __LINUX__ */
227
228
229# ifdef __WIN__
230/**
231 * The Win32 hosted USB Proxy Service.
232 */
233class USBProxyServiceWin32 : public USBProxyService
234{
235public:
236 USBProxyServiceWin32 (Host *aHost);
237 ~USBProxyServiceWin32();
238
239 virtual void *insertFilter (IUSBDeviceFilter *aFilter);
240 virtual void removeFilter (void *aID);
241
242 virtual int captureDevice (HostUSBDevice *aDevice);
243 virtual int holdDevice (HostUSBDevice *aDevice);
244 virtual int releaseDevice (HostUSBDevice *aDevice);
245 virtual int resetDevice (HostUSBDevice *aDevice);
246
247protected:
248 virtual int wait (unsigned aMillies);
249 virtual int interruptWait (void);
250 virtual PUSBDEVICE getDevices (void);
251
252private:
253
254 HANDLE hEventInterrupt;
255};
256# endif /* __WIN__ */
257
258#endif /* VBOX_WITH_USB */
259
260
261#endif /* !____H_USBPROXYSERVICE */
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