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

router_delegate.cpp « routing - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: caaca88a63bebbbd29f13ea885bc12141a437039 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#include "router_delegate.hpp"

namespace routing
{
namespace
{
void DefaultProgressFn(float /* progress */) {}
void DefaultPointFn(m2::PointD const & /* point */) {}
} //  namespace

RouterDelegate::RouterDelegate()
{
  m_progressCallback = DefaultProgressFn;
  m_pointCallback = DefaultPointFn;
}

void RouterDelegate::SetProgressCallback(TProgressCallback const & progressCallback)
{
  m_progressCallback = progressCallback ? progressCallback : DefaultProgressFn;
}

void RouterDelegate::SetPointCheckCallback(TPointCheckCallback const & pointCallback)
{
  m_pointCallback = pointCallback ? pointCallback : DefaultPointFn;
}

void RouterDelegate::OnProgress(float progress) const
{
  lock_guard<mutex> l(m_guard);
  if (!IsCancelled())
    m_progressCallback(progress);
}

void RouterDelegate::Reset()
{
  lock_guard<mutex> l(m_guard);
  TimeoutCancellable::Reset();
}

void RouterDelegate::OnPointCheck(m2::PointD const & point) const
{
  lock_guard<mutex> l(m_guard);
  if (!IsCancelled())
    m_pointCallback(point);
}

TimeoutCancellable::TimeoutCancellable() : m_timeoutSec(0)
{
}

bool TimeoutCancellable::IsCancelled() const
{
  if (m_timeoutSec && m_timer.ElapsedSeconds() > m_timeoutSec)
    return true;
  return Cancellable::IsCancelled();
}

void TimeoutCancellable::Reset()
{
  m_timeoutSec = 0;
  Cancellable::Reset();
}

void TimeoutCancellable::SetTimeout(uint32_t timeoutSec)
{
  m_timeoutSec = timeoutSec;
  m_timer.Reset();
}

}  //  namespace routing