webthrottle: moved common release code to function

Dieser Commit ist enthalten in:
Reinder Feenstra 2025-01-13 23:04:10 +01:00
Ursprung bdcb5574f8
Commit fcbec85ee8
2 geänderte Dateien mit 15 neuen und 13 gelöschten Zeilen

Datei anzeigen

@ -237,14 +237,7 @@ void WebThrottleConnection::processMessage(const nlohmann::json& message)
else if(action == "release")
{
throttle->release(message.value("stop", true));
m_trainPropertyChanged.erase(throttleId);
auto response = nlohmann::json::object();
response.emplace("event", "train");
response.emplace("throttle_id", throttleId);
response.emplace("train", nullptr);
sendMessage(response);
released(throttleId);
}
}
}
@ -285,11 +278,7 @@ const std::shared_ptr<WebThrottle>& WebThrottleConnection::getThrottle(uint32_t
m_throttleReleased.emplace(throttleId, it->second->released.connect(
[this, throttleId]()
{
auto response = nlohmann::json::object();
response.emplace("event", "train");
response.emplace("throttle_id", throttleId);
response.emplace("train", nullptr);
sendMessage(response);
released(throttleId);
}));
return it->second;
}
@ -297,3 +286,14 @@ const std::shared_ptr<WebThrottle>& WebThrottleConnection::getThrottle(uint32_t
return noThrottle;
}
void WebThrottleConnection::released(uint32_t throttleId)
{
m_trainPropertyChanged.erase(throttleId);
auto response = nlohmann::json::object();
response.emplace("event", "train");
response.emplace("throttle_id", throttleId);
response.emplace("train", nullptr);
sendMessage(response);
}

Datei anzeigen

@ -49,6 +49,8 @@ protected:
const std::shared_ptr<WebThrottle>& getThrottle(uint32_t throttleId);
void released(uint32_t throttleId);
public:
const std::string id;