157 lines
4.4 KiB
C++
Executable File
157 lines
4.4 KiB
C++
Executable File
/**
|
|
* @RDE_HEADER@
|
|
* RtProfileObserver
|
|
* $Id$
|
|
* $HeadURL$
|
|
* $Author$
|
|
* Created by Patric Karwat, SLSE, 2016-08-17
|
|
*/
|
|
|
|
#include "rt_profile_observer.h"
|
|
#include <AudioVideoManagement/ava_session.h>
|
|
#include <AudioVideoManagement/ava_control.h>
|
|
#include <AudioVideoManagement/avm_dtc.h>
|
|
#include <LtsUtilsCore/data_modification_enum.h>
|
|
#include <QMap>
|
|
|
|
|
|
namespace AudioVideoManagement
|
|
{
|
|
|
|
RtProfileObserver::RtProfileObserver(Interface::Dtc *dtc, AvaSession *avaSession, RtState *rtState, int exerciseId, int operatorId)
|
|
: m_exerciseId(exerciseId)
|
|
, m_operatorId(operatorId)
|
|
, m_dtc(dtc)
|
|
, m_avaSession(avaSession)
|
|
, m_avaControl(avaSession->control())
|
|
, m_rtState(rtState)
|
|
{
|
|
Q_ASSERT(dtc);
|
|
Q_ASSERT(avaSession);
|
|
Q_ASSERT(rtState);
|
|
|
|
connect(m_avaSession, &AvaSession::sessionEstablished, this, &RtProfileObserver::onSessionEstablished);
|
|
connect(m_dtc, &Interface::Dtc::tvcConfigChanged, this, &RtProfileObserver::onTvcConfigChanged);
|
|
connect(m_dtc, &Interface::Dtc::cnrConfigChanged, this, &RtProfileObserver::onCnrConfigChanged);
|
|
connect(m_dtc, &Interface::Dtc::cnrTvcProfileChanged, this, &RtProfileObserver::onCnrTvcProfileChanged);
|
|
|
|
m_profile = getProfile();
|
|
|
|
if (m_avaSession->isEstablished())
|
|
onSessionEstablished();
|
|
}
|
|
|
|
void RtProfileObserver::onSessionEstablished()
|
|
{
|
|
loadVoiceRadioCommunicationMenu();
|
|
}
|
|
|
|
void RtProfileObserver::loadVoiceRadioCommunicationMenu()
|
|
{
|
|
m_avaControl->setRtProfile(m_rtState, defaultRtChannels());
|
|
}
|
|
|
|
void RtProfileObserver::onCnrConfigChanged(const CnrConfig &cnrConfig, DataModification modType)
|
|
{
|
|
if (modType != DataModification::eModified)
|
|
return;
|
|
if (!isInProfile(cnrConfig))
|
|
return;
|
|
m_avaControl->changeRtProfileCircuitName(m_rtState, {RadioSystem::Cnr, cnrConfig.id(), cnrConfig.radioCircuit()});
|
|
}
|
|
|
|
void RtProfileObserver::onTvcConfigChanged(const TvcConfig &tvcConfig, DataModification modType)
|
|
{
|
|
if (modType != DataModification::eModified)
|
|
return;
|
|
if (!isInProfile(tvcConfig))
|
|
return;
|
|
m_avaControl->changeRtProfileCircuitName(m_rtState, {RadioSystem::Tvc, tvcConfig.id(), tvcConfig.radioCircuit()});
|
|
}
|
|
|
|
void RtProfileObserver::onCnrTvcProfileChanged(const CnrTvcProfile &profile, DataModification modType)
|
|
{
|
|
Q_UNUSED(modType);
|
|
|
|
if (profile.exerciseId() != m_exerciseId || profile.operatorId() != m_operatorId)
|
|
return;
|
|
|
|
switch (modType)
|
|
{
|
|
case DataModification::eAdded:
|
|
case DataModification::eModified:
|
|
m_profile = profile;
|
|
break;
|
|
case DataModification::eRemoved:
|
|
m_profile.reset();
|
|
break;
|
|
default:
|
|
Q_ASSERT(false);
|
|
}
|
|
|
|
loadVoiceRadioCommunicationMenu();
|
|
}
|
|
|
|
QVector<RtState::RadioCircuit> RtProfileObserver::defaultRtChannels() const
|
|
{
|
|
if (!m_profile)
|
|
return {};
|
|
|
|
const QMap<int, CnrConfig> cnrcs = m_dtc->cnrConfigs();
|
|
const QMap<int, TvcConfig> tvccs = m_dtc->tvcConfigs();
|
|
|
|
QVector<RtState::RadioCircuit> rtChannels;
|
|
rtChannels.reserve(m_profile->data().size());
|
|
for (const auto &cnrTvcProfileData : m_profile->data())
|
|
{
|
|
std::string circuitName;
|
|
if (cnrTvcProfileData.radioSystemId() == RadioSystem::Cnr)
|
|
circuitName = cnrcs.value(cnrTvcProfileData.radioCircuitId()).radioCircuit();
|
|
else
|
|
circuitName = tvccs.value(cnrTvcProfileData.radioCircuitId()).radioCircuit();
|
|
|
|
rtChannels.push_back({cnrTvcProfileData.radioSystemId(), cnrTvcProfileData.radioCircuitId(), circuitName});
|
|
}
|
|
|
|
return rtChannels;
|
|
}
|
|
|
|
boost::optional<CnrTvcProfile> RtProfileObserver::getProfile() const
|
|
{
|
|
boost::optional<CnrTvcProfile> foundProfile;
|
|
std::function<bool(const CnrTvcProfile &profile)> forUserInExercise = [this, &foundProfile] (const CnrTvcProfile &profile)
|
|
{
|
|
if (profile.exerciseId() != m_exerciseId || profile.operatorId() != m_operatorId)
|
|
return false;
|
|
foundProfile = profile;
|
|
return true;
|
|
};
|
|
|
|
m_dtc->cnrTvcProfiles(forUserInExercise);
|
|
return foundProfile;
|
|
}
|
|
|
|
bool RtProfileObserver::isInProfile(const CnrConfig &cnrConfig) const
|
|
{
|
|
return isInProfile(RadioSystem::Cnr, cnrConfig.id());
|
|
}
|
|
|
|
bool RtProfileObserver::isInProfile(const TvcConfig &tvcConfig) const
|
|
{
|
|
return isInProfile(RadioSystem::Tvc, tvcConfig.id());
|
|
}
|
|
|
|
bool RtProfileObserver::isInProfile(RadioSystem radioSystem, int32_t id) const
|
|
{
|
|
if (!m_profile)
|
|
return false;
|
|
|
|
for (const auto &cnrTvcProfileData : m_profile->data())
|
|
if (cnrTvcProfileData.radioSystemId() == radioSystem && cnrTvcProfileData.radioCircuitId() == id)
|
|
return true;
|
|
|
|
return false;
|
|
}
|
|
|
|
} //namespace AudioVideoManagement
|