VirtualBox

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

Last change on this file since 45733 was 44528, checked in by vboxsync, 12 years ago

header (C) fixes

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