/** * MainHandler for AereaEffectSimulation * $Id$ * $HeadURL$ * $Author$ */ #include "main_handler.h" #include "settings.h" #include "logger.h" #include "handler_air_support_impact.h" #include "handler_explosion_single.h" #include "handler_explosion_area.h" #include "handler_explosion_cluster.h" #include "handler_effect_cluster.h" #include "handler_functional_area.h" #include "handler_technical_area.h" #include "handler_ncontamination.h" #include "handler_bccontamination.h" #include "handler_booby_trap.h" #include "handler_off_route_mine.h" #include "handler_mine_area.h" #include "handler_mine_corridor.h" #include "handler_danger_area.h" #include "handler_recon_area.h" #include "handler_charge_administration.h" #include "meteo_data_provider.h" #include "handler_borderline.h" #include "handler_gas_pipe.h" #include "handler_dus_single_mine.h" #include "special_area_provider.h" #include "handler_charge_effect.h" #include "handler_trajectory.h" #include "handler_effector.h" // Elevation / Trajectory #include #include #include #include #include #if QT_VERSION >= QT_VERSION_CHECK(5, 10, 0) #include #endif namespace AreaEffectSimulation { MainHandler::MainHandler(QObject *parent) : QObject(parent) , m_logger(getLogger("MainHandler")) { #if QT_VERSION >= QT_VERSION_CHECK(5, 10, 0) QRandomGenerator(time(nullptr)); #else qsrand(time(nullptr)); #endif } MainHandler::~MainHandler() { m_handlerAirSupportImpact = nullptr; m_handlerExplosionSingle = nullptr; m_handlerExplosionArea = nullptr; m_handlerExplosionCluster = nullptr; m_handlerEffectCluster = nullptr; m_handlerFunctionalArea = nullptr; m_handlerTechnicalArea = nullptr; m_handlerNContamination = nullptr; m_handlerBCContamination = nullptr; m_handlerBoobyTrap = nullptr; m_handlerMineArea = nullptr; m_handlerMineCorridor = nullptr; m_handlerDangerArea = nullptr; m_handlerChargeAdmin = nullptr; m_handlerReconArea = nullptr; m_handlerBorderline = nullptr; m_handlerGasPipe = nullptr; m_handlerDusSingleMine = nullptr; m_handlerChargeEffect = nullptr; m_handlerTrajectory = nullptr; m_meteoData = nullptr; m_ddsHandler = nullptr; m_dbHandler = nullptr; m_dbHandlerEx0 = nullptr; // LtsElevationManager and TrajectoryGenerator // should do cleanup on their own :-) } bool MainHandler::init(int domainId, int exerciseId) { NOTICE_LOG(m_logger) << "\n\n*** Start AES ***\n\n"; // initialize database m_dbHandler = std::make_shared(); if(!m_dbHandler->init(exerciseId, Settings::settings())) { ERROR_LOG(m_logger) << "Initialisation DbHandler failed."; return false; } if (exerciseId > 0) { m_dbHandlerEx0 = std::make_shared(); if (!m_dbHandlerEx0->init(0, Settings::settings())) // need a second db connection due to username/password { ERROR_LOG(m_logger) << "Could not init DbHandler"; m_ddsHandler->pacemaker()->setNewState(Core::RunningState::StartingError, QStringLiteral("Could not init DbHandler")); return false; } } else { m_dbHandlerEx0 = m_dbHandler; } // initialize DDS m_ddsHandler = std::make_shared(domainId, exerciseId); if (!m_ddsHandler->init()) { ERROR_LOG(m_logger) << "Initialisation DdsHandler failed."; return false; } m_meteoData = std::make_shared(this); m_specialAreaProvider = std::make_shared(this); // read project specific data from database // publish project specific data // initialize the specific AES handler return initAESHandler(); } bool MainHandler::initAESHandler() { // init this one first as it's needed by ExplosionArea/Single: m_handlerChargeAdmin = std::make_shared(this); if (!m_handlerChargeAdmin->init()) return false; m_handlerAirSupportImpact = std::make_shared(this); if (!m_handlerAirSupportImpact->init()) return false; m_handlerExplosionSingle = std::make_shared(this); if (!m_handlerExplosionSingle->init()) return false; m_handlerExplosionArea = std::make_shared(this); if (!m_handlerExplosionArea->init()) return false; // prepare some basics for HandlerExplosionCluster // - TrajectoryGenerator // - LtsElevationManager DEBUG_LOG(m_logger) << LOGFUNCTION << " ****** std::make_sharedexerciseId(); 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. // Thuis is no error. ltsElevationManager->waitForInitialization(); } #ifndef LTS_DEBUG #ifndef Q_OS_WIN // GUEZE-2195 if (!ltsElevationManager) { ERROR_LOG(m_logger) << LOGFUNCTION << " LtsElevation::createInstance failed."; m_ddsHandler->pacemaker()->setNewState(Core::RunningState::inner_enum::StoppedError); return false; } #endif // Q_OS_WIN #endif // LTS_DEBUG TrajectoryGenerator *trajectoryGenerator = TrajectoryGenerator::getInstance(this->dds()->exerciseId(), this->dds()->exmDtc(), this->dds()->asmDtc()); if (!trajectoryGenerator) { ERROR_LOG(m_logger) << LOGFUNCTION << " TrajectoryGenerator::getInstance failed."; m_ddsHandler->pacemaker()->setNewState(Core::RunningState::inner_enum::StoppedError); return false; } m_handlerExplosionCluster = std::make_shared(this); if (!m_handlerExplosionCluster->init()) return false; DEBUG_LOG(m_logger) << LOGFUNCTION << " ****** std::make_shared(this); if (!m_handlerFunctionalArea->init()) return false; m_handlerTechnicalArea = std::make_shared(this); if (!m_handlerTechnicalArea->init()) return false; m_handlerNContamination = std::make_shared(this); if (!m_handlerNContamination->init()) return false; m_handlerBCContamination = std::make_shared(this); if (!m_handlerBCContamination->init()) return false; m_handlerBoobyTrap = std::make_shared(this); if (!m_handlerBoobyTrap->init()) return false; m_handlerOffRouteMine = std::make_shared(this); if (!m_handlerOffRouteMine->init()) return false; // Corridor needed for Mine Area, so instatiate first! m_handlerMineCorridor = std::make_shared(this); if (!m_handlerMineCorridor->init()) return false; m_handlerMineArea = std::make_shared(this); if (!m_handlerMineArea->init()) return false; m_handlerDangerArea = std::make_shared(this); if (!m_handlerDangerArea->init()) return false; m_handlerReconArea = std::make_shared(this); if (!m_handlerReconArea->init()) return false; m_handlerDusSingleMine = std::make_shared(this); if (!m_handlerDusSingleMine->init()) return false; // create HandlerBorderline m_handlerBorderline = std::make_shared(this); if (!m_handlerBorderline->init()) { ERROR_LOG(m_logger) << LOGFUNCTION << " Initialisation HandlerBorderline failed."; m_ddsHandler->pacemaker()->setNewState(Core::RunningState::inner_enum::StoppedError); return false; } // create HandlerGasPipe m_handlerGasPipe = std::make_shared(this); if (!m_handlerGasPipe->init()) { ERROR_LOG(m_logger) << LOGFUNCTION << " Initialisation HandlerGasPipe failed."; m_ddsHandler->pacemaker()->setNewState(Core::RunningState::inner_enum::StoppedError); return false; } // create HandlerChargeEffect m_handlerChargeEffect = std::make_shared(this); if (!m_handlerChargeEffect->init()) { ERROR_LOG(m_logger) << LOGFUNCTION << " Initialisation HandlerChargeEffect failed."; m_ddsHandler->pacemaker()->setNewState(Core::RunningState::inner_enum::StoppedError); return false; } // create HandlerTrajectory m_handlerTrajectory = std::make_shared(this); // m_handlerTrajectory: no init required // create HandlerEffector m_handlerEffector = std::make_shared(this); if (!m_handlerEffector->init()) { ERROR_LOG(m_logger) << LOGFUNCTION << " Initialisation HandlerChargeEffect failed."; m_ddsHandler->pacemaker()->setNewState(Core::RunningState::inner_enum::StoppedError); return false; } // Effect Cluster last as we need Effector first m_handlerEffectCluster = std::make_shared(this); if (!m_handlerEffectCluster->init()) return false; m_ddsHandler->pacemaker()->setNewState(Core::RunningState::Running); return true; } std::shared_ptr MainHandler::db() { return m_dbHandler->db(); } std::shared_ptr MainHandler::dbEx0() { return m_dbHandlerEx0->db(); } ProjectDataManagement::GearClass MainHandler::gearClassOfChargeTypeId(int chargeTypeId) const { return m_ddsHandler->pdmDtc()->gearClassFromChargeTypeId(chargeTypeId); } } // namespace AreaEffectSimulation