Qt6 migration: LtsWidgets API fixes, LtsWebSocket logger init, RTI Docker install
- LtsWidgets: Fixed Qt6 API compatibility issues - QWheelEvent::delta() → angleDelta().y() - QStyleOption::init() → initFrom() - QComboBox activated signal signature change - QTextCodec removal (UTF-8 default in Qt6) - Missing widget includes added - LtsWebSocket: Fixed m_logger reference initialization - Added NGLLoggerBootstrap includes - Proper initialization in constructor initializer lists - CMake: Added BUILD_LTSWEBSOCKET option for temporary exclusion - Docker: RTI Connext permanent installation script added - ci/install-rti-in-docker.sh for persistent RTI setup - Removes need for volume mounting RTI into container - BUILD options: FilterManagement, RTI, Codification, Grantlee, LtsWebSocket can be disabled for partial builds during migration Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
69 files changed
+12765
-14202
No files matched your search
Executable → Regular
+48
-46
@@ -2,82 +2,84 @@
|
||||
|
||||
#include "client_connection.h"
|
||||
|
||||
#include <NGLLogger/NGLLoggerBootstrap.h>
|
||||
#include <QWebSocket>
|
||||
|
||||
namespace LtsWebSocket
|
||||
{
|
||||
|
||||
ClientConnection::ClientConnection(QWebSocket *socket, QObject *parent)
|
||||
: QThread(parent)
|
||||
, m_socket(socket ? socket : new QWebSocket)
|
||||
ClientConnection::ClientConnection(QWebSocket* socket, QObject* parent)
|
||||
: QThread(parent), m_logger(NGL::NGLLoggerBootstrap::getLogger()), m_socket(socket ? socket : new QWebSocket)
|
||||
{
|
||||
}
|
||||
|
||||
ClientConnection::~ClientConnection()
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "Thread closed" << this;
|
||||
delete m_socket;
|
||||
qDeleteAll(m_messageQueue);
|
||||
DEBUG_LOG(m_logger) << "Thread closed" << this;
|
||||
delete m_socket;
|
||||
qDeleteAll(m_messageQueue);
|
||||
}
|
||||
|
||||
bool ClientConnection::init()
|
||||
{
|
||||
if (m_socket == nullptr)
|
||||
{
|
||||
ERROR_LOG(m_logger) << "Initialisation failed due to an invalid socket";
|
||||
return false;
|
||||
}
|
||||
if (m_socket == nullptr)
|
||||
{
|
||||
ERROR_LOG(m_logger) << "Initialisation failed due to an invalid socket";
|
||||
return false;
|
||||
}
|
||||
|
||||
DEBUG_LOG(m_logger) << "Started new thread" << this;
|
||||
connect(m_socket, &QWebSocket::textMessageReceived, this, &ClientConnection::onNewTextMessageFromSocket, Qt::DirectConnection);
|
||||
connect(m_socket, &QWebSocket::connected, this, &ClientConnection::sendMessagesFromQueue);
|
||||
connect(m_socket, &QWebSocket::disconnected, this, &ClientConnection::onSocketDisconnect);
|
||||
DEBUG_LOG(m_logger) << "Started new thread" << this;
|
||||
connect(m_socket, &QWebSocket::textMessageReceived, this, &ClientConnection::onNewTextMessageFromSocket,
|
||||
Qt::DirectConnection);
|
||||
connect(m_socket, &QWebSocket::connected, this, &ClientConnection::sendMessagesFromQueue);
|
||||
connect(m_socket, &QWebSocket::disconnected, this, &ClientConnection::onSocketDisconnect);
|
||||
|
||||
return true;
|
||||
return true;
|
||||
}
|
||||
|
||||
void ClientConnection::addReply(ReplyMessage *message)
|
||||
void ClientConnection::addReply(ReplyMessage* message)
|
||||
{
|
||||
if (!m_socket || m_socket->state() != QAbstractSocket::ConnectedState)
|
||||
{
|
||||
m_messageQueue.enqueue(message);
|
||||
DEBUG_LOG(m_logger) << "Adding message to queue, size: " << m_messageQueue.size();
|
||||
return;
|
||||
}
|
||||
const QString msg(message->toJsonString());
|
||||
DEBUG_LOG(m_logger) << "Sending message: " << msg ;
|
||||
m_socket->sendTextMessage(msg);
|
||||
delete message;
|
||||
if (!m_socket || m_socket->state() != QAbstractSocket::ConnectedState)
|
||||
{
|
||||
m_messageQueue.enqueue(message);
|
||||
DEBUG_LOG(m_logger) << "Adding message to queue, size: " << m_messageQueue.size();
|
||||
return;
|
||||
}
|
||||
const QString msg(message->toJsonString());
|
||||
DEBUG_LOG(m_logger) << "Sending message: " << msg;
|
||||
m_socket->sendTextMessage(msg);
|
||||
delete message;
|
||||
}
|
||||
|
||||
void ClientConnection::onNewTextMessageFromSocket(const QString &message)
|
||||
void ClientConnection::onNewTextMessageFromSocket(const QString& message)
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "Recv msg: " << message << this;
|
||||
emit newTextMessage(this, message);
|
||||
DEBUG_LOG(m_logger) << "Recv msg: " << message << this;
|
||||
emit newTextMessage(this, message);
|
||||
}
|
||||
|
||||
void ClientConnection::sendMessagesFromQueue()
|
||||
{
|
||||
INFO_LOG(m_logger) << "Client connected ip: " << m_socket->peerAddress().toString() << ":" << m_socket->peerPort();
|
||||
INFO_LOG(m_logger) << "Client connected ip: " << m_socket->peerAddress().toString() << ":" << m_socket->peerPort();
|
||||
|
||||
if (m_socket->state() != QAbstractSocket::ConnectedState)
|
||||
return;
|
||||
while (!m_messageQueue.isEmpty())
|
||||
{
|
||||
ReplyMessage *message = m_messageQueue.dequeue();
|
||||
const QString msg(message->toJsonString());
|
||||
TRACE_LOG(m_logger) << "Send msg: " << msg;
|
||||
m_socket->sendTextMessage(msg);
|
||||
delete message;
|
||||
DEBUG_LOG(m_logger) << "Sent message from queue, new size: " << m_messageQueue.size();
|
||||
}
|
||||
if (m_socket->state() != QAbstractSocket::ConnectedState)
|
||||
return;
|
||||
while (!m_messageQueue.isEmpty())
|
||||
{
|
||||
ReplyMessage* message = m_messageQueue.dequeue();
|
||||
const QString msg(message->toJsonString());
|
||||
TRACE_LOG(m_logger) << "Send msg: " << msg;
|
||||
m_socket->sendTextMessage(msg);
|
||||
delete message;
|
||||
DEBUG_LOG(m_logger) << "Sent message from queue, new size: " << m_messageQueue.size();
|
||||
}
|
||||
}
|
||||
|
||||
void ClientConnection::onSocketDisconnect()
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "Client disconnected ip: " << m_socket->peerAddress().toString() << ":" << m_socket->peerPort();
|
||||
exit(0);
|
||||
emit disconnected(this);
|
||||
DEBUG_LOG(m_logger) << "Client disconnected ip: " << m_socket->peerAddress().toString() << ":"
|
||||
<< m_socket->peerPort();
|
||||
exit(0);
|
||||
emit disconnected(this);
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace LtsWebSocket
|
||||
Executable → Regular
+30
-48
@@ -1,69 +1,51 @@
|
||||
|
||||
|
||||
#pragma once
|
||||
#include <QObject>
|
||||
|
||||
#include <QtCore/QThread>
|
||||
#include <QtCore/QQueue>
|
||||
|
||||
#include "reply_message.h"
|
||||
#include "logger.h"
|
||||
#include "ltswebsocketserver_export.h"
|
||||
#include "reply_message.h"
|
||||
|
||||
#include <QObject>
|
||||
#include <QtCore/QQueue>
|
||||
#include <QtCore/QThread>
|
||||
|
||||
class QWebSocket;
|
||||
|
||||
namespace LtsWebSocket
|
||||
{
|
||||
|
||||
|
||||
|
||||
class LTSWEBSOCKETSERVER_EXPORT ClientConnection
|
||||
: public QThread
|
||||
, public ReplyHandler
|
||||
class LTSWEBSOCKETSERVER_EXPORT ClientConnection : public QThread, public ReplyHandler
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit ClientConnection(QWebSocket* socket, QObject* parent = nullptr);
|
||||
|
||||
explicit ClientConnection(QWebSocket *socket, QObject *parent = nullptr);
|
||||
~ClientConnection();
|
||||
|
||||
bool init();
|
||||
|
||||
|
||||
void addReply(ReplyMessage* message) override;
|
||||
|
||||
~ClientConnection();
|
||||
QWebSocket* webSocket()
|
||||
{
|
||||
return m_socket;
|
||||
}
|
||||
|
||||
|
||||
signals:
|
||||
|
||||
bool init();
|
||||
void newTextMessage(ClientConnection* client, const QString& message);
|
||||
|
||||
|
||||
void disconnected(ClientConnection* client);
|
||||
|
||||
void addReply(ReplyMessage *message) override;
|
||||
private slots:
|
||||
void onNewTextMessageFromSocket(const QString& message);
|
||||
void sendMessagesFromQueue();
|
||||
void onSocketDisconnect();
|
||||
|
||||
QWebSocket *webSocket() { return m_socket; }
|
||||
signals:
|
||||
|
||||
|
||||
void newTextMessage(ClientConnection *client, const QString &message);
|
||||
|
||||
|
||||
|
||||
void disconnected(ClientConnection *client);
|
||||
|
||||
|
||||
private slots:
|
||||
void onNewTextMessageFromSocket(const QString &message);
|
||||
void sendMessagesFromQueue();
|
||||
void onSocketDisconnect();
|
||||
private:
|
||||
|
||||
|
||||
NGL::INGLLogger &m_logger;
|
||||
void sendMessages();
|
||||
|
||||
private:
|
||||
NGL::INGLLogger &m_logger;
|
||||
QWebSocket *m_socket;
|
||||
QQueue<ReplyMessage *> m_messageQueue;
|
||||
};
|
||||
}
|
||||
private:
|
||||
NGL::INGLLogger& m_logger;
|
||||
void sendMessages();
|
||||
QWebSocket* m_socket;
|
||||
QQueue<ReplyMessage*> m_messageQueue;
|
||||
};
|
||||
} // namespace LtsWebSocket
|
||||
Executable → Regular
+39
-40
@@ -3,67 +3,66 @@
|
||||
#pragma once
|
||||
|
||||
#include "client_message.h"
|
||||
#include "reply_message.h"
|
||||
#include "ltswebsocketcommon_export.h"
|
||||
#include "reply_message.h"
|
||||
|
||||
#include <QString>
|
||||
#include <QJsonParseError>
|
||||
#include <QString>
|
||||
|
||||
namespace NGL
|
||||
{
|
||||
class INGLLogger;
|
||||
}
|
||||
|
||||
namespace LtsWebSocket
|
||||
{
|
||||
|
||||
|
||||
|
||||
class LTSWEBSOCKETCOMMON_EXPORT AbstractClientMessageFactory
|
||||
{
|
||||
public:
|
||||
explicit AbstractClientMessageFactory(NGL::INGLLogger &logger)
|
||||
: m_logger(logger)
|
||||
{}
|
||||
public:
|
||||
explicit AbstractClientMessageFactory(NGL::INGLLogger& logger) : m_logger(logger) {}
|
||||
|
||||
virtual ~AbstractClientMessageFactory() {}
|
||||
virtual ~AbstractClientMessageFactory() {}
|
||||
|
||||
|
||||
QJsonParseError parseMessage(const QString& message);
|
||||
|
||||
QJsonParseError parseMessage(const QString &message);
|
||||
virtual AbstractClientMessage* createMessage(ReplyHandler* client, const QString& message) = 0;
|
||||
|
||||
|
||||
protected:
|
||||
AbstractClientMessage* checkAttributes(ReplyHandler* client, const QString& message) const;
|
||||
AbstractClientMessage* checkResult(ReplyHandler* client, const QString& message,
|
||||
AbstractClientMessage* result) const;
|
||||
|
||||
virtual AbstractClientMessage *createMessage(ReplyHandler *client, const QString &message) = 0;
|
||||
|
||||
protected:
|
||||
AbstractClientMessage *checkAttributes(ReplyHandler *client,
|
||||
const QString &message) const;
|
||||
AbstractClientMessage *checkResult(ReplyHandler *client,
|
||||
const QString &message,
|
||||
AbstractClientMessage *result) const;
|
||||
protected:
|
||||
QString m_type;
|
||||
int m_typeId;
|
||||
QString m_uuid;
|
||||
QJsonValue m_data;
|
||||
};
|
||||
protected:
|
||||
NGL::INGLLogger& m_logger;
|
||||
QString m_type;
|
||||
int m_typeId;
|
||||
QString m_uuid;
|
||||
QJsonValue m_data;
|
||||
};
|
||||
|
||||
class PongMessage final : public ReplyMessage
|
||||
{
|
||||
public:
|
||||
static QString strPong() { return QStringLiteral("pong"); }
|
||||
static int idPong() { return 2; }
|
||||
explicit PongMessage(const QString &payload)
|
||||
: ReplyMessage(strPong(), idPong(), QString())
|
||||
, m_payload(payload)
|
||||
{}
|
||||
public:
|
||||
static QString strPong()
|
||||
{
|
||||
return QStringLiteral("pong");
|
||||
}
|
||||
|
||||
QString toJsonString() const override
|
||||
{
|
||||
return m_payload.isEmpty() ? strPong() : QStringLiteral("%1 %2").arg(strPong(), m_payload);
|
||||
}
|
||||
private:
|
||||
QString m_payload;
|
||||
static int idPong()
|
||||
{
|
||||
return 2;
|
||||
}
|
||||
|
||||
explicit PongMessage(const QString& payload) : ReplyMessage(strPong(), idPong(), QString()), m_payload(payload) {}
|
||||
|
||||
QString toJsonString() const override
|
||||
{
|
||||
return m_payload.isEmpty() ? strPong() : QStringLiteral("%1 %2").arg(strPong(), m_payload);
|
||||
}
|
||||
|
||||
private:
|
||||
QString m_payload;
|
||||
};
|
||||
|
||||
}
|
||||
} // namespace LtsWebSocket
|
||||
Executable → Regular
+54
-53
@@ -1,88 +1,89 @@
|
||||
|
||||
|
||||
#include "connection_handler.h"
|
||||
#include <utility>
|
||||
|
||||
#include "client_connection.h"
|
||||
|
||||
#include <NGLLogger/NGLLoggerBootstrap.h>
|
||||
#include <QtWebSockets/QWebSocket>
|
||||
#include <utility>
|
||||
|
||||
using namespace LtsWebSocket;
|
||||
|
||||
ConnectionHandler::ConnectionHandler(QObject *parent) : QObject(parent)
|
||||
, m_server(nullptr),
|
||||
m_logger(NGL::NGLLoggerBootstrap::getLogger()) {}
|
||||
ConnectionHandler::ConnectionHandler(QObject* parent)
|
||||
: QObject(parent), m_server(nullptr), m_logger(NGL::NGLLoggerBootstrap::getLogger())
|
||||
{
|
||||
}
|
||||
|
||||
ConnectionHandler::~ConnectionHandler()
|
||||
{
|
||||
for (auto connection : std::as_const(m_connections))
|
||||
connection->disconnect(this);
|
||||
for (auto connection : std::as_const(m_connections))
|
||||
connection->disconnect(this);
|
||||
}
|
||||
|
||||
bool ConnectionHandler::init(const QString &serviceName, unsigned short port)
|
||||
bool ConnectionHandler::init(const QString& serviceName, unsigned short port)
|
||||
{
|
||||
if (m_server != nullptr)
|
||||
{
|
||||
m_server->disconnect();
|
||||
delete m_server;
|
||||
}
|
||||
|
||||
m_server = new QWebSocketServer(QStringLiteral("RME-") + serviceName, QWebSocketServer::NonSecureMode, this);
|
||||
if (m_server != nullptr)
|
||||
{
|
||||
m_server->disconnect();
|
||||
delete m_server;
|
||||
}
|
||||
|
||||
connect(m_server, &QWebSocketServer::newConnection, this, &ConnectionHandler::onNewConnection);
|
||||
connect(m_server, &QWebSocketServer::serverError, this, &ConnectionHandler::onServerError);
|
||||
m_server = new QWebSocketServer(QStringLiteral("RME-") + serviceName, QWebSocketServer::NonSecureMode, this);
|
||||
|
||||
DEBUG_LOG(m_logger) << "Trying to listen ";
|
||||
if (!m_server->listen(QHostAddress::Any, port))
|
||||
{
|
||||
ERROR_LOG(m_logger) << "Not possible to listen to port " << port;
|
||||
return false;
|
||||
}
|
||||
DEBUG_LOG(m_logger) << "... ok, port " << m_server->serverPort();
|
||||
connect(m_server, &QWebSocketServer::newConnection, this, &ConnectionHandler::onNewConnection);
|
||||
connect(m_server, &QWebSocketServer::serverError, this, &ConnectionHandler::onServerError);
|
||||
|
||||
return true;
|
||||
DEBUG_LOG(m_logger) << "Trying to listen ";
|
||||
if (!m_server->listen(QHostAddress::Any, port))
|
||||
{
|
||||
ERROR_LOG(m_logger) << "Not possible to listen to port " << port;
|
||||
return false;
|
||||
}
|
||||
DEBUG_LOG(m_logger) << "... ok, port " << m_server->serverPort();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void ConnectionHandler::sendToAllClients(ReplyMessage *message)
|
||||
void ConnectionHandler::sendToAllClients(ReplyMessage* message)
|
||||
{
|
||||
for (auto connection : std::as_const(m_connections))
|
||||
connection->addReply(new ReplyMessage(*message));
|
||||
for (auto connection : std::as_const(m_connections))
|
||||
connection->addReply(new ReplyMessage(*message));
|
||||
|
||||
delete message;
|
||||
delete message;
|
||||
}
|
||||
|
||||
void ConnectionHandler::onServerError(QWebSocketProtocol::CloseCode closeCode)
|
||||
{
|
||||
ERROR_LOG(m_logger) << "Got server error with close code " << closeCode;
|
||||
ERROR_LOG(m_logger) << "Got server error with close code " << closeCode;
|
||||
}
|
||||
|
||||
void ConnectionHandler::onNewConnection()
|
||||
{
|
||||
while (m_server->hasPendingConnections())
|
||||
{
|
||||
QWebSocket *socket = m_server->nextPendingConnection();
|
||||
|
||||
ClientConnection *newConnection = new ClientConnection(socket, this);
|
||||
connect(newConnection, &ClientConnection::destroyed, this, [this](QObject* o)
|
||||
while (m_server->hasPendingConnections())
|
||||
{
|
||||
m_connections.remove(static_cast<ClientConnection*>(o));
|
||||
});
|
||||
QWebSocket* socket = m_server->nextPendingConnection();
|
||||
|
||||
if (!newConnection->init())
|
||||
{
|
||||
ERROR_LOG(m_logger) << "Failed to initialise new client";
|
||||
delete newConnection;
|
||||
newConnection = nullptr;
|
||||
continue;
|
||||
ClientConnection* newConnection = new ClientConnection(socket, this);
|
||||
connect(newConnection, &ClientConnection::destroyed, this,
|
||||
[this](QObject* o) { m_connections.remove(static_cast<ClientConnection*>(o)); });
|
||||
|
||||
if (!newConnection->init())
|
||||
{
|
||||
ERROR_LOG(m_logger) << "Failed to initialise new client";
|
||||
delete newConnection;
|
||||
newConnection = nullptr;
|
||||
continue;
|
||||
}
|
||||
newConnection->start();
|
||||
|
||||
connect(newConnection, &ClientConnection::newTextMessage, this, &ConnectionHandler::newTextMessageFromClient);
|
||||
connect(newConnection, &ClientConnection::disconnected, this, &ConnectionHandler::clientDisconnected);
|
||||
connect(newConnection, &ClientConnection::finished, newConnection, &ClientConnection::deleteLater);
|
||||
|
||||
m_connections.insert(newConnection);
|
||||
emit clientConnected(newConnection);
|
||||
INFO_LOG(m_logger) << "New client connected ip: " << socket->localAddress().toString() << ":"
|
||||
<< socket->localPort();
|
||||
}
|
||||
newConnection->start();
|
||||
|
||||
connect(newConnection, &ClientConnection::newTextMessage, this, &ConnectionHandler::newTextMessageFromClient);
|
||||
connect(newConnection, &ClientConnection::disconnected, this, &ConnectionHandler::clientDisconnected);
|
||||
connect(newConnection, &ClientConnection::finished, newConnection, &ClientConnection::deleteLater);
|
||||
|
||||
m_connections.insert(newConnection);
|
||||
emit clientConnected(newConnection);
|
||||
INFO_LOG(m_logger) << "New client connected ip: " << socket->localAddress().toString() << ":" << socket->localPort();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user