blob: 1feae3680da79ed5acd0b5a25c33aac00ea867e6 [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
33namespace winvnc {
34
35 class STrayIconThread;
36
37 class VNCServerWin32 : rfb::VNCServerST::QueryConnectionHandler,
38 rfb::win32::SocketManager::AddressChangeNotifier,
39 rfb::win32::RegConfig::Callback,
40 rfb::win32::EventHandler {
41 public:
42 VNCServerWin32();
43 virtual ~VNCServerWin32();
44
45 // Run the server in the current thread
46 int run();
47
48 // Cause the run() call to return
49 // THREAD-SAFE
50 void stop();
51
52 // Determine whether a viewer is active
53 // THREAD-SAFE
54 bool isServerInUse() const {return isDesktopStarted;}
55
56 // Connect out to the specified VNC Viewer
57 // THREAD-SAFE
58 bool addNewClient(const char* client);
59
60 // Disconnect all connected clients
61 // THREAD-SAFE
62 bool disconnectClients(const char* reason=0);
63
64 // Call used to notify VNCServerST of user accept/reject query completion
65 // CALLED FROM AcceptConnectDialog THREAD
66 void queryConnectionComplete();
67
68 // Where to read the configuration settings from
69 static const TCHAR* RegConfigPath;
70
71 bool getClientsInfo(rfb::ListConnInfo* LCInfo);
72
73 bool setClientsStatus(rfb::ListConnInfo* LCInfo);
74
75 protected:
76 // VNCServerST::QueryConnectionHandler interface
77 // Callback used to prompt user to accept or reject a connection.
78 // CALLBACK IN VNCServerST "HOST" THREAD
79 virtual rfb::VNCServerST::queryResult queryConnection(network::Socket* sock,
80 const char* userName,
81 char** reason);
82
83 // SocketManager::AddressChangeNotifier interface
84 // Used to keep tray icon up to date
85 virtual void processAddressChange(network::SocketListener* sl);
86
87 // RegConfig::Callback interface
88 // Called via the EventManager whenver RegConfig sees the registry change
89 virtual void regConfigChanged();
90
91 // EventHandler interface
92 // Used to perform queued commands
93 virtual void processEvent(HANDLE event);
94
95 protected:
96 // Perform a particular internal function in the server thread
97 typedef enum {NoCommand, DisconnectClients, AddClient, QueryConnectionComplete, SetClientsStatus, GetClientsInfo} Command;
98 bool queueCommand(Command cmd, const void* data, int len, bool wait=true);
99 Command command;
100 const void* commandData;
101 int commandDataLen;
102 rfb::Mutex commandLock;
103 rfb::Condition commandSig;
104 rfb::win32::Handle commandEvent;
Samuel Mannehed60c41932014-02-07 14:53:24 +0000105 rfb::win32::Handle sessionEvent;
Constantin Kaplinsky729598c2006-05-25 05:12:25 +0000106
107 // VNCServerWin32 Server-internal state
108 rfb::win32::SDisplay desktop;
109 rfb::VNCServerST vncServer;
110 rfb::Mutex runLock;
111 rfb::Thread* hostThread;
112 bool runServer;
113 bool isDesktopStarted;
114 JavaViewerServer httpServer;
115 rfb::win32::SocketManager sockMgr;
116 rfb::win32::RegConfig config;
117
118 ManagedListener rfbSock;
119 ManagedListener httpSock;
120 STrayIconThread* trayIcon;
121
Constantin Kaplinsky729598c2006-05-25 05:12:25 +0000122 QueryConnectDialog* queryConnectDialog;
Constantin Kaplinsky729598c2006-05-25 05:12:25 +0000123 };
124
125};
126
127#endif