db-lab1/bserv/server.hpp

53 lines
1.3 KiB
C++
Raw Normal View History

2021-03-05 07:39:47 +00:00
/**
* bserv - Boost-based HTTP Server
*
* reference:
* https://www.boost.org/doc/libs/1_75_0/libs/beast/example/http/server/async/http_server_async.cpp
* https://www.boost.org/doc/libs/1_75_0/libs/beast/example/http/server/coro/http_server_coro.cpp
2021-03-05 07:39:47 +00:00
* https://www.boost.org/doc/libs/1_75_0/libs/beast/example/advanced/server/advanced_server.cpp
*
* websocket:
* https://www.boost.org/doc/libs/1_75_0/libs/beast/example/websocket/server/async/websocket_server_async.cpp
*
2021-03-05 07:39:47 +00:00
*/
2021-07-13 12:53:10 +01:00
#ifndef _SERVER_HPP
#define _SERVER_HPP
2021-03-05 07:39:47 +00:00
#include <boost/beast.hpp>
#include <boost/asio.hpp>
#include <boost/asio/spawn.hpp>
2021-03-05 07:39:47 +00:00
#include <boost/optional.hpp>
#include <boost/json.hpp>
2021-03-05 07:39:47 +00:00
#include <memory>
#include "config.hpp"
2021-07-13 12:53:10 +01:00
#include "router.hpp"
2021-03-05 07:39:47 +00:00
#include "database.hpp"
2021-07-13 12:53:10 +01:00
#include "session.hpp"
2021-03-05 07:39:47 +00:00
namespace bserv {
namespace beast = boost::beast;
namespace http = beast::http;
namespace websocket = beast::websocket;
2021-03-05 07:39:47 +00:00
namespace asio = boost::asio;
namespace json = boost::json;
using asio::ip::tcp;
2021-07-13 12:53:10 +01:00
class server {
private:
// io_context for all I/O
asio::io_context ioc_;
router routes_;
router ws_routes_;
2021-07-14 07:16:00 +01:00
std::shared_ptr<session_manager_base> session_mgr_;
std::shared_ptr<db_connection_manager> db_conn_mgr_;
2021-07-13 12:53:10 +01:00
public:
2021-08-08 01:56:35 +01:00
server(const server_config& config, router&& routes, router&& ws_routes = {});
2021-07-13 12:53:10 +01:00
};
2021-03-05 07:39:47 +00:00
2021-07-13 12:53:10 +01:00
} // bserv
2021-03-05 07:39:47 +00:00
2021-07-13 12:53:10 +01:00
#endif // _SERVER_HPP