217 lines
7.5 KiB
C++
Executable File
217 lines
7.5 KiB
C++
Executable File
/**
|
|
* MainHandler for MessageDataManagement
|
|
* $Id$
|
|
* $HeadURL$
|
|
* $Author$
|
|
* Created by hjl, SLSE, 2016-09-21
|
|
*/
|
|
|
|
#include "main_handler.h"
|
|
#include "settings.h"
|
|
|
|
#include <Core/pacemaker.h>
|
|
#include <LtsPluginManager/lts_plugin_loader.h>
|
|
|
|
#include <LtsElevation/lts_elevation_manager.h>
|
|
#include <LtsCoordinate/lts_coordinate.h>
|
|
|
|
|
|
namespace CentralEffectSimulation
|
|
{
|
|
|
|
MainHandler::MainHandler(QObject *parent)
|
|
: QObject(parent)
|
|
, m_logger(CentralEffectSimulation::getLogger("MainHandler"))
|
|
{
|
|
INFO_LOG(m_logger) << "MainHandler::MainHandler";
|
|
} // end of ctor()
|
|
//-----------------------------------------------------------------------------
|
|
|
|
MainHandler::~MainHandler()
|
|
{
|
|
m_ddsHandler.reset();
|
|
m_db.reset();
|
|
m_handlerParticipant.reset();
|
|
m_handlerBuildingData.reset();
|
|
|
|
INFO_LOG(m_logger) << "MainHandler::~MainHandler";
|
|
} // end of dtor()
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
bool MainHandler::loadPlugin(const LtsPluginManager::PluginInstance &pi)
|
|
{
|
|
DEBUG_LOG(m_logger) << "Trying to load ces plugin '" << pi.fullFileName << "'...";
|
|
|
|
Plugin::Plugin *cesPlugin = qobject_cast<Plugin::Plugin *>(pi.plugin);
|
|
if (!cesPlugin)
|
|
{
|
|
WARNING_LOG(m_logger) << "failed loading a ces plugin - not a CentralEffectSimulation object!";
|
|
return false;
|
|
}
|
|
DEBUG_LOG(m_logger) << "... success";
|
|
std::shared_ptr<Plugin::Interface> ifc = cesPlugin->createInterface(this,
|
|
// m_ddsHandler->dds(),
|
|
nullptr,
|
|
Settings::settings(),
|
|
this);
|
|
|
|
DEBUG_LOG(m_logger) << "Vorher: m_interfaces.size=" << m_interfaces.size();
|
|
|
|
|
|
if (!ifc || !ifc->init(m_domainId, m_exerciseId))
|
|
{
|
|
WARNING_LOG(m_logger) << "Could not initialize CentralEffectSimulation plugin";
|
|
return false;
|
|
}
|
|
|
|
static int counter = 0;
|
|
INFO_LOG(m_logger) << "Loading and init of ces_plugin successfull: "
|
|
<< ++counter
|
|
<< " pluginName = '" << pi.pluginName << "'"
|
|
<< ", filename '" << pi.fullFileName << "'";
|
|
|
|
m_interfaces.push_back(ifc);
|
|
DEBUG_LOG(m_logger) << "Nachher: m_interfaces.size=" << m_interfaces.size();
|
|
|
|
DEBUG_LOG(m_logger) << "ECHO!" << ifc->echo(QStringLiteral("TEST"));
|
|
|
|
return true;
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool MainHandler::init(int domainId, int exerciseId)
|
|
{
|
|
m_domainId = domainId;
|
|
m_exerciseId = exerciseId;
|
|
INFO_LOG(m_logger) << "Start MessageDataManagement MainHandler. domainId =" << domainId
|
|
<< " exerciseId=" << exerciseId;
|
|
|
|
// initialize database
|
|
m_dbHandler = std::make_shared<DbHandler>();
|
|
|
|
if (!m_dbHandler->init(exerciseId, Settings::settings()))
|
|
{
|
|
ERROR_LOG(m_logger) << "Initialisation DbHandler failed.";
|
|
return false;
|
|
}
|
|
m_db = m_dbHandler->db();
|
|
INFO_LOG(m_logger) << "MainHandler::init DbHandler initialized. ";
|
|
|
|
|
|
// initialize DDS
|
|
m_ddsHandler = std::make_shared<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;
|
|
}
|
|
|
|
|
|
NOTICE_LOG(m_logger) << LOGFUNCTION << " LtsElevationManager... ";
|
|
|
|
LtsElevation::LTS_ELEVATION_MANAGER_TYPE ltsElevationManager = LtsElevation::LtsElevationManager::createInstance(exerciseId,
|
|
dds()->exmDtc(),
|
|
dds()->asmDtc());
|
|
if (ltsElevationManager)
|
|
{
|
|
// waitForInitialization,
|
|
// ElevationFile is read in a workerThread and waitForInitialization is used via QFutureWatcher
|
|
// So the logMsg 'Finished reading elevation map of file' will be shown with a delay.
|
|
// This is no error.
|
|
ltsElevationManager->waitForInitialization();
|
|
DEBUG_LOG(m_logger) << LOGFUNCTION << " LtsElevationManager... waitForInitialization DONE";
|
|
|
|
// using elevationCbFunc = std::function<double(double, double, double, bool*)>;
|
|
using namespace std::placeholders;
|
|
LtsCoordTrans::LtsCoordinate::elevationCbFunc elevationCB = std::bind(&LtsElevation::LtsElevationManager::elevation,
|
|
ltsElevationManager.data(), _1, _2, _3, _4);
|
|
LtsCoordTrans::LtsCoordinate::setElevationCallback(elevationCB);
|
|
|
|
NOTICE_LOG(m_logger) << LOGFUNCTION << " LtsElevationManager... LtsCoordinate::setElevationCallback DONE";
|
|
}
|
|
|
|
|
|
DEBUG_LOG(m_logger) << LOGFUNCTION << " LtsElevationManager... DONE ";
|
|
|
|
|
|
|
|
// initialize handlerBuildingData do this before init AesDataHandler
|
|
m_handlerBuildingData = std::make_shared<HandlerBuildingData>(m_ddsHandler, this);
|
|
|
|
if (!m_handlerBuildingData->init())
|
|
{
|
|
ERROR_LOG(m_logger) << "Initialisation HandlerBuildingData failed.";
|
|
m_ddsHandler->pacemaker()->setNewState(Core::RunningState::StartingError);
|
|
return false;
|
|
}
|
|
|
|
|
|
// initialize handlerParticipant
|
|
//m_handlerParticipant = std::make_shared<HandlerParticipant>(m_ddsHandler,
|
|
// this);
|
|
|
|
int cheatingDistanceVehicle = Settings::cesCheatingDistanceVehicle();
|
|
int cheatingDistanceSoldier = Settings::cesCheatingDistanceSoldier();
|
|
|
|
m_handlerParticipant = std::make_shared<HandlerParticipant>(m_ddsHandler,
|
|
m_handlerBuildingData,
|
|
cheatingDistanceVehicle,
|
|
cheatingDistanceSoldier,
|
|
this);
|
|
|
|
if (!m_handlerParticipant->init())
|
|
{
|
|
ERROR_LOG(m_logger) << "Initialisation HandlerParticipant failed.";
|
|
m_ddsHandler->pacemaker()->setNewState(Core::RunningState::StartingError);
|
|
return false;
|
|
}
|
|
|
|
|
|
///////////////
|
|
/// Plugins ///
|
|
///////////////
|
|
|
|
// ProxyBuilding:
|
|
// some plugins need access to other plugins (siblings)
|
|
// If a plugin would like to offer a function, the ProxyXY could be used;
|
|
m_proxyBuilding = std::make_shared<ProxyBuilding>();
|
|
|
|
|
|
|
|
|
|
auto cb = [&](const LtsPluginManager::PluginInstance &pi) { return loadPlugin(pi); };
|
|
LtsPluginManager::LtsPluginLoader::getInstance()->loadPlugins(LtsPluginManager::PluginType::SPECIAL,
|
|
cb,
|
|
QStringList(),
|
|
QStringLiteral("ces"));
|
|
|
|
if (m_interfaces.empty())
|
|
{
|
|
WARNING_LOG(m_logger) << "Could not load any Central Effect Simulation plugin";
|
|
return false;
|
|
}
|
|
INFO_LOG(m_logger) << "m_interfaces size=" << m_interfaces.size();
|
|
|
|
// for (/*std::shared_ptr<*/Plugin::EchoInterface/*> &*/ *ifc : m_interfaces)
|
|
// INFO_LOG(m_logger) << "ECHO! " << ifc->echo(QStringLiteral("TEST"));
|
|
//m_txHandler->addTxHandler(ifc->sendToTab());
|
|
///////////////////
|
|
/// End Plugins ///
|
|
///////////////////
|
|
|
|
m_ddsHandler->pacemaker()->setNewState(Core::RunningState::Running);
|
|
|
|
return true;
|
|
} // end of init()
|
|
//-----------------------------------------------------------------------------
|
|
|
|
} // namespace
|
|
|