Initial commit
This commit is contained in:
commit
b7d90b9afe
16245 files changed
+3396666
No files matched your search
+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()
|
||||
Reference in new issue
Block a user