XNSim/XNMonitorServer/SystemControl.cpp

64 lines
1.4 KiB
C++

#include "SystemControl.h"
#include "XNIDL/XNSimStatusPubSubTypes.hpp"
SystemControl::~SystemControl()
{
if (m_EngineControlWriter != nullptr) {
cleanup();
}
}
void SystemControl::cleanup()
{
TopicManager::Instance()->unregisterPublisher("XNSim::XNSimControl::XNRuntimeControl");
m_EngineControlWriter = nullptr;
}
std::string SystemControl::Initialize()
{
m_EngineControlWriter = nullptr;
XNDDSErrorCode ret = TopicManager::Instance()
->registerPublisher<XNSim::XNSimControl::XNRuntimeControlPubSubType>(
"XNSim::XNSimControl::XNRuntimeControl", m_EngineControlWriter);
if (ret != XNDDSErrorCode::SUCCESS || m_EngineControlWriter == nullptr) {
return "Failed to register engine control publisher, error code: "
+ std::to_string(static_cast<int>(ret));
}
return "Success";
}
void SystemControl::Pause()
{
// 暂停引擎
if (m_EngineControlWriter == nullptr) {
return;
}
XNSim::XNSimControl::XNRuntimeControl cmd;
cmd.XNSimCmd(1);
cmd.XNThrCmd(0);
m_EngineControlWriter->write(&cmd);
}
void SystemControl::Resume()
{
// 恢复引擎
if (m_EngineControlWriter == nullptr) {
return;
}
XNSim::XNSimControl::XNRuntimeControl cmd;
cmd.XNSimCmd(2);
cmd.XNThrCmd(0);
m_EngineControlWriter->write(&cmd);
}
void SystemControl::Stop()
{
// 停止引擎
if (m_EngineControlWriter == nullptr) {
return;
}
XNSim::XNSimControl::XNRuntimeControl cmd;
cmd.XNSimCmd(3);
cmd.XNThrCmd(0);
m_EngineControlWriter->write(&cmd);
}