Caffa  1.1.0
C++ Application Framework for Embedded Systems with introspection
cafRestServerApplication.h
1 // ##################################################################################################
2 //
3 // Caffa
4 // Copyright (C) 2023- Kontur AS
5 //
6 // GNU Lesser General Public License Usage
7 // This library is free software; you can redistribute it and/or modify
8 // it under the terms of the GNU Lesser General Public License as published by
9 // the Free Software Foundation; either version 2.1 of the License, or
10 // (at your option) any later version.
11 //
12 // This library is distributed in the hope that it will be useful, but WITHOUT ANY
13 // WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 // FITNESS FOR A PARTICULAR PURPOSE.
15 //
16 // See the GNU Lesser General Public License at <<http://www.gnu.org/licenses/lgpl-2.1.html>>
17 // for more details.
18 //
19 #pragma once
20 
21 #include "cafNotNull.h"
22 #include "cafRpcServerApplication.h"
23 #include "cafSession.h"
24 
25 #include <utility>
26 
27 #include <boost/asio.hpp>
28 #include <boost/beast/ssl.hpp>
29 
30 #include <atomic>
31 #include <memory>
32 #include <vector>
33 
34 namespace net = boost::asio; // from <boost/asio.hpp>
35 namespace ssl = boost::asio::ssl; // from <boost/asio/ssl.hpp>
36 
37 namespace caffa::rpc
38 {
39 class RestServer;
40 class RestAuthenticator;
41 
47 {
48 public:
56  RestServerApplication( const std::string& clientHost,
57  unsigned short portNumber,
58  int threads,
59  std::shared_ptr<const RestAuthenticator> authenticator );
60  static RestServerApplication* instance();
61 
62  int portNumber() const override;
63  void run() override;
64  void quit() override;
65  bool running() const override;
66 
67 private:
68  std::string m_clientHost;
69  unsigned short m_portNumber;
70  int m_threads;
71  net::io_context m_ioContext;
72  std::shared_ptr<const RestAuthenticator> m_authenticator;
73  std::shared_ptr<ssl::context> m_sslContext;
74  std::shared_ptr<RestServer> m_server;
75  std::atomic<bool> m_threadRunning;
76 };
77 } // namespace caffa::rpc
Definition: cafRestClient.h:44
Definition: cafRpcServerApplication.h:33
Definition: cafRestServerApplication.h:46
RestServerApplication(const std::string &clientHost, unsigned short portNumber, int threads, std::shared_ptr< const RestAuthenticator > authenticator)
Definition: cafRestServerApplication.cpp:38
Definition: cafRestAppService.h:28