Skip to content

Commit b162d67

Browse files
Andrii MorozAndrii Moroz
authored andcommitted
Added command line switches for VNC
Changed VNC start from application to WD
1 parent eab68c7 commit b162d67

File tree

5 files changed

+46
-16
lines changed

5 files changed

+46
-16
lines changed

inc/webdriver_switches.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,13 @@ class Switches {
6969

7070
/// \page page_webdriver_switches WD Server switches
7171
/// - <b>vnc</b><br>
72-
/// Enabling VNC support (by default - false)
73-
static const char kVNCEnabled[];
72+
/// VNC server listening port (by default - 5900)
73+
static const char kVNCPort[];
74+
75+
/// \page page_webdriver_switches WD Server switches
76+
/// - <b>vnc</b><br>
77+
/// VNC server IP address (by default - 127.0.0.1)
78+
static const char kVNCServer[];
7479

7580
};
7681

src/Test/main.cc

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -140,17 +140,6 @@ int main(int argc, char *argv[])
140140
if (0 != wd_server->Configure(cmd_line)) {
141141
return 1;
142142
}
143-
144-
VNCClient *client = new VNCClient();
145-
client->Init("http://127.0.0.1", 5900);
146-
147-
148-
CommandLine cmdLine = webdriver::Server::GetInstance()->GetCommandLine();
149-
150-
if (cmdLine.HasSwitch(webdriver::Switches::kVNCEnabled))
151-
{
152-
WDEventDispatcher::getInstance()->add(new VNCEventDispatcher(client));
153-
}
154143

155144
setQtSettings();
156145
wd_server->Start();
@@ -207,7 +196,9 @@ void PrintHelp() {
207196
<< " described above (port, root, etc.)" << std::endl
208197
<< "wi-server false If true, web inspector will be enabled" << std::endl
209198
<< "wi-port 9222 Web inspector listening port" << std::endl
210-
<< "version Print version information to stdout and exit" << std::endl;
199+
<< "version Print version information to stdout and exit" << std::endl
200+
<< "vnc-port 5900 VNC server listening port" << std::endl
201+
<< "vnc-server 127.0.0.1 VNC server IP address" << std::endl;
211202
}
212203

213204

src/vnc/vncclient.cc

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include <iostream>
44
#include <QtNetwork/QHostAddress>
55
#include <QtCore/QMap>
6+
#include <QtCore/QRegExp>
67

78
#define MAJOR_INDEX 6
89
#define MINOR_INDEX 10
@@ -73,7 +74,15 @@ VNCClient::~VNCClient()
7374
bool VNCClient::Init(QString remoteHost, quint16 port)
7475
{
7576
_socket = new QTcpSocket();
76-
_socket->connectToHost(QHostAddress::LocalHost, port);
77+
QHostAddress addr;
78+
79+
if (!addr.setAddress(remoteHost))
80+
{
81+
remoteHost.replace(QRegExp("http*://"), "");
82+
addr.setAddress(remoteHost);
83+
}
84+
85+
_socket->connectToHost(addr, port);
7786

7887
// QObject::connect(_socket, SIGNAL(bytesWritten(qint64)), this, SLOT(readSocket(qint64)));
7988
QObject::connect(_socket, SIGNAL(readyRead()), this, SLOT(readSocket()));

src/webdriver/webdriver_server.cc

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
1+
#include <QtCore/QString>
12

23
#include "webdriver_server.h"
34
#include "webdriver_route_table.h"
45
#include "commands/command.h"
56
#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"
610

711
#include "mongoose.h"
812

@@ -137,6 +141,25 @@ int Server::Start() {
137141
}
138142
opts[mg_options_.size()] = NULL;
139143

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+
140163
// Initialize SHTTPD context.
141164
mg_ctx_ = mg_start((mg_callback_t)&ProcessHttpRequestCb,
142165
this,

src/webdriver/webdriver_switches.cc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ const char Switches::kWIServer[] = "wi-server";
2222

2323
const char Switches::kWIPort[] = "wi-port";
2424

25-
const char Switches::kVNCEnabled[] = "vnc";
25+
const char Switches::kVNCPort[] = "vnc-port";
26+
27+
const char Switches::kVNCServer[] = "vnc-server";
2628

2729
} // namespace webdriver

0 commit comments

Comments
 (0)