From e4a593f9ce03ecf13e8a33feb588a8c1dabca03c Mon Sep 17 00:00:00 2001 From: Vladimir Byko-Ianko Date: Wed, 24 Apr 2019 17:13:27 +0300 Subject: [PATCH] Adding a callback on routing::SessionState changing. --- routing/routing_callbacks.hpp | 2 +- routing/routing_session.cpp | 15 +++++++++++++++ routing/routing_session.hpp | 4 +++- 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/routing/routing_callbacks.hpp b/routing/routing_callbacks.hpp index 0acca47441..64587f8708 100644 --- a/routing/routing_callbacks.hpp +++ b/routing/routing_callbacks.hpp @@ -76,7 +76,7 @@ using ReadyCallback = std::function; using ReadyCallbackOwnership = std::function, RouterResultCode)>; using RemoveRouteCallback = std::function; using RouteCallback = std::function; -using RouteChangeStateCallback = std::function; +using ChangeSessionStateCallback = std::function; using RoutingStatisticsCallback = std::function const &)>; using SpeedCameraShowCallback = std::function; using SpeedCameraClearCallback = std::function; diff --git a/routing/routing_session.cpp b/routing/routing_session.cpp index 552f17190d..b7206289f4 100644 --- a/routing/routing_session.cpp +++ b/routing/routing_session.cpp @@ -60,6 +60,8 @@ RoutingSession::RoutingSession() , m_passedDistanceOnRouteMeters(0.0) , m_lastCompletionPercent(0.0) { + // To call |m_changeSessionStateCallback| on |m_state| initialization. + SetState(SessionState::RoutingNotActive); m_speedCameraManager.SetRoute(m_route); } @@ -258,6 +260,12 @@ void RoutingSession::Reset() m_lastCompletionPercent = 0; } +void RoutingSession::SetState(SessionState state) +{ + m_changeSessionStateCallback(m_state, state); + m_state = state; +} + SessionState RoutingSession::OnLocationPositionChanged(GpsInfo const & info) { CHECK_THREAD_CHECKER(m_threadChecker, ()); @@ -588,6 +596,13 @@ void RoutingSession::SetCheckpointCallback(CheckpointCallback const & checkpoint m_checkpointCallback = checkpointCallback; } +void RoutingSession::SetChangeSessionStateCallback( + ChangeSessionStateCallback const & changeSessionStateCallback) +{ + CHECK_THREAD_CHECKER(m_threadChecker, ()); + m_changeSessionStateCallback = changeSessionStateCallback; +} + void RoutingSession::SetUserCurrentPosition(m2::PointD const & position) { CHECK_THREAD_CHECKER(m_threadChecker, ()); diff --git a/routing/routing_session.hpp b/routing/routing_session.hpp index 35d154ad39..2d9f9840d0 100644 --- a/routing/routing_session.hpp +++ b/routing/routing_session.hpp @@ -80,7 +80,7 @@ public: bool IsFollowing() const; void Reset(); - inline void SetState(SessionState state) { m_state = state; } + void SetState(SessionState state); /// \returns true if altitude information along |m_route| is available and /// false otherwise. @@ -123,6 +123,7 @@ public: RemoveRouteCallback const & removeRouteCallback); void SetProgressCallback(ProgressCallback const & progressCallback); void SetCheckpointCallback(CheckpointCallback const & checkpointCallback); + void SetChangeSessionStateCallback(ChangeSessionStateCallback const & changeSessionStateCallback); void SetSpeedCamShowCallback(SpeedCameraShowCallback && callback); void SetSpeedCamClearCallback(SpeedCameraClearCallback && callback); @@ -212,6 +213,7 @@ private: RemoveRouteCallback m_removeRouteCallback; ProgressCallback m_progressCallback; CheckpointCallback m_checkpointCallback; + ChangeSessionStateCallback m_changeSessionStateCallback; // Statistics parameters // Passed distance on route including reroutes