VirtualBox

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

Last change on this file since 5976 was 5782, checked in by vboxsync, 17 years ago

Implemented NumLock state synch over VRDP.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 11.5 KB
Line 
1/** @file
2 *
3 * VBox Console VRDP Helper class and implementation of IRemoteDisplayInfo
4 */
5
6/*
7 * Copyright (C) 2006-2007 innotek GmbH
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 as published by the Free Software Foundation,
13 * in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
14 * distribution. VirtualBox OSE is distributed in the hope that it will
15 * 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/HGCM.h>
23
24#include <VBox/VRDPAuth.h>
25
26#include <VBox/HostServices/VBoxClipboardExt.h>
27
28#ifdef VRDP_NO_COM
29#include "SchemaDefs.h"
30#endif /* VRDP_NO_COM */
31
32// ConsoleVRDPServer
33///////////////////////////////////////////////////////////////////////////////
34
35#ifdef VRDP_NO_COM
36typedef struct _VRDPInputSynch
37{
38 int cGuestNumLockAdaptions;
39 int cGuestCapsLockAdaptions;
40
41 bool fGuestNumLock;
42 bool fGuestCapsLock;
43 bool fGuestScrollLock;
44
45 bool fClientNumLock;
46 bool fClientCapsLock;
47 bool fClientScrollLock;
48} VRDPInputSynch;
49#endif /* VRDP_NO_COM */
50
51/* Member of Console. Helper class for VRDP server management. Not a COM class. */
52class ConsoleVRDPServer
53{
54public:
55 ConsoleVRDPServer (Console *console);
56 ~ConsoleVRDPServer ();
57
58 int Launch (void);
59#ifdef VRDP_NO_COM
60 void NotifyAbsoluteMouse (bool fGuestWantsAbsolute)
61 {
62 m_fGuestWantsAbsolute = fGuestWantsAbsolute;
63 }
64
65 void NotifyKeyboardLedsChange (BOOL fNumLock, BOOL fCapsLock, BOOL fScrollLock)
66 {
67 bool fGuestNumLock = (fNumLock != FALSE);
68 bool fGuestCapsLock = (fCapsLock != FALSE);
69 bool fGuestScrollLock = (fScrollLock != FALSE);
70
71 /* Might need to resynch in case the guest itself changed the LED status. */
72 if (m_InputSynch.fClientNumLock != fGuestNumLock)
73 {
74 m_InputSynch.cGuestNumLockAdaptions = 2;
75 }
76
77 if (m_InputSynch.fClientCapsLock != fGuestCapsLock)
78 {
79 m_InputSynch.cGuestCapsLockAdaptions = 2;
80 }
81
82 m_InputSynch.fGuestNumLock = fGuestNumLock;
83 m_InputSynch.fGuestCapsLock = fGuestCapsLock;
84 m_InputSynch.fGuestScrollLock = fGuestScrollLock;
85 }
86
87 void EnableConnections (void);
88 void MousePointerUpdate (const VRDPCOLORPOINTER *pPointer);
89 void MousePointerHide (void);
90#else
91 void SetCallback (void);
92#endif /* VRDP_NO_COM */
93 void Stop (void);
94
95 VRDPAuthResult Authenticate (const Guid &uuid, VRDPAuthGuestJudgement guestJudgement,
96 const char *pszUser, const char *pszPassword, const char *pszDomain,
97 uint32_t u32ClientId);
98
99 void AuthDisconnect (const Guid &uuid, uint32_t u32ClientId);
100
101#ifdef VRDP_NO_COM
102 void USBBackendCreate (uint32_t u32ClientId, void **ppvIntercept);
103#else
104 void USBBackendCreate (uint32_t u32ClientId, PFNVRDPUSBCALLBACK *ppfn, void **ppv);
105#endif /* VRDP_NO_COM */
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 (unsigned cMillies);
120
121#ifdef VRDP_NO_COM
122 void ClipboardCreate (uint32_t u32ClientId);
123#else
124 void ClipboardCreate (uint32_t u32ClientId, PFNVRDPCLIPBOARDCALLBACK *ppfn, void **ppv);
125#endif /* VRDP_NO_COM */
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) const;
133 void SendUpdateBitmap (unsigned uScreenId, uint32_t x, uint32_t y, uint32_t w, uint32_t h) const;
134#ifdef VRDP_NO_COM
135#else
136 void SetFramebuffer (IFramebuffer *framebuffer, uint32_t fFlags) const;
137#endif /* VRDP_NO_COM */
138
139 void SendAudioSamples (void *pvSamples, uint32_t cSamples, VRDPAUDIOFORMAT format) const;
140 void SendAudioVolume (uint16_t left, uint16_t right) const;
141 void SendUSBRequest (uint32_t u32ClientId, void *pvParms, uint32_t cbParms) const;
142
143 void QueryInfo (uint32_t index, void *pvBuffer, uint32_t cbBuffer, uint32_t *pcbOut) const;
144
145private:
146 /* Note: This is not a ComObjPtr here, because the ConsoleVRDPServer object
147 * is actually just a part of the Console.
148 */
149 Console *mConsole;
150
151#ifdef VBOX_VRDP
152 HVRDPSERVER mhServer;
153
154 static bool loadVRDPLibrary (void);
155
156 /** Static because will never load this more than once! */
157 static RTLDRMOD mVRDPLibrary;
158
159#ifdef VRDP_NO_COM
160 static PFNVRDPCREATESERVER mpfnVRDPCreateServer;
161
162 static VRDPENTRYPOINTS_1 *mpEntryPoints;
163 static VRDPCALLBACKS_1 mCallbacks;
164
165 static DECLCALLBACK(int) VRDPCallbackQueryProperty (void *pvCallback, uint32_t index, void *pvBuffer, uint32_t cbBuffer, uint32_t *pcbOut);
166 static DECLCALLBACK(int) VRDPCallbackClientLogon (void *pvCallback, uint32_t u32ClientId, const char *pszUser, const char *pszPassword, const char *pszDomain);
167 static DECLCALLBACK(void) VRDPCallbackClientConnect (void *pvCallback, uint32_t u32ClientId);
168 static DECLCALLBACK(void) VRDPCallbackClientDisconnect (void *pvCallback, uint32_t u32ClientId, uint32_t fu32Intercepted);
169 static DECLCALLBACK(int) VRDPCallbackIntercept (void *pvCallback, uint32_t u32ClientId, uint32_t fu32Intercept, void **ppvIntercept);
170 static DECLCALLBACK(int) VRDPCallbackUSB (void *pvCallback, void *pvIntercept, uint32_t u32ClientId, uint8_t u8Code, const void *pvRet, uint32_t cbRet);
171 static DECLCALLBACK(int) VRDPCallbackClipboard (void *pvCallback, void *pvIntercept, uint32_t u32ClientId, uint32_t u32Function, uint32_t u32Format, const void *pvData, uint32_t cbData);
172 static DECLCALLBACK(bool) VRDPCallbackFramebufferQuery (void *pvCallback, unsigned uScreenId, VRDPFRAMEBUFFERINFO *pInfo);
173 static DECLCALLBACK(void) VRDPCallbackFramebufferLock (void *pvCallback, unsigned uScreenId);
174 static DECLCALLBACK(void) VRDPCallbackFramebufferUnlock (void *pvCallback, unsigned uScreenId);
175 static DECLCALLBACK(void) VRDPCallbackInput (void *pvCallback, int type, const void *pvInput, unsigned cbInput);
176 static DECLCALLBACK(void) VRDPCallbackVideoModeHint (void *pvCallback, unsigned cWidth, unsigned cHeight, unsigned cBitsPerPixel, unsigned uScreenId);
177
178 bool m_fGuestWantsAbsolute;
179 int m_mousex;
180 int m_mousey;
181
182 IFramebuffer *maFramebuffers[SchemaDefs::MaxGuestMonitors];
183
184 IConsoleCallback *mConsoleCallback;
185
186 VRDPInputSynch m_InputSynch;
187#else
188 // VRDP API function pointers
189 static int (VBOXCALL *mpfnVRDPStartServer) (IConsole *pConsole, IVRDPServer *pVRDPServer, HVRDPSERVER *phServer);
190 static int (VBOXCALL *mpfnVRDPSetFramebuffer) (HVRDPSERVER hServer, IFramebuffer *pFramebuffer, uint32_t fFlags);
191 static void (VBOXCALL *mpfnVRDPSetCallback) (HVRDPSERVER hServer, VRDPSERVERCALLBACK *pcallback, void *pvUser);
192 static void (VBOXCALL *mpfnVRDPShutdownServer) (HVRDPSERVER hServer);
193 static void (VBOXCALL *mpfnVRDPSendUpdateBitmap)(HVRDPSERVER hServer, unsigned uScreenId, unsigned x, unsigned y, unsigned w, unsigned h);
194 static void (VBOXCALL *mpfnVRDPSendResize) (HVRDPSERVER hServer);
195 static void (VBOXCALL *mpfnVRDPSendAudioSamples)(HVRDPSERVER hserver, void *pvSamples, uint32_t cSamples, VRDPAUDIOFORMAT format);
196 static void (VBOXCALL *mpfnVRDPSendAudioVolume) (HVRDPSERVER hserver, uint16_t left, uint16_t right);
197 static void (VBOXCALL *mpfnVRDPSendUSBRequest) (HVRDPSERVER hserver, uint32_t u32ClientId, void *pvParms, uint32_t cbParms);
198 static void (VBOXCALL *mpfnVRDPSendUpdate) (HVRDPSERVER hServer, unsigned uScreenId, void *pvUpdate, uint32_t cbUpdate);
199 static void (VBOXCALL *mpfnVRDPQueryInfo) (HVRDPSERVER hserver, uint32_t index, void *pvBuffer, uint32_t cbBuffer, uint32_t *pcbOut);
200 static void (VBOXCALL *mpfnVRDPClipboard) (HVRDPSERVER hserver, uint32_t u32Function, uint32_t u32Format, const void *pvData, uint32_t cbData, uint32_t *pcbActualRead);
201#endif /* VRDP_NO_COM */
202#endif /* VBOX_VRDP */
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 PVRDPAUTHENTRY mpfnAuthEntry;
243 PVRDPAUTHENTRY2 mpfnAuthEntry2;
244};
245
246
247class Console;
248
249class ATL_NO_VTABLE RemoteDisplayInfo :
250 public VirtualBoxSupportErrorInfoImpl <RemoteDisplayInfo, IRemoteDisplayInfo>,
251 public VirtualBoxSupportTranslation <RemoteDisplayInfo>,
252 public VirtualBoxBase,
253 public IRemoteDisplayInfo
254{
255public:
256
257 DECLARE_NOT_AGGREGATABLE(RemoteDisplayInfo)
258
259 DECLARE_PROTECT_FINAL_CONSTRUCT()
260
261 BEGIN_COM_MAP(RemoteDisplayInfo)
262 COM_INTERFACE_ENTRY(ISupportErrorInfo)
263 COM_INTERFACE_ENTRY(IRemoteDisplayInfo)
264 END_COM_MAP()
265
266 NS_DECL_ISUPPORTS
267
268 HRESULT FinalConstruct();
269 void FinalRelease();
270
271 /* Public initializer/uninitializer for internal purposes only. */
272 HRESULT init (Console *aParent);
273 void uninit();
274
275 /* IRemoteDisplayInfo properties */
276 #define DECL_GETTER(_aType, _aName) STDMETHOD(COMGETTER(_aName)) (_aType *a##_aName)
277 DECL_GETTER (BOOL, Active);
278 DECL_GETTER (ULONG, NumberOfClients);
279 DECL_GETTER (LONG64, BeginTime);
280 DECL_GETTER (LONG64, EndTime);
281 DECL_GETTER (ULONG64, BytesSent);
282 DECL_GETTER (ULONG64, BytesSentTotal);
283 DECL_GETTER (ULONG64, BytesReceived);
284 DECL_GETTER (ULONG64, BytesReceivedTotal);
285 DECL_GETTER (BSTR, User);
286 DECL_GETTER (BSTR, Domain);
287 DECL_GETTER (BSTR, ClientName);
288 DECL_GETTER (BSTR, ClientIP);
289 DECL_GETTER (ULONG, ClientVersion);
290 DECL_GETTER (ULONG, EncryptionStyle);
291 #undef DECL_GETTER
292
293 /* For VirtualBoxSupportErrorInfoImpl. */
294 static const wchar_t *getComponentName() { return L"RemoteDisplayInfo"; }
295
296private:
297
298 ComObjPtr <Console, ComWeakRef> mParent;
299};
300
301#endif // ____H_CONSOLEVRDPSERVER
Note: See TracBrowser for help on using the repository browser.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette