[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;
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<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.
// 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.
*
@@ -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
* 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<MwmSet::MwmId> m_lastDrapeMwmsByRect;
std::set<MwmSet::MwmId> m_activeDrapeMwms;
@@ -667,6 +663,11 @@ private:
std::set<MwmSet::MwmId> m_activePositionMwms;
std::set<MwmSet::MwmId> 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<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.
*