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

github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/map
diff options
context:
space:
mode:
authorVladimir Byko-Ianko <bykoianko@gmail.com>2016-12-09 10:47:11 +0300
committerGitHub <noreply@github.com>2016-12-09 10:47:11 +0300
commit2d14212f0090603d282cf1217ab7ade354442f30 (patch)
tree6ac3095f5d3aa201b7413783d668e4c56ce14be6 /map
parent0e1cadf2330de4b618baf2728b0461845ee37fe2 (diff)
parentaf35fcd29b6b8d1cb11a5816587f43872d01ee1e (diff)
Merge pull request #4920 from darina/traffic-manager-logic-update
Update traffic state after downloading or deleting mwm.
Diffstat (limited to 'map')
-rw-r--r--map/framework.cpp3
-rw-r--r--map/traffic_manager.cpp80
-rw-r--r--map/traffic_manager.hpp6
3 files changed, 61 insertions, 28 deletions
diff --git a/map/framework.cpp b/map/framework.cpp
index 9c29efc8dd..07c272339c 100644
--- a/map/framework.cpp
+++ b/map/framework.cpp
@@ -577,6 +577,7 @@ void Framework::OnCountryFileDownloaded(storage::TCountryId const & countryId, s
if (id.IsAlive())
rect = id.GetInfo()->m_limitRect;
}
+ m_trafficManager.Invalidate();
InvalidateRect(rect);
m_searchEngine->ClearCaches();
}
@@ -596,9 +597,11 @@ bool Framework::OnCountryFileDelete(storage::TCountryId const & countryId, stora
bool deferredDelete = false;
if (localFile)
{
+ auto const mwmId = m_model.GetIndex().GetMwmIdByCountryFile(platform::CountryFile(countryId));
rect = m_infoGetter->GetLimitRectForLeaf(countryId);
m_model.DeregisterMap(platform::CountryFile(countryId));
deferredDelete = true;
+ m_trafficManager.OnMwmDelete(mwmId);
}
InvalidateRect(rect);
diff --git a/map/traffic_manager.cpp b/map/traffic_manager.cpp
index 9bab47deb6..b1e6aafd42 100644
--- a/map/traffic_manager.cpp
+++ b/map/traffic_manager.cpp
@@ -31,6 +31,7 @@ TrafficManager::CacheEntry::CacheEntry()
TrafficManager::CacheEntry::CacheEntry(time_point<steady_clock> const & requestTime)
: m_isLoaded(false)
, m_dataSize(0)
+ , m_lastSeenTime(requestTime)
, m_lastRequestTime(requestTime)
, m_retriesCount(0)
, m_isWaitingForResponse(true)
@@ -100,18 +101,14 @@ void TrafficManager::SetEnabled(bool enabled)
m_drapeEngine->EnableTraffic(enabled);
if (enabled)
- {
- if (m_currentModelView.second)
- UpdateViewport(m_currentModelView.first);
- if (m_currentPosition.second)
- UpdateMyPosition(m_currentPosition.first);
- }
-
- m_observer.OnTrafficEnabled(enabled);
+ Invalidate();
+ else
+ m_observer.OnTrafficInfoClear();
}
void TrafficManager::Clear()
{
+ m_currentCacheSizeBytes = 0;
m_mwmCache.clear();
m_lastMwmsByRect.clear();
m_activeMwms.clear();
@@ -128,20 +125,41 @@ void TrafficManager::SetCurrentDataVersion(int64_t dataVersion)
m_currentDataVersion = dataVersion;
}
+void TrafficManager::OnMwmDelete(MwmSet::MwmId const & mwmId)
+{
+ if (!IsEnabled())
+ return;
+
+ {
+ lock_guard<mutex> lock(m_mutex);
+ ClearCache(mwmId);
+ }
+ Invalidate();
+}
+
void TrafficManager::OnDestroyGLContext()
{
if (!IsEnabled())
return;
+ m_observer.OnTrafficInfoClear();
+
lock_guard<mutex> lock(m_mutex);
Clear();
}
void TrafficManager::OnRecoverGLContext()
{
+ Invalidate();
+}
+
+void TrafficManager::Invalidate()
+{
if (!IsEnabled())
return;
+ m_lastMwmsByRect.clear();
+
if (m_currentModelView.second)
UpdateViewport(m_currentModelView.first);
if (m_currentPosition.second)
@@ -236,7 +254,7 @@ bool TrafficManager::WaitForRequest(vector<MwmSet::MwmId> & mwms)
return true;
}
-void TrafficManager::RequestTrafficData(MwmSet::MwmId const & mwmId)
+void TrafficManager::RequestTrafficData(MwmSet::MwmId const & mwmId, bool force)
{
bool needRequesting = false;
auto const currentTime = steady_clock::now();
@@ -248,14 +266,15 @@ void TrafficManager::RequestTrafficData(MwmSet::MwmId const & mwmId)
}
else
{
- it->second.m_lastSeenTime = currentTime;
auto const passedSeconds = currentTime - it->second.m_lastRequestTime;
- if (passedSeconds >= kUpdateInterval)
+ if (passedSeconds >= kUpdateInterval || force)
{
needRequesting = true;
it->second.m_isWaitingForResponse = true;
it->second.m_lastRequestTime = currentTime;
}
+ if (!force)
+ it->second.m_lastSeenTime = currentTime;
}
if (needRequesting)
@@ -273,7 +292,7 @@ void TrafficManager::RequestTrafficData()
for (auto const & mwmId : m_activeMwms)
{
ASSERT(mwmId.IsAlive(), ());
- RequestTrafficData(mwmId);
+ RequestTrafficData(mwmId, false /* force */);
}
UpdateState();
}
@@ -295,11 +314,7 @@ void TrafficManager::OnTrafficRequestFailed(traffic::TrafficInfo && info)
if (m_activeMwms.find(info.GetMwmId()) != m_activeMwms.end())
{
if (it->second.m_retriesCount < kMaxRetriesCount)
- {
- it->second.m_lastRequestTime = steady_clock::now();
- it->second.m_isWaitingForResponse = true;
- RequestTrafficData(info.GetMwmId());
- }
+ RequestTrafficData(info.GetMwmId(), true /* force */);
++it->second.m_retriesCount;
}
else
@@ -359,21 +374,32 @@ void TrafficManager::CheckCacheSize()
while (m_currentCacheSizeBytes > m_maxCacheSizeBytes &&
m_mwmCache.size() > m_activeMwms.size())
{
- auto const mwmId = itSeen->second;
- auto const it = m_mwmCache.find(mwmId);
- if (it->second.m_isLoaded)
- {
- ASSERT_GREATER_OR_EQUAL(m_currentCacheSizeBytes, it->second.m_dataSize, ());
- m_currentCacheSizeBytes -= it->second.m_dataSize;
- m_drapeEngine->ClearTrafficCache(mwmId);
- m_observer.OnTrafficInfoRemoved(mwmId);
- }
- m_mwmCache.erase(it);
+ ClearCache(itSeen->second);
++itSeen;
}
}
}
+void TrafficManager::ClearCache(MwmSet::MwmId const & mwmId)
+{
+ auto const it = m_mwmCache.find(mwmId);
+ if (it == m_mwmCache.end())
+ return;
+
+ if (it->second.m_isLoaded)
+ {
+ ASSERT_GREATER_OR_EQUAL(m_currentCacheSizeBytes, it->second.m_dataSize, ());
+ m_currentCacheSizeBytes -= it->second.m_dataSize;
+
+ m_drapeEngine->ClearTrafficCache(mwmId);
+ GetPlatform().RunOnGuiThread([this, mwmId]()
+ {
+ m_observer.OnTrafficInfoRemoved(mwmId);
+ });
+ }
+ m_mwmCache.erase(it);
+}
+
bool TrafficManager::IsEnabled() const
{
return m_state != TrafficState::Disabled;
diff --git a/map/traffic_manager.hpp b/map/traffic_manager.hpp
index e2ad3ce7d1..f379310073 100644
--- a/map/traffic_manager.hpp
+++ b/map/traffic_manager.hpp
@@ -72,8 +72,11 @@ public:
void UpdateViewport(ScreenBase const & screen);
void UpdateMyPosition(MyPosition const & myPosition);
+ void Invalidate();
+
void OnDestroyGLContext();
void OnRecoverGLContext();
+ void OnMwmDelete(MwmSet::MwmId const & mwmId);
private:
void ThreadRoutine();
@@ -85,9 +88,10 @@ private:
private:
// This is a group of methods that haven't their own synchronization inside.
void RequestTrafficData();
- void RequestTrafficData(MwmSet::MwmId const & mwmId);
+ void RequestTrafficData(MwmSet::MwmId const & mwmId, bool force);
void Clear();
+ void ClearCache(MwmSet::MwmId const & mwmId);
void CheckCacheSize();
void UpdateState();