VirtualBox

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

Last change on this file since 67954 was 62485, checked in by vboxsync, 8 years ago

(C) 2016

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