diff options
author | Mikhail Gorbushin <m.gorbushin@corp.mail.ru> | 2019-10-28 14:21:46 +0300 |
---|---|---|
committer | Tatiana Yan <tatiana.kondakova@gmail.com> | 2019-11-07 12:56:29 +0300 |
commit | 923dbbefee3b6009d1d204a0e0d9192b881068f2 (patch) | |
tree | 40b631d30c53c6b6841014c7136a2fa35f29ad35 /routing/router_delegate.cpp | |
parent | 0e4d9d6bdf2d8d7b8a7d8d9eb69d68ce30a9ed9e (diff) |
[routing] Refactor RouterDelegate
Diffstat (limited to 'routing/router_delegate.cpp')
-rw-r--r-- | routing/router_delegate.cpp | 48 |
1 files changed, 14 insertions, 34 deletions
diff --git a/routing/router_delegate.cpp b/routing/router_delegate.cpp index accde1bbd1..06ff26a4a0 100644 --- a/routing/router_delegate.cpp +++ b/routing/router_delegate.cpp @@ -1,12 +1,14 @@ #include "routing/router_delegate.hpp" +#include <chrono> + namespace routing { namespace { void DefaultProgressFn(float /* progress */) {} void DefaultPointFn(m2::PointD const & /* point */) {} -} // namespace +} // namespace RouterDelegate::RouterDelegate() { @@ -14,56 +16,34 @@ RouterDelegate::RouterDelegate() m_pointCallback = DefaultPointFn; } -void RouterDelegate::SetProgressCallback(ProgressCallback const & progressCallback) -{ - m_progressCallback = progressCallback ? progressCallback : DefaultProgressFn; -} - -void RouterDelegate::SetPointCheckCallback(PointCheckCallback const & pointCallback) -{ - m_pointCallback = pointCallback ? pointCallback : DefaultPointFn; -} - void RouterDelegate::OnProgress(float progress) const { - std::lock_guard<std::mutex> l(m_guard); - if (!IsCancelled()) + if (!m_cancellable.IsCancelled()) m_progressCallback(progress); } -void RouterDelegate::Reset() -{ - std::lock_guard<std::mutex> l(m_guard); - TimeoutCancellable::Reset(); -} - void RouterDelegate::OnPointCheck(m2::PointD const & point) const { - std::lock_guard<std::mutex> l(m_guard); - if (!IsCancelled()) + if (!m_cancellable.IsCancelled()) m_pointCallback(point); } -TimeoutCancellable::TimeoutCancellable() : m_timeoutSec(0) +void RouterDelegate::SetProgressCallback(ProgressCallback const & progressCallback) { + m_progressCallback = progressCallback ? progressCallback : DefaultProgressFn; } -bool TimeoutCancellable::IsCancelled() const +void RouterDelegate::SetPointCheckCallback(PointCheckCallback const & pointCallback) { - if (m_timeoutSec && m_timer.ElapsedSeconds() > m_timeoutSec) - return true; - return Cancellable::IsCancelled(); + m_pointCallback = pointCallback ? pointCallback : DefaultPointFn; } -void TimeoutCancellable::Reset() +void RouterDelegate::SetTimeout(uint32_t timeoutSec) { - m_timeoutSec = 0; - Cancellable::Reset(); -} + if (timeoutSec == kNoTimeout) + return; -void TimeoutCancellable::SetTimeout(uint32_t timeoutSec) -{ - m_timeoutSec = timeoutSec; - m_timer.Reset(); + std::chrono::steady_clock::duration const timeout = std::chrono::seconds(timeoutSec); + m_cancellable.SetDeadline(std::chrono::steady_clock::now() + timeout); } } // namespace routing |