Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/json lib interface #1292

Merged
merged 12 commits into from
Jan 6, 2015
8 changes: 5 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ file(GLOB ServerGlob Server/*.cpp)
file(GLOB DescriptorGlob descriptors/*.cpp)
file(GLOB DatastructureGlob data_structures/search_engine_data.cpp data_structures/route_parameters.cpp Util/bearing.cpp)
list(REMOVE_ITEM DatastructureGlob data_structures/Coordinate.cpp)
file(GLOB CoordinateGlob data_structures/Coordinate.cpp)
file(GLOB CoordinateGlob data_structures/coordinate.cpp)
file(GLOB AlgorithmGlob algorithms/*.cpp)
file(GLOB HttpGlob Server/Http/*.cpp)
file(GLOB LibOSRMGlob Library/*.cpp)
Expand Down Expand Up @@ -299,7 +299,7 @@ if(WITH_TOOLS OR BUILD_TOOLS)
else()
message(FATAL_ERROR "libgdal and/or development headers not found")
endif()
add_executable(osrm-cli tools/simpleclient.cpp $<TARGET_OBJECTS:EXCEPTION> $<TARGET_OBJECTS:LOGGER>)
add_executable(osrm-cli tools/simpleclient.cpp $<TARGET_OBJECTS:EXCEPTION> $<TARGET_OBJECTS:LOGGER> $<TARGET_OBJECTS:COORDINATE>)
target_link_libraries(osrm-cli ${Boost_LIBRARIES} ${OPTIONAL_SOCKET_LIBS} OSRM)
target_link_libraries(osrm-cli ${TBB_LIBRARIES})
add_executable(osrm-io-benchmark tools/io-benchmark.cpp $<TARGET_OBJECTS:EXCEPTION> $<TARGET_OBJECTS:GITDESCRIPTION> $<TARGET_OBJECTS:LOGGER>)
Expand All @@ -321,7 +321,8 @@ if(WITH_TOOLS OR BUILD_TOOLS)
install(TARGETS osrm-springclean DESTINATION bin)
endif()

file(GLOB InstallGlob Include/osrm/*.h Library/OSRM.h)
file(GLOB InstallGlob Include/osrm/*.hpp Library/OSRM.h)
file(GLOB VariantGlob Include/variant/*.hpp)

# Add RPATH info to executables so that when they are run after being installed
# (i.e., from /usr/local/bin/) the linker can find library dependencies. For
Expand All @@ -332,6 +333,7 @@ set_property(TARGET osrm-datastore PROPERTY INSTALL_RPATH_USE_LINK_PATH TRUE)
set_property(TARGET osrm-routed PROPERTY INSTALL_RPATH_USE_LINK_PATH TRUE)

install(FILES ${InstallGlob} DESTINATION include/osrm)
install(FILES ${VariantGlob} DESTINATION include/variant)
install(TARGETS osrm-extract DESTINATION bin)
install(TARGETS osrm-prepare DESTINATION bin)
install(TARGETS osrm-datastore DESTINATION bin)
Expand Down
8 changes: 4 additions & 4 deletions Include/osrm/Coordinate.h → Include/osrm/coordinate.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,16 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

*/

#ifndef FIXED_POINT_COORDINATE_H_
#define FIXED_POINT_COORDINATE_H_
#ifndef COORDINATE_HPP_
#define COORDINATE_HPP_

#include <iosfwd> //for std::ostream
#include <string>
#include <type_traits>

namespace
{
constexpr float COORDINATE_PRECISION = 1000000.f;
constexpr static const float COORDINATE_PRECISION = 1000000.f;
}
struct FixedPointCoordinate
{
Expand Down Expand Up @@ -110,4 +110,4 @@ inline std::ostream &operator<<(std::ostream &out_stream, FixedPointCoordinate c
return out_stream;
}

#endif /* FIXED_POINT_COORDINATE_H_ */
#endif /* COORDINATE_HPP_ */
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#ifndef ROUTE_PARAMETERS_H
#define ROUTE_PARAMETERS_H

#include <osrm/Coordinate.h>
#include <osrm/coordinate.hpp>

#include <boost/fusion/container/vector/vector_fwd.hpp>

Expand All @@ -40,7 +40,7 @@ struct RouteParameters
RouteParameters();

void setZoomLevel(const short level);

void setNumberOfResults(const short number);

void setAlternateRouteFlag(const bool flag);
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
8 changes: 4 additions & 4 deletions Library/OSRM.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,16 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#ifndef OSRM_H
#define OSRM_H

#include <osrm/ServerPaths.h>
#include <osrm/server_paths.hpp>

#include <memory>

class OSRM_impl;
struct RouteParameters;

namespace http
namespace JSON
{
class Reply;
struct Object;
}

class OSRM
Expand All @@ -48,7 +48,7 @@ class OSRM
public:
explicit OSRM(ServerPaths paths, const bool use_shared_memory = false);
~OSRM();
void RunQuery(RouteParameters &route_parameters, http::Reply &reply);
int RunQuery(RouteParameters &route_parameters, JSON::Object &json_result);
};

#endif // OSRM_H
19 changes: 9 additions & 10 deletions Library/OSRM_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,6 @@ namespace boost { namespace interprocess { class named_mutex; } }
#include "OSRM_impl.h"
#include "OSRM.h"

#include <osrm/Reply.h>
#include <osrm/RouteParameters.h>
#include <osrm/ServerPaths.h>

#include "../plugins/distance_table.hpp"
#include "../plugins/hello_world.hpp"
#include "../plugins/locate.hpp"
Expand All @@ -52,6 +48,9 @@ namespace boost { namespace interprocess { class named_mutex; } }
#include <boost/interprocess/sync/named_condition.hpp>
#include <boost/interprocess/sync/scoped_lock.hpp>

#include <osrm/route_parameters.hpp>
#include <osrm/server_paths.hpp>

#include <algorithm>
#include <fstream>
#include <utility>
Expand Down Expand Up @@ -99,13 +98,12 @@ void OSRM_impl::RegisterPlugin(BasePlugin *plugin)
plugin_map.emplace(plugin->GetDescriptor(), plugin);
}

void OSRM_impl::RunQuery(RouteParameters &route_parameters, http::Reply &reply)
int OSRM_impl::RunQuery(RouteParameters &route_parameters, JSON::Object &json_result)
{
const PluginMap::const_iterator &iter = plugin_map.find(route_parameters.service);

if (plugin_map.end() != iter)
{
reply.status = http::Reply::ok;
if (barrier)
{
// lock update pending
Expand All @@ -126,7 +124,7 @@ void OSRM_impl::RunQuery(RouteParameters &route_parameters, http::Reply &reply)
->CheckAndReloadFacade();
}

iter->second->HandleRequest(route_parameters, reply);
iter->second->HandleRequest(route_parameters, json_result);
if (barrier)
{
// lock query
Expand All @@ -143,10 +141,11 @@ void OSRM_impl::RunQuery(RouteParameters &route_parameters, http::Reply &reply)
barrier->no_running_queries_condition.notify_all();
}
}
return 200;
}
else
{
reply = http::Reply::StockReply(http::Reply::badRequest);
return 400;
}
}

Expand All @@ -159,7 +158,7 @@ OSRM::OSRM(ServerPaths paths, const bool use_shared_memory)

OSRM::~OSRM() { OSRM_pimpl_.reset(); }

void OSRM::RunQuery(RouteParameters &route_parameters, http::Reply &reply)
int OSRM::RunQuery(RouteParameters &route_parameters, JSON::Object &json_result)
{
OSRM_pimpl_->RunQuery(route_parameters, reply);
return OSRM_pimpl_->RunQuery(route_parameters, json_result);
}
5 changes: 3 additions & 2 deletions Library/OSRM_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ class BasePlugin;
namespace http { class Reply; }
struct RouteParameters;

#include <osrm/ServerPaths.h>
#include <osrm/json_container.hpp>
#include <osrm/server_paths.hpp>

#include "../data_structures/query_edge.hpp"

Expand All @@ -52,7 +53,7 @@ class OSRM_impl
OSRM_impl(ServerPaths paths, const bool use_shared_memory);
OSRM_impl(const OSRM_impl &) = delete;
virtual ~OSRM_impl();
void RunQuery(RouteParameters &route_parameters, http::Reply &reply);
int RunQuery(RouteParameters &route_parameters, JSON::Object &json_result);

private:
void RegisterPlugin(BasePlugin *plugin);
Expand Down
3 changes: 1 addition & 2 deletions Server/Connection.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,9 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

// #include "RequestParser.h"
#include "Http/CompressionType.h"
#include "Http/Reply.h"
#include "Http/Request.h"

#include <osrm/Reply.h>

#include <boost/array.hpp>
#include <boost/asio.hpp>
#include <boost/config.hpp>
Expand Down
2 changes: 1 addition & 1 deletion Server/DataStructures/BaseDataFacade.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "../../Util/string_util.hpp"
#include "../../typedefs.h"

#include <osrm/Coordinate.h>
#include <osrm/coordinate.hpp>

#include <string>

Expand Down
4 changes: 2 additions & 2 deletions Server/DataStructures/InternalDataFacade.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "../../Util/graph_loader.hpp"
#include "../../Util/simple_logger.hpp"

#include <osrm/Coordinate.h>
#include <osrm/ServerPaths.h>
#include <osrm/coordinate.hpp>
#include <osrm/server_paths.hpp>

template <class EdgeDataT> class InternalDataFacade : public BaseDataFacade<EdgeDataT>
{
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion Server/Http/Reply.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

*/

#include <osrm/Reply.h>
#include "Reply.h"

#include "../../Util/cast.hpp"

Expand Down
File renamed without changes.
32 changes: 23 additions & 9 deletions Server/RequestHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,18 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "RequestHandler.h"

#include "APIGrammar.h"
#include "Http/Reply.h"
#include "Http/Request.h"

#include "../data_structures/json_container.hpp"
#include "../Library/OSRM.h"
#include "../Util/json_renderer.hpp"
#include "../Util/simple_logger.hpp"
#include "../Util/string_util.hpp"
#include "../Util/xml_renderer.hpp"
#include "../typedefs.h"

#include <osrm/Reply.h>
#include <osrm/RouteParameters.h>
#include <osrm/route_parameters.hpp>
#include <osrm/json_container.hpp>

#include <ctime>

Expand Down Expand Up @@ -84,13 +85,14 @@ void RequestHandler::handle_request(const http::Request &req, http::Reply &reply
auto iter = request.begin();
const bool result = boost::spirit::qi::parse(iter, request.end(), api_parser);

JSON::Object json_result;
// check if the was an error with the request
if (!result || (iter != request.end()))
{
reply = http::Reply::StockReply(http::Reply::badRequest);
reply.content.clear();
const auto position = std::distance(request.begin(), iter);
JSON::Object json_result;

json_result.values["status"] = 400;
std::string message = "Query string malformed close to position ";
message += cast::integral_to_string(position);
Expand All @@ -107,29 +109,41 @@ void RequestHandler::handle_request(const http::Request &req, http::Reply &reply
const std::string json_p = (route_parameters.jsonp_parameter + "(");
reply.content.insert(reply.content.end(), json_p.begin(), json_p.end());
}
routing_machine->RunQuery(route_parameters, reply);
if (!route_parameters.jsonp_parameter.empty())
{ // append brace to jsonp response
reply.content.push_back(')');
const auto return_code = routing_machine->RunQuery(route_parameters, json_result);
if (200 != return_code)
{
reply = http::Reply::StockReply(http::Reply::badRequest);
reply.content.clear();
json_result.values["status"] = 400;
std::string message = "Bad Request";
json_result.values["status_message"] = message;
JSON::render(reply.content, json_result);
return;
}

// set headers
reply.headers.emplace_back("Content-Length", cast::integral_to_string(reply.content.size()));
if ("gpx" == route_parameters.output_format)
{ // gpx file
JSON::gpx_render(reply.content, json_result.values["route"]);
reply.headers.emplace_back("Content-Type", "application/gpx+xml; charset=UTF-8");
reply.headers.emplace_back("Content-Disposition", "attachment; filename=\"route.gpx\"");
}
else if (route_parameters.jsonp_parameter.empty())
{ // json file
JSON::render(reply.content, json_result);
reply.headers.emplace_back("Content-Type", "application/json; charset=UTF-8");
reply.headers.emplace_back("Content-Disposition", "inline; filename=\"response.json\"");
}
else
{ // jsonp
JSON::render(reply.content, json_result);
reply.headers.emplace_back("Content-Type", "text/javascript; charset=UTF-8");
reply.headers.emplace_back("Content-Disposition", "inline; filename=\"response.js\"");
}
if (!route_parameters.jsonp_parameter.empty())
{ // append brace to jsonp response
reply.content.push_back(')');
}
}
catch (const std::exception &e)
{
Expand Down
2 changes: 1 addition & 1 deletion Server/RequestParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#define REQUEST_PARSER_H

#include "Http/CompressionType.h"
#include <osrm/Header.h>
#include "Http/Header.h"

#include <boost/logic/tribool.hpp>
#include <boost/tuple/tuple.hpp>
Expand Down
3 changes: 2 additions & 1 deletion UnitTests/Algorithms/DouglasPeuckerTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,13 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

#include "../../algorithms/douglas_peucker.hpp"
#include "../../data_structures/segment_information.hpp"
#include "../../Include/osrm/Coordinate.h"

#include <boost/test/unit_test.hpp>
#include <boost/test/test_case_template.hpp>
#include <boost/mpl/list.hpp>

#include <osrm/coordinate.hpp>

#include <iostream>

BOOST_AUTO_TEST_SUITE(douglas_peucker)
Expand Down
4 changes: 2 additions & 2 deletions UnitTests/data_structures/StaticRTreeTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "../../Util/floating_point.hpp"
#include "../../typedefs.h"

#include <osrm/Coordinate.h>

#include <boost/test/unit_test.hpp>
#include <boost/test/test_case_template.hpp>
#include <boost/mpl/list.hpp>

#include <osrm/coordinate.hpp>

#include <random>
#include <unordered_set>

Expand Down
2 changes: 1 addition & 1 deletion Util/DataStoreOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "osrm_exception.hpp"
#include "simple_logger.hpp"

#include <osrm/ServerPaths.h>
#include <osrm/server_paths.hpp>

#include <boost/any.hpp>
#include <boost/filesystem.hpp>
Expand Down
4 changes: 2 additions & 2 deletions Util/ProgramOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "osrm_exception.hpp"
#include "simple_logger.hpp"

#include <osrm/ServerPaths.h>

#include <boost/any.hpp>
#include <boost/program_options.hpp>

#include <osrm/server_paths.hpp>

#include <fstream>
#include <string>

Expand Down
3 changes: 2 additions & 1 deletion Util/compute_angle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

#include "TrigonometryTables.h"
#include "../Util/MercatorUtil.h"
#include <osrm/Coordinate.h>

#include <osrm/coordinate.hpp>

#include <cmath>

Expand Down
Loading