diff options
author | vng <viktor.govako@gmail.com> | 2011-12-29 05:47:35 +0400 |
---|---|---|
committer | Alex Zolotarev <alex@maps.me> | 2015-09-23 01:31:03 +0300 |
commit | 96c556e962bba2845d0e39c0ec7c98637725daae (patch) | |
tree | cdbc9ef725cf8010bc4691d37ce0c27dfb3ab95e /storage | |
parent | 29a245c35561c3808cbafa11448225c2fafb6517 (diff) |
[search] Add EGeneratingIndex status for country.
Diffstat (limited to 'storage')
-rw-r--r-- | storage/storage.cpp | 39 | ||||
-rw-r--r-- | storage/storage.hpp | 21 |
2 files changed, 41 insertions, 19 deletions
diff --git a/storage/storage.cpp b/storage/storage.cpp index 1348c9c238..b2074fec79 100644 --- a/storage/storage.cpp +++ b/storage/storage.cpp @@ -119,9 +119,12 @@ namespace storage } // second, check if this country has failed while downloading - if (m_failedCountries.find(index) != m_failedCountries.end()) + if (m_failedCountries.count(index) > 0) return EDownloadFailed; + if (m_indexGeneration.count(index) > 0) + return EGeneratingIndex; + LocalAndRemoteSizeT const size = CountryByIndex(index).Size(); if (size.first == size.second) { @@ -327,23 +330,23 @@ namespace storage { if (m_queue.empty()) { - ASSERT(false, ("Invalid url?", request.Data())); + ASSERT ( false, ("Invalid url?", request.Data()) ); return; } + TIndex const index = m_queue.front(); if (request.Status() == HttpRequest::EFailed) { // remove failed country from the queue - TIndex const failedIndex = m_queue.front(); m_queue.pop_front(); - m_failedCountries.insert(failedIndex); + m_failedCountries.insert(index); // notify GUI about failed country if (m_observerChange) - m_observerChange(failedIndex); + m_observerChange(index); } else { - LocalAndRemoteSizeT const size = CountryByIndex(m_queue.front()).Size(); + LocalAndRemoteSizeT const size = CountryByIndex(index).Size(); if (size.second != 0) m_countryProgress.first = size.first; @@ -355,22 +358,29 @@ namespace storage if (i != string::npos) file = file.substr(i+1); - // Generate search index if it's supported in this build Platform & pl = GetPlatform(); if (pl.IsFeatureSupported("search")) - pl.RunAsync(bind(&Storage::GenerateSearchIndex, this, file)); - else // Or simply activate downloaded map - UpdateAfterSearchIndex(file); + { + // Generate search index if it's supported in this build + m_indexGeneration.insert(index); + pl.RunAsync(bind(&Storage::GenerateSearchIndex, this, index, file)); + } + else + { + // Or simply activate downloaded map + UpdateAfterSearchIndex(index, file); + } } + m_request.reset(); DownloadNextCountryFromQueue(); } - void Storage::GenerateSearchIndex(string const & fName) const + void Storage::GenerateSearchIndex(TIndex const & index, string const & fName) { if (indexer::BuildSearchIndexFromDatFile(fName)) { - GetPlatform().RunOnGuiThread(bind(&Storage::UpdateAfterSearchIndex, this, fName)); + GetPlatform().RunOnGuiThread(bind(&Storage::UpdateAfterSearchIndex, this, index, fName)); } else { @@ -378,8 +388,11 @@ namespace storage } } - void Storage::UpdateAfterSearchIndex(string const & fName) const + void Storage::UpdateAfterSearchIndex(TIndex const & index, string const & fName) { + // remove from index set + m_indexGeneration.erase(index); + // activate downloaded map piece m_addMap(fName); diff --git a/storage/storage.hpp b/storage/storage.hpp index 08a080bd85..1b0e042311 100644 --- a/storage/storage.hpp +++ b/storage/storage.hpp @@ -18,6 +18,7 @@ namespace storage enum TStatus { EOnDisk = 0, + EGeneratingIndex, ENotDownloaded, EDownloadFailed, EDownloading, @@ -28,11 +29,14 @@ namespace storage struct TIndex { static int const INVALID; + int m_group; int m_country; int m_region; + TIndex(int group = INVALID, int country = INVALID, int region = INVALID) : m_group(group), m_country(country), m_region(region) {} + bool operator==(TIndex const & other) const { return (m_group == other.m_group && @@ -60,16 +64,21 @@ namespace storage CountriesContainerT m_countries; + /// store queue for downloading typedef list<TIndex> TQueue; TQueue m_queue; + + /// stores countries which download has failed recently + typedef set<TIndex> TCountriesSet; + TCountriesSet m_failedCountries; + + /// store countries set for which search index is generating + TCountriesSet m_indexGeneration; + /// used to correctly calculate total country download progress with more than 1 file /// <current, total> downloader::HttpRequest::ProgressT m_countryProgress; - typedef set<TIndex> TFailedCountries; - /// stores countries which download has failed recently - TFailedCountries m_failedCountries; - /// @name Communicate with GUI //@{ typedef function<void (TIndex const &)> TObserverChangeCountryFunction; @@ -96,8 +105,8 @@ namespace storage void DownloadNextCountryFromQueue(); Country const & CountryByIndex(TIndex const & index) const; - void GenerateSearchIndex(string const & fName) const; - void UpdateAfterSearchIndex(string const & fName) const; + void GenerateSearchIndex(TIndex const & index, string const & fName); + void UpdateAfterSearchIndex(TIndex const & index, string const & fName); public: Storage() {} |