alaCarte Maps
Renderer for OpenStreetMap tiles
http_server.hpp
Go to the documentation of this file.
1 
21 #pragma once
22 #ifndef HTTP_SERVER_HPP
23 #define HTTP_SERVER_HPP
24 
25 #include "settings.hpp"
26 
27 #include <set>
28 #include <boost/asio.hpp>
29 
30 class Configuration;
31 class RequestManager;
32 class HttpRequest;
33 
37 class HttpServer : public boost::enable_shared_from_this<HttpServer>
38 {
39 public:
40  HttpServer ( const shared_ptr<Configuration>& config, const shared_ptr<RequestManager>& manager );
41 
42  TESTABLE void listen();
43  TESTABLE void quit();
44  void stopRequest ( shared_ptr<HttpRequest> request );
45 
46 private:
47  void start_accept();
48  void handle_accept ( const boost::system::error_code &e );
49 
50 private:
52  boost::asio::io_service io_service;
53 
55  boost::asio::signal_set signals;
56 
58  boost::asio::ip::tcp::acceptor acceptor;
59 
61  shared_ptr<HttpRequest> nextRequest;
62 
64  std::set<shared_ptr<HttpRequest>> requests;
65 
66  shared_ptr<Configuration> config;
67  shared_ptr<RequestManager> manager;
68 };
69 
70 #endif
void stopRequest(shared_ptr< HttpRequest > request)
Stops a HttpRequest and deletes it from the request list.
Definition: http_server.cpp:93
shared_ptr< Configuration > config
Definition: http_server.hpp:66
TESTABLE void quit()
Cleans up the HttpServer.
std::set< shared_ptr< HttpRequest > > requests
The managed requests.
Definition: http_server.hpp:64
void start_accept()
Prepares the HttpServer for a new connection and waits asynchronous for it.
TESTABLE void listen()
The HttpServer starts listening for new connections.
Definition: http_server.cpp:57
boost::asio::ip::tcp::acceptor acceptor
Acceptor used to listen for incoming requests.
Definition: http_server.hpp:58
boost::asio::signal_set signals
The signal_set is used to register process termination notifications.
Definition: http_server.hpp:55
A HttpServer waits for connections and creates HttpRequests.
Definition: http_server.hpp:37
shared_ptr< HttpRequest > nextRequest
The next connection to be accepted.
Definition: http_server.hpp:61
HttpServer(const shared_ptr< Configuration > &config, const shared_ptr< RequestManager > &manager)
This file is part of alaCarte.
Definition: http_server.cpp:35
Represents a set of options accessible via strings.
#define TESTABLE
Definition: settings.hpp:85
shared_ptr< RequestManager > manager
Definition: http_server.hpp:67
boost::asio::io_service io_service
The io_service used to perform asynchronous operations.
Definition: http_server.hpp:52
void handle_accept(const boost::system::error_code &e)
Called when a new client connects to the server.