diff --git a/routing/async_router.cpp b/routing/async_router.cpp index 5664e19156..217138bea2 100644 --- a/routing/async_router.cpp +++ b/routing/async_router.cpp @@ -69,7 +69,7 @@ AsyncRouter::~AsyncRouter() { ClearState(); } void AsyncRouter::CalculateRoute(m2::PointD const & startPoint, m2::PointD const & direction, m2::PointD const & finalPoint, TReadyCallback const & readyCallback, - TProgressCallback const & progressCallback) + TProgressCallback const & progressCallback, uint32_t timeoutSec) { { lock_guard paramsGuard(m_paramsMutex); @@ -79,6 +79,7 @@ void AsyncRouter::CalculateRoute(m2::PointD const & startPoint, m2::PointD const m_finalPoint = finalPoint; m_observer.Cancel(); + m_observer.SetTimeout(timeoutSec); } GetPlatform().RunAsync(bind(&AsyncRouter::CalculateRouteImpl, this, readyCallback, progressCallback)); diff --git a/routing/async_router.hpp b/routing/async_router.hpp index 949bf906cd..2ed3108654 100644 --- a/routing/async_router.hpp +++ b/routing/async_router.hpp @@ -40,9 +40,10 @@ public: /// @param finalPoint target point for route /// @param readyCallback function to return routing result /// @param progressCallback function to update the router progress + /// @param timeoutSec timeout to cancel routing. 0 is infinity. virtual void CalculateRoute(m2::PointD const & startPoint, m2::PointD const & direction, m2::PointD const & finalPoint, TReadyCallback const & readyCallback, - TProgressCallback const & progressCallback); + TProgressCallback const & progressCallback, uint32_t timeoutSec); /// Interrupt routing and clear buffers virtual void ClearState(); diff --git a/routing/routing_session.cpp b/routing/routing_session.cpp index 15b4c11480..624c5c619e 100644 --- a/routing/routing_session.cpp +++ b/routing/routing_session.cpp @@ -55,16 +55,11 @@ void RoutingSession::RebuildRoute(m2::PointD const & startPoint, RemoveRoute(); m_state = RouteBuilding; - ResetRoutingWatchdogTimer(); - // Use old-style callback construction, because lambda constructs buggy function on Android // (callback param isn't captured by value). m_router->CalculateRoute(startPoint, startPoint - m_lastGoodPosition, m_endPoint, DoReadyCallback(*this, readyCallback, m_routeSessionMutex), - DoProgressCallback(progressCallback)); - - if (timeoutSec != 0) - InitRoutingWatchdogTimer(timeoutSec); + DoProgressCallback(progressCallback), timeoutSec); } void RoutingSession::DoReadyCallback::operator()(Route & route, IRouter::ResultCode e) @@ -102,8 +97,6 @@ void RoutingSession::Reset() RemoveRouteImpl(); m_router->ClearState(); m_turnsSound.Reset(); - - ResetRoutingWatchdogTimer(); } RoutingSession::State RoutingSession::OnLocationPositionChanged(m2::PointD const & position, @@ -303,22 +296,4 @@ routing::turns::sound::LengthUnits RoutingSession::GetTurnSoundNotificationsUnit return m_turnsSound.GetLengthUnits(); } -void RoutingSession::ResetRoutingWatchdogTimer() -{ - if (m_routingWatchdog) - { - m_routingWatchdog->Cancel(); - m_routingWatchdog->WaitForCompletion(); - m_routingWatchdog.reset(); - } -} - -void RoutingSession::InitRoutingWatchdogTimer(uint32_t timeoutSec) -{ - ASSERT_NOT_EQUAL(0, timeoutSec, ()); - ASSERT(nullptr == m_routingWatchdog, ()); - - m_routingWatchdog = make_unique([this](){ m_router->ClearState(); }, seconds(timeoutSec)); -} - } // namespace routing diff --git a/routing/routing_session.hpp b/routing/routing_session.hpp index 9c8973541d..a513854b94 100644 --- a/routing/routing_session.hpp +++ b/routing/routing_session.hpp @@ -126,9 +126,6 @@ private: void RemoveRoute(); void RemoveRouteImpl(); - void ResetRoutingWatchdogTimer(); - void InitRoutingWatchdogTimer(uint32_t timeoutSec); - private: unique_ptr m_router; Route m_route; @@ -146,8 +143,5 @@ private: turns::sound::TurnsSound m_turnsSound; RoutingSettings m_routingSettings; - - // Watchdog cancels routing if it takes too long time - unique_ptr m_routingWatchdog; }; } // namespace routing