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,286 @@
/**
* @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 <AssetManagement/asm_db.h>
#include <ExerciseManagement/exm_db.h>
#include <FileManagement/flm_db.h>
#include <InfrastructureManagement/ism_db.h>
#include <ParticipantManagement/ppm_db.h>
#include <OperatorManagement/opm_db.h>
#include "WebSocketInterface/Messages/reply_message.h"
#include "WebSocketInterface/json_keys.h"
#include "WebSocketInterface/data_manager.h"
#include <QtCore/QJsonDocument>
#include <QtCore/QUuid>
namespace OcBaseDownload
{
namespace WebSocketInterface
{
namespace Messages
{
using namespace JsonKeys;
// ####### ClientMessageFactory begin #######
ClientMessageFactory::ClientMessageFactory(DataManager *dataManager)
: LtsWebSocket::AbstractClientMessageFactory(getLogger("ClientMessageFactory"))
, m_dataManager(dataManager)
{}
LtsWebSocket::AbstractClientMessage *ClientMessageFactory::createMessage(LtsWebSocket::ReplyHandler *client,
const QString &message)
{
LtsWebSocket::AbstractClientMessage *result = checkAttributes(client, message);
if (result)
return result;
if (m_type == LtsWebSocket::JsonKeys::ERROR_())
result = new ErrorMessage(m_dataManager, client, m_type, m_typeId, m_uuid, m_data);
// SCM telegram
else if (m_type == ServiceManagement::WebSocketInterface::JsonKeys::SERVICE_PORTS_INFORMATION())
result = new ServicePortsInformation(m_dataManager, client, m_type, m_typeId, m_uuid, m_data);
// ASM telegrams
else if (m_type == AssetManagement::WebSocketInterface::JsonKeys::TRAINING_AREA_BASE_DATA())
result = new BaseData<AssetManagement::DatabaseInterface, AssetManagement::Database::AsmTrainingArea>(m_dataManager, client, m_type, m_typeId, m_uuid, m_data);
else if (m_type == AssetManagement::WebSocketInterface::JsonKeys::TECHNICAL_AREA_BASE_DATA())
result = new BaseData<AssetManagement::DatabaseInterface, AssetManagement::Database::AsmTechnicalArea>(m_dataManager, client, m_type, m_typeId, m_uuid, m_data);
else if (m_type == AssetManagement::WebSocketInterface::JsonKeys::LOCATION_BASE_DATA())
result = new BaseData<AssetManagement::DatabaseInterface, AssetManagement::Database::AsmLocation>(m_dataManager, client, m_type, m_typeId, m_uuid, m_data);
else if (m_type == AssetManagement::WebSocketInterface::JsonKeys::ASM_ASSET_BASE_DATA())
result = new BaseData<AssetManagement::DatabaseInterface, AssetManagement::Database::AsmAsset>(m_dataManager, client, m_type, m_typeId, m_uuid, m_data);
// EXM telegrams
else if (m_type == ExerciseManagement::WebSocketInterface::JsonKeys::EXERCISE_BASE_DATA())
result = new BaseData<ExerciseManagement::DatabaseInterface, ExerciseManagement::Database::ExmExercise>(m_dataManager, client, m_type, m_typeId, m_uuid, m_data);
else if (m_type == ExerciseManagement::WebSocketInterface::JsonKeys::EXERCISE_PHASE_BASE_DATA())
result = new BaseData<ExerciseManagement::DatabaseInterface, ExerciseManagement::Database::ExmExercisePhase>(m_dataManager, client, m_type, m_typeId, m_uuid, m_data);
else if (m_type == ExerciseManagement::WebSocketInterface::JsonKeys::EXERCISE_STATE_CHANGE_BASE_DATA())
result = new BaseData<ExerciseManagement::DatabaseInterface, ExerciseManagement::Database::ExmExerciseStateChange>(m_dataManager, client, m_type, m_typeId, m_uuid, m_data);
// ISM telegrams
else if (m_type == InfrastructureManagement::WebSocketInterface::JsonKeys::ISM_ASSET_BASE_DATA())
result = new BaseData<InfrastructureManagement::DatabaseInterface, InfrastructureManagement::Database::IsmAsset>(m_dataManager, client, m_type, m_typeId, m_uuid, m_data);
else if (m_type == InfrastructureManagement::WebSocketInterface::JsonKeys::MAIN_STRUCTURE_ELEMENT_BASE_DATA())
result = new BaseData<InfrastructureManagement::DatabaseInterface, InfrastructureManagement::Database::IsmMainStructureElement>(m_dataManager, client, m_type, m_typeId, m_uuid, m_data);
else if (m_type == InfrastructureManagement::WebSocketInterface::JsonKeys::STRUCTURE_ELEMENT_BASE_DATA())
result = new BaseData<InfrastructureManagement::DatabaseInterface, InfrastructureManagement::Database::IsmStructureElement>(m_dataManager, client, m_type, m_typeId, m_uuid, m_data);
else if (m_type == InfrastructureManagement::WebSocketInterface::JsonKeys::STRUCTURE_ELEMENT_FOOTPRINT_BASE_DATA())
result = new BaseData<InfrastructureManagement::DatabaseInterface, InfrastructureManagement::Database::IsmStructureElementFootprint>(m_dataManager, client, m_type, m_typeId, m_uuid, m_data);
else if (m_type == InfrastructureManagement::WebSocketInterface::JsonKeys::MOUNTING_POINT_ASSET_BASE_DATA())
result = new BaseData<InfrastructureManagement::DatabaseInterface, InfrastructureManagement::Database::IsmMountingPointAsset>(m_dataManager, client, m_type, m_typeId, m_uuid, m_data);
else if (m_type == InfrastructureManagement::WebSocketInterface::JsonKeys::MOUNTING_POINT_SCHEDULE_BASE_DATA())
result = new BaseData<InfrastructureManagement::DatabaseInterface, InfrastructureManagement::Database::IsmMountingPointSchedule>(m_dataManager, client, m_type, m_typeId, m_uuid, m_data);
else if (m_type == InfrastructureManagement::WebSocketInterface::JsonKeys::MOUNTING_POINT_PLAN_BASE_DATA())
result = new BaseData<InfrastructureManagement::DatabaseInterface, InfrastructureManagement::Database::IsmMountingPointPlan>(m_dataManager, client, m_type, m_typeId, m_uuid, m_data);
// PPM Ex0 telegrams
else if (m_type == ParticipantManagement::WebSocketInterface::JsonKeys::EQUIPMENT_TYPE_BASE_DATA())
result = new BaseData<ParticipantManagement::DatabaseInterface, ParticipantManagement::Database::PpmEquipmentType>(m_dataManager, client, m_type, m_typeId, m_uuid, m_data);
else if (m_type == ParticipantManagement::WebSocketInterface::JsonKeys::TYPE_BASE_DATA())
result = new BaseData<ParticipantManagement::DatabaseInterface, ParticipantManagement::Database::PpmType>(m_dataManager, client, m_type, m_typeId, m_uuid, m_data);
// PPM ExN telegrams
else if (m_type == ParticipantManagement::WebSocketInterface::JsonKeys::PARTY_BASE_DATA())
result = new BaseData<ParticipantManagement::DatabaseInterface, ParticipantManagement::Database::PpmParty>(m_dataManager, client, m_type, m_typeId, m_uuid, m_data);
else if (m_type == ParticipantManagement::WebSocketInterface::JsonKeys::PARTICIPANT_BASE_DATA())
result = new BaseData<ParticipantManagement::DatabaseInterface, ParticipantManagement::Database::PpmParticipant>(m_dataManager, client, m_type, m_typeId, m_uuid, m_data);
// OPM telegrams
else if (m_type == OperatorManagement::WebSocketInterface::JsonKeys::GROUP_BASE_DATA())
result = new BaseData<OperatorManagement::DatabaseInterface, OperatorManagement::Database::OpmGroup>(m_dataManager, client, m_type, m_typeId, m_uuid, m_data);
else if (m_type == OperatorManagement::WebSocketInterface::JsonKeys::GROUP_GROUP_BASE_DATA())
result = new BaseData<OperatorManagement::DatabaseInterface, OperatorManagement::Database::OpmGroupGroup>(m_dataManager, client, m_type, m_typeId, m_uuid, m_data);
else if (m_type == OperatorManagement::WebSocketInterface::JsonKeys::OPERATOR_BASE_DATA())
result = new BaseData<OperatorManagement::DatabaseInterface, OperatorManagement::Database::OpmOperator>(m_dataManager, client, m_type, m_typeId, m_uuid, m_data);
else if (m_type == OperatorManagement::WebSocketInterface::JsonKeys::OPERATOR_EXERCISE_BASE_DATA())
result = new BaseData<OperatorManagement::DatabaseInterface, OperatorManagement::Database::OpmOperatorExercise>(m_dataManager, client, m_type, m_typeId, m_uuid, m_data);
else if (m_type == OperatorManagement::WebSocketInterface::JsonKeys::SETTINGS_BASE_DATA())
result = new BaseData<OperatorManagement::DatabaseInterface, OperatorManagement::Database::OpmSettings>(m_dataManager, client, m_type, m_typeId, m_uuid, m_data);
else if (m_type == OperatorManagement::WebSocketInterface::JsonKeys::ACCESS_CONTROL_LEVEL_BASE_DATA())
result = new BaseData<OperatorManagement::DatabaseInterface, OperatorManagement::Database::OpmAccessControlLevel>(m_dataManager, client, m_type, m_typeId, m_uuid, m_data);
else if (m_type == OperatorManagement::WebSocketInterface::JsonKeys::ACL_ALLOW_BASE_DATA())
result = new BaseData<OperatorManagement::DatabaseInterface, OperatorManagement::Database::OpmAclAllow>(m_dataManager, client, m_type, m_typeId, m_uuid, m_data);
else if (m_type == OperatorManagement::WebSocketInterface::JsonKeys::ACL_DENY_BASE_DATA())
result = new BaseData<OperatorManagement::DatabaseInterface, OperatorManagement::Database::OpmAclDeny>(m_dataManager, client, m_type, m_typeId, m_uuid, m_data);
// FLM telegrams
else if (m_type == FileManagement::WebSocketInterface::JsonKeys::FOLDER_BASE_DATA())
result = new BaseData<FileManagement::DatabaseInterface, FileManagement::Database::FlmFolder>(m_dataManager, client, m_type, m_typeId, m_uuid, m_data);
else if (m_type == FileManagement::WebSocketInterface::JsonKeys::FILE_CONTENT_BASE_DATA())
result = new BaseData<FileManagement::DatabaseInterface, FileManagement::Database::FlmFileContent>(m_dataManager, client, m_type, m_typeId, m_uuid, m_data);
else if (m_type == FileManagement::WebSocketInterface::JsonKeys::PDF_LIST_DATA())
result = new PdfListMessage(m_dataManager, client, m_type, m_typeId, m_uuid, m_data);
return checkResult(client, message, result);
}
// ####### ClientMessageFactory end #######
// ####### ClientMessage begin #######
ClientMessage::ClientMessage(DataManager *dataManager, LtsWebSocket::ReplyHandler *client, const QString &type, const int typeId, const QString &uuid, const QJsonValue &data)
: LtsWebSocket::AbstractClientMessage(client, type, typeId, uuid, data)
, m_dataManager(dataManager)
, m_logger(getLogger("ClientMessage"))
{}
// ####### ClientMessage end #######
// ####### ServicesInformation begin #######
ErrorMessage::ErrorMessage(DataManager *dataManager, LtsWebSocket::ReplyHandler *client, const QString &type, const int typeId, const QString &uuid, const QJsonValue &data)
: ClientMessage(dataManager, client, type, typeId, uuid, data)
{}
void ErrorMessage::process()
{
ErrorData err;
err.errorClass = m_data.toObject().value(LtsWebSocket::JsonKeys::ERROR_CLASS()).toInt();
err.uuid = m_data.toObject().value(LtsWebSocket::JsonKeys::UUID_()).toString();
err.errorMessage = m_data.toObject().value(LtsWebSocket::JsonKeys::ERROR_MESSAGE()).toString();
m_dataManager->handleErrorMessage(err);
}
bool ErrorMessage::hasValidData() const
{
return true;
}
// ####### ErrorMessage end #######
// ####### ServicesInformation begin #######
ServicePortsInformation::ServicePortsInformation(DataManager *dataManager, LtsWebSocket::ReplyHandler *client, const QString &type, const int typeId, const QString &uuid, const QJsonValue &data)
: ClientMessage(dataManager, client, type, typeId, uuid, data)
{}
void ServicePortsInformation::process()
{
const 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.contains(ServiceManagement::WebSocketInterface::JsonKeys::REPLAY_PARTITION_ID()))
exercise.replayPartitionId = dds::core::optional<int32_t>(exerciseJsonObject.value(ServiceManagement::WebSocketInterface::JsonKeys::REPLAY_PARTITION_ID()).toInt());
const 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();
const 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 #######
// ####### BaseData begin #######
template <typename DB, typename T>
BaseData<DB, T>::BaseData(DataManager *dataManager, LtsWebSocket::ReplyHandler *client, const QString &type, const int typeId, const QString &uuid, QJsonValue &data)
: ClientMessage(dataManager, client, type, typeId, uuid, data)
{}
template <typename DB, typename T>
void BaseData<DB, T>::process()
{
m_dataManager->baseData<T>(DB::template fromJson<T>(m_data.toArray()));
}
template <typename DB, typename T>
bool BaseData<DB, T>::hasValidData() const
{
return true;
}
// ####### BaseData end #######
// ####### PdfListData begin #######
PdfListMessage::PdfListMessage(DataManager *dataManager, LtsWebSocket::ReplyHandler *client, const QString &type, const int typeId, const QString &uuid, QJsonValue &data)
: ClientMessage(dataManager, client, type, typeId, uuid, data)
{}
void PdfListMessage::process()
{
PdfListData data;
using namespace FileManagement::WebSocketInterface::JsonKeys;
if (m_data.isArray())
{
data.pdfData.reserve(m_data.toArray().size());
QJsonArray arr = m_data.toArray();
for (const QJsonValue &current : qAsConst(arr))
{
if (!current.isObject())
continue;
QJsonObject obj = current.toObject();
data.pdfData.append({obj.value(FILE_ID()).toInt(),
obj.value(NAME()).toString(),
obj.value(FILE_SIZE()).toInt(),
FileManagement::FileCategory::inner_enum(obj.value(FILE_CATEGORY()).toInt()),
obj.value(IS_TEMPLATE()).toBool(),
obj.value(PROPERTIES()),
FileManagement::FileStatus::inner_enum(obj.value(FILE_STATUS()).toInt()),
obj.value(FOLDER_ID()).toInt(),
obj.value(PHASE_ID()).toInt(),
obj.value(OPERATOR_ID()).toInt(),
obj.value(EXERCISE_ID()).toInt()
});
}
}
m_dataManager->handlePdfListMessage(data);
}
bool PdfListMessage::hasValidData() const
{
return true;
}
// ####### PdfListData end #######
} // namespace Messages
} // namespace WebSocketInterface
} // namespace OcBaseDownload
@@ -0,0 +1,198 @@
/**
* @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 <FileManagement/flm_enums.hpp>
#include "logger.h"
namespace OcBaseDownload
{
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);
/**
* @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 int typeId, const QString &uuid, const QJsonValue &data = QJsonValue());
protected: // attributes
DataManager *m_dataManager;
LOGGER_T m_logger;
}; // class ClientMessage
// ################## Message Implementations ##################
class ErrorMessage : public ClientMessage
{
public:
explicit ErrorMessage(DataManager *dataManager, LtsWebSocket::ReplyHandler *client, const QString &type, const int typeId, const QString &uuid, const QJsonValue &data);
/**
* @brief The ErrorData struct represents the data part of an ErrorMessage object
*/
struct ErrorData
{
int errorClass = 0;
QString uuid;
QString errorMessage;
};
void process();
bool hasValidData() const;
};
class ServicePortsInformation : public ClientMessage
{
public:
explicit ServicePortsInformation(DataManager *dataManager, LtsWebSocket::ReplyHandler *client, const QString &type, const int typeId, 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 = 0;
int32_t type = 0;
};
/**
* @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 = 0;
dds::core::optional<int32_t> replayPartitionId;
QVector<ServiceInformation> services;
};
void process();
bool hasValidData() const;
}; // class ServicesInformation
/**
* @brief Handle a BaseData telegram
*/
template <typename DB, typename T>
class BaseData final : public ClientMessage
{
public:
explicit BaseData(DataManager *dataManager, LtsWebSocket::ReplyHandler *client, const QString &type, const int typeId, const QString &uuid, QJsonValue &data);
void process();
bool hasValidData() const;
}; // class BaseData
/**
* @brief Handle a PdfListData telegram
*/
class PdfListMessage : public ClientMessage
{
public:
explicit PdfListMessage(DataManager *dataManager, LtsWebSocket::ReplyHandler *client, const QString &type, const int typeId, const QString &uuid, QJsonValue &data);
struct PdfInformation
{
int32_t id = -1;
QString name;
int fileSize = -1;
FileManagement::FileCategory fileCategory = FileManagement::FileCategory::Global;
bool isTemplate = false;
QJsonValue properties;
FileManagement::FileStatus fileStatus = FileManagement::FileStatus::Deleted;
int folderId = -1;
int phaseId = -1;
int operatorId = -1;
int exerciseId = -1;
PdfInformation() = default;
PdfInformation(int32_t id,
const QString &name,
int fileSize,
FileManagement::FileCategory fileCategory,
bool isTemplate,
const QJsonValue &properties,
FileManagement::FileStatus fileStatus,
int folderId,
int phaseId,
int operatorId,
int exerciseId)
: id(id)
, name(name)
, fileSize(fileSize)
, fileCategory(fileCategory)
, isTemplate(isTemplate)
, properties(properties)
, fileStatus(fileStatus)
, folderId(folderId)
, phaseId(phaseId)
, operatorId(operatorId)
, exerciseId(exerciseId)
{}
};
struct PdfListData
{
QVector<PdfInformation> pdfData;
};
void process();
bool hasValidData() const;
}; // class PdfListData
} // namespace Messages
} // namespace WebSocketInterface
} // namespace OcBaseDownload
@@ -0,0 +1,63 @@
/**
* @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 OcBaseDownload
{
namespace WebSocketInterface
{
namespace Messages
{
using namespace JsonKeys;
using namespace LtsWebSocket::JsonKeys;
// ####### ServicePortsInformationRequest begin #######
ServicePortsInformationRequest::ServicePortsInformationRequest(const QString &uuid)
: ReplyMessage(ServiceManagement::WebSocketInterface::JsonKeys::SERVICE_PORTS_INFORMATION_REQUEST(), 6002, uuid)
{}
// ####### ServicePortsInformationRequest end #######
// ####### BaseDlRequest begin #######
/************************************************************
* Attention! TypeId 6006 is negotiated with ESG for ADLER! *
************************************************************/
BaseDlRequest::BaseDlRequest(const QString &uuid, int exerciseId)
: LtsWebSocket::ReplyMessage(BASE_DL_REQUEST(), 6006, uuid) // Todo: Check whether typeId is correct
{
if (0 < exerciseId)
{
QJsonObject data;
data.insert(EXERCISE_ID(), QJsonValue(exerciseId));
m_jsonRepresentation.insert(DATA(), data);
}
}
// ####### BaseDlRequest end #######
// ####### PdfListRequest begin #######
PdfListRequest::PdfListRequest(const QString &uuid, int exerciseId)
: LtsWebSocket::ReplyMessage(PDF_LIST_REQUEST(), 2, uuid) // Todo: Check whether typeId is correct
{
if (0 < exerciseId)
{
QJsonObject data;
data.insert(EXERCISE_ID(), QJsonValue(exerciseId));
m_jsonRepresentation.insert(DATA(), data);
}
}
// ####### PdfListRequest end #######
} // namespace Messages
} // namespace WebSocketInterface
} // namespace OcBaseDownload
@@ -0,0 +1,58 @@
/**
* @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 OcBaseDownload
{
namespace WebSocketInterface
{
namespace Messages
{
/**
* @brief The ServicePortsInformationRequest class
*/
class ServicePortsInformationRequest : public LtsWebSocket::ReplyMessage
{
public:
explicit ServicePortsInformationRequest(const QString &uuid);
}; // class ServicePortsInformationRequest
/**
* @brief The BaseDlRequest class
*/
class BaseDlRequest : public LtsWebSocket::ReplyMessage
{
public:
explicit BaseDlRequest(const QString &uuid, int exerciseId);
}; // class BaseDlRequest
/**
* @brief The BaseDlRequest class
*/
class PdfListRequest : public LtsWebSocket::ReplyMessage
{
public:
explicit PdfListRequest(const QString &uuid, int exerciseId);
}; // class PdfListRequest
} // namespace Messages
} // namespace WebSocketInterface
} // namespace OcBaseDownload
@@ -0,0 +1,94 @@
/**
* @RDE_HEADER@
* The DataManager class is a convenience class for managing structure data
* offers an interface to get and set structure data
* $Id$
* $HeadURL$
* $Author$
* Created by Philipp Dassow, SLST, 2017-03-27
*/
#include "WebSocketInterface/data_manager.h"
#include <QVector>
namespace OcBaseDownload
{
namespace WebSocketInterface
{
//---------------------------------------------------------------------------------------------------------
DataManager::DataManager(MainHandler *mainHandler)
: m_mainHandler(mainHandler)
, m_currentDownload(CurrentDownload::NOTHING)
, m_logger(getLogger(QStringLiteral("DataManager")))
{
}
//---------------------------------------------------------------------------------------------------------
void DataManager::handleErrorMessage(const OcBaseDownload::WebSocketInterface::Messages::ErrorMessage::ErrorData &errData)
{
ERROR_LOG(m_logger) << "uuid: " << errData.uuid << " error class: " << errData.errorClass << " text: " << errData.errorMessage;
}
//---------------------------------------------------------------------------------------------------------
void DataManager::servicePortsInformation(const QVector<Messages::ServicePortsInformation::ExerciseInformation> &exerciseInformation)
{
DEBUG_LOG(m_logger) << "Got ServicePortsInformation from websocket";
switch (m_currentDownload)
{
case CurrentDownload::PDF:
m_mainHandler->handlerPdfDownload()->handleServicePortsInformation(exerciseInformation);
break;
case CurrentDownload::BASE:
//m_mainHandler->handlerBaseDownload()->handleServicePortsInformation(exerciseInformation);
break;
case CurrentDownload::NOTHING:
default:
WARNING_LOG(m_logger) << "Got Ports Information in neither BASE nor PDF download mode";
break;
}
}
//---------------------------------------------------------------------------------------------------------
void DataManager::handlePdfListMessage(const Messages::PdfListMessage::PdfListData &pdfListData)
{
DEBUG_LOG(m_logger) << "Got PDF list from websocket";
m_mainHandler->handlerPdfDownload()->handlePdfListData(pdfListData);
}
//---------------------------------------------------------------------------------------------------------
void DataManager::setCurrentDownload(CurrentDownload currentDownload)
{
m_currentDownload = currentDownload;
switch (m_currentDownload)
{
case CurrentDownload::PDF:
DEBUG_LOG(m_logger) << "Setting current download mode to PDF";
m_mainHandler->dds()->fts()->enableStartBaseDownload(false);
m_mainHandler->dds()->fts()->enableGetPdfList();
m_mainHandler->dds()->fts()->enableStartPdfDownload();
break;
case CurrentDownload::BASE:
DEBUG_LOG(m_logger) << "Setting current download mode to BASE";
m_mainHandler->dds()->fts()->enableStartBaseDownload();
m_mainHandler->dds()->fts()->enableGetPdfList(false);
m_mainHandler->dds()->fts()->enableStartPdfDownload(false);
break;
case CurrentDownload::NOTHING:
DEBUG_LOG(m_logger) << "Setting current download mode to NOTHING";
m_mainHandler->dds()->fts()->enableAll();
break;
default:
break;
}
}
//---------------------------------------------------------------------------------------------------------
CurrentDownload DataManager::currentDownload() const
{
return m_currentDownload;
}
} // namespace WebSocketInterface
} // namespace OcBaseDownload
@@ -0,0 +1,80 @@
/**
* @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 "main_handler.h"
#include "logger.h"
#include "enums.h"
namespace OcBaseDownload
{
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 handleErrorMessage
* @param errData
*/
void handleErrorMessage(const Messages::ErrorMessage::ErrorData &errData);
/**
* @brief servicePortsInformation processing new port informations, only called during base DL
* @param exerciseInformation
*/
void servicePortsInformation(const QVector<Messages::ServicePortsInformation::ExerciseInformation> &exerciseInformation);
// handling asm base data
template <typename T>
void baseData(std::vector<T> &&data)
{
Q_UNUSED(data)
DEBUG_LOG(m_logger) << "Got new base data.";
//m_mainHandler->handlerBaseDownload()->handleBaseData(std::move(data));
}
/**
* @brief handlePdfListMessage
* @param pdfListData a list of PDF document names
*/
void handlePdfListMessage(const Messages::PdfListMessage::PdfListData &pdfListData);
/**
* @brief setCurrentDownload sets the current download
* @param currentDownload The new value
*/
void setCurrentDownload(CurrentDownload currentDownload);
/**
* @brief Getter for current download
* @return Value of the current download
*/
CurrentDownload currentDownload() const;
private: // attributes
MainHandler *m_mainHandler;
CurrentDownload m_currentDownload;
LOGGER_T m_logger;
}; // class DataManager
} // namespace WebSocketInterface
} // namespace OcBaseDownload
+25
View File
@@ -0,0 +1,25 @@
/**
* @RDE_HEADER@
* Header file which holds all occuring enums
* $Id$
* $HeadURL$
* $Author$
* Created by Hannes Fritsche, NLE, 2019-04-26
*/
#pragma once
namespace OcBaseDownload
{
namespace WebSocketInterface
{
/**
* @brief Helper to serve the correct handler for incoming messages via WebSocket
*/
enum class CurrentDownload
{
NOTHING,
BASE,
PDF
};
}
}
+43
View File
@@ -0,0 +1,43 @@
/**
* @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 <LtsWebSocket/json_keys.h>
#include <AssetManagement/WebSocketInterface/json_keys.h>
#include <ExerciseManagement/WebSocketInterface/json_keys.h>
#include <FileManagement/WebSocketInterface/json_keys.h>
#include <InfrastructureManagement/WebSocketInterface/json_keys.h>
#include <OperatorManagement/WebSocketInterface/json_keys.h>
#include <ParticipantManagement/WebSocketInterface/json_keys.h>
#include <ServiceManagement/WebSocketInterface/json_keys.h>
namespace OcBaseDownload
{
namespace WebSocketInterface
{
/**
* @brief Namespace which holds all occuring JSON keys as const QString objects
*/
namespace JsonKeys
{
// types for client --> server messages
inline QString BASE_DL_REQUEST() { return QStringLiteral("baseDlRequest"); }
inline QString PDF_LIST_REQUEST() { return QStringLiteral("pdfListRequest"); }
// types for server --> client messages
// data keys
inline QString EXERCISE_ID() { return QStringLiteral("exerciseId"); }
} // namespace JsonKeys
} // namespace WebSocketInterface
} // namespace OcBaseDownload
@@ -0,0 +1,133 @@
/**
* @RDE_HEADER@
* Handler for the WebSocket Interface
* $Id$
* $HeadURL$
* $Author$
* Created by Philipp Dassow, SLST, 2017-12-05
*/
#include "websocket_interface_handler.h"
#include "settings.h"
#include "main_handler.h"
#include "data_manager.h"
#include "WebSocketInterface/Messages/client_message.h"
#include <QTimer>
namespace OcBaseDownload
{
namespace WebSocketInterface
{
WebSocketInterfaceHandler::WebSocketInterfaceHandler(MainHandler *mainHandler, QObject *parent)
: QObject(parent)
, m_webSocketClient(nullptr)
, m_messageFactory(nullptr)
, m_dataManager(nullptr)
, m_mainHandler(mainHandler)
, m_webSocketActivityTimer(new QTimer(this))
, m_logger(getLogger("WebSocketInterfaceHandler"))
{
connect(m_webSocketActivityTimer, &QTimer::timeout, this, &WebSocketInterfaceHandler::dataReceiveTimeout, Qt::UniqueConnection);
const int iTimeout = Settings::webSocketActivityTimeoutMSec();
if (iTimeout > 0)
m_webSocketActivityTimer->setInterval(iTimeout);
}
WebSocketInterfaceHandler::~WebSocketInterfaceHandler()
{
cleanup();
}
bool WebSocketInterfaceHandler::init()
{
cleanup();
DEBUG_LOG(m_logger) << "WebSocketInterfaceHandler::init";
m_dataManager = new DataManager(m_mainHandler);
DEBUG_LOG(m_logger) << "... ok";
m_messageFactory = new Messages::ClientMessageFactory(m_dataManager);
return true;
}
void WebSocketInterfaceHandler::open(const QString &hostname, int port)
{
DEBUG_LOG(m_logger) << "Opening " << hostname << ":" << port;
recreateWebSocket();
m_webSocketClient->open(hostname, port);
m_webSocketActivityTimer->start();
}
void WebSocketInterfaceHandler::close()
{
m_webSocketActivityTimer->stop();
if (m_webSocketClient)
{
disconnect(m_webSocketClient);
m_webSocketClient->disconnect();
m_webSocketClient->close();
m_webSocketClient->deleteLater();
m_webSocketClient = nullptr;
}
}
bool WebSocketInterfaceHandler::send(LtsWebSocket::ReplyMessage *message)
{
DEBUG_LOG(m_logger) << "Sending: " << message->toJsonString();
if (!m_webSocketClient)
return false;
m_webSocketClient->addReply(message);
return true;
}
void WebSocketInterfaceHandler::setCurrentDownload(CurrentDownload currentDownload)
{
m_dataManager->setCurrentDownload(currentDownload);
}
CurrentDownload WebSocketInterfaceHandler::currentDownload() const
{
return m_dataManager->currentDownload();
}
void WebSocketInterfaceHandler::recreateWebSocket()
{
close();
m_webSocketClient = new LtsWebSocket::LtsWebSocketClient(m_messageFactory, this);
connect(m_webSocketClient, &LtsWebSocket::LtsWebSocketClient::connected,
this, &WebSocketInterfaceHandler::connected);
connect(m_webSocketClient, &LtsWebSocket::LtsWebSocketClient::disconnected,
this, &WebSocketInterfaceHandler::disconnected);
//connect(m_webSocketClient, &LtsWebSocket::LtsWebSocketClient::dataReceived,
//m_webSocketActivityTimer, QOverload<>::of(&QTimer::start));
connect(m_webSocketClient, &LtsWebSocket::LtsWebSocketClient::dataReceived,
this, [this]()
{
DEBUG_LOG(m_logger) << "data received restart timer";
m_webSocketActivityTimer->start();
});
}
void WebSocketInterfaceHandler::cleanup()
{
delete m_webSocketClient;
delete m_messageFactory;
delete m_dataManager;
m_webSocketClient = nullptr;
m_messageFactory = nullptr;
m_dataManager = nullptr;
}
} // namespace WebSocketInterface
} // namespace OcBaseDownload
@@ -0,0 +1,105 @@
/**
* @RDE_HEADER@
* Handler for the WebSocket Interface
* $Id$
* $HeadURL$
* $Author$
* Created by Philipp Dassow, SLST, 2017-12-05
*/
#pragma once
#include <QObject>
#include <QString>
#include <LtsWebSocket/lts_web_socket_client.h>
#include "logger.h"
#include "enums.h"
class QTimer;
namespace OcBaseDownload
{
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 close
*/
void close();
/**
* @brief send Sends the given message
* @param msg
*/
bool send(LtsWebSocket::ReplyMessage *message);
/**
* @brief setCurrentDownload sets the current download
* @param currentDownload The new value
*/
void setCurrentDownload(CurrentDownload currentDownload);
/**
* @brief Getter for current download
* @return Value of the current download
*/
CurrentDownload currentDownload() const;
signals:
void connected();
void disconnected();
void dataReceiveTimeout();
void dataReceived();
private:
void cleanup();
void recreateWebSocket();
private:
LtsWebSocket::LtsWebSocketClient *m_webSocketClient;
Messages::ClientMessageFactory *m_messageFactory;
DataManager *m_dataManager;
MainHandler *m_mainHandler;
QTimer *m_webSocketActivityTimer;
LOGGER_T m_logger;
}; // class WebSocketInterfaceHandle
} // namespace WebSocketInterface
} // namespace OcBaseDownload