[traffic] Refactoring

Signed-off-by: mvglasow <michael -at- vonglasow.com>
This commit is contained in:
mvglasow
2025-07-08 21:53:02 +03:00
parent daf344b27f
commit d03b47bee0
2 changed files with 27 additions and 21 deletions

View File

@@ -322,7 +322,12 @@ void TrafficManager::OnChangeRoutingSessionState(routing::SessionState previous,
{ {
m_activeMwmsChanged = true; m_activeMwmsChanged = true;
std::swap(mwms, m_activeRoutingMwms); 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()) if (mwm.IsAlive())
activeMwms.insert(mwm); 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; return true;
} }
// TODO no longer needed
#ifdef traffic_dead_code
void TrafficManager::RequestTrafficSubscription() void TrafficManager::RequestTrafficSubscription()
{ {
if ((m_activeDrapeMwms.empty() && m_activePositionMwms.empty() && m_activeRoutingMwms.empty()) if ((m_activeDrapeMwms.empty() && m_activePositionMwms.empty() && m_activeRoutingMwms.empty())
@@ -862,8 +874,6 @@ void TrafficManager::RequestTrafficSubscription()
#endif #endif
} }
// TODO no longer needed
#ifdef traffic_dead_code
void TrafficManager::OnTrafficRequestFailed(traffic::TrafficInfo && info) void TrafficManager::OnTrafficRequestFailed(traffic::TrafficInfo && info)
{ {
std::lock_guard<std::mutex> lock(m_mutex); std::lock_guard<std::mutex> lock(m_mutex);

View File

@@ -498,6 +498,8 @@ private:
// This is a group of methods that haven't their own synchronization inside. // 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. * @brief Requests a refresh of traffic subscriptions to match all currently active MWMs.
* *
@@ -511,8 +513,6 @@ private:
*/ */
void RequestTrafficSubscription(); void RequestTrafficSubscription();
// TODO no longer needed
#ifdef traffic_dead_code
/** /**
* @brief Removes traffic data for one specific MWM from the cache. * @brief Removes traffic data for one specific MWM from the cache.
* *
@@ -644,22 +644,18 @@ private:
* *
* The other groups are stored 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. * 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 * However, the vector is used as a reference to detect changes. Clear() clears the vector but not
* is not, which is used to invalidate the set without destroying its contents. * the set, invalidating the set without destroying its contents.
* *
* Methods which use only the set: * Methods which use only the set:
* *
* * RequestTrafficSubscription(), exits if empty, otherwise cycles through 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()).
* * 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).
* *
* Methods which use both, but in a different way: * 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
* * UpdateActiveMwms(), uses the vector to detect changes (not for routing MWMs). If so, it updates both vector and set. * updates both vector and set, but adds MWMs to the set only if they are alive.
*
* Clear() clears both the set and the vector. (Clearing the set is currently disabled as it breaks ForEachActiveMwm.)
*/ */
std::vector<MwmSet::MwmId> m_lastDrapeMwmsByRect; std::vector<MwmSet::MwmId> m_lastDrapeMwmsByRect;
std::set<MwmSet::MwmId> m_activeDrapeMwms; std::set<MwmSet::MwmId> m_activeDrapeMwms;
@@ -667,6 +663,11 @@ private:
std::set<MwmSet::MwmId> m_activePositionMwms; std::set<MwmSet::MwmId> m_activePositionMwms;
std::set<MwmSet::MwmId> m_activeRoutingMwms; std::set<MwmSet::MwmId> m_activeRoutingMwms;
/**
* @brief Whether active MWMs have changed since the last request.
*/
bool m_activeMwmsChanged = false;
// TODO no longer needed // TODO no longer needed
#ifdef traffic_dead_code #ifdef traffic_dead_code
// The ETag or entity tag is part of HTTP, the protocol for the World Wide Web. // 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<std::chrono::steady_clock> m_lastStorageUpdate; std::chrono::time_point<std::chrono::steady_clock> m_lastStorageUpdate;
/**
* @brief Whether active MWMs have changed since the last request.
*/
bool m_activeMwmsChanged = false;
/** /**
* @brief Whether a poll operation is needed. * @brief Whether a poll operation is needed.
* *