diff options
-rw-r--r-- | map/framework.hpp | 7 | ||||
-rw-r--r-- | routing/async_router.hpp | 2 | ||||
-rw-r--r-- | routing/online_absent_fetcher.hpp | 10 | ||||
-rw-r--r-- | routing/osrm_router.cpp | 4 | ||||
-rw-r--r-- | routing/router_delegate.cpp | 20 | ||||
-rw-r--r-- | routing/router_delegate.hpp | 34 | ||||
-rw-r--r-- | routing/routing_tests/async_router_test.cpp | 17 |
7 files changed, 49 insertions, 45 deletions
diff --git a/map/framework.hpp b/map/framework.hpp index 2b4249a999..eac02803b8 100644 --- a/map/framework.hpp +++ b/map/framework.hpp @@ -554,10 +554,11 @@ public: BookmarkManager & GetBookmarkManager() { return m_bmManager; } public: - using TRouteBuildingCallback = - function<void(routing::IRouter::ResultCode, vector<storage::TIndex> const &, - vector<storage::TIndex> const &)>; + using TRouteBuildingCallback = function<void(routing::IRouter::ResultCode, + vector<storage::TIndex> const &, + vector<storage::TIndex> const &)>; using TRouteProgressCallback = function<void(float)>; + /// @name Routing mode //@{ void SetRouter(routing::RouterType type); diff --git a/routing/async_router.hpp b/routing/async_router.hpp index df06936f29..db5adbe623 100644 --- a/routing/async_router.hpp +++ b/routing/async_router.hpp @@ -50,7 +50,7 @@ public: virtual void ClearState(); /// Wait routing process. For testing use. - void WaitRouting() { lock_guard<mutex> routingGuard(m_routingMutex); } + void WaitRoutingForTesting() { lock_guard<mutex> routingGuard(m_routingMutex); } private: /// This function is called in async mode diff --git a/routing/online_absent_fetcher.hpp b/routing/online_absent_fetcher.hpp index 8396ee2306..80fdcaa9b2 100644 --- a/routing/online_absent_fetcher.hpp +++ b/routing/online_absent_fetcher.hpp @@ -18,9 +18,9 @@ using TCountryLocalFileFn = function<shared_ptr<platform::LocalCountryFile>(stri class IOnlineFetcher { public: + virtual ~IOnlineFetcher() = default; virtual void GenerateRequest(m2::PointD const & startPoint, m2::PointD const & finalPoint) = 0; virtual void GetAbsentCountries(vector<string> & countries) = 0; - virtual ~IOnlineFetcher() {} }; /*! @@ -30,7 +30,13 @@ public: class OnlineAbsentCountriesFetcher : public IOnlineFetcher { public: - OnlineAbsentCountriesFetcher(TCountryFileFn const & countryFileFn, TCountryLocalFileFn const & countryLocalFileFn) : m_countryFileFn(countryFileFn), m_countryLocalFileFn(countryLocalFileFn) {} + OnlineAbsentCountriesFetcher(TCountryFileFn const & countryFileFn, + TCountryLocalFileFn const & countryLocalFileFn) + : m_countryFileFn(countryFileFn), m_countryLocalFileFn(countryLocalFileFn) + { + } + + // IOnlineFetcher overrides: void GenerateRequest(m2::PointD const & startPoint, m2::PointD const & finalPoint) override; void GetAbsentCountries(vector<string> & countries) override; diff --git a/routing/osrm_router.cpp b/routing/osrm_router.cpp index b65f922784..410f038476 100644 --- a/routing/osrm_router.cpp +++ b/routing/osrm_router.cpp @@ -621,8 +621,8 @@ OsrmRouter::ResultCode OsrmRouter::CalculateRoute(m2::PointD const & startPoint, { LOG(LINFO, ("Multiple mwm routing case")); TCheckedPath finalPath; - ResultCode code = - CalculateCrossMwmPath(startTask, m_cachedTargets, m_indexManager, delegate, finalPath); + ResultCode code = CalculateCrossMwmPath(startTask, m_cachedTargets, m_indexManager, delegate, + finalPath); timer.Reset(); delegate.OnProgress(50.0f); diff --git a/routing/router_delegate.cpp b/routing/router_delegate.cpp index 6914b546e4..42b25209dc 100644 --- a/routing/router_delegate.cpp +++ b/routing/router_delegate.cpp @@ -5,29 +5,23 @@ namespace routing namespace { void DefaultProgressFn(float /* progress */) {} -void DefaultPointFn(m2::PointD /* point */) {} +void DefaultPointFn(m2::PointD const & /* point */) {} } // namespace RouterDelegate::RouterDelegate() { - m_progressFn = DefaultProgressFn; - m_pointFn = DefaultPointFn; + m_progressCallback = DefaultProgressFn; + m_pointCallback = DefaultPointFn; } -void RouterDelegate::SetProgressCallback(TProgressCallback const & progressFn) +void RouterDelegate::SetProgressCallback(TProgressCallback const & progressCallback) { - if (progressFn != nullptr) - m_progressFn = progressFn; - else - m_progressFn = DefaultProgressFn; + m_progressCallback = (progressCallback) ? progressCallback : DefaultProgressFn; } -void RouterDelegate::SetPointCheckCallback(TPointCheckCallback const & pointFn) +void RouterDelegate::SetPointCheckCallback(TPointCheckCallback const & pointCallback) { - if (pointFn != nullptr) - m_pointFn = pointFn; - else - m_pointFn = DefaultPointFn; + m_pointCallback = (pointCallback) ? pointCallback : DefaultPointFn; } bool TimeoutCancellable::IsCancelled() const diff --git a/routing/router_delegate.hpp b/routing/router_delegate.hpp index 2b21a982de..ba82340ed4 100644 --- a/routing/router_delegate.hpp +++ b/routing/router_delegate.hpp @@ -9,18 +9,20 @@ namespace routing { - class TimeoutCancellable : public my::Cancellable { - public: - TimeoutCancellable() : m_timeoutSec(0) {} - - /// Sets timeout in seconds to autamaticly calcel. 0 is infinity value. - void SetTimeout(uint32_t); - bool IsCancelled() const override; - private: - my::Timer m_timer; - uint32_t m_timeoutSec; +public: + TimeoutCancellable() : m_timeoutSec(0) {} + + /// Sets timeout before cancellation. 0 means an infinite timeout. + void SetTimeout(uint32_t timeoutSec); + + // Cancellable overrides: + bool IsCancelled() const override; + +private: + my::Timer m_timer; + uint32_t m_timeoutSec; }; class RouterDelegate : public TimeoutCancellable @@ -32,15 +34,15 @@ public: RouterDelegate(); /// Set routing progress. Waits current progress status from 0 to 100. - void OnProgress(float progress) const { m_progressFn(progress); } - void OnPointCheck(m2::PointD const & point) const { m_pointFn(point); } + void OnProgress(float progress) const { m_progressCallback(progress); } + void OnPointCheck(m2::PointD const & point) const { m_pointCallback(point); } - void SetProgressCallback(TProgressCallback const & progressFn); - void SetPointCheckCallback(TPointCheckCallback const & pointFn); + void SetProgressCallback(TProgressCallback const & progressCallback); + void SetPointCheckCallback(TPointCheckCallback const & pointCallback); private: - TProgressCallback m_progressFn; - TPointCheckCallback m_pointFn; + TProgressCallback m_progressCallback; + TPointCheckCallback m_pointCallback; }; } // nomespace routing diff --git a/routing/routing_tests/async_router_test.cpp b/routing/routing_tests/async_router_test.cpp index 9b4109d58a..f6920c725c 100644 --- a/routing/routing_tests/async_router_test.cpp +++ b/routing/routing_tests/async_router_test.cpp @@ -24,9 +24,9 @@ class DummyRouter : public IRouter public: DummyRouter(ResultCode code, vector<string> const & absent) : m_result(code), m_absent(absent) {} - + + // IRouter overrides: string GetName() const override { return "Dummy"; } - ResultCode CalculateRoute(m2::PointD const & startPoint, m2::PointD const & startDirection, m2::PointD const & finalPoint, RouterDelegate const & delegate, Route & route) override @@ -47,6 +47,8 @@ class DummyFetcher : public IOnlineFetcher public: DummyFetcher(vector<string> const & absent) : m_absent(absent) {} + + // IOnlineFetcher overrides: void GenerateRequest(m2::PointD const & startPoint, m2::PointD const & finalPoint) override {} void GetAbsentCountries(vector<string> & countries) override { countries = m_absent; } }; @@ -57,6 +59,7 @@ struct DummyResultCallback { vector<ResultCode> m_codes; vector<vector<string>> m_absent; + void operator()(Route & route, ResultCode code) { m_codes.push_back(code); @@ -77,10 +80,9 @@ UNIT_TEST(NeedMoreMapsSignalTest) // Wait async process start. while (resultCallback.m_codes.empty()) - { - } + ; - async.WaitRouting(); + async.WaitRoutingForTesting(); TEST_EQUAL(resultCallback.m_codes.size(), 2, ()); TEST_EQUAL(resultCallback.m_codes[0], ResultCode::NoError, ()); @@ -102,10 +104,9 @@ UNIT_TEST(StandartAsyncFogTest) // Wait async process start. while (resultCallback.m_codes.empty()) - { - } + ; - async.WaitRouting(); + async.WaitRoutingForTesting(); TEST_EQUAL(resultCallback.m_codes.size(), 1, ()); TEST_EQUAL(resultCallback.m_codes[0], ResultCode::NoError, ()); |