Files
qt5-legatus-legacy/Lts/Proxies/GuezNasat/initialization.cpp
T
torstenandCopilot 3028302f7b Qt6 Migration: Merge latest Qt5 devel content and apply migration fixes
- Merged 292 changed files from dlbo snapshot
- Fixed IDL enum collisions (PortType, PdmEventType)
- Fixed Grantlee template for C++11 scoped enums
- Fixed CMake VERSION_GREATER syntax
- Added missing directories (THP, LtsRestClient, etc.)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-09-15 18:20:51 +00:00

189 lines
6.1 KiB
C++
Executable File
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/**
* Initialization for GuezNasat
* $Id$
* $HeadURL$
* $Author$
* Created by hjl, SLSE, 2016-11-14
*/
#include "initialization.h"
#include "settings.h"
#include "dds_handler.h"
#include "handler_nasat_aircraft.h"
#include "handler_nasat_aircraft_participant.h"
#include "handler_nasat_impact.h"
#include "handler_nasat_nine_liner.h"
#include "handler_participant.h"
#include "tcp_socket_handler.h"
#include "web_socket_handler.h"
#include <GuezNasat/gna_db.h>
#include <DDS/DDSConnector/dds_connector.h>
#include <DDS/Core/pacemaker.h>
#include <QTimer>
namespace GuezNasat
{
Initialization::Initialization()
: m_logger(getLogger("Initialization"))
{
} // end of ctor()
//-----------------------------------------------------------------------------
Initialization::~Initialization()
{
m_jsonSocketHandler = nullptr;
m_handlerNasatAircraft = nullptr;
m_handlerNasatAircraftParticipant = nullptr;
m_handlerNasatImpact = nullptr;
m_handlerNasatNineLiner = nullptr;
m_handlerParticipant = nullptr;
m_ddsHandler = nullptr;
m_dbHandler = nullptr;
} // end of dtor()
//-----------------------------------------------------------------------------
bool Initialization::initialize(const std::shared_ptr<DDSConnector::DdsConnector> &ddsConnector,
const QSqlDatabase &)
{
INFO_LOG(m_logger) << "Start GuezNasat Initialization.";
// initialize DDS
m_ddsHandler = std::make_shared<DdsHandler>(ddsConnector);
if (!m_ddsHandler->init())
{
ERROR_LOG(m_logger) << "Initialisation DdsHandler failed.";
return false;
}
// initialize database, we need an own DB connection
m_dbHandler = std::make_shared<DbHandler>();
if (!m_dbHandler->init(ddsConnector->getPartitionId(), Settings::settings()))
// if (!m_dbHandler->init(ddsConnector->getPartitionId(), sqlDb))
{
ERROR_LOG(m_logger) << "Initialisation DbHandler failed.";
return false;
}
// create HandlerNasatAircraft
m_handlerNasatAircraft.reset(new HandlerNasatAircraft(this));
// create HandlerNasatAircraftParticipant
m_handlerNasatAircraftParticipant.reset(new HandlerNasatAircraftParticipant(this));
// create HandlerNasatNineLiner
m_handlerNasatNineLiner.reset(new HandlerNasatNineLiner(this));
// create HandlerNasatAircraftParticipant
m_handlerNasatImpact.reset(new HandlerNasatImpact(this));
// create ParticipantPositionPublisher
m_handlerParticipant.reset(new HandlerParticipant(this));
// Connection to NASAT
if (Settings::useWebSocket())
{
INFO_LOG(m_logger) << "Using WebSocket";
m_jsonSocketHandler.reset(new WebSocketHandler);
}
else
{
INFO_LOG(m_logger) << "Using TcpSocket";
m_jsonSocketHandler.reset(new TcpSocketHandler);
}
INFO_LOG(m_logger) << "GuezNasat Initialization initialized";
return true;
} // end of init()
//-----------------------------------------------------------------------------
bool Initialization::loadFromDatabase()
{
TRACE_LOG(m_logger) << LOGFUNCTION << "START";
if (!m_ddsHandler ||
!m_dbHandler ||
!m_handlerNasatAircraft ||
!m_handlerNasatAircraftParticipant ||
!m_handlerNasatImpact ||
!m_handlerNasatNineLiner ||
!m_handlerParticipant ||
!m_jsonSocketHandler)
return false;
if (!m_handlerNasatAircraft->init())
{
ERROR_LOG(m_logger) << "Initialisation HandlerNasatAircraft failed.";
return false;
}
if (!m_handlerNasatAircraftParticipant->init())
{
ERROR_LOG(m_logger) << "Initialisation HandlerNasatAircraftParticipant failed.";
return false;
}
if (!m_handlerNasatImpact->init())
{
ERROR_LOG(m_logger) << "Initialisation HandlerNasatImpact failed.";
return false;
}
if (!m_handlerNasatNineLiner->init())
{
ERROR_LOG(m_logger) << "Initialisation HandlerNasatNineLiner failed.";
return false;
}
if (!m_handlerParticipant->init())
{
ERROR_LOG(m_logger) << "Initialisation ParticipantPositionPublisher failed.";
return false;
}
// related to NLDEVCTRL-844: NASAT: Weiterleitung der Luftunterstützung sporadisch ausser Funktion
// Waiting for all (relevant) exercises (AES) to be started, sounds better
// But it´s complicated (some ServiceManagement topics would have to be considered)
// 'AES process is started' is not enough, but when is the FTS available???
// So accept a bailing out (in case of (re-)starting GNA while NASAT is sending data)
// and keep it simple:
#define START_DELAYED
#ifdef START_DELAYED
QTimer::singleShot(31000, m_jsonSocketHandler.get(), [this]() {
NOTICE_LOG(m_logger) << "Initialisation SocketHandler ....";
if (!m_jsonSocketHandler->init(Settings::socketListenPort()))
{
ERROR_LOG(m_logger) << "Initialisation WebSocketHandler failed.";
}
});
#else
if (!m_jsonSocketHandler->init(Settings::socketListenPort()))
{
ERROR_LOG(m_logger) << "Initialisation WebSocketHandler failed.";
return false;
}
#endif // START_DELAYED
QObject::connect(m_jsonSocketHandler.get(), &AbstractSocketHandler::simulationStatusReceived,
m_handlerNasatAircraft.get(), &HandlerNasatAircraft::simulationStatusChanged);
QObject::connect(m_handlerNasatAircraft.get(), &HandlerNasatAircraft::activateNasatAircraftSimulation,
m_jsonSocketHandler.get(), &AbstractSocketHandler::setSimulationStatus);
QObject::connect(m_handlerNasatAircraft.get(), &HandlerNasatAircraft::nasatIdChanged,
m_handlerParticipant.get(), &HandlerParticipant::onNasatIdChanged);
QObject::connect(m_jsonSocketHandler.get(), &AbstractSocketHandler::positionReceived,
m_handlerParticipant.get(), &HandlerParticipant::onNasatPosition);
QObject::connect(m_jsonSocketHandler.get(), &AbstractSocketHandler::weaponReleaseReceived,
m_handlerNasatImpact.get(), &HandlerNasatImpact::nasatWeaponRelease);
QObject::connect(m_jsonSocketHandler.get(), &AbstractSocketHandler::nineLinerReceived,
m_handlerNasatNineLiner.get(), &HandlerNasatNineLiner::nineLinerReceived);
TRACE_LOG(m_logger) << LOGFUNCTION << "END";
return true;
}
std::shared_ptr<DatabaseInterface> Initialization::db() const
{
return m_dbHandler->db();
}
} // namespace GuezNasat