Add viaroute suport for new API
This commit is contained in:
@@ -0,0 +1,82 @@
|
||||
#ifndef SERVER_API_BASE_PARAMETERS_GRAMMAR_HPP
|
||||
#define SERVER_API_BASE_PARAMETERS_GRAMMAR_HPP
|
||||
|
||||
#include "engine/api/base_parameters.hpp"
|
||||
|
||||
#include "engine/polyline_compressor.hpp"
|
||||
#include "engine/hint.hpp"
|
||||
|
||||
#include <boost/spirit/include/qi_lit.hpp>
|
||||
#include <boost/spirit/include/qi_char_.hpp>
|
||||
#include <boost/spirit/include/qi_int.hpp>
|
||||
#include <boost/spirit/include/qi_real.hpp>
|
||||
#include <boost/spirit/include/qi_grammar.hpp>
|
||||
#include <boost/spirit/include/qi_action.hpp>
|
||||
#include <boost/spirit/include/qi_optional.hpp>
|
||||
#include <boost/spirit/include/qi_attr_cast.hpp>
|
||||
#include <boost/spirit/include/qi_operator.hpp>
|
||||
#include <boost/spirit/include/qi_repeat.hpp>
|
||||
#include <boost/spirit/include/qi_as_string.hpp>
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace osrm
|
||||
{
|
||||
namespace server
|
||||
{
|
||||
namespace api
|
||||
{
|
||||
|
||||
namespace qi = boost::spirit::qi;
|
||||
struct BaseParametersGrammar : boost::spirit::qi::grammar<std::string::iterator>
|
||||
{
|
||||
using Iterator = std::string::iterator;
|
||||
using RadiusesT = std::vector<boost::optional<double>>;
|
||||
|
||||
BaseParametersGrammar(qi::rule<Iterator> &child_rule,
|
||||
engine::api::BaseParameters ¶meters_)
|
||||
: BaseParametersGrammar::base_type(child_rule), base_parameters(parameters_)
|
||||
{
|
||||
const auto add_bearing = [this](const boost::optional<boost::fusion::vector<short, short>> &bearing_range) {
|
||||
boost::optional<engine::api::BaseParameters::Bearing> bearing;
|
||||
if (bearing_range)
|
||||
{
|
||||
bearing = engine::api::BaseParameters::Bearing {boost::fusion::at_c<0>(*bearing_range), boost::fusion::at_c<1>(*bearing_range)};
|
||||
}
|
||||
base_parameters.bearings.push_back(std::move(bearing));
|
||||
};
|
||||
const auto set_radiuses = [this](RadiusesT& radiuses) {
|
||||
base_parameters.radiuses = std::move(radiuses);
|
||||
};
|
||||
const auto add_hint = [this](const std::string& hint_string) {
|
||||
if (hint_string.size() > 0)
|
||||
{
|
||||
base_parameters.hints.push_back(engine::Hint::FromBase64(hint_string));
|
||||
}
|
||||
};
|
||||
|
||||
alpha_numeral = +qi::char_("a-zA-Z0-9");
|
||||
base64_char = qi::char_("a-zA-Z0-9--_");
|
||||
|
||||
radiuses_rule = qi::lit("radiuses=") >> -qi::double_ % ";";
|
||||
hints_rule = qi::lit("hints=") >> qi::as_string[qi::repeat(engine::ENCODED_HINT_SIZE)[base64_char]][add_hint] % ";";
|
||||
bearings_rule =
|
||||
qi::lit("bearings=") >> -((qi::short_ >> ',' >> qi::short_))[add_bearing] % ";";
|
||||
base_rule = bearings_rule | radiuses_rule[set_radiuses] | hints_rule;
|
||||
}
|
||||
|
||||
qi::rule<Iterator> base_rule;
|
||||
|
||||
private:
|
||||
engine::api::BaseParameters &base_parameters;
|
||||
qi::rule<Iterator> bearings_rule;
|
||||
qi::rule<Iterator> hints_rule;
|
||||
qi::rule<Iterator, RadiusesT()> radiuses_rule;
|
||||
qi::rule<Iterator, unsigned char()> base64_char;
|
||||
qi::rule<Iterator, std::string()> alpha_numeral;
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,29 @@
|
||||
#ifndef SERVER_API_PARSED_URL_HPP
|
||||
#define SERVER_API_PARSED_URL_HPP
|
||||
|
||||
#include "util/coordinate.hpp"
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace osrm
|
||||
{
|
||||
namespace server
|
||||
{
|
||||
namespace api
|
||||
{
|
||||
|
||||
struct ParsedURL
|
||||
{
|
||||
std::string service;
|
||||
unsigned version;
|
||||
std::string profile;
|
||||
std::vector<util::FixedPointCoordinate> coordinates;
|
||||
std::string options;
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,92 @@
|
||||
#ifndef ROUTE_PARAMETERS_GRAMMAR_HPP
|
||||
#define ROUTE_PARAMETERS_GRAMMAR_HPP
|
||||
|
||||
#include "engine/api/route_parameters.hpp"
|
||||
|
||||
#include "server/api/base_parameters_grammar.hpp"
|
||||
|
||||
#include <boost/spirit/include/qi_lit.hpp>
|
||||
#include <boost/spirit/include/qi_bool.hpp>
|
||||
#include <boost/spirit/include/qi_grammar.hpp>
|
||||
#include <boost/spirit/include/qi_action.hpp>
|
||||
#include <boost/spirit/include/qi_optional.hpp>
|
||||
|
||||
namespace osrm
|
||||
{
|
||||
namespace server
|
||||
{
|
||||
namespace api
|
||||
{
|
||||
|
||||
namespace qi = boost::spirit::qi;
|
||||
struct RouteParametersGrammar : public BaseParametersGrammar
|
||||
{
|
||||
using Iterator = std::string::iterator;
|
||||
using StepsT = bool;
|
||||
using AlternativeT = bool;
|
||||
using GeometriesT = engine::api::RouteParameters::GeometriesType;
|
||||
using OverviewT = engine::api::RouteParameters::OverviewType;
|
||||
using UturnsT = std::vector<boost::optional<bool>>;
|
||||
|
||||
RouteParametersGrammar()
|
||||
: BaseParametersGrammar(root_rule, route_parameters)
|
||||
{
|
||||
const auto set_geojson_type = [this]()
|
||||
{
|
||||
route_parameters.geometries = engine::api::RouteParameters::GeometriesType::GeoJSON;
|
||||
};
|
||||
const auto set_polyline_type = [this]()
|
||||
{
|
||||
route_parameters.geometries = engine::api::RouteParameters::GeometriesType::Polyline;
|
||||
};
|
||||
|
||||
const auto set_simplified_type = [this]()
|
||||
{
|
||||
route_parameters.overview = engine::api::RouteParameters::OverviewType::Simplified;
|
||||
};
|
||||
const auto set_full_type = [this]()
|
||||
{
|
||||
route_parameters.overview = engine::api::RouteParameters::OverviewType::Full;
|
||||
};
|
||||
const auto set_false_type = [this]()
|
||||
{
|
||||
route_parameters.overview = engine::api::RouteParameters::OverviewType::False;
|
||||
};
|
||||
const auto set_steps = [this](const StepsT steps)
|
||||
{
|
||||
route_parameters.steps = steps;
|
||||
};
|
||||
const auto set_alternative = [this](const AlternativeT alternative)
|
||||
{
|
||||
route_parameters.alternative = alternative;
|
||||
};
|
||||
const auto set_uturns = [this](UturnsT &uturns)
|
||||
{
|
||||
route_parameters.uturns = std::move(uturns);
|
||||
};
|
||||
|
||||
alternative_rule = qi::lit("alternative=") >> qi::bool_;
|
||||
steps_rule = qi::lit("steps=") >> qi::bool_;
|
||||
geometries_rule = qi::lit("geometries=geojson")[set_geojson_type] |
|
||||
qi::lit("geometries=polyline")[set_polyline_type];
|
||||
overview_rule = qi::lit("overview=simplified")[set_simplified_type] |
|
||||
qi::lit("overview=full")[set_full_type] |
|
||||
qi::lit("overview=false")[set_false_type];
|
||||
uturns_rule = qi::lit("uturns=") >> -qi::bool_ % ";";
|
||||
route_rule = steps_rule[set_steps] | alternative_rule[set_alternative] | geometries_rule |
|
||||
overview_rule | uturns_rule[set_uturns];
|
||||
root_rule = -((base_rule | route_rule) % '&');
|
||||
}
|
||||
|
||||
engine::api::RouteParameters route_parameters;
|
||||
private:
|
||||
qi::rule<Iterator> root_rule, route_rule, geometries_rule, overview_rule;
|
||||
qi::rule<Iterator, UturnsT()> uturns_rule;
|
||||
qi::rule<Iterator, StepsT()> steps_rule;
|
||||
qi::rule<Iterator, AlternativeT()> alternative_rule;
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,28 @@
|
||||
#ifndef SERVER_API_ROUTE_PARAMETERS_PARSER_HPP
|
||||
#define SERVER_API_ROUTE_PARAMETERS_PARSER_HPP
|
||||
|
||||
#include "engine/api/route_parameters.hpp"
|
||||
#include "server/api/route_parameters_parser.hpp"
|
||||
|
||||
namespace osrm
|
||||
{
|
||||
namespace server
|
||||
{
|
||||
namespace api
|
||||
{
|
||||
|
||||
// Starts parsing and iter and modifies it until iter == end or parsing failed
|
||||
boost::optional<engine::api::RouteParameters> parseRouteParameters(std::string::iterator& iter, std::string::iterator end);
|
||||
|
||||
// copy on purpose because we need mutability
|
||||
inline boost::optional<engine::api::RouteParameters> parseRouteParameters(std::string options_string)
|
||||
{
|
||||
auto iter = options_string.begin();
|
||||
return parseRouteParameters(iter, options_string.end());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,30 @@
|
||||
#ifndef SERVER_URL_PARSER_HPP
|
||||
#define SERVER_URL_PARSER_HPP
|
||||
|
||||
#include "server/api/parsed_url.hpp"
|
||||
|
||||
#include <boost/optional.hpp>
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace osrm
|
||||
{
|
||||
namespace server
|
||||
{
|
||||
namespace api
|
||||
{
|
||||
|
||||
// Starts parsing and iter and modifies it until iter == end or parsing failed
|
||||
boost::optional<ParsedURL> parseURL(std::string::iterator& iter, std::string::iterator end);
|
||||
// copy on purpose because we need mutability
|
||||
inline boost::optional<ParsedURL> parseURL(std::string url_string)
|
||||
{
|
||||
auto iter = url_string.begin();
|
||||
return parseURL(iter, url_string.end());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -1,151 +0,0 @@
|
||||
#ifndef API_GRAMMAR_HPP
|
||||
#define API_GRAMMAR_HPP
|
||||
|
||||
#include <boost/bind.hpp>
|
||||
#include <boost/spirit/include/qi.hpp>
|
||||
#include <boost/spirit/include/qi_action.hpp>
|
||||
|
||||
namespace osrm
|
||||
{
|
||||
namespace server
|
||||
{
|
||||
|
||||
namespace qi = boost::spirit::qi;
|
||||
|
||||
template <typename Iterator, class HandlerT> struct APIGrammar : qi::grammar<Iterator>
|
||||
{
|
||||
explicit APIGrammar(HandlerT *h) : APIGrammar::base_type(api_call), handler(h)
|
||||
{
|
||||
const auto set_x_wrapper = [this](const int x, bool &pass)
|
||||
{
|
||||
pass = handler->SetX(x);
|
||||
};
|
||||
const auto set_y_wrapper = [this](const int y, bool &pass)
|
||||
{
|
||||
pass = handler->SetY(y);
|
||||
};
|
||||
const auto set_z_wrapper = [this](const int z, bool &pass)
|
||||
{
|
||||
pass = handler->SetZ(z);
|
||||
};
|
||||
const auto add_bearing_wrapper = [this](
|
||||
const boost::fusion::vector<int, boost::optional<int>> &received_bearing, bool &pass)
|
||||
{
|
||||
const int bearing = boost::fusion::at_c<0>(received_bearing);
|
||||
const boost::optional<int> range = boost::fusion::at_c<1>(received_bearing);
|
||||
pass = handler->AddBearing(bearing, range);
|
||||
};
|
||||
const auto add_coordinate_wrapper =
|
||||
[this](const boost::fusion::vector<double, double> &received_coordinate)
|
||||
{
|
||||
handler->AddCoordinate(boost::fusion::at_c<0>(received_coordinate),
|
||||
boost::fusion::at_c<1>(received_coordinate));
|
||||
};
|
||||
const auto add_source_wrapper =
|
||||
[this](const boost::fusion::vector<double, double> &received_coordinate)
|
||||
{
|
||||
handler->AddSource(boost::fusion::at_c<0>(received_coordinate),
|
||||
boost::fusion::at_c<1>(received_coordinate));
|
||||
};
|
||||
const auto add_destination_wrapper =
|
||||
[this](const boost::fusion::vector<double, double> &received_coordinate)
|
||||
{
|
||||
handler->AddDestination(boost::fusion::at_c<0>(received_coordinate),
|
||||
boost::fusion::at_c<1>(received_coordinate));
|
||||
};
|
||||
|
||||
api_call =
|
||||
qi::lit('/') >> string[boost::bind(&HandlerT::SetService, handler, ::_1)] >> -query;
|
||||
query = ('?') >> +(zoom | output | jsonp | checksum | uturns | location_with_options |
|
||||
destination_with_options | source_with_options | cmp | language |
|
||||
instruction | geometry | alt_route | old_API | num_results |
|
||||
matching_beta | gps_precision | classify | locs | x | y | z);
|
||||
// all combinations of timestamp, uturn, hint and bearing without duplicates
|
||||
t_u = (u >> -timestamp) | (timestamp >> -u);
|
||||
t_h = (hint >> -timestamp) | (timestamp >> -hint);
|
||||
u_h = (u >> -hint) | (hint >> -u);
|
||||
t_u_h = (hint >> -t_u) | (u >> -t_h) | (timestamp >> -u_h);
|
||||
location_options =
|
||||
(bearing >> -t_u_h) | (t_u_h >> -bearing) | //
|
||||
(u >> bearing >> -t_h) | (timestamp >> bearing >> -u_h) | (hint >> bearing >> t_u) | //
|
||||
(t_h >> bearing >> -u) | (u_h >> bearing >> -timestamp) | (t_u >> bearing >> -hint);
|
||||
location_with_options = location >> -location_options;
|
||||
source_with_options = source >> -location_options;
|
||||
destination_with_options = destination >> -location_options;
|
||||
zoom = (-qi::lit('&')) >> qi::lit('z') >> '=' >>
|
||||
qi::short_[boost::bind(&HandlerT::SetZoomLevel, handler, ::_1)];
|
||||
output = (-qi::lit('&')) >> qi::lit("output=json");
|
||||
jsonp = (-qi::lit('&')) >> qi::lit("jsonp") >> '=' >>
|
||||
stringwithPercent[boost::bind(&HandlerT::SetJSONpParameter, handler, ::_1)];
|
||||
checksum = (-qi::lit('&')) >> qi::lit("checksum") >> '=' >>
|
||||
qi::uint_[boost::bind(&HandlerT::SetChecksum, handler, ::_1)];
|
||||
instruction = (-qi::lit('&')) >> qi::lit("instructions") >> '=' >>
|
||||
qi::bool_[boost::bind(&HandlerT::SetInstructionFlag, handler, ::_1)];
|
||||
geometry = (-qi::lit('&')) >> qi::lit("geometry") >> '=' >>
|
||||
qi::bool_[boost::bind(&HandlerT::SetGeometryFlag, handler, ::_1)];
|
||||
cmp = (-qi::lit('&')) >> qi::lit("compression") >> '=' >>
|
||||
qi::bool_[boost::bind(&HandlerT::SetCompressionFlag, handler, ::_1)];
|
||||
location = (-qi::lit('&')) >> qi::lit("loc") >> '=' >>
|
||||
(qi::double_ >> qi::lit(',') >>
|
||||
qi::double_)[boost::bind<void>(add_coordinate_wrapper, ::_1)];
|
||||
destination = (-qi::lit('&')) >> qi::lit("dst") >> '=' >>
|
||||
(qi::double_ >> qi::lit(',') >>
|
||||
qi::double_)[boost::bind<void>(add_destination_wrapper, ::_1)];
|
||||
source = (-qi::lit('&')) >> qi::lit("src") >> '=' >>
|
||||
(qi::double_ >> qi::lit(',') >>
|
||||
qi::double_)[boost::bind<void>(add_source_wrapper, ::_1)];
|
||||
hint = (-qi::lit('&')) >> qi::lit("hint") >> '=' >>
|
||||
stringwithDot[boost::bind(&HandlerT::AddHint, handler, ::_1)];
|
||||
timestamp = (-qi::lit('&')) >> qi::lit("t") >> '=' >>
|
||||
qi::uint_[boost::bind(&HandlerT::AddTimestamp, handler, ::_1)];
|
||||
bearing = (-qi::lit('&')) >> qi::lit("b") >> '=' >>
|
||||
(qi::int_ >> -(qi::lit(',') >> qi::int_ |
|
||||
qi::attr(10)))[boost::bind<void>(add_bearing_wrapper, ::_1, ::_3)];
|
||||
u = (-qi::lit('&')) >> qi::lit("u") >> '=' >>
|
||||
qi::bool_[boost::bind(&HandlerT::SetUTurn, handler, ::_1)];
|
||||
uturns = (-qi::lit('&')) >> qi::lit("uturns") >> '=' >>
|
||||
qi::bool_[boost::bind(&HandlerT::SetAllUTurns, handler, ::_1)];
|
||||
language = (-qi::lit('&')) >> qi::lit("hl") >> '=' >>
|
||||
string[boost::bind(&HandlerT::SetLanguage, handler, ::_1)];
|
||||
alt_route = (-qi::lit('&')) >> qi::lit("alt") >> '=' >>
|
||||
qi::bool_[boost::bind(&HandlerT::SetAlternateRouteFlag, handler, ::_1)];
|
||||
old_API = (-qi::lit('&')) >> qi::lit("geomformat") >> '=' >>
|
||||
string[boost::bind(&HandlerT::SetDeprecatedAPIFlag, handler, ::_1)];
|
||||
num_results = (-qi::lit('&')) >> qi::lit("num_results") >> '=' >>
|
||||
qi::short_[boost::bind(&HandlerT::SetNumberOfResults, handler, ::_1)];
|
||||
matching_beta = (-qi::lit('&')) >> qi::lit("matching_beta") >> '=' >>
|
||||
qi::float_[boost::bind(&HandlerT::SetMatchingBeta, handler, ::_1)];
|
||||
gps_precision = (-qi::lit('&')) >> qi::lit("gps_precision") >> '=' >>
|
||||
qi::float_[boost::bind(&HandlerT::SetGPSPrecision, handler, ::_1)];
|
||||
classify = (-qi::lit('&')) >> qi::lit("classify") >> '=' >>
|
||||
qi::bool_[boost::bind(&HandlerT::SetClassify, handler, ::_1)];
|
||||
locs = (-qi::lit('&')) >> qi::lit("locs") >> '=' >>
|
||||
stringforPolyline[boost::bind(&HandlerT::SetCoordinatesFromGeometry, handler, ::_1)];
|
||||
|
||||
x = (-qi::lit('&')) >> qi::lit("tx") >> '=' >>
|
||||
qi::int_[boost::bind<void>(set_x_wrapper, ::_1, ::_3)];
|
||||
y = (-qi::lit('&')) >> qi::lit("ty") >> '=' >>
|
||||
qi::int_[boost::bind<void>(set_y_wrapper, ::_1, ::_3)];
|
||||
z = (-qi::lit('&')) >> qi::lit("tz") >> '=' >>
|
||||
qi::int_[boost::bind<void>(set_z_wrapper, ::_1, ::_3)];
|
||||
|
||||
string = +(qi::char_("a-zA-Z"));
|
||||
stringwithDot = +(qi::char_("a-zA-Z0-9_.-"));
|
||||
stringwithPercent = +(qi::char_("a-zA-Z0-9_.-") | qi::char_('[') | qi::char_(']') |
|
||||
(qi::char_('%') >> qi::char_("0-9A-Z") >> qi::char_("0-9A-Z")));
|
||||
stringforPolyline = +(qi::char_("a-zA-Z0-9_.-[]{}@?|\\%~`^"));
|
||||
}
|
||||
|
||||
qi::rule<Iterator> api_call, query, location_options, location_with_options,
|
||||
destination_with_options, source_with_options, t_u, t_h, u_h, t_u_h;
|
||||
qi::rule<Iterator, std::string()> service, zoom, output, string, jsonp, checksum, location,
|
||||
destination, source, hint, timestamp, bearing, stringwithDot, stringwithPercent, language,
|
||||
geometry, cmp, alt_route, u, uturns, old_API, num_results, matching_beta, gps_precision,
|
||||
classify, locs, instruction, stringforPolyline, x, y, z;
|
||||
|
||||
HandlerT *handler;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* API_GRAMMAR_HPP */
|
||||
@@ -1,18 +1,14 @@
|
||||
#ifndef REQUEST_HANDLER_HPP
|
||||
#define REQUEST_HANDLER_HPP
|
||||
|
||||
#include "server/service_handler.hpp"
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace osrm
|
||||
{
|
||||
class OSRM;
|
||||
namespace engine
|
||||
{
|
||||
struct RouteParameters;
|
||||
}
|
||||
namespace server
|
||||
{
|
||||
template <typename Iterator, class HandlerT> struct APIGrammar;
|
||||
|
||||
namespace http
|
||||
{
|
||||
@@ -24,17 +20,16 @@ class RequestHandler
|
||||
{
|
||||
|
||||
public:
|
||||
using APIGrammarParser = APIGrammar<std::string::iterator, engine::RouteParameters>;
|
||||
|
||||
RequestHandler();
|
||||
RequestHandler(const RequestHandler &) = delete;
|
||||
RequestHandler &operator=(const RequestHandler &) = delete;
|
||||
|
||||
void handle_request(const http::request ¤t_request, http::reply ¤t_reply);
|
||||
void RegisterRoutingMachine(OSRM *osrm);
|
||||
void RegisterServiceHandler(std::unique_ptr<ServiceHandler> service_handler);
|
||||
|
||||
void HandleRequest(const http::request ¤t_request, http::reply ¤t_reply);
|
||||
|
||||
private:
|
||||
OSRM *routing_machine;
|
||||
std::unique_ptr<ServiceHandler> service_handler;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
|
||||
#include "server/connection.hpp"
|
||||
#include "server/request_handler.hpp"
|
||||
#include "server/service_handler.hpp"
|
||||
|
||||
#include "util/integer_range.hpp"
|
||||
#include "util/simple_logger.hpp"
|
||||
@@ -76,7 +77,10 @@ class Server
|
||||
|
||||
void Stop() { io_service.stop(); }
|
||||
|
||||
RequestHandler &GetRequestHandlerPtr() { return request_handler; }
|
||||
void RegisterServiceHandler(std::unique_ptr<ServiceHandler> service_handler_)
|
||||
{
|
||||
request_handler.RegisterServiceHandler(std::move(service_handler_));
|
||||
}
|
||||
|
||||
private:
|
||||
void HandleAccept(const boost::system::error_code &e)
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
#ifndef SERVER_SERVICE_BASE_SERVICE_HPP
|
||||
#define SERVER_SERVICE_BASE_SERVICE_HPP
|
||||
|
||||
#include "engine/status.hpp"
|
||||
#include "util/coordinate.hpp"
|
||||
#include "osrm/osrm.hpp"
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace osrm
|
||||
{
|
||||
namespace server
|
||||
{
|
||||
namespace service
|
||||
{
|
||||
|
||||
class BaseService
|
||||
{
|
||||
public:
|
||||
BaseService(OSRM &routing_machine) : routing_machine(routing_machine) {}
|
||||
virtual ~BaseService() = default;
|
||||
|
||||
virtual engine::Status RunQuery(std::vector<util::FixedPointCoordinate> coordinates,
|
||||
std::string &options,
|
||||
util::json::Object &json_result) = 0;
|
||||
virtual unsigned GetVersion() = 0;
|
||||
|
||||
protected:
|
||||
OSRM &routing_machine;
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,34 @@
|
||||
#ifndef SERVER_SERVICE_ROUTE_SERVICE_HPP
|
||||
#define SERVER_SERVICE_ROUTE_SERVICE_HPP
|
||||
|
||||
#include "server/service/base_service.hpp"
|
||||
|
||||
#include "engine/status.hpp"
|
||||
#include "util/coordinate.hpp"
|
||||
#include "osrm/osrm.hpp"
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace osrm
|
||||
{
|
||||
namespace server
|
||||
{
|
||||
namespace service
|
||||
{
|
||||
|
||||
class RouteService final : public BaseService
|
||||
{
|
||||
public:
|
||||
RouteService(OSRM& routing_machine) : BaseService(routing_machine) {}
|
||||
|
||||
virtual engine::Status RunQuery(std::vector<util::FixedPointCoordinate> coordinates,
|
||||
std::string &options,
|
||||
util::json::Object &json_result) final override;
|
||||
virtual unsigned GetVersion() final override { return 1; }
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,40 @@
|
||||
#ifndef SERVER_SERVICE_HANLDER_HPP
|
||||
#define SERVER_SERVICE_HANLDER_HPP
|
||||
|
||||
#include "server/service/base_service.hpp"
|
||||
|
||||
#include "osrm/osrm.hpp"
|
||||
|
||||
#include <unordered_map>
|
||||
|
||||
namespace osrm
|
||||
{
|
||||
namespace util
|
||||
{
|
||||
namespace json
|
||||
{
|
||||
struct Object;
|
||||
}
|
||||
}
|
||||
namespace server
|
||||
{
|
||||
namespace api
|
||||
{
|
||||
struct ParsedURL;
|
||||
}
|
||||
|
||||
class ServiceHandler
|
||||
{
|
||||
public:
|
||||
ServiceHandler(osrm::EngineConfig &config);
|
||||
|
||||
engine::Status RunQuery(api::ParsedURL parsed_url, util::json::Object &json_result);
|
||||
|
||||
private:
|
||||
std::unordered_map<std::string, std::unique_ptr<service::BaseService>> service_map;
|
||||
OSRM routing_machine;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user