blob: ef21a0de3416e5df29cc52800f0750d592ee91e9 (
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
|
#include "map/gps_tracker.hpp"
#include "map/framework.hpp"
#include "platform/platform.hpp"
#include "base/file_name_utils.hpp"
#include "std/atomic.hpp"
#include "defines.hpp"
namespace
{
char const kEnabledKey[] = "GpsTrackingEnabled";
char const kDurationHours[] = "GpsTrackingDuration";
uint32_t constexpr kDefaultDurationHours = 24;
size_t constexpr kMaxItemCount = 100000; // > 24h with 1point/s
inline string GetFilePath()
{
return base::JoinPath(GetPlatform().WritableDir(), GPS_TRACK_FILENAME);
}
inline bool GetSettingsIsEnabled()
{
bool enabled;
if (!settings::Get(kEnabledKey, enabled))
enabled = false;
return enabled;
}
inline void SetSettingsIsEnabled(bool enabled)
{
settings::Set(kEnabledKey, enabled);
}
inline hours GetSettingsDuration()
{
uint32_t duration;
if (!settings::Get(kDurationHours, duration))
duration = kDefaultDurationHours;
return hours(duration);
}
inline void SetSettingsDuration(hours duration)
{
uint32_t const hours = static_cast<uint32_t>(duration.count());
settings::Set(kDurationHours, hours);
}
} // namespace
GpsTracker & GpsTracker::Instance()
{
static GpsTracker instance;
return instance;
}
GpsTracker::GpsTracker()
: m_enabled(GetSettingsIsEnabled())
, m_track(GetFilePath(), kMaxItemCount, GetSettingsDuration(), make_unique<GpsTrackFilter>())
{
}
void GpsTracker::SetEnabled(bool enabled)
{
if (enabled == m_enabled)
return;
SetSettingsIsEnabled(enabled);
m_enabled = enabled;
if (enabled)
m_track.Clear();
}
bool GpsTracker::IsEnabled() const
{
return m_enabled;
}
void GpsTracker::SetDuration(hours duration)
{
SetSettingsDuration(duration);
m_track.SetDuration(duration);
}
hours GpsTracker::GetDuration() const
{
return m_track.GetDuration();
}
void GpsTracker::Connect(TGpsTrackDiffCallback const & fn)
{
m_track.SetCallback(fn);
}
void GpsTracker::Disconnect()
{
m_track.SetCallback(nullptr);
}
void GpsTracker::OnLocationUpdated(location::GpsInfo const & info)
{
if (!m_enabled)
return;
m_track.AddPoint(info);
}
|