Merge pull request #4991 from syershov/MAPSME-3235

Disable sending point in background
This commit is contained in:
Roman Kuznetsov 2016-12-14 18:03:15 +03:00 committed by GitHub
commit 2497be5ebb
5 changed files with 24 additions and 0 deletions

View file

@ -1307,6 +1307,7 @@ void Framework::EnterBackground()
SaveViewport();
m_trafficManager.OnEnterBackground();
m_trackingReporter.SetAllowSendingPoints(false);
ms::LatLon const ll = MercatorBounds::ToLatLon(GetViewportCenter());
alohalytics::Stats::Instance().LogEvent("Framework::EnterBackground", {{"zoom", strings::to_string(GetDrawScale())},
@ -1328,6 +1329,7 @@ void Framework::EnterForeground()
CallDrapeFunction(bind(&df::DrapeEngine::SetTimeInBackground, _1, time));
m_trafficManager.OnEnterForeground();
m_trackingReporter.SetAllowSendingPoints(true);
}
bool Framework::GetCurrentPosition(double & lat, double & lon) const

View file

@ -46,6 +46,14 @@ bool Connection::Reconnect()
return true;
}
void Connection::Shutdown()
{
if (!m_socket)
return;
m_socket->Close();
}
// TODO: implement historical
bool Connection::Send(boost::circular_buffer<DataPoint> const & points)
{

View file

@ -24,6 +24,7 @@ public:
Connection(unique_ptr<platform::Socket> socket, string const & host, uint16_t port,
bool isHistorical);
bool Reconnect();
void Shutdown();
bool Send(boost::circular_buffer<DataPoint> const & points);
private:

View file

@ -92,6 +92,16 @@ void Reporter::Run()
bool Reporter::SendPoints()
{
if (!m_allowSendingPoints)
{
if (m_wasConnected)
{
m_realtimeSender.Shutdown();
m_wasConnected = false;
}
return true;
}
if (m_points.empty())
return true;

View file

@ -37,12 +37,15 @@ public:
void AddLocation(location::GpsInfo const & info);
void SetAllowSendingPoints(bool allow) { m_allowSendingPoints = allow; }
inline void SetIdleFunc(function<void()> fn) { m_idleFn = fn; }
private:
void Run();
bool SendPoints();
bool m_allowSendingPoints = true;
Connection m_realtimeSender;
milliseconds m_pushDelay;
bool m_wasConnected = false;