diff --git a/include/engine/api/base_result.hpp b/include/engine/api/base_result.hpp new file mode 100644 index 00000000000..ae599b54229 --- /dev/null +++ b/include/engine/api/base_result.hpp @@ -0,0 +1,21 @@ +#ifndef ENGINE_API_BASE_RESULT_HPP +#define ENGINE_API_BASE_RESULT_HPP + +#include + +#include + +#include "util/json_container.hpp" + +namespace osrm +{ +namespace engine +{ +namespace api +{ + using ResultT = mapbox::util::variant; +} // ns api +} // ns engine +} // ns osrm + +#endif diff --git a/include/engine/engine.hpp b/include/engine/engine.hpp index 9121c7b0e0a..3d0f9b3a629 100644 --- a/include/engine/engine.hpp +++ b/include/engine/engine.hpp @@ -33,16 +33,17 @@ class EngineInterface public: virtual ~EngineInterface() = default; virtual Status Route(const api::RouteParameters ¶meters, - util::json::Object &result) const = 0; + api::ResultT &result) const = 0; virtual Status Table(const api::TableParameters ¶meters, - util::json::Object &result) const = 0; + api::ResultT &result) const = 0; virtual Status Nearest(const api::NearestParameters ¶meters, - util::json::Object &result) const = 0; + api::ResultT &result) const = 0; virtual Status Trip(const api::TripParameters ¶meters, - util::json::Object &result) const = 0; + api::ResultT &result) const = 0; virtual Status Match(const api::MatchParameters ¶meters, - util::json::Object &result) const = 0; - virtual Status Tile(const api::TileParameters ¶meters, std::string &result) const = 0; + api::ResultT &result) const = 0; + virtual Status Tile(const api::TileParameters ¶meters, + api::ResultT &result) const = 0; }; template class Engine final : public EngineInterface @@ -90,35 +91,37 @@ template class Engine final : public EngineInterface virtual ~Engine() = default; Status Route(const api::RouteParameters ¶ms, - util::json::Object &result) const override final + api::ResultT &result) const override final { return route_plugin.HandleRequest(GetAlgorithms(params), params, result); } Status Table(const api::TableParameters ¶ms, - util::json::Object &result) const override final + api::ResultT &result) const override final { return table_plugin.HandleRequest(GetAlgorithms(params), params, result); } Status Nearest(const api::NearestParameters ¶ms, - util::json::Object &result) const override final + api::ResultT &result) const override final { return nearest_plugin.HandleRequest(GetAlgorithms(params), params, result); } - Status Trip(const api::TripParameters ¶ms, util::json::Object &result) const override final + Status Trip(const api::TripParameters ¶ms, + api::ResultT &result) const override final { return trip_plugin.HandleRequest(GetAlgorithms(params), params, result); } Status Match(const api::MatchParameters ¶ms, - util::json::Object &result) const override final + api::ResultT &result) const override final { return match_plugin.HandleRequest(GetAlgorithms(params), params, result); } - Status Tile(const api::TileParameters ¶ms, std::string &result) const override final + Status Tile(const api::TileParameters ¶ms, + api::ResultT &result) const override final { return tile_plugin.HandleRequest(GetAlgorithms(params), params, result); } diff --git a/include/engine/plugins/match.hpp b/include/engine/plugins/match.hpp index 7a6f932d031..3717aa71828 100644 --- a/include/engine/plugins/match.hpp +++ b/include/engine/plugins/match.hpp @@ -32,7 +32,7 @@ class MatchPlugin : public BasePlugin Status HandleRequest(const RoutingAlgorithmsInterface &algorithms, const api::MatchParameters ¶meters, - util::json::Object &json_result) const; + osrm::engine::api::ResultT &json_result) const; private: const int max_locations_map_matching; diff --git a/include/engine/plugins/nearest.hpp b/include/engine/plugins/nearest.hpp index ccc0a4cdddd..d696c46b0db 100644 --- a/include/engine/plugins/nearest.hpp +++ b/include/engine/plugins/nearest.hpp @@ -21,7 +21,7 @@ class NearestPlugin final : public BasePlugin Status HandleRequest(const RoutingAlgorithmsInterface &algorithms, const api::NearestParameters ¶ms, - util::json::Object &result) const; + osrm::engine::api::ResultT &result) const; private: const int max_results; diff --git a/include/engine/plugins/plugin_base.hpp b/include/engine/plugins/plugin_base.hpp index 78dd9e08950..5db8d6bc0c5 100644 --- a/include/engine/plugins/plugin_base.hpp +++ b/include/engine/plugins/plugin_base.hpp @@ -2,6 +2,7 @@ #define BASE_PLUGIN_HPP #include "engine/api/base_parameters.hpp" +#include "engine/api/base_result.hpp" #include "engine/datafacade/datafacade_base.hpp" #include "engine/phantom_node.hpp" #include "engine/routing_algorithms.hpp" @@ -39,7 +40,7 @@ class BasePlugin bool CheckAlgorithms(const api::BaseParameters ¶ms, const RoutingAlgorithmsInterface &algorithms, - util::json::Object &result) const + osrm::engine::api::ResultT &result) const { if (algorithms.IsValid()) { @@ -64,8 +65,10 @@ class BasePlugin Status Error(const std::string &code, const std::string &message, - util::json::Object &json_result) const + osrm::engine::api::ResultT &result) const { + result = util::json::Object(); + auto& json_result = result.get(); json_result.values["code"] = code; json_result.values["message"] = message; return Status::Error; diff --git a/include/engine/plugins/table.hpp b/include/engine/plugins/table.hpp index 65ea1bba57e..1cd7da6e9fa 100644 --- a/include/engine/plugins/table.hpp +++ b/include/engine/plugins/table.hpp @@ -22,7 +22,7 @@ class TablePlugin final : public BasePlugin Status HandleRequest(const RoutingAlgorithmsInterface &algorithms, const api::TableParameters ¶ms, - util::json::Object &result) const; + osrm::engine::api::ResultT &result) const; private: const int max_locations_distance_table; diff --git a/include/engine/plugins/tile.hpp b/include/engine/plugins/tile.hpp index 24d141e3555..90d598d7829 100644 --- a/include/engine/plugins/tile.hpp +++ b/include/engine/plugins/tile.hpp @@ -28,7 +28,7 @@ class TilePlugin final : public BasePlugin public: Status HandleRequest(const RoutingAlgorithmsInterface &algorithms, const api::TileParameters ¶meters, - std::string &pbf_buffer) const; + osrm::engine::api::ResultT &pbf_buffer) const; }; } } diff --git a/include/engine/plugins/trip.hpp b/include/engine/plugins/trip.hpp index d49126e192d..ee45729f82a 100644 --- a/include/engine/plugins/trip.hpp +++ b/include/engine/plugins/trip.hpp @@ -40,7 +40,7 @@ class TripPlugin final : public BasePlugin Status HandleRequest(const RoutingAlgorithmsInterface &algorithms, const api::TripParameters ¶meters, - util::json::Object &json_result) const; + osrm::engine::api::ResultT &json_result) const; }; } } diff --git a/include/engine/plugins/viaroute.hpp b/include/engine/plugins/viaroute.hpp index b9baea92379..70642d6d1a9 100644 --- a/include/engine/plugins/viaroute.hpp +++ b/include/engine/plugins/viaroute.hpp @@ -33,7 +33,7 @@ class ViaRoutePlugin final : public BasePlugin Status HandleRequest(const RoutingAlgorithmsInterface &algorithms, const api::RouteParameters &route_parameters, - util::json::Object &json_result) const; + osrm::engine::api::ResultT &json_result) const; }; } } diff --git a/include/osrm/osrm.hpp b/include/osrm/osrm.hpp index a1140f3dad3..af3b7f2488d 100644 --- a/include/osrm/osrm.hpp +++ b/include/osrm/osrm.hpp @@ -30,6 +30,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "osrm/osrm_fwd.hpp" #include "osrm/status.hpp" +#include "engine/api/base_result.hpp" #include #include @@ -83,7 +84,7 @@ class OSRM final * \return Status indicating success for the query or failure * \see Status, RouteParameters and json::Object */ - Status Route(const RouteParameters ¶meters, json::Object &result) const; + Status Route(const RouteParameters ¶meters, osrm::engine::api::ResultT &result) const; /** * Distance tables for coordinates. @@ -92,7 +93,7 @@ class OSRM final * \return Status indicating success for the query or failure * \see Status, TableParameters and json::Object */ - Status Table(const TableParameters ¶meters, json::Object &result) const; + Status Table(const TableParameters ¶meters, osrm::engine::api::ResultT &result) const; /** * Nearest street segment for coordinate. @@ -101,7 +102,7 @@ class OSRM final * \return Status indicating success for the query or failure * \see Status, NearestParameters and json::Object */ - Status Nearest(const NearestParameters ¶meters, json::Object &result) const; + Status Nearest(const NearestParameters ¶meters, osrm::engine::api::ResultT &result) const; /** * Trip: shortest round trip between coordinates. @@ -110,7 +111,7 @@ class OSRM final * \return Status indicating success for the query or failure * \see Status, TripParameters and json::Object */ - Status Trip(const TripParameters ¶meters, json::Object &result) const; + Status Trip(const TripParameters ¶meters, osrm::engine::api::ResultT &result) const; /** * Match: snaps noisy coordinate traces to the road network @@ -119,7 +120,7 @@ class OSRM final * \return Status indicating success for the query or failure * \see Status, MatchParameters and json::Object */ - Status Match(const MatchParameters ¶meters, json::Object &result) const; + Status Match(const MatchParameters ¶meters, osrm::engine::api::ResultT &result) const; /** * Tile: vector tiles with internal graph representation @@ -128,7 +129,7 @@ class OSRM final * \return Status indicating success for the query or failure * \see Status, TileParameters and json::Object */ - Status Tile(const TileParameters ¶meters, std::string &result) const; + Status Tile(const TileParameters ¶meters, osrm::engine::api::ResultT &result) const; private: std::unique_ptr engine_; diff --git a/include/server/service/base_service.hpp b/include/server/service/base_service.hpp index 401a072bc0f..9491fa6628c 100644 --- a/include/server/service/base_service.hpp +++ b/include/server/service/base_service.hpp @@ -20,13 +20,11 @@ namespace service class BaseService { public: - using ResultT = mapbox::util::variant; - BaseService(OSRM &routing_machine) : routing_machine(routing_machine) {} virtual ~BaseService() = default; virtual engine::Status - RunQuery(std::size_t prefix_length, std::string &query, ResultT &result) = 0; + RunQuery(std::size_t prefix_length, std::string &query, osrm::engine::api::ResultT &result) = 0; virtual unsigned GetVersion() = 0; diff --git a/include/server/service/match_service.hpp b/include/server/service/match_service.hpp index 07a95e20f1a..139b690e447 100644 --- a/include/server/service/match_service.hpp +++ b/include/server/service/match_service.hpp @@ -23,7 +23,7 @@ class MatchService final : public BaseService MatchService(OSRM &routing_machine) : BaseService(routing_machine) {} engine::Status - RunQuery(std::size_t prefix_length, std::string &query, ResultT &result) final override; + RunQuery(std::size_t prefix_length, std::string &query, osrm::engine::api::ResultT &result) final override; unsigned GetVersion() final override { return 1; } }; diff --git a/include/server/service/nearest_service.hpp b/include/server/service/nearest_service.hpp index ffbbaf84b56..a75381cf17d 100644 --- a/include/server/service/nearest_service.hpp +++ b/include/server/service/nearest_service.hpp @@ -23,7 +23,7 @@ class NearestService final : public BaseService NearestService(OSRM &routing_machine) : BaseService(routing_machine) {} engine::Status - RunQuery(std::size_t prefix_length, std::string &query, ResultT &result) final override; + RunQuery(std::size_t prefix_length, std::string &query, osrm::engine::api::ResultT &result) final override; unsigned GetVersion() final override { return 1; } }; diff --git a/include/server/service/route_service.hpp b/include/server/service/route_service.hpp index 3e9be1bf8ab..c51386a7eaf 100644 --- a/include/server/service/route_service.hpp +++ b/include/server/service/route_service.hpp @@ -23,7 +23,7 @@ class RouteService final : public BaseService RouteService(OSRM &routing_machine) : BaseService(routing_machine) {} engine::Status - RunQuery(std::size_t prefix_length, std::string &query, ResultT &result) final override; + RunQuery(std::size_t prefix_length, std::string &query, osrm::engine::api::ResultT &result) final override; unsigned GetVersion() final override { return 1; } }; diff --git a/include/server/service/table_service.hpp b/include/server/service/table_service.hpp index ca32f4d8351..2610d6de167 100644 --- a/include/server/service/table_service.hpp +++ b/include/server/service/table_service.hpp @@ -23,7 +23,7 @@ class TableService final : public BaseService TableService(OSRM &routing_machine) : BaseService(routing_machine) {} engine::Status - RunQuery(std::size_t prefix_length, std::string &query, ResultT &result) final override; + RunQuery(std::size_t prefix_length, std::string &query, osrm::engine::api::ResultT &result) final override; unsigned GetVersion() final override { return 1; } }; diff --git a/include/server/service/tile_service.hpp b/include/server/service/tile_service.hpp index afa9a442c2a..74339fa84b3 100644 --- a/include/server/service/tile_service.hpp +++ b/include/server/service/tile_service.hpp @@ -23,7 +23,7 @@ class TileService final : public BaseService TileService(OSRM &routing_machine) : BaseService(routing_machine) {} engine::Status - RunQuery(std::size_t prefix_length, std::string &query, ResultT &result) final override; + RunQuery(std::size_t prefix_length, std::string &query, osrm::engine::api::ResultT &result) final override; unsigned GetVersion() final override { return 1; } }; diff --git a/include/server/service/trip_service.hpp b/include/server/service/trip_service.hpp index 7dd6fbfcb46..fbd668fc8bb 100644 --- a/include/server/service/trip_service.hpp +++ b/include/server/service/trip_service.hpp @@ -23,7 +23,7 @@ class TripService final : public BaseService TripService(OSRM &routing_machine) : BaseService(routing_machine) {} engine::Status - RunQuery(std::size_t prefix_length, std::string &query, ResultT &result) final override; + RunQuery(std::size_t prefix_length, std::string &query, osrm::engine::api::ResultT &result) final override; unsigned GetVersion() final override { return 1; } }; diff --git a/include/server/service_handler.hpp b/include/server/service_handler.hpp index bc96c316c1c..00a514925e2 100644 --- a/include/server/service_handler.hpp +++ b/include/server/service_handler.hpp @@ -4,6 +4,7 @@ #include "server/service/base_service.hpp" #include "osrm/osrm.hpp" +#include "engine/api/base_api.hpp" #include @@ -28,14 +29,14 @@ class ServiceHandlerInterface public: virtual ~ServiceHandlerInterface() {} virtual engine::Status RunQuery(api::ParsedURL parsed_url, - service::BaseService::ResultT &result) = 0; + osrm::engine::api::ResultT &result) = 0; }; class ServiceHandler final : public ServiceHandlerInterface { public: ServiceHandler(osrm::EngineConfig &config); - using ResultT = service::BaseService::ResultT; + using ResultT = osrm::engine::api::ResultT; virtual engine::Status RunQuery(api::ParsedURL parsed_url, ResultT &result) override; diff --git a/src/engine/plugins/match.cpp b/src/engine/plugins/match.cpp index 54ad24231df..799ac4393be 100644 --- a/src/engine/plugins/match.cpp +++ b/src/engine/plugins/match.cpp @@ -112,16 +112,17 @@ void filterCandidates(const std::vector &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(); 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(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 diff --git a/src/engine/plugins/nearest.cpp b/src/engine/plugins/nearest.cpp index 934528d873e..4d1fa6737c1 100644 --- a/src/engine/plugins/nearest.cpp +++ b/src/engine/plugins/nearest.cpp @@ -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(); + 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); diff --git a/src/engine/plugins/table.cpp b/src/engine/plugins/table.cpp index f78645c9d5e..07dbc971af5 100644 --- a/src/engine/plugins/table.cpp +++ b/src/engine/plugins/table.cpp @@ -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(); 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; } diff --git a/src/engine/plugins/tile.cpp b/src/engine/plugins/tile.cpp index 47fb1933e76..825d749f65f 100644 --- a/src/engine/plugins/tile.cpp +++ b/src/engine/plugins/tile.cpp @@ -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(); const auto &facade = algorithms.GetFacade(); auto edges = getEdges(facade, parameters.x, parameters.y, parameters.z); auto segregated_nodes = getSegregatedNodes(facade, edges); diff --git a/src/engine/plugins/trip.cpp b/src/engine/plugins/trip.cpp index f402a0c067e..9b2adc8c38c 100644 --- a/src/engine/plugins/trip.cpp +++ b/src/engine/plugins/trip.cpp @@ -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(); 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(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) diff --git a/src/engine/plugins/viaroute.cpp b/src/engine/plugins/viaroute.cpp index a4df2de8652..807a3317482 100644 --- a/src/engine/plugins/viaroute.cpp +++ b/src/engine/plugins/viaroute.cpp @@ -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(); + 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); } } diff --git a/src/osrm/osrm.cpp b/src/osrm/osrm.cpp index 06abf7b79e8..8658e264f81 100644 --- a/src/osrm/osrm.cpp +++ b/src/osrm/osrm.cpp @@ -57,33 +57,37 @@ OSRM &OSRM::operator=(OSRM &&) noexcept = default; // Forward to implementation engine::Status OSRM::Route(const engine::api::RouteParameters ¶ms, - util::json::Object &result) const + osrm::engine::api::ResultT &result) const { return engine_->Route(params, result); } -engine::Status OSRM::Table(const engine::api::TableParameters ¶ms, json::Object &result) const +engine::Status OSRM::Table(const engine::api::TableParameters ¶ms, + osrm::engine::api::ResultT &result) const { return engine_->Table(params, result); } engine::Status OSRM::Nearest(const engine::api::NearestParameters ¶ms, - json::Object &result) const + osrm::engine::api::ResultT &result) const { return engine_->Nearest(params, result); } -engine::Status OSRM::Trip(const engine::api::TripParameters ¶ms, json::Object &result) const +engine::Status OSRM::Trip(const engine::api::TripParameters ¶ms, + osrm::engine::api::ResultT &result) const { return engine_->Trip(params, result); } -engine::Status OSRM::Match(const engine::api::MatchParameters ¶ms, json::Object &result) const +engine::Status OSRM::Match(const engine::api::MatchParameters ¶ms, + osrm::engine::api::ResultT &result) const { return engine_->Match(params, result); } -engine::Status OSRM::Tile(const engine::api::TileParameters ¶ms, std::string &result) const +engine::Status OSRM::Tile(const engine::api::TileParameters ¶ms, + osrm::engine::api::ResultT &result) const { return engine_->Tile(params, result); } diff --git a/src/server/service/match_service.cpp b/src/server/service/match_service.cpp index c8327510794..2918f11b083 100644 --- a/src/server/service/match_service.cpp +++ b/src/server/service/match_service.cpp @@ -42,7 +42,7 @@ std::string getWrongOptionHelp(const engine::api::MatchParameters ¶meters) } // 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(); @@ -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); } } } diff --git a/src/server/service/nearest_service.cpp b/src/server/service/nearest_service.cpp index 67ca91b7ea9..236cf580158 100644 --- a/src/server/service/nearest_service.cpp +++ b/src/server/service/nearest_service.cpp @@ -36,7 +36,7 @@ std::string getWrongOptionHelp(const engine::api::NearestParameters ¶meters) } // 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(); @@ -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); } } } diff --git a/src/server/service/route_service.cpp b/src/server/service/route_service.cpp index 98a8e5b5a2d..ae6a691268b 100644 --- a/src/server/service/route_service.cpp +++ b/src/server/service/route_service.cpp @@ -40,7 +40,7 @@ std::string getWrongOptionHelp(const engine::api::RouteParameters ¶meters) } // 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(); @@ -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); } } } diff --git a/src/server/service/table_service.cpp b/src/server/service/table_service.cpp index ad5f16ab14d..b50c142ff17 100644 --- a/src/server/service/table_service.cpp +++ b/src/server/service/table_service.cpp @@ -71,7 +71,7 @@ std::string getWrongOptionHelp(const engine::api::TableParameters ¶meters) } // 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(); @@ -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); } } } diff --git a/src/server/service/tile_service.cpp b/src/server/service/tile_service.cpp index 35d5ea95a2c..c125bc38f64 100644 --- a/src/server/service/tile_service.cpp +++ b/src/server/service/tile_service.cpp @@ -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(); - return BaseService::routing_machine.Tile(*parameters, string_result); + return BaseService::routing_machine.Tile(*parameters, result); } } } diff --git a/src/server/service/trip_service.cpp b/src/server/service/trip_service.cpp index 2a7d315a102..e893a43b19e 100644 --- a/src/server/service/trip_service.cpp +++ b/src/server/service/trip_service.cpp @@ -41,7 +41,7 @@ std::string getWrongOptionHelp(const engine::api::TripParameters ¶meters) } } // 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(); @@ -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); } } } diff --git a/src/server/service_handler.cpp b/src/server/service_handler.cpp index adc1dae9635..81fc3f71946 100644 --- a/src/server/service_handler.cpp +++ b/src/server/service_handler.cpp @@ -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())