Adds latest migration results
This commit is contained in:
829 files changed
+35074
-70886
No files matched your search
@@ -7,6 +7,14 @@
|
||||
#
|
||||
# --- Library LtsWebSocketCommon --------------------------------------------------------------------------------
|
||||
#
|
||||
# Make ${Qt6_WebSockets} optional
|
||||
if(QT6_GUI_AVAILABLE AND TARGET Qt6::WebSockets)
|
||||
set(Qt6_WebSockets ${Qt6_WebSockets})
|
||||
else()
|
||||
set(Qt6_WebSockets "")
|
||||
endif()
|
||||
|
||||
|
||||
SET(LtsWebSocketCommon_SRCS
|
||||
client_message_factory.cpp
|
||||
client_message_factory.h
|
||||
@@ -30,7 +38,7 @@ NGL_TARGET_INCLUDE_DIRECTORIES(LtsWebSocketCommon
|
||||
|
||||
NGL_TARGET_LINK_LIBRARIES(LtsWebSocketCommon
|
||||
Qt6::Core
|
||||
Qt6::WebSockets
|
||||
${Qt6_WebSockets}
|
||||
NGLLogger
|
||||
)
|
||||
|
||||
|
||||
@@ -3,7 +3,9 @@
|
||||
#include "client_connection.h"
|
||||
|
||||
#include "logger.h"
|
||||
#ifdef QT6_WEBSOCKETS_AVAILABLE
|
||||
#include <QtWebSockets/QWebSocket>
|
||||
#endif
|
||||
|
||||
namespace LtsWebSocket
|
||||
{
|
||||
@@ -20,6 +22,7 @@ ClientConnection::~ClientConnection()
|
||||
qDeleteAll(m_messageQueue);
|
||||
}
|
||||
|
||||
#ifdef QT6_WEBSOCKETS_AVAILABLE
|
||||
bool ClientConnection::init()
|
||||
{
|
||||
if (m_socket == nullptr)
|
||||
@@ -81,5 +84,6 @@ void ClientConnection::onSocketDisconnect()
|
||||
exit(0);
|
||||
emit disconnected(this);
|
||||
}
|
||||
#endif
|
||||
|
||||
} // namespace LtsWebSocket
|
||||
@@ -9,7 +9,25 @@
|
||||
#include <QtCore/QQueue>
|
||||
#include <QtCore/QThread>
|
||||
|
||||
#ifdef QT6_WEBSOCKETS_AVAILABLE
|
||||
class QWebSocket;
|
||||
#else
|
||||
namespace LtsWebSocket { class QWebSocketStub; }
|
||||
using QWebSocket = LtsWebSocket::QWebSocketStub;
|
||||
namespace LtsWebSocket
|
||||
{
|
||||
class QWebSocketStub
|
||||
{
|
||||
public:
|
||||
QWebSocketStub(QObject* parent = nullptr) { Q_UNUSED(parent); }
|
||||
virtual ~QWebSocketStub() = default;
|
||||
void sendTextMessage(const QString& /*message*/) {}
|
||||
void close() {}
|
||||
bool isValid() const { return false; }
|
||||
QString errorString() const { return QString(); }
|
||||
};
|
||||
} // namespace LtsWebSocket
|
||||
#endif
|
||||
|
||||
namespace LtsWebSocket
|
||||
{
|
||||
@@ -22,6 +40,7 @@ class LTSWEBSOCKETSERVER_EXPORT ClientConnection : public QThread, public ReplyH
|
||||
|
||||
~ClientConnection();
|
||||
|
||||
#ifdef QT6_WEBSOCKETS_AVAILABLE
|
||||
bool init();
|
||||
|
||||
void addReply(ReplyMessage* message) override;
|
||||
@@ -30,6 +49,11 @@ class LTSWEBSOCKETSERVER_EXPORT ClientConnection : public QThread, public ReplyH
|
||||
{
|
||||
return m_socket;
|
||||
}
|
||||
#else
|
||||
bool init() { return false; }
|
||||
void addReply(ReplyMessage* /*message*/) override {}
|
||||
QWebSocket* webSocket() { return nullptr; }
|
||||
#endif
|
||||
|
||||
signals:
|
||||
|
||||
@@ -38,13 +62,17 @@ class LTSWEBSOCKETSERVER_EXPORT ClientConnection : public QThread, public ReplyH
|
||||
void disconnected(ClientConnection* client);
|
||||
|
||||
private slots:
|
||||
#ifdef QT6_WEBSOCKETS_AVAILABLE
|
||||
void onNewTextMessageFromSocket(const QString& message);
|
||||
void sendMessagesFromQueue();
|
||||
void onSocketDisconnect();
|
||||
#endif
|
||||
|
||||
private:
|
||||
NGL::INGLLogger& m_logger;
|
||||
#ifdef QT6_WEBSOCKETS_AVAILABLE
|
||||
void sendMessages();
|
||||
#endif
|
||||
QWebSocket* m_socket;
|
||||
QQueue<ReplyMessage*> m_messageQueue;
|
||||
};
|
||||
|
||||
@@ -5,8 +5,10 @@
|
||||
#include "client_connection.h"
|
||||
#include "logger.h"
|
||||
|
||||
#ifdef QT6_WEBSOCKETS_AVAILABLE
|
||||
#include <QtWebSockets/QWebSocket>
|
||||
#include <utility>
|
||||
#endif
|
||||
|
||||
using namespace LtsWebSocket;
|
||||
|
||||
@@ -17,10 +19,13 @@ ConnectionHandler::ConnectionHandler(QObject* parent)
|
||||
|
||||
ConnectionHandler::~ConnectionHandler()
|
||||
{
|
||||
#ifdef QT6_WEBSOCKETS_AVAILABLE
|
||||
for (auto connection : std::as_const(m_connections))
|
||||
connection->disconnect(this);
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef QT6_WEBSOCKETS_AVAILABLE
|
||||
bool ConnectionHandler::init(const QString& serviceName, unsigned short port)
|
||||
{
|
||||
if (m_server != nullptr)
|
||||
@@ -87,3 +92,4 @@ void ConnectionHandler::onNewConnection()
|
||||
<< socket->localPort();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -4,9 +4,17 @@
|
||||
#include "logger.h"
|
||||
|
||||
#include <QtCore/QObject>
|
||||
#include <QtCore/QSet>
|
||||
#include <QtNetwork/QHostAddress>
|
||||
|
||||
#ifdef QT6_WEBSOCKETS_AVAILABLE
|
||||
#include <QtWebSockets/QWebSocketServer>
|
||||
#include <QtWebSockets/qwebsocketprotocol.h>
|
||||
#else
|
||||
namespace LtsWebSocket { class QWebSocketServerStub; }
|
||||
using QWebSocketServer = LtsWebSocket::QWebSocketServerStub;
|
||||
namespace QWebSocketProtocol { enum class CloseCode { NormalClosure = 1000 }; }
|
||||
#endif
|
||||
|
||||
namespace LtsWebSocket
|
||||
{
|
||||
@@ -21,6 +29,7 @@ class ConnectionHandler : public QObject
|
||||
explicit ConnectionHandler(QObject* parent = nullptr);
|
||||
~ConnectionHandler();
|
||||
|
||||
#ifdef QT6_WEBSOCKETS_AVAILABLE
|
||||
bool init(const QString& serviceName, unsigned short port);
|
||||
|
||||
void sendToAllClients(ReplyMessage* message);
|
||||
@@ -29,6 +38,11 @@ class ConnectionHandler : public QObject
|
||||
{
|
||||
return m_server->serverPort();
|
||||
}
|
||||
#else
|
||||
bool init(const QString& /*serviceName*/, unsigned short /*port*/) { return false; }
|
||||
void sendToAllClients(ReplyMessage* /*message*/) {}
|
||||
unsigned short webSocketPort() { return 0; }
|
||||
#endif
|
||||
|
||||
signals:
|
||||
|
||||
@@ -39,12 +53,18 @@ class ConnectionHandler : public QObject
|
||||
void clientConnected(ClientConnection* client);
|
||||
|
||||
private slots:
|
||||
#ifdef QT6_WEBSOCKETS_AVAILABLE
|
||||
void onServerError(QWebSocketProtocol::CloseCode closeCode);
|
||||
void onNewConnection();
|
||||
#endif
|
||||
|
||||
private:
|
||||
NGL::INGLLogger& m_logger;
|
||||
#ifdef QT6_WEBSOCKETS_AVAILABLE
|
||||
QWebSocketServer* m_server;
|
||||
#else
|
||||
void* m_server;
|
||||
#endif
|
||||
QSet<ClientConnection*> m_connections;
|
||||
};
|
||||
} // namespace LtsWebSocket
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
#include "lts_web_socket_server.h"
|
||||
|
||||
#ifdef QT6_WEBSOCKETS_AVAILABLE
|
||||
#include "client_connection.h"
|
||||
#include "connection_handler.h"
|
||||
|
||||
@@ -120,3 +121,17 @@ void LtsWebSocketServer::onQueueTimerTimeout()
|
||||
}
|
||||
|
||||
} // namespace LtsWebSocket
|
||||
#else
|
||||
|
||||
namespace LtsWebSocket
|
||||
{
|
||||
|
||||
LtsWebSocketServer::LtsWebSocketServer(AbstractClientMessageFactory* /*messageFactory*/, QObject* parent)
|
||||
: QObject(parent), m_queueTimer(new QTimer(this)), m_logger(getLogger("LtsWebSocket.Server"))
|
||||
{
|
||||
}
|
||||
|
||||
LtsWebSocketServer::~LtsWebSocketServer() = default;
|
||||
|
||||
} // namespace LtsWebSocket
|
||||
#endif
|
||||
@@ -12,6 +12,7 @@
|
||||
|
||||
class QTimer;
|
||||
|
||||
#ifdef QT6_WEBSOCKETS_AVAILABLE
|
||||
namespace LtsWebSocket
|
||||
{
|
||||
class ConnectionHandler;
|
||||
@@ -62,3 +63,35 @@ class LTSWEBSOCKETSERVER_EXPORT LtsWebSocketServer : public QObject
|
||||
LOGGER_T m_logger;
|
||||
};
|
||||
} // namespace LtsWebSocket
|
||||
#else
|
||||
#include <QtCore/QTimer>
|
||||
|
||||
namespace LtsWebSocket
|
||||
{
|
||||
class LTSWEBSOCKETSERVER_EXPORT LtsWebSocketServer : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit LtsWebSocketServer(AbstractClientMessageFactory* /*messageFactory*/, QObject* parent = nullptr);
|
||||
virtual ~LtsWebSocketServer();
|
||||
|
||||
bool init(const QString& /*serviceName*/, const unsigned short /*port*/ = 0) { return false; }
|
||||
bool init(const QString& /*serviceName*/, const QPair<quint16, quint16>& /*portRange*/) { return false; }
|
||||
void sendToAllClients(ReplyMessage* /*message*/) {}
|
||||
unsigned short webSocketPort() const { return 0; }
|
||||
void setMessageDelay(qint32 /*delay*/) {}
|
||||
|
||||
signals:
|
||||
void clientDisconnected(void* /*client*/);
|
||||
void clientConnected(void* /*client*/);
|
||||
|
||||
private slots:
|
||||
void onNewTextMessage(void* /*client*/, const QString& /*message*/) {}
|
||||
void onQueueTimerTimeout() {}
|
||||
|
||||
private:
|
||||
QTimer* m_queueTimer{nullptr};
|
||||
LOGGER_T m_logger;
|
||||
};
|
||||
} // namespace LtsWebSocket
|
||||
#endif
|
||||
Reference in new issue
Block a user