/** * @RDE_HEADER@ * Routing Test - main object * $Id$ * $HeadURL$ * $Author$ */ #include "main_handler.h" #include #include #include #include #include #include #include #include #include namespace RoutingService { MainHandler::MainHandler() : m_logger(getLogger("MainHandler")) { } MainHandler::~MainHandler() { m_pacemaker = nullptr; shutdown(); } bool MainHandler::init(int domainIdIn, int domainIdOut, unsigned short tcpPortOut) { shutdown(); if (!DDS::QosProfile::setDefault()) { ERROR_LOG(m_logger) << "Error setting default QoS from xml-file "; return false; } NGL::LoggerHandler *lh = NGL::LoggerHandler::getLoggerHandler(); if (lh) { const QByteArray postfix = lh->loggerNamePostfix().toLocal8Bit() + "_dds_"; const QByteArray prefix = lh->loggerNamePrefix().toLocal8Bit(); rti::config::Logger &ddsLogger = rti::config::Logger::instance(); //ddsLogger.output_file(fdopen(STDOUT_FILENO, "w")); ddsLogger.output_file_set(postfix.data(), prefix.data(), 10 * 1024 * 1024, 10); ddsLogger.verbosity(rti::config::Verbosity_def::WARNING); //ddsLogger.verbosity_by_category(rti::config::LogCategory_def::COMMUNICATION, rti::config::Verbosity_def::STATUS_ALL); } std::shared_ptr ddsConnectorIn( new DDSConnector::DdsConnector(domainIdIn, IDL::PartitionType::Global)); ddsConnectorIn->initDomainParticipant(); ddsConnectorIn->initPublisherSubscriber(); // for ExerciseManagement::Exercise, Core::SituationReplay, Heartbeat QUrl tcpDiscoveryUrl; tcpDiscoveryUrl.setPort(tcpPortOut); std::shared_ptr ddsConnectorOut( new DDSConnector::DdsConnector(domainIdOut, IDL::PartitionType::Global, 0, tcpDiscoveryUrl)); ddsConnectorOut->initDomainParticipant(); m_sessionHandler.reset(new SessionHandler(IDL::PartitionType::Exercise, ddsConnectorIn, ddsConnectorOut)); m_pacemaker = std::make_shared(ddsConnectorIn); m_pacemaker->setNewState(Core::RunningState::Starting); m_partitionHandler.reset(new PartitionHandler(ddsConnectorIn)); connect(m_partitionHandler.get(), &PartitionHandler::createSession, m_sessionHandler.get(), &SessionHandler::onCreateSession); connect(m_partitionHandler.get(), &PartitionHandler::destroySession, m_sessionHandler.get(), &SessionHandler::onDestroySession); if (!m_partitionHandler->init() || !m_sessionHandler->init()) { m_pacemaker->setNewState(Core::RunningState::StartingError); return false; } const QString ex_0(QString::fromStdString(DDSConnector::DdsConnector::getPartitionString(IDL::PartitionType::Global))); m_sessionHandler->onCreateSession(ex_0, ex_0); m_pacemaker->setNewState(Core::RunningState::Running); return true; } void MainHandler::shutdown() { if (m_sessionHandler) m_sessionHandler->shutdown(); m_sessionHandler = nullptr; m_partitionHandler = nullptr; } } // namespace RoutingService