Initial commit

This commit is contained in:
torsten committed 2026-08-13 18:33:10 +02:00
commit b7d90b9afe
16245 files changed
+3396666

No files matched your search

@@ -0,0 +1,126 @@
/**
* @RDE_HEADER@
* The ClientMessage class is an abstract base class for concrete ClientMessage objects
* $Id$
* $HeadURL$
* $Author$
* Created by Philipp Dassow, SLST, 2017-12-05
*/
#include "client_message.h"
#include "WebSocketInterface/Messages/reply_message.h"
#include "WebSocketInterface/json_keys.h"
#include "WebSocketInterface/data_manager.h"
#include <QtCore/QJsonDocument>
#include <QtCore/QUuid>
namespace OcSituationClient
{
namespace WebSocketInterface
{
namespace Messages
{
using namespace JsonKeys;
// ####### ClientMessageFactory begin #######
ClientMessageFactory::ClientMessageFactory(DataManager *dataManager)
: LtsWebSocket::AbstractClientMessageFactory(getLogger("ClientMessageFactory"))
, m_dataManager(dataManager)
{}
ClientMessageFactory::~ClientMessageFactory()
{}
LtsWebSocket::AbstractClientMessage *ClientMessageFactory::createMessage(LtsWebSocket::ReplyHandler *client,
const QString &message)
{
LtsWebSocket::AbstractClientMessage *result = checkAttributes(client, message);
if (result)
return result;
if (m_type == ServiceManagement::WebSocketInterface::JsonKeys::SERVICE_PORTS_INFORMATION())
result = new ServicePortsInformation(m_dataManager, client, m_type, m_uuid, m_data);
return checkResult(client, message, result);
}
// ####### ClientMessageFactory end #######
// ####### ClientMessage begin #######
ClientMessage::ClientMessage(DataManager *dataManager, LtsWebSocket::ReplyHandler *client, const QString &type, const QString &uuid, const QJsonValue &data)
: LtsWebSocket::AbstractClientMessage(client, type, uuid, data)
, m_dataManager(dataManager)
{}
// ####### ClientMessage end #######
// ####### ServicesInformation begin #######
ServicePortsInformation::ServicePortsInformation(DataManager *dataManager, LtsWebSocket::ReplyHandler *client, const QString &type, const QString &uuid, const QJsonValue &data)
: ClientMessage (dataManager,client, type, uuid, data)
{}
void ServicePortsInformation::process()
{
QJsonArray exerciseInformationArray = m_data.toArray();
QVector<ExerciseInformation> exercises;
QVector<ServiceInformation> services;
QVector<PortInformation> ports;
exercises.reserve(exerciseInformationArray.size());
for (const auto &exerciseJsonValue : exerciseInformationArray)
{
QJsonObject exerciseJsonObject = exerciseJsonValue.toObject();
ExerciseInformation exercise;
exercise.exerciseId = exerciseJsonObject.value(ServiceManagement::WebSocketInterface::JsonKeys::EXERCISE_ID()).toInt();
if (exerciseJsonObject.find(ServiceManagement::WebSocketInterface::JsonKeys::REPLAY_PARTITION_ID()) != exerciseJsonObject.end())
exercise.replayPartitionId = dds::core::optional<int32_t>(exerciseJsonObject.value(ServiceManagement::WebSocketInterface::JsonKeys::REPLAY_PARTITION_ID()).toInt());
QJsonArray servicesJsonArray = exerciseJsonObject.value(ServiceManagement::WebSocketInterface::JsonKeys::SERVICES()).toArray();
// prepare vector
services.clear();
services.reserve(servicesJsonArray.size());
for (const auto &serviceValue : servicesJsonArray)
{
ServiceInformation service;
QJsonObject serviceObject = serviceValue.toObject();
service.name = serviceObject.value(ServiceManagement::WebSocketInterface::JsonKeys::NAME()).toString();
service.abbreviation = serviceObject.value(ServiceManagement::WebSocketInterface::JsonKeys::NAME_ABBR()).toString();
QJsonArray portsJsonArray = serviceObject.value(ServiceManagement::WebSocketInterface::JsonKeys::PORTS()).toArray();
// prepare vector
ports.clear();
ports.reserve(portsJsonArray.size());
for (const auto &portValue : portsJsonArray)
{
QJsonObject portObject = portValue.toObject();
PortInformation port;
port.number = portObject.value(ServiceManagement::WebSocketInterface::JsonKeys::NUMBER()).toInt();
port.type = portObject.value(ServiceManagement::WebSocketInterface::JsonKeys::TYPE_ID()).toInt();
ports.append(port);
}
service.ports = ports;
services.append(service);
}
exercise.services = services;
exercises.append(exercise);
}
m_dataManager->servicePortsInformation(exercises);
}
bool ServicePortsInformation::hasValidData() const
{
return true;
}
// ####### ServicesInformation end #######
} // namespace Messages
} // namespace WebSocketInterface
} // namespace OcSituationClient
@@ -0,0 +1,106 @@
/**
* @RDE_HEADER@
* The ClientMessage class is an abstract base class for concrete ClientMessage objects
* $Id$
* $HeadURL$
* $Author$
* Created by Philipp Dassow, SLST, 2017-12-05
*/
#pragma once
#include <QtCore/QJsonObject>
#include <QVector>
#include <DDS/Core/core.hpp>
#include <LtsWebSocket/client_message_factory.h>
#include <LtsWebSocket/client_message.h>
#include "logger.h"
namespace OcSituationClient
{
namespace WebSocketInterface
{
class DataManager;
namespace Messages
{
/**
* @brief The ClientMessageFactory class creates ClientMessages which will then be processed
*/
class ClientMessageFactory final : public LtsWebSocket::AbstractClientMessageFactory
{
public:
explicit ClientMessageFactory(DataManager *dataManager);
virtual ~ClientMessageFactory();
/**
* @brief create Only way to create a ClientMessage object
* @param message Text message which will be converted to a ClientMessage object
* @return A ClientMessage object, which represents a concrete ClientMessage
*/
LtsWebSocket::AbstractClientMessage *createMessage(LtsWebSocket::ReplyHandler *client,
const QString &message);
private:
DataManager *m_dataManager;
}; // class ClientMessageFactory
/**
* @brief The ClientMessage class is an abstract base class for concrete ClientMessage objects
*/
class ClientMessage : public LtsWebSocket::AbstractClientMessage
{
protected: // method
explicit ClientMessage(DataManager *dataManager, LtsWebSocket::ReplyHandler *client, const QString &type, const QString &uuid, const QJsonValue &data = QJsonValue());
protected: // attributes
DataManager *m_dataManager;
}; // class ClientMessage
// ################## Message Implementations ##################
class ServicePortsInformation : public ClientMessage
{
public:
explicit ServicePortsInformation (DataManager *dataManager, LtsWebSocket::ReplyHandler *client, const QString &type, const QString &uuid, const QJsonValue &data);
public:
/**
* @brief The PortInformation struct holds the information what kind of port we have here
*/
struct PortInformation
{
int32_t number;
int32_t type;
};
/**
* @brief The ServiceInformation struct information about a service
*/
struct ServiceInformation
{
QString name;
QString abbreviation;
QVector<PortInformation> ports;
};
/**
* @brief The ExerciseInformation struct with information about an exercise (could also be a replay)
*/
struct ExerciseInformation
{
int32_t exerciseId;
dds::core::optional<int32_t> replayPartitionId;
QVector<ServiceInformation> services;
};
void process();
bool hasValidData() const;
}; // class ServicesInformation
} // namespace Messages
} // namespace WebSocketInterface
} // namespace OcSituationClient
@@ -0,0 +1,32 @@
/**
* @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 Philipp Dassow, SLST, 2017-12-05
*/
#include "reply_message.h"
#include <LtsWebSocket/json_keys.h>
#include "WebSocketInterface/json_keys.h"
#include <QtCore/QUuid>
#include <QtCore/QJsonDocument>
namespace OcSituationClient
{
namespace WebSocketInterface
{
namespace Messages
{
using namespace JsonKeys;
using namespace LtsWebSocket::JsonKeys;
ServicePortsInformationRequest::ServicePortsInformationRequest(const QString &uuid)
: ReplyMessage(ServiceManagement::WebSocketInterface::JsonKeys::SERVICE_PORTS_INFORMATION_REQUEST(), uuid)
{}
} // namespace Messages
} // namespace WebSocketInterface
} // namespace OcSituationClient
@@ -0,0 +1,36 @@
/**
* @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 Philipp Dassow, SLST, 2017-12-05
*/
#pragma once
#include <LtsWebSocket/client_message_factory.h>
#include <DDS/Core/core.hpp>
#include <QString>
#include <QMap>
#include <QtCore/QVector>
#include <QtCore/QJsonObject>
#include <QtCore/QJsonArray>
namespace OcSituationClient
{
namespace WebSocketInterface
{
namespace Messages
{
class ServicePortsInformationRequest : public LtsWebSocket::ReplyMessage
{
public:
explicit ServicePortsInformationRequest(const QString &uuid);
};
} // namespace Messages
} // namespace WebSocketInterface
} // namespace OcSituationClient
@@ -0,0 +1,40 @@
/**
* @RDE_HEADER@
* The DataManager class takes strucure element data from the HandlerStructureElement,
* offers an interface to get and set structure data
* $Id$
* $HeadURL$
* $Author$
* Created by Philipp Dassow, SLST, 2017-12-05
*/
#include "WebSocketInterface/data_manager.h"
#include "main_handler.h"
#include <QJsonDocument>
#include <QJsonObject>
#include <QMap>
#include <QVector>
namespace OcSituationClient
{
namespace WebSocketInterface
{
//---------------------------------------------------------------------------------------------------------
DataManager::DataManager(MainHandler *mainHandler)
: m_mainHandler(mainHandler)
, m_logger(getLogger(QStringLiteral("DataManager")))
{
}
//---------------------------------------------------------------------------------------------------------
void DataManager::servicePortsInformation(const QVector<Messages::ServicePortsInformation::ExerciseInformation> &exerciseInformation)
{
DEBUG_LOG(m_logger) << "Got ServicePortsInformation from websocket";
m_mainHandler->handlerBaseDownload()->handleServicePortsInformation(exerciseInformation);
}
} // namespace WebSocketInterface
} // namespace OcSituationClient
@@ -0,0 +1,47 @@
/**
* @RDE_HEADER@
* The DataManager class is a convenience class for managing structure data
* $Id$
* $HeadURL$
* $Author$
* Created by Philipp Dassow, SLST, 2017-12-05
*/
#pragma once
#include "WebSocketInterface/Messages/client_message.h"
#include "logger.h"
namespace OcSituationClient
{
class MainHandler;
namespace WebSocketInterface
{
/**
* @brief The DataManager class is a convenience class for managing structure data
*/
class DataManager final
{
public:
/**
* @brief DataManager Constructor
* @param mainHandler Source for needed handlers
*/
explicit DataManager(MainHandler *mainHandler);
/**
* @brief servicePortsInformation processing new port informations, only called during base DL
* @param exerciseInformation
*/
void servicePortsInformation(const QVector<Messages::ServicePortsInformation::ExerciseInformation> &exerciseInformation);
private: // attributes
MainHandler *m_mainHandler;
LOGGER_T m_logger;
}; // class DataManager
} // namespace WebSocketInterface
} // namespace OcSituationClient
@@ -0,0 +1,32 @@
/**
* @RDE_HEADER@
* Header file which holds all occuring JSON keys
* $Id$
* $HeadURL$
* $Author$
* Created by Philipp Dassow, SLST, 2017-12-05
*/
#pragma once
#include <QtCore/QString>
#include <ServiceManagement/WebSocketInterface/json_keys.h>
namespace OcSituationClient
{
namespace WebSocketInterface
{
/**
* @brief Namespace which holds all occuring JSON keys as const QString objects
*/
namespace JsonKeys
{
// types for client --> server messages
// types for server --> client messages
// data keys
} // namespace JsonKeys
} // namespace WebSocketInterface
} // namespace OcSituationClient
@@ -0,0 +1,72 @@
/**
* @RDE_HEADER@
* Handler for the WebSocket Interface
* $Id$
* $HeadURL$
* $Author$
* Created by Philipp Dassow, SLST, 2017-12-05
*/
#include "websocket_interface_handler.h"
#include "main_handler.h"
#include "data_manager.h"
#include "WebSocketInterface/Messages/client_message.h"
namespace OcSituationClient
{
namespace WebSocketInterface
{
WebSocketInterfaceHandler::WebSocketInterfaceHandler(MainHandler *mainHandler, QObject *parent)
: QObject(parent)
, m_webSocketClient(nullptr)
, m_messageFactory(nullptr)
, m_dataManager(nullptr)
, m_mainHandler(mainHandler)
, m_logger(getLogger("WebSocketInterfaceHandler"))
{
}
WebSocketInterfaceHandler::~WebSocketInterfaceHandler()
{
cleanup();
}
bool WebSocketInterfaceHandler::init()
{
cleanup();
DEBUG_LOG(m_logger) << "Initialising DataManager";
m_dataManager = new DataManager(m_mainHandler);
DEBUG_LOG(m_logger) << "... ok";
m_messageFactory = new Messages::ClientMessageFactory(m_dataManager);
m_webSocketClient = new LtsWebSocket::LtsWebSocketClient(m_messageFactory, this);
DEBUG_LOG(m_logger) << "Connection signals and slots";
connect(m_webSocketClient, &LtsWebSocket::LtsWebSocketClient::connected, this, &WebSocketInterfaceHandler::connected);
connect(m_webSocketClient, &LtsWebSocket::LtsWebSocketClient::disconnected, this, &WebSocketInterfaceHandler::disconnected);
DEBUG_LOG(m_logger) << "... ok";
return true;
}
void WebSocketInterfaceHandler::open(const QString &hostname, int port)
{
m_webSocketClient->open(hostname, port);
}
void WebSocketInterfaceHandler::send(LtsWebSocket::ReplyMessage *message)
{
m_webSocketClient->addReply(message);
}
void WebSocketInterfaceHandler::cleanup()
{
delete m_webSocketClient;
delete m_messageFactory;
delete m_dataManager;
}
} // namespace WebSocketInterface
} // namespace OcSituationClient
@@ -0,0 +1,90 @@
/**
* @RDE_HEADER@
* Handler for the WebSocket Interface
* $Id$
* $HeadURL$
* $Author$
* Created by Philipp Dassow, SLST, 2017-12-05
*/
#pragma once
#include <QtCore/QObject>
#include <QString>
#include <LtsWebSocket/lts_web_socket_client.h>
#include "logger.h"
namespace OcSituationClient
{
class MainHandler;
namespace WebSocketInterface
{
namespace Messages
{
class ClientMessageFactory;
class ReplyMessage;
}
class DataManager;
/**
* @brief The WebSocketInterfaceHandler class is the main class for the WebSocketInterface
*/
class WebSocketInterfaceHandler final : public QObject
{
Q_OBJECT
public:
/**
* @brief WebSocketInterfaceHandler Constructor
* @param mainHandler MainHandler to get the HandlerStructureElement from
*/
explicit WebSocketInterfaceHandler(MainHandler *mainHandler, QObject *parent = nullptr);
/**
* @brief ~WebSocketInterfaceHandler Destructor
*/
~WebSocketInterfaceHandler();
/**
* @brief init Initialises all needed classes for the WebSocketInterface
* @return True on success, otherwise false
*/
bool init();
/**
* @brief open Opens the websocket with the given parameter
* @param hostname
* @param port
*/
void open(const QString &hostname, int port);
/**
* @brief send Sends the given message
* @param msg
*/
void send(LtsWebSocket::ReplyMessage *message);
signals:
/**
* @brief connected
*/
void connected();
/**
* @brief disconnected
*/
void disconnected();
private:
void cleanup();
private:
LtsWebSocket::LtsWebSocketClient *m_webSocketClient;
Messages::ClientMessageFactory *m_messageFactory;
DataManager *m_dataManager;
MainHandler *m_mainHandler;
LOGGER_T m_logger;
}; // class WebSocketInterfaceHandle
} // namespace WebSocketInterface
} // namespace OcSituationClient