diff --git a/CMakeLists.txt b/CMakeLists.txt index 14703f433..7d9a6906d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -69,13 +69,13 @@ file(GLOB PrepareGlob contractor/*.cpp data_structures/hilbert_value.cpp Util/co set(PrepareSources prepare.cpp ${PrepareGlob}) add_executable(osrm-prepare ${PrepareSources} $ $ $ $ $ $ $ $) -file(GLOB ServerGlob Server/*.cpp) +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 AlgorithmGlob algorithms/*.cpp) -file(GLOB HttpGlob Server/http/*.cpp) +file(GLOB HttpGlob server/http/*.cpp) file(GLOB LibOSRMGlob Library/*.cpp) file(GLOB DataStructureTestsGlob unit_tests/data_structures/*.cpp data_structures/hilbert_value.cpp) file(GLOB AlgorithmTestsGlob unit_tests/algorithms/*.cpp) diff --git a/Library/OSRM_impl.cpp b/Library/OSRM_impl.cpp index 4a9fdbd76..cbb33a904 100644 --- a/Library/OSRM_impl.cpp +++ b/Library/OSRM_impl.cpp @@ -42,10 +42,10 @@ class named_mutex; #include "../plugins/nearest.hpp" #include "../plugins/timestamp.hpp" #include "../plugins/viaroute.hpp" -#include "../Server/data_structures/datafacade_base.hpp" -#include "../Server/data_structures/internal_datafacade.hpp" -#include "../Server/data_structures/shared_barriers.hpp" -#include "../Server/data_structures/shared_datafacade.hpp" +#include "../server/data_structures/datafacade_base.hpp" +#include "../server/data_structures/internal_datafacade.hpp" +#include "../server/data_structures/shared_barriers.hpp" +#include "../server/data_structures/shared_datafacade.hpp" #include "../Util/make_unique.hpp" #include "../Util/ProgramOptions.h" #include "../Util/simple_logger.hpp" diff --git a/Server/APIGrammar.h b/Server/APIGrammar.h deleted file mode 100644 index 83a5cd03b..000000000 --- a/Server/APIGrammar.h +++ /dev/null @@ -1,74 +0,0 @@ -/* - -Copyright (c) 2013, Project OSRM, Dennis Luxen, others -All rights reserved. - -Redistribution and use in source and binary forms, with or without modification, -are permitted provided that the following conditions are met: - -Redistributions of source code must retain the above copyright notice, this list -of conditions and the following disclaimer. -Redistributions in binary form must reproduce the above copyright notice, this -list of conditions and the following disclaimer in the documentation and/or -other materials provided with the distribution. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND -ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR -ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON -ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -*/ - -#ifndef APIGRAMMAR_H_ -#define APIGRAMMAR_H_ - -#include -#include -#include - -namespace qi = boost::spirit::qi; - -template -struct APIGrammar : qi::grammar -{ - explicit APIGrammar(HandlerT * h) : APIGrammar::base_type(api_call), handler(h) - { - api_call = qi::lit('/') >> string[boost::bind(&HandlerT::setService, handler, ::_1)] >> *(query) >> -(uturns); - query = ('?') >> (+(zoom | output | jsonp | checksum | location | hint | u | cmp | language | instruction | geometry | alt_route | old_API | num_results) ) ; - - zoom = (-qi::lit('&')) >> qi::lit('z') >> '=' >> qi::short_[boost::bind(&HandlerT::setZoomLevel, handler, ::_1)]; - output = (-qi::lit('&')) >> qi::lit("output") >> '=' >> string[boost::bind(&HandlerT::setOutputFormat, handler, ::_1)]; - 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(&HandlerT::addCoordinate, handler, ::_1)]; - hint = (-qi::lit('&')) >> qi::lit("hint") >> '=' >> stringwithDot[boost::bind(&HandlerT::addHint, handler, ::_1)]; - 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)]; - - 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") )); - } - - qi::rule api_call, query; - qi::rule service, zoom, output, string, jsonp, checksum, location, hint, - stringwithDot, stringwithPercent, language, instruction, geometry, - cmp, alt_route, u, uturns, old_API, num_results; - - HandlerT * handler; -}; - -#endif /* APIGRAMMAR_H_ */ diff --git a/Server/Connection.cpp b/Server/Connection.cpp index 38f64a116..1dd5ae5f1 100644 --- a/Server/Connection.cpp +++ b/Server/Connection.cpp @@ -25,9 +25,9 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include "Connection.h" -#include "RequestHandler.h" -#include "RequestParser.h" +#include "connection.hpp" +#include "request_handler.hpp" +#include "request_parser.hpp" #include #include diff --git a/Util/ProgramOptions.h b/Util/ProgramOptions.h index 3e2471189..0c350fc75 100644 --- a/Util/ProgramOptions.h +++ b/Util/ProgramOptions.h @@ -40,7 +40,6 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include - const static unsigned INIT_OK_START_ENGINE = 0; const static unsigned INIT_OK_DO_NOT_START_ENGINE = 1; const static unsigned INIT_FAILED = -1; @@ -157,45 +156,36 @@ inline unsigned GenerateServerProgramOptions(const int argc, // declare a group of options that will be allowed only on command line boost::program_options::options_description generic_options("Options"); generic_options.add_options()("version,v", "Show version")("help,h", "Show this help message")( - "config,c", - boost::program_options::value(&paths["config"]) - ->default_value("server.ini"), + "config,c", boost::program_options::value(&paths["config"]) + ->default_value("server.ini"), "Path to a configuration file")( - "trial", - boost::program_options::value(&trial)->implicit_value(true), + "trial", boost::program_options::value(&trial)->implicit_value(true), "Quit after initialization"); // declare a group of options that will be allowed both on command line // as well as in a config file boost::program_options::options_description config_options("Configuration"); config_options.add_options()( - "hsgrdata", - boost::program_options::value(&paths["hsgrdata"]), + "hsgrdata", boost::program_options::value(&paths["hsgrdata"]), ".hsgr file")("nodesdata", boost::program_options::value(&paths["nodesdata"]), ".nodes file")( - "edgesdata", - boost::program_options::value(&paths["edgesdata"]), + "edgesdata", boost::program_options::value(&paths["edgesdata"]), ".edges file")("geometry", boost::program_options::value(&paths["geometries"]), ".geometry file")( - "ramindex", - boost::program_options::value(&paths["ramindex"]), + "ramindex", boost::program_options::value(&paths["ramindex"]), ".ramIndex file")( - "fileindex", - boost::program_options::value(&paths["fileindex"]), + "fileindex", boost::program_options::value(&paths["fileindex"]), "File index file")( - "namesdata", - boost::program_options::value(&paths["namesdata"]), + "namesdata", boost::program_options::value(&paths["namesdata"]), ".names file")("timestamp", boost::program_options::value(&paths["timestamp"]), ".timestamp file")( - "ip,i", - boost::program_options::value(&ip_address)->default_value("0.0.0.0"), - "IP address")( - "port,p", boost::program_options::value(&ip_port)->default_value(5000), "TCP/IP port")( - "threads,t", - boost::program_options::value(&requested_num_threads)->default_value(8), + "ip,i", boost::program_options::value(&ip_address)->default_value("0.0.0.0"), + "IP address")("port,p", boost::program_options::value(&ip_port)->default_value(5000), + "TCP/IP port")( + "threads,t", boost::program_options::value(&requested_num_threads)->default_value(8), "Number of threads to use")( "shared-memory,s", boost::program_options::value(&use_shared_memory)->implicit_value(true), @@ -208,8 +198,7 @@ inline unsigned GenerateServerProgramOptions(const int argc, // file, but will not be shown to the user boost::program_options::options_description hidden_options("Hidden options"); hidden_options.add_options()( - "base,b", - boost::program_options::value(&paths["base"]), + "base,b", boost::program_options::value(&paths["base"]), "base path to .osrm file"); // positional option diff --git a/datastore.cpp b/datastore.cpp index 9acb4fe57..d33f6f603 100644 --- a/datastore.cpp +++ b/datastore.cpp @@ -33,9 +33,9 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "data_structures/static_graph.hpp" #include "data_structures/static_rtree.hpp" #include "data_structures/turn_instructions.hpp" -#include "Server/data_structures/datafacade_base.hpp" -#include "Server/data_structures/shared_datatype.hpp" -#include "Server/data_structures/shared_barriers.hpp" +#include "server/data_structures/datafacade_base.hpp" +#include "server/data_structures/shared_datatype.hpp" +#include "server/data_structures/shared_barriers.hpp" #include "Util/BoostFileSystemFix.h" #include "Util/DataStoreOptions.h" #include "Util/simple_logger.hpp" diff --git a/routed.cpp b/routed.cpp index 5768c3d03..96b20133f 100644 --- a/routed.cpp +++ b/routed.cpp @@ -26,7 +26,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "Library/OSRM.h" -#include "Server/Server.h" +#include "server/server.hpp" #include "Util/git_sha.hpp" #include "Util/ProgramOptions.h" #include "Util/simple_logger.hpp" diff --git a/server/Http/Reply.cpp b/server/Http/Reply.cpp new file mode 100644 index 000000000..89b931b05 --- /dev/null +++ b/server/Http/Reply.cpp @@ -0,0 +1,130 @@ +/* + +Copyright (c) 2015, Project OSRM, Dennis Luxen, others +All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, +are permitted provided that the following conditions are met: + +Redistributions of source code must retain the above copyright notice, this list +of conditions and the following disclaimer. +Redistributions in binary form must reproduce the above copyright notice, this +list of conditions and the following disclaimer in the documentation and/or +other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR +ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON +ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +*/ + +#include "reply.hpp" + +#include "../../Util/cast.hpp" + +namespace http +{ + +const char ok_html[] = ""; +const char bad_request_html[] = "{\"status\": 400,\"status_message\":\"Bad Request\"}"; +const char internal_server_error_html[] = + "{\"status\": 500,\"status_message\":\"Internal Server Error\"}"; +const char seperators[] = {':', ' '}; +const char crlf[] = {'\r', '\n'}; +const std::string http_ok_string = "HTTP/1.0 200 OK\r\n"; +const std::string http_bad_request_string = "HTTP/1.0 400 Bad Request\r\n"; +const std::string http_internal_server_error_string = "HTTP/1.0 500 Internal Server Error\r\n"; + +void reply::set_size(const std::size_t size) +{ + for (header &h : headers) + { + if ("Content-Length" == h.name) + { + h.value = cast::integral_to_string(size); + } + } +} + +void reply::set_uncompressed_size() { set_size(content.size()); } + +std::vector reply::to_buffers() +{ + std::vector buffers; + buffers.push_back(status_to_buffer(status)); + for (const header &h : headers) + { + buffers.push_back(boost::asio::buffer(h.name)); + buffers.push_back(boost::asio::buffer(seperators)); + buffers.push_back(boost::asio::buffer(h.value)); + buffers.push_back(boost::asio::buffer(crlf)); + } + buffers.push_back(boost::asio::buffer(crlf)); + buffers.push_back(boost::asio::buffer(content)); + return buffers; +} + +std::vector reply::headers_to_buffers() +{ + std::vector buffers; + buffers.push_back(status_to_buffer(status)); + for (const header ¤t_header : headers) + { + buffers.push_back(boost::asio::buffer(current_header.name)); + buffers.push_back(boost::asio::buffer(seperators)); + buffers.push_back(boost::asio::buffer(current_header.value)); + buffers.push_back(boost::asio::buffer(crlf)); + } + buffers.push_back(boost::asio::buffer(crlf)); + return buffers; +} + +reply reply::stock_reply(const reply::status_type status) +{ + reply reply; + reply.status = status; + reply.content.clear(); + + const std::string status_string = reply.status_to_string(status); + reply.content.insert(reply.content.end(), status_string.begin(), status_string.end()); + reply.headers.emplace_back("Access-Control-Allow-Origin", "*"); + reply.headers.emplace_back("Content-Length", cast::integral_to_string(reply.content.size())); + reply.headers.emplace_back("Content-Type", "text/html"); + return reply; +} + +std::string reply::status_to_string(const reply::status_type status) +{ + if (reply::ok == status) + { + return ok_html; + } + if (reply::bad_request == status) + { + return bad_request_html; + } + return internal_server_error_html; +} + +boost::asio::const_buffer reply::status_to_buffer(const reply::status_type status) +{ + if (reply::ok == status) + { + return boost::asio::buffer(http_ok_string); + } + if (reply::internal_server_error == status) + { + return boost::asio::buffer(http_internal_server_error_string); + } + return boost::asio::buffer(http_bad_request_string); +} + +reply::reply() : status(ok) {} +} diff --git a/server/api_grammar.hpp b/server/api_grammar.hpp new file mode 100644 index 000000000..0697e21c8 --- /dev/null +++ b/server/api_grammar.hpp @@ -0,0 +1,92 @@ +/* + +Copyright (c) 2013, Project OSRM, Dennis Luxen, others +All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, +are permitted provided that the following conditions are met: + +Redistributions of source code must retain the above copyright notice, this list +of conditions and the following disclaimer. +Redistributions in binary form must reproduce the above copyright notice, this +list of conditions and the following disclaimer in the documentation and/or +other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR +ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON +ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +*/ + +#ifndef API_GRAMMAR_HPP +#define API_GRAMMAR_HPP + +#include +#include +#include + +namespace qi = boost::spirit::qi; + +template struct APIGrammar : qi::grammar +{ + explicit APIGrammar(HandlerT *h) : APIGrammar::base_type(api_call), handler(h) + { + api_call = qi::lit('/') >> string[boost::bind(&HandlerT::setService, handler, ::_1)] >> + *(query) >> -(uturns); + query = ('?') >> (+(zoom | output | jsonp | checksum | location | hint | u | cmp | + language | instruction | geometry | alt_route | old_API | num_results)); + + zoom = (-qi::lit('&')) >> qi::lit('z') >> '=' >> + qi::short_[boost::bind(&HandlerT::setZoomLevel, handler, ::_1)]; + output = (-qi::lit('&')) >> qi::lit("output") >> '=' >> + string[boost::bind(&HandlerT::setOutputFormat, handler, ::_1)]; + 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(&HandlerT::addCoordinate, handler, ::_1)]; + hint = (-qi::lit('&')) >> qi::lit("hint") >> '=' >> + stringwithDot[boost::bind(&HandlerT::addHint, handler, ::_1)]; + 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)]; + + 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"))); + } + + qi::rule api_call, query; + qi::rule service, zoom, output, string, jsonp, checksum, location, + hint, stringwithDot, stringwithPercent, language, instruction, geometry, cmp, alt_route, u, + uturns, old_API, num_results; + + HandlerT *handler; +}; + +#endif /* API_GRAMMAR_HPP */ diff --git a/server/connection.cpp b/server/connection.cpp new file mode 100644 index 000000000..1dd5ae5f1 --- /dev/null +++ b/server/connection.cpp @@ -0,0 +1,168 @@ +/* + +Copyright (c) 2015, Project OSRM, Dennis Luxen, others +All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, +are permitted provided that the following conditions are met: + +Redistributions of source code must retain the above copyright notice, this list +of conditions and the following disclaimer. +Redistributions in binary form must reproduce the above copyright notice, this +list of conditions and the following disclaimer in the documentation and/or +other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR +ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON +ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +*/ + +#include "connection.hpp" +#include "request_handler.hpp" +#include "request_parser.hpp" + +#include +#include +#include +#include + +#include +#include + +namespace http +{ + +Connection::Connection(boost::asio::io_service &io_service, RequestHandler &handler) + : strand(io_service), TCP_socket(io_service), request_handler(handler) +{ +} + +boost::asio::ip::tcp::socket &Connection::socket() { return TCP_socket; } + +/// Start the first asynchronous operation for the connection. +void Connection::start() +{ + TCP_socket.async_read_some( + boost::asio::buffer(incoming_data_buffer), + strand.wrap(boost::bind(&Connection::handle_read, this->shared_from_this(), + boost::asio::placeholders::error, + boost::asio::placeholders::bytes_transferred))); +} + +void Connection::handle_read(const boost::system::error_code &error, std::size_t bytes_transferred) +{ + if (error) + { + return; + } + + // no error detected, let's parse the request + compression_type compression_type(no_compression); + osrm::tribool result; + std::tie(result, compression_type) = RequestParser().parse( + request, incoming_data_buffer.data(), incoming_data_buffer.data() + bytes_transferred); + + // the request has been parsed + if (result == osrm::tribool::yes) + { + request.endpoint = TCP_socket.remote_endpoint().address(); + request_handler.handle_request(request, reply); + + // Header compression_header; + std::vector compressed_output; + std::vector output_buffer; + + // compress the result w/ gzip/deflate if requested + switch (compression_type) + { + case deflate_rfc1951: + // use deflate for compression + reply.headers.insert(reply.headers.begin(), {"Content-Encoding", "deflate"}); + compressed_output = compress_buffers(reply.content, compression_type); + reply.set_size(static_cast(compressed_output.size())); + output_buffer = reply.headers_to_buffers(); + output_buffer.push_back(boost::asio::buffer(compressed_output)); + break; + case gzip_rfc1952: + // use gzip for compression + reply.headers.insert(reply.headers.begin(), {"Content-Encoding", "gzip"}); + compressed_output = compress_buffers(reply.content, compression_type); + reply.set_size(static_cast(compressed_output.size())); + output_buffer = reply.headers_to_buffers(); + output_buffer.push_back(boost::asio::buffer(compressed_output)); + break; + case no_compression: + // don't use any compression + reply.set_uncompressed_size(); + output_buffer = reply.to_buffers(); + break; + } + // write result to stream + boost::asio::async_write( + TCP_socket, output_buffer, + strand.wrap(boost::bind(&Connection::handle_write, this->shared_from_this(), + boost::asio::placeholders::error))); + } + else if (result == osrm::tribool::no) + { // request is not parseable + reply = reply::stock_reply(reply::bad_request); + + boost::asio::async_write( + TCP_socket, reply.to_buffers(), + strand.wrap(boost::bind(&Connection::handle_write, this->shared_from_this(), + boost::asio::placeholders::error))); + } + else + { + // we don't have a result yet, so continue reading + TCP_socket.async_read_some( + boost::asio::buffer(incoming_data_buffer), + strand.wrap(boost::bind(&Connection::handle_read, this->shared_from_this(), + boost::asio::placeholders::error, + boost::asio::placeholders::bytes_transferred))); + } +} + +/// Handle completion of a write operation. +void Connection::handle_write(const boost::system::error_code &error) +{ + if (!error) + { + // Initiate graceful connection closure. + boost::system::error_code ignore_error; + TCP_socket.shutdown(boost::asio::ip::tcp::socket::shutdown_both, ignore_error); + } +} + +std::vector Connection::compress_buffers(const std::vector &uncompressed_data, + const compression_type compression_type) +{ + boost::iostreams::gzip_params compression_parameters; + + // there's a trade-off between speed and size. speed wins + compression_parameters.level = boost::iostreams::zlib::best_speed; + // check which compression flavor is used + if (deflate_rfc1951 == compression_type) + { + compression_parameters.noheader = true; + } + + std::vector compressed_data; + // plug data into boost's compression stream + boost::iostreams::filtering_ostream gzip_stream; + gzip_stream.push(boost::iostreams::gzip_compressor(compression_parameters)); + gzip_stream.push(boost::iostreams::back_inserter(compressed_data)); + gzip_stream.write(&uncompressed_data[0], uncompressed_data.size()); + boost::iostreams::close(gzip_stream); + + return compressed_data; +} +} diff --git a/Server/Connection.h b/server/connection.hpp similarity index 97% rename from Server/Connection.h rename to server/connection.hpp index 8d0cfda7d..ad9335523 100644 --- a/Server/Connection.h +++ b/server/connection.hpp @@ -25,8 +25,8 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef CONNECTION_H -#define CONNECTION_H +#ifndef CONNECTION_HPP +#define CONNECTION_HPP #include "http/compression_type.hpp" #include "http/reply.hpp" @@ -89,4 +89,4 @@ class Connection : public std::enable_shared_from_this } // namespace http -#endif // CONNECTION_H +#endif // CONNECTION_HPP diff --git a/server/data_structures/datafacade_base.hpp b/server/data_structures/datafacade_base.hpp new file mode 100644 index 000000000..2de79f915 --- /dev/null +++ b/server/data_structures/datafacade_base.hpp @@ -0,0 +1,126 @@ +/* + +Copyright (c) 2015, Project OSRM, Dennis Luxen, others +All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, +are permitted provided that the following conditions are met: + +Redistributions of source code must retain the above copyright notice, this list +of conditions and the following disclaimer. +Redistributions in binary form must reproduce the above copyright notice, this +list of conditions and the following disclaimer in the documentation and/or +other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR +ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON +ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +*/ + +#ifndef DATAFACADE_BASE_HPP +#define DATAFACADE_BASE_HPP + +// Exposes all data access interfaces to the algorithms via base class ptr + +#include "../../data_structures/edge_based_node.hpp" +#include "../../data_structures/external_memory_node.hpp" +#include "../../data_structures/phantom_node.hpp" +#include "../../data_structures/turn_instructions.hpp" +#include "../../Util/integer_range.hpp" +#include "../../Util/osrm_exception.hpp" +#include "../../Util/string_util.hpp" +#include "../../typedefs.h" + +#include + +#include + +typedef osrm::range EdgeRange; + +template class BaseDataFacade +{ + public: + typedef EdgeBasedNode RTreeLeaf; + typedef EdgeDataT EdgeData; + BaseDataFacade() {} + virtual ~BaseDataFacade() {} + + // search graph access + virtual unsigned GetNumberOfNodes() const = 0; + + virtual unsigned GetNumberOfEdges() const = 0; + + virtual unsigned GetOutDegree(const NodeID n) const = 0; + + virtual NodeID GetTarget(const EdgeID e) const = 0; + + // virtual EdgeDataT &GetEdgeData(const EdgeID e) = 0; + + virtual const EdgeDataT &GetEdgeData(const EdgeID e) const = 0; + + virtual EdgeID BeginEdges(const NodeID n) const = 0; + + virtual EdgeID EndEdges(const NodeID n) const = 0; + + virtual EdgeRange GetAdjacentEdgeRange(const NodeID node) const = 0; + + // searches for a specific edge + virtual EdgeID FindEdge(const NodeID from, const NodeID to) const = 0; + + virtual EdgeID FindEdgeInEitherDirection(const NodeID from, const NodeID to) const = 0; + + virtual EdgeID + FindEdgeIndicateIfReverse(const NodeID from, const NodeID to, bool &result) const = 0; + + // node and edge information access + virtual FixedPointCoordinate GetCoordinateOfNode(const unsigned id) const = 0; + + virtual bool EdgeIsCompressed(const unsigned id) const = 0; + + virtual unsigned GetGeometryIndexForEdgeID(const unsigned id) const = 0; + + virtual void GetUncompressedGeometry(const unsigned id, + std::vector &result_nodes) const = 0; + + virtual TurnInstruction GetTurnInstructionForEdgeID(const unsigned id) const = 0; + + virtual TravelMode GetTravelModeForEdgeID(const unsigned id) const = 0; + + virtual bool LocateClosestEndPointForCoordinate(const FixedPointCoordinate &input_coordinate, + FixedPointCoordinate &result, + const unsigned zoom_level = 18) = 0; + + virtual bool + IncrementalFindPhantomNodeForCoordinate(const FixedPointCoordinate &input_coordinate, + std::vector &resulting_phantom_node_vector, + const unsigned number_of_results) = 0; + + virtual bool + IncrementalFindPhantomNodeForCoordinate(const FixedPointCoordinate &input_coordinate, + PhantomNode &resulting_phantom_node) = 0; + + virtual unsigned GetCheckSum() const = 0; + + virtual unsigned GetNameIndexFromEdgeID(const unsigned id) const = 0; + + virtual void GetName(const unsigned name_id, std::string &result) const = 0; + + std::string GetEscapedNameForNameID(const unsigned name_id) const + { + std::string temporary_string; + GetName(name_id, temporary_string); + return EscapeJSONString(temporary_string); + } + + virtual std::string GetTimestamp() const = 0; +}; + +#endif // DATAFACADE_BASE_HPP diff --git a/server/data_structures/internal_datafacade.hpp b/server/data_structures/internal_datafacade.hpp new file mode 100644 index 000000000..a9949e383 --- /dev/null +++ b/server/data_structures/internal_datafacade.hpp @@ -0,0 +1,449 @@ +/* + +Copyright (c) 2015, Project OSRM, Dennis Luxen, others +All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, +are permitted provided that the following conditions are met: + +Redistributions of source code must retain the above copyright notice, this list +of conditions and the following disclaimer. +Redistributions in binary form must reproduce the above copyright notice, this +list of conditions and the following disclaimer in the documentation and/or +other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR +ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON +ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +*/ + +#ifndef INTERNAL_DATAFACADE_HPP +#define INTERNAL_DATAFACADE_HPP + +// implements all data storage when shared memory is _NOT_ used + +#include "datafacade_base.hpp" + +#include "../../data_structures/original_edge_data.hpp" +#include "../../data_structures/query_node.hpp" +#include "../../data_structures/query_edge.hpp" +#include "../../data_structures/shared_memory_vector_wrapper.hpp" +#include "../../data_structures/static_graph.hpp" +#include "../../data_structures/static_rtree.hpp" +#include "../../data_structures/range_table.hpp" +#include "../../Util/BoostFileSystemFix.h" +#include "../../Util/graph_loader.hpp" +#include "../../Util/simple_logger.hpp" + +#include +#include + +template class InternalDataFacade : public BaseDataFacade +{ + + private: + typedef BaseDataFacade super; + typedef StaticGraph QueryGraph; + typedef typename QueryGraph::InputEdge InputEdge; + typedef typename super::RTreeLeaf RTreeLeaf; + + InternalDataFacade() {} + + unsigned m_check_sum; + unsigned m_number_of_nodes; + QueryGraph *m_query_graph; + std::string m_timestamp; + + std::shared_ptr::vector> m_coordinate_list; + ShM::vector m_via_node_list; + ShM::vector m_name_ID_list; + ShM::vector m_turn_instruction_list; + ShM::vector m_travel_mode_list; + ShM::vector m_names_char_list; + ShM::vector m_edge_is_compressed; + ShM::vector m_geometry_indices; + ShM::vector m_geometry_list; + + boost::thread_specific_ptr< + StaticRTree::vector, false>> m_static_rtree; + boost::filesystem::path ram_index_path; + boost::filesystem::path file_index_path; + RangeTable<16, false> m_name_table; + + void LoadTimestamp(const boost::filesystem::path ×tamp_path) + { + if (boost::filesystem::exists(timestamp_path)) + { + SimpleLogger().Write() << "Loading Timestamp"; + boost::filesystem::ifstream timestamp_stream(timestamp_path); + if (!timestamp_stream) + { + SimpleLogger().Write(logWARNING) << timestamp_path << " not found"; + } + getline(timestamp_stream, m_timestamp); + timestamp_stream.close(); + } + if (m_timestamp.empty()) + { + m_timestamp = "n/a"; + } + if (25 < m_timestamp.length()) + { + m_timestamp.resize(25); + } + } + + void LoadGraph(const boost::filesystem::path &hsgr_path) + { + typename ShM::vector node_list; + typename ShM::vector edge_list; + + SimpleLogger().Write() << "loading graph from " << hsgr_path.string(); + + m_number_of_nodes = readHSGRFromStream(hsgr_path, node_list, edge_list, &m_check_sum); + + BOOST_ASSERT_MSG(0 != node_list.size(), "node list empty"); + // BOOST_ASSERT_MSG(0 != edge_list.size(), "edge list empty"); + SimpleLogger().Write() << "loaded " << node_list.size() << " nodes and " << edge_list.size() + << " edges"; + m_query_graph = new QueryGraph(node_list, edge_list); + + BOOST_ASSERT_MSG(0 == node_list.size(), "node list not flushed"); + BOOST_ASSERT_MSG(0 == edge_list.size(), "edge list not flushed"); + SimpleLogger().Write() << "Data checksum is " << m_check_sum; + } + + void LoadNodeAndEdgeInformation(const boost::filesystem::path &nodes_file, + const boost::filesystem::path &edges_file) + { + boost::filesystem::ifstream nodes_input_stream(nodes_file, std::ios::binary); + + QueryNode current_node; + unsigned number_of_coordinates = 0; + nodes_input_stream.read((char *)&number_of_coordinates, sizeof(unsigned)); + m_coordinate_list = + std::make_shared>(number_of_coordinates); + for (unsigned i = 0; i < number_of_coordinates; ++i) + { + nodes_input_stream.read((char *)¤t_node, sizeof(QueryNode)); + m_coordinate_list->at(i) = FixedPointCoordinate(current_node.lat, current_node.lon); + BOOST_ASSERT((std::abs(m_coordinate_list->at(i).lat) >> 30) == 0); + BOOST_ASSERT((std::abs(m_coordinate_list->at(i).lon) >> 30) == 0); + } + nodes_input_stream.close(); + + boost::filesystem::ifstream edges_input_stream(edges_file, std::ios::binary); + unsigned number_of_edges = 0; + edges_input_stream.read((char *)&number_of_edges, sizeof(unsigned)); + m_via_node_list.resize(number_of_edges); + m_name_ID_list.resize(number_of_edges); + m_turn_instruction_list.resize(number_of_edges); + m_travel_mode_list.resize(number_of_edges); + m_edge_is_compressed.resize(number_of_edges); + + unsigned compressed = 0; + + OriginalEdgeData current_edge_data; + for (unsigned i = 0; i < number_of_edges; ++i) + { + edges_input_stream.read((char *)&(current_edge_data), sizeof(OriginalEdgeData)); + m_via_node_list[i] = current_edge_data.via_node; + m_name_ID_list[i] = current_edge_data.name_id; + m_turn_instruction_list[i] = current_edge_data.turn_instruction; + m_travel_mode_list[i] = current_edge_data.travel_mode; + m_edge_is_compressed[i] = current_edge_data.compressed_geometry; + if (m_edge_is_compressed[i]) + { + ++compressed; + } + } + + edges_input_stream.close(); + } + + void LoadGeometries(const boost::filesystem::path &geometry_file) + { + std::ifstream geometry_stream(geometry_file.string().c_str(), std::ios::binary); + unsigned number_of_indices = 0; + unsigned number_of_compressed_geometries = 0; + + geometry_stream.read((char *)&number_of_indices, sizeof(unsigned)); + + m_geometry_indices.resize(number_of_indices); + if (number_of_indices > 0) + { + geometry_stream.read((char *)&(m_geometry_indices[0]), + number_of_indices * sizeof(unsigned)); + } + + geometry_stream.read((char *)&number_of_compressed_geometries, sizeof(unsigned)); + + BOOST_ASSERT(m_geometry_indices.back() == number_of_compressed_geometries); + m_geometry_list.resize(number_of_compressed_geometries); + + if (number_of_compressed_geometries > 0) + { + geometry_stream.read((char *)&(m_geometry_list[0]), + number_of_compressed_geometries * sizeof(unsigned)); + } + geometry_stream.close(); + } + + void LoadRTree() + { + BOOST_ASSERT_MSG(!m_coordinate_list->empty(), "coordinates must be loaded before r-tree"); + + m_static_rtree.reset( + new StaticRTree(ram_index_path, file_index_path, m_coordinate_list)); + } + + void LoadStreetNames(const boost::filesystem::path &names_file) + { + boost::filesystem::ifstream name_stream(names_file, std::ios::binary); + + name_stream >> m_name_table; + + unsigned number_of_chars = 0; + name_stream.read((char *)&number_of_chars, sizeof(unsigned)); + BOOST_ASSERT_MSG(0 != number_of_chars, "name file broken"); + m_names_char_list.resize(number_of_chars + 1); //+1 gives sentinel element + name_stream.read((char *)&m_names_char_list[0], number_of_chars * sizeof(char)); + if (0 == m_names_char_list.size()) + { + SimpleLogger().Write(logWARNING) << "list of street names is empty"; + } + name_stream.close(); + } + + public: + virtual ~InternalDataFacade() + { + delete m_query_graph; + m_static_rtree.reset(); + } + + explicit InternalDataFacade(const ServerPaths &server_paths) + { + // generate paths of data files + if (server_paths.find("hsgrdata") == server_paths.end()) + { + throw osrm::exception("no hsgr file given in ini file"); + } + if (server_paths.find("ramindex") == server_paths.end()) + { + throw osrm::exception("no ram index file given in ini file"); + } + if (server_paths.find("fileindex") == server_paths.end()) + { + throw osrm::exception("no leaf index file given in ini file"); + } + if (server_paths.find("geometries") == server_paths.end()) + { + throw osrm::exception("no geometries file given in ini file"); + } + if (server_paths.find("nodesdata") == server_paths.end()) + { + throw osrm::exception("no nodes file given in ini file"); + } + if (server_paths.find("edgesdata") == server_paths.end()) + { + throw osrm::exception("no edges file given in ini file"); + } + if (server_paths.find("namesdata") == server_paths.end()) + { + throw osrm::exception("no names file given in ini file"); + } + + ServerPaths::const_iterator paths_iterator = server_paths.find("hsgrdata"); + BOOST_ASSERT(server_paths.end() != paths_iterator); + const boost::filesystem::path &hsgr_path = paths_iterator->second; + paths_iterator = server_paths.find("timestamp"); + BOOST_ASSERT(server_paths.end() != paths_iterator); + const boost::filesystem::path ×tamp_path = paths_iterator->second; + paths_iterator = server_paths.find("ramindex"); + BOOST_ASSERT(server_paths.end() != paths_iterator); + ram_index_path = paths_iterator->second; + paths_iterator = server_paths.find("fileindex"); + BOOST_ASSERT(server_paths.end() != paths_iterator); + file_index_path = paths_iterator->second; + paths_iterator = server_paths.find("nodesdata"); + BOOST_ASSERT(server_paths.end() != paths_iterator); + const boost::filesystem::path &nodes_data_path = paths_iterator->second; + paths_iterator = server_paths.find("edgesdata"); + BOOST_ASSERT(server_paths.end() != paths_iterator); + const boost::filesystem::path &edges_data_path = paths_iterator->second; + paths_iterator = server_paths.find("namesdata"); + BOOST_ASSERT(server_paths.end() != paths_iterator); + const boost::filesystem::path &names_data_path = paths_iterator->second; + paths_iterator = server_paths.find("geometries"); + BOOST_ASSERT(server_paths.end() != paths_iterator); + const boost::filesystem::path &geometries_path = paths_iterator->second; + + // load data + SimpleLogger().Write() << "loading graph data"; + AssertPathExists(hsgr_path); + LoadGraph(hsgr_path); + SimpleLogger().Write() << "loading edge information"; + AssertPathExists(nodes_data_path); + AssertPathExists(edges_data_path); + LoadNodeAndEdgeInformation(nodes_data_path, edges_data_path); + SimpleLogger().Write() << "loading geometries"; + AssertPathExists(geometries_path); + LoadGeometries(geometries_path); + SimpleLogger().Write() << "loading r-tree"; + AssertPathExists(ram_index_path); + AssertPathExists(file_index_path); + SimpleLogger().Write() << "loading timestamp"; + LoadTimestamp(timestamp_path); + SimpleLogger().Write() << "loading street names"; + AssertPathExists(names_data_path); + LoadStreetNames(names_data_path); + } + + // search graph access + unsigned GetNumberOfNodes() const final { return m_query_graph->GetNumberOfNodes(); } + + unsigned GetNumberOfEdges() const final { return m_query_graph->GetNumberOfEdges(); } + + unsigned GetOutDegree(const NodeID n) const final { return m_query_graph->GetOutDegree(n); } + + NodeID GetTarget(const EdgeID e) const final { return m_query_graph->GetTarget(e); } + + // EdgeDataT &GetEdgeData(const EdgeID e) final { return m_query_graph->GetEdgeData(e); } + + EdgeDataT &GetEdgeData(const EdgeID e) const final { return m_query_graph->GetEdgeData(e); } + + EdgeID BeginEdges(const NodeID n) const final { return m_query_graph->BeginEdges(n); } + + EdgeID EndEdges(const NodeID n) const final { return m_query_graph->EndEdges(n); } + + EdgeRange GetAdjacentEdgeRange(const NodeID node) const final + { + return m_query_graph->GetAdjacentEdgeRange(node); + }; + + // searches for a specific edge + EdgeID FindEdge(const NodeID from, const NodeID to) const final + { + return m_query_graph->FindEdge(from, to); + } + + EdgeID FindEdgeInEitherDirection(const NodeID from, const NodeID to) const final + { + return m_query_graph->FindEdgeInEitherDirection(from, to); + } + + EdgeID FindEdgeIndicateIfReverse(const NodeID from, const NodeID to, bool &result) const final + { + return m_query_graph->FindEdgeIndicateIfReverse(from, to, result); + } + + // node and edge information access + FixedPointCoordinate GetCoordinateOfNode(const unsigned id) const final + { + return m_coordinate_list->at(id); + }; + + bool EdgeIsCompressed(const unsigned id) const { return m_edge_is_compressed.at(id); } + + TurnInstruction GetTurnInstructionForEdgeID(const unsigned id) const final + { + return m_turn_instruction_list.at(id); + } + + TravelMode GetTravelModeForEdgeID(const unsigned id) const { return m_travel_mode_list.at(id); } + + bool LocateClosestEndPointForCoordinate(const FixedPointCoordinate &input_coordinate, + FixedPointCoordinate &result, + const unsigned zoom_level = 18) final + { + if (!m_static_rtree.get()) + { + LoadRTree(); + } + + return m_static_rtree->LocateClosestEndPointForCoordinate(input_coordinate, result, + zoom_level); + } + + bool IncrementalFindPhantomNodeForCoordinate(const FixedPointCoordinate &input_coordinate, + PhantomNode &resulting_phantom_node) final + { + std::vector resulting_phantom_node_vector; + auto result = IncrementalFindPhantomNodeForCoordinate(input_coordinate, + resulting_phantom_node_vector, 1); + if (result) + { + BOOST_ASSERT(!resulting_phantom_node_vector.empty()); + resulting_phantom_node = resulting_phantom_node_vector.front(); + } + return result; + } + + bool + IncrementalFindPhantomNodeForCoordinate(const FixedPointCoordinate &input_coordinate, + std::vector &resulting_phantom_node_vector, + const unsigned number_of_results) final + { + if (!m_static_rtree.get()) + { + LoadRTree(); + } + + return m_static_rtree->IncrementalFindPhantomNodeForCoordinate( + input_coordinate, resulting_phantom_node_vector, number_of_results); + } + + unsigned GetCheckSum() const final { return m_check_sum; } + + unsigned GetNameIndexFromEdgeID(const unsigned id) const final + { + return m_name_ID_list.at(id); + }; + + void GetName(const unsigned name_id, std::string &result) const final + { + if (UINT_MAX == name_id) + { + result = ""; + return; + } + auto range = m_name_table.GetRange(name_id); + + result.clear(); + if (range.begin() != range.end()) + { + result.resize(range.back() - range.front() + 1); + std::copy(m_names_char_list.begin() + range.front(), + m_names_char_list.begin() + range.back() + 1, result.begin()); + } + } + + virtual unsigned GetGeometryIndexForEdgeID(const unsigned id) const final + { + return m_via_node_list.at(id); + } + + virtual void GetUncompressedGeometry(const unsigned id, + std::vector &result_nodes) const final + { + const unsigned begin = m_geometry_indices.at(id); + const unsigned end = m_geometry_indices.at(id + 1); + + result_nodes.clear(); + result_nodes.insert(result_nodes.begin(), m_geometry_list.begin() + begin, + m_geometry_list.begin() + end); + } + + std::string GetTimestamp() const final { return m_timestamp; } +}; + +#endif // INTERNAL_DATAFACADE_HPP diff --git a/server/data_structures/shared_barriers.hpp b/server/data_structures/shared_barriers.hpp new file mode 100644 index 000000000..2d7de7e74 --- /dev/null +++ b/server/data_structures/shared_barriers.hpp @@ -0,0 +1,60 @@ +/* + +Copyright (c) 2015, Project OSRM, Dennis Luxen, others +All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, +are permitted provided that the following conditions are met: + +Redistributions of source code must retain the above copyright notice, this list +of conditions and the following disclaimer. +Redistributions in binary form must reproduce the above copyright notice, this +list of conditions and the following disclaimer in the documentation and/or +other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR +ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON +ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +*/ + +#ifndef SHARED_BARRIERS_HPP +#define SHARED_BARRIERS_HPP + +#include +#include + +struct SharedBarriers +{ + + SharedBarriers() + : pending_update_mutex(boost::interprocess::open_or_create, "pending_update"), + update_mutex(boost::interprocess::open_or_create, "update"), + query_mutex(boost::interprocess::open_or_create, "query"), + no_running_queries_condition(boost::interprocess::open_or_create, "no_running_queries"), + update_ongoing(false), number_of_queries(0) + { + } + + // Mutex to protect access to the boolean variable + boost::interprocess::named_mutex pending_update_mutex; + boost::interprocess::named_mutex update_mutex; + boost::interprocess::named_mutex query_mutex; + + // Condition that no update is running + boost::interprocess::named_condition no_running_queries_condition; + + // Is there an ongoing update? + bool update_ongoing; + // Is there any query? + int number_of_queries; +}; + +#endif // SHARED_BARRIERS_HPP diff --git a/server/data_structures/shared_datafacade.hpp b/server/data_structures/shared_datafacade.hpp new file mode 100644 index 000000000..11a295e27 --- /dev/null +++ b/server/data_structures/shared_datafacade.hpp @@ -0,0 +1,423 @@ +/* + +Copyright (c) 2015, Project OSRM, Dennis Luxen, others +All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, +are permitted provided that the following conditions are met: + +Redistributions of source code must retain the above copyright notice, this list +of conditions and the following disclaimer. +Redistributions in binary form must reproduce the above copyright notice, this +list of conditions and the following disclaimer in the documentation and/or +other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR +ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON +ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +*/ + +#ifndef SHARED_DATAFACADE_HPP +#define SHARED_DATAFACADE_HPP + +// implements all data storage when shared memory _IS_ used + +#include "datafacade_base.hpp" +#include "shared_datatype.hpp" + +#include "../../data_structures/range_table.hpp" +#include "../../data_structures/static_graph.hpp" +#include "../../data_structures/static_rtree.hpp" +#include "../../Util/BoostFileSystemFix.h" +#include "../../Util/make_unique.hpp" +#include "../../Util/simple_logger.hpp" + +#include +#include + +template class SharedDataFacade : public BaseDataFacade +{ + + private: + typedef EdgeDataT EdgeData; + typedef BaseDataFacade super; + typedef StaticGraph QueryGraph; + typedef typename StaticGraph::NodeArrayEntry GraphNode; + typedef typename StaticGraph::EdgeArrayEntry GraphEdge; + typedef typename RangeTable<16, true>::BlockT NameIndexBlock; + typedef typename QueryGraph::InputEdge InputEdge; + typedef typename super::RTreeLeaf RTreeLeaf; + using SharedRTree = StaticRTree::vector, true>; + using TimeStampedRTreePair = std::pair>; + using RTreeNode = typename SharedRTree::TreeNode; + + SharedDataLayout *data_layout; + char *shared_memory; + SharedDataTimestamp *data_timestamp_ptr; + + SharedDataType CURRENT_LAYOUT; + SharedDataType CURRENT_DATA; + unsigned CURRENT_TIMESTAMP; + + unsigned m_check_sum; + std::unique_ptr m_query_graph; + std::unique_ptr m_layout_memory; + std::unique_ptr m_large_memory; + std::string m_timestamp; + + std::shared_ptr::vector> m_coordinate_list; + ShM::vector m_via_node_list; + ShM::vector m_name_ID_list; + ShM::vector m_turn_instruction_list; + ShM::vector m_travel_mode_list; + ShM::vector m_names_char_list; + ShM::vector m_name_begin_indices; + ShM::vector m_edge_is_compressed; + ShM::vector m_geometry_indices; + ShM::vector m_geometry_list; + + boost::thread_specific_ptr>> m_static_rtree; + boost::filesystem::path file_index_path; + + std::shared_ptr> m_name_table; + + void LoadChecksum() + { + m_check_sum = + *data_layout->GetBlockPtr(shared_memory, SharedDataLayout::HSGR_CHECKSUM); + SimpleLogger().Write() << "set checksum: " << m_check_sum; + } + + void LoadTimestamp() + { + char *timestamp_ptr = + data_layout->GetBlockPtr(shared_memory, SharedDataLayout::TIMESTAMP); + m_timestamp.resize(data_layout->GetBlockSize(SharedDataLayout::TIMESTAMP)); + std::copy(timestamp_ptr, + timestamp_ptr + data_layout->GetBlockSize(SharedDataLayout::TIMESTAMP), + m_timestamp.begin()); + } + + void LoadRTree() + { + BOOST_ASSERT_MSG(!m_coordinate_list->empty(), "coordinates must be loaded before r-tree"); + + RTreeNode *tree_ptr = + data_layout->GetBlockPtr(shared_memory, SharedDataLayout::R_SEARCH_TREE); + m_static_rtree.reset(new TimeStampedRTreePair( + CURRENT_TIMESTAMP, + osrm::make_unique( + tree_ptr, data_layout->num_entries[SharedDataLayout::R_SEARCH_TREE], + file_index_path, m_coordinate_list))); + } + + void LoadGraph() + { + GraphNode *graph_nodes_ptr = + data_layout->GetBlockPtr(shared_memory, SharedDataLayout::GRAPH_NODE_LIST); + + GraphEdge *graph_edges_ptr = + data_layout->GetBlockPtr(shared_memory, SharedDataLayout::GRAPH_EDGE_LIST); + + typename ShM::vector node_list( + graph_nodes_ptr, data_layout->num_entries[SharedDataLayout::GRAPH_NODE_LIST]); + typename ShM::vector edge_list( + graph_edges_ptr, data_layout->num_entries[SharedDataLayout::GRAPH_EDGE_LIST]); + m_query_graph.reset(new QueryGraph(node_list, edge_list)); + } + + void LoadNodeAndEdgeInformation() + { + + FixedPointCoordinate *coordinate_list_ptr = data_layout->GetBlockPtr( + shared_memory, SharedDataLayout::COORDINATE_LIST); + m_coordinate_list = osrm::make_unique::vector>( + coordinate_list_ptr, data_layout->num_entries[SharedDataLayout::COORDINATE_LIST]); + + TravelMode *travel_mode_list_ptr = + data_layout->GetBlockPtr(shared_memory, SharedDataLayout::TRAVEL_MODE); + typename ShM::vector travel_mode_list( + travel_mode_list_ptr, data_layout->num_entries[SharedDataLayout::TRAVEL_MODE]); + m_travel_mode_list.swap(travel_mode_list); + + TurnInstruction *turn_instruction_list_ptr = data_layout->GetBlockPtr( + shared_memory, SharedDataLayout::TURN_INSTRUCTION); + typename ShM::vector turn_instruction_list( + turn_instruction_list_ptr, + data_layout->num_entries[SharedDataLayout::TURN_INSTRUCTION]); + m_turn_instruction_list.swap(turn_instruction_list); + + unsigned *name_id_list_ptr = + data_layout->GetBlockPtr(shared_memory, SharedDataLayout::NAME_ID_LIST); + typename ShM::vector name_id_list( + name_id_list_ptr, data_layout->num_entries[SharedDataLayout::NAME_ID_LIST]); + m_name_ID_list.swap(name_id_list); + } + + void LoadViaNodeList() + { + NodeID *via_node_list_ptr = + data_layout->GetBlockPtr(shared_memory, SharedDataLayout::VIA_NODE_LIST); + typename ShM::vector via_node_list( + via_node_list_ptr, data_layout->num_entries[SharedDataLayout::VIA_NODE_LIST]); + m_via_node_list.swap(via_node_list); + } + + void LoadNames() + { + unsigned *offsets_ptr = + data_layout->GetBlockPtr(shared_memory, SharedDataLayout::NAME_OFFSETS); + NameIndexBlock *blocks_ptr = + data_layout->GetBlockPtr(shared_memory, SharedDataLayout::NAME_BLOCKS); + typename ShM::vector name_offsets( + offsets_ptr, data_layout->num_entries[SharedDataLayout::NAME_OFFSETS]); + typename ShM::vector name_blocks( + blocks_ptr, data_layout->num_entries[SharedDataLayout::NAME_BLOCKS]); + + char *names_list_ptr = + data_layout->GetBlockPtr(shared_memory, SharedDataLayout::NAME_CHAR_LIST); + typename ShM::vector names_char_list( + names_list_ptr, data_layout->num_entries[SharedDataLayout::NAME_CHAR_LIST]); + m_name_table = osrm::make_unique>( + name_offsets, name_blocks, static_cast(names_char_list.size())); + + m_names_char_list.swap(names_char_list); + } + + void LoadGeometries() + { + unsigned *geometries_compressed_ptr = data_layout->GetBlockPtr( + shared_memory, SharedDataLayout::GEOMETRIES_INDICATORS); + typename ShM::vector edge_is_compressed( + geometries_compressed_ptr, + data_layout->num_entries[SharedDataLayout::GEOMETRIES_INDICATORS]); + m_edge_is_compressed.swap(edge_is_compressed); + + unsigned *geometries_index_ptr = + data_layout->GetBlockPtr(shared_memory, SharedDataLayout::GEOMETRIES_INDEX); + typename ShM::vector geometry_begin_indices( + geometries_index_ptr, data_layout->num_entries[SharedDataLayout::GEOMETRIES_INDEX]); + m_geometry_indices.swap(geometry_begin_indices); + + unsigned *geometries_list_ptr = + data_layout->GetBlockPtr(shared_memory, SharedDataLayout::GEOMETRIES_LIST); + typename ShM::vector geometry_list( + geometries_list_ptr, data_layout->num_entries[SharedDataLayout::GEOMETRIES_LIST]); + m_geometry_list.swap(geometry_list); + } + + public: + virtual ~SharedDataFacade() {} + + SharedDataFacade() + { + data_timestamp_ptr = (SharedDataTimestamp *)SharedMemoryFactory::Get( + CURRENT_REGIONS, sizeof(SharedDataTimestamp), false, false)->Ptr(); + CURRENT_LAYOUT = LAYOUT_NONE; + CURRENT_DATA = DATA_NONE; + CURRENT_TIMESTAMP = 0; + + // load data + CheckAndReloadFacade(); + } + + void CheckAndReloadFacade() + { + if (CURRENT_LAYOUT != data_timestamp_ptr->layout || + CURRENT_DATA != data_timestamp_ptr->data || + CURRENT_TIMESTAMP != data_timestamp_ptr->timestamp) + { + // release the previous shared memory segments + SharedMemory::Remove(CURRENT_LAYOUT); + SharedMemory::Remove(CURRENT_DATA); + + CURRENT_LAYOUT = data_timestamp_ptr->layout; + CURRENT_DATA = data_timestamp_ptr->data; + CURRENT_TIMESTAMP = data_timestamp_ptr->timestamp; + + m_layout_memory.reset(SharedMemoryFactory::Get(CURRENT_LAYOUT)); + + data_layout = (SharedDataLayout *)(m_layout_memory->Ptr()); + + m_large_memory.reset(SharedMemoryFactory::Get(CURRENT_DATA)); + shared_memory = (char *)(m_large_memory->Ptr()); + + const char *file_index_ptr = + data_layout->GetBlockPtr(shared_memory, SharedDataLayout::FILE_INDEX_PATH); + file_index_path = boost::filesystem::path(file_index_ptr); + if (!boost::filesystem::exists(file_index_path)) + { + SimpleLogger().Write(logDEBUG) << "Leaf file name " << file_index_path.string(); + throw osrm::exception("Could not load leaf index file." + "Is any data loaded into shared memory?"); + } + + LoadGraph(); + LoadChecksum(); + LoadNodeAndEdgeInformation(); + LoadGeometries(); + LoadTimestamp(); + LoadViaNodeList(); + LoadNames(); + + data_layout->PrintInformation(); + + SimpleLogger().Write() << "number of geometries: " << m_coordinate_list->size(); + for (unsigned i = 0; i < m_coordinate_list->size(); ++i) + { + if (!GetCoordinateOfNode(i).is_valid()) + { + SimpleLogger().Write() << "coordinate " << i << " not valid"; + } + } + } + } + + // search graph access + unsigned GetNumberOfNodes() const final { return m_query_graph->GetNumberOfNodes(); } + + unsigned GetNumberOfEdges() const final { return m_query_graph->GetNumberOfEdges(); } + + unsigned GetOutDegree(const NodeID n) const final { return m_query_graph->GetOutDegree(n); } + + NodeID GetTarget(const EdgeID e) const final { return m_query_graph->GetTarget(e); } + + EdgeDataT &GetEdgeData(const EdgeID e) const final { return m_query_graph->GetEdgeData(e); } + + EdgeID BeginEdges(const NodeID n) const final { return m_query_graph->BeginEdges(n); } + + EdgeID EndEdges(const NodeID n) const final { return m_query_graph->EndEdges(n); } + + EdgeRange GetAdjacentEdgeRange(const NodeID node) const final + { + return m_query_graph->GetAdjacentEdgeRange(node); + }; + + // searches for a specific edge + EdgeID FindEdge(const NodeID from, const NodeID to) const final + { + return m_query_graph->FindEdge(from, to); + } + + EdgeID FindEdgeInEitherDirection(const NodeID from, const NodeID to) const final + { + return m_query_graph->FindEdgeInEitherDirection(from, to); + } + + EdgeID FindEdgeIndicateIfReverse(const NodeID from, const NodeID to, bool &result) const final + { + return m_query_graph->FindEdgeIndicateIfReverse(from, to, result); + } + + // node and edge information access + FixedPointCoordinate GetCoordinateOfNode(const NodeID id) const final + { + return m_coordinate_list->at(id); + }; + + virtual bool EdgeIsCompressed(const unsigned id) const final + { + return m_edge_is_compressed.at(id); + } + + virtual void GetUncompressedGeometry(const unsigned id, + std::vector &result_nodes) const final + { + const unsigned begin = m_geometry_indices.at(id); + const unsigned end = m_geometry_indices.at(id + 1); + + result_nodes.clear(); + result_nodes.insert(result_nodes.begin(), m_geometry_list.begin() + begin, + m_geometry_list.begin() + end); + } + + virtual unsigned GetGeometryIndexForEdgeID(const unsigned id) const final + { + return m_via_node_list.at(id); + } + + TurnInstruction GetTurnInstructionForEdgeID(const unsigned id) const final + { + return m_turn_instruction_list.at(id); + } + + TravelMode GetTravelModeForEdgeID(const unsigned id) const { return m_travel_mode_list.at(id); } + + bool LocateClosestEndPointForCoordinate(const FixedPointCoordinate &input_coordinate, + FixedPointCoordinate &result, + const unsigned zoom_level = 18) final + { + if (!m_static_rtree.get() || CURRENT_TIMESTAMP != m_static_rtree->first) + { + LoadRTree(); + } + + return m_static_rtree->second->LocateClosestEndPointForCoordinate(input_coordinate, result, + zoom_level); + } + + bool IncrementalFindPhantomNodeForCoordinate(const FixedPointCoordinate &input_coordinate, + PhantomNode &resulting_phantom_node) final + { + std::vector resulting_phantom_node_vector; + auto result = IncrementalFindPhantomNodeForCoordinate(input_coordinate, + resulting_phantom_node_vector, 1); + if (result) + { + BOOST_ASSERT(!resulting_phantom_node_vector.empty()); + resulting_phantom_node = resulting_phantom_node_vector.front(); + } + return result; + } + + bool + IncrementalFindPhantomNodeForCoordinate(const FixedPointCoordinate &input_coordinate, + std::vector &resulting_phantom_node_vector, + const unsigned number_of_results) final + { + if (!m_static_rtree.get() || CURRENT_TIMESTAMP != m_static_rtree->first) + { + LoadRTree(); + } + + return m_static_rtree->second->IncrementalFindPhantomNodeForCoordinate( + input_coordinate, resulting_phantom_node_vector, number_of_results); + } + + unsigned GetCheckSum() const final { return m_check_sum; } + + unsigned GetNameIndexFromEdgeID(const unsigned id) const final + { + return m_name_ID_list.at(id); + }; + + void GetName(const unsigned name_id, std::string &result) const final + { + if (UINT_MAX == name_id) + { + result = ""; + return; + } + auto range = m_name_table->GetRange(name_id); + + result.clear(); + if (range.begin() != range.end()) + { + result.resize(range.back() - range.front() + 1); + std::copy(m_names_char_list.begin() + range.front(), + m_names_char_list.begin() + range.back() + 1, result.begin()); + } + } + + std::string GetTimestamp() const final { return m_timestamp; } +}; + +#endif // SHARED_DATAFACADE_HPP diff --git a/server/data_structures/shared_datatype.hpp b/server/data_structures/shared_datatype.hpp new file mode 100644 index 000000000..9464ff015 --- /dev/null +++ b/server/data_structures/shared_datatype.hpp @@ -0,0 +1,227 @@ +/* + +Copyright (c) 2015, Project OSRM, Dennis Luxen, others +All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, +are permitted provided that the following conditions are met: + +Redistributions of source code must retain the above copyright notice, this list +of conditions and the following disclaimer. +Redistributions in binary form must reproduce the above copyright notice, this +list of conditions and the following disclaimer in the documentation and/or +other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR +ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON +ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +*/ + +#ifndef SHARED_DATA_TYPE_HPP +#define SHARED_DATA_TYPE_HPP + +#include "../../Util/osrm_exception.hpp" +#include "../../Util/simple_logger.hpp" + +#include + +#include + +namespace +{ +// Added at the start and end of each block as sanity check +constexpr static const char CANARY[] = "OSRM"; +} + +struct SharedDataLayout +{ + enum BlockID + { + NAME_OFFSETS = 0, + NAME_BLOCKS, + NAME_CHAR_LIST, + NAME_ID_LIST, + VIA_NODE_LIST, + GRAPH_NODE_LIST, + GRAPH_EDGE_LIST, + COORDINATE_LIST, + TURN_INSTRUCTION, + TRAVEL_MODE, + R_SEARCH_TREE, + GEOMETRIES_INDEX, + GEOMETRIES_LIST, + GEOMETRIES_INDICATORS, + HSGR_CHECKSUM, + TIMESTAMP, + FILE_INDEX_PATH, + NUM_BLOCKS + }; + + std::array num_entries; + std::array entry_size; + + SharedDataLayout() : num_entries(), entry_size() {} + + void PrintInformation() const + { + SimpleLogger().Write(logDEBUG) << "-"; + SimpleLogger().Write(logDEBUG) + << "name_offsets_size: " << num_entries[NAME_OFFSETS]; + SimpleLogger().Write(logDEBUG) + << "name_blocks_size: " << num_entries[NAME_BLOCKS]; + SimpleLogger().Write(logDEBUG) + << "name_char_list_size: " << num_entries[NAME_CHAR_LIST]; + SimpleLogger().Write(logDEBUG) + << "name_id_list_size: " << num_entries[NAME_ID_LIST]; + SimpleLogger().Write(logDEBUG) + << "via_node_list_size: " << num_entries[VIA_NODE_LIST]; + SimpleLogger().Write(logDEBUG) + << "graph_node_list_size: " << num_entries[GRAPH_NODE_LIST]; + SimpleLogger().Write(logDEBUG) + << "graph_edge_list_size: " << num_entries[GRAPH_EDGE_LIST]; + SimpleLogger().Write(logDEBUG) << "timestamp_length: " << num_entries[TIMESTAMP]; + SimpleLogger().Write(logDEBUG) + << "coordinate_list_size: " << num_entries[COORDINATE_LIST]; + SimpleLogger().Write(logDEBUG) + << "turn_instruction_list_size: " << num_entries[TURN_INSTRUCTION]; + SimpleLogger().Write(logDEBUG) + << "travel_mode_list_size: " << num_entries[TRAVEL_MODE]; + SimpleLogger().Write(logDEBUG) + << "r_search_tree_size: " << num_entries[R_SEARCH_TREE]; + SimpleLogger().Write(logDEBUG) + << "geometries_indicators: " << num_entries[GEOMETRIES_INDICATORS] << "/" + << ((num_entries[GEOMETRIES_INDICATORS] / 8) + 1); + SimpleLogger().Write(logDEBUG) + << "geometries_index_list_size: " << num_entries[GEOMETRIES_INDEX]; + SimpleLogger().Write(logDEBUG) + << "geometries_list_size: " << num_entries[GEOMETRIES_LIST]; + SimpleLogger().Write(logDEBUG) + << "sizeof(checksum): " << entry_size[HSGR_CHECKSUM]; + + SimpleLogger().Write(logDEBUG) << "NAME_OFFSETS " + << ": " << GetBlockSize(NAME_OFFSETS); + SimpleLogger().Write(logDEBUG) << "NAME_BLOCKS " + << ": " << GetBlockSize(NAME_BLOCKS); + SimpleLogger().Write(logDEBUG) << "NAME_CHAR_LIST " + << ": " << GetBlockSize(NAME_CHAR_LIST); + SimpleLogger().Write(logDEBUG) << "NAME_ID_LIST " + << ": " << GetBlockSize(NAME_ID_LIST); + SimpleLogger().Write(logDEBUG) << "VIA_NODE_LIST " + << ": " << GetBlockSize(VIA_NODE_LIST); + SimpleLogger().Write(logDEBUG) << "GRAPH_NODE_LIST " + << ": " << GetBlockSize(GRAPH_NODE_LIST); + SimpleLogger().Write(logDEBUG) << "GRAPH_EDGE_LIST " + << ": " << GetBlockSize(GRAPH_EDGE_LIST); + SimpleLogger().Write(logDEBUG) << "COORDINATE_LIST " + << ": " << GetBlockSize(COORDINATE_LIST); + SimpleLogger().Write(logDEBUG) << "TURN_INSTRUCTION " + << ": " << GetBlockSize(TURN_INSTRUCTION); + SimpleLogger().Write(logDEBUG) << "TRAVEL_MODE " + << ": " << GetBlockSize(TRAVEL_MODE); + SimpleLogger().Write(logDEBUG) << "R_SEARCH_TREE " + << ": " << GetBlockSize(R_SEARCH_TREE); + SimpleLogger().Write(logDEBUG) << "GEOMETRIES_INDEX " + << ": " << GetBlockSize(GEOMETRIES_INDEX); + SimpleLogger().Write(logDEBUG) << "GEOMETRIES_LIST " + << ": " << GetBlockSize(GEOMETRIES_LIST); + SimpleLogger().Write(logDEBUG) << "GEOMETRIES_INDICATORS" + << ": " << GetBlockSize(GEOMETRIES_INDICATORS); + SimpleLogger().Write(logDEBUG) << "HSGR_CHECKSUM " + << ": " << GetBlockSize(HSGR_CHECKSUM); + SimpleLogger().Write(logDEBUG) << "TIMESTAMP " + << ": " << GetBlockSize(TIMESTAMP); + SimpleLogger().Write(logDEBUG) << "FILE_INDEX_PATH " + << ": " << GetBlockSize(FILE_INDEX_PATH); + } + + template inline void SetBlockSize(BlockID bid, uint64_t entries) + { + num_entries[bid] = entries; + entry_size[bid] = sizeof(T); + } + + inline uint64_t GetBlockSize(BlockID bid) const + { + // special encoding + if (bid == GEOMETRIES_INDICATORS) + { + return (num_entries[GEOMETRIES_INDICATORS] / 32 + 1) * + entry_size[GEOMETRIES_INDICATORS]; + } + + return num_entries[bid] * entry_size[bid]; + } + + inline uint64_t GetSizeOfLayout() const + { + return GetBlockOffset(NUM_BLOCKS) + NUM_BLOCKS * 2 * sizeof(CANARY); + } + + inline uint64_t GetBlockOffset(BlockID bid) const + { + uint64_t result = sizeof(CANARY); + for (auto i = 0; i < bid; i++) + { + result += GetBlockSize((BlockID)i) + 2 * sizeof(CANARY); + } + return result; + } + + template + inline T *GetBlockPtr(char *shared_memory, BlockID bid) + { + T *ptr = (T *)(shared_memory + GetBlockOffset(bid)); + if (WRITE_CANARY) + { + char *start_canary_ptr = shared_memory + GetBlockOffset(bid) - sizeof(CANARY); + char *end_canary_ptr = shared_memory + GetBlockOffset(bid) + GetBlockSize(bid); + std::copy(CANARY, CANARY + sizeof(CANARY), start_canary_ptr); + std::copy(CANARY, CANARY + sizeof(CANARY), end_canary_ptr); + } + else + { + char *start_canary_ptr = shared_memory + GetBlockOffset(bid) - sizeof(CANARY); + char *end_canary_ptr = shared_memory + GetBlockOffset(bid) + GetBlockSize(bid); + bool start_canary_alive = std::equal(CANARY, CANARY + sizeof(CANARY), start_canary_ptr); + bool end_canary_alive = std::equal(CANARY, CANARY + sizeof(CANARY), end_canary_ptr); + if (!start_canary_alive) + { + throw osrm::exception("Start canary of block corrupted."); + } + if (!end_canary_alive) + { + throw osrm::exception("End canary of block corrupted."); + } + } + + return ptr; + } +}; + +enum SharedDataType +{ + CURRENT_REGIONS, + LAYOUT_1, + DATA_1, + LAYOUT_2, + DATA_2, + LAYOUT_NONE, + DATA_NONE +}; + +struct SharedDataTimestamp +{ + SharedDataType layout; + SharedDataType data; + unsigned timestamp; +}; + +#endif /* SHARED_DATA_TYPE_HPP */ diff --git a/server/http/compression_type.hpp b/server/http/compression_type.hpp new file mode 100644 index 000000000..49163adab --- /dev/null +++ b/server/http/compression_type.hpp @@ -0,0 +1,42 @@ +/* + +Copyright (c) 2015, Project OSRM, Dennis Luxen, others +All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, +are permitted provided that the following conditions are met: + +Redistributions of source code must retain the above copyright notice, this list +of conditions and the following disclaimer. +Redistributions in binary form must reproduce the above copyright notice, this +list of conditions and the following disclaimer in the documentation and/or +other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR +ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON +ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +*/ + +#ifndef COMPRESSION_TYPE_HPP +#define COMPRESSION_TYPE_HPP + +namespace http +{ + +enum compression_type +{ + no_compression, + gzip_rfc1952, + deflate_rfc1951 +}; +} + +#endif // COMPRESSION_TYPE_HPP diff --git a/server/http/header.hpp b/server/http/header.hpp new file mode 100644 index 000000000..7996be439 --- /dev/null +++ b/server/http/header.hpp @@ -0,0 +1,54 @@ +/* + +Copyright (c) 2015, Project OSRM, Dennis Luxen, others +All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, +are permitted provided that the following conditions are met: + +Redistributions of source code must retain the above copyright notice, this list +of conditions and the following disclaimer. +Redistributions in binary form must reproduce the above copyright notice, this +list of conditions and the following disclaimer in the documentation and/or +other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR +ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON +ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +*/ + +#ifndef HEADER_HPP +#define HEADER_HPP + +#include +#include + +namespace http +{ +struct header +{ + // explicitly use default copy c'tor as adding move c'tor + header &operator=(const header &other) = default; + header(const std::string &name, const std::string &value) : name(name), value(value) {} + header(header &&other) : name(std::move(other.name)), value(std::move(other.value)) {} + + void clear() + { + name.clear(); + value.clear(); + } + + std::string name; + std::string value; +}; +} + +#endif // HEADER_HPP diff --git a/server/http/reply.cpp b/server/http/reply.cpp new file mode 100644 index 000000000..89b931b05 --- /dev/null +++ b/server/http/reply.cpp @@ -0,0 +1,130 @@ +/* + +Copyright (c) 2015, Project OSRM, Dennis Luxen, others +All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, +are permitted provided that the following conditions are met: + +Redistributions of source code must retain the above copyright notice, this list +of conditions and the following disclaimer. +Redistributions in binary form must reproduce the above copyright notice, this +list of conditions and the following disclaimer in the documentation and/or +other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR +ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON +ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +*/ + +#include "reply.hpp" + +#include "../../Util/cast.hpp" + +namespace http +{ + +const char ok_html[] = ""; +const char bad_request_html[] = "{\"status\": 400,\"status_message\":\"Bad Request\"}"; +const char internal_server_error_html[] = + "{\"status\": 500,\"status_message\":\"Internal Server Error\"}"; +const char seperators[] = {':', ' '}; +const char crlf[] = {'\r', '\n'}; +const std::string http_ok_string = "HTTP/1.0 200 OK\r\n"; +const std::string http_bad_request_string = "HTTP/1.0 400 Bad Request\r\n"; +const std::string http_internal_server_error_string = "HTTP/1.0 500 Internal Server Error\r\n"; + +void reply::set_size(const std::size_t size) +{ + for (header &h : headers) + { + if ("Content-Length" == h.name) + { + h.value = cast::integral_to_string(size); + } + } +} + +void reply::set_uncompressed_size() { set_size(content.size()); } + +std::vector reply::to_buffers() +{ + std::vector buffers; + buffers.push_back(status_to_buffer(status)); + for (const header &h : headers) + { + buffers.push_back(boost::asio::buffer(h.name)); + buffers.push_back(boost::asio::buffer(seperators)); + buffers.push_back(boost::asio::buffer(h.value)); + buffers.push_back(boost::asio::buffer(crlf)); + } + buffers.push_back(boost::asio::buffer(crlf)); + buffers.push_back(boost::asio::buffer(content)); + return buffers; +} + +std::vector reply::headers_to_buffers() +{ + std::vector buffers; + buffers.push_back(status_to_buffer(status)); + for (const header ¤t_header : headers) + { + buffers.push_back(boost::asio::buffer(current_header.name)); + buffers.push_back(boost::asio::buffer(seperators)); + buffers.push_back(boost::asio::buffer(current_header.value)); + buffers.push_back(boost::asio::buffer(crlf)); + } + buffers.push_back(boost::asio::buffer(crlf)); + return buffers; +} + +reply reply::stock_reply(const reply::status_type status) +{ + reply reply; + reply.status = status; + reply.content.clear(); + + const std::string status_string = reply.status_to_string(status); + reply.content.insert(reply.content.end(), status_string.begin(), status_string.end()); + reply.headers.emplace_back("Access-Control-Allow-Origin", "*"); + reply.headers.emplace_back("Content-Length", cast::integral_to_string(reply.content.size())); + reply.headers.emplace_back("Content-Type", "text/html"); + return reply; +} + +std::string reply::status_to_string(const reply::status_type status) +{ + if (reply::ok == status) + { + return ok_html; + } + if (reply::bad_request == status) + { + return bad_request_html; + } + return internal_server_error_html; +} + +boost::asio::const_buffer reply::status_to_buffer(const reply::status_type status) +{ + if (reply::ok == status) + { + return boost::asio::buffer(http_ok_string); + } + if (reply::internal_server_error == status) + { + return boost::asio::buffer(http_internal_server_error_string); + } + return boost::asio::buffer(http_bad_request_string); +} + +reply::reply() : status(ok) {} +} diff --git a/server/http/reply.hpp b/server/http/reply.hpp new file mode 100644 index 000000000..a4b6cb69b --- /dev/null +++ b/server/http/reply.hpp @@ -0,0 +1,65 @@ +/* + +Copyright (c) 2015, Project OSRM, Dennis Luxen, others +All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, +are permitted provided that the following conditions are met: + +Redistributions of source code must retain the above copyright notice, this list +of conditions and the following disclaimer. +Redistributions in binary form must reproduce the above copyright notice, this +list of conditions and the following disclaimer in the documentation and/or +other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR +ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON +ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +*/ + +#ifndef REPLY_HPP +#define REPLY_HPP + +#include "header.hpp" + +#include + +#include + +namespace http +{ +class reply +{ + public: + enum status_type + { + ok = 200, + bad_request = 400, + internal_server_error = 500 + } status; + + std::vector
headers; + std::vector to_buffers(); + std::vector headers_to_buffers(); + std::vector content; + static reply stock_reply(const status_type status); + void set_size(const std::size_t size); + void set_uncompressed_size(); + + reply(); + + private: + std::string status_to_string(reply::status_type status); + boost::asio::const_buffer status_to_buffer(reply::status_type status); +}; +} + +#endif // REPLY_HPP diff --git a/server/http/request.hpp b/server/http/request.hpp new file mode 100644 index 000000000..0ad622580 --- /dev/null +++ b/server/http/request.hpp @@ -0,0 +1,48 @@ +/* + +Copyright (c) 2015, Project OSRM, Dennis Luxen, others +All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, +are permitted provided that the following conditions are met: + +Redistributions of source code must retain the above copyright notice, this list +of conditions and the following disclaimer. +Redistributions in binary form must reproduce the above copyright notice, this +list of conditions and the following disclaimer in the documentation and/or +other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR +ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON +ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +*/ + +#ifndef REQUEST_HPP +#define REQUEST_HPP + +#include + +#include + +namespace http +{ + +struct request +{ + std::string uri; + std::string referrer; + std::string agent; + boost::asio::ip::address endpoint; +}; + +} // namespace http + +#endif // REQUEST_HPP diff --git a/Server/RequestHandler.cpp b/server/request_handler.cpp similarity index 98% rename from Server/RequestHandler.cpp rename to server/request_handler.cpp index 1ff82e24e..ca95118a9 100644 --- a/Server/RequestHandler.cpp +++ b/server/request_handler.cpp @@ -1,6 +1,6 @@ /* -Copyright (c) 2013, Project OSRM, Dennis Luxen, others +Copyright (c) 2015, Project OSRM, Dennis Luxen, others All rights reserved. Redistribution and use in source and binary forms, with or without modification, @@ -25,9 +25,9 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include "RequestHandler.h" +#include "request_handler.hpp" -#include "APIGrammar.h" +#include "api_grammar.hpp" #include "http/reply.hpp" #include "http/request.hpp" diff --git a/Server/RequestHandler.h b/server/request_handler.hpp similarity index 92% rename from Server/RequestHandler.h rename to server/request_handler.hpp index 2f0fd878f..1965a79c0 100644 --- a/Server/RequestHandler.h +++ b/server/request_handler.hpp @@ -1,6 +1,6 @@ /* -Copyright (c) 2013, Project OSRM, Dennis Luxen, others +Copyright (c) 2015, Project OSRM, Dennis Luxen, others All rights reserved. Redistribution and use in source and binary forms, with or without modification, @@ -25,8 +25,8 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef REQUEST_HANDLER_H -#define REQUEST_HANDLER_H +#ifndef REQUEST_HANDLER_HPP +#define REQUEST_HANDLER_HPP #include @@ -56,4 +56,4 @@ class RequestHandler OSRM *routing_machine; }; -#endif // REQUEST_HANDLER_H +#endif // REQUEST_HANDLER_HPP diff --git a/Server/RequestParser.cpp b/server/request_parser.cpp similarity index 99% rename from Server/RequestParser.cpp rename to server/request_parser.cpp index 25bfddf67..258c89198 100644 --- a/Server/RequestParser.cpp +++ b/server/request_parser.cpp @@ -25,7 +25,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include "RequestParser.h" +#include "request_parser.hpp" #include "http/request.hpp" diff --git a/Server/RequestParser.h b/server/request_parser.hpp similarity index 96% rename from Server/RequestParser.h rename to server/request_parser.hpp index 0df106e68..c7a72071e 100644 --- a/Server/RequestParser.h +++ b/server/request_parser.hpp @@ -25,8 +25,8 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef REQUEST_PARSER_H -#define REQUEST_PARSER_H +#ifndef REQUEST_PARSER_HPP +#define REQUEST_PARSER_HPP #include "http/compression_type.hpp" #include "http/header.hpp" @@ -89,4 +89,4 @@ class RequestParser } // namespace http -#endif // REQUEST_PARSER_H +#endif // REQUEST_PARSER_HPP diff --git a/Server/Server.h b/server/server.hpp similarity index 97% rename from Server/Server.h rename to server/server.hpp index b3d618efe..ee9887e52 100644 --- a/Server/Server.h +++ b/server/server.hpp @@ -25,11 +25,11 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef SERVER_H -#define SERVER_H +#ifndef SERVER_HPP +#define SERVER_HPP -#include "Connection.h" -#include "RequestHandler.h" +#include "connection.hpp" +#include "request_handler.hpp" #include "../Util/cast.hpp" #include "../Util/integer_range.hpp" @@ -116,4 +116,4 @@ class Server RequestHandler request_handler; }; -#endif // SERVER_H +#endif // SERVER_HPP diff --git a/tools/springclean.cpp b/tools/springclean.cpp index 7cf98e9e3..054133a58 100644 --- a/tools/springclean.cpp +++ b/tools/springclean.cpp @@ -28,7 +28,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include "../data_structures/shared_memory_factory.hpp" -#include "../Server/data_structures/shared_datatype.hpp" +#include "../server/data_structures/shared_datatype.hpp" #include "../Util/git_sha.hpp" #include "../Util/simple_logger.hpp" diff --git a/tools/unlock_all_mutexes.cpp b/tools/unlock_all_mutexes.cpp index 78fa6dcbf..f68ec32a7 100644 --- a/tools/unlock_all_mutexes.cpp +++ b/tools/unlock_all_mutexes.cpp @@ -27,7 +27,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "../Util/git_sha.hpp" #include "../Util/simple_logger.hpp" -#include "../Server/data_structures/shared_barriers.hpp" +#include "../server/data_structures/shared_barriers.hpp" #include