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

async_router.hpp « routing - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: dc934ffb33acae39c38c01625c3dc34a9f8d08b3 (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
#pragma once

#include "routing/route.hpp"
#include "routing/router.hpp"

#include "std/atomic.hpp"
#include "std/map.hpp"
#include "std/mutex.hpp"
#include "std/string.hpp"
#include "std/unique_ptr.hpp"

namespace routing
{

class AsyncRouter
{
public:
  /// Callback takes ownership of passed route.
  typedef function<void(Route &, IRouter::ResultCode)> TReadyCallback;

  /// Callback on routing statistics
  typedef function<void(map<string, string> const &)> TRoutingStatisticsCallback;

  /// AsyncRouter is a wrapper class to run routing routines in the different thread
  /// @param router pointer to the router implementation. AsyncRouter will take ownership over
  /// router.
  AsyncRouter(unique_ptr<IRouter> && router,
              TRoutingStatisticsCallback const & routingStatisticsFn);

  virtual ~AsyncRouter();

  /// Main method to calulate new route from startPt to finalPt with start direction
  /// Processed result will be passed to callback. Callback will called at GUI thread.
  ///
  /// @param startPoint point to start routing
  /// @param direction start direction for routers with high cost of the turnarounds
  /// @param finalPoint target point for route
  /// @param callback function to return routing result
  virtual void CalculateRoute(m2::PointD const & startPoint, m2::PointD const & direction,
                              m2::PointD const & finalPoint, TReadyCallback const & callback);

  /// Interrupt routing and clear buffers
  virtual void ClearState();

private:
  /// This function is called in async mode
  void CalculateRouteImpl(TReadyCallback const & callback);

  /// These functions are called to send statistics about the routing
  void SendStatistics(m2::PointD const & startPoint, m2::PointD const & startDirection,
                      m2::PointD const & finalPoint,
                      IRouter::ResultCode resultCode,
                      double elapsedSec);
  void SendStatistics(m2::PointD const & startPoint, m2::PointD const & startDirection,
                      m2::PointD const & finalPoint,
                      string const & exceptionMessage);

  mutex m_paramsMutex;
  mutex m_routeMutex;
  atomic_flag m_isReadyThread;

  m2::PointD m_startPoint;
  m2::PointD m_finalPoint;
  m2::PointD m_startDirection;

  unique_ptr<IRouter> const m_router;
  TRoutingStatisticsCallback const m_routingStatisticsFn;
};

}  // namespace routing