[traffxml] Add router-based decoder, still crude, ugly and buggy

To use it, redefine DefaultTraffDecoder in traffxml/traff_decoder.hpp

Signed-off-by: mvglasow <michael -at- vonglasow.com>
This commit is contained in:
mvglasow
2025-05-24 21:08:58 +03:00
parent bd178932c1
commit 9afb28aaa1
7 changed files with 474 additions and 10 deletions

View File

@@ -296,6 +296,7 @@ Framework::Framework(FrameworkParams const & params, bool loadMaps)
[this]() -> power_management::PowerManager const & { return m_powerManager; }),
static_cast<RoutingManager::Delegate &>(*this))
, m_trafficManager(m_featuresFetcher.GetDataSource(),
[this]() -> storage::CountryInfoGetter const & { return GetCountryInfoGetter(); },
[this](string const & id) -> string { return m_storage.GetParentIdFor(id); },
bind(&Framework::GetMwmsByRect, this, _1, false /* rough */),
kMaxTrafficCacheSizeBytes, m_routingManager.RoutingSession())
@@ -388,6 +389,8 @@ Framework::Framework(FrameworkParams const & params, bool loadMaps)
if (loadMaps)
LoadMapsSync();
m_trafficManager.Start();
}
Framework::~Framework()

View File

@@ -56,13 +56,13 @@ TrafficManager::CacheEntry::CacheEntry(time_point<steady_clock> const & requestT
, m_lastAvailability(traffic::TrafficInfo::Availability::Unknown)
{}
TrafficManager::TrafficManager(DataSource & dataSource,
TrafficManager::TrafficManager(DataSource & dataSource, CountryInfoGetterFn countryInfoGetter,
const CountryParentNameGetterFn &countryParentNameGetter,
GetMwmsByRectFn const & getMwmsByRectFn, size_t maxCacheSizeBytes,
traffic::TrafficObserver & observer)
: m_dataSource(dataSource)
, m_countryInfoGetterFn(countryInfoGetter)
, m_countryParentNameGetterFn(countryParentNameGetter)
, m_traffDecoder(dataSource, countryParentNameGetter, m_messageCache)
, m_getMwmsByRectFn(getMwmsByRectFn)
, m_observer(observer)
, m_currentDataVersion(0)
@@ -129,6 +129,13 @@ void TrafficManager::SetEnabled(bool enabled)
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()
{
// TODO no longer needed
@@ -211,7 +218,6 @@ void TrafficManager::UpdateActiveMwms(m2::RectD const & rect,
{
std::lock_guard<std::mutex> lock(m_mutex);
m_isStarted = true;
m_activeMwmsChanged = true;
activeMwms.clear();
for (auto const & mwm : mwms)
@@ -462,7 +468,7 @@ void TrafficManager::DecodeFirstMessage()
}
LOG(LINFO, (" ", message.m_id, ":", message));
m_traffDecoder.DecodeMessage(message);
m_traffDecoder->DecodeMessage(message);
// store message in cache
m_messageCache.insert_or_assign(message.m_id, message);
// store message coloring in AllMwmColoring

View File

@@ -9,6 +9,8 @@
#include "indexer/mwm_set.hpp"
#include "storage/country_info_getter.hpp"
#include "traffxml/traff_decoder.hpp"
#include "traffxml/traff_model.hpp"
@@ -34,6 +36,7 @@
class TrafficManager final
{
public:
using CountryInfoGetterFn = std::function<storage::CountryInfoGetter const &()>;
using CountryParentNameGetterFn = std::function<std::string(std::string const &)>;
/**
@@ -75,6 +78,7 @@ public:
using GetMwmsByRectFn = std::function<std::vector<MwmSet::MwmId>(m2::RectD const &)>;
TrafficManager(DataSource & dataSource,
CountryInfoGetterFn countryInfoGetter,
CountryParentNameGetterFn const & countryParentNameGetter,
GetMwmsByRectFn const & getMwmsByRectFn, size_t maxCacheSizeBytes,
traffic::TrafficObserver & observer);
@@ -109,6 +113,26 @@ public:
*/
bool IsEnabled() const;
/**
* @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 data source, 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 UpdateViewport(ScreenBase const & screen);
void UpdateMyPosition(MyPosition const & myPosition);
@@ -400,6 +424,7 @@ private:
}
DataSource & m_dataSource;
CountryInfoGetterFn m_countryInfoGetterFn;
CountryParentNameGetterFn m_countryParentNameGetterFn;
GetMwmsByRectFn m_getMwmsByRectFn;
traffic::TrafficObserver & m_observer;
@@ -535,7 +560,7 @@ private:
*
* Used to decode TraFF locations into road segments on the map.
*/
traffxml::DefaultTraffDecoder m_traffDecoder;
std::unique_ptr<traffxml::DefaultTraffDecoder> m_traffDecoder;
/**
* @brief Map between MWM IDs and their colorings.