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

+137
View File
@@ -0,0 +1,137 @@
#
# $Id$
# $HeadURL$
# $Author$
#
INCLUDE(MacroRTIDDSGen)
INCLUDE(MacroCodeGenIdl)
SET(xml_FILE mrk_service.xml)
#
# --- Library svcMrkCommon --------------------------------------------------------------------------------
#
SET(SRCS_common
mrk_export.h
logger.cpp
logger.h
)
# Generate mrk_enums.idl / mrk.idl
CODEGEN_IDL_SVC(SRCS_common ${xml_FILE})
# Generate mrk_db_impl.cpp/.h, mrk_db.h
CODEGEN_DATABASE(SRCS_common ${xml_FILE})
# Generate *.cpp/*.hpp from idl
RTIDDSGEN(SRCS_common mrk_enums.idl)
RTIDDSGEN(SRCS_common mrk.idl)
# Generate mrk_dt[s,c]_types.h, mrk_ft[s,c]_types.h
CODEGEN_TOPIC_TYPEDEFS(SRCS_common ${xml_FILE})
# generate mrk_[d|f]tc.h
CODEGEN_CLIENT_TOPICS_IFC(SRCS_common ${xml_FILE})
NGL_ADD_LIBRARY(AAR SV WS svcMrkCommon SHARED ${SRCS_common})
NGL_TARGET_INCLUDE_DIRECTORIES(svcMrkCommon
PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/../
${CMAKE_CURRENT_BINARY_DIR}/../
)
NGL_TARGET_LINK_LIBRARIES(svcMrkCommon
PRIVATE
RTI::nddscpp2
PUBLIC
Qt5::Core
ngldb
ddscore
NGLLogger
)
NGL_INSTALL_TARGET(svcMrkCommon)
#
# --- Library svcMrkClient --------------------------------------------------------------------------------
#
SET(SRCS_client
mrk_export.h
)
# generate mrk_[d|f]tc_impl.[cpp|h]
CODEGEN_CLIENT_TOPICS_IMPL(SRCS_client ${xml_FILE})
NGL_ADD_LIBRARY(AAR SV WS svcMrkClient SHARED ${SRCS_client})
NGL_TARGET_INCLUDE_DIRECTORIES(svcMrkClient
PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/../
${CMAKE_CURRENT_BINARY_DIR}/../
)
NGL_TARGET_LINK_LIBRARIES(svcMrkClient
PRIVATE
RTI::nddscpp2
ddsconnector
PUBLIC
svcMrkCommon
ddsftc
)
NGL_INSTALL_TARGET(svcMrkClient)
#
# --- Library svcMrkServer --------------------------------------------------------------------------------
#
SET(SRCS_server
mrk_export.h
settings.cpp
settings.h
dds_handler.cpp
dds_handler.h
handler_marker.cpp
handler_marker.h
handler_snapshot.cpp
handler_snapshot.h
initialization.cpp
initialization.h
object_marker.cpp
object_marker.h
object_snapshot.cpp
object_snapshot.h
${xml_FILE}
)
# generate mrk_[d|f]ts.h, mrk_[d|f]ts_impl.[cpp|h]
CODEGEN_SERVER_TOPICS(SRCS_server ${xml_FILE})
# Generate mrk.sql, mrk.xml
CODEGEN_SQL(SRCS_server ${xml_FILE})
NGL_ADD_LIBRARY(AAR SV svcMrkServer SHARED ${SRCS_server})
NGL_TARGET_INCLUDE_DIRECTORIES(svcMrkServer
PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/../
${CMAKE_CURRENT_BINARY_DIR}/../
)
NGL_TARGET_LINK_LIBRARIES(svcMrkServer
PRIVATE
Qt5::Core
RTI::nddscpp2
ddsconnector
ddsfts
svcCoreClient
nglsettings
ProjectConfig
NGLLogger
ngltools
PUBLIC
svcMrkCommon
ngldb
)
NGL_INSTALL_TARGET(svcMrkServer)
#
# --- Topic Type Plugin --------------------------------------------------------------
#
CREATE_TOPIC_TYPE_PLUGIN(${xml_FILE})
# Uncomment if necessary
#ADD_SUBDIRECTORY(UnitTests)
ADD_SUBDIRECTORY(ModuleTests)
+28
View File
@@ -0,0 +1,28 @@
#
# $Id$
# $HeadURL$
# $Author$
#
SET(SRCS_MRK_TEST
mrk_tests.cpp
mrk_tests.h
)
IF(BUILD_TESTING AND TARGET svcMrkClient)
# Testing FunctionTopic Functionality (FTC)
ADD_EXECUTABLE(mrkTests ${SRCS_MRK_TEST})
TARGET_LINK_LIBRARIES(mrkTests
Qt5::Core
Qt5::Test
RTI::nddscpp2
svcMrkClient
LtsCommandLineParser
ddsconnector
nglcoreapplication
)
IF(NOT BUILD_RPM)
NGL_INSTALL(AAR SV TARGETS mrkTests DESTINATION bin/test)
NGL_INSTALL(AAR SV FILES log4cxx_mrk.props DESTINATION bin/test)
ENDIF()
ENDIF()
@@ -0,0 +1,86 @@
log4j.reset=true
log4j.rootLogger=WARN, file
# Service: MarkerManagement
###########################################################
#log4j.logger.MRK=INFO
#log4j.logger.MRK.main=INFO
#log4j.logger.MRK.MainHandler=INFO
#log4j.logger.MRK.DdsHandler=INFO
#log4j.logger.MRK.DbHandler=INFO
#log4j.logger.MRK.HandlerMarker=DEBUG
#log4j.logger.MRK.ObjectMarker=DEBUG
#log4j.logger.MRK.HandlerMarkerDescription=DEBUG
#log4j.logger.MRK.ObjectMarkerDescription=DEBUG
#log4j.logger.MRK.ObjectMarker=INFO
# File
###########################################################
log4j.appender.file=Lts::RollingFileAppender
log4j.appender.file.MaxFileSize=1MB
log4j.appender.file.MaxBackupIndex=9
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d %-5p %c |#| %m (%.50F:%L) %n
# Appnd_Console
###########################################################
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern= %d %p %c %c{1} - %m (%-.30F:%L) %n
# Appnd_Syslog
###########################################################
log4j.appender.syslog=org.apache.log4j.SyslogAppender
log4j.appender.syslog.Threshold=ERROR
log4j.appender.syslog.SysLogHost=localhost
log4j.appender.syslog.Facility=LOCAL7
log4j.appender.syslog.layout=org.apache.log4j.PatternLayout
log4j.appender.syslog.layout.ConversionPattern= %-4r %-5p %c %x - %m
log4j.appender.syslog.LevelRangeFilter.AcceptOnMatch=true
log4j.appender.syslog.LevelRangeFilter.LevelMin=INFO
log4j.appender.syslog.LevelRangeFilter.LevelMax=FATAL
###########################################################
###########################################################
###########################################################
# 1) Available Levels in LOG4CXX Version 0.10.0:
# TRACE,
# DEBUG,
# INFO,
# WARN,
# ERROR
# FATAL
#
# d = date/time
# p = priority (Level)
# c = category/channel
# m = message
# F = file
# L = line
# n = platform dependent line separator character or characters.
# ....
#
# Examples for console:
# a)
# %d %p %c #%m# (%.50F:%L)%n
# date/time
# priority
# category/channel
# #message#
# (Maximal 50Character des Filename von rechts:Line)
# line separator
#
# b)
# %d (%.15F:%L) %-5p %c |#| %m%n
# date/time
# (Maximal 15Character des Filename von rechts:Line)
# priority, Right pad with spaces if the priority name is less than 5 characters long.
# category/channel
# message
# line separator
#
# Examples for files:
+725
View File
@@ -0,0 +1,725 @@
/**
* MRK Function Topic test executable
* $Id$
* $HeadURL$
* $Author$
* Created by hjl, SLSE, 2016-04-18
*/
#include "mrk_tests.h"
#include <nglapplication/nglcoreapplication.h>
#include <LtsCommandLineParser/LtsCommandLineParser.h>
#include <QTimer>
#include <QDateTime>
#include <QString>
#include <QVector>
#include <MarkerManagement/mrk_ftc.h>
#include <MarkerManagement/mrk_dtc.h>
using namespace MarkerManagement;
//-----------------------------------------------------------------------------
MrkTests::MrkTests(QObject *parent)
: QObject(parent)
, m_exerciseId(0)
, m_testId(0)
, m_markerId(0)
, m_eTestStep(eUnknown)
, m_bTestsSuccessful(true)
, m_logger(getLogger("MrkTests"))
{
qRegisterMetaType<Core::FunctionReply>("Core::FunctionReply");
} // end of ctor()
//-----------------------------------------------------------------------------
MrkTests::~MrkTests()
{
} // end of dtor()
//-----------------------------------------------------------------------------
bool MrkTests::init(int domainId, int exerciseId, int testId, int markerId, int snapshotId)
{
INFO_LOG(m_logger) << "MrkTests::init() "
<< " domainId:" << domainId
<< " exerciseId:" << exerciseId
<< " testId: " << testId
<< " markerId: " << markerId
;
m_testId = testId;
m_exerciseId = exerciseId;
m_markerId = markerId;
m_snapshotId = snapshotId;
// initialize DDS
m_ddsConnector.reset(new DDSConnector::DdsConnector(domainId, IDL::PartitionType::Exercise, exerciseId));
if (!m_ddsConnector->init())
return false;
m_ddsConnector->initPublisherSubscriber();
// Access to FTC
DEBUG_LOG(m_logger) << "create ftc";
m_ftc = MarkerManagement::Interface::Ftc::create(m_ddsConnector);
DEBUG_LOG(m_logger) << "init ftc";
bool bRet = m_ftc->enableAll();
DEBUG_LOG(m_logger) << "init end - bRet = " << bRet;
// Access to DTC
DEBUG_LOG(m_logger) << "create dtc";
m_dtc = MarkerManagement::Interface::Dtc::create(m_ddsConnector);
DEBUG_LOG(m_logger) << "init dtc";
bRet = m_dtc->enableAll();
DEBUG_LOG(m_logger) << "init end - bRet = " << bRet;
return bRet;
} // end of init()
//-----------------------------------------------------------------------------
void MrkTests::startTest()
{
INFO_LOG(m_logger) << "startTest() exerciseId:" << m_exerciseId
<< " testId:" << m_testId
<< " markerId:" << m_markerId
;
connect(m_dtc.get(), &Interface::Dtc::markerChanged,
this, &MrkTests::onReceiveMarkerChanged);
if (m_testId <= 1)
QTimer::singleShot(0, this, &MrkTests::tryCreate);
else if (m_testId == 2)
QTimer::singleShot(0, this, &MrkTests::tryModify);
else if (m_testId == 3)
QTimer::singleShot(0, this, &MrkTests::tryRemove);
else if (m_testId == 4)
QTimer::singleShot(0, this, &MrkTests::tryCreateSnapshot);
else if (m_testId == 5)
QTimer::singleShot(0, this, &MrkTests::tryModifySnapshot);
else if (m_testId == 6)
QTimer::singleShot(0, this, &MrkTests::tryRemoveSnapshot);
else if (m_testId == 10)
QTimer::singleShot(0, this, &MrkTests::tryGetAllMarkers);
else if (m_testId == 11)
QTimer::singleShot(0, this, &MrkTests::tryGetMarker);
} // end of startTest()
//-----------------------------------------------------------------------------
void MrkTests::tryCreate()
{
m_eTestStep = eCreate;
MarkerModifyRequest data;
getMarkerCreateRequestData(data);
INFO_LOG(m_logger) << "trying to send MarkerCreateRequest";
if (!m_ftc->markerModifyRequest(data, this))
{
ERROR_LOG(m_logger) << "Error requesting create data";
failExit();
}
} // end of tryCreate()
//-----------------------------------------------------------------------------
void MrkTests::tryModify()
{
m_eTestStep = eModify;
MarkerModifyRequest data;
getMarkerModifyRequestData(data);
INFO_LOG(m_logger) << "trying to send MarkerModifyRequest for markerId:" << data.id();
if (!m_ftc->markerModifyRequest(data, this))
{
ERROR_LOG(m_logger) << "Error requesting modify data for markerId:" << data.id();
failExit();
}
} // end of tryModify()
//-----------------------------------------------------------------------------
void MrkTests::tryRemove()
{
m_eTestStep = eRemove;
MarkerRemoveRequest data;
data.id(m_markerId);
INFO_LOG(m_logger) << "trying to send remove request for markerId:" << data.id();
if (!m_ftc->markerRemoveRequest(data, this))
{
ERROR_LOG(m_logger) << "Error requesting remove data for markerId:" << data.id();
failExit();
}
} // end of tryRemove()
//-----------------------------------------------------------------------------
void MrkTests::tryGetAllMarkers()
{
m_eTestStep = eGetAllMarkers;
DEBUG_LOG(m_logger) << "trying to get all markers";
m_dtc->waitForHistoricalDataMarker();
const QMap<qint32, MarkerManagement::Marker> map = m_dtc->markers();
if (map.isEmpty())
{
ERROR_LOG(m_logger) << "Error requesting all marker data";
QTimer::singleShot(0, qApp, &QCoreApplication::quit);
return;
}
INFO_LOG(m_logger) << "Amout of existing markers:" << map.size();
m_markerId = map.firstKey();
for (auto it = map.begin(); it != map.end(); ++it)
{
INFO_LOG(m_logger) << "Mrk(" << it.key() << ") :"
<< " note:" << it.value().note()
<< " operatorId:" << it.value().operatorId()
<< " timeStamp:" << it.value().timeStamp()
<< " timeStampOffset:" << it.value().timeStampOffset()
<< " description count:" << it.value().descriptions().size();
}
QTimer::singleShot(0, qApp, &QCoreApplication::quit);
} // end of tryGetAllMarkers()
//-----------------------------------------------------------------------------
void MrkTests::tryGetMarker()
{
DEBUG_LOG(m_logger) << "trying to get marker with id:" << m_markerId;
if (m_testId > 1)
m_eTestStep = eGetMarker;
if (m_markerId <= 0)
{
ERROR_LOG(m_logger) << "invalid markerId - test aborted.";
failExit();
}
m_dtc->waitForHistoricalDataMarker();
MarkerManagement::Marker data = m_dtc->marker(m_markerId);
if (data.id() <= 0)
{
ERROR_LOG(m_logger) << "Error receiving data for markerId " << m_markerId << " returnVal:" << data.id();
failExit();
}
else
{
INFO_LOG(m_logger) << "Mrk(" << data.id() << ") :"
<< " note:" << data.note()
<< " operatorId:" << data.operatorId()
<< " timeStamp:" << data.timeStamp()
<< " timeStampOffset:" << data.timeStampOffset()
;
}
if (m_testId == 0)
{
if (m_eTestStep == eCreate)
{
if (! onCompareCreatedData(data))
{
ERROR_LOG(m_logger) << "Compare created data failed!";
failExit();
}
else
{
QTimer::singleShot(0, this, &MrkTests::tryModify);
return;
}
}
else if (m_eTestStep == eModify)
{
if (! onCompareModifiedData(data))
{
ERROR_LOG(m_logger) << "Compare modified data failed!";
failExit();
}
else
{
QTimer::singleShot(0, this, &MrkTests::tryRemove);
return;
}
}
}
else
QTimer::singleShot(0, qApp, &QCoreApplication::quit);
} // end of tryGetMarker()
//-----------------------------------------------------------------------------
void MrkTests::tryCreateSnapshot()
{
m_eTestStep = eCreate;
Snapshot data;
data.id(0); // create
data.name("Snapshot 1");
data.description("Dies ist ein Test");
data.mapSettings("78000 92000 xxxx");
data.operatorId(100);
data.timeStamp(QDateTime::currentMSecsSinceEpoch());
data.planOverlay("Plan Overlay");
INFO_LOG(m_logger) << "trying to send SnapshotCreateRequest";
if (!m_ftc->snapshotModifyRequest(data, this))
{
ERROR_LOG(m_logger) << "Error requesting create data";
failExit();
}
} // end of tryCreateSnapshot()
//-----------------------------------------------------------------------------
void MrkTests::tryModifySnapshot()
{
m_eTestStep = eModify;
Snapshot data;
data.id(m_snapshotId);
data.name("Snapshot modify");
data.description("Dies ist ein Test modify");
data.planOverlay("Plan Overlay updated");
INFO_LOG(m_logger) << "trying to send SnapshotModifyRequest for snapshotId:" << data.id();
if (!m_ftc->snapshotModifyRequest(data, this))
{
ERROR_LOG(m_logger) << "Error requesting modify data for snapshotId:" << data.id();
failExit();
}
} // end of tryModifySnapshot()
//-----------------------------------------------------------------------------
void MrkTests::tryRemoveSnapshot()
{
m_eTestStep = eRemove;
SnapshotRemoveRequest data;
data.id(m_snapshotId);
INFO_LOG(m_logger) << "trying to send remove request for snapshotId:" << data.id();
if (!m_ftc->snapshotRemoveRequest(data, this))
{
ERROR_LOG(m_logger) << "Error requesting remove data for snapshotId:" << data.id();
failExit();
}
} // end of tryRemoveSnapshot()
//-----------------------------------------------------------------------------
void MrkTests::onMarkerCreateReply(const Core::FunctionReplyObject &replyObject)
{
INFO_LOG(m_logger) << "Got createReply with id " << replyObject.id()
<< " and errorString " << replyObject.translated();
m_markerId = replyObject.id();
if (replyObject.error())
{
ERROR_LOG(m_logger) << "Error requesting create data";
failExit();
return;
}
else
DEBUG_LOG(m_logger) << "Requesting create data ok. Got new id:" << replyObject.id() << " ... ok.";
if (m_testId == 0)
// QTimer::singleShot(0, this, &MrkTests::tryModify()));
QTimer::singleShot(0, this, &MrkTests::tryGetMarker);
else
QTimer::singleShot(0, qApp, &QCoreApplication::quit);
} // end of onMarkerCreateReply()
//-----------------------------------------------------------------------------
void MrkTests::onMarkerModifyReply(const Core::FunctionReplyObject &replyObject)
{
if (m_eTestStep == TestStep::eCreate)
return onMarkerCreateReply(replyObject);
INFO_LOG(m_logger) << "Got modifyRequest with id " << replyObject.id()
<< " and errorString " << replyObject.translated();
if (replyObject.error())
{
ERROR_LOG(m_logger) << "Error requesting modify data for id:" << replyObject.id();
failExit();
return;
}
else
DEBUG_LOG(m_logger) << "Requesting modify data for id:" << replyObject.id() << " ... ok.";
if (m_testId == 0)
// QTimer::singleShot(0, this, &MrkTests::tryDelete()));
QTimer::singleShot(0, this, &MrkTests::tryGetMarker);
else
QTimer::singleShot(0, qApp, &QCoreApplication::quit);
} // end of onMarkerModifyReply()
//-----------------------------------------------------------------------------
void MrkTests::onMarkerRemoveReply(const Core::FunctionReplyObject &replyObject)
{
INFO_LOG(m_logger) << "Got removeReply with id " << replyObject.id()
<< " and errorString " << replyObject.translated();
if (replyObject.error())
{
ERROR_LOG(m_logger) << "Error requesting remove data for markerId:" << replyObject.id();
failExit();
return;
}
else
DEBUG_LOG(m_logger) << "Requesting remove data for markerId:" << replyObject.id() << " ... ok.";
if (m_testId == 0)
{
QTimer::singleShot(0, this, &MrkTests::tryCreateSnapshot);
// ansonsten verheriger Ausstieg mit Errorlog.
}
QTimer::singleShot(0, qApp, &QCoreApplication::quit);
} // end of onMarkerRemoveReply()
//-----------------------------------------------------------------------------
void MrkTests::onSnapshotCreateReply(const Core::FunctionReplyObject &replyObject)
{
INFO_LOG(m_logger) << "Got createReply with id " << replyObject.id()
<< " and errorString " << replyObject.translated();
m_snapshotId = replyObject.id();
if (replyObject.error())
{
ERROR_LOG(m_logger) << "Error requesting create data";
failExit();
return;
}
else
DEBUG_LOG(m_logger) << "Requesting create data ok. Got new id:" << replyObject.id() << " ... ok.";
if (m_testId == 0)
QTimer::singleShot(0, this, &MrkTests::tryModifySnapshot);
else
QTimer::singleShot(0, qApp, &QCoreApplication::quit);
} // end of onSnapshotCreateReply()
//-----------------------------------------------------------------------------
void MrkTests::onSnapshotModifyReply(const Core::FunctionReplyObject &replyObject)
{
if (m_eTestStep == TestStep::eCreate)
return onSnapshotCreateReply(replyObject);
INFO_LOG(m_logger) << "Got modifyRequest with id " << replyObject.id()
<< " and errorString " << replyObject.translated();
if (replyObject.error())
{
ERROR_LOG(m_logger) << "Error requesting modify data for id:" << replyObject.id();
failExit();
return;
}
else
DEBUG_LOG(m_logger) << "Requesting modify data for id:" << replyObject.id() << " ... ok.";
if (m_testId == 0)
QTimer::singleShot(0, this, &MrkTests::tryRemoveSnapshot);
else
QTimer::singleShot(0, qApp, &QCoreApplication::quit);
} // end of onSnapshotModifyReply()
//-----------------------------------------------------------------------------
void MrkTests::onSnapshotRemoveReply(const Core::FunctionReplyObject &replyObject)
{
INFO_LOG(m_logger) << "Got removeReply with id " << replyObject.id()
<< " and errorString " << replyObject.translated();
if (replyObject.error())
{
ERROR_LOG(m_logger) << "Error requesting remove data for markerId:" << replyObject.id();
failExit();
return;
}
else
DEBUG_LOG(m_logger) << "Requesting remove data for markerId:" << replyObject.id() << " ... ok.";
if (m_testId == 0)
{
INFO_LOG(m_logger) << "***** FTC/TDC test successfully finished. (used snapshotId:" << replyObject.id() << ") *****";
// ansonsten verheriger Ausstieg mit Errorlog.
}
QTimer::singleShot(0, qApp, &QCoreApplication::quit);
} // end of onSnapshotRemoveReply()
//-----------------------------------------------------------------------------
void MrkTests::onReceiveMarkerChanged(const Marker &data, DataModification modType)
{
// INFO_LOG(m_logger) << "onReceiveMarkerChanged() markerId:" << data.id()
// << " modificationType: = " << (int)modType<< " received";
switch (modType)
{
case DataModification::eAdded:
INFO_LOG(m_logger) << "*** Marker added received. markerId:" << data.id();
break;
case DataModification::eModified:
INFO_LOG(m_logger) << "*** Marker modified received. markerId:" << data.id();
break;
case DataModification::eRemoved:
INFO_LOG(m_logger) << "*** Marker removed received. markerId:" << data.id();
break;
}
} // end of onReceiveMarkerChanged()
//-----------------------------------------------------------------------------
void MrkTests::getMarkerCreateRequestData(MarkerModifyRequest &data)
{
time_t currentTime = time(nullptr);
if (m_testId == 0)
currentTime = currentTime / 10;
data.note("TestMarkerCreate");
data.operatorId(100);
data.timeStamp(currentTime);
data.timeStampOffset(33000);
getMarkerDescriptionCreateRequestData(data);
} // end of getMarkerCreateRequestData()
//-----------------------------------------------------------------------------
void MrkTests::getMarkerDescriptionCreateRequestData(MarkerModifyRequest &data)
{
// Info: FK fuer markerId wird in object_marker gesetzt.
data.descriptions().resize(3);
data.descriptions()[0].markerType(MarkerManagement::MarkerType::Audio);
data.descriptions()[0].content("Audio07, Audio08*, Audio09");
data.descriptions()[1].markerType(MarkerManagement::MarkerType::Video);
data.descriptions()[1].content("cam07, cam08, cam09*");
data.descriptions()[2].markerType(MarkerManagement::MarkerType::Video);
data.descriptions()[2].content("cam06, cam07, cam08, cam09*");
} // end of getMarkerDescriptionCreateRequestData()
//-----------------------------------------------------------------------------
void MrkTests::getMarkerModifyRequestData(MarkerModifyRequest &data)
{
time_t currentTime = time(nullptr);
if (m_testId == 0)
currentTime = currentTime / 10;
data.id(m_markerId);
data.note("TestMarkerModify");
data.operatorId(100);
data.timeStamp(currentTime * 1000);
data.timeStampOffset(77 * 1000);
getMarkerDescriptionCreateRequestData(data);
for (auto &desc : data.descriptions())
desc.content(std::string("+++MOD+++") + desc.content());
} // end of getMarkerModifyRequestData()
//-----------------------------------------------------------------------------
bool MrkTests::onCompareCreatedData(Marker &data)
{
DEBUG_LOG(m_logger) << "start onCompareCreatedData() for id :" << data.id();
// Vergleicht die zurueckgelesen Datan mit den statischen create Daten
MarkerModifyRequest createData;
getMarkerCreateRequestData(createData);
if (createData.note() != data.note())
return false;
if (createData.operatorId() != data.operatorId())
return false;
if (createData.timeStamp() != data.timeStamp())
return false;
if (createData.timeStampOffset() != data.timeStampOffset())
return false;
// Descriptions vergleichen
if (createData.descriptions().size() != data.descriptions().size())
{
ERROR_LOG(m_logger) << "Error onCompareCreatedData() different number of description data.";
failExit();
return false;
}
int foundCount = 0;
for (const auto &expected : createData.descriptions())
{
for (const auto &got : data.descriptions())
{
// we've got one description per type
if (got.markerType() != expected.markerType())
continue;
++foundCount;
if (got.content() != expected.content())
{
ERROR_LOG(m_logger) << "Content for description does not match: "
<< got.content() << " - "
<< expected.content();
failExit();
return false;
}
}
}
if (foundCount != 3)
{
ERROR_LOG(m_logger) << "Did not found all three expected descriptions";
failExit();
return false;
}
DEBUG_LOG(m_logger) << "successfull finished onCompareCreatedData() for id :" << data.id();
return true;
} // end of onCompareCreatedData()
//-----------------------------------------------------------------------------
bool MrkTests::onCompareModifiedData(Marker &data)
{
DEBUG_LOG(m_logger) << "start onCompareModifiedData() for id :" << data.id();
MarkerModifyRequest modifyData;
getMarkerModifyRequestData(modifyData);
if (modifyData.id() != data.id())
return false;
if (modifyData.note() != data.note())
return false;
if (modifyData.operatorId() != data.operatorId())
return false;
if (modifyData.timeStamp() != data.timeStamp())
return false;
if (modifyData.timeStampOffset() != data.timeStampOffset())
return false;
// Alle Descriptions zu dieser MarkerId holen ...
int foundCount = 0;
for (const auto &expected : modifyData.descriptions())
{
for (const auto &got : data.descriptions())
{
// we've got one description per type
if (got.markerType() != expected.markerType())
continue;
++foundCount;
if (got.content() != expected.content())
{
ERROR_LOG(m_logger) << "Content for description does not match: "
<< got.content() << " - "
<< expected.content();
failExit();
return false;
}
}
}
if (foundCount != 3)
{
ERROR_LOG(m_logger) << "Did not found all three expected descriptions";
failExit();
return false;
}
DEBUG_LOG(m_logger) << "successfull finished onCompareModifiedData() for id :" << data.id();
return true;
} // end of onCompareModifiedData()
//-----------------------------------------------------------------------------
void MrkTests::failExit()
{
m_bTestsSuccessful = false;
QTimer::singleShot(0, qApp, &QCoreApplication::quit);
}
//-----------------------------------------------------------------------------
class CmdLineParser : public LtsCommandLineParser::LtsCommandLineParser
{
public:
CmdLineParser()
: LtsCommandLineParser()
{
addOption({ QStringList() << QLatin1String("t") << QLatin1String("testId")
, QLatin1String("TestId.")
, QLatin1String("Default: 0 (all FTC/DTC tests), 1 create, 2 modify, 3 remove, 10 getAllMarker and Descriptions, 11 getMarker")
, QLatin1String("0")
});
addOption({ QStringList() << QLatin1String("m") << QLatin1String("markerId")
, QLatin1String("MarkerId.")
, QLatin1String("Used for tests 2, 3 & 11 only to select the marker")
, QLatin1String("0")
});
addOption({ QStringList() << QLatin1String("s") << QLatin1String("snapshotId")
, QLatin1String("SnapshotId.")
, QLatin1String("Used for tests 4, 5 & 6 only to select the snapshotId")
, QLatin1String("0")
});
}
int testId() const { return isSet(QLatin1String("t")) ? value(QLatin1String("t")).toInt() : -1; }
int markerId() const { return isSet(QLatin1String("m")) ? value(QLatin1String("m")).toInt() : -1; }
int snapshotId() const { return isSet(QLatin1String("s")) ? value(QLatin1String("s")).toInt() : -1; }
};
//-----------------------------------------------------------------------------
int main(int argc, char **argv)
{
NGLCoreApplication app(argc, argv);
app.createLogger("mrk", "log4cxx_mrk_module_tests.props");
int iRet = -1;
CmdLineParser options;
if (!options.init())
return iRet;
std::unique_ptr<MarkerManagement::MrkTests> MrkTests(new MarkerManagement::MrkTests);
if (!MrkTests->init(options.domainId(), options.exerciseId(), options.testId(), options.markerId(), options.snapshotId()))
return iRet;
QTimer::singleShot(2000, MrkTests.get(), &MarkerManagement::MrkTests::startTest);
STARTUP_LOG(app.baseLogger());
app.exec();
iRet = MrkTests->testsSuccessful() ? 0 : 1;
fprintf(stderr, "%d\n", iRet);
DEBUG_LOG(app.baseLogger()) << "** TEST result = " << iRet;
SHUTDOWN_LOG(app.baseLogger());
return iRet;
}
//-----------------------------------------------------------------------------
+112
View File
@@ -0,0 +1,112 @@
/**
* @RDE_HEADER@
*
* EXM Function Topic test executable
*
* ModuleTests for create/modify/remove marker
* ---------------------------------------------------
* Client FTC is implemented
*
* => (!) Preconditon:
* - Service svcMarkerManagent running
*
* -------------------------------------------------
*
* $Id$
* $HeadURL$
* $Author$
* Created by hjl, SLSE, 2016-04-18
*/
#pragma once
#include <MarkerManagement/mrk_ftc.h>
#include <MarkerManagement/mrk_ftc_types.h>
#include <MarkerManagement/mrk_dtc.h>
#include <MarkerManagement/mrk_dtc_types.h>
#include <MarkerManagement/logger.h>
#include <DDS/DDSConnector/dds_connector.h>
namespace MarkerManagement
{
class MrkTests : public QObject
, protected MarkerManagement::Interface::Ftc::MarkerModifyReplyHandler
, protected MarkerManagement::Interface::Ftc::MarkerRemoveReplyHandler
, protected MarkerManagement::Interface::Ftc::SnapshotModifyReplyHandler
, protected MarkerManagement::Interface::Ftc::SnapshotRemoveReplyHandler
{
Q_OBJECT
public:
explicit MrkTests(QObject *parent = nullptr);
~MrkTests();
bool init(int domainId, int exerciseId, int testId, int markerId, int snapshotId);
bool testsSuccessful() const { return m_bTestsSuccessful; }
public Q_SLOTS:
void startTest();
protected Q_SLOTS:
// used to check FTC
void tryCreate();
void tryModify();
void tryRemove();
void tryCreateSnapshot();
void tryModifySnapshot();
void tryRemoveSnapshot();
// used to check DTC
void tryGetAllMarkers();
void tryGetMarker();
// used to check DTC signal/slot connection
void onReceiveMarkerChanged(const Marker &data, DataModification modType);
protected:
// Callbackfunctions for FTC
void onMarkerCreateReply(const Core::FunctionReplyObject &replyObject);
void onMarkerModifyReply(const Core::FunctionReplyObject &replyObject) override final;
void onMarkerRemoveReply(const Core::FunctionReplyObject &replyObject) override final;
void onSnapshotCreateReply(const Core::FunctionReplyObject &replyObject);
void onSnapshotModifyReply(const Core::FunctionReplyObject &replyObject) override final;
void onSnapshotRemoveReply(const Core::FunctionReplyObject &replyObject) override final;
private Q_SLOTS:
bool onCompareCreatedData(Marker &data);
bool onCompareModifiedData(Marker &data);
private:
void getMarkerCreateRequestData(MarkerModifyRequest &data);
void getMarkerModifyRequestData(MarkerModifyRequest &data);
void getMarkerDescriptionCreateRequestData(MarkerModifyRequest &data);
void failExit();
private:
std::shared_ptr<DDSConnector::DdsConnector> m_ddsConnector;
std::shared_ptr<MarkerManagement::Interface::Ftc> m_ftc;
std::shared_ptr<MarkerManagement::Interface::Dtc> m_dtc;
qint32 m_exerciseId;
int m_testId;
int m_markerId;
int m_snapshotId;
enum TestStep
{
eUnknown,
eCreate,
eModify,
eRemove,
eGetAllMarkers,
eGetMarker
} m_eTestStep;
bool m_bTestsSuccessful;
NGL::INGLLogger &m_logger;
};
} // namespace MarkerManagement
+48
View File
@@ -0,0 +1,48 @@
/**
* DdsHandler for DDS
* $Id$
* $HeadURL$
* $Author$
* Created by hjl, SLSE, 2016-04-05
*/
#include "dds_handler.h"
namespace MarkerManagement
{
DdsHandler::DdsHandler(const std::shared_ptr<DDSConnector::DdsConnector> &ddsConnector)
: m_ddsConnector(ddsConnector)
, m_logger(getLogger("DdsHandler"))
{
DEBUG_LOG(m_logger) << "DdsHandler(" << m_ddsConnector->getDomainId() << ") for partition: " << m_ddsConnector->getDefaultPartition();
}
bool DdsHandler::init(const QStringList &qosFileList)
{
INFO_LOG(m_logger) << "--- Start MarkerManagement DDSHandler.";
if (!m_ddsConnector->init(qosFileList))
{
ERROR_LOG(m_logger) << "Error initializing dds connections - aborting";
return false;
}
// default initialize Publisher and Subscriber
m_ddsConnector->initPublisherSubscriber();
m_topicLockMaster = std::make_shared<Core::TopicLockMaster>(m_ddsConnector);
m_ddsDts = MarkerManagement::Interface::Dts::create(m_ddsConnector);
m_ddsFts = MarkerManagement::Interface::Fts::create(m_ddsConnector);
bool bRet = m_ddsDts->enableAll();
INFO_LOG(m_logger) << "Dts initialised";
bRet &= m_ddsFts->enableAll();
INFO_LOG(m_logger) << "Fts initialised";
return bRet;
}
} // Namespace MarkerManagement
+40
View File
@@ -0,0 +1,40 @@
/**
* DdsHandler for DDS
* $Id$
* $HeadURL$
* $Author$
* Created by hjl, SLSE, 2016-04-05
*/
#pragma once
#include <DDS/DDSConnector/dds_connector.h>
#include <DDS/Core/topic_lock_master.h>
#include <MarkerManagement/mrk_dts.h>
#include <MarkerManagement/mrk_fts.h>
#include "logger.h"
namespace MarkerManagement
{
class DdsHandler final
{
public:
explicit DdsHandler(const std::shared_ptr<DDSConnector::DdsConnector> &ddsConnector);
~DdsHandler() = default;
bool init(const QStringList &qosFileList = QStringList());
std::shared_ptr<Core::TopicLockMaster> topicLockMaster() const { return m_topicLockMaster; }
std::shared_ptr<DDSConnector::DdsConnector> ddsConnector() const { return m_ddsConnector; }
std::shared_ptr<MarkerManagement::Interface::Dts> dts() const { return m_ddsDts; }
std::shared_ptr<MarkerManagement::Interface::Fts> fts() const { return m_ddsFts; }
private:
std::shared_ptr<DDSConnector::DdsConnector> m_ddsConnector;
std::shared_ptr<Core::TopicLockMaster> m_topicLockMaster;
std::shared_ptr<MarkerManagement::Interface::Dts> m_ddsDts;
std::shared_ptr<MarkerManagement::Interface::Fts> m_ddsFts;
NGL::INGLLogger &m_logger;
};
} // namespace MarkerManagement
+166
View File
@@ -0,0 +1,166 @@
/**
* Handler for all marker objects
* $Id$
* $HeadURL$
* $Author$
* Created by hjl, SLSE, 2016-04-12
*/
#include "handler_marker.h"
#include "object_marker.h"
#include "dds_handler.h"
namespace MarkerManagement
{
HandlerMarker::HandlerMarker(const std::shared_ptr<DdsHandler> &ddsHandler,
const std::shared_ptr<DatabaseInterface> &db)
: Interface::Fts::MarkerModifyRequestHandler(ddsHandler->fts())
, Interface::Fts::MarkerRemoveRequestHandler(ddsHandler->fts())
, m_ddsHandler(ddsHandler)
, m_db(db)
, m_logger(getLogger("HandlerMarker"))
{
} // end of ctor()
//-----------------------------------------------------------------------------
HandlerMarker::~HandlerMarker()
{
qDeleteAll(m_objectMarkerMap);
} // end of dtor()
//-----------------------------------------------------------------------------
bool HandlerMarker::init()
{
INFO_LOG(m_logger) << "--- Start MarkerManagement HandlerMarker.";
QVector<Database::MrkMarkerDescription> dataDescriptionVec;
// read all marker from database
if (!m_db->select(dataDescriptionVec))
{
ERROR_LOG(m_logger) << "Error reading data from database!";
return false;
}
// create markerObjects
bool bRet = true;
auto cb = [this, &bRet, &dataDescriptionVec] (const Database::MrkMarker &data)
{
Marker ddsMoData = ObjectMarker::toDdsData(data);
// alle Descriptions zu der Marke eintragen
// TODO: select descBymarkerId
for (const Database::MrkMarkerDescription &desc : qAsConst(dataDescriptionVec))
{
if (desc.markerId == ddsMoData.id())
ddsMoData.descriptions().push_back(ObjectMarker::toDdsData(desc));
}
ObjectMarker *ifs(new ObjectMarker(m_ddsHandler, m_db));
Core::FunctionReplyObject ret = ifs->createObject(ddsMoData);
if (ret.error())
{
delete ifs;
ERROR_LOG(m_logger) << ret();
bRet = false;
return;
}
m_objectMarkerMap.insert(ifs->getId(), ifs);
};
if (!m_db->select(cb) || !bRet)
{
ERROR_LOG(m_logger) << "Error reading data from database!";
return false;
}
DEBUG_LOG(m_logger) << "m_objectMarkerMap.size() = " << m_objectMarkerMap.size();
if (m_ddsHandler->fts() == nullptr)
{
ERROR_LOG(m_logger) << "m_ddsHandler->fts() == nullptr!";
return false;
}
return true;
} // end of init()
//-----------------------------------------------------------------------------
void HandlerMarker::onMarkerModifyRequest(const rti::core::SampleIdentity &cookie,
const Marker &request)
{
DEBUG_LOG(m_logger) << "MarkerModifyRequest: " << request;
auto ret = request.id() > 0 ? markerModifyRequest(request) : markerCreateRequest(request);
if (ret.error())
WARNING_LOG(m_logger) << ret();
m_ddsHandler->fts()->markerModifyReply(cookie, ret);
}
//-----------------------------------------------------------------------------
Core::FunctionReplyObject HandlerMarker::markerCreateRequest(const Marker &request)
{
if (m_objectMarkerMap.size() > 5000)
return Core::FunctionReplyObject(tr_lts("dds", "Can not create more than 5000 marker."));
ObjectMarker *ifs(new ObjectMarker(m_ddsHandler, m_db));
const Core::FunctionReplyObject ret = ifs->createObject(request);
if (ret.error())
{
delete ifs;
return ret;
}
m_objectMarkerMap.insert(ifs->getId(), ifs);
return ret;
} // end of onMarkerCreateRequest()
//-----------------------------------------------------------------------------
Core::FunctionReplyObject HandlerMarker::markerModifyRequest(const Marker &request)
{
ObjectMarker *ifs = m_objectMarkerMap.value(request.id());
if (ifs == nullptr)
return Core::FunctionReplyObject(request.id(),
tr_lts("dds", "Marker with id %1 not found")).arg(request.id());
return ifs->updateObject(request);
} // end of markerModifyRequest()
//-----------------------------------------------------------------------------
void HandlerMarker::onMarkerRemoveRequest(const rti::core::SampleIdentity &cookie,
const Core::RemoveElementRequest &request)
{
DEBUG_LOG(m_logger) << "MarkerRemoveRequest: " << request;
auto ret = markerRemoveRequest(request);
if (ret.error())
WARNING_LOG(m_logger) << ret();
m_ddsHandler->fts()->markerRemoveReply(cookie, ret);
}
//-----------------------------------------------------------------------------
Core::FunctionReplyObject HandlerMarker::markerRemoveRequest(const Core::RemoveElementRequest &request)
{
ObjectMarker *ifs = m_objectMarkerMap.value(request.id());
if (ifs == nullptr)
return Core::FunctionReplyObject(request.id(),
tr_lts("dds", "Marker with id %1 not found")).arg(request.id());
if (m_ddsHandler->topicLockMaster()->isLocked(ifs->getData(), m_ddsHandler->ddsConnector()->getPartitionId()))
return Core::FunctionReplyObject(request.id(), tr_lts("dds", "Marker '%1' is used by another user!")).arg(ifs->getName());
const Core::FunctionReplyObject ret = ifs->removeObject();
if (ret.error())
return ret;
// delete ObjectMarker
delete ifs;
m_objectMarkerMap.remove(request.id());
return ret;
} // end of onMarkerRemoveRequest()
//-----------------------------------------------------------------------------
} // namespace MarkerManagement
+50
View File
@@ -0,0 +1,50 @@
/**
* Handler for all marker objects
* $Id$
* $HeadURL$
* $Author$
* Created by hjl, SLSE, 2016-04-12
*/
#pragma once
#include "dds_handler.h"
#include <MarkerManagement/mrk_db.h>
namespace MarkerManagement
{
// Forwarddeclarations
class DdsHandler;
class ObjectMarker;
class HandlerMarker final
: protected Interface::Fts::MarkerModifyRequestHandler
, protected Interface::Fts::MarkerRemoveRequestHandler
{
public:
explicit HandlerMarker(const std::shared_ptr<DdsHandler> &ddsHandler,
const std::shared_ptr<DatabaseInterface> &db);
~HandlerMarker();
bool init();
private: // methods
void onMarkerModifyRequest(const rti::core::SampleIdentity &cookie,
const Marker &request) override final;
Core::FunctionReplyObject markerCreateRequest(const Marker &request);
Core::FunctionReplyObject markerModifyRequest(const Marker &request);
void onMarkerRemoveRequest(const rti::core::SampleIdentity &cookie,
const Core::RemoveElementRequest &request) override final;
Core::FunctionReplyObject markerRemoveRequest(const Core::RemoveElementRequest &request);
private: // attributes
std::shared_ptr<DdsHandler> m_ddsHandler;
std::shared_ptr<DatabaseInterface> m_db;
NGL::INGLLogger &m_logger;
QHash<int, ObjectMarker *> m_objectMarkerMap;
};
} // namespace MarkerManagement
+152
View File
@@ -0,0 +1,152 @@
/**
* Handler for all marker objects
* $Id$
* $HeadURL$
* $Author$
* Created by hjl, SLSE, 2016-04-12
*/
#include "handler_snapshot.h"
#include "object_snapshot.h"
#include "dds_handler.h"
namespace MarkerManagement
{
HandlerSnapshot::HandlerSnapshot(const std::shared_ptr<DdsHandler> &ddsHandler,
const std::shared_ptr<DatabaseInterface> &db)
: Interface::Fts::SnapshotModifyRequestHandler(ddsHandler->fts())
, Interface::Fts::SnapshotRemoveRequestHandler(ddsHandler->fts())
, m_ddsHandler(ddsHandler)
, m_db(db)
, m_logger(getLogger("HandlerSnapshot"))
{
} // end of ctor()
//-----------------------------------------------------------------------------
HandlerSnapshot::~HandlerSnapshot()
{
qDeleteAll(m_objectSnapshotMap);
} // end of dtor()
//-----------------------------------------------------------------------------
bool HandlerSnapshot::init()
{
INFO_LOG(m_logger) << "--- Start MarkerManagement HandlerSnapshot.";
bool bRet = true;
// create markerObjects
auto cb = [this, &bRet] (const Database::MrkSnapshot &data)
{
Snapshot ddsData = ObjectSnapshot::toDdsData(data);
ObjectSnapshot *ifs(new ObjectSnapshot(m_ddsHandler, m_db));
Core::FunctionReplyObject ret = ifs->createObject(ddsData);
if (ret.error())
{
delete ifs;
ERROR_LOG(m_logger) << ret();
bRet = false;
return;
}
m_objectSnapshotMap.insert(ifs->getId(), ifs);
};
if (!m_db->select(cb) || !bRet)
{
ERROR_LOG(m_logger) << "Error reading data from database!";
return false;
}
DEBUG_LOG(m_logger) << "m_objectSnapshotMap.size() = " << m_objectSnapshotMap.size();
return true;
} // end of init()
//-----------------------------------------------------------------------------
void HandlerSnapshot::onSnapshotModifyRequest(const rti::core::SampleIdentity &cookie,
const Snapshot &request)
{
DEBUG_LOG(m_logger) << "SnapshotModifyRequest: " << request;
auto ret = request.id() > 0 ? snapshotModifyRequest(request) : snapshotCreateRequest(request);
if (ret.error())
WARNING_LOG(m_logger) << ret();
m_ddsHandler->fts()->snapshotModifyReply(cookie, ret);
} // end of onSnapshotModifyRequest()
//-----------------------------------------------------------------------------
Core::FunctionReplyObject HandlerSnapshot::snapshotCreateRequest(const Snapshot &request)
{
ObjectSnapshot *ifs(new ObjectSnapshot(m_ddsHandler, m_db));
Core::FunctionReplyObject ret = ifs->createObject(request);
if (ret.error())
delete ifs;
else
m_objectSnapshotMap.insert(ifs->getId(), ifs);
return ret;
} // end of onSnapshotCreateRequest()
//-----------------------------------------------------------------------------
Core::FunctionReplyObject HandlerSnapshot::snapshotModifyRequest(const Snapshot &request)
{
ObjectSnapshot *ifs = m_objectSnapshotMap.value(request.id());
if (ifs == nullptr)
return Core::FunctionReplyObject(request.id(), tr_lts("dds", "Snapshot with id %1 not found")).arg(request.id());
Snapshot ddsData = ifs->getData();
ddsData.name(request.name());
ddsData.description(request.description());
ddsData.fileContentId(request.fileContentId());
if (request.mapSettings().size() > 0)
ddsData.mapSettings(request.mapSettings());
if (request.movementTracks().size() > 0)
ddsData.movementTracks(request.movementTracks());
if (request.planOverlay().size() > 0)
ddsData.planOverlay(request.planOverlay());
if (request.filter().size() > 0)
ddsData.filter(request.filter());
return ifs->updateObject(ddsData);
} // end of onSnapshotModifyRequest()
//-----------------------------------------------------------------------------
void HandlerSnapshot::onSnapshotRemoveRequest(const rti::core::SampleIdentity &cookie,
const Core::RemoveElementRequest &request)
{
DEBUG_LOG(m_logger) << "onSnapshotRemoveRequest() id:" << request.id();
Core::FunctionReplyObject ret;
ObjectSnapshot *ifs = m_objectSnapshotMap.value(request.id());
if (ifs == nullptr)
ret = Core::FunctionReplyObject(request.id(), tr_lts("dds", "Snapshot with id %1 not found")).arg(request.id());
else
{
if (m_ddsHandler->topicLockMaster()->isLocked(ifs->getData(), m_ddsHandler->ddsConnector()->getPartitionId()))
{
ret = Core::FunctionReplyObject(request.id(), tr_lts("dds", "Snapshot '%1' is used by another user!")).arg(ifs->getName());
m_ddsHandler->fts()->snapshotRemoveReply(cookie, ret);
return;
}
ret = ifs->removeObject();
}
if (ret.error())
ERROR_LOG(m_logger) << ret();
else
{
// delete ObjectSnapshot
delete ifs;
m_objectSnapshotMap.remove(request.id());
}
m_ddsHandler->fts()->snapshotRemoveReply(cookie, ret);
} // end of onSnapshotRemoveRequest()
//-----------------------------------------------------------------------------
} // namespace MarkerManagement
+49
View File
@@ -0,0 +1,49 @@
/**
* Handler for all marker objects
* $Id$
* $HeadURL$
* $Author$
* Created by hjl, SLSE, 2016-04-12
*/
#pragma once
#include "dds_handler.h"
#include <MarkerManagement/mrk_db.h>
namespace MarkerManagement
{
// Forwarddeclarations
class DdsHandler;
class ObjectSnapshot;
class HandlerSnapshot final
: protected Interface::Fts::SnapshotModifyRequestHandler
, protected Interface::Fts::SnapshotRemoveRequestHandler
{
public:
explicit HandlerSnapshot(const std::shared_ptr<DdsHandler> &ddsHandler,
const std::shared_ptr<DatabaseInterface> &db);
~HandlerSnapshot();
bool init();
private: // methods
void onSnapshotModifyRequest(const rti::core::SampleIdentity &cookie,
const Snapshot &request) override final;
Core::FunctionReplyObject snapshotCreateRequest(const Snapshot &request);
Core::FunctionReplyObject snapshotModifyRequest(const Snapshot &request);
void onSnapshotRemoveRequest(const rti::core::SampleIdentity &cookie,
const Core::RemoveElementRequest &request) override final;
private: // attributes
std::shared_ptr<DdsHandler> m_ddsHandler;
std::shared_ptr<DatabaseInterface> m_db;
NGL::INGLLogger &m_logger;
QHash<int, ObjectSnapshot *> m_objectSnapshotMap;
};
} // namespace MarkerManagement
+90
View File
@@ -0,0 +1,90 @@
/**
* Initialization for MarkerManagement
* $Id$
* $HeadURL$
* $Author$
* Created by hjl, SLSE, 2016-04-05
*/
#include "initialization.h"
#include "handler_marker.h"
#include "handler_snapshot.h"
#include "settings.h"
#include <DDS/DDSConnector/dds_connector.h>
#include <ngldb/db_service_handler.h>
namespace MarkerManagement
{
Initialization::Initialization()
: m_logger(getLogger("Initialization"))
{
} // end of ctor()
//-----------------------------------------------------------------------------
Initialization::~Initialization()
{
m_handlerMarker = nullptr;
m_handlerSnapshot = nullptr;
m_dbHandler = nullptr;
m_ddsHandler = nullptr;
} // end of dtor()
//-----------------------------------------------------------------------------
bool Initialization::initialize(const std::shared_ptr<DDSConnector::DdsConnector> &ddsConnector, const QSqlDatabase &sqlDb)
{
INFO_LOG(m_logger) << "--- Start MarkerManagement Initialization.";
// initialize DDS
// for MarkerManagement => exerciseId = partitionId
m_ddsHandler = std::make_shared<DdsHandler>(ddsConnector);
if (!m_ddsHandler->init())
{
ERROR_LOG(m_logger) << "Initialisation DdsHandler failed.";
return false;
}
// initialize database
m_dbHandler = std::make_shared<DbHandler>();
if (!m_dbHandler->init(ddsConnector->getPartitionId(), sqlDb))
{
ERROR_LOG(m_logger) << "Initialisation dbHandler failed.";
return false;
}
// read project specific data from database
// publish project specific data
// initialize handler
m_handlerMarker.reset(new HandlerMarker(m_ddsHandler, m_dbHandler->db()));
m_handlerSnapshot.reset(new HandlerSnapshot(m_ddsHandler, m_dbHandler->db()));
INFO_LOG(m_logger) << "MRK Handler initialized.";
return true;
} // end of initialize()
//-----------------------------------------------------------------------------
bool Initialization::loadFromDatabase()
{
if (!m_handlerMarker || !m_handlerMarker->init())
{
ERROR_LOG(m_logger) << "Initialisation HandlerMarker failed.";
return false;
}
if (!m_handlerSnapshot || !m_handlerSnapshot->init())
{
ERROR_LOG(m_logger) << "Initialisation HandlerSnapshot failed.";
return false;
}
INFO_LOG(m_logger) << "MRK Handler initialized.";
return true;
} // end of loadFromDatabase()
//-----------------------------------------------------------------------------
} // namespace MarkerManagement
+48
View File
@@ -0,0 +1,48 @@
/**
* MainHandler for MarkerManagement
* $Id$
* $HeadURL$
* $Author$
* Created by hjl, SLSE, 2016-04-05
*/
#pragma once
#include <MarkerManagement/mrk_db.h>
#include "logger.h"
namespace NGLDB
{
template <typename DB> class DbServiceHandler;
}
namespace DDSConnector
{
class DdsConnector;
}
namespace MarkerManagement
{
using DbHandler = NGLDB::DbServiceHandler<DatabaseInterface>;
class DdsHandler;
class HandlerMarker;
class HandlerSnapshot;
class MRK_SERVER_EXPORT Initialization final
{
public:
Initialization();
~Initialization();
bool initialize(const std::shared_ptr<DDSConnector::DdsConnector> &ddsConnector, const QSqlDatabase &sqlDb);
bool loadFromDatabase();
private: // attributes
std::shared_ptr<DbHandler> m_dbHandler;
std::shared_ptr<DdsHandler> m_ddsHandler;
std::unique_ptr<HandlerMarker> m_handlerMarker;
std::unique_ptr<HandlerSnapshot> m_handlerSnapshot;
NGL::INGLLogger &m_logger;
};
} // namespace MarkerManagement
+36
View File
@@ -0,0 +1,36 @@
/**
* Building Config - logging facility
* $Id$
* $HeadURL$
* $Author$
* Created by hjl, SLSE, 2016-04-05
*/
#include "logger.h"
#include <NGLLogger/NGLLoggerBootstrap.h>
namespace MarkerManagement
{
LOGGER_T getLogger(const char *name)
{
static const char ns[] = "MRK.";
std::string loggerName;
const size_t len = strlen(name);
loggerName.reserve(sizeof(ns) + len);
loggerName.append(ns, sizeof(ns) - 1);
loggerName.append(name, len);
try
{
return NGL::NGLLoggerBootstrap::getNGLRootLogger().
getNGLLogger(loggerName);
}
catch (const std::exception &ex)
{
fprintf(stderr, "Error retrieving logger: %s", ex.what());
abort();
}
}
} // namespace MarkerManagement
+23
View File
@@ -0,0 +1,23 @@
/**
* Logging for MarkerManagement
* $Id$
* $HeadURL$
* $Author$
* Created by hjl, SLSE, 2016-04-05
*/
#pragma once
#include <NGLLogger/INGLLogger.h>
#include "mrk_export.h"
namespace MarkerManagement
{
using LOGGER_T = NGL::INGLLogger &;
MRK_COMMON_EXPORT LOGGER_T getLogger(const char *name);
inline LOGGER_T getLogger(const QString &loggerName)
{
return getLogger(loggerName.toUtf8().constData());
}
} // namespace MarkerManagement
+52
View File
@@ -0,0 +1,52 @@
/**
* Export definitions
* $Id$
* $HeadURL$
* $Author$
* Created by Hanna E. Rathje, SLSE, 2015-08-04
*/
#pragma once
#include <QtCore/qglobal.h>
#ifndef MRK_COMMON_EXPORT
# ifdef BUILD_STATIC_LIBRARIES
# define MRK_COMMON_EXPORT
# else
# if defined(MAKE_SVCMRKCOMMON_LIB)
# define MRK_COMMON_EXPORT Q_DECL_EXPORT
# ifndef WIN32
# ifdef NDDSUSERDllExport
# undef NDDSUSERDllExport
# endif
# define NDDSUSERDllExport Q_DECL_EXPORT
# endif
# else
# define MRK_COMMON_EXPORT Q_DECL_IMPORT
# endif
# endif
#endif
#ifndef MRK_CLIENT_EXPORT
# ifdef BUILD_STATIC_LIBRARIES
# define MRK_CLIENT_EXPORT
# else
# if defined(MAKE_SVCMRKCLIENT_LIB)
# define MRK_CLIENT_EXPORT Q_DECL_EXPORT
# else
# define MRK_CLIENT_EXPORT Q_DECL_IMPORT
# endif
# endif
#endif
#ifndef MRK_SERVER_EXPORT
# ifdef BUILD_STATIC_LIBRARIES
# define MRK_SERVER_EXPORT
# else
# if defined(MAKE_SVCMRKSERVER_LIB)
# define MRK_SERVER_EXPORT Q_DECL_EXPORT
# else
# define MRK_SERVER_EXPORT Q_DECL_IMPORT
# endif
# endif
#endif
+145
View File
@@ -0,0 +1,145 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<service namespace="MarkerManagement" abbreviation="MRK" procNames="MarkerManagement" exerciseDependency="Exercise">
<rcs>
<Id Id="$Id$"/>
<HeadURL HeadURL="$HeadURL$"/>
<Author Author="$Author$"/>
</rcs>
<operatorRights offset="20">
<guiPlugin name="MarkerManagement" offset="1">
<operatorRightGroup name="Marker Management" description="Edit/Create Marker">
<operatorRight right="MarkerEdit" value="1" description="Edit/Create Marker"/>
<operatorRight right="MarkerShow" value="2" description="Show Marker"/>
</operatorRightGroup>
<operatorRightGroup name="Snapshots" description="Edit/Create Snapshots">
<operatorRight right="SnapshotEdit" value="3" description="Edit/Create Snapshots"/>
<operatorRight right="SnapshotShow" value="4" description="Show Snapshots"/>
</operatorRightGroup>
</guiPlugin>
</operatorRights>
<tables>
<table name="mrk_marker">
<column name="id" datatype="integer" isPrimaryKey="1">
<sequence start="1" increment="1"/>
</column>
<column name="note" datatype="text" comment="Describes the reason of the marker"/>
<column name="operator_id" datatype="bigint" isForeignKey="1"/>
<column name="time_stamp" datatype="bigint" comment="Time on which the mark was set"/>
<column name="time_stamp_offset" datatype="bigint" comment="Offset to timestamp, used to get history of the marked event."/>
<column name="map_settings" datatype="text"/>
<column name="filter" datatype="text"/>
<column name="position" datatype="point_2d"/>
<column name="file_content_id" datatype="bigint"/>
<constraint name="UQ_mrk_marker_id" type="unique">
<column name="id"/>
</constraint>
<foreignKey name="FK_mrk_marker_opm_operator">
<source table="mrk_marker" column="operator_id"/>
<destination service="OperatorManagement" serviceAbbr="opm" schema="opm" table="opm_operator" column="id"/>
</foreignKey>
</table>
<table name="mrk_marker_description">
<column name="id" datatype="integer" isPrimaryKey="1">
<sequence start="1" increment="1"/>
</column>
<column name="marker_id" datatype="integer" isForeignKey="1"/>
<column name="marker_type_id" datatype="integer" isForeignKey="1"/>
<column name="content" datatype="text" comment="Contains the name of the available devices eg. CAM07, CAM08*, TVC01, TVC02... The asterisk denotes the name for this data set. For each record is only one asterisk possible."/>
<constraint name="UQ_mrk_marker_description_id" type="unique">
<column name="id"/>
</constraint>
<constraint name="IDX_mrk_marker_description_marker_id" type="index">
<column name="marker_id"/>
</constraint>
<foreignKey name="FK_mrk_marker_description_mrk_marker_type">
<source table="mrk_marker_description" column="marker_type_id"/>
<destination table="mrk_marker_type" column="id"/>
</foreignKey>
<foreignKey name="FK_mrk_marker_description_mrk_marker">
<source table="mrk_marker_description" column="marker_id"/>
<destination table="mrk_marker" column="id"/>
</foreignKey>
</table>
<table name="mrk_marker_type">
<column name="id" datatype="integer" isPrimaryKey="1">
<sequence start="1" increment="1"/>
</column>
<column name="name" datatype="text" comment="Contains the name of the MarkerType"/>
<constraint name="UQ_marker_type_id" type="unique">
<column name="id"/>
</constraint>
</table>
<table name="mrk_snapshot">
<column name="id" datatype="bigint" isPrimaryKey="1">
<sequence start="1" increment="1"/>
</column>
<column name="name" datatype="text"/>
<column name="description" datatype="text"/>
<column name="file_content_id" datatype="bigint"/>
<column name="map_settings" datatype="text"/>
<column name="movement_tracks" datatype="text"/>
<column name="operator_id" datatype="bigint" isForeignKey="1"/>
<column name="time_stamp" datatype="bigint"/>
<column name="filter" datatype="text"/>
<column name="plan_overlay" datatype="text"/>
<foreignKey name="FK_mrk_snapshot_opm_operator">
<source table="mrk_snapshot" column="operator_id"/>
<destination service="OperatorManagement" serviceAbbr="opm" schema="opm" table="opm_operator" column="id"/>
</foreignKey>
</table>
</tables>
<views/>
<dbServiceStructs>
<serviceStruct name="MrkMarker" table="mrk_marker"/>
<serviceStruct name="MrkMarkerDescription" table="mrk_marker_description"/>
<serviceStruct name="MrkSnapshot" table="mrk_snapshot"/>
<table name="mrk_marker_type"/>
<table name="mrk_marker"/>
<table name="mrk_marker_description"/>
<table name="mrk_snapshot"/>
</dbServiceStructs>
<topicTypes>
<topicType name="Marker" isDataObject="1" routeToClient="1" routeToServer="0" routeInReplay="1" baseValueType="Core::BaseEntity">
<column name="note" idlType="string" comment="Describes the reason of the marker"/>
<column name="operatorId" idlType="long"/>
<column name="timeStamp" idlType="long long"/>
<column name="timeStampOffset" idlType="long long"/>
<column name="descriptions" idlType="sequence&lt;MarkerDescription&gt;"/>
<column name="mapSettings" idlType="string"/>
<column name="filter" idlType="string"/>
<column name="position" idlType="Core::GeoPosition"/>
<column name="fileContentId" idlType="long long"/>
</topicType>
<topicType name="MarkerDescription">
<column name="id" idlType="long" comment="FK marker"/>
<column name="markerType" idlType="MarkerType"/>
<column name="content" idlType="string"/>
</topicType>
<topicType name="Snapshot" isDataObject="1" routeToClient="1" routeToServer="0" routeInReplay="1" baseValueType="Core::BaseEntity">
<column name="description" idlType="string"/>
<column name="fileContentId" idlType="long long"/>
<column name="mapSettings" idlType="string"/>
<column name="movementTracks" idlType="string"/>
<column name="operatorId" idlType="long"/>
<column name="timeStamp" idlType="long long"/>
<column name="filter" idlType="string"/>
<column name="planOverlay" idlType="string"/>
</topicType>
</topicTypes>
<functionTopics>
<functionTopic name="MarkerModify" requestTopicType="Marker" replyTopicType="Core::FunctionReply" requestTopicName="MarkerModifyRequest" replyTopicName="MarkerModifyReply" routeInReplay="1"/>
<functionTopic name="MarkerRemove" requestTopicType="Core::RemoveElementRequest" replyTopicType="Core::FunctionReply" requestTopicName="MarkerRemoveRequest" replyTopicName="MarkerRemoveReply" routeInReplay="1"/>
<functionTopic name="SnapshotModify" requestTopicType="Snapshot" replyTopicType="Core::FunctionReply" requestTopicName="SnapshotModifyRequest" replyTopicName="SnapshotModifyReply" routeInReplay="1"/>
<functionTopic name="SnapshotRemove" requestTopicType="Core::RemoveElementRequest" replyTopicType="Core::FunctionReply" requestTopicName="SnapshotRemoveRequest" replyTopicName="SnapshotRemoveReply" routeInReplay="1"/>
</functionTopics>
<customDtcFunctions>
<customDtcFunction/>
</customDtcFunctions>
<enumerations>
<enumeration name="MarkerType" table="mrk_marker_type">
<attribute key="Situation" value="1"/>
<attribute key="Audio" value="2"/>
<attribute key="Video" value="4"/>
</enumeration>
</enumerations>
</service>
+269
View File
@@ -0,0 +1,269 @@
/**
* Marker object
* $Id$
* $HeadURL$
* $Author$
* Created by hjl, SLSE, 2016-04-12
*/
#include "object_marker.h"
#include "dds_handler.h"
#include <ngldb/dbtransaction.h>
namespace MarkerManagement
{
ObjectMarker::ObjectMarker(const std::shared_ptr<DdsHandler> &ddsHandler, const std::shared_ptr<DatabaseInterface> &db)
: m_ddsHandler(ddsHandler)
, m_db(db)
, m_logger(getLogger("ObjectMarker"))
{
} // end of ctor()
//-----------------------------------------------------------------------------
ObjectMarker::~ObjectMarker()
{
m_ddsHandler->dts()->removeMarkerByKey(m_dataMarkerObject.id());
} // end of dtor()
//-----------------------------------------------------------------------------
Core::FunctionReplyObject ObjectMarker::createObject(const Marker &data)
{
m_dataMarkerObject = data;
if (data.id() <= 0)
{
Database::MrkMarker dbDataMarker = toDbData(data);
DBTransaction trans(m_db->database());
if (!m_db->insert(dbDataMarker))
return Core::FunctionReplyObject(0, tr_lts("dds", "Error inserting MrkMarker-data into database"));
// Neue DB Id in lokale Struktur uebernehmen
m_dataMarkerObject.id(dbDataMarker.id);
DEBUG_LOG(m_logger) << "New MarkerId: " << dbDataMarker.id;
DEBUG_LOG(m_logger) << "Handle MarkerDescription for markerId:" << dbDataMarker.id << " number of depending descriptions: " << data.descriptions().size();
// Behandlung von MarkerDescription
for (size_t i = 0; i < data.descriptions().size(); ++i)
{
MarkerDescription &mrkDesc = m_dataMarkerObject.descriptions()[i];
Database::MrkMarkerDescription dbDataDesc = toDbData(mrkDesc);
// Struct MarkerDescription vorbereiten
dbDataDesc.markerId = dbDataMarker.id; // FK auf MarkerId
dbDataDesc.id = 0;
if (!m_db->insert(dbDataDesc))
return Core::FunctionReplyObject(0, tr_lts("dds", "Error inserting MarkerDescription-data into database"));
// Neue DB Id in lokale Struktur uebernehmen
mrkDesc.id(dbDataDesc.id);
}
trans.commit();
}
// Publish Data via DTS
onPublishData();
return Core::FunctionReplyObject(m_dataMarkerObject.id());
} // end of createObject()
//-----------------------------------------------------------------------------
Core::FunctionReplyObject ObjectMarker::updateObject(const Marker &data)
{
if (!isValid())
return Core::FunctionReplyObject(data.id(), tr_lts("dds", "Object not valid/blocked"));
const Database::MrkMarker dbDataMarker = toDbData(data);
auto newData = data;
DBTransaction trans(m_db->database());
if (!m_db->update(dbDataMarker))
return Core::FunctionReplyObject(data.id(), tr_lts("dds", "Error updating MrkMarker-data into database"));
DEBUG_LOG(m_logger) << "Data changed for markerId: " << m_dataMarkerObject.id();
INFO_LOG(m_logger) << "Handle MarkerDescriptions for markerId:" << data.id()
<< ". Number of pending descriptions (new/previous):"
<< data.descriptions().size() << "/" << m_dataMarkerObject.descriptions().size();
// Descriptions mit id -> schon vorhanden
// Desctiptions ohne id -> neu einfügen
for (auto &desc : newData.descriptions())
{
Database::MrkMarkerDescription dbDesc = toDbData(desc);
dbDesc.markerId = dbDataMarker.id; // FK auf MarkerId
if (desc.id() > 0)
{
// immer update ...
if (!m_db->update(dbDesc))
return Core::FunctionReplyObject(data.id(), tr_lts("dds", "Error updating MrkMarkerDescription-data into database"));
}
else
{
if (!m_db->insert(dbDesc))
return Core::FunctionReplyObject(data.id(), tr_lts("dds", "Error inserting MarkerDescription-data into database"));
desc.id(dbDesc.id);
}
}
// jetzt noch prüfen ob ggf. etwas rausgefallen ist
for (const auto &oldDesc : m_dataMarkerObject.descriptions())
{
bool bFound = false;
for (const auto &newDesc : newData.descriptions())
{
if (newDesc.id() == oldDesc.id())
{
bFound = true;
break;
}
}
if (!bFound)
{
DEBUG_LOG(m_logger) << "Description with id " << oldDesc.id() << " was removed - removing from db";
if (!m_db->removeMrkMarkerDescription(oldDesc.id()))
return Core::FunctionReplyObject(data.id(),
tr_lts("dds", "MarkerDescription with id %1 can not be removed"))
.arg(oldDesc.id());
}
}
trans.commit();
m_dataMarkerObject = newData;
// Publish Data via DTS
onPublishData();
return Core::FunctionReplyObject(m_dataMarkerObject.id());
} // end of updateObject()
//-----------------------------------------------------------------------------
Core::FunctionReplyObject ObjectMarker::removeObject()
{
if (isUsed())
return Core::FunctionReplyObject(m_dataMarkerObject.id(), tr_lts("dds", "Marker still in use"));
// MarkerDescription werden automatisch entfernt (ON DELETE CASCADE)
if (!m_db->removeMrkMarker(m_dataMarkerObject.id()))
return Core::FunctionReplyObject(m_dataMarkerObject.id(), tr_lts("dds", "Marker with id %1 can not be removed")).arg(m_dataMarkerObject.id());
m_ddsHandler->dts()->removeMarkerByKey(m_dataMarkerObject.id());
return Core::FunctionReplyObject(m_dataMarkerObject.id());
} // end of removeObject()
//-----------------------------------------------------------------------------
Core::FunctionReplyObject ObjectMarker::setUsed(bool isUsed)
{
if (!isValid())
return Core::FunctionReplyObject(m_dataMarkerObject.id(), tr_lts("dds", "Trying to update an already removed Marker object"));
m_dataMarkerObject.isUsed(isUsed);
// Publish Data via DTS
onPublishData();
return Core::FunctionReplyObject(m_dataMarkerObject.id());
} // end of setUsed()
//-----------------------------------------------------------------------------
bool ObjectMarker::isValid() const
{
return m_dataMarkerObject.id() > 0;
} // end of isValid()
//-----------------------------------------------------------------------------
bool ObjectMarker::isUsed() const
{
return m_dataMarkerObject.isUsed();
} // end of isUsed()
//-----------------------------------------------------------------------------
void ObjectMarker::onPublishData()
{
INFO_LOG(m_logger) << "Publish MrkMarker-data to dds markerId:" << m_dataMarkerObject.id() ;
if (!m_ddsHandler->dts()->publish(m_dataMarkerObject))
WARNING_LOG(m_logger) << "Error publishing MrkMarker-data to dds";
} // end of onPublishData()
//-----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
// convert methods
// ----------------------------------------------------------------------------
// MarkerManagement::Marker => Database::MrkMarker
Database::MrkMarker ObjectMarker::toDbData(const Marker &ddsData)
{
Database::MrkMarker dbData;
dbData.id = ddsData.id();
dbData.operatorId = ddsData.operatorId();
dbData.note = QString::fromStdString(ddsData.note());
dbData.timeStamp = ddsData.timeStamp();
dbData.timeStampOffset = ddsData.timeStampOffset();
dbData.mapSettings = QString::fromStdString(ddsData.mapSettings());
dbData.filter = QString::fromStdString(ddsData.filter());
dbData.position.setX(ddsData.position().lon());
dbData.position.setY(ddsData.position().lat());
dbData.fileContentId = ddsData.fileContentId();
return dbData;
} // end of toDbData()
//-----------------------------------------------------------------------------
//Database::MrkMarker => MarkerManagement::Marker
Marker ObjectMarker::toDdsData(const Database::MrkMarker &dbData)
{
Marker ddsData;
ddsData.id(dbData.id);
ddsData.operatorId(dbData.operatorId);
ddsData.note(dbData.note.toStdString());
ddsData.timeStamp(dbData.timeStamp);
ddsData.timeStampOffset(dbData.timeStampOffset);
ddsData.mapSettings(dbData.mapSettings.toStdString());
ddsData.filter(dbData.filter.toStdString());
ddsData.position(Core::GeoPosition(dbData.position.x(), dbData.position.y(), 0.0));
ddsData.fileContentId(dbData.fileContentId);
// init data not in db
ddsData.isDeleted(false);
ddsData.isUsed(false);
return ddsData;
} // end of toDdsData()
//-----------------------------------------------------------------------------
// MarkerManagement::MarkerDescription => Database::MrkMarkerDescription
Database::MrkMarkerDescription ObjectMarker::toDbData(const MarkerDescription &ddsData)
{
Database::MrkMarkerDescription dbData;
dbData.id = ddsData.id();
dbData.markerTypeId = ddsData.markerType();
dbData.content = QString::fromStdString(ddsData.content());
return dbData;
} // end of toDbData()
//-----------------------------------------------------------------------------
//Database::MrkMarkerDescription => MarkerManagement::MarkerDescription
MarkerDescription ObjectMarker::toDdsData(const Database::MrkMarkerDescription &dbData)
{
MarkerDescription ddsData;
ddsData.id(dbData.id);
ddsData.markerType(dbData.markerTypeId);
ddsData.content(dbData.content.toStdString());
return ddsData;
} // end of toDdsData()
//-----------------------------------------------------------------------------
} // namespace MarkerManagement
+61
View File
@@ -0,0 +1,61 @@
/**
* Marker object
* $Id$
* $HeadURL$
* $Author$
* Created by hjl, SLSE, 2016-04-12
*/
#pragma once
#include "dds_handler.h"
#include "mrk_db.h"
#include <DDS/Core/function_reply_object.h>
// Generated
#include <MarkerManagement/mrk_db.h>
namespace MarkerManagement
{
class ObjectMarker final
{
public:
explicit ObjectMarker(const std::shared_ptr<DdsHandler> &ddsHandler,
const std::shared_ptr<DatabaseInterface> &db);
~ObjectMarker();
Core::FunctionReplyObject createObject(const Marker &data);
Core::FunctionReplyObject updateObject(const Marker &data);
Core::FunctionReplyObject removeObject();
Core::FunctionReplyObject setUsed(bool isUsed);
qint32 getId() const { return m_dataMarkerObject.id(); }
Marker getData() const { return m_dataMarkerObject; }
QString getName() const { return QString::fromStdString(m_dataMarkerObject.name()); }
bool isValid() const;
bool isUsed() const;
// convert methods
static Database::MrkMarker toDbData(const Marker &ddsData); // dds -> db
static Marker toDdsData(const Database::MrkMarker &dbData); // db -> dds
static Database::MrkMarkerDescription toDbData(const MarkerDescription &ddsData); // dds -> db
static MarkerDescription toDdsData(const Database::MrkMarkerDescription &dbData); // db -> dds
private:
void onPublishData();
private:
std::shared_ptr<DdsHandler> m_ddsHandler;
std::shared_ptr<DatabaseInterface> m_db;
Marker m_dataMarkerObject;
NGL::INGLLogger &m_logger;
};
} // namespace MarkerManagement
+145
View File
@@ -0,0 +1,145 @@
/**
* Marker object
* $Id$
* $HeadURL$
* $Author$
* Created by hjl, SLSE, 2016-04-12
*/
#include "object_snapshot.h"
#include "dds_handler.h"
namespace MarkerManagement
{
ObjectSnapshot::ObjectSnapshot(const std::shared_ptr<DdsHandler> &ddsHandler, const std::shared_ptr<DatabaseInterface> &db)
: m_ddsHandler(ddsHandler)
, m_db(db)
, m_logger(getLogger("ObjectSnapshot"))
{
} // end of ctor()
//-----------------------------------------------------------------------------
ObjectSnapshot::~ObjectSnapshot()
{
m_ddsHandler->dts()->removeSnapshotByKey(m_dataSnapshot.id());
} // end of dtor()
//-----------------------------------------------------------------------------
Core::FunctionReplyObject ObjectSnapshot::createObject(const MarkerManagement::Snapshot &data)
{
m_dataSnapshot = data;
Database::MrkSnapshot dbDataSnapshot = toDbData(data);
if (dbDataSnapshot.id <= 0)
{
if (!m_db->insert(dbDataSnapshot))
return Core::FunctionReplyObject(0, tr_lts("dds", "Error inserting Snapshot-data into database"));
}
// Neue DB Id in lokale Struktur uebernehmen
m_dataSnapshot.id(dbDataSnapshot.id);
DEBUG_LOG(m_logger) << "New SnapshotrId: " << dbDataSnapshot.id;
// Publish Data via DTS
onPublishData();
return Core::FunctionReplyObject(m_dataSnapshot.id());
} // end of createObject()
//-----------------------------------------------------------------------------
Core::FunctionReplyObject ObjectSnapshot::updateObject(const Snapshot &data)
{
if (!isValid())
return Core::FunctionReplyObject(data.id(), tr_lts("dds", "Object not valid"));
Database::MrkSnapshot dbDataSnapshot = toDbData(data);
if (!m_db->update(dbDataSnapshot))
return Core::FunctionReplyObject(data.id(), tr_lts("dds", "Error updating MrkSnapshot-data into database"));
m_dataSnapshot = data;
DEBUG_LOG(m_logger) << "Data changed for snapshotId: " << m_dataSnapshot.id();
// Publish Data via DTS
onPublishData();
return Core::FunctionReplyObject(m_dataSnapshot.id());
} // end of updateObject()
//-----------------------------------------------------------------------------
Core::FunctionReplyObject ObjectSnapshot::removeObject()
{
if (!m_db->removeMrkSnapshot(m_dataSnapshot.id()))
return Core::FunctionReplyObject(m_dataSnapshot.id(), tr_lts("dds", "Snapshot with id %1 can not be removed")).arg(m_dataSnapshot.id());
//m_ddsHandler->dts()->startTransaction();
m_ddsHandler->dts()->removeSnapshotByKey(m_dataSnapshot.id());
return Core::FunctionReplyObject(m_dataSnapshot.id());
} // end of removeObject()
//-----------------------------------------------------------------------------
bool ObjectSnapshot::isValid() const
{
return m_dataSnapshot.id() > 0;
} // end of isValid()
//-----------------------------------------------------------------------------
void ObjectSnapshot::onPublishData()
{
INFO_LOG(m_logger) << "Publish MrkSnapshot -data to dds snapshotId:" << m_dataSnapshot.id() ;
if (!m_ddsHandler->dts()->publish(m_dataSnapshot))
ERROR_LOG(m_logger) << "Error publishing MrkMarker-data to dds";
} // end of onPublishData()
//-----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
// convert methods
// ----------------------------------------------------------------------------
// MarkerManagement::Snapshot => Database::MrkSnapshot
Database::MrkSnapshot ObjectSnapshot::toDbData(const Snapshot &ddsData)
{
Database::MrkSnapshot dbData;
dbData.id = ddsData.id();
dbData.operatorId = ddsData.operatorId();
dbData.name = QString::fromStdString(ddsData.name());
dbData.description = QString::fromStdString(ddsData.description());
dbData.fileContentId = ddsData.fileContentId();
dbData.timeStamp = ddsData.timeStamp();
dbData.mapSettings = QString::fromStdString(ddsData.mapSettings());
dbData.movementTracks = QString::fromStdString(ddsData.movementTracks());
dbData.filter = QString::fromStdString(ddsData.filter());
dbData.planOverlay = QString::fromStdString(ddsData.planOverlay());
return dbData;
} // end of toDbData()
//-----------------------------------------------------------------------------
//Database::MrkSnapshot => MarkerManagement::Snapshot
Snapshot ObjectSnapshot::toDdsData(const Database::MrkSnapshot &dbData)
{
Snapshot ddsData;
ddsData.id(dbData.id);
ddsData.operatorId(dbData.operatorId);
ddsData.name(dbData.name.toStdString());
ddsData.description(dbData.description.toStdString());
ddsData.fileContentId(dbData.fileContentId);
ddsData.timeStamp(dbData.timeStamp);
ddsData.mapSettings(dbData.mapSettings.toStdString());
ddsData.movementTracks(dbData.movementTracks.toStdString());
ddsData.filter(dbData.filter.toStdString());
ddsData.planOverlay(dbData.planOverlay.toStdString());
return ddsData;
} // end of toDdsData()
//-----------------------------------------------------------------------------
} // namespace MarkerManagement
+55
View File
@@ -0,0 +1,55 @@
/**
* Marker object
* $Id$
* $HeadURL$
* $Author$
* Created by hjl, SLSE, 2016-04-12
*/
#pragma once
#include <QVector>
#include "dds_handler.h"
#include "mrk_db.h"
#include <DDS/Core/function_reply_object.h>
// Generated
#include <MarkerManagement/mrk_db.h>
namespace MarkerManagement
{
class ObjectSnapshot final
{
public:
explicit ObjectSnapshot(const std::shared_ptr<DdsHandler> &ddsHandler,
const std::shared_ptr<DatabaseInterface> &db);
~ObjectSnapshot();
Core::FunctionReplyObject createObject(const MarkerManagement::Snapshot &data);
Core::FunctionReplyObject updateObject(const MarkerManagement::Snapshot &data);
Core::FunctionReplyObject removeObject();
qint32 getId() const{ return m_dataSnapshot.id(); }
Snapshot getData() const { return m_dataSnapshot; }
QString getName() const { return QString::fromStdString(m_dataSnapshot.name()); }
bool isValid() const;
// convert methods
static Database::MrkSnapshot toDbData(const Snapshot &ddsData); // dds -> db
static Snapshot toDdsData(const Database::MrkSnapshot &dbData); // db -> dds
private:
void onPublishData();
private:
std::shared_ptr<DdsHandler> m_ddsHandler;
std::shared_ptr<DatabaseInterface> m_db;
MarkerManagement::Snapshot m_dataSnapshot;
NGL::INGLLogger &m_logger;
};
} // namespace MarkerManagement
+44
View File
@@ -0,0 +1,44 @@
/**
* Settings for MarkerManagement
* $Id$
* $HeadURL$
* $Author$
* Created by hjl, SLSE, 2016-04-05
*/
#include "settings.h"
#include <QtCore/QSettings>
#include <nglsettings/nglsettings_settings.h>
#include <ngltools/ngltools_filesystem.h>
namespace MarkerManagement
{
class NGLSettingsClass : public NGL::Settings
{
public:
NGLSettingsClass()
: NGL::Settings(s_iniFile.isEmpty() ? NGL::findProjectConfigFile() : s_iniFile)
{}
static void setIniFile(const QString &fn)
{
s_iniFile = fn;
}
static QString s_iniFile;
};
QString NGLSettingsClass::s_iniFile;
Q_GLOBAL_STATIC(NGLSettingsClass, s)
//-----------------------------------------------------------------------------
NGL::Settings *Settings::settings()
{
return s();
}
//-----------------------------------------------------------------------------
void Settings::setIniFile(const QString &ini)
{
NGLSettingsClass::setIniFile(ini);
}
} // namespace MarkerManagement
+26
View File
@@ -0,0 +1,26 @@
/**
* Settings for MarkerManagement
* $Id$
* $HeadURL$
* $Author$
* Created by hjl, SLSE, 2016-04-05
*/
#pragma once
#include <QString>
namespace NGL
{
class Settings;
}
namespace MarkerManagement
{
namespace Settings
{
//!< The real NGL::Settings - object
NGL::Settings *settings();
void setIniFile(const QString &ini);
}
} // namespace MarkerManagement