Add namespace around all files
This commit is contained in:
@@ -5,6 +5,11 @@
|
||||
#include <boost/spirit/include/qi.hpp>
|
||||
#include <boost/spirit/include/qi_action.hpp>
|
||||
|
||||
namespace osrm
|
||||
{
|
||||
namespace server
|
||||
{
|
||||
|
||||
namespace qi = boost::spirit::qi;
|
||||
|
||||
template <typename Iterator, class HandlerT> struct APIGrammar : qi::grammar<Iterator>
|
||||
@@ -98,4 +103,7 @@ template <typename Iterator, class HandlerT> struct APIGrammar : qi::grammar<Ite
|
||||
HandlerT *handler;
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* API_GRAMMAR_HPP */
|
||||
|
||||
@@ -26,10 +26,12 @@ template <class T> T *get_pointer(std::shared_ptr<T> &p) { return p.get(); }
|
||||
|
||||
#endif
|
||||
|
||||
class RequestHandler;
|
||||
|
||||
namespace http
|
||||
namespace osrm
|
||||
{
|
||||
namespace server
|
||||
{
|
||||
|
||||
class RequestHandler;
|
||||
|
||||
/// Represents a single connection from a client.
|
||||
class Connection : public std::enable_shared_from_this<Connection>
|
||||
@@ -51,18 +53,19 @@ class Connection : public std::enable_shared_from_this<Connection>
|
||||
void handle_write(const boost::system::error_code &e);
|
||||
|
||||
std::vector<char> compress_buffers(const std::vector<char> &uncompressed_data,
|
||||
const compression_type compression_type);
|
||||
const http::compression_type compression_type);
|
||||
|
||||
boost::asio::io_service::strand strand;
|
||||
boost::asio::ip::tcp::socket TCP_socket;
|
||||
RequestHandler &request_handler;
|
||||
RequestParser request_parser;
|
||||
boost::array<char, 8192> incoming_data_buffer;
|
||||
request current_request;
|
||||
reply current_reply;
|
||||
http::request current_request;
|
||||
http::reply current_reply;
|
||||
std::vector<char> compressed_output;
|
||||
};
|
||||
|
||||
} // namespace http
|
||||
}
|
||||
}
|
||||
|
||||
#endif // CONNECTION_HPP
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
#ifndef COMPRESSION_TYPE_HPP
|
||||
#define COMPRESSION_TYPE_HPP
|
||||
|
||||
namespace osrm
|
||||
{
|
||||
namespace server
|
||||
{
|
||||
namespace http
|
||||
{
|
||||
|
||||
@@ -10,6 +14,9 @@ enum compression_type
|
||||
gzip_rfc1952,
|
||||
deflate_rfc1951
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif // COMPRESSION_TYPE_HPP
|
||||
|
||||
@@ -4,8 +4,13 @@
|
||||
#include <string>
|
||||
#include <algorithm>
|
||||
|
||||
namespace osrm
|
||||
{
|
||||
namespace server
|
||||
{
|
||||
namespace http
|
||||
{
|
||||
|
||||
struct header
|
||||
{
|
||||
// explicitly use default copy c'tor as adding move c'tor
|
||||
@@ -22,6 +27,9 @@ struct header
|
||||
std::string name;
|
||||
std::string value;
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif // HEADER_HPP
|
||||
|
||||
@@ -7,8 +7,13 @@
|
||||
|
||||
#include <vector>
|
||||
|
||||
namespace osrm
|
||||
{
|
||||
namespace server
|
||||
{
|
||||
namespace http
|
||||
{
|
||||
|
||||
class reply
|
||||
{
|
||||
public:
|
||||
@@ -33,6 +38,9 @@ class reply
|
||||
std::string status_to_string(reply::status_type status);
|
||||
boost::asio::const_buffer status_to_buffer(reply::status_type status);
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif // REPLY_HPP
|
||||
|
||||
@@ -5,6 +5,10 @@
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace osrm
|
||||
{
|
||||
namespace server
|
||||
{
|
||||
namespace http
|
||||
{
|
||||
|
||||
@@ -16,6 +20,8 @@ struct request
|
||||
boost::asio::ip::address endpoint;
|
||||
};
|
||||
|
||||
} // namespace http
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif // REQUEST_HPP
|
||||
|
||||
@@ -3,9 +3,16 @@
|
||||
|
||||
#include <string>
|
||||
|
||||
template <typename Iterator, class HandlerT> struct APIGrammar;
|
||||
struct RouteParameters;
|
||||
namespace osrm
|
||||
{
|
||||
namespace engine
|
||||
{
|
||||
class OSRM;
|
||||
struct RouteParameters;
|
||||
}
|
||||
namespace server
|
||||
{
|
||||
template <typename Iterator, class HandlerT> struct APIGrammar;
|
||||
|
||||
namespace http
|
||||
{
|
||||
@@ -17,16 +24,19 @@ class RequestHandler
|
||||
{
|
||||
|
||||
public:
|
||||
using APIGrammarParser = APIGrammar<std::string::iterator, RouteParameters>;
|
||||
using APIGrammarParser = APIGrammar<std::string::iterator, engine::RouteParameters>;
|
||||
|
||||
RequestHandler();
|
||||
RequestHandler(const RequestHandler &) = delete;
|
||||
|
||||
void handle_request(const http::request ¤t_request, http::reply ¤t_reply);
|
||||
void RegisterRoutingMachine(OSRM *osrm);
|
||||
void RegisterRoutingMachine(engine::OSRM *osrm);
|
||||
|
||||
private:
|
||||
OSRM *routing_machine;
|
||||
engine::OSRM *routing_machine;
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif // REQUEST_HANDLER_HPP
|
||||
|
||||
@@ -7,21 +7,27 @@
|
||||
|
||||
#include <tuple>
|
||||
|
||||
namespace http
|
||||
namespace osrm
|
||||
{
|
||||
namespace server
|
||||
{
|
||||
|
||||
namespace http
|
||||
{
|
||||
struct request;
|
||||
}
|
||||
|
||||
|
||||
class RequestParser
|
||||
{
|
||||
public:
|
||||
RequestParser();
|
||||
|
||||
std::tuple<osrm::tribool, compression_type>
|
||||
parse(request ¤t_request, char *begin, char *end);
|
||||
std::tuple<util::tribool, http::compression_type>
|
||||
parse(http::request ¤t_request, char *begin, char *end);
|
||||
|
||||
private:
|
||||
osrm::tribool consume(request ¤t_request, const char input);
|
||||
util::tribool consume(http::request ¤t_request, const char input);
|
||||
|
||||
bool is_char(const int character) const;
|
||||
|
||||
@@ -60,12 +66,13 @@ class RequestParser
|
||||
post_request
|
||||
} state;
|
||||
|
||||
header current_header;
|
||||
compression_type selected_compression;
|
||||
http::header current_header;
|
||||
http::compression_type selected_compression;
|
||||
bool is_post_header;
|
||||
int content_length;
|
||||
};
|
||||
|
||||
} // namespace http
|
||||
}
|
||||
}
|
||||
|
||||
#endif // REQUEST_PARSER_HPP
|
||||
|
||||
@@ -18,6 +18,11 @@
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
namespace osrm
|
||||
{
|
||||
namespace server
|
||||
{
|
||||
|
||||
class Server
|
||||
{
|
||||
public:
|
||||
@@ -25,7 +30,7 @@ class Server
|
||||
static std::shared_ptr<Server>
|
||||
CreateServer(std::string &ip_address, int ip_port, unsigned requested_num_threads)
|
||||
{
|
||||
SimpleLogger().Write() << "http 1.1 compression handled by zlib version " << zlibVersion();
|
||||
util::SimpleLogger().Write() << "http 1.1 compression handled by zlib version " << zlibVersion();
|
||||
const unsigned hardware_threads = std::max(1u, std::thread::hardware_concurrency());
|
||||
const unsigned real_num_threads = std::min(hardware_threads, requested_num_threads);
|
||||
return std::make_shared<Server>(ip_address, ip_port, real_num_threads);
|
||||
@@ -33,7 +38,7 @@ class Server
|
||||
|
||||
explicit Server(const std::string &address, const int port, const unsigned thread_pool_size)
|
||||
: thread_pool_size(thread_pool_size), acceptor(io_service),
|
||||
new_connection(std::make_shared<http::Connection>(io_service, request_handler))
|
||||
new_connection(std::make_shared<Connection>(io_service, request_handler))
|
||||
{
|
||||
const auto port_string = std::to_string(port);
|
||||
|
||||
@@ -75,7 +80,7 @@ class Server
|
||||
if (!e)
|
||||
{
|
||||
new_connection->start();
|
||||
new_connection = std::make_shared<http::Connection>(io_service, request_handler);
|
||||
new_connection = std::make_shared<Connection>(io_service, request_handler);
|
||||
acceptor.async_accept(
|
||||
new_connection->socket(),
|
||||
boost::bind(&Server::HandleAccept, this, boost::asio::placeholders::error));
|
||||
@@ -85,8 +90,11 @@ class Server
|
||||
unsigned thread_pool_size;
|
||||
boost::asio::io_service io_service;
|
||||
boost::asio::ip::tcp::acceptor acceptor;
|
||||
std::shared_ptr<http::Connection> new_connection;
|
||||
std::shared_ptr<Connection> new_connection;
|
||||
RequestHandler request_handler;
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif // SERVER_HPP
|
||||
|
||||
Reference in New Issue
Block a user