From 5bbc601fe12df57a71608dc0bb599b10b2cb6646 Mon Sep 17 00:00:00 2001 From: Vladimir Byko-Ianko Date: Wed, 24 Feb 2016 11:39:04 +0300 Subject: [PATCH] [new downloader] Calling status change callback in Storage for ancestors. --- storage/storage.cpp | 26 +++++++++++++++++++------- storage/storage.hpp | 9 +-------- 2 files changed, 20 insertions(+), 15 deletions(-) diff --git a/storage/storage.cpp b/storage/storage.cpp index 40c3d5314c..800b0e0a1e 100644 --- a/storage/storage.cpp +++ b/storage/storage.cpp @@ -465,7 +465,7 @@ void Storage::DownloadCountry(TCountryId const & countryId, MapOptions opt) if (m_queue.size() == 1) DownloadNextCountryFromQueue(); else - NotifyStatusChanged(countryId); + NotifyStatusChangedForHierarchy(countryId); SaveDownloadQueue(); } @@ -481,7 +481,7 @@ void Storage::DeleteCountry(TCountryId const & countryId, MapOptions opt) if (localFile) m_update(*localFile); - NotifyStatusChanged(countryId); + NotifyStatusChangedForHierarchy(countryId); } void Storage::DeleteCustomCountryVersion(LocalCountryFile const & localFile) @@ -505,7 +505,7 @@ void Storage::DeleteCustomCountryVersion(LocalCountryFile const & localFile) return; } - MY_SCOPE_GUARD(notifyStatusChanged, bind(&Storage::NotifyStatusChanged, this, countryId)); + MY_SCOPE_GUARD(notifyStatusChanged, bind(&Storage::NotifyStatusChangedForHierarchy, this, countryId)); // If file version equals to current data version, delete from downloader all pending requests for // the country. @@ -533,6 +533,18 @@ void Storage::NotifyStatusChanged(TCountryId const & countryId) observer.m_changeCountryFn(countryId); } +void Storage::NotifyStatusChangedForHierarchy(TCountryId const & countryId) +{ + // Notification status changing for a leaf in country tree. + NotifyStatusChanged(countryId); + + // Notification status changing for ancestors in country tree. + ForEachAncestorExceptForTheRoot(countryId, [&] (TCountryId const & parentId, TCountriesContainer const &) + { + NotifyStatusChanged(parentId); + }); +} + void Storage::DownloadNextCountryFromQueue() { ASSERT_THREAD_CHECKER(m_threadChecker, ()); @@ -549,7 +561,7 @@ void Storage::DownloadNextCountryFromQueue() if (!PreparePlaceForCountryFiles(GetCurrentDataVersion(), m_dataDir, GetCountryFile(countryId))) { OnMapDownloadFinished(countryId, false /* success */, queuedCountry.GetInitOptions()); - NotifyStatusChanged(countryId); + NotifyStatusChangedForHierarchy(countryId); CorrectJustDownloaded(m_queue.begin(), m_queue, m_justDownloaded); DownloadNextCountryFromQueue(); return; @@ -558,7 +570,7 @@ void Storage::DownloadNextCountryFromQueue() DownloadNextFile(queuedCountry); // New status for the country, "Downloading" - NotifyStatusChanged(queuedCountry.GetCountryId()); + NotifyStatusChangedForHierarchy(queuedCountry.GetCountryId()); } void Storage::DownloadNextFile(QueuedCountry const & country) @@ -589,7 +601,7 @@ bool Storage::DeleteFromDownloader(TCountryId const & countryId) if (!DeleteCountryFilesFromDownloader(countryId, MapOptions::MapWithCarRouting)) return false; - NotifyStatusChanged(countryId); + NotifyStatusChangedForHierarchy(countryId); return true; } @@ -679,7 +691,7 @@ void Storage::OnMapFileDownloadFinished(bool success, CorrectJustDownloaded(m_queue.begin(), m_queue, m_justDownloaded); SaveDownloadQueue(); - NotifyStatusChanged(countryId); + NotifyStatusChangedForHierarchy(countryId); m_downloader->Reset(); DownloadNextCountryFromQueue(); } diff --git a/storage/storage.hpp b/storage/storage.hpp index 6a8d0a884b..1f494e4c28 100644 --- a/storage/storage.hpp +++ b/storage/storage.hpp @@ -321,14 +321,6 @@ public: template void ForEachAncestorExceptForTheRoot(TCountryId const & childId, ToDo && toDo) const; - /// \brief Subscribe on change status callback. - /// \returns a unique index of added status callback structure. - size_t SubscribeStatusCallback(StatusCallback const & statusCallbacks) { return 0; } - - /// \brief Unsubscribe from change status callback. - /// \param index is a unique index of callback retruned by SubscribeStatusCallback. - void UnsubscribeStatusCallback(size_t index) {} - /// \brief Sets callback which will be called in case of a click on download map button on the map. void SetCallbackForClickOnDownloadMap(TDownloadFn & downloadFn); @@ -497,6 +489,7 @@ private: Status NodeStatus(TCountriesContainer const & node) const; void NotifyStatusChanged(TCountryId const & countryId); + void NotifyStatusChangedForHierarchy(TCountryId const & countryId); /// @todo Temporary function to gel all associated indexes for the country file name. /// Will be removed in future after refactoring.