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-06-16 18:15:09 +0300
committerAlex Zolotarev <alex@maps.me>2015-09-23 02:53:25 +0300
commit598e71858b63ef4e587efd932db41474f8f516a0 (patch)
tree19e39c1dd331579432c9b58e5e1e82c750842ac3 /indexer/index.cpp
parent9148053b3aa67aac443ade98e2ed2ae899419095 (diff)
Storage redesign.
Diffstat (limited to 'indexer/index.cpp')
-rw-r--r--indexer/index.cpp142
1 files changed, 18 insertions, 124 deletions
diff --git a/indexer/index.cpp b/indexer/index.cpp
index e27814dc74..12d0a02fe7 100644
--- a/indexer/index.cpp
+++ b/indexer/index.cpp
@@ -6,32 +6,27 @@
#include "coding/file_name_utils.hpp"
#include "coding/internal/file_data.hpp"
+using platform::CountryFile;
+using platform::LocalCountryFile;
//////////////////////////////////////////////////////////////////////////////////
// MwmValue implementation
//////////////////////////////////////////////////////////////////////////////////
-MwmValue::MwmValue(string const & name)
- : m_cont(GetPlatform().GetReader(name))
+MwmValue::MwmValue(LocalCountryFile const & localFile)
+ : m_cont(GetPlatform().GetCountryReader(localFile, TMapOptions::EMap)),
+ m_countryFile(localFile.GetCountryFile())
{
m_factory.Load(m_cont);
}
-string MwmValue::GetFileName() const
-{
- string s = m_cont.GetFileName();
- my::GetNameFromFullPath(s);
- my::GetNameWithoutExt(s);
- return s;
-}
-
//////////////////////////////////////////////////////////////////////////////////
// Index implementation
//////////////////////////////////////////////////////////////////////////////////
-bool Index::GetVersion(string const & name, MwmInfo & info) const
+bool Index::GetVersion(LocalCountryFile const & localFile, MwmInfo & info) const
{
- MwmValue value(name);
+ MwmValue value(localFile);
feature::DataHeader const & h = value.GetHeader();
if (!h.IsMWMSuitable())
@@ -47,9 +42,9 @@ bool Index::GetVersion(string const & name, MwmInfo & info) const
return true;
}
-MwmSet::TMwmValueBasePtr Index::CreateValue(string const & name) const
+MwmSet::TMwmValueBasePtr Index::CreateValue(LocalCountryFile const & localFile) const
{
- TMwmValueBasePtr p(new MwmValue(name));
+ TMwmValueBasePtr p(new MwmValue(localFile));
ASSERT(static_cast<MwmValue &>(*p.get()).GetHeader().IsMWMSuitable(), ());
return p;
}
@@ -63,124 +58,23 @@ Index::~Index()
Cleanup();
}
-namespace
+pair<MwmSet::MwmLock, bool> Index::RegisterMap(LocalCountryFile const & localFile)
{
- // Deletes map file denoted by @path and all temporary files related
- // to it.
- 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);
- }
-
- // Deletes all files related to @fileName and renames
- // @fileName.READY_FILE_EXTENSION to @fileName.
- void ReplaceFileWithReady(string const & fileName)
- {
- string const path = GetFullPath(fileName);
- DeleteMapFiles(path, false /* deleteReady */);
- CHECK(my::RenameFileX(path + READY_FILE_EXTENSION, path), (path));
- }
-}
-
-pair<MwmSet::MwmLock, bool> Index::RegisterMap(string const & fileName)
-{
- if (GetPlatform().IsFileExistsByFullPath(GetFullPath(fileName + READY_FILE_EXTENSION)))
- {
- pair<MwmSet::MwmLock, UpdateStatus> updateResult = UpdateMap(fileName);
- switch (updateResult.second)
- {
- case UPDATE_STATUS_OK:
- return make_pair(move(updateResult.first), true);
- case UPDATE_STATUS_BAD_FILE:
- return make_pair(move(updateResult.first), false);
- case UPDATE_STATUS_UPDATE_DELAYED:
- // Not dangerous, but it's strange when adding existing maps.
- ASSERT(false, ());
- return make_pair(move(updateResult.first), true);
- }
- }
-
- pair<MwmSet::MwmLock, bool> result = Register(fileName);
- if (result.second)
- m_observers.ForEach(&Observer::OnMapRegistered, fileName);
+ pair<MwmSet::MwmLock, bool> result = Register(localFile);
+ if (result.first.IsLocked() && result.second)
+ m_observers.ForEach(&Observer::OnMapRegistered, localFile);
return result;
}
-bool Index::DeleteMap(string const & fileName)
-{
- {
- lock_guard<mutex> lock(m_lock);
-
- if (!DeregisterImpl(fileName))
- return false;
-
- DeleteMapFiles(GetFullPath(fileName), true /* deleteReady */);
- }
- m_observers.ForEach(&Observer::OnMapDeleted, fileName);
- return true;
-}
+bool Index::DeregisterMap(CountryFile const & countryFile) { return Deregister(countryFile); }
bool Index::AddObserver(Observer & observer) { return m_observers.Add(observer); }
bool Index::RemoveObserver(Observer const & observer) { return m_observers.Remove(observer); }
-pair<MwmSet::MwmLock, Index::UpdateStatus> Index::UpdateMap(string const & fileName)
-{
- pair<MwmSet::MwmLock, UpdateStatus> result;
- result.second = UPDATE_STATUS_BAD_FILE;
-
- {
- lock_guard<mutex> lock(m_lock);
-
- MwmId const id = GetMwmIdByFileNameImpl(fileName);
- shared_ptr<MwmInfo> info = id.GetInfo();
- if (id.IsAlive() && info->m_lockCount > 0)
- {
- info->SetStatus(MwmInfo::STATUS_PENDING_UPDATE);
- result.first = GetLock(id);
- result.second = UPDATE_STATUS_UPDATE_DELAYED;
- }
- else
- {
- ReplaceFileWithReady(fileName);
- pair<MwmSet::MwmLock, bool> registerResult = RegisterImpl(fileName);
- if (registerResult.second)
- {
- result.first = move(registerResult.first);
- result.second = UPDATE_STATUS_OK;
- }
- }
- }
- if (result.second != UPDATE_STATUS_BAD_FILE)
- m_observers.ForEach(&Observer::OnMapUpdateIsReady, fileName);
- if (result.second == UPDATE_STATUS_OK)
- m_observers.ForEach(&Observer::OnMapUpdated, fileName);
- return result;
-}
-
-void Index::OnMwmDeleted(shared_ptr<MwmInfo> const & info)
-{
- string const & fileName = info->m_fileName;
- DeleteMapFiles(fileName, true /* deleteReady */);
- m_observers.ForEach(&Observer::OnMapDeleted, fileName);
-}
-
-void Index::OnMwmReadyForUpdate(shared_ptr<MwmInfo> const & info)
+void Index::OnMwmDeregistered(LocalCountryFile const & localFile)
{
- ClearCache(MwmId(info));
- ReplaceFileWithReady(info->m_fileName);
- info->SetStatus(MwmInfo::STATUS_UP_TO_DATE);
- m_observers.ForEach(&Observer::OnMapUpdated, info->m_fileName);
+ m_observers.ForEach(&Observer::OnMapDeregistered, localFile);
}
//////////////////////////////////////////////////////////////////////////////////
@@ -194,11 +88,11 @@ Index::FeaturesLoaderGuard::FeaturesLoaderGuard(Index const & parent, MwmId id)
{
}
-string Index::FeaturesLoaderGuard::GetFileName() const
+string Index::FeaturesLoaderGuard::GetCountryFileName() const
{
if (!m_lock.IsLocked())
return string();
- return m_lock.GetValue<MwmValue>()->GetFileName();
+ return m_lock.GetValue<MwmValue>()->GetCountryFile().GetNameWithoutExt();
}
bool Index::FeaturesLoaderGuard::IsWorld() const