mirror of
https://codeberg.org/comaps/comaps
synced 2025-12-19 13:03:36 +00:00
[traffic] Use enabled state instead of Start()
Signed-off-by: mvglasow <michael -at- vonglasow.com>
This commit is contained in:
@@ -376,7 +376,6 @@ Framework::Framework(FrameworkParams const & params, bool loadMaps)
|
|||||||
|
|
||||||
m_trafficManager.SetCurrentDataVersion(m_storage.GetCurrentDataVersion());
|
m_trafficManager.SetCurrentDataVersion(m_storage.GetCurrentDataVersion());
|
||||||
m_trafficManager.SetSimplifiedColorScheme(LoadTrafficSimplifiedColors());
|
m_trafficManager.SetSimplifiedColorScheme(LoadTrafficSimplifiedColors());
|
||||||
m_trafficManager.SetEnabled(LoadTrafficEnabled());
|
|
||||||
|
|
||||||
m_isolinesManager.SetEnabled(LoadIsolinesEnabled());
|
m_isolinesManager.SetEnabled(LoadIsolinesEnabled());
|
||||||
|
|
||||||
@@ -390,7 +389,7 @@ Framework::Framework(FrameworkParams const & params, bool loadMaps)
|
|||||||
if (loadMaps)
|
if (loadMaps)
|
||||||
LoadMapsSync();
|
LoadMapsSync();
|
||||||
|
|
||||||
m_trafficManager.Start();
|
m_trafficManager.SetEnabled(LoadTrafficEnabled());
|
||||||
}
|
}
|
||||||
|
|
||||||
Framework::~Framework()
|
Framework::~Framework()
|
||||||
|
|||||||
@@ -72,7 +72,6 @@ TrafficManager::TrafficManager(DataSource & dataSource, CountryInfoGetterFn coun
|
|||||||
, m_maxCacheSizeBytes(maxCacheSizeBytes)
|
, m_maxCacheSizeBytes(maxCacheSizeBytes)
|
||||||
#endif
|
#endif
|
||||||
, m_isRunning(true)
|
, m_isRunning(true)
|
||||||
, m_isStarted(false)
|
|
||||||
, m_isPaused(false)
|
, m_isPaused(false)
|
||||||
, m_thread(&TrafficManager::ThreadRoutine, this)
|
, m_thread(&TrafficManager::ThreadRoutine, this)
|
||||||
{
|
{
|
||||||
@@ -117,7 +116,10 @@ void TrafficManager::SetEnabled(bool enabled)
|
|||||||
std::lock_guard<std::mutex> lock(m_mutex);
|
std::lock_guard<std::mutex> lock(m_mutex);
|
||||||
if (enabled == IsEnabled())
|
if (enabled == IsEnabled())
|
||||||
return;
|
return;
|
||||||
Clear();
|
if (enabled && !m_traffDecoder)
|
||||||
|
// deferred decoder initialization (requires maps to be loaded)
|
||||||
|
m_traffDecoder = make_unique<traffxml::DefaultTraffDecoder>(m_dataSource, m_countryInfoGetterFn,
|
||||||
|
m_countryParentNameGetterFn, m_messageCache);
|
||||||
ChangeState(enabled ? TrafficState::Enabled : TrafficState::Disabled);
|
ChangeState(enabled ? TrafficState::Enabled : TrafficState::Disabled);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -129,13 +131,6 @@ void TrafficManager::SetEnabled(bool enabled)
|
|||||||
m_observer.OnTrafficInfoClear();
|
m_observer.OnTrafficInfoClear();
|
||||||
}
|
}
|
||||||
|
|
||||||
void TrafficManager::Start()
|
|
||||||
{
|
|
||||||
m_traffDecoder = make_unique<traffxml::DefaultTraffDecoder>(m_dataSource, m_countryInfoGetterFn,
|
|
||||||
m_countryParentNameGetterFn, m_messageCache);
|
|
||||||
m_isStarted = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void TrafficManager::Clear()
|
void TrafficManager::Clear()
|
||||||
{
|
{
|
||||||
// TODO no longer needed
|
// TODO no longer needed
|
||||||
@@ -561,7 +556,7 @@ bool TrafficManager::WaitForRequest()
|
|||||||
if (!m_isRunning)
|
if (!m_isRunning)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (m_isStarted)
|
if (IsEnabled())
|
||||||
{
|
{
|
||||||
// if we have feeds in the queue, return immediately
|
// if we have feeds in the queue, return immediately
|
||||||
if (!m_feedQueue.empty())
|
if (!m_feedQueue.empty())
|
||||||
@@ -592,7 +587,7 @@ bool TrafficManager::WaitForRequest()
|
|||||||
return false;
|
return false;
|
||||||
|
|
||||||
// this works as long as wait timeout is at least equal to the poll interval
|
// this works as long as wait timeout is at least equal to the poll interval
|
||||||
if (m_isStarted)
|
if (IsEnabled())
|
||||||
m_isPollNeeded |= timeout;
|
m_isPollNeeded |= timeout;
|
||||||
|
|
||||||
LOG(LINFO, ("timeout:", timeout, "active MWMs changed:", m_activeMwmsChanged));
|
LOG(LINFO, ("timeout:", timeout, "active MWMs changed:", m_activeMwmsChanged));
|
||||||
|
|||||||
@@ -98,11 +98,26 @@ public:
|
|||||||
/**
|
/**
|
||||||
* @brief Enables or disables the traffic manager.
|
* @brief Enables or disables the traffic manager.
|
||||||
*
|
*
|
||||||
* This sets the internal state and notifies the drape engine. Enabling the traffic manager will
|
* This sets the internal state and notifies the drape engine.
|
||||||
* invalidate its data, disabling it will notify the observer that traffic data has been cleared.
|
*
|
||||||
|
* 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.
|
* 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
|
* @param enabled True to enable, false to disable
|
||||||
*/
|
*/
|
||||||
void SetEnabled(bool enabled);
|
void SetEnabled(bool enabled);
|
||||||
@@ -117,20 +132,6 @@ public:
|
|||||||
/**
|
/**
|
||||||
* @brief Starts the traffic manager.
|
* @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();
|
void Start();
|
||||||
|
|
||||||
@@ -145,7 +146,8 @@ public:
|
|||||||
* This happens when a new MWM file is downloaded, the traffic manager is enabled after being
|
* This happens when a new MWM file is downloaded, the traffic manager is enabled after being
|
||||||
* disabled or resumed after being paused.
|
* 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();
|
void Invalidate();
|
||||||
|
|
||||||
@@ -530,11 +532,6 @@ private:
|
|||||||
// which allows a client to make conditional requests.
|
// which allows a client to make conditional requests.
|
||||||
std::map<MwmSet::MwmId, std::string> m_trafficETags;
|
std::map<MwmSet::MwmId, std::string> m_trafficETags;
|
||||||
|
|
||||||
/**
|
|
||||||
* Whether the traffic manager should begin receiving information.
|
|
||||||
*/
|
|
||||||
std::atomic<bool> m_isStarted;
|
|
||||||
|
|
||||||
std::atomic<bool> m_isPaused;
|
std::atomic<bool> m_isPaused;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user