VirtualBox

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

Last change on this file since 51498 was 51436, checked in by vboxsync, 11 years ago

Main,Frontends: IDisplay provides the guest screen bitmap to frontends.

  • 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 51436 2014-05-28 09:12:15Z 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
42class EmWebcam;
43
44typedef struct _VRDPInputSynch
45{
46 int cGuestNumLockAdaptions;
47 int cGuestCapsLockAdaptions;
48
49 bool fGuestNumLock;
50 bool fGuestCapsLock;
51 bool fGuestScrollLock;
52
53 bool fClientNumLock;
54 bool fClientCapsLock;
55 bool fClientScrollLock;
56} VRDPInputSynch;
57
58/* Member of Console. Helper class for VRDP server management. Not a COM class. */
59class ConsoleVRDPServer
60{
61public:
62 ConsoleVRDPServer (Console *console);
63 ~ConsoleVRDPServer ();
64
65 int Launch (void);
66
67 void NotifyAbsoluteMouse (bool fGuestWantsAbsolute)
68 {
69 m_fGuestWantsAbsolute = fGuestWantsAbsolute;
70 }
71
72 void NotifyKeyboardLedsChange (BOOL fNumLock, BOOL fCapsLock, BOOL fScrollLock)
73 {
74 bool fGuestNumLock = (fNumLock != FALSE);
75 bool fGuestCapsLock = (fCapsLock != FALSE);
76 bool fGuestScrollLock = (fScrollLock != FALSE);
77
78 /* Might need to resync in case the guest itself changed the LED status. */
79 if (m_InputSynch.fClientNumLock != fGuestNumLock)
80 {
81 m_InputSynch.cGuestNumLockAdaptions = 2;
82 }
83
84 if (m_InputSynch.fClientCapsLock != fGuestCapsLock)
85 {
86 m_InputSynch.cGuestCapsLockAdaptions = 2;
87 }
88
89 m_InputSynch.fGuestNumLock = fGuestNumLock;
90 m_InputSynch.fGuestCapsLock = fGuestCapsLock;
91 m_InputSynch.fGuestScrollLock = fGuestScrollLock;
92 }
93
94 void EnableConnections (void);
95 void DisconnectClient (uint32_t u32ClientId, bool fReconnect);
96 int MousePointer(BOOL alpha, ULONG xHot, ULONG yHot, ULONG width, ULONG height, const uint8_t *pu8Shape);
97 void MousePointerUpdate (const VRDECOLORPOINTER *pPointer);
98 void MousePointerHide (void);
99
100 void Stop (void);
101
102 AuthResult Authenticate (const Guid &uuid, AuthGuestJudgement guestJudgement,
103 const char *pszUser, const char *pszPassword, const char *pszDomain,
104 uint32_t u32ClientId);
105
106 void AuthDisconnect (const Guid &uuid, uint32_t u32ClientId);
107
108 void USBBackendCreate (uint32_t u32ClientId, void **ppvIntercept);
109 void USBBackendDelete (uint32_t u32ClientId);
110
111 void *USBBackendRequestPointer (uint32_t u32ClientId, const Guid *pGuid);
112 void USBBackendReleasePointer (const Guid *pGuid);
113
114 /* Private interface for the RemoteUSBBackend destructor. */
115 void usbBackendRemoveFromList (RemoteUSBBackend *pRemoteUSBBackend);
116
117 /* Private methods for the Remote USB thread. */
118 RemoteUSBBackend *usbBackendGetNext (RemoteUSBBackend *pRemoteUSBBackend);
119
120 void notifyRemoteUSBThreadRunning (RTTHREAD thread);
121 bool isRemoteUSBThreadRunning (void);
122 void waitRemoteUSBThreadEvent (RTMSINTERVAL cMillies);
123
124 void ClipboardCreate (uint32_t u32ClientId);
125 void ClipboardDelete (uint32_t u32ClientId);
126
127 /*
128 * Forwarders to VRDP server library.
129 */
130 void SendUpdate (unsigned uScreenId, void *pvUpdate, uint32_t cbUpdate) const;
131 void SendResize (void);
132 void SendUpdateBitmap (unsigned uScreenId, uint32_t x, uint32_t y, uint32_t w, uint32_t h) const;
133
134 void SendAudioSamples (void *pvSamples, uint32_t cSamples, VRDEAUDIOFORMAT format) const;
135 void SendAudioVolume (uint16_t left, uint16_t right) const;
136 void SendUSBRequest (uint32_t u32ClientId, void *pvParms, uint32_t cbParms) const;
137
138 void QueryInfo (uint32_t index, void *pvBuffer, uint32_t cbBuffer, uint32_t *pcbOut) const;
139
140 int SendAudioInputBegin(void **ppvUserCtx,
141 void *pvContext,
142 uint32_t cSamples,
143 uint32_t iSampleHz,
144 uint32_t cChannels,
145 uint32_t cBits);
146
147 void SendAudioInputEnd(void *pvUserCtx);
148
149 int SCardRequest(void *pvUser, uint32_t u32Function, const void *pvData, uint32_t cbData);
150
151 int VideoInDeviceAttach(const VRDEVIDEOINDEVICEHANDLE *pDeviceHandle, void *pvDeviceCtx);
152 int VideoInDeviceDetach(const VRDEVIDEOINDEVICEHANDLE *pDeviceHandle);
153 int VideoInGetDeviceDesc(void *pvUser, const VRDEVIDEOINDEVICEHANDLE *pDeviceHandle);
154 int VideoInControl(void *pvUser, const VRDEVIDEOINDEVICEHANDLE *pDeviceHandle,
155 const VRDEVIDEOINCTRLHDR *pReq, uint32_t cbReq);
156
157 Console *getConsole(void) { return mConsole; }
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 ComPtr<IDisplaySourceBitmap> maSourceBitmaps[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 EmWebcam *mEmWebcam;
346
347 /* Input interface. */
348 VRDEINPUTINTERFACE m_interfaceInput;
349 VRDEINPUTCALLBACKS m_interfaceCallbacksInput;
350 static DECLCALLBACK(void) VRDECallbackInputSetup(void *pvCallback,
351 int rcRequest,
352 uint32_t u32Method,
353 const void *pvResult,
354 uint32_t cbResult);
355 static DECLCALLBACK(void) VRDECallbackInputEvent(void *pvCallback,
356 uint32_t u32Method,
357 const void *pvEvent,
358 uint32_t cbEvent);
359 uint64_t mu64TouchInputTimestampMCS;
360};
361
362
363class Console;
364
365class ATL_NO_VTABLE VRDEServerInfo :
366 public VirtualBoxBase,
367 VBOX_SCRIPTABLE_IMPL(IVRDEServerInfo)
368{
369public:
370
371 VIRTUALBOXBASE_ADD_ERRORINFO_SUPPORT(VRDEServerInfo, IVRDEServerInfo)
372
373 DECLARE_NOT_AGGREGATABLE(VRDEServerInfo)
374
375 DECLARE_PROTECT_FINAL_CONSTRUCT()
376
377 BEGIN_COM_MAP(VRDEServerInfo)
378 VBOX_DEFAULT_INTERFACE_ENTRIES(IVRDEServerInfo)
379 END_COM_MAP()
380
381 DECLARE_EMPTY_CTOR_DTOR (VRDEServerInfo)
382
383 HRESULT FinalConstruct();
384 void FinalRelease();
385
386 /* Public initializer/uninitializer for internal purposes only. */
387 HRESULT init (Console *aParent);
388 void uninit();
389
390 /* IVRDEServerInfo properties */
391 #define DECL_GETTER(_aType, _aName) STDMETHOD(COMGETTER(_aName)) (_aType *a##_aName)
392 DECL_GETTER (BOOL, Active);
393 DECL_GETTER (LONG, Port);
394 DECL_GETTER (ULONG, NumberOfClients);
395 DECL_GETTER (LONG64, BeginTime);
396 DECL_GETTER (LONG64, EndTime);
397 DECL_GETTER (LONG64, BytesSent);
398 DECL_GETTER (LONG64, BytesSentTotal);
399 DECL_GETTER (LONG64, BytesReceived);
400 DECL_GETTER (LONG64, BytesReceivedTotal);
401 DECL_GETTER (BSTR, User);
402 DECL_GETTER (BSTR, Domain);
403 DECL_GETTER (BSTR, ClientName);
404 DECL_GETTER (BSTR, ClientIP);
405 DECL_GETTER (ULONG, ClientVersion);
406 DECL_GETTER (ULONG, EncryptionStyle);
407 #undef DECL_GETTER
408
409private:
410
411 Console * const mParent;
412};
413
414#endif // ____H_CONSOLEVRDPSERVER
415/* 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