1 #ifndef PICHI_API_SESSION_HPP
2 #define PICHI_API_SESSION_HPP
3 
4 #include <boost/asio/io_context.hpp>
5 #include <boost/asio/strand.hpp>
6 #include <memory>
7 #include <pichi/common/adapter.hpp>
8 #include <pichi/common/endpoint.hpp>
9 
10 namespace pichi::api {
11 
12 class Session : public std::enable_shared_from_this<Session> {
13 private:
14   using Strand = boost::asio::io_context::strand;
15   using IngressPtr = std::unique_ptr<Ingress>;
16   using EgressPtr = std::unique_ptr<Egress>;
17 
18   template <typename Yield> void close(Yield);
19 
20 public:
21   Session(Session const&) = delete;
22   Session(Session&&) = delete;
23   Session& operator=(Session const&) = delete;
24   Session& operator=(Session&&) = delete;
25 
26   // According to Effective Moderm C++, Item 22.
27   ~Session();
28   explicit Session(boost::asio::io_context& io, IngressPtr&&, EgressPtr&&);
29   void start(Endpoint const&, ResolveResults const&);
30   void start();
31 
32 private:
33   Strand strand_;
34   IngressPtr ingress_;
35   EgressPtr egress_;
36 };
37 
38 }  // namespace pichi::api
39 
40 #endif
41