VirtualBox

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

Last change on this file since 52442 was 52442, checked in by vboxsync, 10 years ago

Main: convert VirtualBoxClient and VRDEServerInfo to use wrappers

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