Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'routing/router_delegate.cpp')
-rw-r--r--routing/router_delegate.cpp48
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