From d03b47bee00c45b977e5f0dff6a63528a438234e Mon Sep 17 00:00:00 2001 From: mvglasow Date: Tue, 8 Jul 2025 21:53:02 +0300 Subject: [PATCH] [traffic] Refactoring Signed-off-by: mvglasow --- map/traffic_manager.cpp | 18 ++++++++++++++---- map/traffic_manager.hpp | 30 +++++++++++++----------------- 2 files changed, 27 insertions(+), 21 deletions(-) diff --git a/map/traffic_manager.cpp b/map/traffic_manager.cpp index f89525740..c7068c921 100644 --- a/map/traffic_manager.cpp +++ b/map/traffic_manager.cpp @@ -322,7 +322,12 @@ void TrafficManager::OnChangeRoutingSessionState(routing::SessionState previous, { m_activeMwmsChanged = true; std::swap(mwms, m_activeRoutingMwms); - RequestTrafficSubscription(); + + if ((m_activeDrapeMwms.empty() && m_activePositionMwms.empty() && m_activeRoutingMwms.empty()) + || !IsEnabled() || IsInvalidState() || m_isPaused) + return; + + m_condition.notify_one(); } } } @@ -409,7 +414,12 @@ void TrafficManager::UpdateActiveMwms(m2::RectD const & rect, if (mwm.IsAlive()) activeMwms.insert(mwm); } - RequestTrafficSubscription(); + + if ((m_activeDrapeMwms.empty() && m_activePositionMwms.empty() && m_activeRoutingMwms.empty()) + || !IsEnabled() || IsInvalidState() || m_isPaused) + return; + + m_condition.notify_one(); } } @@ -839,6 +849,8 @@ bool TrafficManager::WaitForRequest() return true; } +// TODO no longer needed +#ifdef traffic_dead_code void TrafficManager::RequestTrafficSubscription() { if ((m_activeDrapeMwms.empty() && m_activePositionMwms.empty() && m_activeRoutingMwms.empty()) @@ -862,8 +874,6 @@ void TrafficManager::RequestTrafficSubscription() #endif } -// TODO no longer needed -#ifdef traffic_dead_code void TrafficManager::OnTrafficRequestFailed(traffic::TrafficInfo && info) { std::lock_guard lock(m_mutex); diff --git a/map/traffic_manager.hpp b/map/traffic_manager.hpp index 267259e34..3c4591b56 100644 --- a/map/traffic_manager.hpp +++ b/map/traffic_manager.hpp @@ -498,6 +498,8 @@ private: // This is a group of methods that haven't their own synchronization inside. +// TODO no longer needed +#ifdef traffic_dead_code /** * @brief Requests a refresh of traffic subscriptions to match all currently active MWMs. * @@ -511,8 +513,6 @@ private: */ void RequestTrafficSubscription(); -// TODO no longer needed -#ifdef traffic_dead_code /** * @brief Removes traffic data for one specific MWM from the cache. * @@ -642,24 +642,20 @@ private: * * Routing MWMs are stored as a set. * - * The other groups arestored twice: as a set and as a vector. The set always holds the MWMs which + * The other groups are stored twice: as a set and as a vector. The set always holds the MWMs which * were last seen in use. Both get updated together when active MWMs are added or removed. - * However, the vector is used as a reference to detect changes. It may get cleared when the set - * is not, which is used to invalidate the set without destroying its contents. + * However, the vector is used as a reference to detect changes. Clear() clears the vector but not + * the set, invalidating the set without destroying its contents. * * Methods which use only the set: * * * RequestTrafficSubscription(), exits if empty, otherwise cycles through the set. - * * OnTrafficRequestFailed(), determines if an MWM is still active and the request should be retried. - * * UniteActiveMwms(), build the list of active MWMs (used by RequestTrafficSubscription() or to shrink the cache). - * * UpdateState(), cycles through the set to determine the state of traffic requests (renderer only). + * * UniteActiveMwms(), build the list of active MWMs (used by RequestTrafficSubscription()). * * Methods which use both, but in a different way: * - * * (dead code) ClearCache(), removes the requested MWM from the set but clears the vector completely. - * * UpdateActiveMwms(), uses the vector to detect changes (not for routing MWMs). If so, it updates both vector and set. - * - * Clear() clears both the set and the vector. (Clearing the set is currently disabled as it breaks ForEachActiveMwm.) + * * UpdateActiveMwms(), uses the vector to detect changes (not for routing MWMs). If so, it + * updates both vector and set, but adds MWMs to the set only if they are alive. */ std::vector m_lastDrapeMwmsByRect; std::set m_activeDrapeMwms; @@ -667,6 +663,11 @@ private: std::set m_activePositionMwms; std::set m_activeRoutingMwms; + /** + * @brief Whether active MWMs have changed since the last request. + */ + bool m_activeMwmsChanged = false; + // TODO no longer needed #ifdef traffic_dead_code // The ETag or entity tag is part of HTTP, the protocol for the World Wide Web. @@ -726,11 +727,6 @@ private: */ std::chrono::time_point m_lastStorageUpdate; - /** - * @brief Whether active MWMs have changed since the last request. - */ - bool m_activeMwmsChanged = false; - /** * @brief Whether a poll operation is needed. *