blob: 1a737823466ddaa6f65d19828aa1a90ffd205f97 [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
Pierre Ossman025326d2018-10-08 16:03:01 +020040 class ListConnInfo;
Constantin Kaplinsky729598c2006-05-25 05:12:25 +000041 class STrayIconThread;
42
Pierre Ossmaneef6c9a2018-10-05 17:11:25 +020043 class VNCServerWin32 : rfb::win32::QueryConnectionHandler,
Constantin Kaplinsky729598c2006-05-25 05:12:25 +000044 rfb::win32::SocketManager::AddressChangeNotifier,
45 rfb::win32::RegConfig::Callback,
46 rfb::win32::EventHandler {
47 public:
48 VNCServerWin32();
49 virtual ~VNCServerWin32();
50
51 // Run the server in the current thread
52 int run();
53
54 // Cause the run() call to return
55 // THREAD-SAFE
56 void stop();
57
58 // Determine whether a viewer is active
59 // THREAD-SAFE
60 bool isServerInUse() const {return isDesktopStarted;}
61
62 // Connect out to the specified VNC Viewer
63 // THREAD-SAFE
64 bool addNewClient(const char* client);
65
66 // Disconnect all connected clients
67 // THREAD-SAFE
68 bool disconnectClients(const char* reason=0);
69
70 // Call used to notify VNCServerST of user accept/reject query completion
71 // CALLED FROM AcceptConnectDialog THREAD
72 void queryConnectionComplete();
73
74 // Where to read the configuration settings from
75 static const TCHAR* RegConfigPath;
76
Pierre Ossman025326d2018-10-08 16:03:01 +020077 bool getClientsInfo(ListConnInfo* LCInfo);
Constantin Kaplinsky729598c2006-05-25 05:12:25 +000078
Pierre Ossman025326d2018-10-08 16:03:01 +020079 bool setClientsStatus(ListConnInfo* LCInfo);
Constantin Kaplinsky729598c2006-05-25 05:12:25 +000080
81 protected:
Pierre Ossmaneef6c9a2018-10-05 17:11:25 +020082 // QueryConnectionHandler interface
Constantin Kaplinsky729598c2006-05-25 05:12:25 +000083 // Callback used to prompt user to accept or reject a connection.
84 // CALLBACK IN VNCServerST "HOST" THREAD
Pierre Ossmane6aab242018-10-05 16:59:22 +020085 virtual void queryConnection(network::Socket* sock,
86 const char* userName);
Constantin Kaplinsky729598c2006-05-25 05:12:25 +000087
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
Pierre Ossman025326d2018-10-08 16:03:01 +0200100 void getConnInfo(ListConnInfo * listConn);
101 void setConnStatus(ListConnInfo* listConn);
102
Constantin Kaplinsky729598c2006-05-25 05:12:25 +0000103 protected:
104 // Perform a particular internal function in the server thread
105 typedef enum {NoCommand, DisconnectClients, AddClient, QueryConnectionComplete, SetClientsStatus, GetClientsInfo} Command;
106 bool queueCommand(Command cmd, const void* data, int len, bool wait=true);
107 Command command;
108 const void* commandData;
109 int commandDataLen;
Pierre Ossman338e73a2016-07-07 15:35:13 +0200110 os::Mutex* commandLock;
111 os::Condition* commandSig;
Constantin Kaplinsky729598c2006-05-25 05:12:25 +0000112 rfb::win32::Handle commandEvent;
Samuel Mannehed60c41932014-02-07 14:53:24 +0000113 rfb::win32::Handle sessionEvent;
Constantin Kaplinsky729598c2006-05-25 05:12:25 +0000114
115 // VNCServerWin32 Server-internal state
116 rfb::win32::SDisplay desktop;
117 rfb::VNCServerST vncServer;
Pierre Ossman338e73a2016-07-07 15:35:13 +0200118 os::Mutex* runLock;
119 DWORD thread_id;
Constantin Kaplinsky729598c2006-05-25 05:12:25 +0000120 bool runServer;
121 bool isDesktopStarted;
Constantin Kaplinsky729598c2006-05-25 05:12:25 +0000122 rfb::win32::SocketManager sockMgr;
123 rfb::win32::RegConfig config;
124
125 ManagedListener rfbSock;
Constantin Kaplinsky729598c2006-05-25 05:12:25 +0000126 STrayIconThread* trayIcon;
127
Constantin Kaplinsky729598c2006-05-25 05:12:25 +0000128 QueryConnectDialog* queryConnectDialog;
Constantin Kaplinsky729598c2006-05-25 05:12:25 +0000129 };
130
131};
132
133#endif