Passed ResultT down to engine plugins, so now they can form replies in different formats.

This commit is contained in:
Denis Chaplygin
2019-08-02 17:40:55 +03:00
parent f6f86b2a52
commit 75aadb0f3f
32 changed files with 136 additions and 99 deletions
+13 -12
View File
@@ -112,16 +112,17 @@ void filterCandidates(const std::vector<util::Coordinate> &coordinates,
Status MatchPlugin::HandleRequest(const RoutingAlgorithmsInterface &algorithms,
const api::MatchParameters &parameters,
util::json::Object &json_result) const
osrm::engine::api::ResultT &result) const
{
auto& json_result = result.get<util::json::Object>();
if (!algorithms.HasMapMatching())
{
return Error("NotImplemented",
"Map matching is not implemented for the chosen search algorithm.",
json_result);
result);
}
if (!CheckAlgorithms(parameters, algorithms, json_result))
if (!CheckAlgorithms(parameters, algorithms, result))
return Status::Error;
const auto &facade = algorithms.GetFacade();
@@ -132,12 +133,12 @@ Status MatchPlugin::HandleRequest(const RoutingAlgorithmsInterface &algorithms,
if (max_locations_map_matching > 0 &&
static_cast<int>(parameters.coordinates.size()) > max_locations_map_matching)
{
return Error("TooBig", "Too many trace coordinates", json_result);
return Error("TooBig", "Too many trace coordinates", result);
}
if (!CheckAllCoordinates(parameters.coordinates))
{
return Error("InvalidValue", "Invalid coordinate value.", json_result);
return Error("InvalidValue", "Invalid coordinate value.", result);
}
if (max_radius_map_matching > 0 && std::any_of(parameters.radiuses.begin(),
@@ -148,7 +149,7 @@ Status MatchPlugin::HandleRequest(const RoutingAlgorithmsInterface &algorithms,
return *radius > max_radius_map_matching;
}))
{
return Error("TooBig", "Radius search size is too large for map matching.", json_result);
return Error("TooBig", "Radius search size is too large for map matching.", result);
}
// Check for same or increasing timestamps. Impl. note: Incontrast to `sort(first,
@@ -159,7 +160,7 @@ Status MatchPlugin::HandleRequest(const RoutingAlgorithmsInterface &algorithms,
if (!time_increases_monotonically)
{
return Error(
"InvalidValue", "Timestamps need to be monotonically increasing.", json_result);
"InvalidValue", "Timestamps need to be monotonically increasing.", result);
}
SubMatchingList sub_matchings;
@@ -182,7 +183,7 @@ Status MatchPlugin::HandleRequest(const RoutingAlgorithmsInterface &algorithms,
{
return Error("InvalidValue",
"First and last coordinates must be specified as waypoints.",
json_result);
result);
}
// assuming radius is the standard deviation of a normal distribution
@@ -225,7 +226,7 @@ Status MatchPlugin::HandleRequest(const RoutingAlgorithmsInterface &algorithms,
{
return Error("NoSegment",
std::string("Could not find a matching segment for any coordinate."),
json_result);
result);
}
// call the actual map matching
@@ -238,13 +239,13 @@ Status MatchPlugin::HandleRequest(const RoutingAlgorithmsInterface &algorithms,
if (sub_matchings.size() == 0)
{
return Error("NoMatch", "Could not match the trace.", json_result);
return Error("NoMatch", "Could not match the trace.", result);
}
// trace was split, we don't support the waypoints parameter across multiple match objects
if (sub_matchings.size() > 1 && !parameters.waypoints.empty())
{
return Error("NoMatch", "Could not match the trace with the given waypoints.", json_result);
return Error("NoMatch", "Could not match the trace with the given waypoints.", result);
}
// Error: Check if user-supplied waypoints can be found in the resulting matches
@@ -261,7 +262,7 @@ Status MatchPlugin::HandleRequest(const RoutingAlgorithmsInterface &algorithms,
if (!tidied_waypoints.empty())
{
return Error(
"NoMatch", "Requested waypoint parameter could not be matched.", json_result);
"NoMatch", "Requested waypoint parameter could not be matched.", result);
}
}
// we haven't errored yet, only allow leg collapsing if it was originally requested
+7 -6
View File
@@ -21,11 +21,12 @@ NearestPlugin::NearestPlugin(const int max_results_) : max_results{max_results_}
Status NearestPlugin::HandleRequest(const RoutingAlgorithmsInterface &algorithms,
const api::NearestParameters &params,
util::json::Object &json_result) const
osrm::engine::api::ResultT &result) const
{
BOOST_ASSERT(params.IsValid());
if (!CheckAlgorithms(params, algorithms, json_result))
auto& json_result = result.get<util::json::Object>();
if (!CheckAlgorithms(params, algorithms, result))
return Status::Error;
const auto &facade = algorithms.GetFacade();
@@ -36,22 +37,22 @@ Status NearestPlugin::HandleRequest(const RoutingAlgorithmsInterface &algorithms
return Error("TooBig",
"Number of results " + std::to_string(params.number_of_results) +
" is higher than current maximum (" + std::to_string(max_results) + ")",
json_result);
result);
}
if (!CheckAllCoordinates(params.coordinates))
return Error("InvalidOptions", "Coordinates are invalid", json_result);
return Error("InvalidOptions", "Coordinates are invalid", result);
if (params.coordinates.size() != 1)
{
return Error("InvalidOptions", "Only one input coordinate is supported", json_result);
return Error("InvalidOptions", "Only one input coordinate is supported", result);
}
auto phantom_nodes = GetPhantomNodes(facade, params, params.number_of_results);
if (phantom_nodes.front().size() == 0)
{
return Error("NoSegment", "Could not find a matching segments for coordinate", json_result);
return Error("NoSegment", "Could not find a matching segments for coordinate", result);
}
BOOST_ASSERT(phantom_nodes.front().size() > 0);
+3 -2
View File
@@ -31,8 +31,9 @@ TablePlugin::TablePlugin(const int max_locations_distance_table)
Status TablePlugin::HandleRequest(const RoutingAlgorithmsInterface &algorithms,
const api::TableParameters &params,
util::json::Object &result) const
osrm::engine::api::ResultT &result) const
{
auto& json_result = result.get<util::json::Object>();
if (!algorithms.HasManyToManySearch())
{
return Error("NotImplemented",
@@ -154,7 +155,7 @@ Status TablePlugin::HandleRequest(const RoutingAlgorithmsInterface &algorithms,
}
api::TableAPI table_api{facade, params};
table_api.MakeResponse(result_tables_pair, snapped_phantoms, estimated_pairs, result);
table_api.MakeResponse(result_tables_pair, snapped_phantoms, estimated_pairs, json_result);
return Status::Ok;
}
+2 -1
View File
@@ -665,10 +665,11 @@ void encodeVectorTile(const DataFacadeBase &facade,
Status TilePlugin::HandleRequest(const RoutingAlgorithmsInterface &algorithms,
const api::TileParameters &parameters,
std::string &pbf_buffer) const
osrm::engine::api::ResultT &result) const
{
BOOST_ASSERT(parameters.IsValid());
auto& pbf_buffer = result.get<std::string>();
const auto &facade = algorithms.GetFacade();
auto edges = getEdges(facade, parameters.x, parameters.y, parameters.z);
auto segregated_nodes = getSegregatedNodes(facade, edges);
+11 -10
View File
@@ -144,19 +144,20 @@ void ManipulateTableForFSE(const std::size_t source_id,
Status TripPlugin::HandleRequest(const RoutingAlgorithmsInterface &algorithms,
const api::TripParameters &parameters,
util::json::Object &json_result) const
osrm::engine::api::ResultT &result) const
{
auto& json_result = result.get<util::json::Object>();
if (!algorithms.HasShortestPathSearch())
{
return Error("NotImplemented",
"Shortest path search is not implemented for the chosen search algorithm.",
json_result);
result);
}
if (!algorithms.HasManyToManySearch())
{
return Error("NotImplemented",
"Many to many search is not implemented for the chosen search algorithm.",
json_result);
result);
}
BOOST_ASSERT(parameters.IsValid());
@@ -177,21 +178,21 @@ Status TripPlugin::HandleRequest(const RoutingAlgorithmsInterface &algorithms,
bool fixed_end = (destination_id == number_of_locations - 1);
if (!IsSupportedParameterCombination(fixed_start, fixed_end, parameters.roundtrip))
{
return Error("NotImplemented", "This request is not supported", json_result);
return Error("NotImplemented", "This request is not supported", result);
}
// enforce maximum number of locations for performance reasons
if (max_locations_trip > 0 && static_cast<int>(number_of_locations) > max_locations_trip)
{
return Error("TooBig", "Too many trip coordinates", json_result);
return Error("TooBig", "Too many trip coordinates", result);
}
if (!CheckAllCoordinates(parameters.coordinates))
{
return Error("InvalidValue", "Invalid coordinate value.", json_result);
return Error("InvalidValue", "Invalid coordinate value.", result);
}
if (!CheckAlgorithms(parameters, algorithms, json_result))
if (!CheckAlgorithms(parameters, algorithms, result))
return Status::Error;
const auto &facade = algorithms.GetFacade();
@@ -201,14 +202,14 @@ Status TripPlugin::HandleRequest(const RoutingAlgorithmsInterface &algorithms,
return Error("NoSegment",
std::string("Could not find a matching segment for coordinate ") +
std::to_string(phantom_node_pairs.size()),
json_result);
result);
}
BOOST_ASSERT(phantom_node_pairs.size() == number_of_locations);
if (fixed_start && fixed_end && (source_id >= parameters.coordinates.size() ||
destination_id >= parameters.coordinates.size()))
{
return Error("InvalidValue", "Invalid source or destination value.", json_result);
return Error("InvalidValue", "Invalid source or destination value.", result);
}
auto snapped_phantoms = SnapPhantomNodes(phantom_node_pairs);
@@ -231,7 +232,7 @@ Status TripPlugin::HandleRequest(const RoutingAlgorithmsInterface &algorithms,
if (!IsStronglyConnectedComponent(result_duration_table))
{
return Error("NoTrips", "No trip visiting all destinations possible.", json_result);
return Error("NoTrips", "No trip visiting all destinations possible.", result);
}
if (fixed_start && fixed_end)
+13 -11
View File
@@ -28,16 +28,18 @@ ViaRoutePlugin::ViaRoutePlugin(int max_locations_viaroute, int max_alternatives)
Status ViaRoutePlugin::HandleRequest(const RoutingAlgorithmsInterface &algorithms,
const api::RouteParameters &route_parameters,
util::json::Object &json_result) const
osrm::engine::api::ResultT &result) const
{
BOOST_ASSERT(route_parameters.IsValid());
auto& json_result = result.get<util::json::Object>();
if (!algorithms.HasShortestPathSearch() && route_parameters.coordinates.size() > 2)
{
return Error("NotImplemented",
"Shortest path search is not implemented for the chosen search algorithm. "
"Only two coordinates supported.",
json_result);
result);
}
if (!algorithms.HasDirectShortestPathSearch() && !algorithms.HasShortestPathSearch())
@@ -45,7 +47,7 @@ Status ViaRoutePlugin::HandleRequest(const RoutingAlgorithmsInterface &algorithm
return Error(
"NotImplemented",
"Direct shortest path search is not implemented for the chosen search algorithm.",
json_result);
result);
}
if (max_locations_viaroute > 0 &&
@@ -55,7 +57,7 @@ Status ViaRoutePlugin::HandleRequest(const RoutingAlgorithmsInterface &algorithm
"Number of entries " + std::to_string(route_parameters.coordinates.size()) +
" is higher than current maximum (" +
std::to_string(max_locations_viaroute) + ")",
json_result);
result);
}
// Takes care of alternatives=n and alternatives=true
@@ -65,12 +67,12 @@ Status ViaRoutePlugin::HandleRequest(const RoutingAlgorithmsInterface &algorithm
return Error("TooBig",
"Requested number of alternatives is higher than current maximum (" +
std::to_string(max_alternatives) + ")",
json_result);
result);
}
if (!CheckAllCoordinates(route_parameters.coordinates))
{
return Error("InvalidValue", "Invalid coordinate value.", json_result);
return Error("InvalidValue", "Invalid coordinate value.", result);
}
// Error: first and last points should be waypoints
@@ -80,10 +82,10 @@ Status ViaRoutePlugin::HandleRequest(const RoutingAlgorithmsInterface &algorithm
{
return Error("InvalidValue",
"First and last coordinates must be specified as waypoints.",
json_result);
result);
}
if (!CheckAlgorithms(route_parameters, algorithms, json_result))
if (!CheckAlgorithms(route_parameters, algorithms, result))
return Status::Error;
const auto &facade = algorithms.GetFacade();
@@ -93,7 +95,7 @@ Status ViaRoutePlugin::HandleRequest(const RoutingAlgorithmsInterface &algorithm
return Error("NoSegment",
std::string("Could not find a matching segment for coordinate ") +
std::to_string(phantom_node_pairs.size()),
json_result);
result);
}
BOOST_ASSERT(phantom_node_pairs.size() == route_parameters.coordinates.size());
@@ -175,11 +177,11 @@ Status ViaRoutePlugin::HandleRequest(const RoutingAlgorithmsInterface &algorithm
if (not_in_same_component)
{
return Error("NoRoute", "Impossible route between points", json_result);
return Error("NoRoute", "Impossible route between points", result);
}
else
{
return Error("NoRoute", "No route found between points", json_result);
return Error("NoRoute", "No route found between points", result);
}
}
+10 -6
View File
@@ -57,33 +57,37 @@ OSRM &OSRM::operator=(OSRM &&) noexcept = default;
// Forward to implementation
engine::Status OSRM::Route(const engine::api::RouteParameters &params,
util::json::Object &result) const
osrm::engine::api::ResultT &result) const
{
return engine_->Route(params, result);
}
engine::Status OSRM::Table(const engine::api::TableParameters &params, json::Object &result) const
engine::Status OSRM::Table(const engine::api::TableParameters &params,
osrm::engine::api::ResultT &result) const
{
return engine_->Table(params, result);
}
engine::Status OSRM::Nearest(const engine::api::NearestParameters &params,
json::Object &result) const
osrm::engine::api::ResultT &result) const
{
return engine_->Nearest(params, result);
}
engine::Status OSRM::Trip(const engine::api::TripParameters &params, json::Object &result) const
engine::Status OSRM::Trip(const engine::api::TripParameters &params,
osrm::engine::api::ResultT &result) const
{
return engine_->Trip(params, result);
}
engine::Status OSRM::Match(const engine::api::MatchParameters &params, json::Object &result) const
engine::Status OSRM::Match(const engine::api::MatchParameters &params,
osrm::engine::api::ResultT &result) const
{
return engine_->Match(params, result);
}
engine::Status OSRM::Tile(const engine::api::TileParameters &params, std::string &result) const
engine::Status OSRM::Tile(const engine::api::TileParameters &params,
osrm::engine::api::ResultT &result) const
{
return engine_->Tile(params, result);
}
+2 -2
View File
@@ -42,7 +42,7 @@ std::string getWrongOptionHelp(const engine::api::MatchParameters &parameters)
} // anon. ns
engine::Status
MatchService::RunQuery(std::size_t prefix_length, std::string &query, ResultT &result)
MatchService::RunQuery(std::size_t prefix_length, std::string &query, osrm::engine::api::ResultT &result)
{
result = util::json::Object();
auto &json_result = result.get<util::json::Object>();
@@ -68,7 +68,7 @@ MatchService::RunQuery(std::size_t prefix_length, std::string &query, ResultT &r
}
BOOST_ASSERT(parameters->IsValid());
return BaseService::routing_machine.Match(*parameters, json_result);
return BaseService::routing_machine.Match(*parameters, result);
}
}
}
+2 -2
View File
@@ -36,7 +36,7 @@ std::string getWrongOptionHelp(const engine::api::NearestParameters &parameters)
} // anon. ns
engine::Status
NearestService::RunQuery(std::size_t prefix_length, std::string &query, ResultT &result)
NearestService::RunQuery(std::size_t prefix_length, std::string &query, osrm::engine::api::ResultT &result)
{
result = util::json::Object();
auto &json_result = result.get<util::json::Object>();
@@ -62,7 +62,7 @@ NearestService::RunQuery(std::size_t prefix_length, std::string &query, ResultT
}
BOOST_ASSERT(parameters->IsValid());
return BaseService::routing_machine.Nearest(*parameters, json_result);
return BaseService::routing_machine.Nearest(*parameters, result);
}
}
}
+2 -2
View File
@@ -40,7 +40,7 @@ std::string getWrongOptionHelp(const engine::api::RouteParameters &parameters)
} // anon. ns
engine::Status
RouteService::RunQuery(std::size_t prefix_length, std::string &query, ResultT &result)
RouteService::RunQuery(std::size_t prefix_length, std::string &query, osrm::engine::api::ResultT &result)
{
result = util::json::Object();
auto &json_result = result.get<util::json::Object>();
@@ -66,7 +66,7 @@ RouteService::RunQuery(std::size_t prefix_length, std::string &query, ResultT &r
}
BOOST_ASSERT(parameters->IsValid());
return BaseService::routing_machine.Route(*parameters, json_result);
return BaseService::routing_machine.Route(*parameters, result);
}
}
}
+2 -2
View File
@@ -71,7 +71,7 @@ std::string getWrongOptionHelp(const engine::api::TableParameters &parameters)
} // anon. ns
engine::Status
TableService::RunQuery(std::size_t prefix_length, std::string &query, ResultT &result)
TableService::RunQuery(std::size_t prefix_length, std::string &query, osrm::engine::api::ResultT &result)
{
result = util::json::Object();
auto &json_result = result.get<util::json::Object>();
@@ -97,7 +97,7 @@ TableService::RunQuery(std::size_t prefix_length, std::string &query, ResultT &r
}
BOOST_ASSERT(parameters->IsValid());
return BaseService::routing_machine.Table(*parameters, json_result);
return BaseService::routing_machine.Table(*parameters, result);
}
}
}
+2 -3
View File
@@ -15,7 +15,7 @@ namespace server
namespace service
{
engine::Status TileService::RunQuery(std::size_t prefix_length, std::string &query, ResultT &result)
engine::Status TileService::RunQuery(std::size_t prefix_length, std::string &query, osrm::engine::api::ResultT &result)
{
auto query_iterator = query.begin();
auto parameters =
@@ -43,8 +43,7 @@ engine::Status TileService::RunQuery(std::size_t prefix_length, std::string &que
BOOST_ASSERT(parameters->IsValid());
result = std::string();
auto &string_result = result.get<std::string>();
return BaseService::routing_machine.Tile(*parameters, string_result);
return BaseService::routing_machine.Tile(*parameters, result);
}
}
}
+2 -2
View File
@@ -41,7 +41,7 @@ std::string getWrongOptionHelp(const engine::api::TripParameters &parameters)
}
} // anon. ns
engine::Status TripService::RunQuery(std::size_t prefix_length, std::string &query, ResultT &result)
engine::Status TripService::RunQuery(std::size_t prefix_length, std::string &query, osrm::engine::api::ResultT &result)
{
result = util::json::Object();
auto &json_result = result.get<util::json::Object>();
@@ -69,7 +69,7 @@ engine::Status TripService::RunQuery(std::size_t prefix_length, std::string &que
}
BOOST_ASSERT(parameters->IsValid());
return BaseService::routing_machine.Trip(*parameters, json_result);
return BaseService::routing_machine.Trip(*parameters, result);
}
}
}
+1 -1
View File
@@ -27,7 +27,7 @@ ServiceHandler::ServiceHandler(osrm::EngineConfig &config) : routing_machine(con
}
engine::Status ServiceHandler::RunQuery(api::ParsedURL parsed_url,
service::BaseService::ResultT &result)
osrm::engine::api::ResultT &result)
{
const auto &service_iter = service_map.find(parsed_url.service);
if (service_iter == service_map.end())