ADTF  3.18.4
threaded_http_server.h
Go to the documentation of this file.
1 
15 #ifndef PKG_RPC_RPC_DETAIL_THREAD_HTTP_SERVER_H_
16 #define PKG_RPC_RPC_DETAIL_THREAD_HTTP_SERVER_H_
17 
19 
20 #include <map>
21 #include <memory>
22 #include <string>
23 
24 namespace rpc {
25 namespace http {
26 
28 namespace detail {
29 
30 class cThreadedHttpServer {
31 public:
32  cThreadedHttpServer();
33  ~cThreadedHttpServer();
34  cThreadedHttpServer(const cThreadedHttpServer&) = delete;
35  cThreadedHttpServer& operator=(const cThreadedHttpServer&) = delete;
36  cThreadedHttpServer(cThreadedHttpServer&&) = default;
37  cThreadedHttpServer& operator=(cThreadedHttpServer&&) = default;
38 
44  a_util::result::Result StartListening(const char* strURL, int reuse = 1);
45 
50  a_util::result::Result StopListening();
51 
52 protected:
53  virtual bool HandleRequest(const std::string& strUrl,
54  const std::string& strRequest,
55  std::string& strResponse,
56  std::string& strContentType) = 0;
57 
58  struct tRequest {
59  const std::string& method;
60  const std::string& url;
61  const std::multimap<std::string, std::string>& headers;
62  const std::string& body;
63  const std::map<std::string, std::string>& params;
64  };
65 
66  struct tResponse {
67  int& status;
68  std::multimap<std::string, std::string>& headers;
69  std::string& body;
70  };
71 
72  virtual bool HandleRequest(const tRequest& sRequest, tResponse& sResponse);
73 
74 private:
75  class cImplementation;
76  std::unique_ptr<cImplementation> m_pImplementation;
77 };
78 
79 } // namespace detail
81 } // namespace http
82 } // namespace rpc
83 
84 #endif
A common result class usable as return value throughout.
Common include for Result functionality.