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
diff options
context:
space:
mode:
authorvng <viktor.govako@gmail.com>2012-07-09 01:49:35 +0400
committerAlex Zolotarev <alex@maps.me>2015-09-23 01:40:44 +0300
commitc4c866b1dea0e1205e9da45a0eb7c7d290dcaffb (patch)
tree220f707849b0a18c5c9e0829d236656a21feecc9 /indexer/index.cpp
parent5f04609fff0976ad1e45902beefd8b8bef93beaa (diff)
Refactoring of maps update after downloading:
- Delay maps deleting and updating if mwm is busy; - Fix bugs with different mwm maps status; - Add better function for country bounds; - Simplify Storage logic;
Diffstat (limited to 'indexer/index.cpp')
-rw-r--r--indexer/index.cpp83
1 files changed, 83 insertions, 0 deletions
diff --git a/indexer/index.cpp b/indexer/index.cpp
index 42536b6d75..69de20d718 100644
--- a/indexer/index.cpp
+++ b/indexer/index.cpp
@@ -3,6 +3,8 @@
#include "../platform/platform.hpp"
+#include "../coding/internal/file_data.hpp"
+
MwmValue::MwmValue(string const & name)
: m_cont(GetPlatform().GetReader(name)), m_name(name)
@@ -37,3 +39,84 @@ Index::~Index()
{
Cleanup();
}
+
+namespace
+{
+ void DeleteMapFiles(string const & path, bool deleteReady)
+ {
+ (void)my::DeleteFileX(path);
+ (void)my::DeleteFileX(path + RESUME_FILE_EXTENSION);
+ (void)my::DeleteFileX(path + DOWNLOADING_FILE_EXTENSION);
+
+ if (deleteReady)
+ (void)my::DeleteFileX(path + READY_FILE_EXTENSION);
+ }
+
+ string GetFullPath(string const & fileName)
+ {
+ return GetPlatform().WritablePathForFile(fileName);
+ }
+
+ void ReplaceFileWithReady(string const & fileName)
+ {
+ string const path = GetFullPath(fileName);
+ DeleteMapFiles(path, false);
+ CHECK ( my::RenameFileX(path + READY_FILE_EXTENSION, path), (path) );
+ }
+}
+
+bool Index::DeleteMap(string const & fileName)
+{
+ threads::MutexGuard mutexGuard(m_lock);
+ UNUSED_VALUE(mutexGuard);
+
+ if (!RemoveImpl(fileName))
+ return false;
+
+ DeleteMapFiles(GetFullPath(fileName), true);
+ return true;
+}
+
+bool Index::UpdateMap(string const & fileName, m2::RectD & rect)
+{
+ threads::MutexGuard mutexGuard(m_lock);
+ UNUSED_VALUE(mutexGuard);
+
+ MwmId const id = GetIdByName(fileName);
+ if (id != INVALID_MWM_ID)
+ {
+ m_info[id].m_status = MwmInfo::STATUS_UPDATE;
+ return false;
+ }
+
+ ReplaceFileWithReady(fileName);
+
+ (void)AddImpl(fileName, rect);
+ return true;
+}
+
+void Index::UpdateMwmInfo(MwmId id)
+{
+ switch (m_info[id].m_status)
+ {
+ case MwmInfo::STATUS_TO_REMOVE:
+ if (m_info[id].m_lockCount == 0)
+ {
+ DeleteMapFiles(m_name[id], true);
+
+ CHECK(RemoveImpl(id), ());
+ }
+ break;
+
+ case MwmInfo::STATUS_UPDATE:
+ if (m_info[id].m_lockCount == 0)
+ {
+ ClearCache(id);
+
+ ReplaceFileWithReady(m_name[id]);
+
+ m_info[id].m_status = MwmInfo::STATUS_ACTIVE;
+ }
+ break;
+ }
+}