diff --git a/map/gps_track.cpp b/map/gps_track.cpp index a753ab957b..a81ba2b97b 100644 --- a/map/gps_track.cpp +++ b/map/gps_track.cpp @@ -212,7 +212,11 @@ void GpsTrack::ProcessPoints() if (!m_collection) return; - UpdateCollection(duration, needClear, points); + pair addedIds; + pair evictedIds; + UpdateCollection(duration, needClear, points, addedIds, evictedIds); + + NotifyCallback(addedIds, evictedIds); } bool GpsTrack::HasCallback() @@ -241,7 +245,8 @@ void GpsTrack::UpdateStorage(bool needClear, vector const & points) } } -void GpsTrack::UpdateCollection(hours duration, bool needClear, vector const & points) +void GpsTrack::UpdateCollection(hours duration, bool needClear, vector const & points, + pair & addedIds, pair & evictedIds) { // Apply Clear, SetDuration and Add points @@ -257,17 +262,17 @@ void GpsTrack::UpdateCollection(hours duration, bool needClear, vector co evictedIdsByDuration = m_collection->SetDuration(duration); // Add points to the collection, if need - pair evictedIds = make_pair(kInvalidId, kInvalidId); - pair addedIds = make_pair(kInvalidId, kInvalidId); + pair evictedIdsByAdd = make_pair(kInvalidId, kInvalidId); if (!points.empty()) addedIds = m_collection->Add(points, evictedIds); + else + addedIds = make_pair(kInvalidId, kInvalidId); - // Result evicted is - evictedIds = UnionRanges(evictedIds, UnionRanges(evictedIdsByClear, evictedIdsByDuration)); - - // Send callback notification. - // Callback must be protected by m_callbackGuard + evictedIds = UnionRanges(evictedIdsByAdd, UnionRanges(evictedIdsByClear, evictedIdsByDuration)); +} +void GpsTrack::NotifyCallback(pair const & addedIds, pair const & evictedIds) +{ lock_guard lg(m_callbackGuard); if (!m_callback) @@ -277,7 +282,6 @@ void GpsTrack::UpdateCollection(hours duration, bool needClear, vector co { m_needSendSnapshop = false; - // Get all points from collection to send them to the callback vector> toAdd; toAdd.reserve(m_collection->GetSize()); m_collection->ForEach([&toAdd](TItem const & point, size_t id)->bool @@ -298,10 +302,6 @@ void GpsTrack::UpdateCollection(hours duration, bool needClear, vector co { size_t const addedCount = addedIds.second - addedIds.first + 1; ASSERT_GREATER_OR_EQUAL(m_collection->GetSize(), addedCount, ()); - - // Not all points from infos could be added to collection due to timestamp consequence restriction. - // Get added points from collection - take last points from collection, these points - // were added this time. toAdd.reserve(addedCount); m_collection->ForEach([&toAdd](TItem const & point, size_t id)->bool { diff --git a/map/gps_track.hpp b/map/gps_track.hpp index ad5282f26e..ab00cbedf4 100644 --- a/map/gps_track.hpp +++ b/map/gps_track.hpp @@ -59,7 +59,9 @@ private: void InitStorageIfNeed(); void InitCollection(hours duration); void UpdateStorage(bool needClear, vector const & points); - void UpdateCollection(hours duration, bool needClear, vector const & points); + void UpdateCollection(hours duration, bool needClear, vector const & points, + pair & addedIds, pair & evictedIds); + void NotifyCallback(pair const & addedIds, pair const & evictedIds); size_t const m_maxItemCount; string const m_filePath;