1 | /** @file
|
---|
2 | *
|
---|
3 | * VirtualBox Remote USB backend
|
---|
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_REMOTEUSBBACKEND
|
---|
23 | #define ____H_REMOTEUSBBACKEND
|
---|
24 |
|
---|
25 | #include "RemoteUSBDeviceImpl.h"
|
---|
26 |
|
---|
27 | #include <VBox/vrdpapi.h>
|
---|
28 | #include <VBox/vrdpusb.h>
|
---|
29 |
|
---|
30 | typedef enum
|
---|
31 | {
|
---|
32 | RDLIdle = 0,
|
---|
33 | RDLReqSent,
|
---|
34 | RDLObtained
|
---|
35 | } RDLState;
|
---|
36 |
|
---|
37 | class Console;
|
---|
38 | class ConsoleVRDPServer;
|
---|
39 |
|
---|
40 | #ifdef VRDP_MC
|
---|
41 |
|
---|
42 | /* How many remote devices can be attached to a remote client.
|
---|
43 | * Normally a client computer has 2-8 physical USB ports, so 16 devices
|
---|
44 | * should be usually enough.
|
---|
45 | */
|
---|
46 | #define VRDP_MAX_USB_DEVICES_PER_CLIENT (16)
|
---|
47 |
|
---|
48 | class RemoteUSBBackendListable
|
---|
49 | {
|
---|
50 | public:
|
---|
51 | RemoteUSBBackendListable *pNext;
|
---|
52 | RemoteUSBBackendListable *pPrev;
|
---|
53 |
|
---|
54 | RemoteUSBBackendListable() : pNext (NULL), pPrev (NULL) {};
|
---|
55 | };
|
---|
56 | #endif /* VRDP_MC */
|
---|
57 |
|
---|
58 | #ifdef VRDP_MC
|
---|
59 | class RemoteUSBBackend: public RemoteUSBBackendListable
|
---|
60 | #else
|
---|
61 | class RemoteUSBBackend
|
---|
62 | #endif /* VRDP_MC */
|
---|
63 | {
|
---|
64 | public:
|
---|
65 |
|
---|
66 | #ifdef VRDP_MC
|
---|
67 | RemoteUSBBackend(Console *console, ConsoleVRDPServer *server, uint32_t u32ClientId);
|
---|
68 | ~RemoteUSBBackend();
|
---|
69 |
|
---|
70 | uint32_t ClientId (void) { return mu32ClientId; }
|
---|
71 |
|
---|
72 | void AddRef (void);
|
---|
73 | void Release (void);
|
---|
74 |
|
---|
75 | void QueryVRDPCallbackPointer (PFNVRDPUSBCALLBACK *ppfn, void **ppv);
|
---|
76 |
|
---|
77 | REMOTEUSBCALLBACK *GetBackendCallbackPointer (void) { return &mCallback; }
|
---|
78 |
|
---|
79 | void NotifyDelete (void);
|
---|
80 |
|
---|
81 | void PollRemoteDevices (void);
|
---|
82 | #else
|
---|
83 | RemoteUSBBackend(Console *console, ConsoleVRDPServer *server);
|
---|
84 | ~RemoteUSBBackend();
|
---|
85 |
|
---|
86 | int InterceptUSB (PFNVRDPUSBCALLBACK *ppfn, void **ppv);
|
---|
87 | void ReleaseUSB (void);
|
---|
88 |
|
---|
89 | REMOTEUSBCALLBACK *GetRemoteBackendCallback (void) { return &mCallback; };
|
---|
90 | #endif /* VRDP_MC */
|
---|
91 |
|
---|
92 | public: /* Functions for internal use. */
|
---|
93 |
|
---|
94 | ConsoleVRDPServer *VRDPServer (void) { return mServer; };
|
---|
95 |
|
---|
96 | #ifdef VRDP_MC
|
---|
97 | bool pollingEnabledURB (void) { return mfPollURB; }
|
---|
98 |
|
---|
99 | int saveDeviceList (const void *pvList, uint32_t cbList);
|
---|
100 |
|
---|
101 | int negotiateResponse (const VRDPUSBREQNEGOTIATERET *pret);
|
---|
102 |
|
---|
103 | int reapURB (const void *pvBody, uint32_t cbBody);
|
---|
104 |
|
---|
105 | void request (void);
|
---|
106 | void release (void);
|
---|
107 |
|
---|
108 | PREMOTEUSBDEVICE deviceFromId (VRDPUSBDEVID id);
|
---|
109 |
|
---|
110 | void addDevice (PREMOTEUSBDEVICE pDevice);
|
---|
111 | void removeDevice (PREMOTEUSBDEVICE pDevice);
|
---|
112 |
|
---|
113 | bool addUUID (const Guid *pUuid);
|
---|
114 | bool findUUID (const Guid *pUuid);
|
---|
115 | void removeUUID (const Guid *pUuid);
|
---|
116 | #else
|
---|
117 | bool pollingEnabledURB (void) { return mfPollURB; };
|
---|
118 |
|
---|
119 | void notifyThreadStarted (RTTHREAD self);
|
---|
120 | void notifyThreadFinished (void);
|
---|
121 | bool threadEnabled (void);
|
---|
122 | bool continueThread (void);
|
---|
123 |
|
---|
124 | bool needRDL (void);
|
---|
125 | void notifyRDLSent (void);
|
---|
126 |
|
---|
127 | int negotiateResponse (VRDPUSBREQNEGOTIATERET *pret);
|
---|
128 |
|
---|
129 | int saveDeviceList (void *pvList, uint32_t cbList);
|
---|
130 | bool processRDL (void);
|
---|
131 |
|
---|
132 | void request (void);
|
---|
133 | void release (void);
|
---|
134 |
|
---|
135 | void waitEvent (unsigned cMillies);
|
---|
136 |
|
---|
137 | void addDevice (PREMOTEUSBDEVICE pDevice);
|
---|
138 | void removeDevice (PREMOTEUSBDEVICE pDevice);
|
---|
139 |
|
---|
140 | PREMOTEUSBDEVICE deviceFromId (VRDPUSBDEVID id);
|
---|
141 |
|
---|
142 | int reapURB (void *pvBody, uint32_t cbBody);
|
---|
143 | #endif /* VRDP_MC */
|
---|
144 |
|
---|
145 | private:
|
---|
146 |
|
---|
147 | #ifndef VRDP_MC
|
---|
148 | void initMembers (void);
|
---|
149 | #endif /* !VRDP_MC */
|
---|
150 |
|
---|
151 | Console *mConsole;
|
---|
152 | ConsoleVRDPServer *mServer;
|
---|
153 |
|
---|
154 | #ifdef VRDP_MC
|
---|
155 | int cRefs;
|
---|
156 |
|
---|
157 | uint32_t mu32ClientId;
|
---|
158 |
|
---|
159 | RTCRITSECT mCritsect;
|
---|
160 |
|
---|
161 | REMOTEUSBCALLBACK mCallback;
|
---|
162 |
|
---|
163 | bool mfHasDeviceList;
|
---|
164 |
|
---|
165 | void *mpvDeviceList;
|
---|
166 | uint32_t mcbDeviceList;
|
---|
167 |
|
---|
168 | typedef enum {
|
---|
169 | PollRemoteDevicesStatus_Negotiate,
|
---|
170 | PollRemoteDevicesStatus_WaitNegotiateResponse,
|
---|
171 | PollRemoteDevicesStatus_SendRequest,
|
---|
172 | PollRemoteDevicesStatus_WaitResponse,
|
---|
173 | PollRemoteDevicesStatus_Dereferenced
|
---|
174 | } PollRemoteDevicesStatus;
|
---|
175 |
|
---|
176 | PollRemoteDevicesStatus menmPollRemoteDevicesStatus;
|
---|
177 |
|
---|
178 | bool mfPollURB;
|
---|
179 |
|
---|
180 | PREMOTEUSBDEVICE mpDevices;
|
---|
181 |
|
---|
182 | bool mfWillBeDeleted;
|
---|
183 |
|
---|
184 | Guid aGuids[VRDP_MAX_USB_DEVICES_PER_CLIENT];
|
---|
185 | #else
|
---|
186 | RTCRITSECT mCritsect;
|
---|
187 | RTSEMEVENT mEvent;
|
---|
188 |
|
---|
189 | REMOTEUSBCALLBACK mCallback;
|
---|
190 |
|
---|
191 | RTTHREAD mThread;
|
---|
192 |
|
---|
193 | bool mfThreadActive;
|
---|
194 | bool mfThreadEnabled;
|
---|
195 | bool mfTerminateThread;
|
---|
196 |
|
---|
197 | RDLState menmRDLState;
|
---|
198 |
|
---|
199 | void *mpvDeviceList;
|
---|
200 | uint32_t mcbDeviceList;
|
---|
201 |
|
---|
202 | PREMOTEUSBDEVICE mpDevices;
|
---|
203 |
|
---|
204 | bool mfPollURB;
|
---|
205 | #endif /* VRDP_MC */
|
---|
206 | };
|
---|
207 |
|
---|
208 | #endif /* ____H_REMOTEUSBBACKEND */
|
---|