diff --git a/map/framework.cpp b/map/framework.cpp index 05f92c748..46b7c68f4 100644 --- a/map/framework.cpp +++ b/map/framework.cpp @@ -376,7 +376,6 @@ Framework::Framework(FrameworkParams const & params, bool loadMaps) m_trafficManager.SetCurrentDataVersion(m_storage.GetCurrentDataVersion()); m_trafficManager.SetSimplifiedColorScheme(LoadTrafficSimplifiedColors()); - m_trafficManager.SetEnabled(LoadTrafficEnabled()); m_isolinesManager.SetEnabled(LoadIsolinesEnabled()); @@ -390,7 +389,7 @@ Framework::Framework(FrameworkParams const & params, bool loadMaps) if (loadMaps) LoadMapsSync(); - m_trafficManager.Start(); + m_trafficManager.SetEnabled(LoadTrafficEnabled()); } Framework::~Framework() diff --git a/map/traffic_manager.cpp b/map/traffic_manager.cpp index f6e41767e..3fe4e02e2 100644 --- a/map/traffic_manager.cpp +++ b/map/traffic_manager.cpp @@ -72,7 +72,6 @@ TrafficManager::TrafficManager(DataSource & dataSource, CountryInfoGetterFn coun , m_maxCacheSizeBytes(maxCacheSizeBytes) #endif , m_isRunning(true) - , m_isStarted(false) , m_isPaused(false) , m_thread(&TrafficManager::ThreadRoutine, this) { @@ -117,7 +116,10 @@ void TrafficManager::SetEnabled(bool enabled) std::lock_guard lock(m_mutex); if (enabled == IsEnabled()) return; - Clear(); + if (enabled && !m_traffDecoder) + // deferred decoder initialization (requires maps to be loaded) + m_traffDecoder = make_unique(m_dataSource, m_countryInfoGetterFn, + m_countryParentNameGetterFn, m_messageCache); ChangeState(enabled ? TrafficState::Enabled : TrafficState::Disabled); } @@ -129,13 +131,6 @@ void TrafficManager::SetEnabled(bool enabled) m_observer.OnTrafficInfoClear(); } -void TrafficManager::Start() -{ - m_traffDecoder = make_unique(m_dataSource, m_countryInfoGetterFn, - m_countryParentNameGetterFn, m_messageCache); - m_isStarted = true; -} - void TrafficManager::Clear() { // TODO no longer needed @@ -561,7 +556,7 @@ bool TrafficManager::WaitForRequest() if (!m_isRunning) return false; - if (m_isStarted) + if (IsEnabled()) { // if we have feeds in the queue, return immediately if (!m_feedQueue.empty()) @@ -592,7 +587,7 @@ bool TrafficManager::WaitForRequest() return false; // this works as long as wait timeout is at least equal to the poll interval - if (m_isStarted) + if (IsEnabled()) m_isPollNeeded |= timeout; LOG(LINFO, ("timeout:", timeout, "active MWMs changed:", m_activeMwmsChanged)); diff --git a/map/traffic_manager.hpp b/map/traffic_manager.hpp index c8f8967bf..1a87ef717 100644 --- a/map/traffic_manager.hpp +++ b/map/traffic_manager.hpp @@ -98,11 +98,26 @@ public: /** * @brief Enables or disables the traffic manager. * - * This sets the internal state and notifies the drape engine. Enabling the traffic manager will - * invalidate its data, disabling it will notify the observer that traffic data has been cleared. + * This sets the internal state and notifies the drape engine. + * + * Upon creation, the traffic manager is disabled and will not poll any sources or process any + * feeds until enabled. Feeds received through `Push()` will be added to the queue before the + * traffic manager is started, but will not be processed any further until the traffic manager is + * started. + * + * MWMs must be loaded before first enabling the traffic manager. * * Calling this function with `enabled` identical to the current state is a no-op. * + * @todo Currently, all MWMs must be loaded before calling `SetEnabled()`, as MWMs loaded after + * that will not get picked up. We need to extend `TrafficManager` to react to MWMs being added + * (and removed) – note that this affects the `DataSource`, not the set of active MWMs. + * + * @todo Enabling the traffic manager will invalidate its data, disabling it will notify the + * observer that traffic data has been cleared. This is old logic, to be reviewed/removed. + * + * @todo State/pause/resume logic is not fully implemented ATM and needs to be revisited. + * * @param enabled True to enable, false to disable */ void SetEnabled(bool enabled); @@ -117,20 +132,6 @@ public: /** * @brief Starts the traffic manager. * - * After creation, the traffic manager will not poll any sources or process any feeds until it is - * started. Feeds received through `Push()` will be added to the queue before the traffic manager - * is started, but will not be processed any further until the traffic manager is started. - * - * MWMs must be loaded before starting the traffic manager. - * - * @todo Currently, all MWMs must be loaded before calling `Start()`, as MWMs loaded after that - * will not get picked up. We need to extend `TrafficManager` to react to MWMs being added (and - * removed) – note that this affects the `DataSource`, not the set of active MWMs. - * - * @todo Start is currently not integrated with state or pause/resume logic (all of which might - * not be fully implemented ATM). If the traffic manager is not started, no message processing - * (other than filling the queue and deduplication) will take place, regardless of state. Starting - * the traffic manager will not change the state it reports. */ void Start(); @@ -145,7 +146,8 @@ public: * This happens when a new MWM file is downloaded, the traffic manager is enabled after being * disabled or resumed after being paused. * - * @todo this goes for the old MWM arch, see if this makes sense for TraFF. + * @todo this goes for the old MWM arch. For TraFF we need to refresh the MWM set for the decoder + * and possibly decode locations again (MWMs might have changed, or new ones added). */ void Invalidate(); @@ -530,11 +532,6 @@ private: // which allows a client to make conditional requests. std::map m_trafficETags; - /** - * Whether the traffic manager should begin receiving information. - */ - std::atomic m_isStarted; - std::atomic m_isPaused; /**