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:
authorLev Dragunov <l.dragunov@corp.mail.ru>2015-10-14 13:27:13 +0300
committerLev Dragunov <l.dragunov@corp.mail.ru>2015-10-14 13:53:45 +0300
commitfaf802173ca06121760a46751476f18e3359c4b5 (patch)
tree7954ab33c2b88395b3eedc8923f80bacad0b352e /routing
parent7af71e98efa11e5d8bfc61041d1e90594ccb84df (diff)
Close m_container on cross_mwm_routing.
Diffstat (limited to 'routing')
-rw-r--r--routing/osrm_router.cpp4
-rw-r--r--routing/routing_mapping.cpp24
-rw-r--r--routing/routing_mapping.hpp9
-rw-r--r--routing/routing_tests/routing_mapping_test.cpp4
4 files changed, 26 insertions, 15 deletions
diff --git a/routing/osrm_router.cpp b/routing/osrm_router.cpp
index ecbffdbdc0..24174242c6 100644
--- a/routing/osrm_router.cpp
+++ b/routing/osrm_router.cpp
@@ -370,13 +370,13 @@ private:
bool OsrmRouter::CheckRoutingAbility(m2::PointD const & startPoint, m2::PointD const & finalPoint,
TCountryFileFn const & countryFileFn, Index * index)
{
- RoutingIndexManager manager(countryFileFn, index);
+ RoutingIndexManager manager(countryFileFn, *index);
return manager.GetMappingByPoint(startPoint)->IsValid() &&
manager.GetMappingByPoint(finalPoint)->IsValid();
}
OsrmRouter::OsrmRouter(Index * index, TCountryFileFn const & countryFileFn)
- : m_pIndex(index), m_indexManager(countryFileFn, index)
+ : m_pIndex(index), m_indexManager(countryFileFn, *index)
{
}
diff --git a/routing/routing_mapping.cpp b/routing/routing_mapping.cpp
index deb422a7a4..228857551d 100644
--- a/routing/routing_mapping.cpp
+++ b/routing/routing_mapping.cpp
@@ -47,17 +47,15 @@ bool CheckMwmConsistency(LocalCountryFile const & localFile)
namespace routing
{
-RoutingMapping::RoutingMapping(string const & countryFile, MwmSet * pIndex)
+RoutingMapping::RoutingMapping(string const & countryFile, MwmSet & index)
: m_mapCounter(0),
m_facadeCounter(0),
m_crossContextLoaded(0),
m_countryFile(countryFile),
m_error(IRouter::ResultCode::RouteFileNotExist),
- m_pIndex(pIndex)
+ m_pIndex(&index)
{
- CHECK(m_pIndex != nullptr, ());
-
- m_handle = pIndex->GetMwmHandleByCountryFile(CountryFile(countryFile));
+ m_handle = index.GetMwmHandleByCountryFile(CountryFile(countryFile));
if (!m_handle.IsAlive())
return;
@@ -86,13 +84,19 @@ void RoutingMapping::LoadFileIfNeeded()
{
ASSERT(m_pIndex != nullptr, ());
if (!m_handle.IsAlive() && m_mwmId.IsAlive())
+ {
m_handle = m_pIndex->GetMwmHandleById(m_mwmId);
+ m_container.Open(m_mwmId.GetInfo()->GetLocalFile().GetPath(MapOptions::CarRouting));
+ }
}
void RoutingMapping::FreeFileIfPossible()
{
- if (m_handle.IsAlive() && m_mapCounter == 0 && m_facadeCounter == 0)
+ if (m_mapCounter == 0 && m_facadeCounter == 0 && m_handle.IsAlive())
+ {
m_handle = MwmSet::MwmHandle();
+ m_container.Close();
+ }
}
RoutingMapping::~RoutingMapping()
@@ -106,6 +110,8 @@ RoutingMapping::~RoutingMapping()
void RoutingMapping::Map()
{
LoadFileIfNeeded();
+ if (!m_handle.IsAlive())
+ return;
++m_mapCounter;
if (!m_segMapping.IsMapped())
{
@@ -127,6 +133,8 @@ void RoutingMapping::LoadFacade()
if (!m_facadeCounter)
{
LoadFileIfNeeded();
+ if (!m_handle.IsAlive())
+ return;
m_dataFacade.Load(m_container);
}
++m_facadeCounter;
@@ -149,6 +157,9 @@ void RoutingMapping::LoadCrossContext()
LoadFileIfNeeded();
+ if (!m_handle.IsAlive())
+ return;
+
if (m_container.IsExist(ROUTING_CROSS_CONTEXT_TAG))
{
m_crossContext.Load(m_container.GetReader(ROUTING_CROSS_CONTEXT_TAG));
@@ -160,6 +171,7 @@ void RoutingMapping::FreeCrossContext()
{
m_crossContextLoaded = false;
m_crossContext = CrossRoutingContextReader();
+ FreeFileIfPossible();
}
TRoutingMappingPtr RoutingIndexManager::GetMappingByPoint(m2::PointD const & point)
diff --git a/routing/routing_mapping.hpp b/routing/routing_mapping.hpp
index 844a6c818b..5e46cf48aa 100644
--- a/routing/routing_mapping.hpp
+++ b/routing/routing_mapping.hpp
@@ -27,7 +27,7 @@ struct RoutingMapping
/// @postcondition IsValid() == false.
RoutingMapping() : m_pIndex(nullptr) {}
/// @param countryFile Country file name without extension.
- RoutingMapping(string const & countryFile, MwmSet * pIndex);
+ RoutingMapping(string const & countryFile, MwmSet & index);
~RoutingMapping();
void Map();
@@ -39,7 +39,7 @@ struct RoutingMapping
void LoadCrossContext();
void FreeCrossContext();
- bool IsValid() const { return m_mwmId.IsAlive() && m_error == IRouter::ResultCode::NoError; }
+ bool IsValid() const { return m_error == IRouter::ResultCode::NoError && m_mwmId.IsAlive(); }
IRouter::ResultCode GetError() const { return m_error; }
@@ -97,10 +97,9 @@ public:
class RoutingIndexManager
{
public:
- RoutingIndexManager(TCountryFileFn const & countryFileFn, MwmSet * index)
+ RoutingIndexManager(TCountryFileFn const & countryFileFn, MwmSet & index)
: m_countryFileFn(countryFileFn), m_index(index)
{
- ASSERT(index, ());
}
TRoutingMappingPtr GetMappingByPoint(m2::PointD const & point);
@@ -118,7 +117,7 @@ public:
private:
TCountryFileFn m_countryFileFn;
unordered_map<string, TRoutingMappingPtr> m_mapping;
- MwmSet * m_index;
+ MwmSet & m_index;
};
} // namespace routing
diff --git a/routing/routing_tests/routing_mapping_test.cpp b/routing/routing_tests/routing_mapping_test.cpp
index 7d4c977250..5f0303925d 100644
--- a/routing/routing_tests/routing_mapping_test.cpp
+++ b/routing/routing_tests/routing_mapping_test.cpp
@@ -70,7 +70,7 @@ UNIT_TEST(RoutingMappingCountryFileLockTest)
{
LocalFileGenerator generator("1TestCountry");
{
- RoutingMapping testMapping(generator.GetCountryName(), (&generator.GetMwmSet()));
+ RoutingMapping testMapping(generator.GetCountryName(), (generator.GetMwmSet()));
TEST(testMapping.IsValid(), ());
TEST_EQUAL(generator.GetNumRefs(), 1, ());
}
@@ -83,7 +83,7 @@ UNIT_TEST(IndexManagerLockManagementTest)
string const fileName("1TestCountry");
LocalFileGenerator generator(fileName);
RoutingIndexManager manager([&fileName](m2::PointD const & q) { return fileName; },
- &generator.GetMwmSet());
+ generator.GetMwmSet());
{
auto testMapping = manager.GetMappingByName(fileName);
TEST(testMapping->IsValid(), ());