[traffic] Keep polling and processing messages while routing

Signed-off-by: mvglasow <michael -at- vonglasow.com>
This commit is contained in:
mvglasow
2025-11-08 17:49:46 +02:00
parent 1d87e0e987
commit a9700156db
2 changed files with 27 additions and 13 deletions

View File

@@ -259,7 +259,7 @@ void TrafficManager::OnChangeRoutingSessionState(routing::SessionState previous,
std::swap(mwms, m_activeRoutingMwms);
if ((m_activeDrapeMwms.empty() && m_activePositionMwms.empty() && m_activeRoutingMwms.empty())
|| !IsEnabled() || IsInvalidState() || m_isPaused)
|| !IsEnabled() || IsInvalidState() || IsPausedAndNotRouting())
return;
m_condition.notify_one();
@@ -269,7 +269,7 @@ void TrafficManager::OnChangeRoutingSessionState(routing::SessionState previous,
void TrafficManager::RecalculateSubscription(bool forceRenewal)
{
if (!IsEnabled() || m_isPaused)
if (!IsEnabled() || IsPausedAndNotRouting())
return;
if (m_currentModelView.second)
@@ -367,7 +367,7 @@ void TrafficManager::UpdateActiveMwms(m2::RectD const & rect, std::vector<MwmSet
activeMwms.insert(mwm);
if ((m_activeDrapeMwms.empty() && m_activePositionMwms.empty() && m_activeRoutingMwms.empty())
|| !IsEnabled() || IsInvalidState() || m_isPaused)
|| !IsEnabled() || IsInvalidState() || IsPausedAndNotRouting())
return;
m_condition.notify_one();
@@ -381,7 +381,7 @@ void TrafficManager::UpdateMyPosition(MyPosition const & myPosition)
double const kSquareSideM = 5000.0;
m_currentPosition = {myPosition, true /* initialized */};
if (!IsEnabled() || IsInvalidState() || m_isPaused)
if (!IsEnabled() || IsInvalidState() || IsPausedAndNotRouting())
return;
m2::RectD const rect = mercator::RectByCenterXYAndSizeInMeters(myPosition.m_position, kSquareSideM / 2.0);
@@ -393,7 +393,7 @@ void TrafficManager::UpdateViewport(ScreenBase const & screen)
{
m_currentModelView = {screen, true /* initialized */};
if (!IsEnabled() || IsInvalidState() || m_isPaused)
if (!IsEnabled() || IsInvalidState() || IsPausedAndNotRouting())
return;
if (df::GetZoomLevel(screen.GetScale()) < df::kRoadClass0ZoomLevel)
@@ -669,7 +669,7 @@ void TrafficManager::ThreadRoutine()
while (WaitForRequest())
{
if (!IsEnabled() || m_isPaused)
if (!IsEnabled() || IsPausedAndNotRouting())
continue;
/*
@@ -733,7 +733,7 @@ bool TrafficManager::WaitForRequest()
if (!m_isRunning)
return false;
if (IsEnabled() && !m_isPaused)
if (IsEnabled() && !IsPausedAndNotRouting())
{
// if we have feeds in the queue, return immediately
if (!m_feedQueue.empty())

View File

@@ -492,13 +492,14 @@ private:
*
* Upon creation, the traffic manager is not paused.
*
* While paused, the traffic manager will not update its subscription area (upon being enabled
* again, it will do so if necessary). It will not poll any sources or process any messages. Feeds
* added via `ReceiveFeed()` will be added to the queue but will not be processed until the
* traffic manager is resumed.
* While the traffic manager is paused and no route is active, the traffic manager will not update
* its subscription area (upon resuming, it will do so if necessary). It will not poll any sources
* or process any messages. Feeds added via `ReceiveFeed()` will be added to the queue but will
* not be processed until the traffic manager is resumed.
*
* Pausing and resuming is similar in effect to disabling and enabling the traffic manager, except
* it does not change the external state. It is intended for internal use by the framework.
* it does not change the external state, and an active route effectively overrides the paused
* state. It is intended for internal use by the framework.
*/
void Pause();
@@ -513,7 +514,8 @@ private:
* received before or while the traffic manager was paused.
*
* Pausing and resuming is similar in effect to disabling and enabling the traffic manager, except
* it does not change the external state. It is intended for internal use by the framework.
* it does not change the external state, and an active route effectively overrides the paused
* state. It is intended for internal use by the framework.
*/
void Resume();
@@ -547,6 +549,18 @@ private:
bool IsObserverInhibited() const { return (m_routingSessionState == routing::SessionState::RouteBuilding)
|| (m_routingSessionState == routing::SessionState::RouteRebuilding); }
/**
* @brief Whether we are currently routing.
*/
bool IsRouting() const { return m_routingSessionState != routing::SessionState::NoValidRoute; }
/**
* @brief Whether the traffic manager is paused and not routing.
*
* This is used to inhibit polling and message decoding.
*/
bool IsPausedAndNotRouting() const { return m_isPaused && !IsRouting(); }
DataSource & m_dataSource;
CountryInfoGetterFn m_countryInfoGetterFn;
CountryParentNameGetterFn m_countryParentNameGetterFn;