Skip to content

Commit 545ba2f

Browse files
author
Mykola Tryshnivskyy
committed
Added fix for MHA-655
1 parent 53bdc96 commit 545ba2f

File tree

4 files changed

+74
-4
lines changed

4 files changed

+74
-4
lines changed

src/ServerThread.cc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#include "ServerThread.h"
2+
#include "WebDriver.h"
3+
4+
void ServerThread::run()
5+
{
6+
main_server(argc, argv);
7+
}

src/ServerThread.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#ifndef SERVERTHREAD_H
2+
#define SERVERTHREAD_H
3+
4+
#include <QtCore/QThread>
5+
6+
class ServerThread : public QThread
7+
{
8+
Q_OBJECT
9+
10+
public:
11+
int argc;
12+
char** argv;
13+
14+
protected:
15+
void run();
16+
};
17+
18+
#endif // SERVERTHREAD_H

src/Test/main.cc

Lines changed: 46 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,38 @@
1616

1717
#include <WebDriver.h>
1818

19+
#if defined(_WIN32)
20+
#include <windows.h>
21+
#include <signal.h>
22+
#endif
23+
24+
#include "ServerThread.h"
25+
26+
ServerThread* pServerThread;
27+
28+
#if defined(_WIN32)
29+
BOOL CtrlHandler(DWORD fdwCtrlType)
30+
{
31+
switch (fdwCtrlType)
32+
{
33+
// Handle the CTRL-C signal.
34+
case CTRL_BREAK_EVENT:
35+
case CTRL_C_EVENT:
36+
qDebug() << "try to stop thread";
37+
pServerThread->terminate();
38+
39+
while (!pServerThread->isFinished()) {}
40+
41+
if (!pServerThread->isRunning())
42+
qDebug() << "thread is stopped";
43+
44+
return TRUE;
45+
46+
default:
47+
return FALSE;
48+
}
49+
}
50+
#endif //_WIN32
1951

2052
int main(int argc, char *argv[])
2153
{
@@ -39,11 +71,21 @@ int main(int argc, char *argv[])
3971
QWebSettings::globalSettings()->setOfflineWebApplicationCachePath("./web/html5");
4072

4173
// registerView<QWebView>("QWebView");
74+
#if defined(_WIN32)
75+
SetConsoleCtrlHandler((PHANDLER_ROUTINE)CtrlHandler, TRUE);
76+
#endif //_WIN32
4277

43-
QFutureWatcher<int> watcher;
44-
QObject::connect(&watcher, SIGNAL(finished()), qApp, SLOT(quit()));
45-
QFuture<int> future = QtConcurrent::run(main_server, argc, argv);
46-
watcher.setFuture(future);
78+
//QFutureWatcher<int> watcher;
79+
//QObject::connect(&watcher, SIGNAL(finished()), qApp, SLOT(quit()));
80+
//QFuture<int> future = QtConcurrent::run(main_server, argc, argv);
81+
//watcher.setFuture(future);
82+
pServerThread = new ServerThread;
83+
QObject::connect(pServerThread, SIGNAL(finished()), qApp, SLOT(quit()));
4784

85+
pServerThread->argc = argc;
86+
pServerThread->argv = argv;
87+
pServerThread->start();
88+
4889
return app.exec();
4990
}
91+

wd.gyp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,7 @@
385385
'<(INTERMEDIATE_DIR)/moc_qtaskrunner.cc',
386386
'<(INTERMEDIATE_DIR)/moc_qwebviewext.cc',
387387
'<(INTERMEDIATE_DIR)/moc_webdriver_automation.cc',
388+
'<(INTERMEDIATE_DIR)/moc_ServerThread.cc',
388389
'src/net/base/file_stream.cc',
389390
'src/net/base/file_stream_metrics.cc',
390391
'src/net/base/file_stream_net_log_parameters.cc',
@@ -397,6 +398,8 @@
397398
'src/qwebviewext.cc',
398399
'src/third_party/webdriver/atoms.cc',
399400
'src/viewfactory.cc',
401+
'src/ServerThread.h',
402+
'src/ServerThread.cc',
400403
],
401404

402405
'conditions': [

0 commit comments

Comments
 (0)