Skip to content

Commit ffe1a2d

Browse files
Andrii MorozAndrii Moroz
authored andcommitted
Moved VNC to extensions
1 parent b162d67 commit ffe1a2d

File tree

4 files changed

+40
-23
lines changed

4 files changed

+40
-23
lines changed

src/vnc/vncclient.cc

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
#define MAJOR_INDEX 6
99
#define MINOR_INDEX 10
1010

11+
VNCClient* VNCClient::_instance = NULL;
12+
1113
static QMap<quint32, quint16> initializeMap()
1214
{
1315
QMap<quint32, quint16> resultMap;
@@ -71,6 +73,16 @@ VNCClient::~VNCClient()
7173
delete _serverParameters;
7274
}
7375

76+
VNCClient* VNCClient::getInstance()
77+
{
78+
if (NULL == _instance)
79+
{
80+
_instance = new VNCClient();
81+
}
82+
83+
return _instance;
84+
}
85+
7486
bool VNCClient::Init(QString remoteHost, quint16 port)
7587
{
7688
_socket = new QTcpSocket();

src/vnc/vncclient.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,10 @@ class VNCClient : public QObject
1212
Q_OBJECT
1313

1414
public:
15-
VNCClient();
1615
~VNCClient();
1716

17+
static VNCClient* getInstance();
18+
1819
bool Init(QString remoteHost, quint16 port);
1920
void sendKeyEvent(QKeyEvent *key);
2021
void sendMouseEvent(QMouseEvent *mouse);
@@ -30,6 +31,8 @@ private slots:
3031
void onError(QAbstractSocket::SocketError error);
3132

3233
private:
34+
VNCClient();
35+
3336
bool establishProtocolVersion(QByteArray& data);
3437
bool establishSecurity(QByteArray& data);
3538
bool finishHandshaking(QByteArray& data);
@@ -68,6 +71,7 @@ private slots:
6871
static QMap<quint32, quint16> _keymap;
6972

7073
private:
74+
static VNCClient *_instance;
7175
QTcpSocket *_socket;
7276
bool _versionEstablished;
7377
bool _securityEstablished;

src/webdriver/extension_qt/q_session_lifecycle_actions.cc

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
#include "extension_qt/q_session_lifecycle_actions.h"
2+
#include "extension_qt/wd_event_dispatcher.h"
3+
#include "extension_qt/vnc_event_dispatcher.h"
4+
#include "webdriver_switches.h"
5+
#include "webdriver_server.h"
26

37
#include "q_proxy_parser.h"
48

@@ -29,6 +33,25 @@ Error* QSessionLifeCycleActions::PostInit(const base::DictionaryValue* desired_c
2933
session_->logger().Log(kInfoLogLevel, "no proxy settings requsted.");
3034
}
3135

36+
// start VNC module
37+
CommandLine cmdLine = webdriver::Server::GetInstance()->GetCommandLine();
38+
if (cmdLine.HasSwitch(webdriver::Switches::kVNCServer) || cmdLine.HasSwitch(webdriver::Switches::kVNCPort))
39+
{
40+
QString address = "127.0.0.1";
41+
int port = 5900;
42+
43+
if (cmdLine.HasSwitch(webdriver::Switches::kVNCServer))
44+
address = cmdLine.GetSwitchValueASCII(webdriver::Switches::kVNCServer).c_str();
45+
if (cmdLine.HasSwitch(webdriver::Switches::kVNCPort))
46+
port = QString(cmdLine.GetSwitchValueASCII(webdriver::Switches::kVNCPort).c_str()).toInt();
47+
48+
VNCClient *client = VNCClient::getInstance();
49+
if (!client->isReady())
50+
client->Init(address, port);
51+
52+
WDEventDispatcher::getInstance()->add(new VNCEventDispatcher(client));
53+
}
54+
3255
return error;
3356
}
3457

src/webdriver/webdriver_server.cc

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@
44
#include "webdriver_route_table.h"
55
#include "commands/command.h"
66
#include "commands/response.h"
7-
#include "vnc/vncclient.h"
8-
#include "extension_qt/wd_event_dispatcher.h"
9-
#include "extension_qt/vnc_event_dispatcher.h"
107

118
#include "mongoose.h"
129

@@ -141,25 +138,6 @@ int Server::Start() {
141138
}
142139
opts[mg_options_.size()] = NULL;
143140

144-
// start VNC module
145-
CommandLine cmdLine = webdriver::Server::GetInstance()->GetCommandLine();
146-
if (cmdLine.HasSwitch(webdriver::Switches::kVNCServer) || cmdLine.HasSwitch(webdriver::Switches::kVNCPort))
147-
{
148-
QString address = "127.0.0.1";
149-
int port = 5900;
150-
151-
if (cmdLine.HasSwitch(webdriver::Switches::kVNCServer))
152-
address = cmdLine.GetSwitchValueASCII(webdriver::Switches::kVNCServer).c_str();
153-
if (cmdLine.HasSwitch(webdriver::Switches::kVNCPort))
154-
port = QString(cmdLine.GetSwitchValueASCII(webdriver::Switches::kVNCPort).c_str()).toInt();
155-
156-
VNCClient *client = new VNCClient();
157-
client->Init(address, port);
158-
159-
160-
WDEventDispatcher::getInstance()->add(new VNCEventDispatcher(client));
161-
}
162-
163141
// Initialize SHTTPD context.
164142
mg_ctx_ = mg_start((mg_callback_t)&ProcessHttpRequestCb,
165143
this,

0 commit comments

Comments
 (0)