-
Notifications
You must be signed in to change notification settings - Fork 2
/
TvnAssistServer.h
216 lines (190 loc) · 6.86 KB
/
TvnAssistServer.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
// Copyright (C) 2009,2010,2011,2012 GlavSoft LLC.
// All rights reserved.
//
//-------------------------------------------------------------------------
// This file is part of the TightVNC software. Please visit our Web site:
//
// http://www.tightvnc.com/
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License along
// with this program; if not, write to the Free Software Foundation, Inc.,
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
//-------------------------------------------------------------------------
//
#ifndef _TVN_ASSIST_SERVER_H_
#define _TVN_ASSIST_SERVER_H_
#include "util/CommonHeader.h"
#include "desktop/WinServiceDesktopFactory.h"
#include "desktop/ApplicationDesktopFactory.h"
#include "tvnserver-app/RfbClientManager.h"
#include "tvnserver-app/RfbServer.h"
#include "tvnserver-app/ExtraRfbServers.h"
#include "tvnserver-app/ControlServer.h"
#include "tvnserver-app/TvnServerListener.h"
#include "http-server-lib/HttpServer.h"
#include "thread/ZombieKiller.h"
#include "thread/LocalMutex.h"
#include "log-writer/LogWriter.h"
#include "util/Singleton.h"
#include "util/ListenerContainer.h"
#include "tvnserver-app/NewConnectionEvents.h"
#include "server-config-lib/Configurator.h"
#include "tvncontrol-app/TvnServerInfo.h"
#include "tvnserver-app/LogInitListener.h"
/**
* TightVNC server singleton that includes serveral components:
* 1) Zombie killer singleton.
* 2) Configurator singleton.
* 3) Log singleton.
* 4) Rfb servers (main rfb server and extra servers).
* 5) Http server.
* 6) Control server.
* 7) Other features:
1) Do action when last client disconnects.
*/
class TvnAssistServer : public Singleton<TvnAssistServer>,
public ListenerContainer<TvnServerListener*>,
public ConfigReloadListener,
public RfbClientManagerEventListener
{
public:
bool runServer;
/**
* Creates and starts TightVNC server execution (in separate thread).
*
* Makes sereval steps:
* 1) Instanizes zombie killer.
* 2) Instanizes configurator and load configuration.
* 3) Instanizes log.
* 4) Starts all servers.
*
* @param runsInServiceContext must be set to true if TvnServer is running in service context,
* false, if in context of single application. Parameter determinates control client behavour and
* initial place for loading TightVNC configuration.
*
* @remark doesn't block calling thread execution cause all servers runs in it's own threads.
* To know when need to shutdown TightVNC server you need to use addListener method.
*/
TvnAssistServer(bool runsInServiceContext,
NewConnectionEvents* newConnectionEvents,
LogInitListener* logInitListener,
Logger* logger);
/**
* Stops and destroys TightVNC server.
* @remark don't generate shutdown signal(like shutdown() method does) for listeners.
*/
virtual ~TvnAssistServer();
/**
* Fills structure with information of current state of TvnServer.
* @param info [out] output parameter that will contain TightVNC server information
* after call of this method.
* @fixme place extended information to server info.
*/
void getServerInfo(TvnServerInfo* info);
RfbClientManager getRfbClientManager();
/**
* Inherited from ConfigReloadListener interface to catch configuration reload event.
*
* Make several things:
* 1) Changes log level.
* 2) Restarts rfb servers.
* 3) Restarts http server.
*/
virtual void onConfigReload(ServerConfig* serverConfig);
/**
* Only generates shutdown signal (event) for TvnServer listeners.
*
* @remark used by ControlClient, when it recieves command to shutdown TightVNC.
* @remark doesn't stop TightVNC server.
* @fixme rename this method.
*/
void generateExternalShutdownSignal();
/**
* Checks if TightVNC server runs in service context.
* @returns true if runs in service context.
* @deprecated use getServerInfo() instead or move to private.
*/
bool isRunningAsService() const;
/**
* Implemented from RfbClientManagerEventListener.
*
* Does nothing.
*/
virtual void afterFirstClientConnect();
/**
* Implemented from RfbClientManagerEventListener.
*
* Does specifed in configuration action when last client disconnects from
* rfb server.
*/
virtual void afterLastClientDisconnect();
protected:
void restartHttpServer();
void restartControlServer();
void restartMainRfbServer();
void stopHttpServer();
void stopControlServer();
void stopMainRfbServer();
// Calls a callback function to change update log properties.
void changeLogProps();
protected:
LogWriter m_log;
ZombieKiller m_zombieKiller;
Configurator m_config;
/**
* Shortcut to global server configuration.
*/
ServerConfig* m_srvConfig;
/**
* Mutex for protecting servers.
*/
LocalMutex m_mutex;
/**
* Flag that determitates if we run in server context.
* true if service, false if application.
*/
const bool m_runAsService;
WinServiceDesktopFactory m_serviceDesktopFactory;
ApplicationDesktopFactory m_applicationDesktopFactory;
/**
* Rfb client manager (for all rfb servers), used by rfb servers
* rfb clients, control server and control clients.
*/
RfbClientManager* m_rfbClientManager;
/**
* Control server.
*/
ControlServer* m_controlServer;
/**
* Builtin http server.
*/
HttpServer* m_httpServer;
/**
* Main rfb server.
*/
RfbServer* m_rfbServer;
/**
* Extra servers for extra ports. This object is not protected by any mutex
* and it does not implement any internal locking, so it should be used with
* caution. Here we change its state on owner creation, on owner deletion
* and on each configuration change (via a listener function called from
* other threads). The listener function is registered after the object
* creation and unregistered before the owner destruction, and its calls are
* properly synchronized. Thus, we can be sure that m_extraRfbServers is not
* used by different threads simultaneously.
*/
ExtraRfbServers m_extraRfbServers;
LogInitListener* m_logInitListener;
UINT m_contextSwitchResolution; // in ms
};
#endif