Initial commit
This commit is contained in:
commit
b7d90b9afe
16245 files changed
+3396666
No files matched your search
Executable
+151
@@ -0,0 +1,151 @@
|
||||
#
|
||||
# $Id$
|
||||
# $HeadURL$
|
||||
# $Author$
|
||||
#
|
||||
|
||||
INCLUDE(MacroRTIDDSGen)
|
||||
INCLUDE(MacroCodeGenIdl)
|
||||
|
||||
SET(xml_FILE alm_service.xml)
|
||||
#
|
||||
# --- Library svcAlmCommon --------------------------------------------------------------------------------
|
||||
#
|
||||
SET(SRCS_common
|
||||
alm_export.h
|
||||
logger.cpp
|
||||
logger.h
|
||||
)
|
||||
|
||||
# Generate alm_enums.idl / alm.idl
|
||||
CODEGEN_IDL_SVC(SRCS_common ${xml_FILE})
|
||||
# Generate alm_db_impl.cpp/.h, alm_db.h
|
||||
CODEGEN_DATABASE(SRCS_common ${xml_FILE})
|
||||
|
||||
# Generate *.cpp/*.hpp from idl
|
||||
RTIDDSGEN(SRCS_common alm_enums.idl)
|
||||
RTIDDSGEN(SRCS_common alm.idl)
|
||||
|
||||
# Generate alm_dt[s,c]_types.h, alm_ft[s,c]_types.h
|
||||
CODEGEN_TOPIC_TYPEDEFS(SRCS_common ${xml_FILE})
|
||||
# Generate alm_[d|f]tc.h
|
||||
CODEGEN_CLIENT_TOPICS_IFC(SRCS_common ${xml_FILE})
|
||||
|
||||
NGL_ADD_LIBRARY(AAR SV WS svcAlmCommon SHARED ${SRCS_common})
|
||||
NGL_TARGET_INCLUDE_DIRECTORIES(svcAlmCommon
|
||||
PUBLIC
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/../
|
||||
${CMAKE_CURRENT_BINARY_DIR}/../
|
||||
)
|
||||
NGL_TARGET_LINK_LIBRARIES(svcAlmCommon
|
||||
PRIVATE
|
||||
RTI::nddscpp2
|
||||
PUBLIC
|
||||
Qt5::Core
|
||||
ddscore
|
||||
NGLLogger
|
||||
svcPdmCommon
|
||||
ngldb
|
||||
)
|
||||
NGL_INSTALL_TARGET(svcAlmCommon)
|
||||
|
||||
#
|
||||
# --- Library svcAlmClient --------------------------------------------------------------------------------
|
||||
#
|
||||
SET(SRCS_client
|
||||
alm_export.h
|
||||
)
|
||||
# generate alm_[d|f]tc.h, tlm_[d|f]tc_impl.[cpp|h]
|
||||
CODEGEN_CLIENT_TOPICS_IMPL(SRCS_client ${xml_FILE})
|
||||
|
||||
NGL_ADD_LIBRARY(AAR SV WS svcAlmClient SHARED ${SRCS_client})
|
||||
NGL_TARGET_INCLUDE_DIRECTORIES(svcAlmClient
|
||||
PUBLIC
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/../
|
||||
${CMAKE_CURRENT_BINARY_DIR}/../
|
||||
)
|
||||
|
||||
NGL_TARGET_LINK_LIBRARIES(svcAlmClient
|
||||
PRIVATE
|
||||
RTI::nddscpp2
|
||||
ddsconnector
|
||||
PUBLIC
|
||||
svcAlmCommon
|
||||
ddsftc
|
||||
|
||||
)
|
||||
NGL_INSTALL_TARGET(svcAlmClient)
|
||||
|
||||
#
|
||||
# --- Library svcAlmServer --------------------------------------------------------------------------------
|
||||
#
|
||||
SET(SRCS_server
|
||||
alm_export.h
|
||||
dds_handler.cpp
|
||||
dds_handler.h
|
||||
handler_configure_alarms.cpp
|
||||
handler_configure_alarms.h
|
||||
handler_participant.cpp
|
||||
handler_participant.h
|
||||
handler_emergency_call.cpp
|
||||
handler_emergency_call.h
|
||||
initialization.cpp
|
||||
initialization.h
|
||||
object_emergency_call.cpp
|
||||
object_emergency_call.h
|
||||
# settings.cpp
|
||||
# settings.h
|
||||
)
|
||||
# generate alm_[d|f]ts.h, alm_[d|f]ts_impl.[cpp|h]
|
||||
CODEGEN_SERVER_TOPICS(SRCS_server ${xml_FILE})
|
||||
# Generate alm.sql, alm.xml
|
||||
CODEGEN_SQL(SRCS_server ${xml_FILE})
|
||||
|
||||
NGL_ADD_LIBRARY(AAR SV svcAlmServer SHARED ${SRCS_server})
|
||||
NGL_TARGET_INCLUDE_DIRECTORIES(svcAlmServer
|
||||
PUBLIC
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/../
|
||||
${CMAKE_CURRENT_BINARY_DIR}/../
|
||||
)
|
||||
|
||||
NGL_TARGET_LINK_LIBRARIES(svcAlmServer
|
||||
PRIVATE
|
||||
RTI::nddscpp2
|
||||
Qt5::Core
|
||||
ddsfts
|
||||
ddsconnector
|
||||
ddsQoS
|
||||
svcPdmCommon
|
||||
svcAlmCommon
|
||||
svcAlmClient
|
||||
svcEemClient
|
||||
svcPpmClient
|
||||
svcMrkClient
|
||||
svcCoreClient
|
||||
svcTabClient
|
||||
svcExmClient
|
||||
svcTabServer
|
||||
nglsettings
|
||||
NGLLogger
|
||||
ddscore
|
||||
ngltools
|
||||
PUBLIC
|
||||
svcAlmCommon
|
||||
ngldb
|
||||
)
|
||||
NGL_INSTALL_TARGET(svcAlmServer)
|
||||
|
||||
#
|
||||
# --- Topic Type Plugin --------------------------------------------------------------
|
||||
#
|
||||
CREATE_TOPIC_TYPE_PLUGIN(${xml_FILE})
|
||||
|
||||
#
|
||||
# --- RecordReplayPlugin --------------------------------------------------------------
|
||||
#
|
||||
CREATE_RECORD_REPLAY_PLUGIN(${xml_FILE} SRCS_server)
|
||||
|
||||
|
||||
# Uncomment if necessary
|
||||
#ADD_SUBDIRECTORY(UnitTests)
|
||||
ADD_SUBDIRECTORY(ModuleTests)
|
||||
+48
@@ -0,0 +1,48 @@
|
||||
#
|
||||
# $Id$
|
||||
# $HeadURL$
|
||||
# $Author$
|
||||
#
|
||||
|
||||
|
||||
IF(BUILD_TESTING)
|
||||
IF(TARGET svcAlmClient AND TARGET svcTabServer)
|
||||
|
||||
####################################
|
||||
# Message Test
|
||||
####################################
|
||||
|
||||
SET(SRCS_TEST_ALM
|
||||
alm_tests.cpp
|
||||
)
|
||||
SET(HDRS_TEST_ALM
|
||||
alm_tests.h
|
||||
)
|
||||
|
||||
NGL_TARGET_INCLUDE_DIRECTORIES(almTests
|
||||
PUBLIC
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/../
|
||||
${CMAKE_CURRENT_BINARY_DIR}/../
|
||||
)
|
||||
|
||||
# Testing FunctionTopic Functionality (FTC)
|
||||
ADD_EXECUTABLE(almTests ${SRCS_TEST_ALM} ${HDRS_TEST_ALM})
|
||||
TARGET_LINK_LIBRARIES(almTests
|
||||
Qt5::Core
|
||||
Qt5::Test
|
||||
RTI::nddscpp2
|
||||
svcAlmClient
|
||||
svcCoreClient
|
||||
svcEemServer
|
||||
svcPpmServer
|
||||
LtsCommandLineParser
|
||||
ddsconnector
|
||||
nglcoreapplication
|
||||
)
|
||||
IF(NOT BUILD_RPM)
|
||||
NGL_INSTALL(AAR SV TARGETS almTests DESTINATION bin/test)
|
||||
NGL_INSTALL(AAR SV FILES log4cxx_alm.props DESTINATION bin/test)
|
||||
ENDIF()
|
||||
ENDIF()
|
||||
ENDIF()
|
||||
|
||||
+335
@@ -0,0 +1,335 @@
|
||||
/**
|
||||
* Msg Function Topic Module Test
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
*/
|
||||
|
||||
#include "alm_tests.h"
|
||||
|
||||
#include <nglapplication/nglcoreapplication.h>
|
||||
#include <LtsCommandLineParser/LtsCommandLineParser.h>
|
||||
#include <QTimer>
|
||||
#include <QDateTime>
|
||||
#include <QJsonObject>
|
||||
#include <QJsonDocument>
|
||||
|
||||
/* ----------------------------------------------------------------------------------
|
||||
* HOW TO RUN THE TESTS
|
||||
* ----------------------------------------------------------------------------------
|
||||
*
|
||||
* Preconditions: Nothing
|
||||
*
|
||||
* Start services: (SV)
|
||||
* ./svcExerciseEventManagement -e 42
|
||||
* ./almTests -t 1 -e 42 // Configure Alarms with participantId=0, send EEM-Event and receive Alarm
|
||||
* ./almTests -t 2 -e 42 // Configure Alarms with participantId-List, send EEM-Event and receive Alarm
|
||||
* ./almTests -t 3 -e 42 // Configure Alarms with vulnerability > 0, send EEM-Event and receive Alarm
|
||||
*/
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
namespace AlarmManagement
|
||||
{
|
||||
AlmTests::AlmTests(QObject *parent)
|
||||
: QObject(parent)
|
||||
, m_testId(0)
|
||||
, m_bTestsSuccessful(true)
|
||||
, m_logger(getLogger("AlmTests"))
|
||||
, m_participantIndex(0)
|
||||
{}
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
AlmTests::~AlmTests()
|
||||
{}
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
bool AlmTests::init(int domainId, int testId, int operatorId)
|
||||
{
|
||||
INFO_LOG(m_logger) << "init begin";
|
||||
|
||||
m_testId = testId;
|
||||
m_operatorId = operatorId;
|
||||
m_participantIndex = 0;
|
||||
|
||||
m_ddsConnector.reset(new DDSConnector::DdsConnector(domainId, IDL::PartitionType::Any));
|
||||
if (!m_ddsConnector->init())
|
||||
return false;
|
||||
m_ddsConnector->initPublisherSubscriber();
|
||||
|
||||
m_ftcAlm = AlarmManagement::Interface::Ftc::create(m_ddsConnector);
|
||||
bool bRet = m_ftcAlm->enableAll();
|
||||
|
||||
m_dtcAlm = AlarmManagement::Interface::Dtc::create(m_ddsConnector);
|
||||
bRet &= m_dtcAlm->enableAll();
|
||||
|
||||
m_dtsEem = ExerciseEventManagement::Interface::Dts::create(m_ddsConnector);
|
||||
bRet &= m_dtsEem->enableAll();
|
||||
|
||||
m_dtsPpm = ParticipantManagement::Interface::Dts::create(m_ddsConnector);
|
||||
bRet &= m_dtsPpm->enableAll();
|
||||
|
||||
return bRet;
|
||||
} // init
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
void AlmTests::startTest()
|
||||
{
|
||||
INFO_LOG(m_logger) << "startTest m_testId=" << m_testId;
|
||||
if (m_testId <= 1) // Send FTC ConfigureAlarms and EEM Event
|
||||
{
|
||||
QTimer::singleShot(0, this, &AlmTests::tryConfigureAlarms);
|
||||
QTimer::singleShot(100, this, &AlmTests::trySendEvent);
|
||||
QTimer::singleShot(200, this, &AlmTests::checkAlarm);
|
||||
}
|
||||
if (m_testId == 2)
|
||||
{
|
||||
QTimer::singleShot(0, this, &AlmTests::tryCreateParticipant);
|
||||
QTimer::singleShot(100, this, &AlmTests::tryCreateParticipant);
|
||||
QTimer::singleShot(200, this, &AlmTests::tryConfigureAlarmsList);
|
||||
QTimer::singleShot(300, this, &AlmTests::trySendEvent);
|
||||
QTimer::singleShot(400, this, &AlmTests::checkAlarm);
|
||||
}
|
||||
if (m_testId == 3)
|
||||
{
|
||||
QTimer::singleShot(0, this, &AlmTests::tryCreateParticipant);
|
||||
QTimer::singleShot(100, this, &AlmTests::tryCreateParticipant);
|
||||
QTimer::singleShot(200, this, &AlmTests::tryConfigureAlarmsList);
|
||||
QTimer::singleShot(300, this, &AlmTests::trySendEvent);
|
||||
QTimer::singleShot(400, this, &AlmTests::checkAlarm);
|
||||
}
|
||||
QTimer::singleShot(5000, this, &AlmTests::failExit);
|
||||
} // startTest
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
void AlmTests::tryConfigureAlarms()
|
||||
{
|
||||
INFO_LOG(m_logger) << "trying to send createRequest Operator Message";
|
||||
|
||||
std::vector<AlarmManagement::AlarmAction> alarms;
|
||||
alarms.resize(2);
|
||||
|
||||
alarms[0].setMarker(true);
|
||||
alarms[0].messageWindow(true);
|
||||
alarms[0].vulnerabilityState(-1);
|
||||
alarms[0].eventTypeId(ProjectDataManagement::EventType_def::Hit);
|
||||
|
||||
alarms[1].setMarker(true);
|
||||
alarms[1].messageWindow(true);
|
||||
alarms[1].vulnerabilityState(0);
|
||||
alarms[1].eventTypeId(ProjectDataManagement::EventType_def::EnterNuclear);
|
||||
|
||||
std::vector<int32_t> participantIds;
|
||||
participantIds.push_back(0);
|
||||
bool globalEvent = true;
|
||||
bool remove = false;
|
||||
|
||||
if (!m_ftcAlm->configureAlarmsRequest(ConfigureAlarmsRequest(alarms, m_operatorId, participantIds, globalEvent, remove), this))
|
||||
{
|
||||
ERROR_LOG(m_logger) << "Error requesting create data";
|
||||
failExit();
|
||||
}
|
||||
} // tryConfigureAlarms
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
void AlmTests::tryCreateParticipant()
|
||||
{
|
||||
INFO_LOG(m_logger) << "trying to create Participant index = " << m_participantIndex;
|
||||
ParticipantManagement::Participant participant;
|
||||
switch (m_participantIndex)
|
||||
{
|
||||
case 0:
|
||||
participant.id(1);
|
||||
participant.superiorId(0);
|
||||
participant.inferiorIds().resize(2);
|
||||
participant.inferiorIds().at(0) = 2;
|
||||
participant.inferiorIds().at(1) = 3;
|
||||
participant.partyId(5);
|
||||
break;
|
||||
case 1:
|
||||
participant.id(2);
|
||||
participant.superiorId(1);
|
||||
participant.inferiorIds().resize(2);
|
||||
participant.inferiorIds().at(0) = 4;
|
||||
participant.inferiorIds().at(1) = 5;
|
||||
participant.partyId(5);
|
||||
break;
|
||||
}
|
||||
DEBUG_LOG(m_logger) << "Publishing Participant";
|
||||
if (!m_dtsPpm->publish(participant))
|
||||
{
|
||||
ERROR_LOG(m_logger) << "Error publish Participant";
|
||||
failExit();
|
||||
}
|
||||
m_participantIndex++;
|
||||
} // tryCreateParticipant
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
void AlmTests::tryConfigureAlarmsList()
|
||||
{
|
||||
INFO_LOG(m_logger) << "trying to send createRequest Operator Message";
|
||||
|
||||
std::vector<AlarmManagement::AlarmAction> alarms;
|
||||
alarms.resize(2);
|
||||
|
||||
alarms[0].setMarker(true);
|
||||
alarms[0].messageWindow(true);
|
||||
alarms[0].eventTypeId(ProjectDataManagement::EventType_def::Hit);
|
||||
alarms[0].vulnerabilityState(-1);
|
||||
|
||||
alarms[1].setMarker(true);
|
||||
alarms[1].messageWindow(true);
|
||||
alarms[1].vulnerabilityState(-1);
|
||||
alarms[1].eventTypeId(ProjectDataManagement::EventType_def::WeaponAssignment);
|
||||
|
||||
std::vector<int32_t> participantIds;
|
||||
participantIds.push_back(1);
|
||||
participantIds.push_back(2);
|
||||
bool globalEvent = true;
|
||||
bool remove = false;
|
||||
|
||||
if (!m_ftcAlm->configureAlarmsRequest(ConfigureAlarmsRequest(alarms, m_operatorId, participantIds, globalEvent, remove), this))
|
||||
{
|
||||
ERROR_LOG(m_logger) << "Error requesting create data";
|
||||
failExit();
|
||||
}
|
||||
} // tryConfigureAlarmsList
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
void AlmTests::trySendEvent()
|
||||
{
|
||||
INFO_LOG(m_logger) << "trying to send ParticipantEvent";
|
||||
|
||||
ExerciseEventManagement::Event pe;
|
||||
|
||||
// publish new Event data here
|
||||
pe.id(100);
|
||||
//pe.aesItemId(5);
|
||||
pe.eventTypeId(ProjectDataManagement::EventType_def::Hit); // same as eventTypeId in ConfigureAlarms
|
||||
pe.participantId(2);
|
||||
pe.equipmentNumber(55);
|
||||
pe.sampleTime(QDateTime::currentMSecsSinceEpoch());
|
||||
//pe.friendlyFire(1);
|
||||
//pe.vulnerability(0);
|
||||
|
||||
QJsonObject obj;
|
||||
obj[QStringLiteral("FriendlyFire")] = QJsonValue(true);
|
||||
|
||||
QString properties = QString::fromUtf8(QJsonDocument(obj).toJson());
|
||||
pe.properties(properties.toStdString());
|
||||
DEBUG_LOG(m_logger) << "Publishing EEM Event";
|
||||
if (!m_dtsEem->publish(pe))
|
||||
{
|
||||
ERROR_LOG(m_logger) << "Error publish EEM Event";
|
||||
failExit();
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
void AlmTests::onConfigureAlarmsReply(const Core::FunctionReplyObject &replyObject)
|
||||
{
|
||||
INFO_LOG(m_logger) << "onConfigureAlarmsReply, error = " << replyObject.error();
|
||||
if (replyObject.error())
|
||||
{
|
||||
ERROR_LOG(m_logger) << "Error ConfigureAlarms - aborting";
|
||||
failExit();
|
||||
}
|
||||
} // onConfigureAlarmsReply
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
void AlmTests::checkAlarm()
|
||||
{
|
||||
INFO_LOG(m_logger) << "checkAlarm";
|
||||
m_dtcAlm->waitForHistoricalDataNotification();
|
||||
qint32 id = 0;
|
||||
AlarmManagement::Notification notification = m_dtcAlm->notification(id);
|
||||
INFO_LOG(m_logger) << "Recived AlarmManagement::Notification: " << notification
|
||||
<< " testId: " << m_testId;
|
||||
|
||||
switch (m_testId)
|
||||
{
|
||||
case 1:
|
||||
case 2:
|
||||
case 3:
|
||||
INFO_LOG(m_logger) << "ExitSuccess";
|
||||
ExitSuccess();
|
||||
break;
|
||||
default:
|
||||
// nothing
|
||||
INFO_LOG(m_logger) << "failExit";
|
||||
failExit();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
void AlmTests::failExit()
|
||||
{
|
||||
m_bTestsSuccessful = false;
|
||||
QTimer::singleShot(0, qApp, &QCoreApplication::quit);
|
||||
} // failExit
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
void AlmTests::ExitSuccess()
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "SUCCESS";
|
||||
m_bTestsSuccessful = true;
|
||||
QTimer::singleShot(0, qApp, &QCoreApplication::quit);
|
||||
} // ExitSuccess
|
||||
|
||||
} // namespace
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
class CmdLineParser : public LtsCommandLineParser::LtsCommandLineParser
|
||||
{
|
||||
public:
|
||||
CmdLineParser()
|
||||
: LtsCommandLineParser()
|
||||
{
|
||||
addOption({ QStringList() << QLatin1String("t") << QLatin1String("testId")
|
||||
, QLatin1String("TestId.")
|
||||
, QLatin1String("Default: 0 (all tests)")
|
||||
, QLatin1String("0")
|
||||
});
|
||||
addOption({ QStringList() << QLatin1String("o") << QLatin1String("operatorId")
|
||||
, QLatin1String("OperatorId.")
|
||||
, QLatin1String("Default: 10")
|
||||
, QLatin1String("10")
|
||||
});
|
||||
|
||||
}
|
||||
int testId() const { return isSet(QLatin1String("t")) ? value(QLatin1String("t")).toInt() : 0; }
|
||||
int operatorId() const { return isSet(QLatin1String("o")) ? value(QLatin1String("o")).toInt() : 10; }
|
||||
};
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
NGLCoreApplication app(argc, argv);
|
||||
app.createLogger("ALM", "log4cxx_alm.props");
|
||||
|
||||
CmdLineParser options;
|
||||
if (!options.init())
|
||||
return -1;
|
||||
|
||||
int iRet = -1;
|
||||
{
|
||||
std::unique_ptr<AlarmManagement::AlmTests> almTests(new AlarmManagement::AlmTests);
|
||||
|
||||
if (!almTests->init(options.domainId(), options.testId(), options.operatorId()))
|
||||
return iRet;
|
||||
|
||||
almTests->startTest();
|
||||
|
||||
STARTUP_LOG(app.baseLogger());
|
||||
|
||||
app.exec();
|
||||
|
||||
iRet = almTests->testsSuccessful() ? 0 : 1;
|
||||
fprintf(stderr, "%d\n", iRet);
|
||||
|
||||
SHUTDOWN_LOG(app.baseLogger());
|
||||
}
|
||||
|
||||
return iRet;
|
||||
} // main
|
||||
|
||||
+69
@@ -0,0 +1,69 @@
|
||||
/**
|
||||
* ModuleTests for Msg
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <AlarmManagement/alm_dtc.h>
|
||||
#include <AlarmManagement/alm_ftc.h>
|
||||
#include <AlarmManagement/alm_ftc_types.h>
|
||||
#include <AlarmManagement/logger.h>
|
||||
#include <ExerciseEventManagement/eem_dts.h>
|
||||
#include <ParticipantManagement/ppm_dts.h>
|
||||
|
||||
#include <DDS/DDSConnector/dds_connector.h>
|
||||
|
||||
namespace AlarmManagement
|
||||
{
|
||||
class AlmTests : public QObject
|
||||
, protected AlarmManagement::Interface::Ftc::ConfigureAlarmsReplyHandler
|
||||
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit AlmTests(QObject *parent = nullptr);
|
||||
~AlmTests();
|
||||
|
||||
bool init(int domainId, int testId, int operatorId);
|
||||
|
||||
bool testsSuccessful() const
|
||||
{
|
||||
return m_bTestsSuccessful;
|
||||
}
|
||||
|
||||
public Q_SLOTS:
|
||||
void startTest();
|
||||
|
||||
protected Q_SLOTS:
|
||||
void tryConfigureAlarms();
|
||||
void tryConfigureAlarmsList();
|
||||
void trySendEvent();
|
||||
void tryCreateParticipant();
|
||||
void failExit();
|
||||
void ExitSuccess();
|
||||
|
||||
protected:
|
||||
void onConfigureAlarmsReply(const Core::FunctionReplyObject &replyObject) override final;
|
||||
|
||||
private:
|
||||
void checkAlarm();
|
||||
|
||||
std::shared_ptr<DDSConnector::DdsConnector> m_ddsConnector;
|
||||
std::shared_ptr<AlarmManagement::Interface::Ftc> m_ftcAlm;
|
||||
std::shared_ptr<AlarmManagement::Interface::Dtc> m_dtcAlm;
|
||||
std::shared_ptr<ExerciseEventManagement::Interface::Dts> m_dtsEem;
|
||||
std::shared_ptr<ParticipantManagement::Interface::Dts> m_dtsPpm;
|
||||
|
||||
int m_testId;
|
||||
bool m_bTestsSuccessful;
|
||||
int m_operatorId;
|
||||
|
||||
NGL::INGLLogger &m_logger;
|
||||
int m_participantIndex;
|
||||
|
||||
};
|
||||
|
||||
} // namespace AlarmManagement
|
||||
@@ -0,0 +1,86 @@
|
||||
log4j.reset=true
|
||||
log4j.rootLogger=WARN, file
|
||||
|
||||
# Service: AlarmManagement
|
||||
###########################################################
|
||||
|
||||
#log4j.logger.ALM=WARN
|
||||
#log4j.logger.ALM.main=WARN
|
||||
#log4j.logger.ALM.DbAdmin=WARN
|
||||
#log4j.logger.ALM.DdsHandler=WARN
|
||||
#log4j.logger.ALM.HandlerConfigureAlarms=DEBUG
|
||||
#log4j.logger.ALM.HandlerParticipant=DEBUG
|
||||
#log4j.logger.ALM.MainHandler=DEBUG
|
||||
#log4j.logger.ALM.Settings=WARN
|
||||
#log4j.logger.ALM.Publisher=WARN
|
||||
#log4j.logger.ALM.Fts=WARN
|
||||
|
||||
# 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:
|
||||
Executable
+52
@@ -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 ALM_COMMON_EXPORT
|
||||
# ifdef BUILD_STATIC_LIBRARIES
|
||||
# define ALM_COMMON_EXPORT
|
||||
# else
|
||||
# if defined(MAKE_SVCALMCOMMON_LIB)
|
||||
# define ALM_COMMON_EXPORT Q_DECL_EXPORT
|
||||
# ifndef WIN32
|
||||
# ifdef NDDSUSERDllExport
|
||||
# undef NDDSUSERDllExport
|
||||
# endif
|
||||
# define NDDSUSERDllExport Q_DECL_EXPORT
|
||||
# endif
|
||||
# else
|
||||
# define ALM_COMMON_EXPORT Q_DECL_IMPORT
|
||||
# endif
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef ALM_CLIENT_EXPORT
|
||||
# ifdef BUILD_STATIC_LIBRARIES
|
||||
# define ALM_CLIENT_EXPORT
|
||||
# else
|
||||
# if defined(MAKE_SVCALMCLIENT_LIB)
|
||||
# define ALM_CLIENT_EXPORT Q_DECL_EXPORT
|
||||
# else
|
||||
# define ALM_CLIENT_EXPORT Q_DECL_IMPORT
|
||||
# endif
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef ALM_SERVER_EXPORT
|
||||
# ifdef BUILD_STATIC_LIBRARIES
|
||||
# define ALM_SERVER_EXPORT
|
||||
# else
|
||||
# if defined(MAKE_SVCALMSERVER_LIB)
|
||||
# define ALM_SERVER_EXPORT Q_DECL_EXPORT
|
||||
# else
|
||||
# define ALM_SERVER_EXPORT Q_DECL_IMPORT
|
||||
# endif
|
||||
# endif
|
||||
#endif
|
||||
Executable
+153
@@ -0,0 +1,153 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||
<service namespace="AlarmManagement" abbreviation="ALM" procNames="AlarmManagement" exerciseDependency="Exercise">
|
||||
<rcs>
|
||||
<Id Id="$Id$"/>
|
||||
<HeadURL HeadURL="$HeadURL$"/>
|
||||
<Author Author="$Author$"/>
|
||||
</rcs>
|
||||
<operatorRights offset="45">
|
||||
<guiPlugin name="AlarmManagement" offset="1">
|
||||
<operatorRightGroup name="Alarm Management (Global)" description="Configure Alarms">
|
||||
<operatorRight right="ConfigGlobalDialog" value="1" description="Configure Alarms"/>
|
||||
</operatorRightGroup>
|
||||
</guiPlugin>
|
||||
<guiPlugin name="AlmConfigParticipantAlarms" offset="2">
|
||||
<operatorRightGroup name="Alarm Management (Participants)" description="Configure Participant Alarms">
|
||||
<operatorRight right="ConfigParticipantDialog" value="1" description="Configure Participant Alarms"/>
|
||||
</operatorRightGroup>
|
||||
</guiPlugin>
|
||||
<guiPlugin name="AlmEmergencyCall" offset="3">
|
||||
<operatorRightGroup name="Emergency Call" description="Allow User to Handle Emergency Calls">
|
||||
<operatorRight right="EmergencyCall" value="1" description="Allow User to Handle Emergency Calls"/>
|
||||
</operatorRightGroup>
|
||||
</guiPlugin>
|
||||
</operatorRights>
|
||||
<tables>
|
||||
<table name="alm_config">
|
||||
<column name="id" datatype="integer" isPrimaryKey="1">
|
||||
<sequence start="1" increment="1"/>
|
||||
</column>
|
||||
<column name="operator_id" datatype="integer" isForeignKey="1"/>
|
||||
<column name="event_type_id" datatype="integer" isForeignKey="1"/>
|
||||
<column name="set_marker" datatype="boolean"/>
|
||||
<column name="message_window" datatype="boolean"/>
|
||||
<column name="participant_id" datatype="integer" isOptional="1" isForeignKey="1"/>
|
||||
<column name="global" datatype="boolean"/>
|
||||
<column name="vulnerability_state" datatype="integer" comment="-1 = All Types other Values see PDM-&gt;Service-&gt;Enumerations-&gt;VulnerabilityState"/>
|
||||
<constraint name="IDX_operator_id" type="index">
|
||||
<column name="operator_id"/>
|
||||
</constraint>
|
||||
<foreignKey name="FK_alm_config_opm_operator">
|
||||
<source table="alm_config" column="operator_id"/>
|
||||
<destination service="OperatorManagement" serviceAbbr="opm" schema="opm" table="opm_operator" column="id"/>
|
||||
</foreignKey>
|
||||
<foreignKey name="FK_alm_config_pdm_event_type">
|
||||
<source table="alm_config" column="event_type_id"/>
|
||||
<destination service="ProjectDataManagement" serviceAbbr="pdm" schema="pdm" table="pdm_event_type" column="id"/>
|
||||
</foreignKey>
|
||||
<foreignKey name="FK_alm_config_ppm_participant">
|
||||
<source table="alm_config" column="participant_id"/>
|
||||
<destination service="ParticipantManagement" serviceAbbr="ppm" table="ppm_participant" column="id"/>
|
||||
</foreignKey>
|
||||
</table>
|
||||
<table name="alm_emergency_call">
|
||||
<column name="id" datatype="integer" isPrimaryKey="1">
|
||||
<sequence start="1" increment="1"/>
|
||||
</column>
|
||||
<column name="sample_time" datatype="bigint"/>
|
||||
<column name="incoming_time" datatype="bigint"/>
|
||||
<column name="name" datatype="text"/>
|
||||
<column name="issi" datatype="integer"/>
|
||||
<column name="position" datatype="point_2d"/>
|
||||
<column name="expired" datatype="boolean"/>
|
||||
<column name="operator_id" datatype="integer"/>
|
||||
<column name="deleted" datatype="bigint"/>
|
||||
<column name="comment" datatype="text"/>
|
||||
</table>
|
||||
</tables>
|
||||
<views/>
|
||||
<dbServiceStructs>
|
||||
<serviceStruct name="AlmConfig" table="alm_config"/>
|
||||
<table name="alm_config"/>
|
||||
<serviceStruct name="AlmEmergencyCall" table="alm_emergency_call"/>
|
||||
<table name="alm_emergency_call"/>
|
||||
</dbServiceStructs>
|
||||
<topicTypes>
|
||||
<topicType name="AlmEmergencyCall" isDataObject="1" routeToClient="1" routeToServer="0" routeInReplay="0" recordTopic="1" >
|
||||
<column name="id" idlType="long" isKey="1"/>
|
||||
<column name="sampleTime" idlType="long long"/>
|
||||
<column name="incomingTime" idlType="long long"/>
|
||||
<column name="name" idlType="string"/>
|
||||
<column name="issi" idlType="long"/>
|
||||
<column name="position" idlType="Core::GeoPosition2D"/>
|
||||
<column name="expired" idlType="boolean"/>
|
||||
<column name="operatorId" idlType="long"/>
|
||||
<column name="deleted" idlType="long long"/>
|
||||
<column name="comment" idlType="string"/>
|
||||
</topicType>
|
||||
<topicType name="EmergencyCallAcknowledgeRequest">
|
||||
<column name="id" idlType="long"/>
|
||||
<column name="timestamp" idlType="long long"/>
|
||||
<column name="incomingTime" idlType="long long"/>
|
||||
<column name="name" idlType="string"/>
|
||||
<column name="issi" idlType="long"/>
|
||||
<column name="operatorId" idlType="long"/>
|
||||
<column name="comment" idlType="string"/>
|
||||
<column name="expired" idlType="boolean"/>
|
||||
</topicType>
|
||||
<topicType name="AlarmAction">
|
||||
<column name="setMarker" idlType="boolean"/>
|
||||
<column name="messageWindow" idlType="boolean"/>
|
||||
<column name="eventTypeId" idlType="ProjectDataManagement::EventType"/>
|
||||
<column name="vulnerabilityState" idlType="long" comment="Only trigger, when this state is reached"/>
|
||||
</topicType>
|
||||
<topicType name="AlarmConfig" isDataObject="1" routeToClient="1" routeToServer="0" routeInReplay="0">
|
||||
<column name="operatorId" idlType="long"/>
|
||||
<column name="participantId" idlType="long"/>
|
||||
<column name="eventTypeId" idlType="ProjectDataManagement::EventType"/>
|
||||
<column name="messageWindow" idlType="boolean"/>
|
||||
<column name="setMarker" idlType="boolean"/>
|
||||
<column name="id" idlType="long" isKey="1"/>
|
||||
<column name="global" idlType="boolean"/>
|
||||
<column name="vulnerabilityState" idlType="long"/>
|
||||
</topicType>
|
||||
<topicType name="ConfigureAlarmsRequest">
|
||||
<column name="alarms" idlType="sequence<AlarmAction>"/>
|
||||
<column name="operatorId" idlType="long"/>
|
||||
<column name="participantIds" idlType="sequence<long>" comment="<ul> <li>Any event that comes for a participant in the list is sent as an alarm.</li> </ul> <ul> <li>If the participant is 0, an alarm is sent for each event independently of the participant.</li> </ul>"/>
|
||||
<column name="global" idlType="boolean" comment="global/local Alarm"/>
|
||||
<column name="remove" idlType="boolean" comment="Remove alarm from Service, DDS and DB"/>
|
||||
</topicType>
|
||||
<topicType name="Notification" isDataObject="1" routeToClient="1" routeToServer="0" routeInReplay="0">
|
||||
<column name="id" idlType="long" isKey="1"/>
|
||||
<column name="operatorId" idlType="long"/>
|
||||
<column name="eventId" idlType="long" comment="ExerciseEventManagement::EventType"/>
|
||||
<column name="eventType" idlType="ProjectDataManagement::EventType"/>
|
||||
<column name="time" idlType="long long"/>
|
||||
<column name="equipmentNumber" idlType="long"/>
|
||||
<column name="participantId" idlType="long" isOptional="1"/>
|
||||
<column name="aesId" idlType="long" isOptional="1"/>
|
||||
<column name="position" idlType="Core::GeoPosition"/>
|
||||
<column name="properties" idlType="string" comment="Json-Object: Globale und lokale Borderlines: Global (Type boolean: true = global, false = local) optional Global, FriendlyFire , equipmentNumber, EventTypeId, participantId, aesId"/>
|
||||
</topicType>
|
||||
<topicType name="AcknowledgeSOSInAllExercises" isDataObject="1" >
|
||||
<column name="id" idlType="long" isKey="1"/>
|
||||
<column name="timestamp" idlType="long long"/>
|
||||
<column name="incomingTime" idlType="long long"/>
|
||||
<column name="name" idlType="string"/>
|
||||
<column name="issi" idlType="long"/>
|
||||
<column name="operatorId" idlType="long"/>
|
||||
<column name="comment" idlType="string"/>
|
||||
<column name="expired" idlType="boolean"/>
|
||||
</topicType>
|
||||
</topicTypes>
|
||||
<functionTopics>
|
||||
<functionTopic name="EmergencyCallAcknowledge" requestTopicType="EmergencyCallAcknowledgeRequest" replyTopicType="Core::FunctionReply" requestTopicName="EmergencyCallAcknowledgeRequest" replyTopicName="EmergencyCallAcknowledgeReply" routeInReplay="0"/>
|
||||
<functionTopic name="ConfigureAlarms" requestTopicType="ConfigureAlarmsRequest" replyTopicType="Core::FunctionReply" requestTopicName="ConfigureAlarmsRequest" replyTopicName="ConfigureAlarmsReply" routeInReplay="0"/>
|
||||
</functionTopics>
|
||||
<enumerations>
|
||||
<enumeration name="Dummy">
|
||||
<attribute key="dummy1" value="1"/>
|
||||
</enumeration>
|
||||
</enumerations>
|
||||
</service>
|
||||
Executable
+97
@@ -0,0 +1,97 @@
|
||||
/**
|
||||
* DdsHandler for DDS
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
* Created by gr, SLSE, 2015-09-02
|
||||
*/
|
||||
|
||||
#include "dds_handler.h"
|
||||
#include <DDS/DTS/generic_dts_impl.h>
|
||||
#include <DDS/DDSConnector/publisher.h>
|
||||
|
||||
namespace AlarmManagement
|
||||
{
|
||||
|
||||
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)
|
||||
{
|
||||
if (!m_ddsConnector->init(qosFileList))
|
||||
{
|
||||
ERROR_LOG(m_logger) << "Error initializing dds connections - aborting";
|
||||
return false;
|
||||
}
|
||||
|
||||
// default initialize Publisher and Subscriber
|
||||
m_ddsConnector->initPublisherSubscriber();
|
||||
|
||||
// has to be false, because Snapshot Data Topics can be very large and fragmentation is not supported for batched writers!
|
||||
m_ddsConnector->enableBatchedWriter(false);
|
||||
|
||||
m_topicLockMaster = std::make_shared<Core::TopicLockMaster>(m_ddsConnector);
|
||||
|
||||
m_dtcCore = Core::Interface::Dtc::create(m_ddsConnector);
|
||||
m_dtcCore->enablePartitionTime();
|
||||
|
||||
m_dtsAlm = AlarmManagement::Interface::Dts::create(m_ddsConnector);
|
||||
bool bRet = m_dtsAlm->enableAll();
|
||||
INFO_LOG(m_logger) << "Dts initialised";
|
||||
|
||||
m_dtcAlm = AlarmManagement::Interface::Dtc::create(m_ddsConnector);
|
||||
bRet &= m_dtcAlm->enableAcknowledgeSOSInAllExercises();
|
||||
INFO_LOG(m_logger) << "Dts initialised";
|
||||
|
||||
m_ftsAlm = AlarmManagement::Interface::Fts::create(m_ddsConnector);
|
||||
bRet &= m_ftsAlm->enableAll();
|
||||
INFO_LOG(m_logger) << "Fts initialised";
|
||||
|
||||
m_dtcEem = ExerciseEventManagement::Interface::Dtc::create(m_ddsConnector);
|
||||
bRet &= m_dtcEem->enableEvent();
|
||||
INFO_LOG(m_logger) << "Dtc EEM initialised";
|
||||
|
||||
m_ftcMrk = MarkerManagement::Interface::Ftc::create(m_ddsConnector);
|
||||
bRet &= m_ftcMrk->enableMarkerModify();
|
||||
INFO_LOG(m_logger) << "Ftc MRK initialised";
|
||||
|
||||
m_dtcPpm = ParticipantManagement::Interface::Dtc::create(m_ddsConnector);
|
||||
bRet &= m_dtcPpm->enableParticipant();
|
||||
INFO_LOG(m_logger) << "Dtc PPM initialised";
|
||||
|
||||
m_exmDtc = ExerciseManagement::Interface::Dtc::create(m_ddsConnector);
|
||||
bRet &= m_exmDtc->enableExercise();
|
||||
|
||||
m_dtcTab = TrainingAreaBase::Interface::Dtc::create(m_ddsConnector);
|
||||
bRet &= m_dtcTab->enableEmergencyCall();
|
||||
INFO_LOG(m_logger) << "Dtc TAB initialised";
|
||||
|
||||
|
||||
m_dtsEmergencyCallPublisher = std::make_shared<DDSConnector::Publisher>(m_ddsConnector->getDomainParticipant(),
|
||||
DDSConnector::DdsConnector::getPartitionString(IDL::PartitionType::AllExercises));
|
||||
|
||||
m_dtsEmergencyCall = std::make_shared<DTS::AcknowledgeSOSInAllExercisesImpl>(m_ddsConnector->getDomainParticipant(),
|
||||
m_dtsEmergencyCallPublisher->getDdsPublisher(),
|
||||
DDS::Helper::getShortTopicName(DDS::topic_type_name<AlarmManagement::AcknowledgeSOSInAllExercises>::value()));
|
||||
|
||||
INFO_LOG(m_logger) << "Dtc TAB initialised";
|
||||
|
||||
return bRet;
|
||||
}
|
||||
|
||||
int DdsHandler::exerciseId() const
|
||||
{
|
||||
return m_ddsConnector->getPartitionId();
|
||||
} // end of init
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
qint64 DdsHandler::currentPartitionTime() const
|
||||
{
|
||||
return m_dtcCore->partitionTime().timeStamp();
|
||||
}
|
||||
|
||||
} // Namespace AlarmManagement
|
||||
Executable
+72
@@ -0,0 +1,72 @@
|
||||
/**
|
||||
* DdsHandler for DDS
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
* Created by gr, SLSE, 2015-09-02
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include <DDS/DDSConnector/dds_connector.h>
|
||||
#include <DDS/Core/core_dtc.h>
|
||||
#include <DDS/Core/topic_lock_master.h>
|
||||
#include <AlarmManagement/alm_dts.h>
|
||||
#include <AlarmManagement/alm_dtc.h>
|
||||
#include <AlarmManagement/alm_fts.h>
|
||||
#include <AlarmManagement/alm_dts_types.h>
|
||||
#include <ExerciseEventManagement/eem_dtc.h>
|
||||
#include <MarkerManagement/mrk_ftc.h>
|
||||
#include <ParticipantManagement/ppm_dtc.h>
|
||||
#include <TrainingAreaBase/tab_dtc.h>
|
||||
#include <ExerciseManagement/exm_dtc.h>
|
||||
#include "logger.h"
|
||||
|
||||
namespace AlarmManagement
|
||||
{
|
||||
class DdsHandler final
|
||||
{
|
||||
public:
|
||||
explicit DdsHandler(const std::shared_ptr<DDSConnector::DdsConnector> &ddsConnector);
|
||||
~DdsHandler() = default;
|
||||
|
||||
bool init(const QStringList &qosFileList = QStringList());
|
||||
|
||||
std::shared_ptr<DDSConnector::DdsConnector> dds() const { return m_ddsConnector; }
|
||||
|
||||
std::shared_ptr<AlarmManagement::Interface::Dts> dtsAlm() const { return m_dtsAlm;} ///< Pointer to DTS AlarmManagement interface object
|
||||
std::shared_ptr<AlarmManagement::Interface::Dtc> dtcAlm() const { return m_dtcAlm;} ///< Pointer to DTC AlarmManagement interface object
|
||||
std::shared_ptr<AlarmManagement::Interface::Fts> ftsAlm() const { return m_ftsAlm;} ///< Pointer to FTS AlarmManagement interface object
|
||||
std::shared_ptr<ExerciseEventManagement::Interface::Dtc> dtcEem() const { return m_dtcEem;} ///< Pointer to DTC ExerciseEventManagement interface object
|
||||
std::shared_ptr<MarkerManagement::Interface::Ftc> ftcMrk() const { return m_ftcMrk;}
|
||||
std::shared_ptr<ParticipantManagement::Interface::Dtc> dtcPpm() const { return m_dtcPpm;} ///< Pointer to DTC Participant Management interface object
|
||||
std::shared_ptr<TrainingAreaBase::Interface::Dtc> dtcTab() const { return m_dtcTab;} ///< Pointer to DTC TrainingAreaBase Management interface object
|
||||
std::shared_ptr<DTS::AcknowledgeSOSInAllExercises> publishSOS() const {return m_dtsEmergencyCall;}
|
||||
std::shared_ptr<ExerciseManagement::Interface::Dtc> dtcExm() const {return m_exmDtc;}
|
||||
|
||||
std::shared_ptr<Core::TopicLockMaster> topicLockMaster() const { return m_topicLockMaster; }
|
||||
|
||||
int exerciseId() const;
|
||||
qint64 currentPartitionTime() const;
|
||||
|
||||
private:
|
||||
std::shared_ptr<DDSConnector::DdsConnector> m_ddsConnector;
|
||||
std::shared_ptr<Core::Interface::Dtc> m_dtcCore;
|
||||
std::shared_ptr<Core::TopicLockMaster> m_topicLockMaster;
|
||||
|
||||
std::shared_ptr<AlarmManagement::Interface::Dts> m_dtsAlm; ///< Pointer to DTS AlarmManagement interface object
|
||||
std::shared_ptr<AlarmManagement::Interface::Dtc> m_dtcAlm; ///< Pointer to DTC AlarmManagement interface object
|
||||
std::shared_ptr<AlarmManagement::Interface::Fts> m_ftsAlm; ///< Pointer to FTS AlarmManagement interface object
|
||||
std::shared_ptr<ExerciseEventManagement::Interface::Dtc> m_dtcEem;
|
||||
std::shared_ptr<ExerciseManagement::Interface::Dtc> m_exmDtc;
|
||||
std::shared_ptr<MarkerManagement::Interface::Ftc> m_ftcMrk;
|
||||
std::shared_ptr<ParticipantManagement::Interface::Dtc> m_dtcPpm;
|
||||
std::shared_ptr<TrainingAreaBase::Interface::Dtc> m_dtcTab;
|
||||
std::shared_ptr<DDSConnector::Publisher> m_dtsEmergencyCallPublisher;
|
||||
std::shared_ptr<DTS::AcknowledgeSOSInAllExercises> m_dtsEmergencyCall;
|
||||
|
||||
|
||||
|
||||
NGL::INGLLogger &m_logger;
|
||||
};
|
||||
|
||||
}
|
||||
+404
@@ -0,0 +1,404 @@
|
||||
/**
|
||||
* Handler for message data request
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
* Created by hjl, SLSE, 2016-10-12
|
||||
*/
|
||||
|
||||
#include "handler_configure_alarms.h"
|
||||
#include "initialization.h"
|
||||
#include <QJsonObject>
|
||||
#include <QJsonDocument>
|
||||
#include <QSet>
|
||||
#include <QTimer>
|
||||
#include <ProjectDataManagement/pdm_translation.h>
|
||||
#include <LtsUtilsCore/json_object.h>
|
||||
|
||||
namespace AlarmManagement
|
||||
{
|
||||
static AlarmConfig toDds(const Database::AlmConfig &data)
|
||||
{
|
||||
AlarmConfig almConfig;
|
||||
almConfig.id(data.id);
|
||||
almConfig.operatorId(data.operatorId);
|
||||
if (data.participantId.isValid())
|
||||
almConfig.participantId(data.participantId.toInt());
|
||||
else
|
||||
almConfig.participantId(0);
|
||||
almConfig.eventTypeId(data.eventTypeId);
|
||||
almConfig.messageWindow(data.messageWindow);
|
||||
almConfig.global(data.global);
|
||||
almConfig.vulnerabilityState(data.vulnerabilityState);
|
||||
almConfig.setMarker(data.setMarker);
|
||||
return almConfig;
|
||||
}
|
||||
|
||||
HandlerConfigureAlarms::HandlerConfigureAlarms(Initialization *mainHandler)
|
||||
: QObject()
|
||||
, ConfigureAlarmsRequestHandler(mainHandler->dds()->ftsAlm())
|
||||
, m_mainHandler(mainHandler)
|
||||
, m_logger(getLogger("HandlerConfigureAlarms"))
|
||||
, m_windowIndex(0)
|
||||
{
|
||||
} // end of ctor()
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
HandlerConfigureAlarms::~HandlerConfigureAlarms()
|
||||
{
|
||||
} // end of dtor()
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
bool HandlerConfigureAlarms::init()
|
||||
{
|
||||
INFO_LOG(m_logger) << "Start HandlerConfigureAlarms.";
|
||||
|
||||
auto dtcEem = m_mainHandler->dds()->dtcEem();
|
||||
|
||||
connect(dtcEem.get(), &ExerciseEventManagement::Interface::Dtc::eventChanged,
|
||||
this, &HandlerConfigureAlarms::onEventChanged);
|
||||
|
||||
// publish data from db-table 'alm_config'
|
||||
auto cb = [this](const Database::AlmConfig & data)
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "restore AlarmConfig from DB data: id=" << data.id
|
||||
<< " operatorId=" << data.operatorId
|
||||
<< " participantId=" << data.participantId.toInt()
|
||||
<< " global=" << data.global
|
||||
<< " eventTypeId=" << data.eventTypeId
|
||||
<< " setMarker=" << data.setMarker
|
||||
<< " messageWindow=" << data.messageWindow
|
||||
<< " vulnerabilityState=" << data.vulnerabilityState;
|
||||
|
||||
m_mainHandler->dds()->dtsAlm()->publish(toDds(data));
|
||||
m_alarms.insert(data.id, data);
|
||||
};
|
||||
if (!m_mainHandler->db()->select(cb))
|
||||
{
|
||||
ERROR_LOG(m_logger) << "Error reading data from database 'alm_config'!";
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
} // end init()
|
||||
|
||||
|
||||
void HandlerConfigureAlarms::removeAlarmConfig(int operatorId,
|
||||
int participantId,
|
||||
int eventTypeId)
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "removeAlarmConfig m_alarms.size=" << m_alarms.size()
|
||||
<< " operatorId=" << operatorId
|
||||
<< " participantId=" << participantId
|
||||
<< " eventTypeId=" << eventTypeId;
|
||||
|
||||
// Find Key
|
||||
QMapIterator<int, Database::AlmConfig> i(m_alarms);
|
||||
while (i.hasNext())
|
||||
{
|
||||
i.next();
|
||||
DEBUG_LOG(m_logger) << "key= " << i.key() << ": "
|
||||
<< " operatorId=" << i.value().operatorId
|
||||
<< " participantId=" << i.value().participantId.toInt()
|
||||
<< " eventTypeId=" << i.value().eventTypeId.underlying();
|
||||
if ((operatorId == i.value().operatorId)
|
||||
&& (participantId == i.value().participantId)
|
||||
&& (eventTypeId == ProjectDataManagement::EventType_def::Unknown || eventTypeId == i.value().eventTypeId.underlying()))
|
||||
{
|
||||
const int key = i.key();
|
||||
DEBUG_LOG(m_logger) << "found alarm to remove: " << key << ", eventTypeId: " << eventTypeId;
|
||||
m_mainHandler->db()->removeAlmConfig(key);
|
||||
m_mainHandler->dds()->dtsAlm()->removeAlarmConfigByKey(key);
|
||||
m_alarms.remove(key); // is ok, QMapIterator work on a copy
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void HandlerConfigureAlarms::removeGlobalAlarmConfig(int operatorId)
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "removeAlarmConfig m_alarms.size=" << m_alarms.size();
|
||||
|
||||
// Find Key
|
||||
QMapIterator<int, Database::AlmConfig> i(m_alarms);
|
||||
while (i.hasNext())
|
||||
{
|
||||
i.next();
|
||||
DEBUG_LOG(m_logger) << "key= " << i.key()
|
||||
<< " participantId=" << i.value().participantId.toInt();
|
||||
if ((operatorId == i.value().operatorId)
|
||||
&& (i.value().participantId.toInt()) == 0)
|
||||
{
|
||||
const int key = i.key();
|
||||
DEBUG_LOG(m_logger) << "found alarm to remove: " << key;
|
||||
m_mainHandler->db()->removeAlmConfig(key);
|
||||
m_mainHandler->dds()->dtsAlm()->removeAlarmConfigByKey(key);
|
||||
m_alarms.remove(key); // is ok, QMapIterator work on a copy
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
void HandlerConfigureAlarms::onConfigureAlarmsRequest(const rti::core::SampleIdentity &cookie,
|
||||
const ConfigureAlarmsRequest &request)
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "onConfigureAlarmsRequest " << request;
|
||||
if (request.participantIds().size() == 0)
|
||||
{
|
||||
Core::FunctionReplyObject ret(0, tr_lts("dds", "Error adding ConfigureAlarms to database. There were no participants given."));
|
||||
m_mainHandler->dds()->ftsAlm()->configureAlarmsReply(cookie, ret);
|
||||
return;
|
||||
}
|
||||
|
||||
if (request.remove())
|
||||
{
|
||||
// remove only this one Alarm, not all types of the participant for operator
|
||||
// in DB,
|
||||
// from DDS
|
||||
DEBUG_LOG(m_logger) << "request.remove()";
|
||||
if (request.participantIds().size() > 0 &&
|
||||
request.alarms().size() > 0)
|
||||
{
|
||||
int participantId = request.participantIds()[0];
|
||||
int eventTypeId = request.alarms()[0].eventTypeId().underlying();
|
||||
DEBUG_LOG(m_logger) << "removeAlarmConfig(request.operatorId()=" << request.operatorId()
|
||||
<< " participantId=" << participantId
|
||||
<< " eventTypeId=" << eventTypeId;
|
||||
removeAlarmConfig(request.operatorId(), participantId, eventTypeId);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// remove old configuration
|
||||
for (int participantId : request.participantIds())
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "remove old configuration participantId=" << participantId;
|
||||
removeAlarmConfig(request.operatorId(), participantId, 0);
|
||||
}
|
||||
if ( request.global())
|
||||
{
|
||||
removeGlobalAlarmConfig(request.operatorId());
|
||||
}
|
||||
|
||||
for (int participantId : request.participantIds())
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "participantId: " << participantId;
|
||||
for (const AlarmManagement::AlarmAction &action : request.alarms())
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "action: " << action;
|
||||
|
||||
AlarmManagement::AlarmConfig almConfig;
|
||||
almConfig.operatorId(request.operatorId());
|
||||
almConfig.participantId(participantId);
|
||||
almConfig.eventTypeId(action.eventTypeId());
|
||||
almConfig.messageWindow(action.messageWindow());
|
||||
almConfig.vulnerabilityState(action.vulnerabilityState());
|
||||
almConfig.setMarker(action.setMarker());
|
||||
almConfig.global(request.global());
|
||||
|
||||
Database::AlmConfig newConfig;
|
||||
newConfig.operatorId = request.operatorId();
|
||||
if (participantId != 0)
|
||||
newConfig.participantId = participantId;
|
||||
|
||||
newConfig.eventTypeId = action.eventTypeId();
|
||||
newConfig.messageWindow = action.messageWindow();
|
||||
newConfig.vulnerabilityState = action.vulnerabilityState();
|
||||
newConfig.setMarker = action.setMarker();
|
||||
newConfig.global = request.global();
|
||||
if (!m_mainHandler->db()->insert(newConfig))
|
||||
{
|
||||
Core::FunctionReplyObject ret(0, tr_lts("dds", "Error adding ConfigureAlarms to database."));
|
||||
m_mainHandler->dds()->ftsAlm()->configureAlarmsReply(cookie, ret);
|
||||
}
|
||||
DEBUG_LOG(m_logger) << "m_dbAlmConfig.insert id=" << newConfig.id;
|
||||
|
||||
almConfig.id(newConfig.id);
|
||||
m_alarms.insert(newConfig.id, newConfig);
|
||||
m_mainHandler->dds()->dtsAlm()->publish(almConfig);
|
||||
}
|
||||
}
|
||||
}
|
||||
m_mainHandler->dds()->ftsAlm()->configureAlarmsReply(cookie, Core::FunctionReplyObject());
|
||||
|
||||
} // end onConfigureAlarmsRequest()
|
||||
//-----------------------------------------------------------------------------
|
||||
void HandlerConfigureAlarms::onEventChanged(const ExerciseEventManagement::Event &eventData, DataModification modType)
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "onParticipantEventChanged participantId=" << eventData.participantId();
|
||||
if (modType == DataModification::eRemoved ||
|
||||
modType == DataModification::eModified)
|
||||
return;
|
||||
DEBUG_LOG(m_logger) << "onParticipantEventChanged verarbeiten m_alarms.size =" << m_alarms.size();
|
||||
|
||||
ExerciseEventManagement::Event eventDatalocal = eventData;
|
||||
|
||||
QVector<int> participants;
|
||||
QSet<int> sentEventToOperator;
|
||||
|
||||
// toBool() returns false if attribute does not exist
|
||||
const QJsonObject eventObject = getEventProperties(eventDatalocal);
|
||||
const bool friendlyFireBool = eventObject.value(QStringLiteral("FriendlyFire")).toBool();
|
||||
const int vulnerabilityState = eventObject.value(QStringLiteral("vulnerabilityState")).toInt();
|
||||
|
||||
// Schleife ueber jede Konfiguration,
|
||||
// pruefen, ob eventTypeId == EventTypeId
|
||||
// Schleife ueber jeden Participant in der Konfiguration
|
||||
// Vergleich Participant-ID Event mit Konfiguration Event
|
||||
// Wenn ja, Alarm an operatorId schicken
|
||||
for (const Database::AlmConfig &alarm : qAsConst(m_alarms))
|
||||
{
|
||||
{
|
||||
/*DEBUG_LOG(m_logger) << " alarmConfigItem.id=" << alarm.id
|
||||
<< " alarmConfigItem.participantId=" << alarm.participantId
|
||||
<< " alarmConfigItem.eventTypeId=" << alarm.eventTypeId
|
||||
<< " eventDatalocal.eventTypeId()=" << eventDatalocal.eventTypeId().underlying()
|
||||
<< " alarm.operatorId=" << alarm.operatorId
|
||||
<< " friendyFire =" << friendlyFireBool;*/
|
||||
|
||||
if ((alarm.eventTypeId == eventDatalocal.eventTypeId().underlying()) ||
|
||||
(alarm.eventTypeId == ProjectDataManagement::EventType_def::FriendlyFire && friendlyFireBool))
|
||||
{
|
||||
if (friendlyFireBool && eventDatalocal.eventTypeId() == ProjectDataManagement::EventType_def::FireEvent)
|
||||
eventDatalocal.eventTypeId(ProjectDataManagement::EventType_def::FriendlyFire);
|
||||
|
||||
participants.clear();
|
||||
if (alarm.participantId.isValid())
|
||||
participants = m_mainHandler->hdlParticipant()->getRecursiveInferiorIds(alarm.participantId.toInt());
|
||||
else
|
||||
participants.append(0);
|
||||
|
||||
for (int participantId : qAsConst(participants))
|
||||
{
|
||||
bool allVulnerabilityStates = alarm.vulnerabilityState == -1;
|
||||
bool vulnerabilityCheck = vulnerabilityState == alarm.vulnerabilityState;
|
||||
bool globalAlarm = participantId == 0;
|
||||
DEBUG_LOG(m_logger) << " allVulnerabilityStates=" << allVulnerabilityStates
|
||||
<< " vulnerabilityCheck=" << vulnerabilityCheck
|
||||
<< " participantId=" << participantId
|
||||
<< " eventDatalocal.participantId()=" << eventDatalocal.participantId();
|
||||
if (((allVulnerabilityStates || vulnerabilityCheck) &&
|
||||
(participantId == eventDatalocal.participantId())) || globalAlarm)
|
||||
{
|
||||
if (sentEventToOperator.contains(alarm.operatorId))
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "Event " << eventDatalocal.eventTypeId() << " already handled for Operator:" << alarm.operatorId;
|
||||
continue;
|
||||
}
|
||||
|
||||
sentEventToOperator += alarm.operatorId;
|
||||
if (alarm.messageWindow)
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "send Window to Operator:" << alarm.operatorId;
|
||||
sendWindow(eventDatalocal, alarm);
|
||||
}
|
||||
if (alarm.setMarker)
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "set Marker to Operator:" << alarm.operatorId;
|
||||
sendMarker(eventDatalocal, alarm);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} // end onParticipantEventChanged
|
||||
|
||||
|
||||
void HandlerConfigureAlarms::sendWindow(const ExerciseEventManagement::Event &eventData,
|
||||
const Database::AlmConfig &config)
|
||||
{
|
||||
AlarmManagement::Notification wi;
|
||||
QJsonObject eventObject = getEventProperties(eventData);
|
||||
QJsonObject obj;
|
||||
|
||||
wi.id(m_windowIndex);
|
||||
wi.operatorId(config.operatorId);
|
||||
wi.time(eventData.sampleTime());
|
||||
wi.eventId(eventData.id());
|
||||
|
||||
if (eventData.eventTypeId() == ProjectDataManagement::EventType_def::CrossGlobalBorderline
|
||||
|| eventData.eventTypeId() == ProjectDataManagement::EventType_def::CrossLocalBorderline)
|
||||
{
|
||||
if (eventObject.contains(QStringLiteral("Global")))
|
||||
obj[QStringLiteral("Global")] = eventObject.value(QStringLiteral("Global"));
|
||||
}
|
||||
if (eventObject.contains(QStringLiteral("FriendlyFire")))
|
||||
obj[QStringLiteral("FriendlyFire")] = eventObject.value(QStringLiteral("FriendlyFire"));
|
||||
if (eventObject.contains(QStringLiteral("AesId")))
|
||||
wi.aesId(eventObject.value(QStringLiteral("AesId")).toInt());
|
||||
// AesEvent from the radio:
|
||||
int originatorType = eventObject[QStringLiteral("OriginatorType")].toInt();
|
||||
if (originatorType == ProjectDataManagement::StateChangeOriginator_def::AreaEffectSimulation
|
||||
|| originatorType == ProjectDataManagement::StateChangeOriginator_def::FunctionalArea)
|
||||
obj[QStringLiteral("aesId")] = eventObject[QStringLiteral("OriginatorId")].toInt();
|
||||
|
||||
wi.equipmentNumber(eventData.equipmentNumber());
|
||||
wi.eventType(eventData.eventTypeId());
|
||||
wi.participantId(eventData.participantId());
|
||||
wi.position(eventData.position());
|
||||
|
||||
const QByteArray propertiesStr = QJsonDocument(obj).toJson(QJsonDocument::Compact);
|
||||
wi.properties() = propertiesStr.data();
|
||||
m_mainHandler->dds()->dtsAlm()->publish(wi);
|
||||
// take data from dds-bus after 1 min
|
||||
const auto id = wi.id();
|
||||
QTimer::singleShot(1 * 60 * 1000, this, [id, this]() { m_mainHandler->dds()->dtsAlm()->removeNotificationByKey(id); });
|
||||
incrementWindowIndex(); // m_windowIndex++;
|
||||
|
||||
} // end sendWindow
|
||||
|
||||
|
||||
|
||||
QJsonObject HandlerConfigureAlarms::getEventProperties(const ExerciseEventManagement::Event &eventData)
|
||||
{
|
||||
return LtsUtils::JsonObject::fromJson(eventData.properties());
|
||||
}
|
||||
|
||||
void HandlerConfigureAlarms::sendMarker(const ExerciseEventManagement::Event &eventData,
|
||||
const Database::AlmConfig &config)
|
||||
{
|
||||
int defaultOffset = 10000;
|
||||
|
||||
DEBUG_LOG(m_logger) << "eventProperties =" << eventData.properties();
|
||||
|
||||
QString contentStr;
|
||||
contentStr = QStringLiteral("Equip No.: ");
|
||||
const int participantId = eventData.participantId();
|
||||
const int equipNo = m_mainHandler->hdlParticipant()->participantId2EquipNo(participantId);
|
||||
QJsonObject eventObject = getEventProperties(eventData);
|
||||
|
||||
contentStr += QString::number(equipNo);
|
||||
contentStr += QStringLiteral(" ");
|
||||
contentStr += ProjectDataManagement::toString(eventData.eventTypeId());
|
||||
if (eventObject.contains(QStringLiteral("AesName")))
|
||||
{
|
||||
contentStr += QStringLiteral(" (");
|
||||
contentStr += eventObject.value(QStringLiteral("AesName")).toString();
|
||||
contentStr += QStringLiteral(")");
|
||||
}
|
||||
DEBUG_LOG(m_logger) << "contentStr=" << contentStr;
|
||||
|
||||
const QByteArray contentArr = contentStr.toUtf8();
|
||||
|
||||
MarkerManagement::MarkerDescription ma;
|
||||
ma.content(contentArr.data());
|
||||
ma.markerType(MarkerManagement::MarkerType_def::Situation);
|
||||
|
||||
MarkerManagement::Marker mcr;
|
||||
mcr.operatorId(config.operatorId);
|
||||
mcr.note(ma.content()); // really?
|
||||
mcr.timeStamp(eventData.sampleTime());
|
||||
mcr.timeStampOffset(defaultOffset);
|
||||
mcr.descriptions().push_back(ma);
|
||||
mcr.position(eventData.position());
|
||||
mcr.fileContentId(0); // we cannot save an image here
|
||||
m_mainHandler->dds()->ftcMrk()->markerModifyRequest(mcr, this);
|
||||
|
||||
} // end sendMarker
|
||||
|
||||
void HandlerConfigureAlarms::onMarkerModifyReply(const Core::FunctionReplyObject &replyObject)
|
||||
{
|
||||
Q_UNUSED(replyObject);
|
||||
INFO_LOG(m_logger) << "************** onMarkerCreateReply";
|
||||
} // end onMarkerCreateReply
|
||||
} // namespace AlarmManagement
|
||||
+91
@@ -0,0 +1,91 @@
|
||||
/**
|
||||
* Handler for table-io message data request
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
* Created by hjl, SLSE, 2016-10-12
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <QObject>
|
||||
#include "dds_handler.h"
|
||||
#include "logger.h"
|
||||
#include <alm_db.h>
|
||||
|
||||
#include <AlarmManagement/alm_fts.h>
|
||||
#include <AlarmManagement/alm_ftc.h>
|
||||
#include <AlarmManagement/alm_dtc.h>
|
||||
#include <AlarmManagement/alm_dts.h>
|
||||
|
||||
#include <ExerciseEventManagement/eem_dtc.h>
|
||||
#include <MarkerManagement/mrk_ftc.h>
|
||||
#include <handler_participant.h>
|
||||
|
||||
namespace AlarmManagement
|
||||
{
|
||||
class Initialization;
|
||||
|
||||
class HandlerConfigureAlarms final
|
||||
: public QObject
|
||||
, protected Interface::Fts::ConfigureAlarmsRequestHandler
|
||||
, protected MarkerManagement::Interface::Ftc::MarkerModifyReplyHandler
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit HandlerConfigureAlarms(Initialization *mainHandler);
|
||||
|
||||
~HandlerConfigureAlarms();
|
||||
|
||||
bool init();
|
||||
|
||||
void onMarkerModifyReply(const Core::FunctionReplyObject &replyObject) override final;
|
||||
void incrementWindowIndex() { m_windowIndex++; }
|
||||
int getWindowIndex() const { return m_windowIndex; }
|
||||
|
||||
|
||||
private Q_SLOTS:
|
||||
void onEventChanged(const ExerciseEventManagement::Event &eventData, DataModification modType);
|
||||
|
||||
private: // methods
|
||||
void onConfigureAlarmsRequest(const rti::core::SampleIdentity &cookie,
|
||||
const ConfigureAlarmsRequest &request) override;
|
||||
void sendWindow(const ExerciseEventManagement::Event &eventData,
|
||||
const Database::AlmConfig &config);
|
||||
void sendMarker(const ExerciseEventManagement::Event &eventData,
|
||||
const Database::AlmConfig &config);
|
||||
static QJsonObject getEventProperties(const ExerciseEventManagement::Event &eventData);
|
||||
|
||||
void removeAlarmConfig(int operatorId, int participantId, int eventTypeId);
|
||||
void removeGlobalAlarmConfig(int operatorId);
|
||||
|
||||
private: // attributes
|
||||
Initialization *m_mainHandler;
|
||||
|
||||
struct AlarmKey
|
||||
{
|
||||
int operatorId = 0;
|
||||
int participantId = 0;
|
||||
AlarmKey() = default;
|
||||
explicit AlarmKey(const Database::AlmConfig &db)
|
||||
: operatorId(db.operatorId)
|
||||
, participantId(db.participantId.isNull() ? 0 : db.participantId.toInt())
|
||||
{}
|
||||
explicit AlarmKey(int operatorId_, int participantId_)
|
||||
: operatorId(operatorId_)
|
||||
, participantId(participantId_)
|
||||
{}
|
||||
|
||||
bool operator<(const AlarmKey &o) const
|
||||
{
|
||||
if (operatorId != o.operatorId)
|
||||
return operatorId < o.operatorId;
|
||||
return participantId < o.participantId;
|
||||
}
|
||||
};
|
||||
QMap<int, Database::AlmConfig> m_alarms; // Key = almConfig.id
|
||||
|
||||
NGL::INGLLogger &m_logger;
|
||||
int m_windowIndex;
|
||||
};
|
||||
} // namespace AlarmManagement
|
||||
+238
@@ -0,0 +1,238 @@
|
||||
/**
|
||||
* Handler emergency call from tetra radio
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
* Created by Astrid Müller, SGAS, 2018-02-23
|
||||
*/
|
||||
|
||||
#include "handler_emergency_call.h"
|
||||
#include "initialization.h"
|
||||
#include "handler_configure_alarms.h"
|
||||
#include "object_emergency_call.h"
|
||||
#include "alm_db.h"
|
||||
#include <DDS/DTS/generic_dts.h>
|
||||
|
||||
#include <QJsonObject>
|
||||
#include <QJsonDocument>
|
||||
#include <QDebug>
|
||||
namespace AlarmManagement
|
||||
{
|
||||
HandlerEmergencyCall::HandlerEmergencyCall(const std::shared_ptr<HandlerConfigureAlarms> &configAlarmHandler,
|
||||
Initialization *mainHandler)
|
||||
: QObject()
|
||||
, EmergencyCallAcknowledgeRequestHandler(mainHandler->dds()->ftsAlm())
|
||||
, m_mainHandler(mainHandler)
|
||||
, m_configAlarmHandler(configAlarmHandler)
|
||||
, m_logger(getLogger("HandlerEmergencyCall"))
|
||||
{
|
||||
}
|
||||
|
||||
HandlerEmergencyCall::~HandlerEmergencyCall()
|
||||
{
|
||||
}
|
||||
|
||||
bool HandlerEmergencyCall::init()
|
||||
{
|
||||
INFO_LOG(m_logger) << "Start HandlerEmergencyCall.";
|
||||
|
||||
auto dtcTab = m_mainHandler->dds()->dtcTab();
|
||||
|
||||
connect(dtcTab.get(), &TrainingAreaBase::Interface::Dtc::emergencyCallChanged,
|
||||
this, &HandlerEmergencyCall::onEmergencyCallChanged);
|
||||
connect(m_mainHandler->dds()->dtcAlm().get(), &AlarmManagement::Interface::Dtc::acknowledgeSOSInAllExercisesChanged,
|
||||
this, &HandlerEmergencyCall::onAcknowledgeSOSInExercises);
|
||||
|
||||
|
||||
// create and init Object
|
||||
bool bRet = true;
|
||||
auto cbEmergencyCall = [this, &bRet](const Database::AlmEmergencyCall &data)
|
||||
{
|
||||
WARNING_LOG(m_logger)<<" ALM_EMERGENCY " << "Reading from DB AlmEmergencyCall with id = " << data.id;
|
||||
if (!this->isExerciseValidForEmergencyCall() && !data.expired)
|
||||
return;
|
||||
|
||||
ObjectEmergencyCall *ifs(new ObjectEmergencyCall(m_mainHandler));
|
||||
Core::FunctionReplyObject ret = ifs->createObject(data);
|
||||
if (ret.error())
|
||||
{
|
||||
delete ifs;
|
||||
ERROR_LOG(m_logger) << ret();
|
||||
bRet = false;
|
||||
return;
|
||||
}
|
||||
|
||||
m_emergencyObjMap.insert(ifs->getId(), ifs);
|
||||
};
|
||||
|
||||
if (!m_mainHandler->db()->select(cbEmergencyCall) || !bRet)
|
||||
{
|
||||
ERROR_LOG(m_logger) <<"Error reading data from database 'alm_emergency_call!";
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool HandlerEmergencyCall::createEmergencyCallObject(const AlarmManagement::AlmEmergencyCall &data)
|
||||
{
|
||||
if (!isNewEmergencyCall(data) || std::isnan(data.position().lat()))
|
||||
return false;
|
||||
|
||||
Database::AlmEmergencyCall newData;
|
||||
newData.id = 0;
|
||||
newData.operatorId = 0;
|
||||
newData.sampleTime = data.sampleTime();
|
||||
newData.incomingTime = data.sampleTime();
|
||||
newData.expired = false;
|
||||
newData.issi = data.issi();
|
||||
newData.position.setX(data.position().lon());
|
||||
newData.position.setY(data.position().lat());
|
||||
newData.comment = QStringLiteral("");
|
||||
newData.name = QStringLiteral("");
|
||||
ObjectEmergencyCall *ifs(new ObjectEmergencyCall(m_mainHandler, this));
|
||||
Core::FunctionReplyObject ret = ifs->createObject(newData);
|
||||
if (ret.error())
|
||||
{
|
||||
delete ifs;
|
||||
ERROR_LOG(m_logger)<< ret();
|
||||
return false;
|
||||
}
|
||||
|
||||
WARNING_LOG(m_logger)<< "Entry createEmergencyCallObject in the DB id: "<<ifs->getData().id<<" issi: "<<ifs->getData().issi<<" expired: "<<ifs->getData().expired;
|
||||
m_emergencyObjMap.insert(ifs->getId(), ifs);
|
||||
return true;
|
||||
}
|
||||
|
||||
void HandlerEmergencyCall::onEmergencyCallAcknowledgeRequest(const rti::core::SampleIdentity &cookie, const EmergencyCallAcknowledgeRequest &request)
|
||||
{
|
||||
WARNING_LOG(m_logger) << "[onEmergencyCallAcknowledgeRequest] request: " << request;
|
||||
Core::FunctionReplyObject ret = emergencyCallAcknowledgeRequest(request);
|
||||
if (ret.error())
|
||||
WARNING_LOG(m_logger)<< ret();
|
||||
|
||||
if (request.expired())
|
||||
{
|
||||
AcknowledgeSOSInAllExercises ackInEx;
|
||||
ackInEx.id(request.id());
|
||||
ackInEx.timestamp(request.timestamp());
|
||||
ackInEx.incomingTime(request.incomingTime());
|
||||
ackInEx.name(request.name());
|
||||
ackInEx.issi(request.issi());
|
||||
ackInEx.operatorId(request.operatorId());
|
||||
ackInEx.comment(request.comment());
|
||||
ackInEx.expired(request.expired());
|
||||
WARNING_LOG(m_logger) << "onEmergencyCallAcknowledgeRequest: issi: "<<ackInEx.issi();
|
||||
m_mainHandler->dds()->publishSOS()->write(ackInEx);
|
||||
}
|
||||
m_mainHandler->dds()->ftsAlm()->emergencyCallAcknowledgeReply(cookie,ret);
|
||||
}
|
||||
|
||||
Core::FunctionReplyObject HandlerEmergencyCall::emergencyCallAcknowledgeRequest(const EmergencyCallAcknowledgeRequest &request)
|
||||
{
|
||||
ObjectEmergencyCall *ifs = nullptr;
|
||||
for(auto _ifs : qAsConst(m_emergencyObjMap))
|
||||
{
|
||||
auto data = _ifs->getData();
|
||||
if (data.issi == request.issi()
|
||||
&& data.incomingTime == request.incomingTime()
|
||||
&& !data.expired)
|
||||
{
|
||||
ifs = _ifs;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (ifs == nullptr)
|
||||
{
|
||||
WARNING_LOG(m_logger)<<" Couldn't acknowledge SOS with issi: " <<request.issi()<< ": already acknowledged or issi doesn't exist.";
|
||||
return Core::FunctionReplyObject(request.id(), tr_lts("dds", "already acknowledged or issi(%1) couldn't be found")).arg(request.issi());
|
||||
}
|
||||
|
||||
if (ifs->getData().expired) // if already expired do nothing
|
||||
{
|
||||
WARNING_LOG(m_logger) << "SOS Already expired do nothing";
|
||||
return Core::FunctionReplyObject(ifs->getData().id);
|
||||
}
|
||||
|
||||
WARNING_LOG(m_logger) << "emergencyCallAcknowledgeRequest: issi found!: "<<request.issi()<<" ifs->state: "<<ifs->getData().expired;
|
||||
Database::AlmEmergencyCall newData(ifs->getData());
|
||||
newData.expired = true;
|
||||
newData.issi = request.issi();
|
||||
newData.sampleTime = request.timestamp();
|
||||
newData.deleted = request.timestamp();
|
||||
newData.operatorId = request.operatorId();
|
||||
newData.name = QString::fromStdString(request.name());
|
||||
newData.comment = QString::fromStdString(request.comment());
|
||||
return ifs->updateObject(newData);
|
||||
}
|
||||
|
||||
bool HandlerEmergencyCall::isExerciseValidForEmergencyCall() const
|
||||
{
|
||||
const auto &exmDtc = m_mainHandler->dds()->dtcExm();
|
||||
exmDtc->waitForHistoricalDataExercise();
|
||||
const ExerciseManagement::Exercise exercise = exmDtc->exercise(m_mainHandler->dds()->exerciseId());
|
||||
|
||||
if (exercise.state() != ExerciseManagement::ExerciseState::Started
|
||||
&& exercise.state() != ExerciseManagement::ExerciseState::Paused)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool HandlerEmergencyCall::isNewEmergencyCall(const AlmEmergencyCall &newdata)
|
||||
{
|
||||
for(const auto &ifs : qAsConst(m_emergencyObjMap))
|
||||
{
|
||||
const auto &data = ifs->getData();
|
||||
if (data.issi == newdata.issi()
|
||||
&& data.incomingTime == newdata.incomingTime()
|
||||
&& !data.expired)
|
||||
{
|
||||
WARNING_LOG(m_logger)<<" SOS EXISTS and not yet quit! issi: "<<data.issi<<" incomingTime: "<<data.incomingTime<<" expired: "<<data.expired;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void HandlerEmergencyCall::onEmergencyCallChanged(const TrainingAreaBase::EmergencyCall &data, DataModification modType)
|
||||
{
|
||||
if (modType == DataModification::eRemoved || !isExerciseValidForEmergencyCall())
|
||||
return;
|
||||
|
||||
AlarmManagement::AlmEmergencyCall emc;
|
||||
emc.id(0);
|
||||
emc.operatorId(0); // global
|
||||
emc.sampleTime(data.sampleTime());
|
||||
emc.incomingTime(data.sampleTime());
|
||||
emc.expired(false);
|
||||
emc.issi(data.equipmentNumber());
|
||||
Core::GeoPosition position;
|
||||
position.lat(data.position().lat());
|
||||
position.lon(data.position().lon());
|
||||
emc.position(position);
|
||||
|
||||
createEmergencyCallObject(emc);
|
||||
}
|
||||
|
||||
void HandlerEmergencyCall::onAcknowledgeSOSInExercises(const AcknowledgeSOSInAllExercises &data, DataModification modType)
|
||||
{
|
||||
DEBUG_LOG(m_logger)<< "onAcknowledgeSOSInExercises START ";
|
||||
Q_UNUSED(modType)
|
||||
|
||||
EmergencyCallAcknowledgeRequest request;
|
||||
request.comment(data.comment());
|
||||
request.expired(data.expired());
|
||||
request.id(data.id());
|
||||
request.issi(data.issi());
|
||||
request.incomingTime(data.incomingTime());
|
||||
request.name(data.name());
|
||||
request.timestamp(data.timestamp());
|
||||
request.operatorId(data.operatorId());
|
||||
emergencyCallAcknowledgeRequest(request);
|
||||
|
||||
DEBUG_LOG(m_logger)<< "onAcknowledgeEmergencyInExercises END ";
|
||||
}
|
||||
|
||||
} // namespace AlarmManagement
|
||||
+55
@@ -0,0 +1,55 @@
|
||||
/**
|
||||
* Handler emergency call from tetra radio
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
* Created by Astrid Müller, SGAS, 2018-02-23
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <QObject>
|
||||
#include <AlarmManagement/alm_db.h>
|
||||
#include "dds_handler.h"
|
||||
#include "logger.h"
|
||||
#include "alm_fts.h"
|
||||
|
||||
namespace AlarmManagement
|
||||
{
|
||||
class Initialization;
|
||||
class HandlerConfigureAlarms;
|
||||
class ObjectEmergencyCall;
|
||||
|
||||
class HandlerEmergencyCall final : public QObject
|
||||
, protected Interface::Fts::EmergencyCallAcknowledgeRequestHandler
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit HandlerEmergencyCall(const std::shared_ptr<HandlerConfigureAlarms> &configAlarmHandler,
|
||||
Initialization *mainHandler);
|
||||
~HandlerEmergencyCall();
|
||||
|
||||
bool init();
|
||||
|
||||
private:
|
||||
bool createEmergencyCallObject(const AlmEmergencyCall &data);
|
||||
void onEmergencyCallAcknowledgeRequest(const rti::core::SampleIdentity &cookie,
|
||||
const EmergencyCallAcknowledgeRequest &request) override final;
|
||||
Core::FunctionReplyObject emergencyCallAcknowledgeRequest(const EmergencyCallAcknowledgeRequest &request);
|
||||
bool isExerciseValidForEmergencyCall() const;
|
||||
bool isNewEmergencyCall(const AlmEmergencyCall &newdata);
|
||||
|
||||
private slots:
|
||||
void onEmergencyCallChanged(const TrainingAreaBase::EmergencyCall &data, DataModification modType);
|
||||
void onAcknowledgeSOSInExercises(const AlarmManagement::AcknowledgeSOSInAllExercises &data, DataModification modType);
|
||||
|
||||
private:
|
||||
Initialization *m_mainHandler;
|
||||
std::shared_ptr<HandlerConfigureAlarms> m_configAlarmHandler;
|
||||
NGL::INGLLogger &m_logger;
|
||||
|
||||
QMap<int, ObjectEmergencyCall *> m_emergencyObjMap; // Key = DangerAreaId
|
||||
};
|
||||
|
||||
} // namespace AlarmManagement
|
||||
+193
@@ -0,0 +1,193 @@
|
||||
/**
|
||||
* Handler for player data
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
* Created by gr, SLSE, 2017-02-20
|
||||
*/
|
||||
|
||||
#include "handler_participant.h"
|
||||
#include "settings.h"
|
||||
|
||||
using namespace AlarmManagement;
|
||||
|
||||
HandlerParticipant::HandlerParticipant(const std::shared_ptr<DdsHandler> &ddsHandler)
|
||||
: QObject()
|
||||
, m_ddsHandler(ddsHandler)
|
||||
, m_logger(getLogger("HandlerParticipant"))
|
||||
{
|
||||
} // end of ctor()
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
HandlerParticipant::~HandlerParticipant()
|
||||
{
|
||||
} // end of dtor()
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
bool HandlerParticipant::init()
|
||||
{
|
||||
auto dtcPpm = m_ddsHandler->dtcPpm();
|
||||
|
||||
connect(dtcPpm.get(), &ParticipantManagement::Interface::Dtc::participantChanged,
|
||||
this, &HandlerParticipant::onParticipantChanged);
|
||||
connect(dtcPpm.get(), &ParticipantManagement::Interface::Dtc::dynamicParticipantDataChanged,
|
||||
this, &HandlerParticipant::onDynamicParticipantChanged);
|
||||
|
||||
// Get 'static' data for all participants
|
||||
{
|
||||
auto cb = [this](const ParticipantManagement::Participant & es)
|
||||
{
|
||||
onParticipantChanged(es, DataModification::eAdded);
|
||||
};
|
||||
if (!dtcPpm->participants(cb))
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!dtcPpm->enableParticipant())
|
||||
{
|
||||
ERROR_LOG(m_logger) << "Could not initialize ParticipantManagement enableParticipant data topic client";
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!dtcPpm->enableDynamicParticipantData())
|
||||
{
|
||||
ERROR_LOG(m_logger) << "Could not initialize ParticipantManagement enableDynamicParticipant data topic client";
|
||||
return false;
|
||||
}
|
||||
|
||||
// Get 'static' data for all participants (playerdata)
|
||||
QMap<qint32, ParticipantManagement::Participant> participantsMap;
|
||||
participantsMap = dtcPpm->participants();
|
||||
|
||||
// Player in Referenzmap eintragen
|
||||
for (auto i = participantsMap.begin(); i != participantsMap.end(); ++i)
|
||||
{
|
||||
const ParticipantManagement::Participant &participant = i.value();
|
||||
|
||||
if (participant.equipmentNumber().is_set())
|
||||
{
|
||||
m_partId2EquipNoMap.insert(participant.id(), participant.equipmentNumber().get());
|
||||
DEBUG_LOG(m_logger) << "m_partId2EquipNoMap.insert participantId=" << participant.id() << "EquimentNo=" << participant.equipmentNumber().get();
|
||||
}
|
||||
else
|
||||
m_partId2EquipNoMap.insert(participant.id(), 0);
|
||||
}
|
||||
|
||||
// Get 'static' data for all dynamicParticipants (playerdata)
|
||||
QMap<qint32, ParticipantManagement::DynamicParticipantData> dynamicParticipantsMap = dtcPpm->dynamicParticipantDatas();
|
||||
|
||||
// Player in Referenzmap eintragen
|
||||
for (auto i = dynamicParticipantsMap.begin(); i != dynamicParticipantsMap.end(); ++i)
|
||||
{
|
||||
const ParticipantManagement::DynamicParticipantData &dynamicParticipant = i.value();
|
||||
|
||||
if (dynamicParticipant.stateHistory().size() > 0)
|
||||
{
|
||||
std::vector<ParticipantManagement::StateInformation> states = dynamicParticipant.stateHistory();
|
||||
ParticipantManagement::StateInformation state = states[0];
|
||||
int vulnerability = state.vulnerabilityState().underlying();
|
||||
m_partId2VulnerabilityMap.insert(i.value().participantId(), vulnerability);
|
||||
DEBUG_LOG(m_logger) << "m_partId2EquipNoMap.insert participantId=" << i.value().participantId() << "vulnerability=" << vulnerability;
|
||||
}
|
||||
else
|
||||
m_partId2VulnerabilityMap.insert(i.value().participantId(), -1);
|
||||
}
|
||||
|
||||
INFO_LOG(m_logger) << "HandlerParticipant::init() finished. ";
|
||||
return true;
|
||||
} // end of init()
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
void HandlerParticipant::onParticipantChanged(const ParticipantManagement::Participant &data, DataModification modType)
|
||||
{
|
||||
if (modType == DataModification::eRemoved)
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "onParticipantChanged - remove: " << data.id();
|
||||
m_participantHierarchy.remove(data.id());
|
||||
}
|
||||
else
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "onParticipantChanged:" << data;
|
||||
m_participantHierarchy.insert(data.id(),
|
||||
AlarmManagement::HandlerParticipant::ParticipantHierarchy(data));
|
||||
const int equipNo = data.equipmentNumber().is_set() ? data.equipmentNumber().get() : 0;
|
||||
m_partId2EquipNoMap.insert(data.id(), equipNo);
|
||||
|
||||
}
|
||||
} // end of onParticipantChanged()
|
||||
|
||||
void HandlerParticipant::onDynamicParticipantChanged(const ParticipantManagement::DynamicParticipantData &data, DataModification modType)
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "onDynamicParticipant participantId=" << data.participantId();
|
||||
if (modType == DataModification::eRemoved)
|
||||
{
|
||||
}
|
||||
else
|
||||
{
|
||||
INFO_LOG(m_logger) << "onDynamicParticipant()"
|
||||
<< " participantId: " << data.participantId();
|
||||
if (data.stateHistory().size() > 0)
|
||||
{
|
||||
std::vector<ParticipantManagement::StateInformation> states = data.stateHistory();
|
||||
ParticipantManagement::StateInformation state = states[0];
|
||||
int vulnerability = state.vulnerabilityState().underlying();
|
||||
m_partId2VulnerabilityMap.insert(data.participantId(), vulnerability);
|
||||
DEBUG_LOG(m_logger) << "m_partId2EquipNoMap.insert participantId=" << data.participantId()
|
||||
<< " vulnerability=" << vulnerability;
|
||||
}
|
||||
else
|
||||
m_partId2VulnerabilityMap.insert(data.participantId(), -1);
|
||||
|
||||
}
|
||||
} // end of onParticipantChanged()
|
||||
|
||||
QVector<AlarmManagement::HandlerParticipant::ParticipantHierarchy> HandlerParticipant::getInferiorParts(int participantId) const
|
||||
{
|
||||
QVector<AlarmManagement::HandlerParticipant::ParticipantHierarchy> retVector;
|
||||
auto it = m_participantHierarchy.find(participantId);
|
||||
if (it == m_participantHierarchy.end())
|
||||
return retVector;
|
||||
|
||||
const AlarmManagement::HandlerParticipant::ParticipantHierarchy &participant = it.value();
|
||||
retVector.reserve(participant.inferiorIds.size() + retVector.size());
|
||||
|
||||
retVector.append(participant);
|
||||
for (int inferiorId : participant.inferiorIds)
|
||||
retVector.append(getInferiorParts(inferiorId));
|
||||
|
||||
return retVector;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
QVector<int> HandlerParticipant::getRecursiveInferiorIds(const int participantId) const
|
||||
{
|
||||
QVector <int> result;
|
||||
if (participantId == 0)
|
||||
{
|
||||
result.append(participantId);
|
||||
return result;
|
||||
}
|
||||
|
||||
const QVector<AlarmManagement::HandlerParticipant::ParticipantHierarchy> inferiorParts = HandlerParticipant::getInferiorParts(participantId);
|
||||
result.reserve(inferiorParts.size());
|
||||
for (const auto &inferior : inferiorParts)
|
||||
result.append(inferior.participantId);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
int HandlerParticipant::participantId2EquipNo(const int participantId) const
|
||||
{
|
||||
int ret = m_partId2EquipNoMap.value(participantId, 0);
|
||||
INFO_LOG(m_logger) << "participantId2EquipNo participantId=" << participantId
|
||||
<< " EquipmentNumber=" << ret;
|
||||
return ret;
|
||||
} // end of participantId2EquipNo()
|
||||
|
||||
int HandlerParticipant::participantId2Vulnerability(const int participantId) const
|
||||
{
|
||||
int ret = m_partId2VulnerabilityMap.value(participantId, 0);
|
||||
INFO_LOG(m_logger) << "m_partId2VulnerabilityMap participantId=" << participantId
|
||||
<< " Vulnerability=" << ret;
|
||||
return ret;
|
||||
} // end of participantId2Vulnerability()
|
||||
+92
@@ -0,0 +1,92 @@
|
||||
/**
|
||||
* Handler for player data
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
* Created by gr, SLSE, 2017-02-20
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <QObject>
|
||||
#include "dds_handler.h"
|
||||
#include "logger.h"
|
||||
|
||||
#include <ParticipantManagement/ppm_dtc.h>
|
||||
|
||||
#include <QtCore/QObject>
|
||||
#include <QtCore/QList>
|
||||
#include <QtCore/QVector>
|
||||
#include <QtCore/QHash>
|
||||
|
||||
// AES-Handling for participants outside buildings
|
||||
namespace AlarmManagement
|
||||
{
|
||||
|
||||
class HandlerParticipant : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
|
||||
struct ParticipantHierarchy
|
||||
{
|
||||
int participantId = 0;
|
||||
int superiorId = 0;
|
||||
std::vector<int32_t> inferiorIds;
|
||||
|
||||
ParticipantHierarchy() = default;
|
||||
explicit ParticipantHierarchy(const ParticipantManagement::Participant &p)
|
||||
: participantId(p.id())
|
||||
, superiorId(p.superiorId())
|
||||
, inferiorIds(p.inferiorIds())
|
||||
{}
|
||||
};
|
||||
|
||||
|
||||
public:
|
||||
explicit HandlerParticipant(const std::shared_ptr<DdsHandler> &ddsHandler);
|
||||
|
||||
~HandlerParticipant();
|
||||
|
||||
/**
|
||||
* Initialize the handler to manage information from participant management
|
||||
*/
|
||||
bool init();
|
||||
|
||||
QVector<int> getRecursiveInferiorIds(const int participantId) const;
|
||||
|
||||
/**
|
||||
* Get equipment number for the given participant
|
||||
* @param participantId participant id to get the equipment number for
|
||||
* @return equipment number or 0 in case of failure
|
||||
*/
|
||||
int participantId2EquipNo(const int participantId) const;
|
||||
|
||||
/**
|
||||
* Get vulnerability for the given participant
|
||||
* @param participantId participant id to get the equipment number for
|
||||
* @return vulnerability
|
||||
*/
|
||||
int participantId2Vulnerability(const int participantId) const;
|
||||
|
||||
|
||||
private Q_SLOTS:
|
||||
/**
|
||||
* Handle the signals from 'ParticipantManagement'
|
||||
*/
|
||||
void onParticipantChanged(const ParticipantManagement::Participant &data, DataModification modType);
|
||||
void onDynamicParticipantChanged(const ParticipantManagement::DynamicParticipantData &data, DataModification modType);
|
||||
|
||||
private: // methoden
|
||||
QVector<AlarmManagement::HandlerParticipant::ParticipantHierarchy> getInferiorParts(int participantId) const;
|
||||
|
||||
private: // attributes
|
||||
QMap<int, int> m_partId2EquipNoMap; ///< Reference map participant (player) to equipment number (participantId, equipmentNo)
|
||||
QMap<int, int> m_partId2VulnerabilityMap; ///< Reference map participant (player) to Vulnerability
|
||||
QHash<int, ParticipantHierarchy> m_participantHierarchy;
|
||||
std::shared_ptr<DdsHandler> m_ddsHandler; ///< Pointer to VOM DDS handler
|
||||
NGL::INGLLogger &m_logger; ///< Interface to the Logging-Facility
|
||||
|
||||
};
|
||||
} // namespace AlarmManagement
|
||||
|
||||
+99
@@ -0,0 +1,99 @@
|
||||
/**
|
||||
* Initialization for MessageDataManagement
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
* Created by hjl, SLSE, 2016-09-21
|
||||
*/
|
||||
|
||||
#include "initialization.h"
|
||||
#include "handler_configure_alarms.h"
|
||||
#include "handler_emergency_call.h"
|
||||
#include "handler_participant.h"
|
||||
|
||||
#include <ngldb/db_service_handler.h>
|
||||
#include <DDS/DDSConnector/dds_connector.h>
|
||||
|
||||
using namespace AlarmManagement;
|
||||
|
||||
Initialization::Initialization()
|
||||
: m_logger(getLogger("Initialization"))
|
||||
{
|
||||
INFO_LOG(m_logger) << "Initialization::Initialization";
|
||||
} // end of ctor()
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
Initialization::~Initialization()
|
||||
{
|
||||
m_handlerConfigureAlarms = nullptr;
|
||||
m_handlerParticipant = nullptr;
|
||||
m_handlerEmergencyCall = nullptr;
|
||||
|
||||
m_dbHandler = nullptr;
|
||||
m_ddsHandler = nullptr;
|
||||
|
||||
INFO_LOG(m_logger) << "Initialization::~Initialization";
|
||||
} // end of dtor()
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
bool Initialization::initialize(const std::shared_ptr<DDSConnector::DdsConnector> &ddsConnector, const QSqlDatabase &sqlDb)
|
||||
{
|
||||
INFO_LOG(m_logger) << "Start AlarmManagement Initialization. domainId =" << ddsConnector->getDomainId()
|
||||
<< " exerciseId=" << ddsConnector->getPartitionId();
|
||||
|
||||
// initialize DDS
|
||||
m_ddsHandler = std::make_shared<DdsHandler>(ddsConnector);
|
||||
if (!m_ddsHandler->init())
|
||||
{
|
||||
ERROR_LOG(m_logger) << "Initialisation DdsHandler failed.";
|
||||
return false;
|
||||
}
|
||||
INFO_LOG(m_logger) << "m_ddsHandler initialized. ";
|
||||
|
||||
// initialize database
|
||||
m_dbHandler = std::make_shared<DbHandler>();
|
||||
if (!m_dbHandler->init(ddsConnector->getPartitionId(), sqlDb))
|
||||
{
|
||||
ERROR_LOG(m_logger) << "Initialisation DbHandler failed.";
|
||||
return false;
|
||||
}
|
||||
INFO_LOG(m_logger) << "DbHandler initialized. ";
|
||||
|
||||
|
||||
// create handlers
|
||||
m_handlerParticipant = std::make_shared<HandlerParticipant>(m_ddsHandler);
|
||||
m_handlerConfigureAlarms = std::make_shared<HandlerConfigureAlarms>(this);
|
||||
m_handlerEmergencyCall = std::make_shared<HandlerEmergencyCall>(m_handlerConfigureAlarms, this);
|
||||
|
||||
DEBUG_LOG(m_logger) << "initialize successfully finished";
|
||||
|
||||
return true;
|
||||
} // end of init()
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
bool Initialization::loadFromDatabase()
|
||||
{
|
||||
// initialize handlers
|
||||
if (!m_handlerParticipant || !m_handlerParticipant->init())
|
||||
{
|
||||
ERROR_LOG(m_logger) << "Can not initialize Participant handler";
|
||||
return false;
|
||||
}
|
||||
if (!m_handlerConfigureAlarms || !m_handlerConfigureAlarms->init())
|
||||
{
|
||||
ERROR_LOG(m_logger) << "Can not initialize Alarm handler";
|
||||
return false;
|
||||
}
|
||||
if (!m_handlerEmergencyCall || !m_handlerEmergencyCall->init())
|
||||
{
|
||||
ERROR_LOG(m_logger) << "Can not initialize EmergencyCall handler";
|
||||
return false;
|
||||
}
|
||||
DEBUG_LOG(m_logger) << "loadFromDatabase successfully finished";
|
||||
return true;
|
||||
}
|
||||
|
||||
std::shared_ptr<DatabaseInterface> Initialization::db() const
|
||||
{
|
||||
return m_dbHandler->db();
|
||||
}
|
||||
+57
@@ -0,0 +1,57 @@
|
||||
/**
|
||||
* MainHandler for Messaging
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
* Created by hjl, SLSE, 2016-09-21
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <AlarmManagement/alm_db.h>
|
||||
#include <ngldb/db_service_handler.h>
|
||||
#include "dds_handler.h"
|
||||
#include "logger.h"
|
||||
|
||||
namespace DDSConnector
|
||||
{
|
||||
class DdsConnector;
|
||||
}
|
||||
namespace NGLDB
|
||||
{
|
||||
template <typename DB> class DbServiceHandler;
|
||||
}
|
||||
|
||||
namespace AlarmManagement
|
||||
{
|
||||
using DbHandler = NGLDB::DbServiceHandler<DatabaseInterface>;
|
||||
class DdsHandler;
|
||||
class HandlerConfigureAlarms;
|
||||
class HandlerEmergencyCall;
|
||||
class HandlerParticipant;
|
||||
|
||||
class ALM_SERVER_EXPORT Initialization
|
||||
{
|
||||
public:
|
||||
Initialization();
|
||||
~Initialization();
|
||||
|
||||
bool initialize(const std::shared_ptr<DDSConnector::DdsConnector> &ddsConnector, const QSqlDatabase &sqlDb);
|
||||
bool loadFromDatabase();
|
||||
|
||||
std::shared_ptr<DdsHandler> dds() const { return m_ddsHandler; }
|
||||
std::shared_ptr<DatabaseInterface> db() const;
|
||||
std::shared_ptr<HandlerParticipant> hdlParticipant() const { return m_handlerParticipant; }
|
||||
|
||||
private: // attributes
|
||||
std::shared_ptr<DdsHandler> m_ddsHandler;
|
||||
std::shared_ptr<DbHandler> m_dbHandler; ///< Pointer to DB handler
|
||||
std::shared_ptr<HandlerConfigureAlarms> m_handlerConfigureAlarms;
|
||||
std::shared_ptr<HandlerParticipant> m_handlerParticipant; ///< Pointer to handler for all participants
|
||||
std::shared_ptr<HandlerEmergencyCall> m_handlerEmergencyCall;
|
||||
|
||||
NGL::INGLLogger &m_logger; ///< Interface to the Logging-Facility
|
||||
|
||||
};
|
||||
} // namespace MessagingDataManagement
|
||||
Executable
+37
@@ -0,0 +1,37 @@
|
||||
/**
|
||||
* @RDE_HEADER@
|
||||
* Building Config - logging facility
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
*/
|
||||
|
||||
#include "logger.h"
|
||||
|
||||
#include <NGLLogger/NGLLoggerBootstrap.h>
|
||||
|
||||
namespace AlarmManagement
|
||||
{
|
||||
|
||||
LOGGER_T getLogger(const char *name)
|
||||
{
|
||||
static const char ns[] = "ALM.";
|
||||
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 AlarmManagement
|
||||
Executable
+23
@@ -0,0 +1,23 @@
|
||||
/**
|
||||
* @RDE_HEADER@
|
||||
* Logging for AlarmManagement
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <NGLLogger/INGLLogger.h>
|
||||
#include "alm_export.h"
|
||||
|
||||
namespace AlarmManagement
|
||||
{
|
||||
using LOGGER_T = NGL::INGLLogger &;
|
||||
|
||||
ALM_COMMON_EXPORT LOGGER_T getLogger(const char *name);
|
||||
inline LOGGER_T getLogger(const QString &loggerName)
|
||||
{
|
||||
return getLogger(loggerName.toUtf8().constData());
|
||||
}
|
||||
} // namespace AlarmManagement
|
||||
+81
@@ -0,0 +1,81 @@
|
||||
#include "object_emergency_call.h"
|
||||
#include "logger.h"
|
||||
#include "initialization.h"
|
||||
|
||||
namespace AlarmManagement{
|
||||
|
||||
ObjectEmergencyCall::ObjectEmergencyCall(Initialization *mainHandler, QObject *parent)
|
||||
: QObject(parent)
|
||||
, m_mainHandler(mainHandler)
|
||||
, m_logger(getLogger("ObjectEmergencyCall"))
|
||||
{
|
||||
}
|
||||
|
||||
ObjectEmergencyCall::~ObjectEmergencyCall()
|
||||
{
|
||||
if (m_data.id > 0)
|
||||
m_mainHandler->dds()->dtsAlm()->removeAlarmConfigByKey(m_data.id);
|
||||
}
|
||||
|
||||
Core::FunctionReplyObject ObjectEmergencyCall::createObject(const Database::AlmEmergencyCall &data)
|
||||
{
|
||||
m_data = data;
|
||||
if (m_data.id <= 0)
|
||||
{
|
||||
if (!m_mainHandler->db()->insert(m_data))
|
||||
return Core::FunctionReplyObject(0, tr_lts("dds", "Error inserting Order into database."));
|
||||
WARNING_LOG(m_logger) << "New EmergencyCall created Id: " << m_data.id;
|
||||
}
|
||||
// Publish Data via DTS
|
||||
onPublishData();
|
||||
|
||||
return Core::FunctionReplyObject(m_data.id);
|
||||
}
|
||||
|
||||
Core::FunctionReplyObject ObjectEmergencyCall::updateObject(const Database::AlmEmergencyCall &data)
|
||||
{
|
||||
if (data.id <= 0)
|
||||
return Core::FunctionReplyObject(m_data.id, tr_lts("dds", "Object not valid/blocked"));
|
||||
m_data = data;
|
||||
|
||||
if (!m_mainHandler->db()->update(m_data))
|
||||
return Core::FunctionReplyObject(m_data.id, tr_lts("dds", "Error updating EmergencyCall into database"));
|
||||
|
||||
DEBUG_LOG(m_logger) << "Data changed for Changed Id: " << m_data.id;
|
||||
|
||||
// Publish Data via DTS
|
||||
onPublishData();
|
||||
|
||||
return Core::FunctionReplyObject(m_data.id);
|
||||
}
|
||||
|
||||
Core::FunctionReplyObject ObjectEmergencyCall::removeObject()
|
||||
{
|
||||
if (!m_mainHandler->db()->removeAlmEmergencyCall(m_data.id))
|
||||
return Core::FunctionReplyObject(m_data.id, tr_lts("dds", "AlmEmergencyCall %1 can not be removed")).arg(m_data.id);
|
||||
|
||||
return Core::FunctionReplyObject(m_data.id);
|
||||
}
|
||||
|
||||
|
||||
void ObjectEmergencyCall::onPublishData()
|
||||
{
|
||||
AlarmManagement::AlmEmergencyCall ddsData;
|
||||
ddsData.id(m_data.id);
|
||||
ddsData.sampleTime(m_data.sampleTime);
|
||||
ddsData.incomingTime(m_data.incomingTime);
|
||||
ddsData.name(m_data.name.toStdString());
|
||||
ddsData.issi(m_data.issi);
|
||||
ddsData.position(Core::GeoPosition2D(m_data.position.x(), m_data.position.y()));
|
||||
ddsData.expired(m_data.expired);
|
||||
ddsData.deleted(m_data.deleted);
|
||||
ddsData.operatorId(m_data.operatorId);
|
||||
ddsData.comment(m_data.comment.toStdString());
|
||||
|
||||
INFO_LOG(m_logger) << "Publish AlmEmergencyCall-data to dds (" << m_data.id << ") ...";
|
||||
|
||||
if (!m_mainHandler->dds()->dtsAlm()->publish(ddsData))
|
||||
ERROR_LOG(m_logger) << "Error publishing AlmEmergencyCall-data to dds";
|
||||
}
|
||||
|
||||
}// namespace AlarmManagement
|
||||
+42
@@ -0,0 +1,42 @@
|
||||
#pragma once
|
||||
|
||||
#include <QObject>
|
||||
#include <dds_handler.h>
|
||||
#include "logger.h"
|
||||
|
||||
#include <DDS/Core/function_reply_object.h>
|
||||
//Generated
|
||||
#include <AlarmManagement/alm_db.h>
|
||||
|
||||
|
||||
namespace AlarmManagement {
|
||||
|
||||
class Initialization;
|
||||
|
||||
class ObjectEmergencyCall : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit ObjectEmergencyCall(Initialization *mainHandler, QObject *parent = nullptr);
|
||||
~ObjectEmergencyCall();
|
||||
|
||||
Core::FunctionReplyObject createObject(const Database::AlmEmergencyCall &data);
|
||||
Core::FunctionReplyObject updateObject(const Database::AlmEmergencyCall &data);
|
||||
Core::FunctionReplyObject removeObject();
|
||||
|
||||
int getId() const { return m_data.id; }
|
||||
const Database::AlmEmergencyCall &getData() const { return m_data; }
|
||||
Core::FunctionReplyObject updateObject() { return updateObject(m_data); }
|
||||
|
||||
protected Q_SLOTS:
|
||||
void onPublishData();
|
||||
|
||||
private:
|
||||
Initialization *m_mainHandler;
|
||||
Database::AlmEmergencyCall m_data;
|
||||
NGL::INGLLogger &m_logger;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
Executable
+42
@@ -0,0 +1,42 @@
|
||||
/**
|
||||
* Settings for AlarmManagement
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
*/
|
||||
|
||||
#include "settings.h"
|
||||
|
||||
#include <QtCore/QSettings>
|
||||
#include <nglsettings/nglsettings_settings.h>
|
||||
#include <ngltools/ngltools_filesystem.h>
|
||||
|
||||
namespace AlarmManagement
|
||||
{
|
||||
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 AlarmManagement
|
||||
Executable
+24
@@ -0,0 +1,24 @@
|
||||
/**
|
||||
* Settings for AlarmManagement
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include <QString>
|
||||
|
||||
namespace NGL
|
||||
{
|
||||
class Settings;
|
||||
}
|
||||
|
||||
namespace AlarmManagement
|
||||
{
|
||||
namespace Settings
|
||||
{
|
||||
NGL::Settings *settings();
|
||||
void setIniFile(const QString &ini);
|
||||
}
|
||||
|
||||
} // namespace AlarmManagement
|
||||
Reference in new issue
Block a user