VirtualBox

source: vbox/trunk/src/VBox/Frontends/VBoxBFE/USBProxyService.h@ 8539

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

Drop the USBDEVICE bits we don't currently need.

  • 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 *
3 * VBox frontends: Basic Frontend (BFE):
4 * Declaration of USBProxyService and USBProxyServiceLinux classes
5 */
6
7/*
8 * Copyright (C) 2006-2007 Sun Microsystems, Inc.
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 (GPL) as published by the Free Software
14 * Foundation, in version 2 as it comes in the "COPYING" file of the
15 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
16 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
17 *
18 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
19 * Clara, CA 95054 USA or visit http://www.sun.com if you need
20 * additional information or have any questions.
21 */
22
23#ifndef ____H_USBPROXYSERVICE
24#define ____H_USBPROXYSERVICE
25
26#ifndef VBOXBFE_WITH_USB
27# error "misconfiguration VBOXBFE_WITH_USB isn't defined and USBProxyService.h was included."
28#endif
29
30#include "HostUSBImpl.h"
31#include "HostUSBDeviceImpl.h"
32
33/**
34 * Base class for the USB Proxy service.
35 */
36class USBProxyService
37{
38public:
39 USBProxyService (HostUSB *aHost);
40 virtual ~USBProxyService();
41
42 /**
43 * A VM is trying to capture a device, do necessary preperations.
44 *
45 * @returns VBox status code.
46 * @param pDevice The device in question.
47 */
48 virtual int captureDevice (HostUSBDevice *pDevice);
49
50 /**
51 * The device is to be held so that the host OS will not start using it.
52 *
53 * @returns VBox status code.
54 * @param pDevice The device in question.
55 */
56 virtual int holdDevice (HostUSBDevice *pDevice);
57
58 /**
59 * A VM is releasing a device back to the host.
60 *
61 * @returns VBox status code.
62 * @param pDevice The device in question.
63 */
64 virtual int releaseDevice (HostUSBDevice *pDevice);
65
66 /**
67 * A VM is releasing a device back to be held or assigned to another VM.
68 * A port reset should be performed.
69 *
70 * @returns VBox status code.
71 * @param pDevice The device in question.
72 */
73 virtual int resetDevice (HostUSBDevice *pDevice);
74
75 /**
76 * Query if the service is active and working.
77 *
78 * @returns true if the service is up running.
79 * @returns false if the service isn't running.
80 */
81 bool isActive (void);
82
83 /**
84 * Get last error.
85 * Can be used to check why the proxy !isActive() upon construction.
86 *
87 * @returns VBox status code.
88 */
89 int getLastError (void);
90
91 /**
92 * Calculate the hash of the serial string.
93 *
94 * 64bit FNV1a, chosen because it is designed to hash in to a power of two
95 * space, and is much quicker and simpler than, say, a half MD4.
96 *
97 * @returns the hash.
98 * @param aSerial The serial string.
99 */
100 static uint64_t calcSerialHash (const char *aSerial);
101
102protected:
103
104 /**
105 * Starts the service.
106 *
107 * @returns VBox status.
108 */
109 int start (void);
110
111 /**
112 * Stops the service.
113 *
114 * @returns VBox status.
115 */
116 int stop (void);
117
118 /**
119 * Wait for a change in the USB devices attached to the host.
120 *
121 * @returns VBox status (ignored).
122 * @param aMillies Number of milliseconds to wait.
123 */
124 virtual int wait (unsigned aMillies);
125
126 /**
127 * Interrupt any wait() call in progress.
128 *
129 * @returns VBox status.
130 */
131 virtual int interruptWait (void);
132
133 /**
134 * Get a list of USB device currently attached to the host.
135 *
136 * @returns Pointer to a list of USB devices.
137 * The list nodes are freed individually by calling freeDevice().
138 */
139 virtual PUSBDEVICE getDevices (void);
140
141public:
142#ifdef USBDEVICE_WITH_EVERYTHING
143 /**
144 * Free all the members of a USB interface returned by getDevice().
145 *
146 * @param pIf Pointer to the interface.
147 * @param cIfs Number of consecutive interfaces pIf points to
148 */
149 static void freeInterfaceMembers (PUSBINTERFACE pIf, unsigned cIfs);
150#endif
151
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 HostUSB object. */
175 HostUSB *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 <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#if defined(RT_OS_LINUX) || defined(RT_OS_L4)
191#include <stdio.h>
192
193/**
194 * The Linux hosted USB Proxy Service.
195 */
196class USBProxyServiceLinux : public USBProxyService
197{
198public:
199 USBProxyServiceLinux (HostUSB *aHost, const char *aUsbfsRoot = "/proc/bus/usb");
200 ~USBProxyServiceLinux();
201
202 virtual int captureDevice (HostUSBDevice *aDevice);
203 virtual int holdDevice (HostUSBDevice *aDevice);
204 virtual int releaseDevice (HostUSBDevice *aDevice);
205 virtual int resetDevice (HostUSBDevice *aDevice);
206
207protected:
208 virtual int wait (unsigned aMillies);
209 virtual int interruptWait (void);
210 virtual PUSBDEVICE getDevices (void);
211
212private:
213 /** File handle to the '/proc/bus/usb/devices' file. */
214 RTFILE mFile;
215 /** Stream for mFile. */
216 FILE *mStream;
217 /** Pipe used to interrupt wait(), the read end. */
218 RTFILE mWakeupPipeR;
219 /** Pipe used to interrupt wait(), the write end. */
220 RTFILE mWakeupPipeW;
221 /** The root of usbfs. */
222 std::string mUsbfsRoot;
223};
224#endif /* RT_OS_LINUX */
225
226
227#ifdef RT_OS_WINDOWS
228/**
229 * The Win32/Win64 hosted USB Proxy Service.
230 */
231class USBProxyServiceWin32 : public USBProxyService
232{
233public:
234 USBProxyServiceWin32 (HostUSB *aHost);
235 ~USBProxyServiceWin32();
236
237 virtual int captureDevice (HostUSBDevice *aDevice);
238 virtual int holdDevice (HostUSBDevice *aDevice);
239 virtual int releaseDevice (HostUSBDevice *aDevice);
240 virtual int resetDevice (HostUSBDevice *aDevice);
241
242protected:
243 virtual int wait (unsigned aMillies);
244 virtual int interruptWait (void);
245 virtual PUSBDEVICE getDevices (void);
246
247private:
248
249 HANDLE hEventInterrupt;
250};
251#endif
252
253
254#endif /* !____H_USBPROXYSERVICE */
Note: See TracBrowser for help on using the repository browser.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette