Initial commit
This commit is contained in:
commit
b7d90b9afe
16245 files changed
+3396666
No files matched your search
+71
@@ -0,0 +1,71 @@
|
||||
/**
|
||||
* @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 ServiceManagement
|
||||
{
|
||||
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 == SERVICE_PORTS_INFORMATION_REQUEST())
|
||||
result = new ServicePortsInformationRequest(m_dataManager, client, m_type, m_typeId, m_uuid);
|
||||
|
||||
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)
|
||||
{}
|
||||
// ####### ClientMessage end #######
|
||||
|
||||
// ####### ServicesInformation begin #######
|
||||
ServicePortsInformationRequest::ServicePortsInformationRequest(DataManager *dataManager, LtsWebSocket::ReplyHandler *client, const QString &type, const int typeId, const QString &uuid)
|
||||
: ClientMessage (dataManager,client, type, typeId, uuid)
|
||||
{}
|
||||
|
||||
void ServicePortsInformationRequest::process()
|
||||
{
|
||||
m_client->addReply(m_dataManager->servicesInformation(m_uuid));
|
||||
}
|
||||
|
||||
bool ServicePortsInformationRequest::hasValidData() const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
// ####### ServicesInformation end #######
|
||||
|
||||
} // namespace Messages
|
||||
} // namespace WebSocketInterface
|
||||
} // namespace ServiceManagement
|
||||
+73
@@ -0,0 +1,73 @@
|
||||
/**
|
||||
* @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 <LtsWebSocket/client_message_factory.h>
|
||||
#include <LtsWebSocket/client_message.h>
|
||||
|
||||
#include "logger.h"
|
||||
|
||||
namespace ServiceManagement
|
||||
{
|
||||
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;
|
||||
}; // class ClientMessage
|
||||
|
||||
// ################## Message Implementations ##################
|
||||
class ServicePortsInformationRequest : public ClientMessage
|
||||
{
|
||||
public:
|
||||
explicit ServicePortsInformationRequest (DataManager *dataManager, LtsWebSocket::ReplyHandler *client, const QString &type, const int typeId, const QString &uuid);
|
||||
|
||||
void process();
|
||||
bool hasValidData() const;
|
||||
|
||||
}; // class ServicesInformation
|
||||
|
||||
} // namespace Messages
|
||||
} // namespace WebSocketInterface
|
||||
} // namespace ServiceManagement
|
||||
+69
@@ -0,0 +1,69 @@
|
||||
/**
|
||||
* @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 ServiceManagement
|
||||
{
|
||||
namespace WebSocketInterface
|
||||
{
|
||||
namespace Messages
|
||||
{
|
||||
using namespace JsonKeys;
|
||||
using namespace LtsWebSocket::JsonKeys;
|
||||
|
||||
// ####### ServicePortsInformationMessage begin #######
|
||||
/********************************************************
|
||||
* Warning: 6002 has been negotiated with ESG for ADLER *
|
||||
********************************************************/
|
||||
ServicePortsInformationMessage::ServicePortsInformationMessage(const QVector<ExerciseInformation> &data, const QString &uuid)
|
||||
: ReplyMessage (SERVICE_PORTS_INFORMATION(), 6002, uuid) // Todo check whether TypeID is correct.
|
||||
{
|
||||
QJsonArray exercises;
|
||||
for (const auto &exercise : data)
|
||||
{
|
||||
QJsonArray services;
|
||||
for (const auto &service : exercise.services)
|
||||
{
|
||||
QJsonArray ports;
|
||||
|
||||
for (const auto &port : service.ports)
|
||||
{
|
||||
ports.append(QJsonObject({{NUMBER(),port.number},
|
||||
{TYPE_ID(),port.type},
|
||||
{PROPERTIES(), port.properties}
|
||||
}));
|
||||
}
|
||||
|
||||
services.append(QJsonObject({{NAME(), service.name},
|
||||
{NAME_ABBR(), service.abbreviation},
|
||||
{PORTS(), ports}
|
||||
}));
|
||||
}
|
||||
QJsonObject obj({{EXERCISE_ID(), exercise.exerciseId},
|
||||
{SERVICES(), services}
|
||||
});
|
||||
if (exercise.replayPartitionId.is_set())
|
||||
obj.insert(REPLAY_PARTITION_ID(), exercise.replayPartitionId.get());
|
||||
|
||||
exercises.append(obj);
|
||||
}
|
||||
|
||||
m_jsonRepresentation.insert(DATA(), exercises);
|
||||
}
|
||||
// ####### ServicePortsInformationMessage end #######
|
||||
|
||||
} // namespace Messages
|
||||
} // namespace WebSocketInterface
|
||||
} // namespace ServiceManagement
|
||||
@@ -0,0 +1,71 @@
|
||||
/**
|
||||
* @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 ServiceManagement
|
||||
{
|
||||
namespace WebSocketInterface
|
||||
{
|
||||
namespace Messages
|
||||
{
|
||||
/**
|
||||
* @brief The ServicePortsInformationMessage class represents the service informations collected by the svcServiceManagement
|
||||
*/
|
||||
class ServicePortsInformationMessage final : public LtsWebSocket::ReplyMessage
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* @brief The PortInformation struct holds the information what kind of port we have here
|
||||
*/
|
||||
struct PortInformation
|
||||
{
|
||||
int32_t number;
|
||||
int32_t type;
|
||||
QString properties;
|
||||
};
|
||||
|
||||
/**
|
||||
* @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;
|
||||
};
|
||||
|
||||
explicit ServicePortsInformationMessage (const QVector<ExerciseInformation> &data, const QString &uuid);
|
||||
}; // class ServicePortsInformationMessage
|
||||
|
||||
} // namespace Messages
|
||||
} // namespace WebSocketInterface
|
||||
} // namespace ServiceManagement
|
||||
|
||||
@@ -0,0 +1,80 @@
|
||||
/**
|
||||
* @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 ServiceManagement
|
||||
{
|
||||
namespace WebSocketInterface
|
||||
{
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------
|
||||
DataManager::DataManager(MainHandler *mainHandler)
|
||||
: m_mainHandler(mainHandler)
|
||||
, m_logger(getLogger(QStringLiteral("DataManager")))
|
||||
{
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------
|
||||
bool DataManager::init()
|
||||
{
|
||||
m_groupHandler = m_mainHandler->groupHandler();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------
|
||||
LtsWebSocket::ReplyMessage *DataManager::servicesInformation(const QString &uuid) const
|
||||
{
|
||||
using namespace Messages;
|
||||
|
||||
const QVector<Group *> groups = m_groupHandler->groups();
|
||||
QVector<ServicePortsInformationMessage::ExerciseInformation> data;
|
||||
data.reserve(groups.size());
|
||||
for (auto group : groups)
|
||||
{
|
||||
const QMap<int, ServiceProcess *> serviceProcs = group->serviceProcs();
|
||||
ServicePortsInformationMessage::ExerciseInformation exerciseInfo;
|
||||
|
||||
for (ServiceProcess *service : serviceProcs)
|
||||
{
|
||||
if (service->ports().is_set())
|
||||
{
|
||||
ServicePortsInformationMessage::ServiceInformation serviceInfo;
|
||||
serviceInfo.name = service->serviceName();
|
||||
serviceInfo.abbreviation = service->abbreviation();
|
||||
|
||||
const auto ports = service->ports().get();
|
||||
for (const auto &port : ports)
|
||||
serviceInfo.ports.append(ServicePortsInformationMessage::PortInformation({port.number(), port.type().underlying(), QString::fromStdString(port.properties())}));
|
||||
|
||||
exerciseInfo.services.append(serviceInfo);
|
||||
}
|
||||
}
|
||||
|
||||
if (!exerciseInfo.services.isEmpty())
|
||||
{
|
||||
exerciseInfo.exerciseId = group->exercisePartitionId();
|
||||
exerciseInfo.replayPartitionId = group->replayPartitionId();
|
||||
data.append(exerciseInfo);
|
||||
}
|
||||
}
|
||||
|
||||
return new ServicePortsInformationMessage(data, uuid);
|
||||
}
|
||||
|
||||
} // namespace WebSocketInterface
|
||||
} // namespace ServiceManagement
|
||||
@@ -0,0 +1,51 @@
|
||||
/**
|
||||
* @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/reply_message.h"
|
||||
#include "logger.h"
|
||||
|
||||
namespace ServiceManagement
|
||||
{
|
||||
class MainHandler;
|
||||
class GroupHandler;
|
||||
|
||||
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 init Initialises a DataManager object
|
||||
* @return True on sucess, otherwise false
|
||||
*/
|
||||
bool init();
|
||||
|
||||
LtsWebSocket::ReplyMessage *servicesInformation(const QString &uuid) const;
|
||||
|
||||
private: // attributes
|
||||
MainHandler *m_mainHandler;
|
||||
std::shared_ptr <GroupHandler> m_groupHandler;
|
||||
|
||||
LOGGER_T m_logger;
|
||||
}; // class DataManager
|
||||
|
||||
} // namespace WebSocketInterface
|
||||
} // namespace ServiceManagement
|
||||
@@ -0,0 +1,41 @@
|
||||
/**
|
||||
* @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>
|
||||
|
||||
namespace ServiceManagement
|
||||
{
|
||||
namespace WebSocketInterface
|
||||
{
|
||||
/**
|
||||
* @brief Namespace which holds all occuring JSON keys as const QString objects
|
||||
*/
|
||||
namespace JsonKeys
|
||||
{
|
||||
// types for client --> server messages
|
||||
inline QString SERVICE_PORTS_INFORMATION_REQUEST() { return QStringLiteral("servicePortsInformationRequest"); }
|
||||
|
||||
// types for server --> client messages
|
||||
inline QString SERVICE_PORTS_INFORMATION() { return QStringLiteral("servicePortsInformation"); }
|
||||
|
||||
// data keys
|
||||
inline QString EXERCISE_ID() { return QStringLiteral("exerciseId"); }
|
||||
inline QString NAME() { return QStringLiteral("name"); }
|
||||
inline QString NAME_ABBR() { return QStringLiteral("nameAbbrevation"); }
|
||||
inline QString NUMBER() { return QStringLiteral("number"); }
|
||||
inline QString PORTS() { return QStringLiteral("ports"); }
|
||||
inline QString REPLAY_PARTITION_ID() { return QStringLiteral("replayPartitionId"); }
|
||||
inline QString SERVICES() { return QStringLiteral("services"); }
|
||||
inline QString TYPE_ID() { return QStringLiteral("typeId"); }
|
||||
inline QString PROPERTIES() { return QStringLiteral("properties"); }
|
||||
|
||||
} // namespace JsonKeys
|
||||
} // namespace WebSocketInterface
|
||||
} // namespace ServiceManagement
|
||||
+77
@@ -0,0 +1,77 @@
|
||||
/**
|
||||
* @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"
|
||||
#include <nglsettings/nglsettings_connections.h>
|
||||
|
||||
namespace ServiceManagement
|
||||
{
|
||||
namespace WebSocketInterface
|
||||
{
|
||||
|
||||
WebSocketInterfaceHandler::WebSocketInterfaceHandler(MainHandler *mainHandler, QObject *parent)
|
||||
: QObject(parent)
|
||||
, m_webSocketServer(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) << "... ok";
|
||||
|
||||
DEBUG_LOG(m_logger) << "Initialising DataManager";
|
||||
m_dataManager = new DataManager(m_mainHandler);
|
||||
if (!m_dataManager->init())
|
||||
{
|
||||
ERROR_LOG(m_logger) << "Failed to initialise DataManager";
|
||||
return false;
|
||||
}
|
||||
DEBUG_LOG(m_logger) << "... ok";
|
||||
|
||||
|
||||
m_messageFactory = new Messages::ClientMessageFactory(m_dataManager);
|
||||
|
||||
m_webSocketServer = new LtsWebSocket::LtsWebSocketServer(m_messageFactory, this);
|
||||
|
||||
DEBUG_LOG(m_logger) << "Initialising LtsWebSocketServer";
|
||||
if (!m_webSocketServer->init(QStringLiteral("SCM"), NGL::Connections::port(NGL::Connections::eConnection::SCM_WEBSOCKET)))
|
||||
{
|
||||
ERROR_LOG(m_logger) << "Failed to initialise LtsWebSocketServer";
|
||||
return false;
|
||||
}
|
||||
DEBUG_LOG(m_logger) << "... ok";
|
||||
|
||||
DEBUG_LOG(m_logger) << "Connection signals and slots";
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void WebSocketInterfaceHandler::cleanup()
|
||||
{
|
||||
delete m_webSocketServer;
|
||||
delete m_messageFactory;
|
||||
delete m_dataManager;
|
||||
}
|
||||
|
||||
} // namespace WebSocketInterface
|
||||
} // namespace ServiceManagement
|
||||
+69
@@ -0,0 +1,69 @@
|
||||
/**
|
||||
* @RDE_HEADER@
|
||||
* Handler for the WebSocket Interface
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
* Created by Philipp Dassow, SLST, 2017-12-05
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include <QtCore/QObject>
|
||||
|
||||
#include <LtsWebSocket/lts_web_socket_server.h>
|
||||
|
||||
#include "logger.h"
|
||||
|
||||
namespace ServiceManagement
|
||||
{
|
||||
class MainHandler;
|
||||
namespace WebSocketInterface
|
||||
{
|
||||
namespace Messages
|
||||
{
|
||||
class ClientMessageFactory;
|
||||
}
|
||||
class DataManager;
|
||||
|
||||
/**
|
||||
* @brief The WebSocketInterfaceHandler class is the main class for the WebSocketInterface
|
||||
*/
|
||||
class WebSocketInterfaceHandler final : public QObject
|
||||
{
|
||||
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 webSocketPort returns the listen port
|
||||
* @return listen port
|
||||
*/
|
||||
unsigned short webSocketPort() { return m_webSocketServer->webSocketPort(); }
|
||||
|
||||
private:
|
||||
void cleanup();
|
||||
|
||||
private:
|
||||
LtsWebSocket::LtsWebSocketServer *m_webSocketServer;
|
||||
Messages::ClientMessageFactory *m_messageFactory;
|
||||
DataManager *m_dataManager;
|
||||
MainHandler *m_mainHandler;
|
||||
LOGGER_T m_logger;
|
||||
}; // class WebSocketInterfaceHandle
|
||||
|
||||
} // namespace WebSocketInterface
|
||||
} // namespace ServiceManagement
|
||||
Reference in new issue
Block a user