mirror of
https://codeberg.org/comaps/comaps
synced 2026-01-08 13:27:57 +00:00
[traffic] Update routing MWMs as route changes
Signed-off-by: mvglasow <michael -at- vonglasow.com>
This commit is contained in:
@@ -19,6 +19,8 @@ AbsentRegionsFinder::AbsentRegionsFinder(CountryFileGetterFn const & countryFile
|
||||
void AbsentRegionsFinder::GenerateAbsentRegions(Checkpoints const & checkpoints,
|
||||
RouterDelegate const & delegate)
|
||||
{
|
||||
m_regions.clear();
|
||||
|
||||
if (m_routerThread)
|
||||
{
|
||||
m_routerThread->Cancel();
|
||||
@@ -52,20 +54,21 @@ void AbsentRegionsFinder::GetAbsentRegions(std::set<std::string> & regions)
|
||||
|
||||
void AbsentRegionsFinder::GetAllRegions(std::set<std::string> & countries)
|
||||
{
|
||||
countries.clear();
|
||||
|
||||
if (!m_routerThread)
|
||||
return;
|
||||
|
||||
m_routerThread->Join();
|
||||
|
||||
for (auto const & mwmName : m_routerThread->GetRoutineAs<RegionsRouter>()->GetMwmNames())
|
||||
// Note: if called from `RoutingSession` callback, m_state will still have its pre-update value.
|
||||
if (m_routerThread)
|
||||
{
|
||||
if (!mwmName.empty())
|
||||
countries.emplace(mwmName);
|
||||
m_routerThread->Join();
|
||||
|
||||
for (auto const & mwmName : m_routerThread->GetRoutineAs<RegionsRouter>()->GetMwmNames())
|
||||
{
|
||||
if (!mwmName.empty())
|
||||
m_regions.emplace(mwmName);
|
||||
}
|
||||
|
||||
m_routerThread.reset();
|
||||
}
|
||||
|
||||
m_routerThread.reset();
|
||||
countries = m_regions;
|
||||
}
|
||||
|
||||
bool AbsentRegionsFinder::AreCheckpointsInSameMwm(Checkpoints const & checkpoints) const
|
||||
|
||||
@@ -25,9 +25,27 @@ public:
|
||||
|
||||
// Creates new thread |m_routerThread| and starts routing in it.
|
||||
void GenerateAbsentRegions(Checkpoints const & checkpoints, RouterDelegate const & delegate);
|
||||
// Waits for the routing thread |m_routerThread| to finish and returns results from it.
|
||||
|
||||
/**
|
||||
* @brief Retrieves the MWMs needed to build the route.
|
||||
*
|
||||
* When called for the first time after `GenerateAbsentRegions()`, this method waits for the
|
||||
* routing thread `m_routerThread` to finish and returns results from it. Results are cached and
|
||||
* subsequent calls are served from the cache.
|
||||
*
|
||||
* @param countries Receives the list of MWM names.
|
||||
*/
|
||||
void GetAllRegions(std::set<std::string> & countries);
|
||||
// Waits for the results from GetAllRegions() and returns only regions absent on the device.
|
||||
|
||||
/**
|
||||
* @brief Retrieves the missing MWMs needed to build the route.
|
||||
*
|
||||
* This calls `GetAllRegions()` and strips from the result all regions already present on the
|
||||
* device, leaving only the missing ones. If the call to `GetAllRegions()` is the first one after
|
||||
* calling `GenerateAbsentRegions()`, this involves waiting for the router thread to finish.
|
||||
*
|
||||
* @param absentCountries Receives the list of missing MWM names.
|
||||
*/
|
||||
void GetAbsentRegions(std::set<std::string> & absentCountries);
|
||||
|
||||
private:
|
||||
@@ -40,5 +58,19 @@ private:
|
||||
DataSource & m_dataSource;
|
||||
|
||||
std::unique_ptr<threads::Thread> m_routerThread;
|
||||
|
||||
/**
|
||||
* @brief Mutex for access to `m_regions`.
|
||||
*
|
||||
* Threads which access `m_regions` must lock this mutex while doing so.
|
||||
*/
|
||||
std::mutex m_mutex;
|
||||
|
||||
/**
|
||||
* @brief Regions required for building the last route.
|
||||
*
|
||||
* This member is cleared by `GenerateAbsentRegions()` and populated by `GetAllRegions()`.
|
||||
*/
|
||||
std::set<std::string> m_regions;
|
||||
};
|
||||
} // namespace routing
|
||||
|
||||
@@ -83,6 +83,13 @@ bool AsyncRouter::FindClosestProjectionToRoad(m2::PointD const & point,
|
||||
return m_router->FindClosestProjectionToRoad(point, direction, radius, proj);
|
||||
}
|
||||
|
||||
void AsyncRouter::GetAllRegions(std::set<std::string> & countries)
|
||||
{
|
||||
if (!m_absentRegionsFinder)
|
||||
return;
|
||||
m_absentRegionsFinder->GetAllRegions(countries);
|
||||
}
|
||||
|
||||
void AsyncRouter::RouterDelegateProxy::OnProgress(float progress)
|
||||
{
|
||||
ProgressCallback onProgress = nullptr;
|
||||
|
||||
@@ -62,6 +62,15 @@ public:
|
||||
bool FindClosestProjectionToRoad(m2::PointD const & point, m2::PointD const & direction,
|
||||
double radius, EdgeProj & proj);
|
||||
|
||||
/**
|
||||
* @brief Retrieves the MWMs needed to build the route.
|
||||
*
|
||||
* Waits for the routing thread to finish and returns the list of MWM names from it.
|
||||
*
|
||||
* @param countries Receives the list of MWM names.
|
||||
*/
|
||||
void GetAllRegions(std::set<std::string> & countries);
|
||||
|
||||
private:
|
||||
/// Worker thread function
|
||||
void ThreadFunc();
|
||||
|
||||
@@ -470,6 +470,13 @@ double RoutingSession::GetCompletionPercent() const
|
||||
return percent;
|
||||
}
|
||||
|
||||
void RoutingSession::GetAllRegions(std::set<std::string> & countries)
|
||||
{
|
||||
if (!m_router)
|
||||
return;
|
||||
m_router->GetAllRegions(countries);
|
||||
}
|
||||
|
||||
void RoutingSession::PassCheckpoints()
|
||||
{
|
||||
CHECK_THREAD_CHECKER(m_threadChecker, ());
|
||||
|
||||
@@ -258,6 +258,15 @@ public:
|
||||
|
||||
double GetCompletionPercent() const;
|
||||
|
||||
/**
|
||||
* @brief Retrieves the MWMs needed to build the route.
|
||||
*
|
||||
* Waits for the `RegionsRouter` thread to finish and returns the list of MWM names from it.
|
||||
*
|
||||
* @param countries Receives the list of MWM names.
|
||||
*/
|
||||
void GetAllRegions(std::set<std::string> & countries);
|
||||
|
||||
private:
|
||||
struct DoReadyCallback
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user