Initial commit
This commit is contained in:
commit
b7d90b9afe
16245 files changed
+3396666
No files matched your search
@@ -0,0 +1,99 @@
|
||||
/**
|
||||
* Websocket interface to the training area proxy
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
* Created by Christian Ehrlicher, SLSE, 2017-01-11
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <QObject>
|
||||
#include <QQueue>
|
||||
#include <QWebSocketServer>
|
||||
#include <memory>
|
||||
#include <TrainingAreaBase/training_area_telegrams.h>
|
||||
|
||||
#include <Common/logger.h>
|
||||
|
||||
namespace HighLevelArchitecture
|
||||
{
|
||||
class MainHandler;
|
||||
|
||||
|
||||
class WebSocketWrapper;
|
||||
|
||||
class WebSocketHandler : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit WebSocketHandler(int exerciseId, MainHandler *mainHandler, QObject *parent = nullptr);
|
||||
~WebSocketHandler();
|
||||
|
||||
bool init(quint16 listenPort);
|
||||
|
||||
bool isConnected() const
|
||||
{
|
||||
return !m_webSockets.isEmpty();
|
||||
}
|
||||
template <typename T>
|
||||
bool sendTelegram(const T *data, int exerciseId)
|
||||
{
|
||||
if (!isConnected() || !data || m_webSockets.isEmpty())
|
||||
return false;
|
||||
|
||||
return sendTelegramInternal(data,
|
||||
TrainingAreaBase::TetraIcd::Constraints<T>::type(),
|
||||
exerciseId);
|
||||
}
|
||||
|
||||
Q_SIGNALS:
|
||||
void initRequest(const TrainingAreaBase::TetraIcd::Init &request);
|
||||
void vulnerabilityStateRequest(const TrainingAreaBase::TetraIcd::DemandVulnerabilityStateChange &request);
|
||||
void cesHitInformationRequest(const TrainingAreaBase::TetraIcd::CesHitInformation &request);
|
||||
|
||||
public Q_SLOTS:
|
||||
void sendHlaConnectionState();
|
||||
void sendParticipantConnectionStates();
|
||||
void onExternalEquipmentNumberAdded(int equipNo);
|
||||
void onExternalEquipmentNumberRemoved(int equipNo);
|
||||
|
||||
private:
|
||||
void sendDataCommunicationState(int equipNo, bool bIsAvailable);
|
||||
bool sendTelegramInternal(const TrainingAreaBase::TetraIcd::TrainingAreaTelegram *data,
|
||||
const QString &type, int exerciseId);
|
||||
private Q_SLOTS:
|
||||
void onNewConnection();
|
||||
void onWebSocketDisconnected();
|
||||
void onTextMessageReceived(const QByteArray &baJson);
|
||||
private:
|
||||
QWebSocketServer *m_webSocketServer;
|
||||
QVector<std::shared_ptr<WebSocketWrapper>> m_webSockets;
|
||||
MainHandler *m_mainHandler;
|
||||
int m_exerciseId;
|
||||
|
||||
LOGGER_T m_logger;
|
||||
};
|
||||
|
||||
class WebSocketWrapper : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit WebSocketWrapper(QWebSocket *ws);
|
||||
~WebSocketWrapper();
|
||||
|
||||
bool sendTextMessage(const QString &msg, int exerciseId);
|
||||
|
||||
void setExerciseId(int exerciseId);
|
||||
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_exerciseId;
|
||||
};
|
||||
|
||||
} // namespace HighLevelArchitecture
|
||||
Reference in new issue
Block a user