VirtualBox

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

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

The Giant CDDL Dual-License Header Change.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 6.6 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 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 (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
19#ifndef ____H_USBPROXYSERVICE
20#define ____H_USBPROXYSERVICE
21
22#ifndef VBOXBFE_WITH_USB
23# error "misconfiguration VBOXBFE_WITH_USB isn't defined and USBProxyService.h was included."
24#endif
25
26#include "HostUSBImpl.h"
27#include "HostUSBDeviceImpl.h"
28
29/**
30 * Base class for the USB Proxy service.
31 */
32class USBProxyService
33{
34public:
35 USBProxyService (HostUSB *aHost);
36 virtual ~USBProxyService();
37
38 /**
39 * A VM is trying to capture a device, do necessary preperations.
40 *
41 * @returns VBox status code.
42 * @param pDevice The device in question.
43 */
44 virtual int captureDevice (HostUSBDevice *pDevice);
45
46 /**
47 * The device is to be held so that the host OS will not start using it.
48 *
49 * @returns VBox status code.
50 * @param pDevice The device in question.
51 */
52 virtual int holdDevice (HostUSBDevice *pDevice);
53
54 /**
55 * A VM is releasing a device back to the host.
56 *
57 * @returns VBox status code.
58 * @param pDevice The device in question.
59 */
60 virtual int releaseDevice (HostUSBDevice *pDevice);
61
62 /**
63 * A VM is releasing a device back to be held or assigned to another VM.
64 * A port reset should be performed.
65 *
66 * @returns VBox status code.
67 * @param pDevice The device in question.
68 */
69 virtual int resetDevice (HostUSBDevice *pDevice);
70
71 /**
72 * Query if the service is active and working.
73 *
74 * @returns true if the service is up running.
75 * @returns false if the service isn't running.
76 */
77 bool isActive (void);
78
79 /**
80 * Get last error.
81 * Can be used to check why the proxy !isActive() upon construction.
82 *
83 * @returns VBox status code.
84 */
85 int getLastError (void);
86
87 /**
88 * Calculate the hash of the serial string.
89 *
90 * 64bit FNV1a, chosen because it is designed to hash in to a power of two
91 * space, and is much quicker and simpler than, say, a half MD4.
92 *
93 * @returns the hash.
94 * @param aSerial The serial string.
95 */
96 static uint64_t calcSerialHash (const char *aSerial);
97
98protected:
99
100 /**
101 * Starts the service.
102 *
103 * @returns VBox status.
104 */
105 int start (void);
106
107 /**
108 * Stops the service.
109 *
110 * @returns VBox status.
111 */
112 int stop (void);
113
114 /**
115 * Wait for a change in the USB devices attached to the host.
116 *
117 * @returns VBox status (ignored).
118 * @param aMillies Number of milliseconds to wait.
119 */
120 virtual int wait (unsigned aMillies);
121
122 /**
123 * Interrupt any wait() call in progress.
124 *
125 * @returns VBox status.
126 */
127 virtual int interruptWait (void);
128
129 /**
130 * Get a list of USB device currently attached to the host.
131 *
132 * @returns Pointer to a list of USB devices.
133 * The list nodes are freed individually by calling freeDevice().
134 */
135 virtual PUSBDEVICE getDevices (void);
136
137public:
138 /**
139 * Free all the members of a USB interface returned by getDevice().
140 *
141 * @param pIf Pointer to the interface.
142 * @param cIfs Number of consecutive interfaces pIf points to
143 */
144 static void freeInterfaceMembers (PUSBINTERFACE pIf, unsigned cIfs);
145
146 /**
147 * Free one USB device returned by getDevice().
148 *
149 * @param pDevice Pointer to the device.
150 */
151 static void freeDevice (PUSBDEVICE pDevice);
152
153private:
154 /**
155 * Process any relevant changes in the attached USB devices.
156 */
157 void processChanges (void);
158
159 /**
160 * The service thread created by start().
161 *
162 * @param Thread The thread handle.
163 * @param pvUser Pointer to the USBProxyService instance.
164 */
165 static DECLCALLBACK (int) serviceThread (RTTHREAD Thread, void *pvUser);
166
167protected:
168 /** Pointer to the HostUSB object. */
169 HostUSB *mHost;
170 /** Thread handle of the service thread. */
171 RTTHREAD mThread;
172 /** Flag which stop() sets to cause serviceThread to return. */
173 bool volatile mTerminate;
174 /** List of smart HostUSBDevice pointers. */
175 typedef std::list <HostUSBDevice *> HostUSBDeviceList;
176 /** List of the known USB devices. */
177 HostUSBDeviceList mDevices;
178 /** VBox status code of the last failure.
179 * (Only used by start(), stop() and the child constructors.) */
180 int mLastError;
181};
182
183
184#if defined(RT_OS_LINUX) || defined(RT_OS_L4)
185#include <stdio.h>
186
187/**
188 * The Linux hosted USB Proxy Service.
189 */
190class USBProxyServiceLinux : public USBProxyService
191{
192public:
193 USBProxyServiceLinux (HostUSB *aHost, const char *aUsbfsRoot = "/proc/bus/usb");
194 ~USBProxyServiceLinux();
195
196 virtual int captureDevice (HostUSBDevice *aDevice);
197 virtual int holdDevice (HostUSBDevice *aDevice);
198 virtual int releaseDevice (HostUSBDevice *aDevice);
199 virtual int resetDevice (HostUSBDevice *aDevice);
200
201protected:
202 virtual int wait (unsigned aMillies);
203 virtual int interruptWait (void);
204 virtual PUSBDEVICE getDevices (void);
205
206private:
207 /** File handle to the '/proc/bus/usb/devices' file. */
208 RTFILE mFile;
209 /** Stream for mFile. */
210 FILE *mStream;
211 /** Pipe used to interrupt wait(), the read end. */
212 RTFILE mWakeupPipeR;
213 /** Pipe used to interrupt wait(), the write end. */
214 RTFILE mWakeupPipeW;
215 /** The root of usbfs. */
216 std::string mUsbfsRoot;
217};
218#endif /* RT_OS_LINUX */
219
220
221#ifdef RT_OS_WINDOWS
222/**
223 * The Win32/Win64 hosted USB Proxy Service.
224 */
225class USBProxyServiceWin32 : public USBProxyService
226{
227public:
228 USBProxyServiceWin32 (HostUSB *aHost);
229 ~USBProxyServiceWin32();
230
231 virtual int captureDevice (HostUSBDevice *aDevice);
232 virtual int holdDevice (HostUSBDevice *aDevice);
233 virtual int releaseDevice (HostUSBDevice *aDevice);
234 virtual int resetDevice (HostUSBDevice *aDevice);
235
236protected:
237 virtual int wait (unsigned aMillies);
238 virtual int interruptWait (void);
239 virtual PUSBDEVICE getDevices (void);
240
241private:
242
243 HANDLE hEventInterrupt;
244};
245#endif
246
247
248#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