XNSim/XNMonitorServer/SystemControl.cpp

58 lines
1.4 KiB
C++
Raw Normal View History

#include "SystemControl.h"
#include "../XNCore/XNIDL/XNSimStatusPubSubTypes.hpp"
SystemControl::~SystemControl()
{
//注销引擎控制发布者
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);
}