Skip to content

Commit d748c6c

Browse files
author
Mykola Tryshnivskyy
committed
Merge branch 'WD_1.X_dev' of https://portal-ua.globallogic.com/git/wd into WD_1.X_dev
2 parents 3da5325 + e72a9f6 commit d748c6c

File tree

11 files changed

+124
-17
lines changed

11 files changed

+124
-17
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: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@
3636
#include "webdriver_server.h"
3737
#include "webdriver_view_transitions.h"
3838
#include "versioninfo.h"
39+
#include "webdriver_route_table.h"
40+
#include "shutdown_command.h"
3941

4042
#if (WD_TEST_ENABLE_WEB_VIEW == 1)
4143
#include "extension_qt/web_view_creator.h"
@@ -141,16 +143,11 @@ int main(int argc, char *argv[])
141143
return 1;
142144
}
143145

144-
VNCClient *client = new VNCClient();
145-
client->Init("http://127.0.0.1", 5900);
146+
webdriver::RouteTable *routeTableWithShutdownCommand = new webdriver::RouteTable(wd_server->GetRouteTable());
147+
const char shutdownCommandRoute[] = "/-CISCO-shutdown";
148+
routeTableWithShutdownCommand->Add<webdriver::ShutdownCommand>(shutdownCommandRoute);
149+
wd_server->SetRouteTable(routeTableWithShutdownCommand);
146150

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-
}
154151

155152
setQtSettings();
156153
wd_server->Start();
@@ -207,7 +204,9 @@ void PrintHelp() {
207204
<< " described above (port, root, etc.)" << std::endl
208205
<< "wi-server false If true, web inspector will be enabled" << std::endl
209206
<< "wi-port 9222 Web inspector listening port" << std::endl
210-
<< "version Print version information to stdout and exit" << std::endl;
207+
<< "version Print version information to stdout and exit" << std::endl
208+
<< "vnc-port 5900 VNC server listening port" << std::endl
209+
<< "vnc-server 127.0.0.1 VNC server IP address" << std::endl;
211210
}
212211

213212

src/Test/shutdown_command.cc

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#include "shutdown_command.h"
2+
#include <iostream>
3+
#include "webdriver_server.h"
4+
#include <QtGui/QApplication>
5+
6+
namespace webdriver {
7+
8+
ShutdownCommand::ShutdownCommand(const std::vector<std::string> &path_segments,
9+
const base::DictionaryValue * const parameters)
10+
: Command(path_segments, parameters) {}
11+
12+
ShutdownCommand::~ShutdownCommand() { }
13+
14+
void ShutdownCommand::ExecutePost(Response * const response)
15+
{
16+
Server *wd_server = Server::GetInstance();
17+
QApplication::quit();
18+
wd_server->Stop(true);
19+
}
20+
21+
bool ShutdownCommand::DoesPost() const
22+
{
23+
return true;
24+
}
25+
26+
}

src/Test/shutdown_command.h

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#ifndef SHUTDOWN_COMMAND_H
2+
#define SHUTDOWN_COMMAND_H
3+
4+
#include "commands/command.h"
5+
#include "commands/response.h"
6+
7+
namespace webdriver {
8+
9+
class ShutdownCommand : public Command
10+
{
11+
public:
12+
ShutdownCommand(const std::vector<std::string>& path_segments,
13+
const base::DictionaryValue* const parameters);
14+
virtual ~ShutdownCommand();
15+
16+
virtual bool DoesPost() const OVERRIDE;
17+
18+
virtual void ExecutePost(Response* const response) OVERRIDE;
19+
20+
private:
21+
DISALLOW_COPY_AND_ASSIGN(ShutdownCommand);
22+
};
23+
24+
}
25+
26+
#endif // SHUTDOWN_COMMAND_H

src/vnc/vncclient.cc

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,13 @@
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
910

11+
VNCClient* VNCClient::_instance = NULL;
12+
1013
static QMap<quint32, quint16> initializeMap()
1114
{
1215
QMap<quint32, quint16> resultMap;
@@ -70,10 +73,28 @@ VNCClient::~VNCClient()
7073
delete _serverParameters;
7174
}
7275

76+
VNCClient* VNCClient::getInstance()
77+
{
78+
if (NULL == _instance)
79+
{
80+
_instance = new VNCClient();
81+
}
82+
83+
return _instance;
84+
}
85+
7386
bool VNCClient::Init(QString remoteHost, quint16 port)
7487
{
7588
_socket = new QTcpSocket();
76-
_socket->connectToHost(QHostAddress::LocalHost, port);
89+
QHostAddress addr;
90+
91+
if (!addr.setAddress(remoteHost))
92+
{
93+
remoteHost.replace(QRegExp("http*://"), "");
94+
addr.setAddress(remoteHost);
95+
}
96+
97+
_socket->connectToHost(addr, port);
7798

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

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_route_table.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ CommandCreatorPtr RouteTable::GetRouteForURL(const std::string& url, std::string
115115
bool RouteTable::AddRoute(const std::string& uri_pattern,
116116
const CommandCreatorPtr& creator) {
117117
// custom command check
118-
if (!CommandRoutes::IsStandardRoute(uri_pattern)) {
118+
if (false){//!CommandRoutes::IsStandardRoute(uri_pattern)) {
119119
std::vector<std::string> url_segments;
120120
base::SplitString(uri_pattern, '/', &url_segments);
121121

src/webdriver/webdriver_server.cc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
#include "webdriver_server.h"
32
#include "webdriver_route_table.h"
43
#include "commands/command.h"

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)