blob: 579a6a0bf8068741b9ed0736b0505442d77b83a5 [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>
29#include <rfb_win32/SFileTransferManagerWin32.h>
30#include <winvnc/QueryConnectDialog.h>
31#include <winvnc/JavaViewer.h>
32#include <winvnc/ManagedListener.h>
33
34namespace winvnc {
35
36 class STrayIconThread;
37
38 class VNCServerWin32 : rfb::VNCServerST::QueryConnectionHandler,
39 rfb::win32::SocketManager::AddressChangeNotifier,
40 rfb::win32::RegConfig::Callback,
41 rfb::win32::EventHandler {
42 public:
43 VNCServerWin32();
44 virtual ~VNCServerWin32();
45
46 // Run the server in the current thread
47 int run();
48
49 // Cause the run() call to return
50 // THREAD-SAFE
51 void stop();
52
53 // Determine whether a viewer is active
54 // THREAD-SAFE
55 bool isServerInUse() const {return isDesktopStarted;}
56
57 // Connect out to the specified VNC Viewer
58 // THREAD-SAFE
59 bool addNewClient(const char* client);
60
61 // Disconnect all connected clients
62 // THREAD-SAFE
63 bool disconnectClients(const char* reason=0);
64
65 // Call used to notify VNCServerST of user accept/reject query completion
66 // CALLED FROM AcceptConnectDialog THREAD
67 void queryConnectionComplete();
68
69 // Where to read the configuration settings from
70 static const TCHAR* RegConfigPath;
71
72 bool getClientsInfo(rfb::ListConnInfo* LCInfo);
73
74 bool setClientsStatus(rfb::ListConnInfo* LCInfo);
75
76 protected:
77 // VNCServerST::QueryConnectionHandler interface
78 // Callback used to prompt user to accept or reject a connection.
79 // CALLBACK IN VNCServerST "HOST" THREAD
80 virtual rfb::VNCServerST::queryResult queryConnection(network::Socket* sock,
81 const char* userName,
82 char** reason);
83
84 // SocketManager::AddressChangeNotifier interface
85 // Used to keep tray icon up to date
86 virtual void processAddressChange(network::SocketListener* sl);
87
88 // RegConfig::Callback interface
89 // Called via the EventManager whenver RegConfig sees the registry change
90 virtual void regConfigChanged();
91
92 // EventHandler interface
93 // Used to perform queued commands
94 virtual void processEvent(HANDLE event);
95
96 protected:
97 // Perform a particular internal function in the server thread
98 typedef enum {NoCommand, DisconnectClients, AddClient, QueryConnectionComplete, SetClientsStatus, GetClientsInfo} Command;
99 bool queueCommand(Command cmd, const void* data, int len, bool wait=true);
100 Command command;
101 const void* commandData;
102 int commandDataLen;
103 rfb::Mutex commandLock;
104 rfb::Condition commandSig;
105 rfb::win32::Handle commandEvent;
106
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
122 //rfb::SSecurityFactoryStandard securityFactory;
123
124 QueryConnectDialog* queryConnectDialog;
125 rfb::win32::SFileTransferManagerWin32 m_FTManager;
126 };
127
128};
129
130#endif