Diag-Client-Lib
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
tls_server.h
Go to the documentation of this file.
1 /* Diagnostic Client library
2  * Copyright (C) 2024 Avijit Dey
3  *
4  * This Source Code Form is subject to the terms of the Mozilla Public
5  * License, v. 2.0. If a copy of the MPL was not distributed with this
6  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
7  */
8 #ifndef DIAG_CLIENT_LIB_LIB_BOOST_SUPPORT_INCLUDE_BOOST_SUPPORT_SERVER_TLS_TLS_SERVER_H_
9 #define DIAG_CLIENT_LIB_LIB_BOOST_SUPPORT_INCLUDE_BOOST_SUPPORT_SERVER_TLS_TLS_SERVER_H_
10 
11 #include <functional>
12 #include <memory>
13 
15 #include "core/include/result.h"
16 
17 namespace boost_support {
18 namespace socket {
19 namespace tls {
20 class TlsSocket;
21 } // namespace tls
22 } // namespace socket
23 
24 namespace server {
25 namespace tls {
26 
30 class TlsServer final {
31  public:
36 
41 
46 
51 
55  using HandlerRead = std::function<void(MessagePtr)>;
56 
57  public:
63  explicit TlsServer(std::string_view server_name, TlsSocket tls_socket) noexcept;
64 
68  TlsServer(const TlsServer &other) noexcept = delete;
69  TlsServer &operator=(const TlsServer &other) noexcept = delete;
70 
74  TlsServer(TlsServer &&other) noexcept;
75  TlsServer &operator=(TlsServer &&other) noexcept;
76 
80  ~TlsServer() noexcept;
81 
85  void Initialize() noexcept;
86 
90  void DeInitialize() noexcept;
91 
98  void SetReadHandler(HandlerRead read_handler) noexcept;
99 
106  core_type::Result<void> Transmit(MessageConstPtr tcp_message);
107 
108  private:
112  class TlsServerImpl;
113 
117  std::unique_ptr<TlsServerImpl> tls_server_impl_;
118 };
119 
120 } // namespace tls
121 } // namespace server
122 } // namespace boost_support
123 #endif // DIAG_CLIENT_LIB_LIB_BOOST_SUPPORT_INCLUDE_BOOST_SUPPORT_SERVER_TLS_TLS_SERVER_H_
Immutable class to store received tcp message.
Definition: tcp_message.h:26
Server that manages unsecured/ secured tcp connection.
Definition: tls_server.h:30
std::function< void(MessagePtr)> HandlerRead
Tcp function template used for reception.
Definition: tls_server.h:55
boost_support::message::tcp::TcpMessagePtr MessagePtr
Type alias for Tcp message pointer.
Definition: tls_server.h:45
boost_support::message::tcp::TcpMessageConstPtr MessageConstPtr
Type alias for Tcp message const pointer.
Definition: tls_server.h:50
std::unique_ptr< TlsServerImpl > tls_server_impl_
Unique pointer to tcp server implementation.
Definition: tls_server.h:112
TlsServer & operator=(TlsServer &&other) noexcept
TlsServer(const TlsServer &other) noexcept=delete
Deleted copy assignment and copy constructor.
~TlsServer() noexcept
Destruct an instance of TcpServer.
TlsServer(TlsServer &&other) noexcept
Move assignment and move constructor.
void SetReadHandler(HandlerRead read_handler) noexcept
Function to set the read handler that is invoked when message is received.
Definition: tls_server.cpp:106
core_type::Result< void > Transmit(MessageConstPtr tcp_message)
Function to transmit the provided tcp message.
Definition: tls_server.cpp:110
TlsServer & operator=(const TlsServer &other) noexcept=delete
void DeInitialize() noexcept
De-initialize the server.
Definition: tls_server.cpp:104
void Initialize() noexcept
Initialize the server.
Definition: tls_server.cpp:102
TlsServer(std::string_view server_name, TlsSocket tls_socket) noexcept
Constructs an instance of TlsServer.
Definition: tls_server.cpp:93
Class used to create a tcp socket for handling transmission and reception of tcp message from driver.
Definition: tls_socket.h:25
std::unique_ptr< TcpMessage > TcpMessagePtr
The unique pointer to TcpMessage.
Definition: tcp_message.h:151
std::unique_ptr< TcpMessage const > TcpMessageConstPtr
The unique pointer to const TcpMessage.
Definition: tcp_message.h:146
core_type::Result< T, E > Result
Class type to contains a value (of type ValueType), or an error (of type ErrorType)