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

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

#include "tracking/connection.hpp"

#include "traffic/speed_groups.hpp"

#include "base/thread.hpp"

#include "std/atomic.hpp"
#include "std/chrono.hpp"
#include "std/condition_variable.hpp"
#include "std/function.hpp"
#include "std/mutex.hpp"
#include "std/string.hpp"
#include "std/unique_ptr.hpp"
#include "std/vector.hpp"

#include "boost/circular_buffer.hpp"

namespace location
{
class GpsInfo;
}

namespace platform
{
class Socket;
}

namespace tracking
{
class Reporter final
{
public:
  static milliseconds const kPushDelayMs;
  static const char kEnableTrackingKey[];

  Reporter(unique_ptr<platform::Socket> socket, string const & host, uint16_t port,
           milliseconds pushDelay);
  ~Reporter();

  void AddLocation(location::GpsInfo const & info, traffic::SpeedGroup traffic);

  void SetAllowSendingPoints(bool allow) { m_allowSendingPoints = allow; }

  inline void SetIdleFunc(function<void()> fn) { m_idleFn = fn; }

private:
  void Run();
  bool SendPoints();

  atomic<bool> m_allowSendingPoints;
  Connection m_realtimeSender;
  milliseconds m_pushDelay;
  bool m_wasConnected = false;
  double m_lastConnectionAttempt = 0.0;
  double m_lastNotChargingEvent = 0.0;
  // Function to be called every |kPushDelayMs| in
  // case no points were sent.
  function<void()> m_idleFn;
  // Input buffer for incoming points. Worker thread steals it contents.
  vector<DataPoint> m_input;
  // Last collected points, sends periodically to server.
  boost::circular_buffer<DataPoint> m_points;
  double m_lastGpsTime = 0.0;
  bool m_isFinished = false;
  mutex m_mutex;
  condition_variable m_cv;
  threads::SimpleThread m_thread;
};
}  // namespace tracking