webthrottle: moved common release code to function
Dieser Commit ist enthalten in:
Ursprung
bdcb5574f8
Commit
fcbec85ee8
@ -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);
|
||||
}
|
||||
|
||||
@ -49,6 +49,8 @@ protected:
|
||||
|
||||
const std::shared_ptr<WebThrottle>& getThrottle(uint32_t throttleId);
|
||||
|
||||
void released(uint32_t throttleId);
|
||||
|
||||
public:
|
||||
const std::string id;
|
||||
|
||||
|
||||
Laden…
x
In neuem Issue referenzieren
Einen Benutzer sperren