Initial commit
This commit is contained in:
commit
b7d90b9afe
16245 files changed
+3396666
No files matched your search
@@ -0,0 +1,78 @@
|
||||
#pragma once
|
||||
|
||||
#include "ws_interface.h"
|
||||
#include "logger.h"
|
||||
|
||||
#include <TrainingAreaBase/training_area_telegrams.h>
|
||||
#include <QWebSocketServer>
|
||||
#include <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;
|
||||
};
|
||||
}
|
||||
Reference in new issue
Block a user