blob: 271cb76a9926ee9fc09049fdf1a9cf3e7975e09e [file] [log] [blame]
Constantin Kaplinsky729598c2006-05-25 05:12:25 +00001/* Copyright (C) 2002-2005 RealVNC Ltd. All Rights Reserved.
2 *
3 * This is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This software is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this software; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
16 * USA.
17 */
18
19#ifndef __VNCSERVER_WIN32_H__
20#define __VNCSERVER_WIN32_H__
21
22#include <winsock2.h>
23#include <network/TcpSocket.h>
24#include <rfb/VNCServerST.h>
25#include <rfb_win32/RegConfig.h>
26#include <rfb_win32/SDisplay.h>
27#include <rfb_win32/SocketManager.h>
28#include <rfb_win32/TCharArray.h>
Constantin Kaplinsky729598c2006-05-25 05:12:25 +000029#include <winvnc/QueryConnectDialog.h>
Constantin Kaplinsky729598c2006-05-25 05:12:25 +000030#include <winvnc/ManagedListener.h>
31
Pierre Ossman338e73a2016-07-07 15:35:13 +020032namespace os {
33 class Mutex;
34 class Condition;
35 class Thread;
36}
37
Constantin Kaplinsky729598c2006-05-25 05:12:25 +000038namespace winvnc {
39
40 class STrayIconThread;
41
42 class VNCServerWin32 : rfb::VNCServerST::QueryConnectionHandler,
43 rfb::win32::SocketManager::AddressChangeNotifier,
44 rfb::win32::RegConfig::Callback,
45 rfb::win32::EventHandler {
46 public:
47 VNCServerWin32();
48 virtual ~VNCServerWin32();
49
50 // Run the server in the current thread
51 int run();
52
53 // Cause the run() call to return
54 // THREAD-SAFE
55 void stop();
56
57 // Determine whether a viewer is active
58 // THREAD-SAFE
59 bool isServerInUse() const {return isDesktopStarted;}
60
61 // Connect out to the specified VNC Viewer
62 // THREAD-SAFE
63 bool addNewClient(const char* client);
64
65 // Disconnect all connected clients
66 // THREAD-SAFE
67 bool disconnectClients(const char* reason=0);
68
69 // Call used to notify VNCServerST of user accept/reject query completion
70 // CALLED FROM AcceptConnectDialog THREAD
71 void queryConnectionComplete();
72
73 // Where to read the configuration settings from
74 static const TCHAR* RegConfigPath;
75
76 bool getClientsInfo(rfb::ListConnInfo* LCInfo);
77
78 bool setClientsStatus(rfb::ListConnInfo* LCInfo);
79
80 protected:
81 // VNCServerST::QueryConnectionHandler interface
82 // Callback used to prompt user to accept or reject a connection.
83 // CALLBACK IN VNCServerST "HOST" THREAD
84 virtual rfb::VNCServerST::queryResult queryConnection(network::Socket* sock,
85 const char* userName,
86 char** reason);
87
88 // SocketManager::AddressChangeNotifier interface
89 // Used to keep tray icon up to date
Pierre Ossman79f82f92015-03-17 13:44:00 +010090 virtual void processAddressChange();
Constantin Kaplinsky729598c2006-05-25 05:12:25 +000091
92 // RegConfig::Callback interface
klemens0536d092017-01-28 20:56:56 +010093 // Called via the EventManager whenever RegConfig sees the registry change
Constantin Kaplinsky729598c2006-05-25 05:12:25 +000094 virtual void regConfigChanged();
95
96 // EventHandler interface
97 // Used to perform queued commands
98 virtual void processEvent(HANDLE event);
99
100 protected:
101 // Perform a particular internal function in the server thread
102 typedef enum {NoCommand, DisconnectClients, AddClient, QueryConnectionComplete, SetClientsStatus, GetClientsInfo} Command;
103 bool queueCommand(Command cmd, const void* data, int len, bool wait=true);
104 Command command;
105 const void* commandData;
106 int commandDataLen;
Pierre Ossman338e73a2016-07-07 15:35:13 +0200107 os::Mutex* commandLock;
108 os::Condition* commandSig;
Constantin Kaplinsky729598c2006-05-25 05:12:25 +0000109 rfb::win32::Handle commandEvent;
Samuel Mannehed60c41932014-02-07 14:53:24 +0000110 rfb::win32::Handle sessionEvent;
Constantin Kaplinsky729598c2006-05-25 05:12:25 +0000111
112 // VNCServerWin32 Server-internal state
113 rfb::win32::SDisplay desktop;
114 rfb::VNCServerST vncServer;
Pierre Ossman338e73a2016-07-07 15:35:13 +0200115 os::Mutex* runLock;
116 DWORD thread_id;
Constantin Kaplinsky729598c2006-05-25 05:12:25 +0000117 bool runServer;
118 bool isDesktopStarted;
Constantin Kaplinsky729598c2006-05-25 05:12:25 +0000119 rfb::win32::SocketManager sockMgr;
120 rfb::win32::RegConfig config;
121
122 ManagedListener rfbSock;
Constantin Kaplinsky729598c2006-05-25 05:12:25 +0000123 STrayIconThread* trayIcon;
124
Constantin Kaplinsky729598c2006-05-25 05:12:25 +0000125 QueryConnectDialog* queryConnectDialog;
Constantin Kaplinsky729598c2006-05-25 05:12:25 +0000126 };
127
128};
129
130#endif