Files
qt5-legatus-legacy/Lts/Services/AudioVideoManagement/stream_name_mapping_publisher.cpp
2026-08-13 18:33:10 +02:00

113 lines
3.2 KiB
C++
Executable File

/**
* @RDE_HEADER@
* StreamNameMappingPublisher
* $Id$
* $HeadURL$
* $Author$
* Created by Christian Fröbel, NLSE, 2018-03-13
*/
#include "stream_name_mapping_publisher.h"
#include "audio_video_handler_impl.h"
#include <AudioVideoManagement/avm_dts.h>
#include <InfrastructureManagement/ism_dtc.h>
#include <InfrastructureManagement/ism.hpp>
#include <LtsUtilsCore/data_modification_enum.h>
#include <QtGlobal>
#include <string>
namespace
{
bool isMountingPointOfInterest(const InfrastructureManagement::StructureElement &se)
{
if (se.structureElementTypeId() != InfrastructureManagement::StructureElementType::MountingPoint)
return false;
if (se.mountingPointTypeId() == InfrastructureManagement::MountingPointType::IndoorCamera ||
se.mountingPointTypeId() == InfrastructureManagement::MountingPointType::OutdoorCamera ||
se.mountingPointTypeId() == InfrastructureManagement::MountingPointType::AnnouncementUnit)
return true;
return false;
}
std::string displayName(const InfrastructureManagement::StructureElement &mp)
{
Q_ASSERT(isMountingPointOfInterest(mp));
if (mp.displayName().size() > 0)
return mp.displayName();
return AudioVideoManagement::AudioVideoHandlerImpl::internalStreamName(mp.id()).toStdString();
}
} // anonymous namespace
namespace AudioVideoManagement
{
StreamNameMappingPublisher::StreamNameMappingPublisher(InfrastructureManagement::Interface::Dtc *ismDtc, Interface::Dts *dts)
: m_ismDtc(ismDtc)
, m_dts(dts)
{
Q_ASSERT(ismDtc);
Q_ASSERT(dts);
QObject::connect(m_ismDtc, &InfrastructureManagement::Interface::Dtc::mainStructureElementChanged, this, &StreamNameMappingPublisher::onMainStructureElementChanged);
}
void StreamNameMappingPublisher::onMainStructureElementChanged(const InfrastructureManagement::MainStructureElement &mse, DataModification modType)
{
switch (modType)
{
case DataModification::eAdded:
Q_FALLTHROUGH();
case DataModification::eModified:
onMseChanged(mse);
return;
case DataModification::eRemoved:
onMseRemoved(mse);
return;
default:
Q_ASSERT(false);
}
}
void StreamNameMappingPublisher::onMseChanged(const InfrastructureManagement::MainStructureElement &mse)
{
const auto &structureElements = mse.elements();
for (auto &se : structureElements)
if (isMountingPointOfInterest(se))
publish(se);
}
void StreamNameMappingPublisher::onMseRemoved(const InfrastructureManagement::MainStructureElement &mse)
{
const auto &structureElements = mse.elements();
for (auto &se : structureElements)
if (isMountingPointOfInterest(se))
remove(se);
}
void StreamNameMappingPublisher::publish(const InfrastructureManagement::StructureElement &mountingPoint)
{
StreamName streamName;
streamName.mountingPointId(mountingPoint.id());
streamName.internalName(AudioVideoHandlerImpl::internalStreamName(mountingPoint.id()).toStdString());
streamName.displayName(displayName(mountingPoint));
if (m_streamNames[mountingPoint.id()] != streamName)
m_dts->publish(streamName);
m_streamNames[mountingPoint.id()] = streamName;
}
void StreamNameMappingPublisher::remove(const InfrastructureManagement::StructureElement &mountingPoint)
{
m_dts->removeStreamNameByKey(mountingPoint.id());
}
} // namespace AudioVideoManagement