Skip to content

Commit

Permalink
Moving ReadyCallback with passing owner ship to routing_callbacks.hpp.
Browse files Browse the repository at this point in the history
  • Loading branch information
bykoianko authored and tatiana-yan committed Jun 15, 2018
1 parent b9d632f commit 7ef88db
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 12 deletions.
4 changes: 2 additions & 2 deletions routing/async_router.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ map<string, string> PrepareStatisticsData(string const & routerName,

// ----------------------------------------------------------------------------------------------------------------------------

AsyncRouter::RouterDelegateProxy::RouterDelegateProxy(TReadyCallback const & onReady,
AsyncRouter::RouterDelegateProxy::RouterDelegateProxy(ReadyCallbackOwnership const & onReady,
PointCheckCallback const & onPointCheck,
ProgressCallback const & onProgress,
uint32_t timeoutSec)
Expand Down Expand Up @@ -130,7 +130,7 @@ void AsyncRouter::SetRouter(unique_ptr<IRouter> && router, unique_ptr<IOnlineFet
}

void AsyncRouter::CalculateRoute(Checkpoints const & checkpoints, m2::PointD const & direction,
bool adjustToPrevRoute, TReadyCallback const & readyCallback,
bool adjustToPrevRoute, ReadyCallbackOwnership const & readyCallback,
ProgressCallback const & progressCallback,
uint32_t timeoutSec)
{
Expand Down
14 changes: 4 additions & 10 deletions routing/async_router.hpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#pragma once

#include "routing/routing_callbacks.hpp"
#include "routing/checkpoints.hpp"
#include "routing/online_absent_fetcher.hpp"
#include "routing/route.hpp"
#include "routing/router.hpp"
#include "routing/router_delegate.hpp"
#include "routing/routing_callbacks.hpp"

#include "base/thread.hpp"

Expand All @@ -23,12 +23,6 @@ namespace routing
class AsyncRouter final
{
public:
/// Callback takes ownership of passed route.
using TReadyCallback = function<void(Route &, RouterResultCode)>;

/// Callback on routing statistics
// using TRoutingStatisticsCallback = function<void(map<string, string> const &)>;

/// AsyncRouter is a wrapper class to run routing routines in the different thread
AsyncRouter(RoutingStatisticsCallback const & routingStatisticsCallback,
PointCheckCallback const & pointCheckCallback);
Expand All @@ -49,7 +43,7 @@ class AsyncRouter final
/// @param progressCallback function to update the router progress
/// @param timeoutSec timeout to cancel routing. 0 is infinity.
void CalculateRoute(Checkpoints const & checkpoints, m2::PointD const & direction,
bool adjustToPrevRoute, TReadyCallback const & readyCallback,
bool adjustToPrevRoute, ReadyCallbackOwnership const & readyCallback,
ProgressCallback const & progressCallback,
uint32_t timeoutSec);

Expand Down Expand Up @@ -81,7 +75,7 @@ class AsyncRouter final
class RouterDelegateProxy
{
public:
RouterDelegateProxy(TReadyCallback const & onReady,
RouterDelegateProxy(ReadyCallbackOwnership const & onReady,
PointCheckCallback const & onPointCheck,
ProgressCallback const & onProgress,
uint32_t timeoutSec);
Expand All @@ -96,7 +90,7 @@ class AsyncRouter final
void OnPointCheck(m2::PointD const & pt);

mutex m_guard;
TReadyCallback const m_onReady;
ReadyCallbackOwnership const m_onReady;
PointCheckCallback const m_onPointCheck;
ProgressCallback const m_onProgress;
RouterDelegate m_delegate;
Expand Down
5 changes: 5 additions & 0 deletions routing/routing_callbacks.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,12 @@ enum class RouterResultCode

using CheckpointCallback = std::function<void(size_t passedCheckpointIdx)>;
using ProgressCallback = std::function<void(float)>;
// @TODO(bykoianko) ReadyCallback and ReadyCallbackOwnership callbacks should be gathered
// to one with the following signature:
// std::function<void(std::unique_ptr<Route>, RouterResultCode)>
// That means calling ReadyCallback means passing ownership of ready instance of Route.
using ReadyCallback = std::function<void(Route const &, RouterResultCode)>;
using ReadyCallbackOwnership = std::function<void(Route &, RouterResultCode)>;
using RouteCallback = std::function<void(Route const &)>;
using RoutingStatisticsCallback = std::function<void(std::map<std::string, std::string> const &)>;
using PointCheckCallback = std::function<void(m2::PointD const &)>;
Expand Down

0 comments on commit 7ef88db

Please sign in to comment.