Initial commit
This commit is contained in:
commit
b7d90b9afe
16245 files changed
+3396666
No files matched your search
+136
@@ -0,0 +1,136 @@
|
||||
/**
|
||||
* Handler ShootbackTargets (L400)
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
* Created by N. Thoden, NLE, 06.04.2020
|
||||
*/
|
||||
|
||||
#include "main_handler.h"
|
||||
#include "handler_target_information.h"
|
||||
#include "object_target_information.h"
|
||||
|
||||
using namespace ParticipantManagement;
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
HandlerTargetInformation::HandlerTargetInformation(MainHandler *mainHandler)
|
||||
: ModifyTargetInformationRequestHandler(mainHandler->fts())
|
||||
, RemoveTargetInformationRequestHandler(mainHandler->fts())
|
||||
, m_mainHandler(mainHandler)
|
||||
, m_logger(getLogger("HandlerTargetInformation"))
|
||||
{
|
||||
TRACE_LOG(m_logger) << LOGFUNCTION << " START";
|
||||
TRACE_LOG(m_logger) << LOGFUNCTION << " END";
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
HandlerTargetInformation::~HandlerTargetInformation()
|
||||
{
|
||||
TRACE_LOG(m_logger) << LOGFUNCTION << " START";
|
||||
TRACE_LOG(m_logger) << LOGFUNCTION << " END";
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
bool HandlerTargetInformation::init()
|
||||
{
|
||||
TRACE_LOG(m_logger) << LOGFUNCTION << " START";
|
||||
|
||||
bool bRet = true;
|
||||
// create objects
|
||||
auto cb = [this, &bRet](const Database::PpmTargetInformation & data)
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "Reading from DB PpmTargetInformation with id = " << data.id;
|
||||
ObjectTargetInformation *ifs(new ObjectTargetInformation(m_mainHandler));
|
||||
Core::FunctionReplyObject ret = ifs->createObject(ObjectTargetInformation::toDdsData(data));
|
||||
if (ret.error())
|
||||
{
|
||||
delete ifs;
|
||||
ERROR_LOG(m_logger) << ret();
|
||||
bRet = false;
|
||||
return;
|
||||
}
|
||||
m_objectMap.insert(ifs->getId(), ifs);
|
||||
};
|
||||
if (!m_mainHandler->db()->select(cb) || !bRet)
|
||||
{
|
||||
ERROR_LOG(m_logger) << "Error reading data from database!";
|
||||
return false;
|
||||
}
|
||||
DEBUG_LOG(m_logger) << "m_objectMap.size() = " << m_objectMap.size();
|
||||
TRACE_LOG(m_logger) << LOGFUNCTION << " END";
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
void HandlerTargetInformation::onModifyTargetInformationRequest(const rti::core::SampleIdentity &cookie,
|
||||
const ModifyTargetInformationRequest &request)
|
||||
{
|
||||
TRACE_LOG(m_logger) << LOGFUNCTION << " START";
|
||||
const auto ret = targetInformationModifyRequest(request);
|
||||
if (ret.error())
|
||||
WARNING_LOG(m_logger) << ret();
|
||||
|
||||
m_mainHandler->fts()->modifyTargetInformationReply(cookie, ret);
|
||||
TRACE_LOG(m_logger) << LOGFUNCTION << " END";
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
Core::FunctionReplyObject HandlerTargetInformation::targetInformationModifyRequest(const ModifyTargetInformationRequest &request)
|
||||
{
|
||||
TRACE_LOG(m_logger) << LOGFUNCTION << " START";
|
||||
const int requestId = request.targetInfo().id();
|
||||
// modify
|
||||
if (requestId > 0)
|
||||
{
|
||||
ObjectTargetInformation *ifs = m_objectMap.value(requestId);
|
||||
if (!ifs)
|
||||
return Core::FunctionReplyObject(requestId, tr_lts("dds", "TargetInformation with id %1 not found")).arg(requestId);
|
||||
|
||||
auto ret = ifs->updateObject(request.targetInfo());
|
||||
return ret;
|
||||
}
|
||||
// create
|
||||
ObjectTargetInformation *ifs(new ObjectTargetInformation(m_mainHandler));
|
||||
auto ret = ifs->createObject(request.targetInfo());
|
||||
if (ret.error())
|
||||
{
|
||||
delete ifs;
|
||||
ifs = nullptr;
|
||||
}
|
||||
else
|
||||
m_objectMap.insert(ifs->getId(), ifs);
|
||||
TRACE_LOG(m_logger) << LOGFUNCTION << " END";
|
||||
return ret;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
void HandlerTargetInformation::onRemoveTargetInformationRequest(const rti::core::SampleIdentity &cookie,
|
||||
const RemoveTargetInformationRequest &request)
|
||||
{
|
||||
TRACE_LOG(m_logger) << LOGFUNCTION << " request=" << request;
|
||||
|
||||
Core::FunctionReplyObject ret;
|
||||
ObjectTargetInformation *ifs = m_objectMap.value(request.id());
|
||||
|
||||
if (ifs == nullptr)
|
||||
{
|
||||
ret = Core::FunctionReplyObject(request.id(), tr_lts("dds", "ShootbackTarget with id %1 not found")).arg(request.id());
|
||||
m_mainHandler->fts()->removeTargetInformationReply(cookie, ret);
|
||||
return;
|
||||
}
|
||||
|
||||
ret = ifs->removeObject();
|
||||
if (ret.error())
|
||||
ERROR_LOG(m_logger) << ret();
|
||||
else
|
||||
{
|
||||
// delete Object
|
||||
delete ifs;
|
||||
m_objectMap.remove(request.id());
|
||||
}
|
||||
|
||||
m_mainHandler->fts()->removeTargetInformationReply(cookie, ret);
|
||||
return;
|
||||
}
|
||||
+61
@@ -0,0 +1,61 @@
|
||||
/**
|
||||
* Handler ShootbackTargets (L400)
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
* Created by N. Thoden, NLE, 06.04.2020
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <QObject>
|
||||
#include "dds_handler.h"
|
||||
#include <ParticipantManagement/logger.h>
|
||||
|
||||
#include <ParticipantManagement/ppm_dts.h>
|
||||
#include <ParticipantManagement/ppm_fts.h>
|
||||
|
||||
namespace ParticipantManagement
|
||||
{
|
||||
class MainHandler;
|
||||
class ObjectTargetInformation;
|
||||
|
||||
class HandlerTargetInformation final
|
||||
: protected Interface::Fts::ModifyTargetInformationRequestHandler
|
||||
, protected Interface::Fts::RemoveTargetInformationRequestHandler
|
||||
{
|
||||
public:
|
||||
|
||||
explicit HandlerTargetInformation(MainHandler *mainHandler);
|
||||
~HandlerTargetInformation();
|
||||
|
||||
/**
|
||||
* Initialize the handler to manage information
|
||||
*/
|
||||
bool init();
|
||||
|
||||
const QHash<int, ObjectTargetInformation *> &getObjectMap() const { return m_objectMap; }
|
||||
|
||||
ObjectTargetInformation *data(int id)
|
||||
{
|
||||
if (!m_objectMap.contains(id))
|
||||
return nullptr;
|
||||
return m_objectMap[id];
|
||||
}
|
||||
|
||||
private: // methods
|
||||
void onModifyTargetInformationRequest(const rti::core::SampleIdentity &cookie,
|
||||
const ModifyTargetInformationRequest &request) override;
|
||||
Core::FunctionReplyObject targetInformationModifyRequest(const ModifyTargetInformationRequest &request);
|
||||
void onRemoveTargetInformationRequest(const rti::core::SampleIdentity &cookie,
|
||||
const RemoveTargetInformationRequest &request) override;
|
||||
|
||||
private: // attributes
|
||||
|
||||
QHash<int, ObjectTargetInformation *> m_objectMap;
|
||||
MainHandler *m_mainHandler;
|
||||
NGL::INGLLogger &m_logger; ///< Interface to the Logging-Facility
|
||||
|
||||
};
|
||||
} // namespace ParticipantManagement
|
||||
|
||||
+262
@@ -0,0 +1,262 @@
|
||||
/**
|
||||
* Handler ShootbackTargets (L400)
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
* Created by N. Thoden, SLTE, 31.05.2022
|
||||
*/
|
||||
|
||||
#include "object_target_information.h"
|
||||
#include "../main_handler.h"
|
||||
|
||||
#include <QJsonDocument>
|
||||
#include <QDebug>
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
namespace ParticipantManagement
|
||||
{
|
||||
|
||||
//
|
||||
// Core::GeoPosition2D
|
||||
Core::GeoPosition2D posFromJson(const QJsonValue &val)
|
||||
{
|
||||
const QJsonObject objElement(val.toObject());
|
||||
Core::GeoPosition2D element;
|
||||
{
|
||||
const QJsonValue valLon(objElement.value(QStringLiteral("lon")));
|
||||
element.lon(valLon.toDouble());
|
||||
}
|
||||
{
|
||||
const QJsonValue valLat(objElement.value(QStringLiteral("lat")));
|
||||
element.lat(valLat.toDouble());
|
||||
}
|
||||
return element;
|
||||
}
|
||||
QJsonObject toJson(const Core::GeoPosition2D &element)
|
||||
{
|
||||
QJsonObject obj;
|
||||
obj[QStringLiteral("lon")] = element.lon();
|
||||
obj[QStringLiteral("lat")] = element.lat();
|
||||
return obj;
|
||||
}
|
||||
|
||||
//
|
||||
// ShootbackArea
|
||||
ShootbackArea areaFromJson(const QJsonValue &val)
|
||||
{
|
||||
ShootbackArea area;
|
||||
// use val.toObject().value instead val[key] introduced with qt5.10
|
||||
area.identifier(val.toObject().value(QStringLiteral("identifier")).toString().toStdString());
|
||||
|
||||
if (val.toObject().value(QStringLiteral("coords")).isArray())
|
||||
{
|
||||
const QJsonArray &arr = val.toObject().value(QStringLiteral("coords")).toArray();
|
||||
if (arr.size() > 0) area.coord1( posFromJson(arr.at(0)) );
|
||||
if (arr.size() > 1) area.coord2( posFromJson(arr.at(1)) );
|
||||
if (arr.size() > 2) area.coord3( posFromJson(arr.at(2)) );
|
||||
if (arr.size() > 3) area.coord4( posFromJson(arr.at(3)) );
|
||||
}
|
||||
return area;
|
||||
}
|
||||
|
||||
QJsonObject toJson(const ShootbackArea &area)
|
||||
{
|
||||
QJsonObject obj;
|
||||
obj.insert(QStringLiteral("identifier"), QString::fromStdString(area.identifier()));
|
||||
|
||||
QJsonArray arr;
|
||||
arr.push_back(toJson(area.coord1()));
|
||||
arr.push_back(toJson(area.coord2()));
|
||||
arr.push_back(toJson(area.coord3()));
|
||||
arr.push_back(toJson(area.coord4()));
|
||||
obj.insert(QStringLiteral("coords"), arr);
|
||||
return obj;
|
||||
}
|
||||
|
||||
//
|
||||
// vector<ShootbackArea>
|
||||
QJsonObject toJson(const std::vector<ShootbackArea>& shootback_areas)
|
||||
{
|
||||
if (shootback_areas.size() == 0)
|
||||
return {};
|
||||
QJsonArray arr;
|
||||
for (const ShootbackArea &area : shootback_areas)
|
||||
arr.push_back(toJson(area));
|
||||
|
||||
QJsonObject obj;
|
||||
obj.insert(QStringLiteral("shootback_areas"), arr);
|
||||
return obj;
|
||||
}
|
||||
|
||||
std::vector<ShootbackArea> vecfromJson(const QJsonValue &val)
|
||||
{
|
||||
std::vector<ShootbackArea> ret;
|
||||
if (val.isNull())
|
||||
return ret;
|
||||
|
||||
// use val.toObject().value instead val[key] introduced with qt5.10
|
||||
if (val.toObject().value(QStringLiteral("shootback_areas")).isArray())
|
||||
{
|
||||
const QJsonArray &arr = val.toObject().value(QStringLiteral("shootback_areas")).toArray();
|
||||
ret.reserve(arr.size());
|
||||
for (const auto& item : arr)
|
||||
ret.push_back(areaFromJson(item));
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
ObjectTargetInformation::ObjectTargetInformation(MainHandler *mainHandler)
|
||||
: m_mainHandler(mainHandler)
|
||||
, m_logger(getLogger("ObjectTargetInformation"))
|
||||
{
|
||||
TRACE_LOG(m_logger) << LOGFUNCTION << " START";
|
||||
TRACE_LOG(m_logger) << LOGFUNCTION << " END";
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
ObjectTargetInformation::~ObjectTargetInformation()
|
||||
{
|
||||
TRACE_LOG(m_logger) << LOGFUNCTION << " START";
|
||||
if (isValid())
|
||||
m_mainHandler->dts()->removeTargetInformationByKey(m_data.id());
|
||||
TRACE_LOG(m_logger) << LOGFUNCTION << " END";
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
bool ObjectTargetInformation::isValid() const
|
||||
{
|
||||
return m_data.id() > 0;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
Core::FunctionReplyObject ObjectTargetInformation::createObject(const TargetInformation &data)
|
||||
{
|
||||
TRACE_LOG(m_logger) << LOGFUNCTION << " START";
|
||||
m_data = data;
|
||||
|
||||
if (m_data.id() <= 0)
|
||||
{
|
||||
Database::PpmTargetInformation dbData(toDbData(data));
|
||||
|
||||
if (!m_mainHandler->db()->insert(dbData))
|
||||
return Core::FunctionReplyObject(0, tr_lts("dds", "Error inserting TargetInformation-data into database"));
|
||||
|
||||
m_data.id(dbData.id);
|
||||
DEBUG_LOG(m_logger) << "New PpmTargetInformation: " /*<< m_data.id()*/;
|
||||
}
|
||||
|
||||
// Publish Data via DTS
|
||||
onPublishData();
|
||||
|
||||
TRACE_LOG(m_logger) << LOGFUNCTION << " END";
|
||||
return Core::FunctionReplyObject(m_data.id());
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
Core::FunctionReplyObject ObjectTargetInformation::updateObject(const TargetInformation &data)
|
||||
{
|
||||
TRACE_LOG(m_logger) << LOGFUNCTION << " START, participantId=" << data.participantId()
|
||||
<< " size =" << data.shootbackAreas().size();
|
||||
Database::PpmTargetInformation dbData;
|
||||
dbData = toDbData(data);
|
||||
|
||||
if (!m_mainHandler->db()->update(dbData))
|
||||
return Core::FunctionReplyObject(data.id(), tr_lts("dds", "Error updating TargetInformation-data into database"));
|
||||
|
||||
m_data = data;
|
||||
DEBUG_LOG(m_logger) << "Data changed for TargetInformation: " << m_data.participantId();
|
||||
|
||||
// Publish Data via DTS
|
||||
onPublishData();
|
||||
|
||||
TRACE_LOG(m_logger) << LOGFUNCTION << " END, id=" << data.id()
|
||||
<< " size =" << data.shootbackAreas().size();
|
||||
return Core::FunctionReplyObject(m_data.id());
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
Core::FunctionReplyObject ObjectTargetInformation::removeObject()
|
||||
{
|
||||
TRACE_LOG(m_logger) << LOGFUNCTION << " START";
|
||||
|
||||
if (!m_mainHandler->db()->removePpmTargetInformation(m_data.id()))
|
||||
return Core::FunctionReplyObject(m_data.id(), tr_lts("dds", "TargetInformation with id %1 can not be removed from DB")).arg(m_data.id());
|
||||
|
||||
if (!m_mainHandler->dts()->removeTargetInformationByKey(m_data.id()))
|
||||
return Core::FunctionReplyObject(m_data.id(), tr_lts("dds", "TargetInformation with id %1 can not be removed from DDS")).arg(m_data.id());
|
||||
|
||||
TRACE_LOG(m_logger) << LOGFUNCTION << " END";
|
||||
return Core::FunctionReplyObject(m_data.id());
|
||||
}
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
void ObjectTargetInformation::onPublishData()
|
||||
{
|
||||
TRACE_LOG(m_logger) << "Publish TargetInformation-data to dds (" << m_data.id() << ") ...";
|
||||
|
||||
if (!m_mainHandler->dts()->publish(m_data))
|
||||
ERROR_LOG(m_logger) << "Error publishing TargetInformation-data to dds";
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------------------------------------
|
||||
// convert methods
|
||||
// -------------------------------------------------------------------------------------------------------
|
||||
|
||||
// ParticipantManagement::TargetInformation => Database::PpmTargetInformation
|
||||
Database::PpmTargetInformation ObjectTargetInformation::toDbData(const TargetInformation &ddsData)
|
||||
{
|
||||
Database::PpmTargetInformation dbData;
|
||||
|
||||
dbData.id = ddsData.id();
|
||||
dbData.participantId = ddsData.participantId();
|
||||
|
||||
dbData.preWarningInterval = ddsData.prewarningInterval();
|
||||
dbData.preWarningEffect = static_cast<int>(ddsData.prewarningEffect().underlying());
|
||||
dbData.takeDownInterval = ddsData.takedownInterval();
|
||||
dbData.takeDownEffect = static_cast<int>(ddsData.takedownEffect().underlying());
|
||||
|
||||
const std::vector<ParticipantManagement::ShootbackArea>& shootback_areas = ddsData.shootbackAreas();
|
||||
|
||||
const QJsonObject &obj = toJson(shootback_areas);
|
||||
dbData.properties = QString::fromStdString( QJsonDocument(obj).toJson(QJsonDocument::Compact).toStdString() );
|
||||
|
||||
return dbData;
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------------------------------------
|
||||
// Database::PpmTargetInformation => ParticipantManagement::TargetInformation
|
||||
TargetInformation ObjectTargetInformation::toDdsData(const Database::PpmTargetInformation &dbData)
|
||||
{
|
||||
TargetInformation ddsData;
|
||||
|
||||
ddsData.id(dbData.id);
|
||||
ddsData.participantId(dbData.participantId);
|
||||
|
||||
ddsData.prewarningInterval(dbData.preWarningInterval);
|
||||
ddsData.prewarningEffect(static_cast<ProjectDataManagement::VulnerabilityState::inner_enum>(dbData.preWarningEffect));
|
||||
ddsData.takedownInterval(dbData.takeDownInterval);
|
||||
ddsData.takedownEffect(static_cast<ProjectDataManagement::VulnerabilityState::inner_enum>(dbData.takeDownEffect));
|
||||
|
||||
const QByteArray &propertiesBa = dbData.properties.toUtf8();
|
||||
QJsonParseError parserError;
|
||||
const QJsonDocument doc(QJsonDocument::fromJson(propertiesBa, &parserError));
|
||||
|
||||
if (parserError.error != QJsonParseError::NoError)
|
||||
qCritical() << "Error parsing json document: " << parserError.errorString() << " '" << propertiesBa << "'";
|
||||
|
||||
qDebug() << "json to parse: " << doc.toJson();
|
||||
|
||||
QJsonObject obj(doc.object());
|
||||
const std::vector<ShootbackArea> &sbAreas = vecfromJson(obj);
|
||||
ddsData.shootbackAreas(sbAreas);
|
||||
|
||||
return ddsData;
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------------------------------------
|
||||
|
||||
} // Namespace ParticipantManagement
|
||||
+57
@@ -0,0 +1,57 @@
|
||||
/**
|
||||
* Handler ObjectTargetInformation (L400)
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
* Created by N. Thoden, SLTE, 31.05.2022
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include "dds_handler.h"
|
||||
#include <ParticipantManagement/logger.h>
|
||||
|
||||
#include <DDS/Core/function_reply_object.h>
|
||||
|
||||
// Generated
|
||||
#include <ParticipantManagement/ppm.hpp>
|
||||
#include <ParticipantManagement/ppm_db.h>
|
||||
|
||||
namespace NGL
|
||||
{
|
||||
class INGLLogger;
|
||||
}
|
||||
|
||||
namespace ParticipantManagement
|
||||
{
|
||||
class MainHandler;
|
||||
|
||||
class ObjectTargetInformation
|
||||
{
|
||||
public:
|
||||
explicit ObjectTargetInformation(MainHandler *mainHandler);
|
||||
~ObjectTargetInformation();
|
||||
|
||||
Core::FunctionReplyObject createObject(const TargetInformation &data);
|
||||
Core::FunctionReplyObject updateObject(const TargetInformation &data);
|
||||
Core::FunctionReplyObject removeObject();
|
||||
|
||||
qint32 getId() const { return m_data.id(); }
|
||||
qint32 getParticipantId() const { return m_data.participantId(); }
|
||||
const TargetInformation &getData() const { return m_data; }
|
||||
|
||||
bool isValid() const;
|
||||
|
||||
// convert methods
|
||||
static Database::PpmTargetInformation toDbData(const TargetInformation &ddsData); // dds -> db
|
||||
static TargetInformation toDdsData(const Database::PpmTargetInformation &dbData); // db -> dds
|
||||
|
||||
protected:
|
||||
void onPublishData();
|
||||
|
||||
private:
|
||||
MainHandler *m_mainHandler;
|
||||
TargetInformation m_data;
|
||||
NGL::INGLLogger &m_logger;
|
||||
|
||||
};
|
||||
}
|
||||
Reference in new issue
Block a user