/** * @RDE_HEADER@ * MainHandler for InfrastructureManagement * $Id$ * $HeadURL$ * $Author$ * Created by Iuliana Ojog, SLSE, 2016-11-26 */ #include "main_handler.h" #include "handler_main_structure_element.h" #include "handler_instrumentation_asset.h" #include "handler_mounting_point_asset.h" #include "handler_effect_area.h" #include "handler_main_schedule.h" #include "handler_special_area.h" #include "parse_building_xml.h" #include "WebSocketInterface/websocket_interface_handler.h" #include "settings.h" #include #include #include #include namespace InfrastructureManagement { //------------------------------------------------------------------------------------------------------------- MainHandler::MainHandler() : m_logger(getLogger("MainHandler")) { } // end of ctor() //------------------------------------------------------------------------------------------------------------- MainHandler::~MainHandler() { m_handlerWebSocketInterface = nullptr; m_handlerMainSchedule = nullptr; m_handlerMountingPointAsset = nullptr; m_handlerInstrumentationAsset = nullptr; m_handlerMainStructureElement = nullptr; m_dbHandler = nullptr; m_ddsHandler = nullptr; m_exmDtc = nullptr; } // end of dtor() //------------------------------------------------------------------------------------------------------------- bool MainHandler::init(int domainId) { INFO_LOG(m_logger) << "--- Start InfrastructureManagement MainHandler."; // initialize DDS // for InfrastructureManagement => exerciseId = partitionId m_ddsHandler = std::make_shared(domainId); if (!m_ddsHandler->init()) { ERROR_LOG(m_logger) << "Initialisation DdsHandler failed."; if (m_ddsHandler->pacemaker()) m_ddsHandler->pacemaker()->setNewState(Core::RunningState::StartingError); return false; } auto pm = m_ddsHandler->pacemaker(); // initialize database m_dbHandler = std::make_shared(); if (!m_dbHandler->init(0, Settings::settings())) { ERROR_LOG(m_logger) << "Initialisation DbHandler failed."; pm->setNewState(Core::RunningState::StoppedError); return false; } pm->setNewState(Core::RunningState::Starting); QScopedPointer cs(Settings::useCoherentSet() ? new DDSConnector::CoherentSet(dds()->ddsConnector()) : nullptr); // read project specific data from database // publish project specific data // initialize handler MainStructureElement m_handlerMainStructureElement = std::make_shared(this); if (!m_handlerMainStructureElement->init()) { ERROR_LOG(m_logger) << "Initialisation HandlerMainStructureElement failed."; pm->setNewState(Core::RunningState::StoppedError); return false; } // pm->setNewState(Core::RunningState::Starting); // initialize handler Asset m_handlerInstrumentationAsset = std::make_shared(this); if (!m_handlerInstrumentationAsset->init()) { ERROR_LOG(m_logger) << "Initialisation HandlerInstrumentationAsset failed."; pm->setNewState(Core::RunningState::StartingError); return false; } // initialize handler MountingPointAsset m_handlerMountingPointAsset = std::make_shared(this); if (!m_handlerMountingPointAsset->init()) { ERROR_LOG(m_logger) << "Initialisation HandlerMountingPointAsset failed."; pm->setNewState(Core::RunningState::StartingError); return false; } // pm->setNewState(Core::RunningState::Starting); // initialize handler SoundArea m_handlerEffectArea = std::make_shared(this); if (!m_handlerEffectArea->init()) { ERROR_LOG(m_logger) << "Initialisation HandlerEffectArea failed."; pm->setNewState(Core::RunningState::StartingError); return false; } // initialize handler SpecailArea m_handlerSpecialArea = std::make_shared(this); if (!m_handlerSpecialArea->init()) { ERROR_LOG(m_logger) << "Initialisation HandlerSpecialArea failed."; pm->setNewState(Core::RunningState::StartingError); return false; } // init MainSchedule handler m_handlerMainSchedule = std::make_shared(this); if (!m_handlerMainSchedule->init()) { ERROR_LOG(m_logger) << "Initialisation HandlerMainSchedule failed."; pm->setNewState(Core::RunningState::StartingError); return false; } // pm->setNewState(Core::RunningState::Starting); m_exmDtc = ExerciseManagement::Interface::Dtc::create(m_ddsHandler->ddsConnector()); m_exmDtc->enableExercise(); QObject::connect(m_exmDtc.get(), &ExerciseManagement::Interface::Dtc::exerciseChanged, m_handlerMainStructureElement.get(), &HandlerMainStructureElement::onExerciseStateChanged); // init WebSocketInterface using namespace WebSocketInterface; m_handlerWebSocketInterface = std::make_shared(this); if (!m_handlerWebSocketInterface->init()) { ERROR_LOG(m_logger) << "Initialisation WebSocketInterface failed."; pm->setNewState(Core::RunningState::StartingError); return false; } INFO_LOG(m_logger) << "ISM MainHandler initialized."; pm->setNewState(Core::RunningState::Running); pm->addPort(m_handlerWebSocketInterface->webSocketPort(), Core::PortType::WebSocketServer); return true; } // end of init() //------------------------------------------------------------------------------------------------------------- std::shared_ptr MainHandler::db() const { return m_dbHandler->db(); } //------------------------------------------------------------------------------------------------------------- int MainHandler::exerciseId() const { if (dds()) return dds()->ddsConnector()->getPartitionId(); return -1; } //------------------------------------------------------------------------------------------------------------- QPointF rotatePoint(const double xIn, const double yIn, double angleDegree) { const double angleRad = angleDegree * LtsCoordTrans::deg2rad(); const double sinAngle = sin(angleRad); const double cosAngle = cos(angleRad); return QPointF(xIn * cosAngle - yIn * sinAngle, xIn * sinAngle + yIn * cosAngle); } } // namespace InfrastructureManagement;