Service skeletons for nearest, trip, match
This commit is contained in:
parent
c59647ad2f
commit
4d20dea271
@ -24,6 +24,7 @@ class BaseService
|
|||||||
virtual engine::Status RunQuery(std::vector<util::FixedPointCoordinate> coordinates,
|
virtual engine::Status RunQuery(std::vector<util::FixedPointCoordinate> coordinates,
|
||||||
std::string &options,
|
std::string &options,
|
||||||
util::json::Object &json_result) = 0;
|
util::json::Object &json_result) = 0;
|
||||||
|
|
||||||
virtual unsigned GetVersion() = 0;
|
virtual unsigned GetVersion() = 0;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
35
include/server/service/match_service.hpp
Normal file
35
include/server/service/match_service.hpp
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
#ifndef SERVER_SERVICE_MATCH_SERVICE_HPP
|
||||||
|
#define SERVER_SERVICE_MATCH_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 MatchService final : public BaseService
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
MatchService(OSRM &routing_machine) : BaseService(routing_machine) {}
|
||||||
|
|
||||||
|
engine::Status RunQuery(std::vector<util::FixedPointCoordinate> coordinates,
|
||||||
|
std::string &options,
|
||||||
|
util::json::Object &result) final override;
|
||||||
|
|
||||||
|
unsigned GetVersion() final override { return 1; }
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
35
include/server/service/nearest_service.hpp
Normal file
35
include/server/service/nearest_service.hpp
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
#ifndef SERVER_SERVICE_NEAREST_SERVICE_HPP
|
||||||
|
#define SERVER_SERVICE_NEAREST_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 NearestService final : public BaseService
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
NearestService(OSRM &routing_machine) : BaseService(routing_machine) {}
|
||||||
|
|
||||||
|
engine::Status RunQuery(std::vector<util::FixedPointCoordinate> coordinates,
|
||||||
|
std::string &options,
|
||||||
|
util::json::Object &result) final override;
|
||||||
|
|
||||||
|
unsigned GetVersion() final override { return 1; }
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
@ -20,12 +20,13 @@ namespace service
|
|||||||
class RouteService final : public BaseService
|
class RouteService final : public BaseService
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
RouteService(OSRM& routing_machine) : BaseService(routing_machine) {}
|
RouteService(OSRM &routing_machine) : BaseService(routing_machine) {}
|
||||||
|
|
||||||
virtual engine::Status RunQuery(std::vector<util::FixedPointCoordinate> coordinates,
|
engine::Status RunQuery(std::vector<util::FixedPointCoordinate> coordinates,
|
||||||
std::string &options,
|
std::string &options,
|
||||||
util::json::Object &json_result) final override;
|
util::json::Object &result) final override;
|
||||||
virtual unsigned GetVersion() final override { return 1; }
|
|
||||||
|
unsigned GetVersion() final override { return 1; }
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,12 +20,13 @@ namespace service
|
|||||||
class TableService final : public BaseService
|
class TableService final : public BaseService
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
TableService(OSRM& routing_machine) : BaseService(routing_machine) {}
|
TableService(OSRM &routing_machine) : BaseService(routing_machine) {}
|
||||||
|
|
||||||
virtual engine::Status RunQuery(std::vector<util::FixedPointCoordinate> coordinates,
|
engine::Status RunQuery(std::vector<util::FixedPointCoordinate> coordinates,
|
||||||
std::string &options,
|
std::string &options,
|
||||||
util::json::Object &json_result) final override;
|
util::json::Object &result) final override;
|
||||||
virtual unsigned GetVersion() final override { return 1; }
|
|
||||||
|
unsigned GetVersion() final override { return 1; }
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
35
include/server/service/trip_service.hpp
Normal file
35
include/server/service/trip_service.hpp
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
#ifndef SERVER_SERVICE_TRIP_SERVICE_HPP
|
||||||
|
#define SERVER_SERVICE_TRIP_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 TripService final : public BaseService
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
TripService(OSRM &routing_machine) : BaseService(routing_machine) {}
|
||||||
|
|
||||||
|
engine::Status RunQuery(std::vector<util::FixedPointCoordinate> coordinates,
|
||||||
|
std::string &options,
|
||||||
|
util::json::Object &result) final override;
|
||||||
|
|
||||||
|
unsigned GetVersion() final override { return 1; }
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
26
src/server/service/match_service.cpp
Normal file
26
src/server/service/match_service.cpp
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
#include "server/service/match_service.hpp"
|
||||||
|
|
||||||
|
#include "engine/api/match_parameters.hpp"
|
||||||
|
#include "server/api/parameters_parser.hpp"
|
||||||
|
|
||||||
|
#include "util/json_container.hpp"
|
||||||
|
|
||||||
|
#include <boost/format.hpp>
|
||||||
|
|
||||||
|
namespace osrm
|
||||||
|
{
|
||||||
|
namespace server
|
||||||
|
{
|
||||||
|
namespace service
|
||||||
|
{
|
||||||
|
|
||||||
|
engine::Status RouteService::RunQuery(std::vector<util::FixedPointCoordinate> coordinates,
|
||||||
|
std::string &options,
|
||||||
|
util::json::Object &json_result)
|
||||||
|
{
|
||||||
|
// TODO(daniel-j-h)
|
||||||
|
return Status::Error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
26
src/server/service/nearest_service.cpp
Normal file
26
src/server/service/nearest_service.cpp
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
#include "server/service/nearest_service.hpp"
|
||||||
|
|
||||||
|
#include "engine/api/nearest_parameters.hpp"
|
||||||
|
#include "server/api/parameters_parser.hpp"
|
||||||
|
|
||||||
|
#include "util/json_container.hpp"
|
||||||
|
|
||||||
|
#include <boost/format.hpp>
|
||||||
|
|
||||||
|
namespace osrm
|
||||||
|
{
|
||||||
|
namespace server
|
||||||
|
{
|
||||||
|
namespace service
|
||||||
|
{
|
||||||
|
|
||||||
|
engine::Status RouteService::RunQuery(std::vector<util::FixedPointCoordinate> coordinates,
|
||||||
|
std::string &options,
|
||||||
|
util::json::Object &json_result)
|
||||||
|
{
|
||||||
|
// TODO(daniel-j-h)
|
||||||
|
return Status::Error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
26
src/server/service/trip_service.cpp
Normal file
26
src/server/service/trip_service.cpp
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
#include "server/service/trip_service.hpp"
|
||||||
|
|
||||||
|
#include "engine/api/trip_parameters.hpp"
|
||||||
|
#include "server/api/parameters_parser.hpp"
|
||||||
|
|
||||||
|
#include "util/json_container.hpp"
|
||||||
|
|
||||||
|
#include <boost/format.hpp>
|
||||||
|
|
||||||
|
namespace osrm
|
||||||
|
{
|
||||||
|
namespace server
|
||||||
|
{
|
||||||
|
namespace service
|
||||||
|
{
|
||||||
|
|
||||||
|
engine::Status RouteService::RunQuery(std::vector<util::FixedPointCoordinate> coordinates,
|
||||||
|
std::string &options,
|
||||||
|
util::json::Object &json_result)
|
||||||
|
{
|
||||||
|
// TODO(daniel-j-h)
|
||||||
|
return Status::Error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -2,6 +2,9 @@
|
|||||||
|
|
||||||
#include "server/service/route_service.hpp"
|
#include "server/service/route_service.hpp"
|
||||||
#include "server/service/table_service.hpp"
|
#include "server/service/table_service.hpp"
|
||||||
|
#include "server/service/nearest_service.hpp"
|
||||||
|
#include "server/service/trip_service.hpp"
|
||||||
|
#include "server/service/match_service.hpp"
|
||||||
|
|
||||||
#include "server/api/parsed_url.hpp"
|
#include "server/api/parsed_url.hpp"
|
||||||
#include "util/json_util.hpp"
|
#include "util/json_util.hpp"
|
||||||
@ -11,31 +14,34 @@ namespace osrm
|
|||||||
{
|
{
|
||||||
namespace server
|
namespace server
|
||||||
{
|
{
|
||||||
ServiceHandler::ServiceHandler(osrm::EngineConfig &config) : routing_machine(config)
|
ServiceHandler::ServiceHandler(osrm::EngineConfig &config) : routing_machine(config)
|
||||||
|
{
|
||||||
|
service_map["route"] = util::make_unique<service::RouteService>(routing_machine);
|
||||||
|
service_map["table"] = util::make_unique<service::TableService>(routing_machine);
|
||||||
|
service_map["nearest"] = util::make_unique<service::NearestService>(routing_machine);
|
||||||
|
service_map["trip"] = util::make_unique<service::TripService>(routing_machine);
|
||||||
|
service_map["match"] = util::make_unique<service::MatchService>(routing_machine);
|
||||||
|
}
|
||||||
|
|
||||||
|
engine::Status ServiceHandler::RunQuery(api::ParsedURL parsed_url, util::json::Object &result)
|
||||||
|
{
|
||||||
|
const auto &service_iter = service_map.find(parsed_url.service);
|
||||||
|
if (service_iter == service_map.end())
|
||||||
{
|
{
|
||||||
service_map["route"] = util::make_unique<service::RouteService>(routing_machine);
|
result.values["code"] = "invalid-service";
|
||||||
service_map["table"] = util::make_unique<service::TableService>(routing_machine);
|
result.values["message"] = "Service " + parsed_url.service + " not found!";
|
||||||
|
return engine::Status::Error;
|
||||||
|
}
|
||||||
|
auto &service = service_iter->second;
|
||||||
|
|
||||||
|
if (service->GetVersion() != parsed_url.version)
|
||||||
|
{
|
||||||
|
result.values["code"] = "invalid-version";
|
||||||
|
result.values["message"] = "Service " + parsed_url.service + " not found!";
|
||||||
|
return engine::Status::Error;
|
||||||
}
|
}
|
||||||
|
|
||||||
engine::Status ServiceHandler::RunQuery(api::ParsedURL parsed_url, util::json::Object &json_result)
|
return service->RunQuery(std::move(parsed_url.coordinates), parsed_url.options, result);
|
||||||
{
|
}
|
||||||
const auto& service_iter = service_map.find(parsed_url.service);
|
|
||||||
if (service_iter == service_map.end())
|
|
||||||
{
|
|
||||||
json_result.values["code"] = "invalid-service";
|
|
||||||
json_result.values["message"] = "Service " + parsed_url.service + " not found!";
|
|
||||||
return engine::Status::Error;
|
|
||||||
}
|
|
||||||
auto &service = service_iter->second;
|
|
||||||
|
|
||||||
if (service->GetVersion() != parsed_url.version)
|
|
||||||
{
|
|
||||||
json_result.values["code"] = "invalid-version";
|
|
||||||
json_result.values["message"] = "Service " + parsed_url.service + " not found!";
|
|
||||||
return engine::Status::Error;
|
|
||||||
}
|
|
||||||
|
|
||||||
return service->RunQuery(std::move(parsed_url.coordinates), parsed_url.options, json_result);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user