VirtualBox

source: vbox/trunk/src/VBox/Main/include/ConsoleVRDPServer.h@ 48701

Last change on this file since 48701 was 48406, checked in by vboxsync, 11 years ago

Main,VBoxManage: Implemented IConsole::EmulatedUSB. Removed IMachine::emulatedUSBWebcameraEnabled.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 17.2 KB
Line 
1/* $Id: ConsoleVRDPServer.h 48406 2013-09-10 12:53:50Z vboxsync $ */
2/** @file
3 * VBox Console VRDE Server Helper class and implementation of IVRDEServerInfo
4 */
5
6/*
7 * Copyright (C) 2006-2012 Oracle Corporation
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 (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 */
17
18#ifndef ____H_CONSOLEVRDPSERVER
19#define ____H_CONSOLEVRDPSERVER
20
21#include "RemoteUSBBackend.h"
22#include "HGCM.h"
23
24#include <VBox/VBoxAuth.h>
25
26#include <VBox/RemoteDesktop/VRDEImage.h>
27#include <VBox/RemoteDesktop/VRDEMousePtr.h>
28#include <VBox/RemoteDesktop/VRDESCard.h>
29#include <VBox/RemoteDesktop/VRDETSMF.h>
30#define VRDE_VIDEOIN_WITH_VRDEINTERFACE /* Get the VRDE interface definitions. */
31#include <VBox/RemoteDesktop/VRDEVideoIn.h>
32#include <VBox/RemoteDesktop/VRDEInput.h>
33
34#include <VBox/HostServices/VBoxClipboardExt.h>
35#include <VBox/HostServices/VBoxHostChannel.h>
36
37#include "SchemaDefs.h"
38
39// ConsoleVRDPServer
40///////////////////////////////////////////////////////////////////////////////
41
42typedef struct _VRDPInputSynch
43{
44 int cGuestNumLockAdaptions;
45 int cGuestCapsLockAdaptions;
46
47 bool fGuestNumLock;
48 bool fGuestCapsLock;
49 bool fGuestScrollLock;
50
51 bool fClientNumLock;
52 bool fClientCapsLock;
53 bool fClientScrollLock;
54} VRDPInputSynch;
55
56/* Member of Console. Helper class for VRDP server management. Not a COM class. */
57class ConsoleVRDPServer
58{
59public:
60 ConsoleVRDPServer (Console *console);
61 ~ConsoleVRDPServer ();
62
63 int Launch (void);
64
65 void NotifyAbsoluteMouse (bool fGuestWantsAbsolute)
66 {
67 m_fGuestWantsAbsolute = fGuestWantsAbsolute;
68 }
69
70 void NotifyKeyboardLedsChange (BOOL fNumLock, BOOL fCapsLock, BOOL fScrollLock)
71 {
72 bool fGuestNumLock = (fNumLock != FALSE);
73 bool fGuestCapsLock = (fCapsLock != FALSE);
74 bool fGuestScrollLock = (fScrollLock != FALSE);
75
76 /* Might need to resync in case the guest itself changed the LED status. */
77 if (m_InputSynch.fClientNumLock != fGuestNumLock)
78 {
79 m_InputSynch.cGuestNumLockAdaptions = 2;
80 }
81
82 if (m_InputSynch.fClientCapsLock != fGuestCapsLock)
83 {
84 m_InputSynch.cGuestCapsLockAdaptions = 2;
85 }
86
87 m_InputSynch.fGuestNumLock = fGuestNumLock;
88 m_InputSynch.fGuestCapsLock = fGuestCapsLock;
89 m_InputSynch.fGuestScrollLock = fGuestScrollLock;
90 }
91
92 void EnableConnections (void);
93 void DisconnectClient (uint32_t u32ClientId, bool fReconnect);
94 int MousePointer(BOOL alpha, ULONG xHot, ULONG yHot, ULONG width, ULONG height, const uint8_t *pu8Shape);
95 void MousePointerUpdate (const VRDECOLORPOINTER *pPointer);
96 void MousePointerHide (void);
97
98 void Stop (void);
99
100 AuthResult Authenticate (const Guid &uuid, AuthGuestJudgement guestJudgement,
101 const char *pszUser, const char *pszPassword, const char *pszDomain,
102 uint32_t u32ClientId);
103
104 void AuthDisconnect (const Guid &uuid, uint32_t u32ClientId);
105
106 void USBBackendCreate (uint32_t u32ClientId, void **ppvIntercept);
107 void USBBackendDelete (uint32_t u32ClientId);
108
109 void *USBBackendRequestPointer (uint32_t u32ClientId, const Guid *pGuid);
110 void USBBackendReleasePointer (const Guid *pGuid);
111
112 /* Private interface for the RemoteUSBBackend destructor. */
113 void usbBackendRemoveFromList (RemoteUSBBackend *pRemoteUSBBackend);
114
115 /* Private methods for the Remote USB thread. */
116 RemoteUSBBackend *usbBackendGetNext (RemoteUSBBackend *pRemoteUSBBackend);
117
118 void notifyRemoteUSBThreadRunning (RTTHREAD thread);
119 bool isRemoteUSBThreadRunning (void);
120 void waitRemoteUSBThreadEvent (RTMSINTERVAL cMillies);
121
122 void ClipboardCreate (uint32_t u32ClientId);
123 void ClipboardDelete (uint32_t u32ClientId);
124
125 /*
126 * Forwarders to VRDP server library.
127 */
128 void SendUpdate (unsigned uScreenId, void *pvUpdate, uint32_t cbUpdate) const;
129 void SendResize (void);
130 void SendUpdateBitmap (unsigned uScreenId, uint32_t x, uint32_t y, uint32_t w, uint32_t h) const;
131
132 void SendAudioSamples (void *pvSamples, uint32_t cSamples, VRDEAUDIOFORMAT format) const;
133 void SendAudioVolume (uint16_t left, uint16_t right) const;
134 void SendUSBRequest (uint32_t u32ClientId, void *pvParms, uint32_t cbParms) const;
135
136 void QueryInfo (uint32_t index, void *pvBuffer, uint32_t cbBuffer, uint32_t *pcbOut) const;
137
138 int SendAudioInputBegin(void **ppvUserCtx,
139 void *pvContext,
140 uint32_t cSamples,
141 uint32_t iSampleHz,
142 uint32_t cChannels,
143 uint32_t cBits);
144
145 void SendAudioInputEnd(void *pvUserCtx);
146
147 int SCardRequest(void *pvUser, uint32_t u32Function, const void *pvData, uint32_t cbData);
148
149 int VideoInDeviceAttach(const VRDEVIDEOINDEVICEHANDLE *pDeviceHandle, void *pvDeviceCtx);
150 int VideoInDeviceDetach(const VRDEVIDEOINDEVICEHANDLE *pDeviceHandle);
151 int VideoInGetDeviceDesc(void *pvUser, const VRDEVIDEOINDEVICEHANDLE *pDeviceHandle);
152 int VideoInControl(void *pvUser, const VRDEVIDEOINDEVICEHANDLE *pDeviceHandle,
153 const VRDEVIDEOINCTRLHDR *pReq, uint32_t cbReq);
154
155private:
156 /* Note: This is not a ComObjPtr here, because the ConsoleVRDPServer object
157 * is actually just a part of the Console.
158 */
159 Console *mConsole;
160
161 HVRDESERVER mhServer;
162 int mServerInterfaceVersion;
163
164 int32_t volatile mcInResize; /* Do not Stop the server if this is not 0. */
165
166 static int loadVRDPLibrary (const char *pszLibraryName);
167
168 /** Static because will never load this more than once! */
169 static RTLDRMOD mVRDPLibrary;
170
171 static PFNVRDECREATESERVER mpfnVRDECreateServer;
172
173 static VRDEENTRYPOINTS_4 mEntryPoints;
174 static VRDEENTRYPOINTS_4 *mpEntryPoints;
175 static VRDECALLBACKS_4 mCallbacks;
176
177 static DECLCALLBACK(int) VRDPCallbackQueryProperty (void *pvCallback, uint32_t index, void *pvBuffer, uint32_t cbBuffer, uint32_t *pcbOut);
178 static DECLCALLBACK(int) VRDPCallbackClientLogon (void *pvCallback, uint32_t u32ClientId, const char *pszUser, const char *pszPassword, const char *pszDomain);
179 static DECLCALLBACK(void) VRDPCallbackClientConnect (void *pvCallback, uint32_t u32ClientId);
180 static DECLCALLBACK(void) VRDPCallbackClientDisconnect (void *pvCallback, uint32_t u32ClientId, uint32_t fu32Intercepted);
181 static DECLCALLBACK(int) VRDPCallbackIntercept (void *pvCallback, uint32_t u32ClientId, uint32_t fu32Intercept, void **ppvIntercept);
182 static DECLCALLBACK(int) VRDPCallbackUSB (void *pvCallback, void *pvIntercept, uint32_t u32ClientId, uint8_t u8Code, const void *pvRet, uint32_t cbRet);
183 static DECLCALLBACK(int) VRDPCallbackClipboard (void *pvCallback, void *pvIntercept, uint32_t u32ClientId, uint32_t u32Function, uint32_t u32Format, const void *pvData, uint32_t cbData);
184 static DECLCALLBACK(bool) VRDPCallbackFramebufferQuery (void *pvCallback, unsigned uScreenId, VRDEFRAMEBUFFERINFO *pInfo);
185 static DECLCALLBACK(void) VRDPCallbackFramebufferLock (void *pvCallback, unsigned uScreenId);
186 static DECLCALLBACK(void) VRDPCallbackFramebufferUnlock (void *pvCallback, unsigned uScreenId);
187 static DECLCALLBACK(void) VRDPCallbackInput (void *pvCallback, int type, const void *pvInput, unsigned cbInput);
188 static DECLCALLBACK(void) VRDPCallbackVideoModeHint (void *pvCallback, unsigned cWidth, unsigned cHeight, unsigned cBitsPerPixel, unsigned uScreenId);
189 static DECLCALLBACK(void) VRDECallbackAudioIn (void *pvCallback, void *pvCtx, uint32_t u32ClientId, uint32_t u32Event, const void *pvData, uint32_t cbData);
190
191 bool m_fGuestWantsAbsolute;
192 int m_mousex;
193 int m_mousey;
194
195 IFramebuffer *maFramebuffers[SchemaDefs::MaxGuestMonitors];
196
197 ComPtr<IEventListener> mConsoleListener;
198
199 VRDPInputSynch m_InputSynch;
200
201 int32_t mVRDPBindPort;
202
203 RTCRITSECT mCritSect;
204
205 int lockConsoleVRDPServer (void);
206 void unlockConsoleVRDPServer (void);
207
208 int mcClipboardRefs;
209 HGCMSVCEXTHANDLE mhClipboard;
210 PFNVRDPCLIPBOARDEXTCALLBACK mpfnClipboardCallback;
211
212 static DECLCALLBACK(int) ClipboardCallback (void *pvCallback, uint32_t u32ClientId, uint32_t u32Function, uint32_t u32Format, const void *pvData, uint32_t cbData);
213 static DECLCALLBACK(int) ClipboardServiceExtension (void *pvExtension, uint32_t u32Function, void *pvParm, uint32_t cbParms);
214
215#ifdef VBOX_WITH_USB
216 RemoteUSBBackend *usbBackendFindByUUID (const Guid *pGuid);
217 RemoteUSBBackend *usbBackendFind (uint32_t u32ClientId);
218
219 typedef struct _USBBackends
220 {
221 RemoteUSBBackend *pHead;
222 RemoteUSBBackend *pTail;
223
224 RTTHREAD thread;
225
226 bool fThreadRunning;
227
228 RTSEMEVENT event;
229 } USBBackends;
230
231 USBBackends mUSBBackends;
232
233 void remoteUSBThreadStart (void);
234 void remoteUSBThreadStop (void);
235#endif /* VBOX_WITH_USB */
236
237 /* External authentication library handle. The library is loaded in the
238 * Authenticate method and unloaded at the object destructor.
239 */
240 RTLDRMOD mAuthLibrary;
241 PAUTHENTRY mpfnAuthEntry;
242 PAUTHENTRY2 mpfnAuthEntry2;
243 PAUTHENTRY3 mpfnAuthEntry3;
244
245 uint32_t volatile mu32AudioInputClientId;
246
247 int32_t volatile mcClients;
248
249 static DECLCALLBACK(void) H3DORBegin(const void *pvContext, void **ppvInstance,
250 const char *pszFormat);
251 static DECLCALLBACK(void) H3DORGeometry(void *pvInstance,
252 int32_t x, int32_t y, uint32_t w, uint32_t h);
253 static DECLCALLBACK(void) H3DORVisibleRegion(void *pvInstance,
254 uint32_t cRects, const RTRECT *paRects);
255 static DECLCALLBACK(void) H3DORFrame(void *pvInstance,
256 void *pvData, uint32_t cbData);
257 static DECLCALLBACK(void) H3DOREnd(void *pvInstance);
258 static DECLCALLBACK(int) H3DORContextProperty(const void *pvContext, uint32_t index,
259 void *pvBuffer, uint32_t cbBuffer, uint32_t *pcbOut);
260
261 void remote3DRedirect(bool fEnable);
262
263 /*
264 * VRDE server optional interfaces.
265 */
266
267 /* Image update interface. */
268 bool m_fInterfaceImage;
269 VRDEIMAGECALLBACKS m_interfaceCallbacksImage;
270 VRDEIMAGEINTERFACE m_interfaceImage;
271 static DECLCALLBACK(int) VRDEImageCbNotify (void *pvContext,
272 void *pvUser,
273 HVRDEIMAGE hVideo,
274 uint32_t u32Id,
275 void *pvData,
276 uint32_t cbData);
277 /* Mouse pointer interface. */
278 VRDEMOUSEPTRINTERFACE m_interfaceMousePtr;
279
280 /* Smartcard interface. */
281 VRDESCARDINTERFACE m_interfaceSCard;
282 VRDESCARDCALLBACKS m_interfaceCallbacksSCard;
283 static DECLCALLBACK(int) VRDESCardCbNotify(void *pvContext,
284 uint32_t u32Id,
285 void *pvData,
286 uint32_t cbData);
287 static DECLCALLBACK(int) VRDESCardCbResponse(void *pvContext,
288 int rcRequest,
289 void *pvUser,
290 uint32_t u32Function,
291 void *pvData,
292 uint32_t cbData);
293
294 /* TSMF interface. */
295 VRDETSMFINTERFACE m_interfaceTSMF;
296 VRDETSMFCALLBACKS m_interfaceCallbacksTSMF;
297 static DECLCALLBACK(void) VRDETSMFCbNotify(void *pvContext,
298 uint32_t u32Notification,
299 void *pvChannel,
300 const void *pvParm,
301 uint32_t cbParm);
302 void setupTSMF(void);
303
304 static DECLCALLBACK(int) tsmfHostChannelAttach(void *pvProvider, void **ppvInstance, uint32_t u32Flags,
305 VBOXHOSTCHANNELCALLBACKS *pCallbacks, void *pvCallbacks);
306 static DECLCALLBACK(void) tsmfHostChannelDetach(void *pvInstance);
307 static DECLCALLBACK(int) tsmfHostChannelSend(void *pvInstance, const void *pvData, uint32_t cbData);
308 static DECLCALLBACK(int) tsmfHostChannelRecv(void *pvInstance, void *pvData, uint32_t cbData,
309 uint32_t *pcbReturned, uint32_t *pcbRemaining);
310 static DECLCALLBACK(int) tsmfHostChannelControl(void *pvInstance, uint32_t u32Code,
311 const void *pvParm, uint32_t cbParm,
312 const void *pvData, uint32_t cbData, uint32_t *pcbDataReturned);
313 int tsmfLock(void);
314 void tsmfUnlock(void);
315 RTCRITSECT mTSMFLock;
316
317 /* Video input interface. */
318 VRDEVIDEOININTERFACE m_interfaceVideoIn;
319 VRDEVIDEOINCALLBACKS m_interfaceCallbacksVideoIn;
320 static DECLCALLBACK(void) VRDECallbackVideoInNotify(void *pvCallback,
321 uint32_t u32Id,
322 const void *pvData,
323 uint32_t cbData);
324 static DECLCALLBACK(void) VRDECallbackVideoInDeviceDesc(void *pvCallback,
325 int rcRequest,
326 void *pDeviceCtx,
327 void *pvUser,
328 const VRDEVIDEOINDEVICEDESC *pDeviceDesc,
329 uint32_t cbDevice);
330 static DECLCALLBACK(void) VRDECallbackVideoInControl(void *pvCallback,
331 int rcRequest,
332 void *pDeviceCtx,
333 void *pvUser,
334 const VRDEVIDEOINCTRLHDR *pControl,
335 uint32_t cbControl);
336 static DECLCALLBACK(void) VRDECallbackVideoInFrame(void *pvCallback,
337 int rcRequest,
338 void *pDeviceCtx,
339 const VRDEVIDEOINPAYLOADHDR *pFrame,
340 uint32_t cbFrame);
341
342 /* Input interface. */
343 VRDEINPUTINTERFACE m_interfaceInput;
344 VRDEINPUTCALLBACKS m_interfaceCallbacksInput;
345 static DECLCALLBACK(void) VRDECallbackInputSetup(void *pvCallback,
346 int rcRequest,
347 uint32_t u32Method,
348 const void *pvResult,
349 uint32_t cbResult);
350 static DECLCALLBACK(void) VRDECallbackInputEvent(void *pvCallback,
351 uint32_t u32Method,
352 const void *pvEvent,
353 uint32_t cbEvent);
354 uint64_t mu64TouchInputTimestampMCS;
355};
356
357
358class Console;
359
360class ATL_NO_VTABLE VRDEServerInfo :
361 public VirtualBoxBase,
362 VBOX_SCRIPTABLE_IMPL(IVRDEServerInfo)
363{
364public:
365
366 VIRTUALBOXBASE_ADD_ERRORINFO_SUPPORT(VRDEServerInfo, IVRDEServerInfo)
367
368 DECLARE_NOT_AGGREGATABLE(VRDEServerInfo)
369
370 DECLARE_PROTECT_FINAL_CONSTRUCT()
371
372 BEGIN_COM_MAP(VRDEServerInfo)
373 VBOX_DEFAULT_INTERFACE_ENTRIES(IVRDEServerInfo)
374 END_COM_MAP()
375
376 DECLARE_EMPTY_CTOR_DTOR (VRDEServerInfo)
377
378 HRESULT FinalConstruct();
379 void FinalRelease();
380
381 /* Public initializer/uninitializer for internal purposes only. */
382 HRESULT init (Console *aParent);
383 void uninit();
384
385 /* IVRDEServerInfo properties */
386 #define DECL_GETTER(_aType, _aName) STDMETHOD(COMGETTER(_aName)) (_aType *a##_aName)
387 DECL_GETTER (BOOL, Active);
388 DECL_GETTER (LONG, Port);
389 DECL_GETTER (ULONG, NumberOfClients);
390 DECL_GETTER (LONG64, BeginTime);
391 DECL_GETTER (LONG64, EndTime);
392 DECL_GETTER (LONG64, BytesSent);
393 DECL_GETTER (LONG64, BytesSentTotal);
394 DECL_GETTER (LONG64, BytesReceived);
395 DECL_GETTER (LONG64, BytesReceivedTotal);
396 DECL_GETTER (BSTR, User);
397 DECL_GETTER (BSTR, Domain);
398 DECL_GETTER (BSTR, ClientName);
399 DECL_GETTER (BSTR, ClientIP);
400 DECL_GETTER (ULONG, ClientVersion);
401 DECL_GETTER (ULONG, EncryptionStyle);
402 #undef DECL_GETTER
403
404private:
405
406 Console * const mParent;
407};
408
409#endif // ____H_CONSOLEVRDPSERVER
410/* vi: set tabstop=4 shiftwidth=4 expandtab: */
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