forked from organicmaps/organicmaps
Using of local file checking API
This commit is contained in:
parent
c68603248c
commit
7eed4e572d
4 changed files with 24 additions and 15 deletions
|
@ -271,11 +271,16 @@ namespace integration
|
|||
void TestOnlineFetcher(m2::PointD const & startPoint, m2::PointD const & finalPoint,
|
||||
vector<string> const & expected, OsrmRouterComponents & routerComponents)
|
||||
{
|
||||
search::Engine * searchEngine(routerComponents.GetSearchEngine());
|
||||
routing::OnlineAbsentFetcher fetcher([&searchEngine](m2::PointD const & pt)
|
||||
{
|
||||
return searchEngine->GetCountryFile(pt);
|
||||
});
|
||||
auto countryFileGetter = [&routerComponents](m2::PointD const & p) -> string
|
||||
{
|
||||
return routerComponents.GetSearchEngine()->GetCountryFile(p);
|
||||
};
|
||||
auto localFileGetter = [&routerComponents](string const & countryFile) -> shared_ptr<LocalCountryFile>
|
||||
{
|
||||
//Always returns empty LocalFile
|
||||
return shared_ptr<LocalCountryFile>(new LocalCountryFile());
|
||||
};
|
||||
routing::OnlineAbsentFetcher fetcher(countryFileGetter, localFileGetter);
|
||||
fetcher.GenerateRequest(MercatorBounds::FromLatLon(startPoint.y, startPoint.x),
|
||||
MercatorBounds::FromLatLon(finalPoint.y, finalPoint.x));
|
||||
vector<string> absent;
|
||||
|
|
|
@ -2169,7 +2169,7 @@ void Framework::SetRouter(RouterType type)
|
|||
{
|
||||
router.reset(new OsrmRouter(&m_model.GetIndex(), countryFileGetter, localFileGetter,
|
||||
routingVisualizerFn));
|
||||
fetcher.reset(new OnlineAbsentFetcher(countryFileFn));
|
||||
fetcher.reset(new OnlineAbsentFetcher(countryFileGetter, localFileGetter));
|
||||
}
|
||||
|
||||
m_routingSession.SetRouter(move(router), move(fetcher), routingStatisticsFn);
|
||||
|
|
|
@ -3,13 +3,19 @@
|
|||
#include "defines.hpp"
|
||||
#include "online_cross_fetcher.hpp"
|
||||
|
||||
#include "platform/country_file.hpp"
|
||||
#include "platform/local_country_file.hpp"
|
||||
|
||||
using platform::CountryFile;
|
||||
using platform::LocalCountryFile;
|
||||
|
||||
namespace routing
|
||||
{
|
||||
void OnlineAbsentFetcher::GenerateRequest(const m2::PointD & startPoint,
|
||||
const m2::PointD & finalPoint)
|
||||
{
|
||||
// single mwm case
|
||||
if (m_countryFunction(startPoint) == m_countryFunction(finalPoint))
|
||||
if (m_countryFileFn(startPoint) == m_countryFileFn(finalPoint))
|
||||
return;
|
||||
unique_ptr<OnlineCrossFetcher> fetcher =
|
||||
make_unique<OnlineCrossFetcher>(OSRM_ONLINE_SERVER_URL, startPoint, finalPoint);
|
||||
|
@ -24,12 +30,9 @@ void OnlineAbsentFetcher::GetAbsentCountries(vector<string> & countries)
|
|||
m_fetcherThread.Join();
|
||||
for (auto point : static_cast<OnlineCrossFetcher *>(m_fetcherThread.GetRoutine())->GetMwmPoints())
|
||||
{
|
||||
string name = m_countryFunction(point);
|
||||
//TODO (ldragunov) rewrite when storage GetLocalCountryFile will be present.
|
||||
Platform & pl = GetPlatform();
|
||||
string const mwmName = name + DATA_FILE_EXTENSION;
|
||||
string const fPath = pl.WritablePathForFile(mwmName + ROUTING_FILE_EXTENSION);
|
||||
if (!pl.IsFileExistsByFullPath(fPath))
|
||||
string name = m_countryFileFn(point);
|
||||
auto localFile = m_countryLocalFileFn(name);
|
||||
if (!HasOptions(localFile->GetFiles(), TMapOptions::EMapWithCarRouting))
|
||||
{
|
||||
LOG(LINFO, ("Online recomends to download: ", name));
|
||||
countries.emplace_back(move(name));
|
||||
|
|
|
@ -14,12 +14,13 @@ namespace routing
|
|||
class OnlineAbsentFetcher
|
||||
{
|
||||
public:
|
||||
OnlineAbsentFetcher(TCountryFileFn const & fn) : m_countryFunction(fn) {}
|
||||
OnlineAbsentFetcher(TCountryFileFn const & countryFileFn, TCountryLocalFileFn const & countryLocalFileFn) : m_countryFileFn(countryFileFn), m_countryLocalFileFn(countryLocalFileFn) {}
|
||||
void GenerateRequest(m2::PointD const & startPoint, m2::PointD const & finalPoint);
|
||||
void GetAbsentCountries(vector<string> & countries);
|
||||
|
||||
private:
|
||||
TCountryFileFn const m_countryFunction;
|
||||
TCountryFileFn const m_countryFileFn;
|
||||
TCountryLocalFileFn const m_countryLocalFileFn;
|
||||
threads::Thread m_fetcherThread;
|
||||
};
|
||||
} // namespace routing
|
||||
|
|
Loading…
Add table
Reference in a new issue