From fcbec85ee8a292c0ef234639db90f53c19ac693d Mon Sep 17 00:00:00 2001 From: Reinder Feenstra Date: Mon, 13 Jan 2025 23:04:10 +0100 Subject: [PATCH] webthrottle: moved common release code to function --- server/src/network/webthrottleconnection.cpp | 26 ++++++++++---------- server/src/network/webthrottleconnection.hpp | 2 ++ 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/server/src/network/webthrottleconnection.cpp b/server/src/network/webthrottleconnection.cpp index f1cc8daa..fac63d27 100644 --- a/server/src/network/webthrottleconnection.cpp +++ b/server/src/network/webthrottleconnection.cpp @@ -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& 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& 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); +} diff --git a/server/src/network/webthrottleconnection.hpp b/server/src/network/webthrottleconnection.hpp index a16ca44f..80129ccf 100644 --- a/server/src/network/webthrottleconnection.hpp +++ b/server/src/network/webthrottleconnection.hpp @@ -49,6 +49,8 @@ protected: const std::shared_ptr& getThrottle(uint32_t throttleId); + void released(uint32_t throttleId); + public: const std::string id;