VirtualBox

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

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

The Big Sun Rebranding Header Change

  • 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 /**
143 * Free all the members of a USB interface returned by getDevice().
144 *
145 * @param pIf Pointer to the interface.
146 * @param cIfs Number of consecutive interfaces pIf points to
147 */
148 static void freeInterfaceMembers (PUSBINTERFACE pIf, unsigned cIfs);
149
150 /**
151 * Free one USB device returned by getDevice().
152 *
153 * @param pDevice Pointer to the device.
154 */
155 static void freeDevice (PUSBDEVICE pDevice);
156
157private:
158 /**
159 * Process any relevant changes in the attached USB devices.
160 */
161 void processChanges (void);
162
163 /**
164 * The service thread created by start().
165 *
166 * @param Thread The thread handle.
167 * @param pvUser Pointer to the USBProxyService instance.
168 */
169 static DECLCALLBACK (int) serviceThread (RTTHREAD Thread, void *pvUser);
170
171protected:
172 /** Pointer to the HostUSB object. */
173 HostUSB *mHost;
174 /** Thread handle of the service thread. */
175 RTTHREAD mThread;
176 /** Flag which stop() sets to cause serviceThread to return. */
177 bool volatile mTerminate;
178 /** List of smart HostUSBDevice pointers. */
179 typedef std::list <HostUSBDevice *> HostUSBDeviceList;
180 /** List of the known USB devices. */
181 HostUSBDeviceList mDevices;
182 /** VBox status code of the last failure.
183 * (Only used by start(), stop() and the child constructors.) */
184 int mLastError;
185};
186
187
188#if defined(RT_OS_LINUX) || defined(RT_OS_L4)
189#include <stdio.h>
190
191/**
192 * The Linux hosted USB Proxy Service.
193 */
194class USBProxyServiceLinux : public USBProxyService
195{
196public:
197 USBProxyServiceLinux (HostUSB *aHost, const char *aUsbfsRoot = "/proc/bus/usb");
198 ~USBProxyServiceLinux();
199
200 virtual int captureDevice (HostUSBDevice *aDevice);
201 virtual int holdDevice (HostUSBDevice *aDevice);
202 virtual int releaseDevice (HostUSBDevice *aDevice);
203 virtual int resetDevice (HostUSBDevice *aDevice);
204
205protected:
206 virtual int wait (unsigned aMillies);
207 virtual int interruptWait (void);
208 virtual PUSBDEVICE getDevices (void);
209
210private:
211 /** File handle to the '/proc/bus/usb/devices' file. */
212 RTFILE mFile;
213 /** Stream for mFile. */
214 FILE *mStream;
215 /** Pipe used to interrupt wait(), the read end. */
216 RTFILE mWakeupPipeR;
217 /** Pipe used to interrupt wait(), the write end. */
218 RTFILE mWakeupPipeW;
219 /** The root of usbfs. */
220 std::string mUsbfsRoot;
221};
222#endif /* RT_OS_LINUX */
223
224
225#ifdef RT_OS_WINDOWS
226/**
227 * The Win32/Win64 hosted USB Proxy Service.
228 */
229class USBProxyServiceWin32 : public USBProxyService
230{
231public:
232 USBProxyServiceWin32 (HostUSB *aHost);
233 ~USBProxyServiceWin32();
234
235 virtual int captureDevice (HostUSBDevice *aDevice);
236 virtual int holdDevice (HostUSBDevice *aDevice);
237 virtual int releaseDevice (HostUSBDevice *aDevice);
238 virtual int resetDevice (HostUSBDevice *aDevice);
239
240protected:
241 virtual int wait (unsigned aMillies);
242 virtual int interruptWait (void);
243 virtual PUSBDEVICE getDevices (void);
244
245private:
246
247 HANDLE hEventInterrupt;
248};
249#endif
250
251
252#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