VirtualBox

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

Last change on this file since 48112 was 47571, checked in by vboxsync, 11 years ago

include,Devices,Main,VirtualBox: multi-touch input.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 17.4 KB
Line 
1/* $Id: ConsoleVRDPServer.h 47571 2013-08-07 09:49:33Z 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#ifdef VBOX_WITH_USB_VIDEO
147 int GetVideoFrameDimensions(uint16_t *pu16Heigh, uint16_t *pu16Width);
148 int SendVideoSreamOn(bool fFetch);
149#endif
150
151 int SCardRequest(void *pvUser, uint32_t u32Function, const void *pvData, uint32_t cbData);
152
153 int VideoInDeviceAttach(const VRDEVIDEOINDEVICEHANDLE *pDeviceHandle, void *pvDeviceCtx);
154 int VideoInDeviceDetach(const VRDEVIDEOINDEVICEHANDLE *pDeviceHandle);
155 int VideoInGetDeviceDesc(void *pvUser, const VRDEVIDEOINDEVICEHANDLE *pDeviceHandle);
156 int VideoInControl(void *pvUser, const VRDEVIDEOINDEVICEHANDLE *pDeviceHandle,
157 const VRDEVIDEOINCTRLHDR *pReq, uint32_t cbReq);
158
159private:
160 /* Note: This is not a ComObjPtr here, because the ConsoleVRDPServer object
161 * is actually just a part of the Console.
162 */
163 Console *mConsole;
164
165 HVRDESERVER mhServer;
166 int mServerInterfaceVersion;
167
168 int32_t volatile mcInResize; /* Do not Stop the server if this is not 0. */
169
170 static int loadVRDPLibrary (const char *pszLibraryName);
171
172 /** Static because will never load this more than once! */
173 static RTLDRMOD mVRDPLibrary;
174
175 static PFNVRDECREATESERVER mpfnVRDECreateServer;
176
177 static VRDEENTRYPOINTS_4 mEntryPoints;
178 static VRDEENTRYPOINTS_4 *mpEntryPoints;
179 static VRDECALLBACKS_4 mCallbacks;
180
181 static DECLCALLBACK(int) VRDPCallbackQueryProperty (void *pvCallback, uint32_t index, void *pvBuffer, uint32_t cbBuffer, uint32_t *pcbOut);
182 static DECLCALLBACK(int) VRDPCallbackClientLogon (void *pvCallback, uint32_t u32ClientId, const char *pszUser, const char *pszPassword, const char *pszDomain);
183 static DECLCALLBACK(void) VRDPCallbackClientConnect (void *pvCallback, uint32_t u32ClientId);
184 static DECLCALLBACK(void) VRDPCallbackClientDisconnect (void *pvCallback, uint32_t u32ClientId, uint32_t fu32Intercepted);
185 static DECLCALLBACK(int) VRDPCallbackIntercept (void *pvCallback, uint32_t u32ClientId, uint32_t fu32Intercept, void **ppvIntercept);
186 static DECLCALLBACK(int) VRDPCallbackUSB (void *pvCallback, void *pvIntercept, uint32_t u32ClientId, uint8_t u8Code, const void *pvRet, uint32_t cbRet);
187 static DECLCALLBACK(int) VRDPCallbackClipboard (void *pvCallback, void *pvIntercept, uint32_t u32ClientId, uint32_t u32Function, uint32_t u32Format, const void *pvData, uint32_t cbData);
188 static DECLCALLBACK(bool) VRDPCallbackFramebufferQuery (void *pvCallback, unsigned uScreenId, VRDEFRAMEBUFFERINFO *pInfo);
189 static DECLCALLBACK(void) VRDPCallbackFramebufferLock (void *pvCallback, unsigned uScreenId);
190 static DECLCALLBACK(void) VRDPCallbackFramebufferUnlock (void *pvCallback, unsigned uScreenId);
191 static DECLCALLBACK(void) VRDPCallbackInput (void *pvCallback, int type, const void *pvInput, unsigned cbInput);
192 static DECLCALLBACK(void) VRDPCallbackVideoModeHint (void *pvCallback, unsigned cWidth, unsigned cHeight, unsigned cBitsPerPixel, unsigned uScreenId);
193 static DECLCALLBACK(void) VRDECallbackAudioIn (void *pvCallback, void *pvCtx, uint32_t u32ClientId, uint32_t u32Event, const void *pvData, uint32_t cbData);
194
195 bool m_fGuestWantsAbsolute;
196 int m_mousex;
197 int m_mousey;
198
199 IFramebuffer *maFramebuffers[SchemaDefs::MaxGuestMonitors];
200
201 ComPtr<IEventListener> mConsoleListener;
202
203 VRDPInputSynch m_InputSynch;
204
205 int32_t mVRDPBindPort;
206
207 RTCRITSECT mCritSect;
208
209 int lockConsoleVRDPServer (void);
210 void unlockConsoleVRDPServer (void);
211
212 int mcClipboardRefs;
213 HGCMSVCEXTHANDLE mhClipboard;
214 PFNVRDPCLIPBOARDEXTCALLBACK mpfnClipboardCallback;
215
216 static DECLCALLBACK(int) ClipboardCallback (void *pvCallback, uint32_t u32ClientId, uint32_t u32Function, uint32_t u32Format, const void *pvData, uint32_t cbData);
217 static DECLCALLBACK(int) ClipboardServiceExtension (void *pvExtension, uint32_t u32Function, void *pvParm, uint32_t cbParms);
218
219#ifdef VBOX_WITH_USB
220 RemoteUSBBackend *usbBackendFindByUUID (const Guid *pGuid);
221 RemoteUSBBackend *usbBackendFind (uint32_t u32ClientId);
222
223 typedef struct _USBBackends
224 {
225 RemoteUSBBackend *pHead;
226 RemoteUSBBackend *pTail;
227
228 RTTHREAD thread;
229
230 bool fThreadRunning;
231
232 RTSEMEVENT event;
233 } USBBackends;
234
235 USBBackends mUSBBackends;
236
237 void remoteUSBThreadStart (void);
238 void remoteUSBThreadStop (void);
239#endif /* VBOX_WITH_USB */
240
241 /* External authentication library handle. The library is loaded in the
242 * Authenticate method and unloaded at the object destructor.
243 */
244 RTLDRMOD mAuthLibrary;
245 PAUTHENTRY mpfnAuthEntry;
246 PAUTHENTRY2 mpfnAuthEntry2;
247 PAUTHENTRY3 mpfnAuthEntry3;
248
249 uint32_t volatile mu32AudioInputClientId;
250
251 int32_t volatile mcClients;
252
253 static DECLCALLBACK(void) H3DORBegin(const void *pvContext, void **ppvInstance,
254 const char *pszFormat);
255 static DECLCALLBACK(void) H3DORGeometry(void *pvInstance,
256 int32_t x, int32_t y, uint32_t w, uint32_t h);
257 static DECLCALLBACK(void) H3DORVisibleRegion(void *pvInstance,
258 uint32_t cRects, const RTRECT *paRects);
259 static DECLCALLBACK(void) H3DORFrame(void *pvInstance,
260 void *pvData, uint32_t cbData);
261 static DECLCALLBACK(void) H3DOREnd(void *pvInstance);
262 static DECLCALLBACK(int) H3DORContextProperty(const void *pvContext, uint32_t index,
263 void *pvBuffer, uint32_t cbBuffer, uint32_t *pcbOut);
264
265 void remote3DRedirect(bool fEnable);
266
267 /*
268 * VRDE server optional interfaces.
269 */
270
271 /* Image update interface. */
272 bool m_fInterfaceImage;
273 VRDEIMAGECALLBACKS m_interfaceCallbacksImage;
274 VRDEIMAGEINTERFACE m_interfaceImage;
275 static DECLCALLBACK(int) VRDEImageCbNotify (void *pvContext,
276 void *pvUser,
277 HVRDEIMAGE hVideo,
278 uint32_t u32Id,
279 void *pvData,
280 uint32_t cbData);
281 /* Mouse pointer interface. */
282 VRDEMOUSEPTRINTERFACE m_interfaceMousePtr;
283
284 /* Smartcard interface. */
285 VRDESCARDINTERFACE m_interfaceSCard;
286 VRDESCARDCALLBACKS m_interfaceCallbacksSCard;
287 static DECLCALLBACK(int) VRDESCardCbNotify(void *pvContext,
288 uint32_t u32Id,
289 void *pvData,
290 uint32_t cbData);
291 static DECLCALLBACK(int) VRDESCardCbResponse(void *pvContext,
292 int rcRequest,
293 void *pvUser,
294 uint32_t u32Function,
295 void *pvData,
296 uint32_t cbData);
297
298 /* TSMF interface. */
299 VRDETSMFINTERFACE m_interfaceTSMF;
300 VRDETSMFCALLBACKS m_interfaceCallbacksTSMF;
301 static DECLCALLBACK(void) VRDETSMFCbNotify(void *pvContext,
302 uint32_t u32Notification,
303 void *pvChannel,
304 const void *pvParm,
305 uint32_t cbParm);
306 void setupTSMF(void);
307
308 static DECLCALLBACK(int) tsmfHostChannelAttach(void *pvProvider, void **ppvInstance, uint32_t u32Flags,
309 VBOXHOSTCHANNELCALLBACKS *pCallbacks, void *pvCallbacks);
310 static DECLCALLBACK(void) tsmfHostChannelDetach(void *pvInstance);
311 static DECLCALLBACK(int) tsmfHostChannelSend(void *pvInstance, const void *pvData, uint32_t cbData);
312 static DECLCALLBACK(int) tsmfHostChannelRecv(void *pvInstance, void *pvData, uint32_t cbData,
313 uint32_t *pcbReturned, uint32_t *pcbRemaining);
314 static DECLCALLBACK(int) tsmfHostChannelControl(void *pvInstance, uint32_t u32Code,
315 const void *pvParm, uint32_t cbParm,
316 const void *pvData, uint32_t cbData, uint32_t *pcbDataReturned);
317 int tsmfLock(void);
318 void tsmfUnlock(void);
319 RTCRITSECT mTSMFLock;
320
321 /* Video input interface. */
322 VRDEVIDEOININTERFACE m_interfaceVideoIn;
323 VRDEVIDEOINCALLBACKS m_interfaceCallbacksVideoIn;
324 static DECLCALLBACK(void) VRDECallbackVideoInNotify(void *pvCallback,
325 uint32_t u32Id,
326 const void *pvData,
327 uint32_t cbData);
328 static DECLCALLBACK(void) VRDECallbackVideoInDeviceDesc(void *pvCallback,
329 int rcRequest,
330 void *pDeviceCtx,
331 void *pvUser,
332 const VRDEVIDEOINDEVICEDESC *pDeviceDesc,
333 uint32_t cbDevice);
334 static DECLCALLBACK(void) VRDECallbackVideoInControl(void *pvCallback,
335 int rcRequest,
336 void *pDeviceCtx,
337 void *pvUser,
338 const VRDEVIDEOINCTRLHDR *pControl,
339 uint32_t cbControl);
340 static DECLCALLBACK(void) VRDECallbackVideoInFrame(void *pvCallback,
341 int rcRequest,
342 void *pDeviceCtx,
343 const VRDEVIDEOINPAYLOADHDR *pFrame,
344 uint32_t cbFrame);
345
346 /* Input interface. */
347 VRDEINPUTINTERFACE m_interfaceInput;
348 VRDEINPUTCALLBACKS m_interfaceCallbacksInput;
349 static DECLCALLBACK(void) VRDECallbackInputSetup(void *pvCallback,
350 int rcRequest,
351 uint32_t u32Method,
352 const void *pvResult,
353 uint32_t cbResult);
354 static DECLCALLBACK(void) VRDECallbackInputEvent(void *pvCallback,
355 uint32_t u32Method,
356 const void *pvEvent,
357 uint32_t cbEvent);
358 uint64_t mu64TouchInputTimestampMCS;
359};
360
361
362class Console;
363
364class ATL_NO_VTABLE VRDEServerInfo :
365 public VirtualBoxBase,
366 VBOX_SCRIPTABLE_IMPL(IVRDEServerInfo)
367{
368public:
369
370 VIRTUALBOXBASE_ADD_ERRORINFO_SUPPORT(VRDEServerInfo, IVRDEServerInfo)
371
372 DECLARE_NOT_AGGREGATABLE(VRDEServerInfo)
373
374 DECLARE_PROTECT_FINAL_CONSTRUCT()
375
376 BEGIN_COM_MAP(VRDEServerInfo)
377 VBOX_DEFAULT_INTERFACE_ENTRIES(IVRDEServerInfo)
378 END_COM_MAP()
379
380 DECLARE_EMPTY_CTOR_DTOR (VRDEServerInfo)
381
382 HRESULT FinalConstruct();
383 void FinalRelease();
384
385 /* Public initializer/uninitializer for internal purposes only. */
386 HRESULT init (Console *aParent);
387 void uninit();
388
389 /* IVRDEServerInfo properties */
390 #define DECL_GETTER(_aType, _aName) STDMETHOD(COMGETTER(_aName)) (_aType *a##_aName)
391 DECL_GETTER (BOOL, Active);
392 DECL_GETTER (LONG, Port);
393 DECL_GETTER (ULONG, NumberOfClients);
394 DECL_GETTER (LONG64, BeginTime);
395 DECL_GETTER (LONG64, EndTime);
396 DECL_GETTER (LONG64, BytesSent);
397 DECL_GETTER (LONG64, BytesSentTotal);
398 DECL_GETTER (LONG64, BytesReceived);
399 DECL_GETTER (LONG64, BytesReceivedTotal);
400 DECL_GETTER (BSTR, User);
401 DECL_GETTER (BSTR, Domain);
402 DECL_GETTER (BSTR, ClientName);
403 DECL_GETTER (BSTR, ClientIP);
404 DECL_GETTER (ULONG, ClientVersion);
405 DECL_GETTER (ULONG, EncryptionStyle);
406 #undef DECL_GETTER
407
408private:
409
410 Console * const mParent;
411};
412
413#endif // ____H_CONSOLEVRDPSERVER
414/* 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