Initial commit
This commit is contained in:
commit
b7d90b9afe
16245 files changed
+3396666
No files matched your search
+94
@@ -0,0 +1,94 @@
|
||||
/**
|
||||
* @RDE_HEADER@
|
||||
* The ClientConnection class represents a connection to a single client.
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
* Created by Hannes Fritsche, SLSE, 2017-09-07
|
||||
*/
|
||||
#include "client_connection.h"
|
||||
|
||||
#include "WebSocketInterface/Messages/reply_message.h"
|
||||
|
||||
#include <QtWebSockets/QWebSocket>
|
||||
#include <QtCore/QTimer>
|
||||
|
||||
using namespace CombatNetRadio::WebSocketInterface::Connection;
|
||||
|
||||
ClientConnection::ClientConnection(QWebSocket *socket, QObject *parent)
|
||||
: QObject(parent)
|
||||
, m_socket(socket)
|
||||
, m_ip(socket->peerAddress())
|
||||
, m_logger(getLogger(QLatin1String("ClientConnection")))
|
||||
{}
|
||||
|
||||
ClientConnection::~ClientConnection()
|
||||
{
|
||||
if (m_socket)
|
||||
{
|
||||
m_socket->disconnect(this);
|
||||
m_socket->close();
|
||||
}
|
||||
delete m_socket;
|
||||
}
|
||||
|
||||
bool ClientConnection::init()
|
||||
{
|
||||
if (m_socket == nullptr)
|
||||
{
|
||||
ERROR_LOG(m_logger) << "Initialisation failed due to an invalid socket";
|
||||
return false;
|
||||
}
|
||||
|
||||
connect(m_socket, &QWebSocket::textMessageReceived, this, &ClientConnection::onNewTextMessageFromSocket);
|
||||
connect(m_socket, &QWebSocket::connected, this, &ClientConnection::sendMessagesFromQueue);
|
||||
connect(m_socket, &QWebSocket::disconnected, this, &ClientConnection::onSocketDisconnect);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
QHostAddress ClientConnection::ip() const
|
||||
{
|
||||
return m_ip;
|
||||
}
|
||||
|
||||
void ClientConnection::addMessage(const CombatNetRadio::WebSocketInterface::Messages::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) << "Send msg: " << msg;
|
||||
m_socket->sendTextMessage(msg);
|
||||
}
|
||||
|
||||
void ClientConnection::onNewTextMessageFromSocket(const QString &message)
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "Recv msg: " << message;
|
||||
emit newTextMessage(this, message);
|
||||
}
|
||||
|
||||
void ClientConnection::sendMessagesFromQueue()
|
||||
{
|
||||
if (m_socket->state() != QAbstractSocket::ConnectedState)
|
||||
return;
|
||||
while (!m_messageQueue.isEmpty())
|
||||
{
|
||||
Messages::ReplyMessage message = m_messageQueue.dequeue();
|
||||
const QString msg(message.toJsonString());
|
||||
TRACE_LOG(m_logger) << "Send msg: " << msg;
|
||||
m_socket->sendTextMessage(msg);
|
||||
DEBUG_LOG(m_logger) << "Sent message from queue, new size: " << m_messageQueue.size();
|
||||
}
|
||||
}
|
||||
|
||||
void ClientConnection::onSocketDisconnect()
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "Client with ip "
|
||||
<< m_ip.toString()
|
||||
<< " disconnected";
|
||||
emit disconnected(this);
|
||||
}
|
||||
+60
@@ -0,0 +1,60 @@
|
||||
/**
|
||||
* @RDE_HEADER@
|
||||
* The ClientConnection class represents a connection to a single client.
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
* Created by Hannes Fritsche, SLSE, 2017-09-07
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include <QtCore/QQueue>
|
||||
#include <QtNetwork/QHostAddress>
|
||||
|
||||
#include "WebSocketInterface/Messages/message_transmitter.h"
|
||||
#include "logger.h"
|
||||
|
||||
class QWebSocket;
|
||||
class QTimer;
|
||||
|
||||
namespace CombatNetRadio
|
||||
{
|
||||
namespace WebSocketInterface
|
||||
{
|
||||
namespace Connection
|
||||
{
|
||||
class ClientConnection
|
||||
: public QObject
|
||||
, public Messages::MessageTransmitter
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit ClientConnection(QWebSocket *socket, QObject *parent = nullptr);
|
||||
~ClientConnection();
|
||||
|
||||
bool init();
|
||||
QHostAddress ip() const;
|
||||
void addMessage(const Messages::ReplyMessage &message) override final;
|
||||
|
||||
Q_SIGNALS:
|
||||
void newTextMessage(MessageTransmitter *transmitter, const QString &message);
|
||||
void disconnected(ClientConnection *conn);
|
||||
|
||||
private Q_SLOTS:
|
||||
void onNewTextMessageFromSocket(const QString &message);
|
||||
void sendMessagesFromQueue();
|
||||
void onSocketDisconnect();
|
||||
|
||||
private: // methods
|
||||
void sendMessages();
|
||||
|
||||
private: // attributes
|
||||
QWebSocket *m_socket;
|
||||
QQueue<Messages::ReplyMessage> m_messageQueue;
|
||||
QHostAddress m_ip;
|
||||
|
||||
LOGGER_T m_logger;
|
||||
}; // class ClientConnection
|
||||
} // namespace Connection
|
||||
} // namespace WebSocketInterface
|
||||
} // namespace CombatNetRadio
|
||||
+114
@@ -0,0 +1,114 @@
|
||||
/**
|
||||
* @RDE_HEADER@
|
||||
* The ConnectionHandler class functions as a WebSocket server and manages incoming client connections.
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
* Created by Hannes Fritsche, SLSE, 2017-09-07
|
||||
*/
|
||||
#include "connection_handler.h"
|
||||
|
||||
#include "client_connection.h"
|
||||
|
||||
#include <QtWebSockets/QWebSocketServer>
|
||||
#include <QtWebSockets/QWebSocket>
|
||||
|
||||
using namespace CombatNetRadio::WebSocketInterface::Connection;
|
||||
|
||||
ConnectionHandler::ConnectionHandler()
|
||||
: m_server(nullptr)
|
||||
, m_logger(getLogger("ConnectionHandler"))
|
||||
{
|
||||
}
|
||||
|
||||
ConnectionHandler::~ConnectionHandler()
|
||||
{
|
||||
for (auto s : qAsConst(m_connections))
|
||||
s->disconnect(this);
|
||||
qDeleteAll(m_connections);
|
||||
}
|
||||
|
||||
bool ConnectionHandler::init()
|
||||
{
|
||||
if (m_server != nullptr)
|
||||
{
|
||||
m_server->disconnect();
|
||||
delete m_server;
|
||||
}
|
||||
// TODO: get a server name from config ?
|
||||
// TODO: get the SslMode from config ?
|
||||
m_server = new QWebSocketServer(QStringLiteral("RDE-EXC"), QWebSocketServer::NonSecureMode, this);
|
||||
|
||||
connect(m_server, &QWebSocketServer::newConnection, this, &ConnectionHandler::onNewConnection);
|
||||
connect(m_server, &QWebSocketServer::serverError, this, &ConnectionHandler::onServerError);
|
||||
|
||||
// TODO: read port from config?
|
||||
quint16 port = 2081;
|
||||
DEBUG_LOG(m_logger) << "Trying to listen to port " << port;
|
||||
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";
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void ConnectionHandler::onUpdate()
|
||||
{
|
||||
emit clearFrequencyPlanningStatus();
|
||||
for (ClientConnection *currentConnection : qAsConst(m_connections))
|
||||
currentConnection->addMessage(Messages::UpdateMessage());
|
||||
}
|
||||
|
||||
void ConnectionHandler::onNewMessage(CombatNetRadio::WebSocketInterface::Messages::MessageTransmitter *transmitter, const QString &message)
|
||||
{
|
||||
emit newTextMessageFromClient(transmitter, message);
|
||||
}
|
||||
|
||||
void ConnectionHandler::onServerError(QWebSocketProtocol::CloseCode 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);
|
||||
|
||||
if (!newConnection->init())
|
||||
{
|
||||
ERROR_LOG(m_logger) << "Failed to initialise new client";
|
||||
delete newConnection;
|
||||
newConnection = nullptr;
|
||||
continue;
|
||||
}
|
||||
|
||||
connect(newConnection, &ClientConnection::newTextMessage, this, &ConnectionHandler::onNewMessage);
|
||||
connect(newConnection, &ClientConnection::disconnected, this, &ConnectionHandler::onDisconnected);
|
||||
|
||||
m_connections.append(newConnection);
|
||||
DEBUG_LOG(m_logger) << "New client with ip " << newConnection->ip().toString() << " connected";
|
||||
emit newClientConnection((qint64) static_cast<WebSocketInterface::Connection::ClientConnection::MessageTransmitter*>(newConnection));
|
||||
}
|
||||
}
|
||||
|
||||
void ConnectionHandler::onDisconnected(ClientConnection *conn)
|
||||
{
|
||||
bool removeCount = m_connections.removeOne(conn);
|
||||
Q_ASSERT(removeCount == 1);
|
||||
conn->deleteLater(); // use deleteLater() as the signal is emitted from with ClientConnection
|
||||
|
||||
emit clientConnectionClosed((qint64) static_cast<WebSocketInterface::Connection::ClientConnection::MessageTransmitter*>(conn));
|
||||
if (m_connections.empty())
|
||||
emit lastConnectionClosed();
|
||||
}
|
||||
|
||||
void ConnectionHandler::onPositions(const CombatNetRadio::WebSocketInterface::Messages::ReplyMessage &positionsCnr)
|
||||
{
|
||||
for (ClientConnection *currentConnection : qAsConst(m_connections))
|
||||
currentConnection->addMessage(positionsCnr);
|
||||
}
|
||||
+66
@@ -0,0 +1,66 @@
|
||||
/**
|
||||
* @RDE_HEADER@
|
||||
* The ConnectionHandler class functions as a WebSocket server and manages incoming client connections.
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
* Created by Hannes Fritsche, SLSE, 2017-09-07
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include <QtNetwork/QHostAddress>
|
||||
#include <QtWebSockets/qwebsocketprotocol.h>
|
||||
|
||||
#include "../Messages/reply_message.h"
|
||||
#include "logger.h"
|
||||
|
||||
class QWebSocketServer;
|
||||
|
||||
namespace CombatNetRadio
|
||||
{
|
||||
namespace WebSocketInterface
|
||||
{
|
||||
namespace Messages
|
||||
{
|
||||
class MessageTransmitter;
|
||||
}
|
||||
namespace Connection
|
||||
{
|
||||
class ClientConnection;
|
||||
|
||||
class ConnectionHandler
|
||||
: public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit ConnectionHandler();
|
||||
~ConnectionHandler();
|
||||
|
||||
bool init();
|
||||
|
||||
Q_SIGNALS:
|
||||
void newTextMessageFromClient(Messages::MessageTransmitter *transmitter, const QString &message);
|
||||
void lastConnectionClosed();
|
||||
void newClientConnection(qint64 id);
|
||||
void clientConnectionClosed(qint64 id);
|
||||
void clearFrequencyPlanningStatus();
|
||||
|
||||
public Q_SLOTS:
|
||||
void onUpdate();
|
||||
void onPositions(const Messages::ReplyMessage &positionsCnr);
|
||||
|
||||
private Q_SLOTS:
|
||||
void onNewMessage(Messages::MessageTransmitter *transmitter, const QString &message);
|
||||
void onServerError(QWebSocketProtocol::CloseCode closeCode);
|
||||
void onNewConnection();
|
||||
void onDisconnected(ClientConnection *conn);
|
||||
|
||||
private: // attributes
|
||||
QWebSocketServer *m_server;
|
||||
QVector<ClientConnection *> m_connections;
|
||||
|
||||
LOGGER_T m_logger;
|
||||
};
|
||||
} // namespace Connection
|
||||
} // namespace WebSocketInterface
|
||||
} // namespace CombatNetRadio
|
||||
@@ -0,0 +1,210 @@
|
||||
/**
|
||||
* @RDE_HEADER@
|
||||
* The ClientMessage class is an abstract base class for concrete ClientMessage objects
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
* Created by Hannes Fritsche, SLSE, 2017-09-07
|
||||
*/
|
||||
#include "client_message.h"
|
||||
#include "reply_message.h"
|
||||
#include "exercise_manager.h"
|
||||
#include "WebSocketInterface/Messages/message_transmitter.h"
|
||||
#include "WebSocketInterface/Messages/reply_message.h"
|
||||
#include "WebSocketInterface/json_keys.h"
|
||||
|
||||
#include <QtCore/QJsonDocument>
|
||||
#include <QtCore/QUuid>
|
||||
#include <chrono>
|
||||
|
||||
/*
|
||||
*python testing:
|
||||
|
||||
import websocket
|
||||
import json
|
||||
import time
|
||||
ws = websocket.create_connection("ws://127.0.0.1:2081")
|
||||
d = { 'type' : 'getEssentials', 'uuid': 'blub' }
|
||||
ws.send(json.dumps(d))
|
||||
d = { 'type' : 'getConfigCNR', 'uuid': 'blub' }
|
||||
ws.send(json.dumps(d))
|
||||
d = { 'type' : 'getPositionsCNR', 'uuid': 'blub', 'data': {'repeat': 10}}
|
||||
ws.send(json.dumps(d))
|
||||
while True:
|
||||
ws.recv()
|
||||
|
||||
*/
|
||||
|
||||
namespace CombatNetRadio
|
||||
{
|
||||
namespace WebSocketInterface
|
||||
{
|
||||
|
||||
using namespace JsonKeys;
|
||||
|
||||
namespace Messages
|
||||
{
|
||||
|
||||
// ####### ClientMessage begin #######
|
||||
ClientMessage *ClientMessage::create(const QString &message, NGL::INGLLogger &logger)
|
||||
{
|
||||
ClientMessage *result = nullptr;
|
||||
QJsonParseError error;
|
||||
QJsonDocument doc = QJsonDocument::fromJson(message.toUtf8(), &error);
|
||||
|
||||
if (error.error != QJsonParseError::NoError)
|
||||
{
|
||||
ERROR_LOG(logger) << "Got message which is not JSON conform: " << message;
|
||||
return new InvalidMessage(QString(), QStringLiteral("Got message which is not JSON conform"));
|
||||
}
|
||||
|
||||
QJsonObject obj = doc.object();
|
||||
|
||||
QJsonObject dataPart = obj.value(DATA()).toObject();
|
||||
QString type = obj.value(TYPE()).toString();
|
||||
QString uuid = obj.value(UUID_()).toString();
|
||||
|
||||
if (type.isEmpty())
|
||||
{
|
||||
ERROR_LOG(logger) << "Got message without type: " << message;
|
||||
result = new InvalidMessage(uuid, QStringLiteral("Message has no type"));
|
||||
}
|
||||
else if (type == ERROR_() && dataPart.contains(ERROR_MESSAGE()) && dataPart.contains(ERROR_CLASS()) && dataPart.contains(UUID_()))
|
||||
{
|
||||
ERROR_LOG(logger) << "Got error message: " << QJsonDocument(dataPart).toJson();
|
||||
return nullptr;
|
||||
}
|
||||
else if (uuid.isEmpty())
|
||||
{
|
||||
ERROR_LOG(logger) << "Got message without uuid: " << message;
|
||||
result = new InvalidMessage(QString(), QStringLiteral("Got message without uuid"));
|
||||
}
|
||||
else if (type == GET_ESSENTIALS())
|
||||
result = new GetEssentialsMessage(type, uuid, dataPart);
|
||||
else if (type == GET_CONFIG_CNR())
|
||||
result = new GetConfigCnrMessage(type, uuid, dataPart);
|
||||
else if (type == GET_POSITIONS_CNR())
|
||||
result = new GetPositionsCnrMessage(type, uuid, dataPart);
|
||||
else if (type == ALIVE_REQUEST())
|
||||
result = new AliveRequest(type, uuid, dataPart);
|
||||
else if (type == OK())
|
||||
result = new OkMessageC(type, uuid, dataPart);
|
||||
else if (type == CONFIG_CNR())
|
||||
result = new ConfigCnrMessageC(type, uuid, dataPart);
|
||||
|
||||
if (result == nullptr)
|
||||
{
|
||||
ERROR_LOG(logger) << "Got message with invalid type: " << message;
|
||||
result = new InvalidMessage(uuid, QStringLiteral("Invalid type"));
|
||||
}
|
||||
|
||||
if (!result->hasValidData())
|
||||
{
|
||||
ERROR_LOG(logger) << "Got message with invalid data part: " << message;
|
||||
delete result;
|
||||
result = new InvalidMessage(uuid, QStringLiteral("Has invalid data part"));
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
ClientMessage::ClientMessage(const QString &type, const QString &uuid, const QJsonObject &data)
|
||||
: m_type(type)
|
||||
, m_uuid(uuid)
|
||||
, m_data(data)
|
||||
{
|
||||
}
|
||||
|
||||
// ####### ClientMessage end #######
|
||||
|
||||
// ####### InvalidMessage begin #######
|
||||
void InvalidMessage::process(ExerciseManager *exerciseManager, MessageTransmitter *transmitter)
|
||||
{
|
||||
Q_UNUSED(exerciseManager);
|
||||
ErrorMessage::ErrorData errorData;
|
||||
|
||||
errorData.errorClass = 1; // ??????????
|
||||
errorData.errorMessage = m_errorText;
|
||||
errorData.uuid = m_uuid;
|
||||
|
||||
transmitter->addMessage(ErrorMessage(errorData));
|
||||
}
|
||||
|
||||
bool InvalidMessage::hasValidData() const
|
||||
{
|
||||
// always true because there is no data part
|
||||
return true;
|
||||
}
|
||||
|
||||
// ####### InvalidMessage end #######
|
||||
|
||||
|
||||
// ####### GetEssentialsMessage begin #######
|
||||
void GetEssentialsMessage::process(ExerciseManager *exerciseManager, MessageTransmitter *transmitter)
|
||||
{
|
||||
using namespace Messages;
|
||||
transmitter->addMessage(exerciseManager->trainingAreaData(m_uuid));
|
||||
|
||||
for (const ReplyMessage ¤tMessage : exerciseManager->radioStations(m_uuid))
|
||||
transmitter->addMessage(currentMessage);
|
||||
|
||||
QString requester = m_data.value(REQUESTER()).toString();
|
||||
bool isActiveClient = m_data.value(ISACTIVECLIENT()).toBool();
|
||||
|
||||
transmitter->addMessage(exerciseManager->configCnr(m_uuid));
|
||||
exerciseManager->onConfigCnrSent((qint64) transmitter, m_uuid, requester, isActiveClient);
|
||||
}
|
||||
|
||||
// ####### GetEssentialsMessage end #######
|
||||
|
||||
// ####### GetConfigCnrMessage begin #######
|
||||
void GetConfigCnrMessage::process(ExerciseManager *exerciseManager, MessageTransmitter *transmitter)
|
||||
{
|
||||
QString requester = m_data.value(REQUESTER()).toString();
|
||||
bool isActiveClient = m_data.value(ISACTIVECLIENT()).toBool();
|
||||
transmitter->addMessage(exerciseManager->configCnr(m_uuid));
|
||||
exerciseManager->onConfigCnrSent((qint64) transmitter, m_uuid, requester, isActiveClient);
|
||||
}
|
||||
|
||||
// ####### GetConfigCnrMessage end #######
|
||||
|
||||
void OkMessageC::process(ExerciseManager *exerciseManager, MessageTransmitter *transmitter)
|
||||
{
|
||||
exerciseManager->onConfigCnrReceived((qint64) transmitter, m_uuid);
|
||||
}
|
||||
|
||||
// ####### GetPositionsCnrMessage begin #######
|
||||
void GetPositionsCnrMessage::process(ExerciseManager *exerciseManager, MessageTransmitter *transmitter)
|
||||
{
|
||||
transmitter->addMessage(exerciseManager->positionsCnr(m_uuid));
|
||||
|
||||
int updateInterval = m_data.value(REPEAT()).toInt();
|
||||
if (updateInterval > 0)
|
||||
exerciseManager->setPositionsUpdateInterval(std::chrono::seconds(updateInterval));
|
||||
else
|
||||
exerciseManager->stopPositionsUpdate();
|
||||
}
|
||||
|
||||
bool GetPositionsCnrMessage::hasValidData() const
|
||||
{
|
||||
return m_data.contains(REPEAT());
|
||||
}
|
||||
|
||||
// ####### GetPositionsCnrMessage end #######
|
||||
|
||||
// ####### GetPositionsCnrMessage begin #######
|
||||
void AliveRequest::process(ExerciseManager *exerciseManager, MessageTransmitter *transmitter)
|
||||
{
|
||||
Q_UNUSED(exerciseManager);
|
||||
transmitter->addMessage(AliveResponse(m_uuid));
|
||||
}
|
||||
|
||||
void ConfigCnrMessageC::process(ExerciseManager *exerciseManager, MessageTransmitter *transmitter)
|
||||
{
|
||||
exerciseManager->onConfigCnrProcessed((qint64) transmitter, m_uuid, m_data);
|
||||
}
|
||||
|
||||
// ####### GetPositionsCnrMessage end #######
|
||||
} // namespace Messages
|
||||
} // namespace WebSocketInterface
|
||||
} // namespace CombatNetRadio
|
||||
@@ -0,0 +1,116 @@
|
||||
/**
|
||||
* @RDE_HEADER@
|
||||
* The ClientMessage class is an abstract base class for concrete ClientMessage objects
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
* Created by Hannes Fritsche, SLSE, 2017-09-07
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include <QtCore/QJsonObject>
|
||||
|
||||
#include "logger.h"
|
||||
|
||||
namespace CombatNetRadio
|
||||
{
|
||||
class ExerciseManager;
|
||||
|
||||
namespace WebSocketInterface
|
||||
{
|
||||
|
||||
namespace Messages
|
||||
{
|
||||
class MessageTransmitter;
|
||||
|
||||
class ClientMessage
|
||||
{
|
||||
public:
|
||||
static ClientMessage *create(const QString &message, NGL::INGLLogger &logger);
|
||||
|
||||
virtual void process(ExerciseManager *exerciseManager, MessageTransmitter *transmitter) = 0;
|
||||
virtual bool hasValidData() const = 0;
|
||||
virtual ~ClientMessage() = default;
|
||||
ClientMessage(const QString &type, const QString &uuid, const QJsonObject &data = QJsonObject());
|
||||
|
||||
protected: // attributes
|
||||
const QString m_type;
|
||||
const QString m_uuid;
|
||||
const QJsonObject m_data;
|
||||
|
||||
}; // class ClientMessage
|
||||
|
||||
|
||||
class GetEssentialsMessage final : public ClientMessage
|
||||
{
|
||||
public:
|
||||
void process(ExerciseManager *exerciseManager, MessageTransmitter *transmitter) override;
|
||||
bool hasValidData() const override { return true; }
|
||||
|
||||
using ClientMessage::ClientMessage;
|
||||
}; // class GetEssentialsMessage
|
||||
|
||||
class GetConfigCnrMessage final : public ClientMessage
|
||||
{
|
||||
public:
|
||||
void process(ExerciseManager *exerciseManager, MessageTransmitter *transmitter) override;
|
||||
bool hasValidData() const override { return true; }
|
||||
|
||||
using ClientMessage::ClientMessage;
|
||||
}; // GetConfigCnrMessage
|
||||
|
||||
class GetPositionsCnrMessage final : public ClientMessage
|
||||
{
|
||||
public:
|
||||
void process(ExerciseManager *exerciseManager, MessageTransmitter *transmitter) override;
|
||||
bool hasValidData() const override;
|
||||
|
||||
using ClientMessage::ClientMessage;
|
||||
}; // PositionsCnrMessage
|
||||
|
||||
class AliveRequest final : public ClientMessage
|
||||
{
|
||||
public:
|
||||
void process(ExerciseManager *exerciseManager, MessageTransmitter *transmitter) override;
|
||||
bool hasValidData() const override { return true; }
|
||||
|
||||
using ClientMessage::ClientMessage;
|
||||
};
|
||||
|
||||
|
||||
class OkMessageC final : public ClientMessage
|
||||
{
|
||||
public:
|
||||
void process(ExerciseManager *exerciseManager, MessageTransmitter *transmitter) override;
|
||||
bool hasValidData() const override { return true; }
|
||||
|
||||
using ClientMessage::ClientMessage;
|
||||
};
|
||||
|
||||
class ConfigCnrMessageC final : public ClientMessage
|
||||
{
|
||||
public:
|
||||
void process(ExerciseManager *exerciseManager, MessageTransmitter *transmitter) override;
|
||||
bool hasValidData() const override { return true; }
|
||||
|
||||
using ClientMessage::ClientMessage;
|
||||
}; // ConfigCnrMessageC
|
||||
|
||||
class InvalidMessage final : public ClientMessage
|
||||
{
|
||||
friend class ClientMessage;
|
||||
|
||||
public:
|
||||
void process(ExerciseManager *exerciseManager, MessageTransmitter *transmitter) override;
|
||||
bool hasValidData() const override;
|
||||
|
||||
using ClientMessage::ClientMessage;
|
||||
|
||||
private: // attributes
|
||||
QString m_errorText;
|
||||
|
||||
}; // class InvalidMessage
|
||||
|
||||
} // namespace Messages
|
||||
} // namespace WebSocketInterface
|
||||
} // namespace CombatNetRadio
|
||||
@@ -0,0 +1,49 @@
|
||||
/**
|
||||
* @RDE_HEADER@
|
||||
* The MessageHandler class processes messages from the client an creates appropriate replys
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
* Created by Hannes Fritsche, SLSE, 2017-09-07
|
||||
*/
|
||||
#include "message_handler.h"
|
||||
#include "message_transmitter.h"
|
||||
#include "client_message.h"
|
||||
#include <memory>
|
||||
|
||||
namespace CombatNetRadio
|
||||
{
|
||||
namespace WebSocketInterface
|
||||
{
|
||||
namespace Messages
|
||||
{
|
||||
|
||||
MessageHandler::MessageHandler(ExerciseManager *exerciseManager)
|
||||
: m_exerciseManager(exerciseManager)
|
||||
, m_logger(getLogger("MessageHandler"))
|
||||
{
|
||||
Q_ASSERT(exerciseManager);
|
||||
}
|
||||
|
||||
void MessageHandler::onNewTextMessage(MessageTransmitter *transmitter, const QString &message)
|
||||
{
|
||||
Q_ASSERT(transmitter);
|
||||
|
||||
const QString pingMsg(QStringLiteral("ping"));
|
||||
if (message.startsWith(pingMsg))
|
||||
{
|
||||
transmitter->addMessage(PongMessage(message.mid(pingMsg.size())));
|
||||
return;
|
||||
}
|
||||
|
||||
std::unique_ptr<ClientMessage> clientMessage(ClientMessage::create(message, m_logger));
|
||||
|
||||
if (!clientMessage)
|
||||
return;
|
||||
|
||||
clientMessage->process(m_exerciseManager, transmitter);
|
||||
}
|
||||
|
||||
} // namespace CombatNetRadio
|
||||
} // namespace WebSocketInterface
|
||||
} // namespace Messages
|
||||
@@ -0,0 +1,43 @@
|
||||
/**
|
||||
* @RDE_HEADER@
|
||||
* The MessageHandler class processes messages from the client an creates appropriate replys
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
* Created by Hannes Fritsche, SLSE, 2017-09-07
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include <QtCore/QObject>
|
||||
|
||||
#include "logger.h"
|
||||
|
||||
namespace CombatNetRadio
|
||||
{
|
||||
class ExerciseManager;
|
||||
|
||||
namespace WebSocketInterface
|
||||
{
|
||||
|
||||
namespace Messages
|
||||
{
|
||||
class MessageTransmitter;
|
||||
|
||||
class MessageHandler
|
||||
: public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit MessageHandler(ExerciseManager *exerciseManager);
|
||||
|
||||
public Q_SLOTS:
|
||||
void onNewTextMessage(MessageTransmitter *transmitter, const QString &message);
|
||||
|
||||
private:
|
||||
ExerciseManager *m_exerciseManager;
|
||||
|
||||
LOGGER_T m_logger;
|
||||
};
|
||||
} // namespace Messages
|
||||
} // namespace WebSocketInterface
|
||||
} // namespace CombatNetRadio
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
/**
|
||||
* @RDE_HEADER@
|
||||
* The MessageTransmitter Interface offers an extremely lightweight API for a class to just write textmessages to
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
* Created by Hannes Fritsche, SLSE, 2017-09-07
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include "reply_message.h"
|
||||
|
||||
namespace CombatNetRadio
|
||||
{
|
||||
namespace WebSocketInterface
|
||||
{
|
||||
namespace Messages
|
||||
{
|
||||
class MessageTransmitter
|
||||
{
|
||||
public:
|
||||
virtual void addMessage(const ReplyMessage &message) = 0;
|
||||
};
|
||||
} // namespace Messages
|
||||
} // namespace WebSocketInterface
|
||||
} // namespace CombatNetRadio
|
||||
@@ -0,0 +1,192 @@
|
||||
/**
|
||||
* @RDE_HEADER@
|
||||
* The ReplyMessage class is an abstract base class for all possible messages which are sent to the client
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
* Created by Hannes Fritsche, SLSE, 2017-09-07
|
||||
*/
|
||||
#include "reply_message.h"
|
||||
|
||||
#include "WebSocketInterface/json_keys.h"
|
||||
#include "helper.h"
|
||||
|
||||
#include <QtCore/QUuid>
|
||||
#include <QtCore/QJsonDocument>
|
||||
#include <QtGlobal>
|
||||
#include <QDateTime>
|
||||
|
||||
namespace CombatNetRadio
|
||||
{
|
||||
namespace WebSocketInterface
|
||||
{
|
||||
|
||||
using namespace JsonKeys;
|
||||
|
||||
namespace Messages
|
||||
{
|
||||
|
||||
// ####### ReplyMessage begin #######
|
||||
QJsonObject ReplyMessage::LonLatPoint::toJSon() const
|
||||
{
|
||||
if (lon < 0 || lat < 0)
|
||||
return QJsonObject();
|
||||
return {{LONGITUDE(), lon}, {LATITUDE(), lat}};
|
||||
}
|
||||
|
||||
QJsonObject ReplyMessage::XYPoint::toJSon() const
|
||||
{
|
||||
return {{X(), x}, {Y(), y}};
|
||||
}
|
||||
|
||||
QString ReplyMessage::toJsonString() const
|
||||
{
|
||||
return QString::fromUtf8(QJsonDocument(m_jsonRepresentation).toJson()); //QJsonDocument::Compact));
|
||||
}
|
||||
|
||||
ReplyMessage::ReplyMessage(const QString &type, const QString &uuid)
|
||||
{
|
||||
m_jsonRepresentation.insert(TYPE(), type);
|
||||
|
||||
Q_ASSERT(!uuid.isEmpty());
|
||||
m_jsonRepresentation.insert(UUID_(), uuid);
|
||||
}
|
||||
|
||||
QString ReplyMessage::uuid() const
|
||||
{
|
||||
return m_jsonRepresentation.value(UUID_()).toString();
|
||||
}
|
||||
|
||||
// ####### ReplyMessage end #######
|
||||
|
||||
// ####### OkMessage begin #######
|
||||
OkMessage::OkMessage(const OkMessage::OkData &data)
|
||||
: ReplyMessage(OK(), data.uuid)
|
||||
{
|
||||
m_jsonRepresentation.insert(DATA(),
|
||||
QJsonObject({
|
||||
{MESSAGE_TYPE(), data.messageType},
|
||||
{INFO(), data.info}
|
||||
}));
|
||||
}
|
||||
// ####### OkMessage end #######
|
||||
|
||||
// ####### ErrorMessage begin #######
|
||||
ErrorMessage::ErrorMessage(const ErrorMessage::ErrorData &data)
|
||||
: ReplyMessage(ERROR_(), data.uuid)
|
||||
{
|
||||
m_jsonRepresentation.insert(DATA(),
|
||||
QJsonObject({
|
||||
{ERROR_CLASS(), data.errorClass},
|
||||
{ERROR_MESSAGE(), data.errorMessage}
|
||||
}));
|
||||
}
|
||||
|
||||
// ####### ErrorMessage end #######
|
||||
|
||||
// ####### TrainingAreaMessage begin #######
|
||||
TrainingAreaMessage::TrainingAreaMessage(const TrainingAreaMessage::TrainingAreaData &data, const QString &uuid)
|
||||
: ReplyMessage(TRAINING_AREA(), uuid)
|
||||
{
|
||||
m_jsonRepresentation.insert(DATA(),
|
||||
QJsonObject({{ID(), data.id},
|
||||
{DESIGNATION(), data.designation},
|
||||
{REF_POINT(), data.refPoint.toJSon()},
|
||||
{PATH(), vecToPath(data.path)}
|
||||
}));
|
||||
}
|
||||
// ####### TrainingAreaMessage end #######
|
||||
|
||||
// ####### RadioStationMessage begin #######
|
||||
RadioStationMessage::RadioStationMessage(const RadioStationMessage::RadioStationData &data, const QString &uuid)
|
||||
: ReplyMessage(RADIO_STATION(), uuid)
|
||||
{
|
||||
m_jsonRepresentation.insert(DATA(),
|
||||
QJsonObject({{ID(), data.id},
|
||||
{DESIGNATION(), data.designation},
|
||||
{GEO_POINT(), data.geoPoint.toJSon()},
|
||||
{TRAINING_AREA_ID(), data.trainingAreaId}
|
||||
}));
|
||||
}
|
||||
// ####### RadioStationMessage end #######
|
||||
|
||||
// ####### ConfigCnrMessage begin #######
|
||||
QJsonObject ConfigCnrMessage::SubRadioCircuit::toJSon() const
|
||||
{
|
||||
|
||||
return QJsonObject({{RC_ID(), rcSubId},
|
||||
{RC_SUB_NAME(), rcSubName},
|
||||
{RC_MODE(), rcMode},
|
||||
{STATION(), station},
|
||||
{PT_SIG(), ptSig},
|
||||
{RC_TYPE(), rcType},
|
||||
{CROSSBEAM(), crossbeam},
|
||||
{ORIENTATION(), orientation},
|
||||
{FREQUENCY(), frequency},
|
||||
{AKW(), akw},
|
||||
{FSB(), fsb},
|
||||
{RC_AKW(), rcAkw},
|
||||
{COMSEC(), comsec},
|
||||
{MODULATION_TYPE(), modulationType},
|
||||
{CHANNEL_SPACING(), channelSpacing},
|
||||
{SQUELCH(), squelch},
|
||||
{CLIPPER(), clipper},
|
||||
{AGC(), agc}
|
||||
});
|
||||
}
|
||||
|
||||
QJsonObject ConfigCnrMessage::RadioCircuit::toJSon() const
|
||||
{
|
||||
return QJsonObject({{RC_ID(), rcId},
|
||||
{SSRC(), ssrc},
|
||||
{RC_NAME(), rcName},
|
||||
{IS_ROAMING(), isRoaming},
|
||||
{SUB_CIRCUIT(), vecToPath(subCircuits)}
|
||||
});
|
||||
}
|
||||
|
||||
ConfigCnrMessage::ConfigCnrMessage(const ConfigCnrMessage::ConfigCnrData &data, const QString &uuid)
|
||||
: ReplyMessage(CONFIG_CNR(), uuid)
|
||||
{
|
||||
m_jsonRepresentation.insert(DATA(),
|
||||
QJsonObject({{SET_ID(), data.setId},
|
||||
{TIME(), QDateTime::currentDateTime().toString(Qt::ISODate)},
|
||||
{RADIO_CIRCUIT(), vecToPath(data.radioCircuit)}
|
||||
}));
|
||||
}
|
||||
// ####### ConfigCnrMessage end #######
|
||||
|
||||
// ####### PositionsCnrMessage begin #######
|
||||
QJsonObject PositionsCnrMessage::RadioCircuit::toJSon() const
|
||||
{
|
||||
return QJsonObject{{RC_ID(), rcId}, {POSITIONS(), vecToPath(positions)}};
|
||||
}
|
||||
|
||||
PositionsCnrMessage::PositionsCnrMessage(const PositionsCnrMessage::PositionsCnrMessageData &data, const QString &uuid)
|
||||
: ReplyMessage(POSITIONS_CNR(), uuid)
|
||||
{
|
||||
m_jsonRepresentation.insert(DATA(),
|
||||
QJsonObject({{TIME(), data.time},
|
||||
{RADIO_CIRCUIT(), vecToPath(data.radioCircuit)}
|
||||
}));
|
||||
}
|
||||
// ####### PositionsCnrMessage end #######
|
||||
|
||||
// ####### UpdateMessage begin ######
|
||||
UpdateMessage::UpdateMessage(const QString &info)
|
||||
: ReplyMessage(UPDATE(), QUuid::createUuid().toString())
|
||||
{
|
||||
m_jsonRepresentation.insert(DATA(), QJsonObject({{INFO(), info}}));
|
||||
}
|
||||
// ####### UpdateMessage end ######
|
||||
|
||||
// ####### UpdateMessage begin ######
|
||||
AliveResponse::AliveResponse(const QString &uuid)
|
||||
: ReplyMessage(ALIVE_RESPONSE(), uuid)
|
||||
{
|
||||
}
|
||||
// ####### UpdateMessage end ######
|
||||
|
||||
} // namespace Messages
|
||||
} // namespace WebSocketInterface
|
||||
} // namespace CombatNetRadio
|
||||
@@ -0,0 +1,248 @@
|
||||
/**
|
||||
* @RDE_HEADER@
|
||||
* The ReplyMessage class is an abstract base class for all possible messages which are sent to the client
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
* Created by Hannes Fritsche, SLSE, 2017-09-07
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include <QtCore/QVector>
|
||||
#include <QtCore/QJsonObject>
|
||||
#include <QtCore/QJsonArray>
|
||||
#include <QtCore/QString>
|
||||
|
||||
namespace CombatNetRadio
|
||||
{
|
||||
namespace WebSocketInterface
|
||||
{
|
||||
namespace Messages
|
||||
{
|
||||
|
||||
class ReplyMessage
|
||||
{
|
||||
public:
|
||||
struct LonLatPoint
|
||||
{
|
||||
double lon = 0.;
|
||||
double lat = 0.;
|
||||
|
||||
LonLatPoint() = default;
|
||||
LonLatPoint(double _lon, double _lat)
|
||||
: lon(_lon)
|
||||
, lat(_lat)
|
||||
{}
|
||||
|
||||
QJsonObject toJSon() const;
|
||||
};
|
||||
|
||||
struct XYPoint
|
||||
{
|
||||
double x = 0.;
|
||||
double y = 0.;
|
||||
|
||||
QJsonObject toJSon() const;
|
||||
};
|
||||
|
||||
ReplyMessage() = default; //!< QVector requires this; don't use directly
|
||||
|
||||
virtual ~ReplyMessage() = default;
|
||||
|
||||
virtual QString toJsonString() const;
|
||||
QString uuid() const;
|
||||
|
||||
|
||||
protected:
|
||||
template<typename T>
|
||||
static QJsonArray vecToPath(const QVector<T> &points)
|
||||
{
|
||||
QJsonArray result;
|
||||
for (const T &p : points)
|
||||
result.append(p.toJSon());
|
||||
return result;
|
||||
}
|
||||
|
||||
protected: // methods
|
||||
explicit ReplyMessage(const QString &type, const QString &uuid);
|
||||
|
||||
protected: // attributes
|
||||
QJsonObject m_jsonRepresentation;
|
||||
|
||||
}; // class Reply Message
|
||||
|
||||
class ErrorMessage final
|
||||
: public ReplyMessage
|
||||
{
|
||||
public:
|
||||
struct ErrorData
|
||||
{
|
||||
int errorClass = 0;
|
||||
QString uuid;
|
||||
QString errorMessage;
|
||||
|
||||
ErrorData() = default;
|
||||
explicit ErrorData(int errorClass_, const QString &uuid_, const QString &errorMessage_)
|
||||
: errorClass(errorClass_)
|
||||
, uuid(uuid_)
|
||||
, errorMessage(errorMessage_)
|
||||
{}
|
||||
};
|
||||
|
||||
explicit ErrorMessage(const ErrorData &data);
|
||||
explicit ErrorMessage(int errorClass, const QString &uuid, const QString &errorMessage)
|
||||
: ErrorMessage(ErrorData(errorClass, uuid, errorMessage))
|
||||
{}
|
||||
}; // class ErrorMessage
|
||||
|
||||
|
||||
class OkMessage final
|
||||
: public ReplyMessage
|
||||
{
|
||||
public:
|
||||
struct OkData
|
||||
{
|
||||
QString uuid;
|
||||
QString messageType;
|
||||
QString info;
|
||||
};
|
||||
|
||||
explicit OkMessage(const OkData &data);
|
||||
}; // class OkMessage
|
||||
|
||||
class TrainingAreaMessage final
|
||||
: public ReplyMessage
|
||||
{
|
||||
public:
|
||||
struct TrainingAreaData
|
||||
{
|
||||
int32_t id;
|
||||
QString designation;
|
||||
LonLatPoint refPoint;
|
||||
QVector<LonLatPoint> path;
|
||||
};
|
||||
|
||||
explicit TrainingAreaMessage(const TrainingAreaData &data, const QString &uuid);
|
||||
}; // class TrainingAreaMessage
|
||||
|
||||
class RadioStationMessage final
|
||||
: public ReplyMessage
|
||||
{
|
||||
public:
|
||||
|
||||
struct RadioStationData
|
||||
{
|
||||
int32_t id;
|
||||
QString designation;
|
||||
LonLatPoint geoPoint;
|
||||
int32_t trainingAreaId;
|
||||
};
|
||||
|
||||
explicit RadioStationMessage(const RadioStationData &data, const QString &uuid);
|
||||
}; // RadioStationMessage
|
||||
|
||||
class ConfigCnrMessage final
|
||||
: public ReplyMessage
|
||||
{
|
||||
public:
|
||||
struct SubRadioCircuit
|
||||
{
|
||||
QString rcSubId;
|
||||
QString rcSubName;
|
||||
int32_t frequencyBand = 0;
|
||||
int32_t rcMode = 0;
|
||||
int32_t station = 0;
|
||||
int32_t ptSig = 0;
|
||||
int32_t rcType;
|
||||
int32_t crossbeam;
|
||||
int32_t orientation;
|
||||
int32_t frequency = 0;
|
||||
int32_t akw = 0;
|
||||
int32_t fsb = 0;
|
||||
int32_t rcAkw = 0;
|
||||
int32_t comsec = 0;
|
||||
int32_t modulationType;
|
||||
int32_t channelSpacing;
|
||||
int32_t squelch = 0;
|
||||
bool clipper;
|
||||
bool agc;
|
||||
|
||||
QJsonObject toJSon() const;
|
||||
};
|
||||
|
||||
struct RadioCircuit
|
||||
{
|
||||
QString rcId;
|
||||
int32_t ssrc = 0;
|
||||
QString rcName;
|
||||
bool isRoaming;
|
||||
|
||||
QVector<SubRadioCircuit> subCircuits;
|
||||
QJsonObject toJSon() const;
|
||||
};
|
||||
|
||||
struct ConfigCnrData
|
||||
{
|
||||
int32_t setId = 0;
|
||||
QString time;
|
||||
QVector<RadioCircuit> radioCircuit;
|
||||
};
|
||||
|
||||
explicit ConfigCnrMessage(const ConfigCnrData &data, const QString &uuid);
|
||||
}; // ConfigCnrMessage
|
||||
|
||||
class PositionsCnrMessage final
|
||||
: public ReplyMessage
|
||||
{
|
||||
public:
|
||||
struct RadioCircuit
|
||||
{
|
||||
QString rcId;
|
||||
QVector<LonLatPoint> positions;
|
||||
|
||||
QJsonObject toJSon() const;
|
||||
};
|
||||
|
||||
struct PositionsCnrMessageData
|
||||
{
|
||||
QString time;
|
||||
QVector<RadioCircuit> radioCircuit;
|
||||
};
|
||||
|
||||
explicit PositionsCnrMessage(const PositionsCnrMessageData &data, const QString &uuid);
|
||||
}; // PositionsCnrMessage
|
||||
|
||||
class UpdateMessage final
|
||||
: public ReplyMessage
|
||||
{
|
||||
public:
|
||||
explicit UpdateMessage(const QString &info = QString());
|
||||
}; // UpdateMessage
|
||||
|
||||
class PongMessage final : public ReplyMessage
|
||||
{
|
||||
public:
|
||||
static QString strPong() { return QStringLiteral("pong"); }
|
||||
explicit PongMessage(const QString &payload)
|
||||
: ReplyMessage(strPong(), QString())
|
||||
, m_payload(payload)
|
||||
{}
|
||||
|
||||
QString toJsonString() const override
|
||||
{
|
||||
return m_payload.isEmpty() ? strPong() : QStringLiteral("%1 %2").arg(strPong(), m_payload);
|
||||
}
|
||||
private:
|
||||
QString m_payload;
|
||||
};
|
||||
|
||||
class AliveResponse final : public ReplyMessage
|
||||
{
|
||||
public:
|
||||
explicit AliveResponse(const QString &uuid);
|
||||
};
|
||||
|
||||
} // namespace Messages
|
||||
} // namespace WebSocketInterface
|
||||
} // namespace CombatNetRadio
|
||||
|
||||
@@ -0,0 +1,94 @@
|
||||
/**
|
||||
* @RDE_HEADER@
|
||||
* Header file which holds all occuring JSON keys
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
* Created by Hannes Fritsche, SLSE, 2017-09-07
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include <QtCore/QString>
|
||||
|
||||
namespace CombatNetRadio
|
||||
{
|
||||
namespace WebSocketInterface
|
||||
{
|
||||
namespace JsonKeys
|
||||
{
|
||||
// TODO: add constexpr once we do no longer support msvc2013
|
||||
// root keys
|
||||
inline QString DATA() { return QLatin1String("data"); }
|
||||
inline QString UUID_() { return QStringLiteral("uuid"); } // Windows: typedef GUID UUUID; ...
|
||||
inline QString TYPE() { return QStringLiteral("type"); }
|
||||
|
||||
// types for client --> server messages
|
||||
inline QString GET_ESSENTIALS() { return QStringLiteral("getEssentials"); }
|
||||
inline QString GET_CONFIG_CNR() { return QLatin1String("getConfigCNR"); }
|
||||
inline QString GET_POSITIONS_CNR() { return QLatin1String("getPositionsCNR"); }
|
||||
inline QString ALIVE_REQUEST() { return QLatin1String("aliveRequest"); }
|
||||
inline QString ERROR_() { return QLatin1String("error"); }
|
||||
|
||||
// types for server --> client messages
|
||||
inline QString TRAINING_AREA() { return QLatin1String("trainingArea"); }
|
||||
inline QString RADIO_STATION() { return QLatin1String("radioStation"); }
|
||||
inline QString POSITIONS_CNR() { return QLatin1String("positionsCNR"); }
|
||||
inline QString UPDATE() { return QLatin1String("update"); }
|
||||
inline QString ALIVE_RESPONSE() { return QLatin1String("aliveResponse"); }
|
||||
|
||||
// types for both directions
|
||||
inline QString OK() { return QStringLiteral("ok"); }
|
||||
inline QString CONFIG_CNR() { return QLatin1String("configCNR"); }
|
||||
|
||||
// data keys
|
||||
inline QString ID() { return QLatin1String("id"); }
|
||||
inline QString DESIGNATION() { return QLatin1String("designation"); }
|
||||
inline QString PATH() { return QLatin1String("path"); }
|
||||
inline QString GEO_POINT() { return QLatin1String("geoPoint"); }
|
||||
inline QString LATITUDE() { return QLatin1String("lat"); }
|
||||
inline QString LONGITUDE() { return QLatin1String("lon"); }
|
||||
inline QString POINT() { return QLatin1String("point"); }
|
||||
inline QString X() { return QLatin1String("x"); }
|
||||
inline QString Y() { return QLatin1String("y"); }
|
||||
inline QString REF_POINT() { return QLatin1String("refPoint"); }
|
||||
inline QString MGRS() { return QLatin1String("MGRS"); }
|
||||
inline QString TRAINING_AREA_ID() { return QLatin1String("trainingAreaId"); }
|
||||
inline QString TIME() { return QLatin1String("time"); }
|
||||
inline QString RADIO_CIRCUIT() { return QLatin1String("radioCircuit"); }
|
||||
inline QString RC_ID() { return QLatin1String("rcId"); }
|
||||
inline QString SSRC() { return QLatin1String("SSRC"); }
|
||||
inline QString RC_NAME() { return QLatin1String("rcName"); }
|
||||
inline QString IS_ROAMING() { return QLatin1String("isRoaming"); }
|
||||
inline QString SUB_CIRCUIT() { return QLatin1String("subCircuit"); }
|
||||
inline QString RC_SUB_ID() { return QLatin1String("rcSubId"); }
|
||||
inline QString RC_SUB_NAME() { return QLatin1String("rcSubName"); }
|
||||
inline QString RC_MODE() { return QLatin1String("rcMode"); }
|
||||
inline QString STATION() { return QLatin1String("station"); }
|
||||
inline QString PT_SIG() { return QLatin1String("ptSig"); }
|
||||
inline QString RC_TYPE() { return QLatin1String("rcType"); }
|
||||
inline QString CROSSBEAM() { return QLatin1String("crossbeam"); }
|
||||
inline QString ORIENTATION() { return QLatin1String("orientation"); }
|
||||
inline QString FREQUENCY() { return QLatin1String("frequency"); }
|
||||
inline QString AKW() { return QLatin1String("AKW"); }
|
||||
inline QString FSB() { return QLatin1String("FSB"); }
|
||||
inline QString RC_AKW() { return QLatin1String("rcAKW"); }
|
||||
inline QString COMSEC() { return QLatin1String("COMSEC"); }
|
||||
inline QString MODULATION_TYPE() { return QLatin1String("modulationType"); }
|
||||
inline QString CHANNEL_SPACING() { return QLatin1String("channelSpacing"); }
|
||||
inline QString SQUELCH() { return QLatin1String("squelch"); }
|
||||
inline QString CLIPPER() { return QLatin1String("clipper"); }
|
||||
inline QString AGC() { return QLatin1String("agc"); }
|
||||
inline QString REPEAT() { return QLatin1String("repeat"); }
|
||||
inline QString ERROR_CLASS() { return QLatin1String("errorClass"); }
|
||||
inline QString ERROR_MESSAGE() { return QLatin1String("errorMessage"); }
|
||||
inline QString MESSAGE_TYPE() { return QLatin1String("msgType"); }
|
||||
inline QString INFO() { return QLatin1String("info"); }
|
||||
inline QString SET_ID() { return QLatin1String("setId"); }
|
||||
inline QString POSITIONS() { return QLatin1String("positions"); }
|
||||
inline QString REQUESTER() { return QLatin1String("requester"); }
|
||||
inline QString REASON() { return QLatin1String("reason"); }
|
||||
inline QString ISACTIVECLIENT() { return QLatin1String("isActiveClient"); }
|
||||
|
||||
} // namespace JsonKeys
|
||||
} // namespace WebSocketInterface
|
||||
} // namespace CombatNetRadio
|
||||
+65
@@ -0,0 +1,65 @@
|
||||
/**
|
||||
* @RDE_HEADER@
|
||||
* Handler for the WebSocket Interface
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
* Created by Hannes Fritsche, SLSE, 2017-09-07
|
||||
*/
|
||||
#include "websocket_interface_handler.h"
|
||||
|
||||
#include "Connection/connection_handler.h"
|
||||
#include "Messages/message_handler.h"
|
||||
#include "Messages/message_transmitter.h"
|
||||
#include "dds_handler.h"
|
||||
#include "exercise_manager.h"
|
||||
|
||||
namespace CombatNetRadio
|
||||
{
|
||||
namespace WebSocketInterface
|
||||
{
|
||||
|
||||
WebSocketInterfaceHandler::WebSocketInterfaceHandler(ExerciseManager *exerciseManager)
|
||||
: m_exerciseManager(exerciseManager)
|
||||
, m_connectionHandler(nullptr)
|
||||
, m_messageHandler(nullptr)
|
||||
, m_logger(getLogger("WebSocketInterfaceHandler"))
|
||||
{
|
||||
Q_ASSERT(exerciseManager);
|
||||
}
|
||||
|
||||
WebSocketInterfaceHandler::~WebSocketInterfaceHandler()
|
||||
{
|
||||
delete m_connectionHandler;
|
||||
delete m_messageHandler;
|
||||
}
|
||||
|
||||
bool WebSocketInterfaceHandler::init()
|
||||
{
|
||||
Q_ASSERT(!m_connectionHandler);
|
||||
|
||||
m_connectionHandler = new Connection::ConnectionHandler;
|
||||
|
||||
QObject::connect(m_connectionHandler, &Connection::ConnectionHandler::newClientConnection, m_exerciseManager, &ExerciseManager::onNewClientConnection);
|
||||
QObject::connect(m_connectionHandler, &Connection::ConnectionHandler::clientConnectionClosed, m_exerciseManager, &ExerciseManager::onClientConnectionClosed);
|
||||
QObject::connect(m_connectionHandler, &Connection::ConnectionHandler::clearFrequencyPlanningStatus, m_exerciseManager, &ExerciseManager::onClearFrequencyPlanningStatus);
|
||||
|
||||
if (!m_connectionHandler->init())
|
||||
{
|
||||
ERROR_LOG(m_logger) << "Failed to initialise ConnectionHandler";
|
||||
return false;
|
||||
}
|
||||
|
||||
m_messageHandler = new Messages::MessageHandler(m_exerciseManager);
|
||||
|
||||
QObject::connect(m_connectionHandler, &Connection::ConnectionHandler::lastConnectionClosed, m_exerciseManager, &ExerciseManager::stopPositionsUpdate);
|
||||
QObject::connect(m_connectionHandler, &Connection::ConnectionHandler::newTextMessageFromClient, m_messageHandler, &Messages::MessageHandler::onNewTextMessage);
|
||||
QObject::connect(m_exerciseManager, &ExerciseManager::essentialsUpdate, m_connectionHandler, &Connection::ConnectionHandler::onUpdate);
|
||||
QObject::connect(m_exerciseManager, &ExerciseManager::positionsUpdate, m_connectionHandler, &Connection::ConnectionHandler::onPositions);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace WebSocketInterface
|
||||
|
||||
} // namespace CombatNetRadio
|
||||
+45
@@ -0,0 +1,45 @@
|
||||
/**
|
||||
* @RDE_HEADER@
|
||||
* Handler for the WebSocket Interface
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
* Created by Hannes Fritsche, SLSE, 2017-09-07
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include <QtCore/QObject>
|
||||
|
||||
#include "logger.h"
|
||||
|
||||
namespace CombatNetRadio
|
||||
{
|
||||
class ExerciseManager;
|
||||
|
||||
namespace WebSocketInterface
|
||||
{
|
||||
namespace Messages
|
||||
{
|
||||
class MessageHandler;
|
||||
}
|
||||
namespace Connection
|
||||
{
|
||||
class ConnectionHandler;
|
||||
}
|
||||
|
||||
class WebSocketInterfaceHandler final
|
||||
{
|
||||
public:
|
||||
explicit WebSocketInterfaceHandler(ExerciseManager *exerciseManager);
|
||||
~WebSocketInterfaceHandler();
|
||||
|
||||
bool init();
|
||||
|
||||
private:
|
||||
ExerciseManager *m_exerciseManager;
|
||||
Connection::ConnectionHandler *m_connectionHandler;
|
||||
Messages::MessageHandler *m_messageHandler;
|
||||
LOGGER_T m_logger;
|
||||
}; // class WebSocketInterfaceHandle
|
||||
} // namespace WebSocketInterface
|
||||
} // namespace CombatNetRadio
|
||||
Reference in new issue
Block a user