Resolves 17 conflicts against legacy Qt5 semantics; validates with BUILD_RTI=ON BUILD_GRANTLEE=ON.
79 lines
2.3 KiB
C++
Executable File
79 lines
2.3 KiB
C++
Executable File
#pragma once
|
|
|
|
#include "ws_interface.h"
|
|
#include "logger.h"
|
|
|
|
#include <TrainingAreaBase/training_area_telegrams.h>
|
|
#include <QtWebSockets/QWebSocketServer>
|
|
#include <QtCore/QObject>
|
|
#include <memory>
|
|
|
|
|
|
namespace TrainingAreaBase
|
|
{
|
|
class WebSocketWrapper;
|
|
|
|
class WebSocketHandler : public WebSocketInterface
|
|
{
|
|
Q_OBJECT
|
|
public:
|
|
explicit WebSocketHandler(QObject *parent = nullptr);
|
|
~WebSocketHandler();
|
|
|
|
// WSInterface interface
|
|
public:
|
|
bool init(quint16 listenPort) override;
|
|
bool isConnected() const override;
|
|
quint16 getPort() const override;
|
|
bool sendTelegram(const int typeId, const QJsonObject *data, const int exerciseId) override;
|
|
bool sendTelegram(const int wsId, const QJsonObject *data) override;
|
|
bool disconnectWs(int wsId) override;
|
|
QString getPeerAddress(int wsId) const override;
|
|
QUrl getPeerUrl(int wsId) const override;
|
|
|
|
int getExerciseId(int wsId) const override;
|
|
|
|
//Q_SIGNALS:
|
|
// void wsDisconnect(const int wsId);
|
|
private Q_SLOTS:
|
|
void onNewConnection();
|
|
void onWebSocketDisconnected();
|
|
void onTextMessageReceived(const QByteArray &baJson);
|
|
private:
|
|
bool sendTelegramInternal(const TrainingAreaBase::TetraIcd::TrainingAreaTelegram *data, const QString &type, int exerciseId);
|
|
bool sendTelegramInternal(const int wsId, const TrainingAreaBase::TetraIcd::TrainingAreaTelegram *data, const QString &type, const int exerciseId);
|
|
int getWSIdFromWS( WebSocketWrapper* wsw );
|
|
private:
|
|
QWebSocketServer *m_webSocketServer;
|
|
//QVector<std::shared_ptr<WebSocketWrapper>> m_webSockets;
|
|
QMap<int, std::shared_ptr<WebSocketWrapper>> m_connections; // key = wsId
|
|
|
|
int m_nextWsId = 1;
|
|
AdlerJson::LOGGER_T m_logger;
|
|
};
|
|
|
|
class WebSocketWrapper : public QObject
|
|
{
|
|
Q_OBJECT
|
|
public:
|
|
explicit WebSocketWrapper(QWebSocket *ws);
|
|
~WebSocketWrapper();
|
|
|
|
bool sendTextMessage(const QString &msg);
|
|
|
|
void setExerciseId(int exerciseId);
|
|
void setWsId(int wsId){ m_wsId = wsId; }
|
|
int getWsId(){ return m_wsId; }
|
|
int exerciseId() const { return m_exerciseId; }
|
|
QWebSocket *webSocket() const { return m_webSocket; }
|
|
Q_SIGNALS:
|
|
void textMessageReceived(const QByteArray &data);
|
|
private Q_SLOTS:
|
|
void onTextMessageReceived(const QString &data);
|
|
private:
|
|
QWebSocket *m_webSocket;
|
|
int m_wsId;
|
|
int m_exerciseId;
|
|
};
|
|
}
|