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:
authorYuri Gorshenin <y@maps.me>2015-07-01 16:55:50 +0300
committerAlex Zolotarev <alex@maps.me>2015-09-23 02:53:33 +0300
commit54e5990c7e4c65b0749c21ce4fe3866909a29668 (patch)
treeec9f80550c7402b7d5f577773353c0d7eb6fb0a7 /indexer/mwm_set.cpp
parent025f73ad85d489c4ea143b9d95dde4d308daf89b (diff)
Revert "Merge pull request #1068 from maps/revert-929-abstract-country-file"
This reverts commit 66aac38c3004d261ee06a16f7e9db372f67614df, reversing changes made to ad8708944070f6b32a17fbb944d3c493b3fb2a24.
Diffstat (limited to 'indexer/mwm_set.cpp')
-rw-r--r--indexer/mwm_set.cpp130
1 files changed, 68 insertions, 62 deletions
diff --git a/indexer/mwm_set.cpp b/indexer/mwm_set.cpp
index c9005078ce..d6961ebdd0 100644
--- a/indexer/mwm_set.cpp
+++ b/indexer/mwm_set.cpp
@@ -9,6 +9,9 @@
#include "std/algorithm.hpp"
+using platform::CountryFile;
+using platform::LocalCountryFile;
+
MwmInfo::MwmInfo() : m_minScale(0), m_maxScale(0), m_status(STATUS_DEREGISTERED), m_lockCount(0) {}
MwmInfo::MwmTypeT MwmInfo::GetType() const
@@ -74,57 +77,64 @@ MwmSet::~MwmSet()
void MwmSet::Cleanup()
{
lock_guard<mutex> lock(m_lock);
-
ClearCacheImpl(m_cache.begin(), m_cache.end());
-
-#ifdef DEBUG
- for (auto const & p : m_info)
- {
- MwmInfo const & info = *p.second;
- if (info.IsUpToDate())
- {
- ASSERT_EQUAL(info.m_lockCount, 0, (info.m_fileName));
- ASSERT(!info.m_fileName.empty(), ());
- }
- }
-#endif
}
-MwmSet::MwmId MwmSet::GetMwmIdByFileNameImpl(TMwmFileName const & name) const
+MwmSet::MwmId MwmSet::GetMwmIdByCountryFileImpl(CountryFile const & countryFile) const
{
+ string const name = countryFile.GetNameWithoutExt();
ASSERT(!name.empty(), ());
auto const it = m_info.find(name);
- if (it == m_info.cend())
+ if (it == m_info.cend() || it->second.empty())
return MwmId();
- return MwmId(it->second);
+ return MwmId(it->second.back());
}
-pair<MwmSet::MwmLock, bool> MwmSet::Register(TMwmFileName const & fileName)
+pair<MwmSet::MwmLock, bool> MwmSet::Register(LocalCountryFile const & localFile)
{
lock_guard<mutex> lock(m_lock);
- MwmId const id = GetMwmIdByFileNameImpl(fileName);
+ CountryFile const & countryFile = localFile.GetCountryFile();
+ MwmId const id = GetMwmIdByCountryFileImpl(countryFile);
if (!id.IsAlive())
- return RegisterImpl(fileName);
+ return RegisterImpl(localFile);
+
shared_ptr<MwmInfo> info = id.GetInfo();
- if (info->IsRegistered())
- LOG(LWARNING, ("Trying to add already registered mwm:", fileName));
- else
- info->SetStatus(MwmInfo::STATUS_UP_TO_DATE);
- return make_pair(GetLock(id), false);
+
+ // Deregister old mwm for the country.
+ if (info->GetVersion() < localFile.GetVersion())
+ {
+ DeregisterImpl(id);
+ return RegisterImpl(localFile);
+ }
+
+ string const name = countryFile.GetNameWithoutExt();
+ // Update the status of the mwm with the same version.
+ if (info->GetVersion() == localFile.GetVersion())
+ {
+ LOG(LWARNING, ("Trying to add already registered mwm:", name));
+ info->SetStatus(MwmInfo::STATUS_REGISTERED);
+ return make_pair(GetLock(id), false);
+ }
+
+ LOG(LWARNING, ("Trying to add too old (", localFile.GetVersion(), ") mwm (", name,
+ "), current version:", info->GetVersion()));
+ return make_pair(MwmLock(), false);
}
-pair<MwmSet::MwmLock, bool> MwmSet::RegisterImpl(TMwmFileName const & fileName)
+pair<MwmSet::MwmLock, bool> MwmSet::RegisterImpl(LocalCountryFile const & localFile)
{
shared_ptr<MwmInfo> info(new MwmInfo());
// This function can throw an exception for a bad mwm file.
- if (!GetVersion(fileName, *info))
+ if (!GetVersion(localFile, *info))
return make_pair(MwmLock(), false);
- info->SetStatus(MwmInfo::STATUS_UP_TO_DATE);
- info->m_fileName = fileName;
- m_info[fileName] = info;
+ info->SetStatus(MwmInfo::STATUS_REGISTERED);
+ info->m_file = localFile;
+ string const name = localFile.GetCountryFile().GetNameWithoutExt();
+ vector<shared_ptr<MwmInfo>> & infos = m_info[name];
+ infos.push_back(info);
return make_pair(GetLock(MwmId(info)), true);
}
@@ -133,26 +143,28 @@ bool MwmSet::DeregisterImpl(MwmId const & id)
if (!id.IsAlive())
return false;
shared_ptr<MwmInfo> const & info = id.GetInfo();
+
if (info->m_lockCount == 0)
{
info->SetStatus(MwmInfo::STATUS_DEREGISTERED);
- m_info.erase(info->m_fileName);
- OnMwmDeleted(info);
+ vector<shared_ptr<MwmInfo>> & infos = m_info[info->GetCountryName()];
+ infos.erase(remove(infos.begin(), infos.end(), info), infos.end());
+ OnMwmDeregistered(info->GetLocalFile());
return true;
}
info->SetStatus(MwmInfo::STATUS_MARKED_TO_DEREGISTER);
return false;
}
-bool MwmSet::Deregister(TMwmFileName const & fileName)
+bool MwmSet::Deregister(CountryFile const & countryFile)
{
lock_guard<mutex> lock(m_lock);
- return DeregisterImpl(fileName);
+ return DeregisterImpl(countryFile);
}
-bool MwmSet::DeregisterImpl(TMwmFileName const & fileName)
+bool MwmSet::DeregisterImpl(CountryFile const & countryFile)
{
- MwmId const id = GetMwmIdByFileNameImpl(fileName);
+ MwmId const id = GetMwmIdByCountryFileImpl(countryFile);
if (!id.IsAlive())
return false;
bool const deregistered = DeregisterImpl(id);
@@ -164,21 +176,24 @@ void MwmSet::DeregisterAll()
{
lock_guard<mutex> lock(m_lock);
- for (auto it = m_info.begin(); it != m_info.end();)
+ for (auto const & p : m_info)
{
- auto cur = it++;
- DeregisterImpl(MwmId(cur->second));
+ // Vector of shared pointers is copied here because an original
+ // vector will be modified by the body of the cycle.
+ vector<shared_ptr<MwmInfo>> infos = p.second;
+ for (shared_ptr<MwmInfo> info : infos)
+ DeregisterImpl(MwmId(info));
}
// Do not call ClearCache - it's under mutex lock.
ClearCacheImpl(m_cache.begin(), m_cache.end());
}
-bool MwmSet::IsLoaded(TMwmFileName const & fileName) const
+bool MwmSet::IsLoaded(CountryFile const & countryFile) const
{
lock_guard<mutex> lock(m_lock);
- MwmId const id = GetMwmIdByFileNameImpl(fileName + DATA_FILE_EXTENSION);
+ MwmId const id = GetMwmIdByCountryFileImpl(countryFile);
return id.IsAlive() && id.GetInfo()->IsRegistered();
}
@@ -188,7 +203,10 @@ void MwmSet::GetMwmsInfo(vector<shared_ptr<MwmInfo>> & info) const
info.clear();
info.reserve(m_info.size());
for (auto const & p : m_info)
- info.push_back(p.second);
+ {
+ if (!p.second.empty())
+ info.push_back(p.second.back());
+ }
}
MwmSet::TMwmValueBasePtr MwmSet::LockValue(MwmId const & id)
@@ -216,7 +234,7 @@ MwmSet::TMwmValueBasePtr MwmSet::LockValueImpl(MwmId const & id)
return result;
}
}
- return CreateValue(info->m_fileName);
+ return CreateValue(info->GetLocalFile());
}
void MwmSet::UnlockValue(MwmId const & id, TMwmValueBasePtr p)
@@ -233,22 +251,10 @@ void MwmSet::UnlockValueImpl(MwmId const & id, TMwmValueBasePtr p)
return;
shared_ptr<MwmInfo> const & info = id.GetInfo();
- CHECK_GREATER(info->m_lockCount, 0, ());
+ ASSERT_GREATER(info->m_lockCount, 0, ());
--info->m_lockCount;
- if (info->m_lockCount == 0)
- {
- switch (info->GetStatus())
- {
- case MwmInfo::STATUS_MARKED_TO_DEREGISTER:
- CHECK(DeregisterImpl(id), ());
- break;
- case MwmInfo::STATUS_PENDING_UPDATE:
- OnMwmReadyForUpdate(info);
- break;
- default:
- break;
- }
- }
+ if (info->m_lockCount == 0 && info->GetStatus() == MwmInfo::STATUS_MARKED_TO_DEREGISTER)
+ VERIFY(DeregisterImpl(id), ());
if (info->IsUpToDate())
{
@@ -267,20 +273,20 @@ void MwmSet::ClearCache()
ClearCacheImpl(m_cache.begin(), m_cache.end());
}
-MwmSet::MwmId MwmSet::GetMwmIdByFileName(TMwmFileName const & fileName) const
+MwmSet::MwmId MwmSet::GetMwmIdByCountryFile(CountryFile const & countryFile) const
{
lock_guard<mutex> lock(m_lock);
- MwmId const id = GetMwmIdByFileNameImpl(fileName);
- ASSERT(id.IsAlive(), ("Can't get an mwm's (", fileName, ") identifier."));
+ MwmId const id = GetMwmIdByCountryFileImpl(countryFile);
+ ASSERT(id.IsAlive(), ("Can't get an mwm's (", countryFile.GetNameWithoutExt(), ") identifier."));
return id;
}
-MwmSet::MwmLock MwmSet::GetMwmLockByFileName(TMwmFileName const & fileName)
+MwmSet::MwmLock MwmSet::GetMwmLockByCountryFile(CountryFile const & countryFile)
{
lock_guard<mutex> lock(m_lock);
- MwmId const id = GetMwmIdByFileNameImpl(fileName);
+ MwmId const id = GetMwmIdByCountryFileImpl(countryFile);
TMwmValueBasePtr value(nullptr);
if (id.IsAlive())
value = LockValueImpl(id);