blob: f384bbeb5da1d6dfd8919a6f8d0b01e16afc96b8 [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>
30#include <winvnc/JavaViewer.h>
31#include <winvnc/ManagedListener.h>
32
Pierre Ossman338e73a2016-07-07 15:35:13 +020033namespace os {
34 class Mutex;
35 class Condition;
36 class Thread;
37}
38
Constantin Kaplinsky729598c2006-05-25 05:12:25 +000039namespace winvnc {
40
41 class STrayIconThread;
42
43 class VNCServerWin32 : rfb::VNCServerST::QueryConnectionHandler,
44 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
77 bool getClientsInfo(rfb::ListConnInfo* LCInfo);
78
79 bool setClientsStatus(rfb::ListConnInfo* LCInfo);
80
81 protected:
82 // VNCServerST::QueryConnectionHandler interface
83 // Callback used to prompt user to accept or reject a connection.
84 // CALLBACK IN VNCServerST "HOST" THREAD
85 virtual rfb::VNCServerST::queryResult queryConnection(network::Socket* sock,
86 const char* userName,
87 char** reason);
88
89 // SocketManager::AddressChangeNotifier interface
90 // Used to keep tray icon up to date
Pierre Ossman79f82f92015-03-17 13:44:00 +010091 virtual void processAddressChange();
Constantin Kaplinsky729598c2006-05-25 05:12:25 +000092
93 // RegConfig::Callback interface
klemens0536d092017-01-28 20:56:56 +010094 // Called via the EventManager whenever RegConfig sees the registry change
Constantin Kaplinsky729598c2006-05-25 05:12:25 +000095 virtual void regConfigChanged();
96
97 // EventHandler interface
98 // Used to perform queued commands
99 virtual void processEvent(HANDLE event);
100
101 protected:
102 // Perform a particular internal function in the server thread
103 typedef enum {NoCommand, DisconnectClients, AddClient, QueryConnectionComplete, SetClientsStatus, GetClientsInfo} Command;
104 bool queueCommand(Command cmd, const void* data, int len, bool wait=true);
105 Command command;
106 const void* commandData;
107 int commandDataLen;
Pierre Ossman338e73a2016-07-07 15:35:13 +0200108 os::Mutex* commandLock;
109 os::Condition* commandSig;
Constantin Kaplinsky729598c2006-05-25 05:12:25 +0000110 rfb::win32::Handle commandEvent;
Samuel Mannehed60c41932014-02-07 14:53:24 +0000111 rfb::win32::Handle sessionEvent;
Constantin Kaplinsky729598c2006-05-25 05:12:25 +0000112
113 // VNCServerWin32 Server-internal state
114 rfb::win32::SDisplay desktop;
115 rfb::VNCServerST vncServer;
Pierre Ossman338e73a2016-07-07 15:35:13 +0200116 os::Mutex* runLock;
117 DWORD thread_id;
Constantin Kaplinsky729598c2006-05-25 05:12:25 +0000118 bool runServer;
119 bool isDesktopStarted;
120 JavaViewerServer httpServer;
121 rfb::win32::SocketManager sockMgr;
122 rfb::win32::RegConfig config;
123
124 ManagedListener rfbSock;
125 ManagedListener httpSock;
126 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