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,409 @@
/**
* @RDE_HEADER@
* The ClientMessage class is an abstract base class for concrete ClientMessage objects
* $Id$
* $HeadURL$
* $Author$
* Created by Hannes Baeuerle, SLSE, 2016-08-25
*/
#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>
#include <QSet>
namespace InfrastructureManagement
{
namespace WebSocketInterface
{
namespace Messages
{
using namespace JsonKeys;
template <typename T>
static QJsonArray fillArray(const T &messages)
{
QJsonArray arr;
for (const auto &currentMsg : messages)
arr += currentMsg.json().value(LtsWebSocket::JsonKeys::DATA());
return arr;
}
// ####### 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 == OcBaseDownload::WebSocketInterface::JsonKeys::BASE_DL_REQUEST())
result = new BaseDlRequest(m_dataManager, client, m_type, m_typeId, m_uuid);
else if (m_type == GET_ASSETS())
result = new GetAssetsMessage(m_dataManager, client, m_type, m_typeId, m_uuid, m_data);
else if (m_type == GET_ASSET_STATE())
result = new GetAssetStateMessage(m_dataManager, client, m_type, m_typeId, m_uuid, m_data);
else if (m_type == GET_BUILDING_STATE())
result = new GetBuildingStateMessage(m_dataManager, client, m_type, m_typeId, m_uuid, m_data);
else if (m_type == GET_ESSENTIALS())
result = new GetEssentialsMessage(m_dataManager, client, m_type, m_typeId, m_uuid, m_data);
else if (m_type == GET_OBJECT_MOUNTING())
result = new GetObjectMountingMessage(m_dataManager, client, m_type, m_typeId, m_uuid, m_data);
else if (m_type == GET_PLANNED_MOUNTINGS())
result = new GetPlannedMountingsMessage(m_dataManager, client, m_type, m_typeId, m_uuid);
else if (m_type == MOUNT())
result = new MountMessage(m_dataManager, client, m_type, m_typeId, m_uuid, m_data);
else if (m_type == MOUNT_TAG())
result = new MountTagMessage(m_dataManager, client, m_type, m_typeId, m_uuid, m_data);
else if (m_type == OBJECT_MOUNTING_READY())
result = new ObjectMountingReadyMessage(m_dataManager, client, m_type, m_typeId, m_uuid, m_data);
else if (m_type == UNMOUNT_AREA())
result = new UnmountAreaMessage(m_dataManager, client, m_type, m_typeId, m_uuid, m_data);
else if (m_type == UNMOUNT_ASSET())
result = new UnmountAssetMessage(m_dataManager, client, m_type, m_typeId, m_uuid, m_data);
else if (m_type == UNMOUNT_MOUNTING_POINT())
result = new UnmountMountingPointMessage(m_dataManager, client, m_type, m_typeId, m_uuid, m_data);
else if (m_type == UNMOUNT_OBJECT())
result = new UnmountObjectMessage(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)
{}
// ####### ClientMessage end #######
// ####### GetAssetStateMessage begin #######
void GetAssetStateMessage::process()
{
m_client->addReply(m_dataManager->getAssetState(m_data.toObject().value(ASSET_ID()).toInt(),
m_data.toObject().value(ASSET_TAG()).toString(),
m_uuid));
}
bool GetAssetStateMessage::hasValidData() const
{
// one (exclusive) value has to be set
return ((!m_data.toObject().value(ASSET_ID()).isDouble() && m_data.toObject().value(ASSET_TAG()).isString()) ||
(m_data.toObject().value(ASSET_ID()).isDouble() && !m_data.toObject().value(ASSET_TAG()).isString()));
}
GetAssetStateMessage::GetAssetStateMessage(DataManager *dataManager, LtsWebSocket::ReplyHandler *client, const QString &type, const int typeId, const QString &uuid, const QJsonValue &data)
: ClientMessage(dataManager, client, type, typeId, uuid, data)
{
}
// ####### GetAssetStateMessage end #######
// ####### GetAssetStateMessage begin #######
void GetAssetsMessage::process()
{
const QJsonValue val = m_data.toObject().value(ASSET_TYPE_ID());
QSet<int> assetTypeIds;
if (val.isArray())
{
const QJsonArray ary = val.toArray();
assetTypeIds.reserve(ary.size());
for (const auto &ele : ary)
assetTypeIds += ele.toInt();
}
else
assetTypeIds += val.toInt();
m_client->addReply(m_dataManager->getAssets(assetTypeIds,
m_uuid));
}
bool GetAssetsMessage::hasValidData() const
{
const auto val = m_data.toObject().value(ASSET_TYPE_ID());
return val.isDouble() || val.isArray();
}
GetAssetsMessage::GetAssetsMessage(DataManager *dataManager, LtsWebSocket::ReplyHandler *client, const QString &type, const int typeId, const QString &uuid, const QJsonValue &data)
: ClientMessage(dataManager, client, type, typeId, uuid, data)
{
}
// ####### GetAssetStateMessage end #######
// ####### GetBuildingStateMessage begin #######
void GetBuildingStateMessage::process()
{
m_client->addReply(m_dataManager->getBuildingState(m_data.toObject().value(BUILDING_ID()).toInt(),
m_uuid));
}
bool GetBuildingStateMessage::hasValidData() const
{
return m_data.toObject().value(BUILDING_ID()).isDouble();
}
GetBuildingStateMessage::GetBuildingStateMessage(DataManager *dataManager, LtsWebSocket::ReplyHandler *client, const QString &type, const int typeId, const QString &uuid, const QJsonValue &data)
: ClientMessage(dataManager, client, type, typeId, uuid, data)
{
}
// ####### GetBuildingStateMessage end #######
class GetEssentialsReply final : public ReplyMessage
{
public:
GetEssentialsReply(const QJsonObject &obj, const QString &uuid)
: ReplyMessage(QStringLiteral("essentials"), 2, uuid) // Todo: Check whether typeId is correct
{
m_jsonRepresentation.insert(LtsWebSocket::JsonKeys::DATA(), obj);
}
};
// ####### GetEssentialsMessage begin #######
void GetEssentialsMessage::process()
{
const DataManager::EinruestEssentials data = m_dataManager->getEssentials(m_uuid);
QJsonObject obj;
obj[TRAINING_AREAS()] = fillArray(data.trainingAreas);
obj[AREAS()] = fillArray(data.areas);
obj[OBJECTS()] = fillArray(data.objects);
obj[LEVELS()] = fillArray(data.levels);
obj[ROOMS()] = fillArray(data.rooms);
obj[MOUNTING_POINTS()] = fillArray(data.mountingPoints);
obj[ASSET_TYPES()] = fillArray(data.assetTypes);
m_client->addReply(new GetEssentialsReply(obj, m_uuid));
}
bool GetEssentialsMessage::hasValidData() const
{
return true; // no data part to validate
}
GetEssentialsMessage::GetEssentialsMessage(DataManager *dataManager, LtsWebSocket::ReplyHandler *client, const QString &type, const int typeId, const QString &uuid, const QJsonValue &data)
: ClientMessage(dataManager, client, type, typeId, uuid, data)
{
}
// ####### GetEssentialsMessage end #######
// ####### GetPlannedMountingMessage begin #######
class PlannedMountingsReply final : public ReplyMessage
{
public:
PlannedMountingsReply(const QJsonArray &arr, const QString &uuid)
: ReplyMessage(QStringLiteral("plannedMountings"), 13, uuid) // Todo: Check whether typeId is correct
{
m_jsonRepresentation.insert(LtsWebSocket::JsonKeys::DATA(), arr);
}
};
void GetPlannedMountingsMessage::process()
{
const QVector<PlannedMountingMessage> plannedMountings = m_dataManager->getPlannedMounting(m_uuid);
m_client->addReply(new PlannedMountingsReply(fillArray(plannedMountings), m_uuid));
}
bool GetPlannedMountingsMessage::hasValidData() const
{
return true; // no data part to validate
}
GetPlannedMountingsMessage::GetPlannedMountingsMessage(DataManager *dataManager, LtsWebSocket::ReplyHandler *client, const QString &type, const int typeId, const QString &uuid)
: ClientMessage(dataManager, client, type, typeId, uuid)
{
}
// ####### GetPlannedMountingMessage end #######
// ####### GetObjectMountingMessage begin #######
void GetObjectMountingMessage::process()
{
m_client->addReply(m_dataManager->getObjectMounting(m_data.toObject().value(PLANNED_MOUNTING_ID()).toInt(),
m_data.toObject().value(OBJECT_ID()).toInt(),
m_uuid));
}
bool GetObjectMountingMessage::hasValidData() const
{
return m_data.toObject().value(PLANNED_MOUNTING_ID()).isDouble() &&
m_data.toObject().value(OBJECT_ID()).isDouble();
}
GetObjectMountingMessage::GetObjectMountingMessage(DataManager *dataManager, LtsWebSocket::ReplyHandler *client, const QString &type, const int typeId, const QString &uuid, const QJsonValue &data)
: ClientMessage(dataManager, client, type, typeId, uuid, data)
{
}
// ####### GetObjectMountingMessage end #######
// ####### MountMessage begin #######
void MountMessage::process()
{
m_client->addReply(m_dataManager->mount(m_data.toObject().value(MOUNTING_POINT_ID()).toInt(),
m_data.toObject().value(ASSET_ID()).toInt(),
m_type,
m_uuid));
}
bool MountMessage::hasValidData() const
{
return m_data.toObject().value(MOUNTING_POINT_ID()).isDouble() &&
m_data.toObject().value(ASSET_ID()).isDouble();
}
MountMessage::MountMessage(DataManager *dataManager, LtsWebSocket::ReplyHandler *client, const QString &type, const int typeId, const QString &uuid, const QJsonValue &data)
: ClientMessage(dataManager, client, type, typeId, uuid, data)
{
}
// ####### MountMessage end #######
// ####### MountTagMessage begin #######
void MountTagMessage::process()
{
m_client->addReply(m_dataManager->mountTag(m_data.toObject().value(MOUNTING_POINT_TAG()).toString(),
m_data.toObject().value(ASSET_TAG()).toString(),
m_type,
m_uuid));
}
bool MountTagMessage::hasValidData() const
{
// at least one
return m_data.toObject().value(ASSET_TAG()).isString() || m_data.toObject().value(MOUNTING_POINT_TAG()).isString();
}
MountTagMessage::MountTagMessage(DataManager *dataManager, LtsWebSocket::ReplyHandler *client, const QString &type, const int typeId, const QString &uuid, const QJsonValue &data)
: ClientMessage(dataManager, client, type, typeId, uuid, data)
{
}
// ####### MountTagMessage end #######
// ####### ObjectMountingReadyMessage begin #######
void ObjectMountingReadyMessage::process()
{
m_client->addReply(m_dataManager->objectMountingReady(m_data.toObject().value(PLANNED_MOUNTING_ID()).toInt(),
m_data.toObject().value(OBJECT_ID()).toInt(),
m_type,
m_uuid));
}
bool ObjectMountingReadyMessage::hasValidData() const
{
return m_data.toObject().value(PLANNED_MOUNTING_ID()).isDouble() &&
m_data.toObject().value(OBJECT_ID()).isDouble();
}
ObjectMountingReadyMessage::ObjectMountingReadyMessage(DataManager *dataManager, LtsWebSocket::ReplyHandler *client, const QString &type, const int typeId, const QString &uuid, const QJsonValue &data)
: ClientMessage(dataManager, client, type, typeId, uuid, data)
{
}
// ####### ObjectMountingReadyMessage end #######
// ####### UnmountAreaMessage begin #######
void UnmountAreaMessage::process()
{
m_client->addReply(m_dataManager->unmountArea(m_data.toObject().value(AREA_ID()).toInt(),
m_type,
m_uuid));
}
bool UnmountAreaMessage::hasValidData() const
{
return m_data.toObject().value(AREA_ID()).isDouble();
}
UnmountAreaMessage::UnmountAreaMessage(DataManager *dataManager, LtsWebSocket::ReplyHandler *client, const QString &type, const int typeId, const QString &uuid, const QJsonValue &data)
: ClientMessage(dataManager, client, type, typeId, uuid, data)
{
}
// ####### UnmountAreaMessage end #######
// ####### UnmountAssetMessage begin #######
void UnmountAssetMessage::process()
{
m_client->addReply(m_dataManager->unmountAsset(m_data.toObject().value(ASSET_ID()).toInt(),
m_type,
m_uuid));
}
bool UnmountAssetMessage::hasValidData() const
{
return m_data.toObject().value(ASSET_ID()).isDouble();
}
UnmountAssetMessage::UnmountAssetMessage(DataManager *dataManager, LtsWebSocket::ReplyHandler *client, const QString &type, const int typeId, const QString &uuid, const QJsonValue &data)
: ClientMessage(dataManager, client, type, typeId, uuid, data)
{
}
// ####### UnmountAssetMessage end #######
// ####### UnmountMountingPointMessage begin #######
void UnmountMountingPointMessage::process()
{
m_client->addReply(m_dataManager->unmountMountingPoint(m_data.toObject().value(MOUNTING_POINT_ID()).toInt(),
m_type,
m_uuid));
}
bool UnmountMountingPointMessage::hasValidData() const
{
return m_data.toObject().value(MOUNTING_POINT_ID()).isDouble();
}
UnmountMountingPointMessage::UnmountMountingPointMessage(DataManager *dataManager, LtsWebSocket::ReplyHandler *client, const QString &type, const int typeId, const QString &uuid, const QJsonValue &data)
: ClientMessage(dataManager, client, type, typeId, uuid, data)
{
}
// ####### UnmountMountingPointMessage end #######
// ####### UnmountObjectMessage begin #######
void UnmountObjectMessage::process()
{
m_client->addReply(m_dataManager->unmountObject(m_data.toObject().value(OBJECT_ID()).toInt(),
m_type,
m_uuid));
}
bool UnmountObjectMessage::hasValidData() const
{
return m_data.toObject().value(OBJECT_ID()).isDouble();
}
UnmountObjectMessage::UnmountObjectMessage(DataManager *dataManager, LtsWebSocket::ReplyHandler *client, const QString &type, const int typeId, const QString &uuid, const QJsonValue &data)
: ClientMessage(dataManager, client, type, typeId, uuid, data)
{
}
// ####### UnmountObjectMessage end #######
// ####### BaseDlRequest begin #######
BaseDlRequest::BaseDlRequest(DataManager *dataManager, LtsWebSocket::ReplyHandler *client, const QString &type, const int typeId, const QString &uuid)
: ClientMessage(dataManager, client, type, typeId, uuid)
{}
void BaseDlRequest::process()
{
m_client->addReply(m_dataManager->assetBaseData(m_uuid));
m_client->addReply(m_dataManager->mainStructureElementBaseData(m_uuid));
m_client->addReply(m_dataManager->structureElementBaseData(m_uuid));
m_client->addReply(m_dataManager->structureElementFootprintBaseData(m_uuid));
m_client->addReply(m_dataManager->mountingPointAssetBaseData(m_uuid));
m_client->addReply(m_dataManager->mountingPointScheduleBaseData(m_uuid));
m_client->addReply(m_dataManager->mountingPointPlanBaseData(m_uuid));
}
bool BaseDlRequest::hasValidData() const
{
return true;
}
// ####### BaseDlRequest end #######
} // namespace Messages
} // namespace WebSocketInterface
} // namespace Infrastrukture Management
@@ -0,0 +1,211 @@
/**
* @RDE_HEADER@
* The ClientMessage class is an abstract base class for concrete ClientMessage objects
* $Id$
* $HeadURL$
* $Author$
* Created by Hannes Baeuerle, SLSE, 2016-08-25
*/
#pragma once
#include <QtCore/QJsonObject>
#include <LtsWebSocket/client_message_factory.h>
#include <LtsWebSocket/client_message.h>
#include "logger.h"
namespace InfrastructureManagement
{
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
// the following classes are concrete implementation classes of ClientMessage
/**
* @brief The GetAssetStateMessage class represents the appropriate telegram
*/
class GetAssetStateMessage final : public ClientMessage
{
public:
explicit GetAssetStateMessage(DataManager *dataManager, LtsWebSocket::ReplyHandler *client, const QString &type, const int typeId, const QString &uuid, const QJsonValue &data);
void process() override;
bool hasValidData() const override;
}; // class AssetStateMessage
/**
* @brief Retrieve all assets for the given asset type
*/
class GetAssetsMessage final : public ClientMessage
{
public:
GetAssetsMessage(DataManager *dataManager, LtsWebSocket::ReplyHandler *client, const QString &type, const int typeId, const QString &uuid, const QJsonValue &data);
void process() override;
bool hasValidData() const override;
}; // class GetAssetsMessage
/**
* @brief The GetBuildingStateMessage class represents the appropriate telegram
*/
class GetBuildingStateMessage final : public ClientMessage
{
public:
explicit GetBuildingStateMessage(DataManager *dataManager, LtsWebSocket::ReplyHandler *client, const QString &type, const int typeId, const QString &uuid, const QJsonValue &data);
void process() override;
bool hasValidData() const override;
}; // class GetBuildingStateMessage
/**
* @brief The GetEssentialsMessage class represents the appropriate telegram
*/
class GetEssentialsMessage final : public ClientMessage
{
public:
explicit GetEssentialsMessage(DataManager *dataManager, LtsWebSocket::ReplyHandler *client, const QString &type, const int typeId, const QString &uuid, const QJsonValue &data);
void process() override;
bool hasValidData() const override;
}; // class GetEssentialsMessage
/**
* @brief The GetPlannedMountingMessage class represents the appropriate telegram
*/
class GetPlannedMountingsMessage final : public ClientMessage
{
public:
explicit GetPlannedMountingsMessage(DataManager *dataManager, LtsWebSocket::ReplyHandler *client, const QString &type, const int typeId, const QString &uuid);
void process() override;
bool hasValidData() const override;
}; // class GetPlannedMountingMessage
/**
* @brief The GetObjectMountingMessage class represents the appropriate telegram
*/
class GetObjectMountingMessage final : public ClientMessage
{
public:
explicit GetObjectMountingMessage(DataManager *dataManager, LtsWebSocket::ReplyHandler *client, const QString &type, const int typeId, const QString &uuid, const QJsonValue &data);
void process() override;
bool hasValidData() const override;
}; // class GetObjectMountingMessage
/**
* @brief The MountMessage class represents the appropriate telegram
*/
class MountMessage final : public ClientMessage
{
public:
explicit MountMessage(DataManager *dataManager, LtsWebSocket::ReplyHandler *client, const QString &type, const int typeId, const QString &uuid, const QJsonValue &data);
void process() override;
bool hasValidData() const override;
}; // class MountMessage
/**
* @brief The MountTagMessage class represents the appropriate telegram
*/
class MountTagMessage final : public ClientMessage
{
public:
explicit MountTagMessage(DataManager *dataManager, LtsWebSocket::ReplyHandler *client, const QString &type, const int typeId, const QString &uuid, const QJsonValue &data);
void process() override;
bool hasValidData() const override;
}; // class MountTagMessage
/**
* @brief The ObjectMountingReadyMessage class represents the appropriate telegram
*/
class ObjectMountingReadyMessage final : public ClientMessage
{
public:
ObjectMountingReadyMessage(DataManager *dataManager, LtsWebSocket::ReplyHandler *client, const QString &type, const int typeId, const QString &uuid, const QJsonValue &data);
void process() override;
bool hasValidData() const override;
}; // class ObjectMountingReadyMessage
/**
* @brief The UnmountAreaMessage class represents the appropriate telegram
*/
class UnmountAreaMessage final : public ClientMessage
{
public:
explicit UnmountAreaMessage(DataManager *dataManager, LtsWebSocket::ReplyHandler *client, const QString &type, const int typeId, const QString &uuid, const QJsonValue &data);
void process() override;
bool hasValidData() const override;
}; // class UnmountAreaMessage
/**
* @brief The UnmountAssetMessage class represents the appropriate telegram
*/
class UnmountAssetMessage final : public ClientMessage
{
public:
explicit UnmountAssetMessage(DataManager *dataManager, LtsWebSocket::ReplyHandler *client, const QString &type, const int typeId, const QString &uuid, const QJsonValue &data);
void process() override;
bool hasValidData() const override;
}; // class UnmountAssetMessage
class UnmountMountingPointMessage final : public ClientMessage
{
public:
explicit UnmountMountingPointMessage(DataManager *dataManager, LtsWebSocket::ReplyHandler *client, const QString &type, const int typeId, const QString &uuid, const QJsonValue &data);
void process() override;
bool hasValidData() const override;
}; // class UnmountMountingPointMessage
class UnmountObjectMessage final : public ClientMessage
{
public:
explicit UnmountObjectMessage(DataManager *dataManager, LtsWebSocket::ReplyHandler *client, const QString &type, const int typeId, const QString &uuid, const QJsonValue &data);
void process() override;
bool hasValidData() const override;
}; // class UnmountObjectMessage
/**
* @brief The BaseDlRequest class handles the base DL request and sends multiple replys depending on the data requested
*/
class BaseDlRequest : public ClientMessage
{
public:
explicit BaseDlRequest(DataManager *dataManager, LtsWebSocket::ReplyHandler *client, const QString &type, const int typeId, const QString &uuid);
void process();
bool hasValidData() const;
}; // class BaseDlRequest
} // namespace Messages
} // namespace WebSocketInterface
} // namespace InfrastructureManagement
@@ -0,0 +1,329 @@
/**
* @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 Baeuerle, SLSE, 2016-08-25
*/
#include "reply_message.h"
#include <LtsWebSocket/json_keys.h>
#include "WebSocketInterface/json_keys.h"
#include <QtCore/QUuid>
#include <QtCore/QJsonDocument>
namespace InfrastructureManagement
{
namespace WebSocketInterface
{
namespace Messages
{
using namespace JsonKeys;
using namespace LtsWebSocket::JsonKeys;
// ####### ReplyMessage begin #######
QJsonObject ReplyMessage::LonLatPoint::toJSon() const
{
return {{LONGITUDE(), lon}, {LATITUDE(), lat}};
}
QJsonObject ReplyMessage::Point3d::toJSon() const
{
return {{X(), x}, {Y(), y}, {Z(), z}};
}
QJsonObject ReplyMessage::XYPoint::toJSon() const
{
return {{X(), x}, {Y(), y}};
}
ReplyMessage::ReplyMessage(const QString &type, const int typeId, const QString &uuid)
: LtsWebSocket::ReplyMessage(type, typeId, uuid)
{}
// ####### ReplyMessage end #######
// ####### OkMessage begin #######
OkMessage::OkMessage(const OkMessage::OkData &data)
: ReplyMessage(OK(), 1, QString()) // Todo: Check whether typeId is correct
{
m_jsonRepresentation.insert(DATA(),
QJsonObject({{UUID_(), data.uuid},
{MESSAGE_TYPE(), data.messageType},
{INFO(), data.info}
}));
}
// ####### OkMessage end #######
// ####### RoomMessage begin #######
RoomMessage::RoomMessage(const RoomMessage::RoomData &data, const QString &uuid)
: ReplyMessage(ROOM(), 3, uuid) // Todo: Check whether typeId is correct
{
m_jsonRepresentation.insert(DATA(),
QJsonObject({{PATH(), vecToPath(data.path)},
{ID(), data.id},
{DESIGNATION(), data.designation},
{LEVEL_ID(), data.levelId}
}));
}
// ####### RoomMessage end #######
// ####### AssetData begin #######
QJsonObject AssetData::toJsonObject() const
{
return QJsonObject(
{
{ID(), id},
{ERROR_DESCRIPTION(), errorDescription},
{TIME(), time},
{STATE(), state},
{IP_ADDRESS(), hostname}, // TODO: Fix ICD
{MOUNTING_POINT_ID(), mountingPointId},
{ASSET_TYPE_ID(), assetTypeId},
{ASSET_TAG(), assetTag},
{DESIGNATION(), designation}
});
}
// ####### AssetData end #######
// ####### AreaMessage begin #######
AreaMessage::AreaMessage(const AreaMessage::AreaData &data, const QString &uuid)
: ReplyMessage(AREA(), 4, uuid) // Todo: Check whether typeId is correct
{
m_jsonRepresentation.insert(DATA(),
QJsonObject({{PATH(), vecToPath(data.path)},
{ID(), data.id},
{DESIGNATION(), data.designation},
{TRAINING_AREA_ID(), data.trainingAreaId}
}));
}
// ####### AreaMessage end #######
// ####### AssetStateMessage begin #######
AssetStateMessage::AssetStateMessage(const AssetData &data, const QString &uuid)
: ReplyMessage(ASSET_STATE(), 5, uuid) // Todo: Check whether typeId is correct
{
m_jsonRepresentation.insert(DATA(), {data.toJsonObject()});
}
// ####### AssetStateMessage end #######
// ####### AssetStateMessage begin #######
AssetsMessage::AssetsMessage(const QVector<AssetData> &data,
const QString &uuid)
: ReplyMessage(ASSETS(), 6, uuid) // Todo: Check whether typeId is correct
{
QJsonArray arr;
for (const AssetData &ad : data)
arr += ad.toJsonObject();
m_jsonRepresentation.insert(DATA(), arr);
}
// ####### AssetStateMessage end #######
// ####### AssetStateObjectMessage begin #######
AssetStateObjectMessage::AssetStateObjectMessage(const AssetStateObjectMessage::AssetStateObjectData &data, const QString &uuid)
: ReplyMessage(ASSET_STATE_OBJECT(), 7, uuid) // Todo: Check whether typeId is correct
{
QJsonArray assetStates;
for (const AssetStatesEntry &currentEntry : data.assetStates)
assetStates.append(QJsonObject({{MOUNTING_POINT_ID(), currentEntry.mountingPointId},
{ASSET_ID(), currentEntry.assetId},
{ASSET_TYPE_ID(), currentEntry.assetTypeId},
{IP_ADDRESS(), currentEntry.hostname}, // TODO: Fix ICD
{STATE(), currentEntry.state}
}));
m_jsonRepresentation.insert(DATA(), QJsonObject({{ASSET_STATES(), assetStates},
{OBJECT_ID(), data.objectId},
{TIME(), data.time}
}));
}
// ####### AssetStateObjectMessage end #######
// ####### AssetTypeMessage begin #######
AssetTypeMessage::AssetTypeMessage(const AssetTypeMessage::AssetTypeData &data, const QString &uuid)
: ReplyMessage(ASSET_TYPE(), 8, uuid) // Todo: Check whether typeId is correct
{
m_jsonRepresentation.insert(DATA(), QJsonObject({{ID(), data.id},
{DESIGNATION(), data.designation},
{DEVICE_CLASS(), data.deviceClass}
}));
}
// ####### AssetTypeMessage end #######
// ####### LevelMessage end #######
LevelMessage::LevelMessage(const LevelMessage::LevelData &data, const QString &uuid)
: ReplyMessage(LEVEL(), 9, uuid) // Todo: Check whether typeId is correct
{
m_jsonRepresentation.insert(DATA(), QJsonObject({{Z_POSITION(), data.zPos},
{NUMBER(), data.number},
{OBJECT_ID(), data.objectid},
{DESIGNATION(), data.designation},
{ID(), data.id},
{PATH(), vecToPath(data.path)}
}));
}
// ####### LevelMessage end #######
// ####### MountingPointMessage begin #######
MountingPointMessage::MountingPointMessage(const MountingPointMessage::MountingPointData &data, const QString &uuid)
: ReplyMessage(MOUNTING_POINT(), 10, uuid) // Todo: Check whether typeId is correct
{
QJsonArray supportedAssetTypeIds;
for (int currentId : data.supportedAssetTypIds)
supportedAssetTypeIds.append(currentId);
m_jsonRepresentation.insert(DATA(), QJsonObject({{SUPPORTED_ASSET_TYPE_IDS(), supportedAssetTypeIds},
{POSITION_3D(), data.position3d.toJSon()},
{ID(), data.id},
{DESIGNATION(), data.designation},
{TAG(), data.tag},
{OBJECT_ID(), data.objectId},
{LEVEL_ID(), data.levelId},
{ROOM_ID(), data.roomId},
{ASSET_ID(), data.assetId}
}));
}
// ####### MountingPointMessage end #######
// ####### ObjectMessage begin #######
ObjectMessage::ObjectMessage(const ObjectMessage::ObjectMessageData &data, const QString &uuid)
: ReplyMessage(OBJECT(), 11, uuid) // Todo: Check whether typeId is correct
{
m_jsonRepresentation.insert(DATA(), QJsonObject({{NUMBER(), data.number},
{STREET(), data.street},
{AREA_ID(), data.areaId},
{DESIGNATION(), data.designation},
{ID(), data.id},
{MSE_ID(), data.mseId},
{REF_POINT(), data.refPoint.toJSon()},
{Z(), data.z},
{ROTATION_DEGREE(), data.rotationDegree},
{PATH(), vecToPath(data.path)},
{PATH_RELATIVE(), vecToPath(data.pathRelative)}
}));
}
// ####### ObjectMessage end #######
// ####### ObjectMountingMessage begin #######
ObjectMountingMessage::ObjectMountingMessage(const ObjectMountingMessage::ObjectMountingData &data, const QString &uuid)
: ReplyMessage(OBJECT_MOUNTING(), 12, uuid) // Todo: Check whether typeId is correct
{
QJsonArray planned;
for (const PlannedEntry &currentEntry : data.planned)
planned.append(QJsonObject({{ID(), currentEntry.id},
{ASSET_ID(), currentEntry.assetId},
{PLANNING_STATE(), currentEntry.planningState}
}));
m_jsonRepresentation.insert(DATA(), QJsonObject({{PLANNED(), planned},
{PLANNED_MOUNTING_ID(), data.plannedMountingId},
{OBJECT_ID(), data.objectId}
}));
}
// ####### ObjectMountingMessage end #######
// ####### PlannedMountingMessage begin #######
PlannedMountingMessage::PlannedMountingMessage(const PlannedMountingMessage::PlannedMountingData &data, const QString &uuid)
: ReplyMessage(PLANNED_MOUNTING(), 13, uuid) // Todo: Check whether typeId is correct
{
QJsonArray mounting;
for (const MountingEntry &currentEntry : data.mounting)
mounting.append(QJsonObject({{ID(), currentEntry.id},
{STATE(), currentEntry.state}
}));
m_jsonRepresentation.insert(DATA(), QJsonObject({{MOUNTING(), mounting},
{PLANNED_MOUNTING_ID(), data.plannedMountingId},
{DESIGNATION(), data.designation},
{AREA_ID(), data.areaId}
}));
}
// ####### PlannedMountingMessage end #######
// ####### TrainingAreaMessage begin #######
TrainingAreaMessage::TrainingAreaMessage(const TrainingAreaMessage::TrainingAreaData &data, const QString &uuid)
: ReplyMessage(TRAINING_AREA(), 14, uuid) // Todo: Check whether typeId is correct
{
m_jsonRepresentation.insert(DATA(), QJsonObject({{PATH(), vecToPath(data.path)},
{ID(), data.id},
{DESIGNATION(), data.designation}
}));
}
// ####### TrainingAreaMessage end #######
// ######################### base DL messages #########################
// ####### AssetBaseData begin #######
AssetBaseData::AssetBaseData(const QJsonArray &data, const QString &uuid)
: LtsWebSocket::ReplyMessage (ISM_ASSET_BASE_DATA(), 15, uuid) // Todo: Check whether typeId is correct
{
m_jsonRepresentation.insert(DATA(), data);
}
// ####### AssetBaseData end #######
// ####### MainStructureElementBaseData begin #######
MainStructureElementBaseData::MainStructureElementBaseData(const QJsonArray &data, const QString &uuid)
: LtsWebSocket::ReplyMessage (MAIN_STRUCTURE_ELEMENT_BASE_DATA(), 16, uuid) // Todo: Check whether typeId is correct
{
m_jsonRepresentation.insert(DATA(), data);
}
// ####### MainStructureElementBaseData end #######
// ####### VulnerabilityModelDataBaseData begin #######
VulnerabilityModelDataBaseData::VulnerabilityModelDataBaseData(const QJsonArray &data, const QString &uuid)
: LtsWebSocket::ReplyMessage (VULNERABILITY_MODEL_DATA_BASE_DATA(), 17, uuid) // Todo: Check whether typeId is correct
{
m_jsonRepresentation.insert(DATA(), data);
}
// ####### VulnerabilityModelDataBaseData end #######
// ####### StructureElementBaseData begin #######
StructureElementBaseData::StructureElementBaseData(const QJsonArray &data, const QString &uuid)
: LtsWebSocket::ReplyMessage (STRUCTURE_ELEMENT_BASE_DATA(), 18, uuid) // Todo: Check whether typeId is correct
{
m_jsonRepresentation.insert(DATA(), data);
}
// ####### StructureElementBaseData end #######
// ####### StructureElementFootprintBaseData begin #######
StructureElementFootprintBaseData::StructureElementFootprintBaseData(const QJsonArray &data, const QString &uuid)
: LtsWebSocket::ReplyMessage (STRUCTURE_ELEMENT_FOOTPRINT_BASE_DATA(), 19, uuid) // Todo: Check whether typeId is correct
{
m_jsonRepresentation.insert(DATA(), data);
}
// ####### StructureElementFootprintBaseData end #######
// ####### MountingPointAssetBaseData begin #######
MountingPointAssetBaseData::MountingPointAssetBaseData(const QJsonArray &data, const QString &uuid)
: LtsWebSocket::ReplyMessage (MOUNTING_POINT_ASSET_BASE_DATA(), 20, uuid) // Todo: Check whether typeId is correct
{
m_jsonRepresentation.insert(DATA(), data);
}
// ####### MountingPointAssetBaseData end #######
// ####### MountingPointPlanBaseData begin #######
MountingPointPlanBaseData::MountingPointPlanBaseData(const QJsonArray &data, const QString &uuid)
: LtsWebSocket::ReplyMessage (MOUNTING_POINT_PLAN_BASE_DATA(), 21, uuid) // Todo: Check whether typeId is correct
{
m_jsonRepresentation.insert(DATA(), data);
}
// ####### MountingPointPlanBaseData end #######
// ####### MountingPointScheduleBaseData begin #######
MountingPointScheduleBaseData::MountingPointScheduleBaseData(const QJsonArray &data, const QString &uuid)
: LtsWebSocket::ReplyMessage (MOUNTING_POINT_SCHEDULE_BASE_DATA(), 22, uuid) // Todo: Check whether typeId is correct
{
m_jsonRepresentation.insert(DATA(), data);
}
// ####### MountingPointScheduleBaseData end #######
} // namespace Messages
} // namespace WebSocketInterface
} // namespace Infrastrukture Management
@@ -0,0 +1,534 @@
/**
* @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 Baeuerle, SLSE, 2016-08-25
*/
#pragma once
#include <LtsWebSocket/client_message_factory.h>
#include <QtCore/QVector>
#include <QtCore/QJsonObject>
#include <QtCore/QJsonArray>
namespace InfrastructureManagement
{
namespace WebSocketInterface
{
namespace Messages
{
/**
* @brief The ReplyMessage class is an abstract base class for all possible messages
* which are sent to the client
*/
class ReplyMessage : public LtsWebSocket::ReplyMessage
{
public:
/**
* @brief The LonLatPoint struct represents a point in any data part which has lon lat
*/
struct LonLatPoint
{
double lon = 0.;
double lat = 0.;
QJsonObject toJSon() const;
};
/**
* @brief The Point3d struct represents a 3D point in any data part which needs it
*/
struct Point3d
{
double x = 0.;
double y = 0.;
double z = 0.;
QJsonObject toJSon() const;
};
/**
* @brief The XYPoint struct represents a 2D point in any data part which needs it
*/
struct XYPoint
{
double x = 0.;
double y = 0.;
QJsonObject toJSon() const;
};
ReplyMessage() = default;
/**
* @brief ~ReplyMessage Destructor
*/
virtual ~ReplyMessage() = default;
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 int typeId, const QString &uuid);
}; // class Reply Message
/**
* @brief The AreaMessage class represents an area
*/
class AreaMessage final
: public ReplyMessage
{
public:
/**
* @brief The AreaData struct represents the data part of an AreaMessage object
*/
struct AreaData
{
int id = 0;
int trainingAreaId = 0;
QString designation;
QVector<LonLatPoint> path;
};
/**
* @brief AreaMessage Constructor
* @param data Data part of an AreaMessage object
*/
AreaMessage(const AreaData &data, const QString &uuid);
AreaMessage() = default;
}; // class AreaMessage
/**
* @brief The AssetStateData struct represents the data part of an AssetStateMessage(/AssetsMessage object
*/
struct AssetData
{
int id = 0;
int assetTypeId = 0;
int mountingPointId = 0;
QString assetTag;
QString designation;
QString hostname; // Hostname
QString state;
QString time; // "DD.MM.JJ hh:mm"
QString errorDescription;
QJsonObject toJsonObject() const;
};
/**
* @brief The AssetStateMessage class represents an asset state
*/
class AssetStateMessage final
: public ReplyMessage
{
public:
/**
* @brief AssetStateMessage Constructor
* @param data Data part of an AssetStateMessage object
*/
explicit AssetStateMessage(const AssetData &data, const QString &uuid);
}; // class AssetStateMessage
/**
* @brief The AssetStateMessage class represents an asset state
*/
class AssetsMessage final
: public ReplyMessage
{
public:
/**
* @brief AssetStateMessage Constructor
* @param data Data part of an AssetStateMessage object
*/
explicit AssetsMessage(const QVector<AssetData> &data, const QString &uuid);
}; // class AssetStateMessage
/**
* @brief The AssetStateObjectMessage class includes data which represents the states of all
* assets in a specific object
*/
class AssetStateObjectMessage final
: public ReplyMessage
{
public:
/**
* @brief The AssetStatesEntry struct represents an entry in AssetStateObjectData.assetStates
*/
struct AssetStatesEntry
{
int assetId = 0;
int assetTypeId = 0;
int mountingPointId = 0;
QString hostname;
QString state;
};
/**
* @brief The AssetStateObjectData struct represents the data part of an AssetStateObjectMessage object
*/
struct AssetStateObjectData
{
int objectId = 0;
QString time; // "DD.MM.JJ hh:mm"
QVector<AssetStatesEntry> assetStates;
};
/**
* @brief AssetStateObjectMessage Constructor
* @param data Data part of an AssetStateObjectMessage object
*/
explicit AssetStateObjectMessage(const AssetStateObjectData &data, const QString &uuid);
}; // class AssetStateObjectMessage
/**
* @brief The AssetTypeMessage class represents an asset type
*/
class AssetTypeMessage final
: public ReplyMessage
{
public:
/**
* @brief The AssetTypeData struct represents the data part of an AssetStateObjectMessage object
*/
struct AssetTypeData
{
int id = 0;
int deviceClass = 0;
QString designation;
};
/**
* @brief AssetTypeMessage Construcor
* @param data Data part of an AssetTypeMessage object
*/
AssetTypeMessage(const AssetTypeData &data, const QString &uuid);
AssetTypeMessage() = default;
}; // class AssetTypeMessage
/**
* @brief The LevelMessage class represents a level
*/
class LevelMessage final
: public ReplyMessage
{
public:
/**
* @brief The LevelData struct represents the data part of an LevelMessage object
*/
struct LevelData
{
int id = 0;
int objectid = 0;
int number = 0;
double zPos = 0;
QString designation;
QVector<XYPoint> path;
};
/**
* @brief LevelMessage Constructor
* @param data Data part of an LevelMessage object
*/
LevelMessage(const LevelData &data, const QString &uuid);
LevelMessage() = default;
}; // class LevelMessage
/**
* @brief The MountingPointMessage class represents a mounting point
*/
class MountingPointMessage final
: public ReplyMessage
{
public:
/**
* @brief The MountingPointData struct represents the data part of an MountingPointMessage object
*/
struct MountingPointData
{
int id = 0;
int objectId = 0;
int levelId = 0;
int roomId = 0;
int assetId = 0;
QString tag;
QString designation;
Point3d position3d;
QVector<int> supportedAssetTypIds;
};
/**
* @brief MountingPointMessage Constructor
* @param data Data part of an MountingPointMessage object
*/
MountingPointMessage(const MountingPointData &data, const QString &uuid);
MountingPointMessage() = default;
}; // class MountingPointMessage
/**
* @brief The ObjectMessage class represents an object
*/
class ObjectMessage final
: public ReplyMessage
{
public:
/**
* @brief The ObjectMessageData struct represents the data part of an ObjectMessage object
*/
struct ObjectMessageData
{
int id = 0;
int areaId = 0;
int mseId = 0; //!< not part of ICD but needed for our tools
QString number;
QString designation;
LonLatPoint refPoint;
double z; // aboveMsl
double rotationDegree;
QString street;
QVector<LonLatPoint> path;
QVector<XYPoint> pathRelative;
};
/**
* @brief ObjectMessage Constructor
* @param data Data part of an ObjectMessage object
*/
ObjectMessage(const ObjectMessageData &data, const QString &uuid);
ObjectMessage() = default;
}; // class ObjectMessage
/**
* @brief The ObjectMountingMessage class represents an object mounting plan
*/
class ObjectMountingMessage final
: public ReplyMessage
{
public:
/**
* @brief The PlannedEntry struct represents an entry in ObjectMountingData.planned
*/
struct PlannedEntry
{
int id = 0;
int assetId = 0;
int planningState = 0;
};
/**
* @brief The ObjectMountingData struct represents the data part of an ObjectMountingMessage object
*/
struct ObjectMountingData
{
int objectId = 0;
int plannedMountingId = 0;
QVector<PlannedEntry> planned;
};
/**
* @brief ObjectMountingMessage Constructor
* @param data Data part of an ObjectMountingMessage object
*/
explicit ObjectMountingMessage(const ObjectMountingData &data, const QString &uuid);
}; // class ObjectMountingMessage
/**
* @brief The OkMessage is sent when a message from a client does not need
* any concrete response and eveything is fine
*/
class OkMessage final
: public ReplyMessage
{
public:
/**
* @brief The OkData struct represents the data part of an OkMessage object
*/
struct OkData
{
QString uuid;
QString messageType;
QString info;
};
/**
* @brief OkMessage Constructor
* @param data Data part of an OkMessage object
*/
explicit OkMessage(const OkData &data);
}; // class OkMessage
/**
* @brief The PlannedMountingMessage class represents a mounting plan
*/
class PlannedMountingMessage final
: public ReplyMessage
{
public:
/**
* @brief The MountingEntry struct represents an entry in PlannedMountingData.mounting
*/
struct MountingEntry
{
int id = 0;
int state = 0;
};
/**
* @brief The PlannedMountingData struct represents the data part of an PlannedMountingMessage object
*/
struct PlannedMountingData
{
int areaId = 0;
int plannedMountingId = 0;
QString designation;
QVector<MountingEntry> mounting;
};
/**
* @brief PlannedMountingMessage Constructor
* @param data Data part of an PlannedMountingMessage object
*/
PlannedMountingMessage(const PlannedMountingData &data, const QString &uuid);
PlannedMountingMessage() = default;
}; // class PlannedMountingMessage
/**
* @brief The RoomMessage class represents a room
*/
class RoomMessage final
: public ReplyMessage
{
public:
/**
* @brief The RoomData struct represents the data part of an RoomMessage object
*/
struct RoomData
{
int id = 0;
int levelId = 0;
QString designation;
QVector<XYPoint> path;
};
/**
* @brief RoomMessage Constructor
* @param data Data part of an RoomMessage object
*/
RoomMessage(const RoomData &data, const QString &uuid);
RoomMessage() = default;
}; // RoomMessage
/**
* @brief The TrainingAreaMessage class represents a training area
*/
class TrainingAreaMessage final
: public ReplyMessage
{
public:
/**
* @brief The TrainingAreaData struct represents the data part of an TrainingAreaMessage object
*/
struct TrainingAreaData
{
int id = 0;
QString designation;
QVector<LonLatPoint> path;
};
/**
* @brief TrainingAreaMessage Constructor
* @param data Data part of an TrainingAreaMessage object
*/
explicit TrainingAreaMessage(const TrainingAreaData &data, const QString &uuid);
TrainingAreaMessage() = default;
}; // class TrainingAreaMessage
// ######################### base DL messages #########################
/**
* @brief The AssetBaseData class asset data for base DL
*/
class AssetBaseData : public LtsWebSocket::ReplyMessage
{
public:
explicit AssetBaseData(const QJsonArray &data, const QString &uuid);
}; // class AssetBaseData
/**
* @brief The MainStructureElementBaseData class main structure element data for base DL
*/
class MainStructureElementBaseData : public LtsWebSocket::ReplyMessage
{
public:
explicit MainStructureElementBaseData(const QJsonArray &data, const QString &uuid);
}; // class MainStructureElementBaseData
/**
* @brief The VulnerabilityModelDataBaseData class vulnerability model data for base DL
*/
class VulnerabilityModelDataBaseData : public LtsWebSocket::ReplyMessage
{
public:
explicit VulnerabilityModelDataBaseData(const QJsonArray &data, const QString &uuid);
}; // class VulnerabilityModelDataBaseData
/**
* @brief The StructureElementBaseData class structure element data for base DL
*/
class StructureElementBaseData : public LtsWebSocket::ReplyMessage
{
public:
explicit StructureElementBaseData(const QJsonArray &data, const QString &uuid);
}; // class StructureElementBaseData
/**
* @brief The StructureElementFootprintBaseData class structure element footprint data for base DL
*/
class StructureElementFootprintBaseData : public LtsWebSocket::ReplyMessage
{
public:
explicit StructureElementFootprintBaseData(const QJsonArray &data, const QString &uuid);
}; // class StructureElementFootprintBaseData
/**
* @brief The MountingPointAssetBaseData class mounting point asset data for base DL
*/
class MountingPointAssetBaseData : public LtsWebSocket::ReplyMessage
{
public:
explicit MountingPointAssetBaseData(const QJsonArray &data, const QString &uuid);
}; // class MountingPointAssetBaseData
/**
* @brief The MountingPointScheduleBaseData class mounting point schedule data for base DL
*/
class MountingPointScheduleBaseData : public LtsWebSocket::ReplyMessage
{
public:
explicit MountingPointScheduleBaseData(const QJsonArray &data, const QString &uuid);
}; // class MountingPointScheduleBaseData
/**
* @brief The MountingPointPlanBaseData class mounting point plan data for base DL
*/
class MountingPointPlanBaseData : public LtsWebSocket::ReplyMessage
{
public:
explicit MountingPointPlanBaseData(const QJsonArray &data, const QString &uuid);
}; // class MountingPointPlanBaseData
} // namespace Messages
} // namespace WebSocketInterfac
} // namespace InfrastructureManagement
File diff suppressed because it is too large. Load diff
@@ -0,0 +1,171 @@
/**
* @RDE_HEADER@
* The DataManager class is a convenience class for managing structure data
* $Id$
* $HeadURL$
* $Author$
* Created by Hannes Baeuerle, SLSE, 2016-09-12
*/
#pragma once
#include <LtsWebSocket/data_manager_base_dl.h>
#include <InfrastructureManagement/ism_db.h>
#include "WebSocketInterface/Messages/reply_message.h"
#include "Messages/reply_message.h"
#include "logger.h"
namespace AssetManagement
{
namespace Interface
{
class Dtc;
} // namespace Interface
} // namespace AssetManagement
namespace InfrastructureManagement
{
class MainHandler;
class ObjectInstrumentationAsset;
namespace WebSocketInterface
{
namespace Messages
{
class TrainingAreaMessage;
class AreaMessage;
class ObjectMessage;
class LevelMessage;
class RoomMessage;
class MountingPointMessage;
class AssetTypeMessage;
} // namespace Messages
/**
* @brief The DataManager class is a convenience class for managing structure data
*/
class DataManager final : LtsWebSocket::DataManagerBaseDl<DatabaseInterface>
{
public:
/**
* @brief The EinruestEssentials struct is just there to bundle essentials data
* to a single return value
*/
struct EinruestEssentials
{
QVector<Messages::TrainingAreaMessage> trainingAreas;
QVector<Messages::AreaMessage> areas;
QVector<Messages::ObjectMessage> objects;
QVector<Messages::LevelMessage> levels;
QVector<Messages::RoomMessage> rooms;
QVector<Messages::MountingPointMessage> mountingPoints;
QVector<Messages::AssetTypeMessage> assetTypes;
};
/**
* @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();
/**
* @brief getEssentials Getter for initial data
* @param uuid Identifier of the message to be responded to
* @return Initial data of type EinruestEssentials
*/
EinruestEssentials getEssentials(const QString &uuid) const;
/**
* @brief getPlannedMounting Getter for data needed in response to a getPlannedMounting Message
* @param uuid Identifier of the message to be responded to
* @return All planned mounting messages
*/
QVector<Messages::PlannedMountingMessage> getPlannedMounting(const QString &uuid) const;
/**
* @brief getObjectMounting Getter for a Messages::ObjectMessage
* @param plannedMountingId Id of the schedule
* @param objectId Id of the object/building
* @param uuid Identifier of the message to be responded to
* @return Messages::ObjectMessage if combination of plannedMountingId and objectId exists,
* otherwise Messages::ErrorMessage
*/
LtsWebSocket::ReplyMessage *getObjectMounting(int plannedMountingId, int objectId, const QString &uuid) const;
LtsWebSocket::ReplyMessage *mountTag(const QString &mountingPointTag,
const QString &assetTag,
const QString &messageType,
const QString &uuid) const;
LtsWebSocket::ReplyMessage *mount(int32_t mountingPointId,
int32_t assetId,
const QString &messageType,
const QString &uuid) const;
LtsWebSocket::ReplyMessage *unmountAsset(int32_t assetId,
const QString &messageType,
const QString &uuid) const;
LtsWebSocket::ReplyMessage *unmountMountingPoint(int32_t mountingPointId,
const QString &messageType,
const QString &uuid) const;
LtsWebSocket::ReplyMessage *unmountObject(int32_t objectId,
const QString &messageType,
const QString &uuid) const;
LtsWebSocket::ReplyMessage *unmountArea(int32_t areaId,
const QString &messageType,
const QString &uuid) const;
LtsWebSocket::ReplyMessage *objectMountingReady(int32_t plannedMountingId,
int32_t objectId,
const QString &messageType,
const QString &uuid) const;
LtsWebSocket::ReplyMessage *getAssetState(int32_t assetId,
const QString &assetTag,
const QString &uuid) const;
LtsWebSocket::ReplyMessage *getAssets(const QSet<int> &assetTypeIds,
const QString &uuid) const;
LtsWebSocket::ReplyMessage *getBuildingState(int32_t buildingId,
const QString &uuid) const;
// base DL OC
LtsWebSocket::ReplyMessage *assetBaseData(const QString &uuid) const;
LtsWebSocket::ReplyMessage *mainStructureElementBaseData(const QString &uuid) const;
LtsWebSocket::ReplyMessage *structureElementBaseData(const QString &uuid) const;
LtsWebSocket::ReplyMessage *structureElementFootprintBaseData(const QString &uuid) const;
LtsWebSocket::ReplyMessage *mountingPointAssetBaseData(const QString &uuid) const;
LtsWebSocket::ReplyMessage *mountingPointScheduleBaseData(const QString &uuid) const;
LtsWebSocket::ReplyMessage *mountingPointPlanBaseData(const QString &uuid) const;
private: //methods
static QVector<Messages::ReplyMessage::LonLatPoint> relativeToGeographic(const Messages::ReplyMessage::LonLatPoint &pos,
const QVector<Messages::ReplyMessage::XYPoint> &relPoints);
QVector<Messages::ReplyMessage::XYPoint> pathForStructureId(int32_t structureElementId) const;
QVector<Messages::PlannedMountingMessage::MountingEntry> entriesForScheduleId(int32_t scheduleId) const;
int32_t areaIdForScheduleId(int32_t scheduleId) const;
int32_t stateForBuilding(int32_t buildingId) const;
bool isMounted(int32_t mountingPointId) const;
bool isPlannedObject(int32_t objectId) const;
QVector<Messages::ObjectMountingMessage::PlannedEntry> entriesForBuildingInSchedule(int32_t scheduleId, int32_t buildingId) const;
int32_t getMountedAssetId(int32_t mountingPointId) const;
int32_t mountingPointIdFromBarcode(const QString &barcode) const;
int32_t assetIdFromBarcode(const QString &barcode) const;
Messages::AssetData assetData(int32_t assetId) const;
Messages::AssetData assetData(const ObjectInstrumentationAsset *asset) const;
MountingPointState getMountingPointState(int32_t mountingPointId, int32_t scheduleId) const;
private: // attributes
MainHandler *m_mainHandler;
std::shared_ptr<AssetManagement::Interface::Dtc> m_asmDtc;
}; // class DataManager
} // namespace WebSocketInterface
} // namespace InfrastructureManagement
@@ -0,0 +1,119 @@
/**
* @RDE_HEADER@
* Header file which holds all occuring JSON keys
* $Id$
* $HeadURL$
* $Author$
* Created by Hannes Baeuerle, SLSE, 2016-08-25
*/
#pragma once
#include <QtCore/QString>
#include <OcBaseDownload/WebSocketInterface/json_keys.h>
namespace InfrastructureManagement
{
namespace WebSocketInterface
{
/**
* @brief Namespace which holds all occuring JSON keys as const QString objects
*/
namespace JsonKeys
{
// types for client --> server messages
inline QString GET_ASSETS() { return QStringLiteral("getAssets"); }
inline QString GET_ASSET_STATE() { return QStringLiteral("getAssetState"); }
inline QString GET_BUILDING_STATE() { return QStringLiteral("getBuildingState"); }
inline QString GET_ESSENTIALS() { return QStringLiteral("getEssentials"); }
inline QString GET_OBJECT_MOUNTING() { return QStringLiteral("getObjectMounting"); }
inline QString GET_PLANNED_MOUNTINGS() { return QStringLiteral("getPlannedMountings"); }
inline QString MOUNT() { return QStringLiteral("mount"); }
inline QString MOUNT_TAG() { return QStringLiteral("mountTag"); }
inline QString OBJECT_MOUNTING_READY() { return QStringLiteral("objectMountingReady"); }
inline QString UNMOUNT_AREA() { return QStringLiteral("unmountArea"); }
inline QString UNMOUNT_ASSET() { return QStringLiteral("unmountAsset"); }
inline QString UNMOUNT_MOUNTING_POINT() { return QStringLiteral("unmountMountingPoint"); }
inline QString UNMOUNT_OBJECT() { return QStringLiteral("unmountObject"); }
// types for server --> client messages
inline QString AREA() { return QStringLiteral("area"); }
inline QString AREAS() { return QStringLiteral("areas"); }
inline QString ASSET_STATE() { return QStringLiteral("assetState"); }
inline QString ASSETS() { return QStringLiteral("assets"); }
inline QString ASSET_STATE_OBJECT() { return QStringLiteral("assetStateObject"); }
inline QString ASSET_TYPE() { return QStringLiteral("assetType"); }
inline QString ASSET_TYPES() { return QStringLiteral("assetTypes"); }
inline QString LEVEL() { return QStringLiteral("level"); }
inline QString LEVELS() { return QStringLiteral("levels"); }
inline QString MOUNTING_POINT() { return QStringLiteral("mountingPoint"); }
inline QString MOUNTING_POINTS() { return QStringLiteral("mountingPoints"); }
inline QString OBJECT() { return QStringLiteral("object"); }
inline QString OBJECTS() { return QStringLiteral("objects"); }
inline QString OBJECT_MOUNTING() { return QStringLiteral("objectMounting"); }
inline QString OK() { return QStringLiteral("ok"); }
inline QString PLANNED_MOUNTING() { return QStringLiteral("plannedMounting"); }
inline QString PLANNED_MOUNTINGS() { return QStringLiteral("plannedMountings"); }
inline QString ROOM() { return QStringLiteral("room"); }
inline QString ROOMS() { return QStringLiteral("rooms"); }
inline QString TRAINING_AREA() { return QStringLiteral("trainingArea"); }
inline QString TRAINING_AREAS() { return QStringLiteral("trainingAreas"); }
// types for server --> client messages base DL
inline QString ISM_ASSET_BASE_DATA() { return QStringLiteral("ismAssetBaseData"); }
inline QString MAIN_STRUCTURE_ELEMENT_BASE_DATA() { return QStringLiteral("mainStructureElementBaseData"); }
inline QString VULNERABILITY_MODEL_DATA_BASE_DATA() { return QStringLiteral("vulnerabilityModelDataBaseData"); }
inline QString STRUCTURE_ELEMENT_BASE_DATA() { return QStringLiteral("structureElementBaseData"); }
inline QString STRUCTURE_ELEMENT_FOOTPRINT_BASE_DATA() { return QStringLiteral("structureElementFootprintBaseData"); }
inline QString MOUNTING_POINT_ASSET_BASE_DATA() { return QStringLiteral("mountingPointAssetBaseData"); }
inline QString MOUNTING_POINT_SCHEDULE_BASE_DATA() { return QStringLiteral("mountingPointScheduleBaseData"); }
inline QString MOUNTING_POINT_PLAN_BASE_DATA() { return QStringLiteral("mountingPointPlanBaseData"); }
// data keys
inline QString AREA_ID() { return QStringLiteral("areaId"); }
inline QString ASSET_ID() { return QStringLiteral("assetId"); }
inline QString ASSET_STATES() { return QStringLiteral("assetStates"); }
inline QString ASSET_TAG() { return QStringLiteral("assetTag"); }
inline QString ASSET_TYPE_ID() { return QStringLiteral("assetTypeId"); }
inline QString BUILDING_ID() { return QStringLiteral("buildingId"); }
inline QString DESIGNATION() { return QStringLiteral("designation"); }
inline QString DEVICE_CLASS() { return QStringLiteral("deviceClass"); }
inline QString ERROR_DESCRIPTION() { return QStringLiteral("errorDescription"); }
inline QString GEO_POINT() { return QStringLiteral("geoPoint"); }
inline QString ID() { return QStringLiteral("id"); }
inline QString MSE_ID() { return QStringLiteral("mseId"); }
inline QString INFO() { return QStringLiteral("info"); }
inline QString IP_ADDRESS() { return QStringLiteral("ipAddr"); }
inline QString LATITUDE() { return QStringLiteral("lat"); }
inline QString LEVEL_ID() { return QStringLiteral("levelId"); }
inline QString LONGITUDE() { return QStringLiteral("lon"); }
inline QString MESSAGE_TYPE() { return QStringLiteral("msgType"); }
inline QString MOUNTING() { return QStringLiteral("mounting"); }
inline QString MOUNTING_POINT_ID() { return QStringLiteral("mountingPointId"); }
inline QString MOUNTING_POINT_TAG() { return QStringLiteral("mountingPointTag"); }
inline QString NUMBER() { return QStringLiteral("number"); }
inline QString OBJECT_ID() { return QStringLiteral("objectId"); }
inline QString PATH() { return QStringLiteral("path"); }
inline QString PATH_RELATIVE() { return QStringLiteral("pathRelative"); }
inline QString PLANNED() { return QStringLiteral("planned"); }
inline QString PLANNED_MOUNTING_ID() { return QStringLiteral("plannedMountingId"); }
inline QString PLANNING_STATE() { return QStringLiteral("planningState"); }
inline QString POINT() { return QStringLiteral("point"); }
inline QString POSITION_3D() { return QStringLiteral("position3d"); }
inline QString REF_POINT() { return QStringLiteral("refPoint"); }
inline QString ROTATION_DEGREE() { return QStringLiteral("rotationDegree"); }
inline QString ROOM_ID() { return QStringLiteral("roomId"); }
inline QString STATE() { return QStringLiteral("state"); }
inline QString STREET() { return QStringLiteral("street"); }
inline QString SUPPORTED_ASSET_TYPE_IDS() { return QStringLiteral("supportedAssetTypeIds"); }
inline QString TAG() { return QStringLiteral("tag"); }
inline QString TIME() { return QStringLiteral("time"); }
inline QString TRAINING_AREA_ID() { return QStringLiteral("trainingAreaId"); }
inline QString X() { return QStringLiteral("x"); }
inline QString Y() { return QStringLiteral("y"); }
inline QString Z() { return QStringLiteral("z"); }
inline QString Z_POSITION() { return QStringLiteral("zPos"); }
} // namespace JsonKeys
} // namespace WebSocketInterface
} // namespace InfrastructureManagement
@@ -0,0 +1,81 @@
/**
* @RDE_HEADER@
* Handler for the WebSocket Interface
* $Id$
* $HeadURL$
* $Author$
* Created by Hannes Baeuerle, SLSE, 2016-08-25
*/
#include "websocket_interface_handler.h"
#include "main_handler.h"
#include "data_manager.h"
#include "WebSocketInterface/Messages/client_message.h"
#include <nglsettings/nglsettings_connections.h>
#include "settings.h"
namespace InfrastructureManagement
{
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) << "Setting Message Delay to " << Settings::messageDelay();
m_webSocketServer->setMessageDelay(Settings::messageDelay());
DEBUG_LOG(m_logger) << "Initialising LtsWebSocketServer";
if (!m_webSocketServer->init(QStringLiteral("ISM"),
NGL::Connections::port(NGL::Connections::eConnection::ISM_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 InfrastructureManagement
@@ -0,0 +1,69 @@
/**
* @RDE_HEADER@
* Handler for the WebSocket Interface
* $Id$
* $HeadURL$
* $Author$
* Created by Hannes Baeuerle, SLSE, 2016-08-25
*/
#pragma once
#include <QtCore/QObject>
#include <LtsWebSocket/lts_web_socket_server.h>
#include <InfrastructureManagement/logger.h>
namespace InfrastructureManagement
{
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 WebSocketInterfaceHandler
} // namespace WebSocketInterface
} // namespace InfrastructureManagement