Passed ResultT down to engine plugins, so now they can form replies in different formats.
This commit is contained in:
@@ -112,16 +112,17 @@ void filterCandidates(const std::vector<util::Coordinate> &coordinates,
|
||||
|
||||
Status MatchPlugin::HandleRequest(const RoutingAlgorithmsInterface &algorithms,
|
||||
const api::MatchParameters ¶meters,
|
||||
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
|
||||
|
||||
@@ -21,11 +21,12 @@ NearestPlugin::NearestPlugin(const int max_results_) : max_results{max_results_}
|
||||
|
||||
Status NearestPlugin::HandleRequest(const RoutingAlgorithmsInterface &algorithms,
|
||||
const api::NearestParameters ¶ms,
|
||||
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);
|
||||
|
||||
|
||||
@@ -31,8 +31,9 @@ TablePlugin::TablePlugin(const int max_locations_distance_table)
|
||||
|
||||
Status TablePlugin::HandleRequest(const RoutingAlgorithmsInterface &algorithms,
|
||||
const api::TableParameters ¶ms,
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -665,10 +665,11 @@ void encodeVectorTile(const DataFacadeBase &facade,
|
||||
|
||||
Status TilePlugin::HandleRequest(const RoutingAlgorithmsInterface &algorithms,
|
||||
const api::TileParameters ¶meters,
|
||||
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
@@ -144,19 +144,20 @@ void ManipulateTableForFSE(const std::size_t source_id,
|
||||
|
||||
Status TripPlugin::HandleRequest(const RoutingAlgorithmsInterface &algorithms,
|
||||
const api::TripParameters ¶meters,
|
||||
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)
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user