From 6e9d1d9acaad8d549450d89283892fcfc4dcfb8f Mon Sep 17 00:00:00 2001 From: Olga Khlopkova Date: Thu, 26 Nov 2020 12:26:59 +0300 Subject: [PATCH] [routing][map] Pass AbsentRegionsFinder from RoutingManager to AsyncRouter instead of OnlineAbsentFetcher. --- map/routing_manager.cpp | 38 +++++++++++++++++++------------------ routing/async_router.cpp | 19 ++++++++++--------- routing/async_router.hpp | 9 +++++---- routing/routing_session.cpp | 4 ++-- routing/routing_session.hpp | 2 +- 5 files changed, 38 insertions(+), 34 deletions(-) diff --git a/map/routing_manager.cpp b/map/routing_manager.cpp index 6d1a92c024..233ad810fc 100644 --- a/map/routing_manager.cpp +++ b/map/routing_manager.cpp @@ -4,49 +4,49 @@ #include "map/power_management/power_manager.hpp" #include "map/routing_mark.hpp" -#include "private.h" - -#include "tracking/reporter.hpp" - +#include "routing/absent_regions_finder.hpp" #include "routing/checkpoint_predictor.hpp" #include "routing/index_router.hpp" -#include "routing/online_absent_fetcher.hpp" #include "routing/route.hpp" #include "routing/routing_callbacks.hpp" #include "routing/routing_helpers.hpp" #include "routing/speed_camera.hpp" -#include "routing_common/num_mwm_id.hpp" - -#include "drape_frontend/drape_engine.hpp" - -#include "indexer/map_style_reader.hpp" -#include "indexer/scales.hpp" +#include "tracking/reporter.hpp" #include "storage/country_info_getter.hpp" #include "storage/routing_helpers.hpp" #include "storage/storage.hpp" -#include "coding/file_reader.hpp" -#include "coding/file_writer.hpp" -#include "coding/string_utf8_multilang.hpp" +#include "drape_frontend/drape_engine.hpp" + +#include "routing_common/num_mwm_id.hpp" + +#include "indexer/map_style_reader.hpp" +#include "indexer/scales.hpp" #include "platform/country_file.hpp" #include "platform/mwm_traits.hpp" #include "platform/platform.hpp" #include "platform/socket.hpp" +#include "coding/file_reader.hpp" +#include "coding/file_writer.hpp" +#include "coding/string_utf8_multilang.hpp" + #include "base/scope_guard.hpp" #include "base/string_utils.hpp" -#include "3party/Alohalytics/src/alohalytics.h" -#include "3party/jansson/myjansson.hpp" +#include "private.h" #include #include #include #include +#include "3party/Alohalytics/src/alohalytics.h" +#include "3party/jansson/myjansson.hpp" + using namespace routing; using namespace std; @@ -549,14 +549,16 @@ void RoutingManager::SetRouterImpl(RouterType type) return m_callbacks.m_countryInfoGetter().GetLimitRectForLeaf(countryId); }; - auto fetcher = make_unique(countryFileGetter, localFileChecker); + auto regionsFinder = + make_unique(countryFileGetter, localFileChecker, numMwmIds, dataSource); + auto router = make_unique(vehicleType, m_loadAltitudes, m_callbacks.m_countryParentNameGetterFn, countryFileGetter, getMwmRectByName, numMwmIds, MakeNumMwmTree(*numMwmIds, m_callbacks.m_countryInfoGetter()), m_routingSession, dataSource); m_routingSession.SetRoutingSettings(GetRoutingSettings(vehicleType)); - m_routingSession.SetRouter(move(router), move(fetcher)); + m_routingSession.SetRouter(move(router), move(regionsFinder)); m_currentRouterType = type; } diff --git a/routing/async_router.cpp b/routing/async_router.cpp index adc47afb13..ccdb68bec4 100644 --- a/routing/async_router.cpp +++ b/routing/async_router.cpp @@ -203,14 +203,15 @@ AsyncRouter::~AsyncRouter() m_thread.join(); } -void AsyncRouter::SetRouter(unique_ptr && router, unique_ptr && fetcher) +void AsyncRouter::SetRouter(unique_ptr && router, + unique_ptr && finder) { unique_lock ul(m_guard); ResetDelegate(); m_router = move(router); - m_absentFetcher = move(fetcher); + m_absentRegionsFinder = move(finder); } void AsyncRouter::CalculateRoute(Checkpoints const & checkpoints, m2::PointD const & direction, @@ -352,7 +353,7 @@ void AsyncRouter::CalculateRoute() shared_ptr delegateProxy; m2::PointD startDirection; bool adjustToPrevRoute = false; - shared_ptr absentFetcher; + shared_ptr absentRegionsFinder; shared_ptr router; uint64_t routeId = 0; RoutingStatisticsCallback routingStatisticsCallback; @@ -375,7 +376,7 @@ void AsyncRouter::CalculateRoute() adjustToPrevRoute = m_adjustToPrevRoute; delegateProxy = m_delegateProxy; router = m_router; - absentFetcher = m_absentFetcher; + absentRegionsFinder = m_absentRegionsFinder; routeId = ++m_routeCounter; routingStatisticsCallback = m_routingStatisticsCallback; routerName = router->GetName(); @@ -394,8 +395,8 @@ void AsyncRouter::CalculateRoute() LOG(LINFO, ("Calculating the route. checkpoints:", checkpoints, "startDirection:", startDirection, "router name:", router->GetName())); - if (absentFetcher) - absentFetcher->GenerateRequest(checkpoints); + if (absentRegionsFinder) + absentRegionsFinder->GenerateAbsentRegions(checkpoints, delegateProxy->GetDelegate()); // Run basic request. code = router->CalculateRoute(checkpoints, startDirection, adjustToPrevRoute, @@ -439,12 +440,12 @@ void AsyncRouter::CalculateRoute() [delegateProxy, route, code]() { delegateProxy->OnReady(route, code); }); } - bool const needFetchAbsent = (code != RouterResultCode::Cancelled); + bool const needAbsentRegions = (code != RouterResultCode::Cancelled); // Check online response if we have. set absent; - if (absentFetcher && needFetchAbsent) - absentFetcher->GetAbsentCountries(absent); + if (absentRegionsFinder && needAbsentRegions) + absentRegionsFinder->GetAbsentRegions(absent); absent.insert(route->GetAbsentCountries().cbegin(), route->GetAbsentCountries().cend()); if (!absent.empty()) diff --git a/routing/async_router.hpp b/routing/async_router.hpp index 9cf59085c2..6093b90859 100644 --- a/routing/async_router.hpp +++ b/routing/async_router.hpp @@ -1,7 +1,7 @@ #pragma once +#include "routing/absent_regions_finder.hpp" #include "routing/checkpoints.hpp" -#include "routing/online_absent_fetcher.hpp" #include "routing/route.hpp" #include "routing/router.hpp" #include "routing/router_delegate.hpp" @@ -34,8 +34,9 @@ public: /// Sets a synchronous router, current route calculation will be cancelled /// @param router pointer to a router implementation - /// @param fetcher pointer to a online fetcher - void SetRouter(std::unique_ptr && router, std::unique_ptr && fetcher); + /// @param finder pointer to a router for generated absent wmwms. + void SetRouter(std::unique_ptr && router, + std::unique_ptr && finder); /// Main method to calculate new route from startPt to finalPt with start direction /// Processed result will be passed to callback. Callback will be called at the GUI thread. @@ -122,7 +123,7 @@ private: m2::PointD m_startDirection = m2::PointD::Zero(); bool m_adjustToPrevRoute = false; std::shared_ptr m_delegateProxy; - std::shared_ptr m_absentFetcher; + std::shared_ptr m_absentRegionsFinder; std::shared_ptr m_router; RoutingStatisticsCallback const m_routingStatisticsCallback; diff --git a/routing/routing_session.cpp b/routing/routing_session.cpp index bc8fc832e5..c6106d4cd7 100644 --- a/routing/routing_session.cpp +++ b/routing/routing_session.cpp @@ -516,12 +516,12 @@ void RoutingSession::AssignRoute(shared_ptr route, RouterResultCode e) } void RoutingSession::SetRouter(unique_ptr && router, - unique_ptr && fetcher) + unique_ptr && finder) { CHECK_THREAD_CHECKER(m_threadChecker, ()); ASSERT(m_router != nullptr, ()); Reset(); - m_router->SetRouter(move(router), move(fetcher)); + m_router->SetRouter(move(router), move(finder)); } void RoutingSession::MatchLocationToRoadGraph(location::GpsInfo & location) diff --git a/routing/routing_session.hpp b/routing/routing_session.hpp index e0010e2462..cc65d80507 100644 --- a/routing/routing_session.hpp +++ b/routing/routing_session.hpp @@ -54,7 +54,7 @@ public: PointCheckCallback const & pointCheckCallback); void SetRouter(std::unique_ptr && router, - std::unique_ptr && fetcher); + std::unique_ptr && finder); /// @param[in] checkpoints in mercator /// @param[in] timeoutSec timeout in seconds, if zero then there is no timeout