Files
qt5-legatus-legacy/Lts/Proxies/GuezNasat/dds_handler.cpp
T
2026-08-13 18:33:10 +02:00

205 lines
6.9 KiB
C++
Executable File

/**
* DDS Handler for GuezNasat
* $Id$
* $HeadURL$
* $Author$
* Created by hjl, SLSE, 2016-11-14
*/
#include "dds_handler.h"
#include <TrainingAreaBase/tab_dts.h>
#include <DDS/DTS/generic_dts.h>
namespace GuezNasat
{
//-----------------------------------------------------------------------------
// ParticipantDds
//-----------------------------------------------------------------------------
Participant2Dds::Participant2Dds(const dds::domain::DomainParticipant &domainParticipant, int exerciseId)
: m_ddsConnector(new DDSConnector::DdsConnector(domainParticipant, IDL::PartitionType::Exercise, exerciseId))
, m_logger(getLogger("Participant2Dds"))
{
m_ddsConnector->initPublisherSubscriber();
m_ppmDtc = ParticipantManagement::Interface::Dtc::create(m_ddsConnector);
connect(m_ppmDtc.get(), &ParticipantManagement::Interface::Dtc::participantChanged,
this, &Participant2Dds::onParticipantChanged);
m_ppmDtc->enableParticipant();
// related to NLDEVCTRL-844: NASAT: Weiterleitung der Luftunterstützung sporadisch ausser Funktion
// Um die Erzeugung von DDS-Objecten weiter zu entzerren, wird bereits hier
// ein enableAirSupportImpactModify durchgeführt:
// (Hier ist die Zugehörigkeit zu einer Exercise gegeben)
// AES FTC
DEBUG_LOG(m_logger) << LOGFUNCTION << " create FTC..." << " exerciseId=" << exerciseId;
m_aesFtc = AreaEffectSimulation::Interface::Ftc::create(m_ddsConnector);
if (!m_aesFtc->enableAirSupportImpactModify())
{
ERROR_LOG(m_logger) << "Could not enable AES AirSupportImpactModify FTC for"
<< " exerciseId=" << exerciseId;
m_aesFtc = nullptr;
}
if (!m_aesFtc->enableExplosionClusterModify())
{
ERROR_LOG(m_logger) << "Could not enable AES enableExplosionClusterModify FTC for"
<< " exerciseId=" << exerciseId;
m_aesFtc = nullptr;
}
DEBUG_LOG(m_logger) << LOGFUNCTION << " create FTC..." << " exerciseId=" << exerciseId << " Done: " << m_aesFtc.get();
}
bool Participant2Dds::publish(const TrainingAreaBase::EquipmentPosition &pos)
{
if (!m_tabDts)
{
m_tabDts = TrainingAreaBase::Interface::Dts::create(m_ddsConnector);
if (!m_tabDts->enableEquipmentPosition())
{
ERROR_LOG(m_logger) << "Could not enable TAB equipment position DTS for "
<< m_ddsConnector->getDefaultPartition();
m_tabDts = nullptr;
return false;
}
}
return m_tabDts->publish(pos);
}
bool Participant2Dds::publish(const AreaEffectSimulation::AirSupportImpactModifyRequest &req,
AreaEffectSimulation::Interface::Ftc::AirSupportImpactModifyReplyHandler *handler)
{
return m_aesFtc->airSupportImpactModifyRequest(req, handler);
}
bool Participant2Dds::publish(const AreaEffectSimulation::ExplosionClusterModifyRequest &req,
AreaEffectSimulation::Interface::Ftc::ExplosionClusterModifyReplyHandler *handler)
{
return m_aesFtc->explosionClusterModifyRequest(req, handler);
}
bool Participant2Dds::publish(const GuezNasat::Nasat9Liner &nl)
{
if (!m_gnaDts)
{
m_gnaDts = GuezNasat::Interface::Dts::create(m_ddsConnector);
if (!m_gnaDts->enableNasat9Liner())
{
ERROR_LOG(m_logger) << "Could not enable GNA Nasat9Liner DTS for "
<< m_ddsConnector->getDefaultPartition();
m_gnaDts = nullptr;
return false;
}
}
return m_gnaDts->publish(nl);
}
void Participant2Dds::addParticipantToWatch(int participantId)
{
DEBUG_LOG(m_logger) << "addParticipantToWatch: " << participantId;
m_participantsToWatch += participantId;
}
void Participant2Dds::removeParticipantToWatch(int participantId)
{
DEBUG_LOG(m_logger) << "removeParticipantToWatch: " << participantId;
m_participantsToWatch -= participantId;
}
int Participant2Dds::partyId(int participantId) const
{
auto ret = -1;
std::function<bool(const ParticipantManagement::Participant&)> cb = [participantId, &ret](const ParticipantManagement::Participant &p)
{
if (p.id() != participantId)
return false;
ret = p.partyId();
return true;
};
m_ppmDtc->participants(cb);
return ret;
}
void Participant2Dds::onParticipantChanged(const ParticipantManagement::Participant &data, DataModification modType)
{
if (modType == DataModification::eRemoved)
return;
DEBUG_LOG(m_logger) << "onParticipantChanged: " << data.id()
<< ", " << m_participantsToWatch.contains(data.id())
<< ", " << m_participantsToWatch.size()
<< ", " << m_participantsToWatch.contains(data.id())
<< ", " << data.isDeleted();
if (!m_participantsToWatch.contains(data.id()))
return;
if (data.isDeleted())
emit participantRemoved(m_ddsConnector->getPartitionId(), data.id());
}
//-----------------------------------------------------------------------------
// DdsHandler
//-----------------------------------------------------------------------------
DdsHandler::DdsHandler(const std::shared_ptr<DDSConnector::DdsConnector> &ddsConnector)
: m_ddsConnector(std::make_shared<DDSConnector::DdsConnector>(ddsConnector->getDomainParticipant(), IDL::PartitionType::AllExercises))
, m_logger(getLogger("DdsHandler"))
{
DEBUG_LOG(m_logger) << "DdsHandler(" << m_ddsConnector->getDomainId() << ") for partition: " << m_ddsConnector->getDefaultPartition();
}
bool DdsHandler::init(const QStringList &qosFileList)
{
INFO_LOG(m_logger) << "--- Start GuezNasat DDSHandler.";
if (!m_ddsConnector->init(qosFileList))
{
ERROR_LOG(m_logger) << "Error initializing dds connections - aborting";
return false;
}
// default initialize Publisher and Subscriber
m_ddsConnector->initPublisherSubscriber();
// DTS
m_ddsDts = GuezNasat::Interface::Dts::create(m_ddsConnector);
bool bRet = m_ddsDts->enableNasatAircraft() &&
m_ddsDts->enableNasatAircraftParticipant();
INFO_LOG(m_logger) << "Dts initialised: " << bRet;
// FTS
m_ddsFts = GuezNasat::Interface::Fts::create(m_ddsConnector);
bRet &= m_ddsFts->enableAll();
INFO_LOG(m_logger) << "Fts initialised: " << bRet;
// EXM DTC
m_exmDtc = ExerciseManagement::Interface::Dtc::create(m_ddsConnector);
bRet &= m_exmDtc->enableExercise();
INFO_LOG(m_logger) << "EXM Dtc initialised: " << bRet;
// PDM DTC
m_pdmDtc = ProjectDataManagement::Interface::Dtc::create(m_ddsConnector);
bRet &= m_pdmDtc->enableChargeType();
INFO_LOG(m_logger) << "PDM Dtc initialised: " << bRet;
return bRet;
} // end of init()
std::shared_ptr<Participant2Dds> DdsHandler::ddsParticipant(int exerciseId)
{
auto it = m_nasatParticipant2Dds.find(exerciseId);
if (it != m_nasatParticipant2Dds.end())
{
auto ret = it.value().lock();
if (ret)
return ret;
m_nasatParticipant2Dds.erase(it);
}
auto ret = std::make_shared<Participant2Dds>(m_ddsConnector->getDomainParticipant(), exerciseId);
m_nasatParticipant2Dds[exerciseId] = ret;
return ret;
}
} // namespace GuezNasat