blob: d882d9cd8e60764caab15cd1427e9daa2b32025f (
plain)
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
|
// Copyright (C) 2017 Ford Motor Company
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
#include "timemodel.h"
#include <QCoreApplication>
#include <QSslConfiguration>
#include "sslserver.h"
#include <QRemoteObjectHost>
/*
* http://stackoverflow.com/questions/7404163/windows-handling-ctrlc-in-different-thread
*/
void SigIntHandler()
{
qDebug()<<"Ctrl-C received. Quitting.";
qApp->quit();
}
#if defined(Q_OS_UNIX) || defined(Q_OS_LINUX) || defined(Q_OS_QNX)
#include <signal.h>
void unix_handler(int s)
{
if (s==SIGINT)
SigIntHandler();
}
#elif defined(Q_OS_WIN32)
#include <windows.h>
BOOL WINAPI WinHandler(DWORD CEvent)
{
switch (CEvent)
{
case CTRL_C_EVENT:
SigIntHandler();
break;
}
return TRUE;
}
#endif
int main(int argc, char *argv[])
{
QCoreApplication app(argc, argv);
auto config = QSslConfiguration::defaultConfiguration();
config.setCaCertificates(QSslCertificate::fromPath(QStringLiteral(":/sslcert/rootCA.pem")));
QSslConfiguration::setDefaultConfiguration(config);
#if defined(Q_OS_UNIX) || defined(Q_OS_LINUX) || defined(Q_OS_QNX)
signal(SIGINT, &unix_handler);
#elif defined(Q_OS_WIN32)
SetConsoleCtrlHandler((PHANDLER_ROUTINE)WinHandler, TRUE);
#endif
QRemoteObjectHost host;
SslServer server;
server.listen(QHostAddress::Any, 65511);
host.setHostUrl(server.serverAddress().toString(), QRemoteObjectHost::AllowExternalRegistration);
QObject::connect(&server, &SslServer::encryptedSocketReady, &server, [&host](QSslSocket *socket) {
QObject::connect(socket, &QSslSocket::errorOccurred,
socket, [](QAbstractSocket::SocketError error){
qDebug() << "QSslSocket::error" << error;
}) ;
host.addHostSideConnection(socket);
});
MinuteTimer timer;
host.enableRemoting(&timer);
Q_UNUSED(timer)
return app.exec();
}
|