From 91483a5cf6e07864eb3bb16f848666571530b255 Mon Sep 17 00:00:00 2001 From: VladiMihaylenko Date: Thu, 1 Feb 2018 14:10:04 +0300 Subject: Added applying status to nodes. --- storage/storage.cpp | 13 ++++++++++- storage/storage.hpp | 3 +++ storage/storage_defines.cpp | 53 ++++++++++++++++++++++++++------------------- storage/storage_defines.hpp | 20 +++++++++-------- 4 files changed, 57 insertions(+), 32 deletions(-) (limited to 'storage') diff --git a/storage/storage.cpp b/storage/storage.cpp index b0e4750dce..34083c4123 100644 --- a/storage/storage.cpp +++ b/storage/storage.cpp @@ -404,7 +404,7 @@ Status Storage::CountryStatus(TCountryId const & countryId) const if (IsCountryInQueue(countryId)) { if (IsCountryFirstInQueue(countryId)) - return Status::EDownloading; + return IsDiffApplyingInProgressToCountry(countryId) ? Status::EApplying : Status::EDownloading; else return Status::EInQueue; } @@ -871,6 +871,7 @@ void Storage::RegisterDownloadedFiles(TCountryId const & countryId, MapOptions o /// and we can't stop the process. /// TODO: Make the applying process cancellable. m_queue.begin()->SetFrozen(); + NotifyStatusChangedForHierarchy(countryId); ApplyDiff(countryId, fn); return; } @@ -1067,6 +1068,16 @@ bool Storage::IsCountryFirstInQueue(TCountryId const & countryId) const return !m_queue.empty() && m_queue.front().GetCountryId() == countryId; } +bool Storage::IsDiffApplyingInProgressToCountry(TCountryId const & countryId) const +{ + ASSERT_THREAD_CHECKER(m_threadChecker, ()); + + if (!IsCountryFirstInQueue(countryId)) + return false; + + return m_queue.front().IsFrozen(); +} + void Storage::SetLocale(string const & locale) { m_countryNameGetter.SetLocale(locale); } string Storage::GetLocale() const { return m_countryNameGetter.GetLocale(); } void Storage::SetDownloaderForTesting(unique_ptr && downloader) diff --git a/storage/storage.hpp b/storage/storage.hpp index e79983b650..b938eca52c 100644 --- a/storage/storage.hpp +++ b/storage/storage.hpp @@ -588,6 +588,9 @@ private: // Returns true when country is first in the downloader's queue. bool IsCountryFirstInQueue(TCountryId const & countryId) const; + // Returns true if we started the diff applying procedure for an mwm with countryId. + bool IsDiffApplyingInProgressToCountry(TCountryId const & countryId) const; + // Returns local country files of a particular version, or wrapped // nullptr if there're no country files corresponding to the // version. diff --git a/storage/storage_defines.cpp b/storage/storage_defines.cpp index cd36806f2e..17e359bb5c 100644 --- a/storage/storage_defines.cpp +++ b/storage/storage_defines.cpp @@ -1,6 +1,9 @@ #include "storage/storage_defines.hpp" -#include "std/sstream.hpp" +#include + +using namespace std; +using namespace string_literals; namespace storage { @@ -9,23 +12,25 @@ string DebugPrint(Status status) switch (status) { case Status::EUndefined: - return string("EUndefined"); + return "EUndefined"s; case Status::EOnDisk: - return string("OnDisk"); + return "OnDisk"s; case Status::ENotDownloaded: - return string("NotDownloaded"); + return "NotDownloaded"s; case Status::EDownloadFailed: - return string("DownloadFailed"); + return "DownloadFailed"s; case Status::EDownloading: - return string("Downloading"); + return "Downloading"s; + case Status::EApplying: + return "Applying"s; case Status::EInQueue: - return string("InQueue"); + return "InQueue"s; case Status::EUnknown: - return string("Unknown"); + return "Unknown"s; case Status::EOnDiskOutOfDate: - return string("OnDiskOutOfDate"); + return "OnDiskOutOfDate"s; case Status::EOutOfMemFailed: - return string("OutOfMemFailed"); + return "OutOfMemFailed"s; } } @@ -34,21 +39,23 @@ string DebugPrint(NodeStatus status) switch (status) { case NodeStatus::Undefined: - return string("Undefined"); + return "Undefined"s; case NodeStatus::Error: - return string("Error"); + return "Error"s; case NodeStatus::OnDisk: - return string("OnDisk"); + return "OnDisk"s; case NodeStatus::NotDownloaded: - return string("NotDownloaded"); + return "NotDownloaded"s; case NodeStatus::Downloading: - return string("Downloading"); + return "Downloading"s; + case NodeStatus::Applying: + return "Applying"s; case NodeStatus::InQueue: - return string("InQueue"); + return "InQueue"s; case NodeStatus::OnDiskOutOfDate: - return string("OnDiskOutOfDate"); + return "OnDiskOutOfDate"s; case NodeStatus::Partly: - return string("Partly"); + return "Partly"s; } } @@ -57,13 +64,13 @@ string DebugPrint(NodeErrorCode status) switch (status) { case NodeErrorCode::NoError: - return string("NoError"); + return "NoError"s; case NodeErrorCode::UnknownError: - return string("UnknownError"); + return "UnknownError"s; case NodeErrorCode::OutOfMemFailed: - return string("OutOfMemFailed"); + return "OutOfMemFailed"s; case NodeErrorCode::NoInetConnection: - return string("NoInetConnection"); + return "NoInetConnection"s; } } @@ -81,6 +88,8 @@ StatusAndError ParseStatus(Status innerStatus) return StatusAndError(NodeStatus::Error, NodeErrorCode::NoInetConnection); case Status::EDownloading: return StatusAndError(NodeStatus::Downloading, NodeErrorCode::NoError); + case Status::EApplying: + return StatusAndError(NodeStatus::Applying, NodeErrorCode::NoError); case Status::EInQueue: return StatusAndError(NodeStatus::InQueue, NodeErrorCode::NoError); case Status::EUnknown: diff --git a/storage/storage_defines.hpp b/storage/storage_defines.hpp index ee2c6361d6..052357e7d2 100644 --- a/storage/storage_defines.hpp +++ b/storage/storage_defines.hpp @@ -2,10 +2,10 @@ #include "storage/index.hpp" -#include "std/cstdint.hpp" -#include "std/function.hpp" -#include "std/string.hpp" -#include "std/utility.hpp" +#include +#include +#include +#include namespace storage { @@ -17,12 +17,13 @@ namespace storage ENotDownloaded, /**< Mwm can be download but not downloaded yet. */ EDownloadFailed, /**< Downloading failed because no internet connection. */ EDownloading, /**< Downloading a new mwm or updating an old one. */ + EApplying, /**< Applying downloaded diff for an old mwm. */ EInQueue, /**< A mwm is waiting for downloading in the queue. */ EUnknown, /**< Downloading failed because of unknown error. */ EOnDiskOutOfDate, /**< An update for a downloaded mwm is ready according to counties.txt. */ EOutOfMemFailed, /**< Downloading failed because it's not enough memory */ }; - string DebugPrint(Status status); + std::string DebugPrint(Status status); /// \note The order of enum items is important. It is used in Storage::NodeStatus method. /// If it's necessary to add more statuses it's better to add to the end. @@ -30,6 +31,7 @@ namespace storage { Undefined, Downloading, /**< Downloading a new mwm or updating an old one. */ + Applying, /**< Applying downloaded diff for an old mwm. */ InQueue, /**< An mwm is waiting for downloading in the queue. */ Error, /**< An error happened while downloading */ OnDiskOutOfDate, /**< An update for a downloaded mwm is ready according to counties.txt. */ @@ -37,7 +39,7 @@ namespace storage NotDownloaded, /**< An mwm can be downloaded but not downloaded yet. */ Partly, /**< Leafs of group node has a mix of NotDownloaded and OnDisk status. */ }; - string DebugPrint(NodeStatus status); + std::string DebugPrint(NodeStatus status); enum class NodeErrorCode { @@ -46,7 +48,7 @@ namespace storage OutOfMemFailed, /**< Downloading failed because it's not enough memory */ NoInetConnection, /**< Downloading failed because internet connection was interrupted */ }; - string DebugPrint(NodeErrorCode status); + std::string DebugPrint(NodeErrorCode status); struct StatusAndError { @@ -61,9 +63,9 @@ namespace storage NodeStatus status; NodeErrorCode error; }; - string DebugPrint(StatusAndError statusAndError); + std::string DebugPrint(StatusAndError statusAndError); StatusAndError ParseStatus(Status innerStatus); } // namespace storage -using TDownloadFn = function; +using TDownloadFn = std::function; -- cgit v1.2.3