215 lines
6.7 KiB
C++
Executable File
215 lines
6.7 KiB
C++
Executable File
/**
|
|
* MainHandler for VideoOverlayManagement
|
|
* $Id$
|
|
* $HeadURL$
|
|
* $Author$
|
|
* Created by hjl, SLSE, 2016-06-23
|
|
*/
|
|
|
|
#include "main_handler.h"
|
|
#include "settings.h"
|
|
|
|
#include <QTimer>
|
|
|
|
#include <DDS/Core/pacemaker.h>
|
|
|
|
using namespace VideoOverlayManagement;
|
|
|
|
MainHandler::MainHandler(QObject *parent)
|
|
: QObject(parent)
|
|
, m_exerciseId(0)
|
|
, m_avsIf(new AvsInterface(true, this))
|
|
, m_avsConnectionState(AvsIfConnectionState::Undefined)
|
|
, m_ddsHandler(nullptr)
|
|
, m_handlerParticipantData(nullptr)
|
|
, m_handlerInfrastructureData(nullptr)
|
|
, m_handlerOverlays(nullptr)
|
|
, m_checkConnectTimer(new QTimer(this))
|
|
, m_keepAliveTriggerTimer(new QTimer(this))
|
|
, m_bAvsSocketWarnedOnce(false)
|
|
, m_logger(getLogger("MainHandler"))
|
|
{
|
|
} // end of ctor()
|
|
//-----------------------------------------------------------------------------
|
|
|
|
MainHandler::~MainHandler()
|
|
{
|
|
m_ddsHandler.reset();
|
|
} // end of dtor()
|
|
//-----------------------------------------------------------------------------
|
|
|
|
bool MainHandler::init(int domainId, int exerciseId)
|
|
{
|
|
INFO_LOG(m_logger) << "Start VideoOverlayManagement MainHandler.";
|
|
|
|
m_exerciseId = exerciseId;
|
|
|
|
// init AVS-Interface
|
|
QString hostName = Settings::getAvsHostname();
|
|
quint16 port = Settings::getAvsAvaPort();
|
|
INFO_LOG(m_logger) << "Init AVS-Interface Hostname/Ip:" << hostName
|
|
<< " Port: " << port;
|
|
|
|
m_avsIf->start(hostName, port);
|
|
|
|
connect(m_avsIf, &AvsInterface::avsIfConnectionState,
|
|
this, &MainHandler::onAvsIfConnectionState);
|
|
|
|
connect(m_avsIf, &AvsInterface::avsCmdState,
|
|
this, &MainHandler::onAvsCmdState);
|
|
|
|
connect(m_avsIf, &AvsInterface::avsKeepAliveTimeout,
|
|
this, &MainHandler::onAvsKeepAliveTimeout);
|
|
|
|
connect(m_keepAliveTriggerTimer, &QTimer::timeout,
|
|
this, &MainHandler::onSendKeepAlive);
|
|
|
|
// initialize DDS
|
|
// for VideoOverlayManagement => exerciseId = partitionId
|
|
m_ddsHandler.reset(new DdsHandler(domainId, exerciseId));
|
|
if (!m_ddsHandler->init())
|
|
{
|
|
ERROR_LOG(m_logger) << "Initialisation DdsHandler failed.";
|
|
if (m_ddsHandler->pacemaker())
|
|
m_ddsHandler->pacemaker()->setNewState(Core::RunningState::StartingError);
|
|
return false;
|
|
}
|
|
|
|
// initialize handlerParticipantData
|
|
m_handlerParticipantData.reset(new HandlerParticipantData(m_ddsHandler, this));
|
|
|
|
if (!m_handlerParticipantData->init())
|
|
{
|
|
ERROR_LOG(m_logger) << "Initialisation HandlerPlayerData failed.";
|
|
m_ddsHandler->pacemaker()->setNewState(Core::RunningState::StartingError);
|
|
return false;
|
|
}
|
|
|
|
// initialize handlerInfraStructureData
|
|
m_handlerInfrastructureData.reset(new HandlerInfrastructureData(m_ddsHandler, this));
|
|
|
|
if (!m_handlerInfrastructureData->init(m_exerciseId))
|
|
{
|
|
ERROR_LOG(m_logger) << "Initialisation HandlerInfrastructreData failed.";
|
|
m_ddsHandler->pacemaker()->setNewState(Core::RunningState::StartingError);
|
|
return false;
|
|
}
|
|
|
|
// Initialisation of OverlayHandler wait until AVS is connected
|
|
connect(m_checkConnectTimer, &QTimer::timeout,
|
|
this, &MainHandler::onTryToInitOverlayHandler);
|
|
m_checkConnectTimer->start(1000);
|
|
|
|
INFO_LOG(m_logger) << "VOM Handler initialized. (Connection to AVS may be still pending) ";
|
|
m_ddsHandler->pacemaker()->setNewState(Core::RunningState::Starting);
|
|
|
|
return true;
|
|
} // end of init()
|
|
//-----------------------------------------------------------------------------
|
|
|
|
bool MainHandler::onTryToInitOverlayHandler()
|
|
{
|
|
m_avsConnectionState = m_avsIf->getAvsIfState();
|
|
if (m_avsConnectionState != AvsIfConnectionState::Connected)
|
|
{
|
|
if (!m_bAvsSocketWarnedOnce)
|
|
{
|
|
m_bAvsSocketWarnedOnce = true;
|
|
WARNING_LOG(m_logger) << "MainHandler::onTryToInitOverlayHandler()"
|
|
<< " Wait for AvsIfConnectionState::Connected... ";
|
|
}
|
|
return false;
|
|
}
|
|
m_bAvsSocketWarnedOnce = true; // reset
|
|
|
|
m_checkConnectTimer->stop();
|
|
|
|
// initialize handlerOverlays
|
|
m_handlerOverlays.reset(new HandlerOverlays(m_avsIf, m_handlerParticipantData, m_handlerInfrastructureData, m_exerciseId, this));
|
|
|
|
if (!m_handlerOverlays->init())
|
|
{
|
|
ERROR_LOG(m_logger) << "Initialisation HandlerOverlays failed.";
|
|
m_ddsHandler->pacemaker()->setNewState(Core::RunningState::StoppedError);
|
|
return false;
|
|
}
|
|
|
|
INFO_LOG(m_logger) << "VOM Handler initialized. (Connection to AVS established) ";
|
|
m_ddsHandler->pacemaker()->setNewState(Core::RunningState::Running);
|
|
|
|
return true;
|
|
} // end of onTryToInitOverlayHandler()
|
|
//-----------------------------------------------------------------------------
|
|
|
|
void MainHandler::onAvsIfConnectionState(AvsIfConnectionState state)
|
|
{
|
|
switch (state)
|
|
{
|
|
case AvsIfConnectionState::Connected:
|
|
INFO_LOG(m_logger) << "AvsIfConnectionState::Connected ... start keepAliveTriggerTimer";
|
|
m_keepAliveTriggerTimer->start(Settings::getAvsKeepAliveTriggerRequestTime());
|
|
break;
|
|
case AvsIfConnectionState::Disconnected:
|
|
m_keepAliveTriggerTimer->stop();
|
|
break;
|
|
case AvsIfConnectionState::TryReconnect:
|
|
m_keepAliveTriggerTimer->stop();
|
|
break;
|
|
case AvsIfConnectionState::ConnectionError:
|
|
ERROR_LOG(m_logger) << "AvsIfConnectionState::ConnectionError !";
|
|
m_keepAliveTriggerTimer->stop();
|
|
m_ddsHandler->pacemaker()->setNewState(Core::RunningState::StoppedError);
|
|
break;
|
|
case AvsIfConnectionState::Undefined:
|
|
default:
|
|
WARNING_LOG(m_logger) << "Undefined AvsIfConnectionState !";
|
|
break;
|
|
}
|
|
} // end of onAvsIfConnectionState()
|
|
//-----------------------------------------------------------------------------
|
|
|
|
void MainHandler::onAvsCmdState(AvsCmdState state)
|
|
{
|
|
bool bOk = false;
|
|
switch (state)
|
|
{
|
|
case AvsCmdState::Ok:
|
|
INFO_LOG(m_logger) << "AvsCmdState::Ok";
|
|
bOk = true;
|
|
break;
|
|
case AvsCmdState::BadArguments:
|
|
WARNING_LOG(m_logger) << "AvsCmdState::BadArguments";
|
|
break;
|
|
case AvsCmdState::CommandNotStateValid:
|
|
WARNING_LOG(m_logger) << "AvsCmdState::CommandNotStateValid";
|
|
break;
|
|
case AvsCmdState::KeepAlive:
|
|
DEBUG_LOG(m_logger) << "AvsCmdState::KeepAlive";
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
|
|
if (!bOk)
|
|
{
|
|
// ToDo: Fehlermeldung an ServiceManagement senden
|
|
}
|
|
} // end of onAvsCmdState()
|
|
//-----------------------------------------------------------------------------
|
|
|
|
void MainHandler::onAvsKeepAliveTimeout()
|
|
{
|
|
// ToDo: Fehlermeldung an ServiceManagement senden
|
|
WARNING_LOG(m_logger) << "AVS KeepAlive timeout !";
|
|
} // end of onAvsKeepAliveTimeout()
|
|
//-----------------------------------------------------------------------------
|
|
|
|
void MainHandler::onSendKeepAlive()
|
|
{
|
|
QString cmd(QLatin1String("KEEPALIVE"));
|
|
QByteArray qba = cmd.toLatin1();
|
|
qba += "\r\n";
|
|
m_avsIf->sendCommand(qba);
|
|
} // end of onSendKeepAlive()
|
|
//-----------------------------------------------------------------------------
|