Diag-Client-Lib
tls_server.cpp
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 
10 
13 
14 namespace boost_support {
15 namespace server {
16 namespace tls {
17 
19  public:
24 
30 
36  explicit TlsServerImpl(std::string_view server_name, TlsSocket tcp_socket) noexcept
37  : tcp_connection_{server_name, std::move(tcp_socket)} {}
38 
42  TlsServerImpl(const TlsServerImpl &other) noexcept = delete;
43  TlsServerImpl &operator=(const TlsServerImpl &other) noexcept = delete;
44 
48  TlsServerImpl(TlsServerImpl &&other) noexcept = delete;
49  TlsServerImpl &operator=(TlsServerImpl &&other) noexcept = delete;
50 
54  ~TlsServerImpl() noexcept = default;
55 
59  void Initialize() noexcept { tcp_connection_.Initialize(); }
60 
64  void DeInitialize() noexcept { tcp_connection_.DeInitialize(); }
65 
72  void SetReadHandler(HandlerRead read_handler) noexcept {
73  tcp_connection_.SetReadHandler(std::move(read_handler));
74  }
75 
83  return tcp_connection_.Transmit(std::move(tcp_message));
84  }
85 
86  private:
91 };
92 
93 TlsServer::TlsServer(std::string_view server_name, TlsServer::TlsSocket tls_socket) noexcept
94  : tls_server_impl_{std::make_unique<TlsServerImpl>(server_name, std::move(tls_socket))} {}
95 
96 TlsServer::TlsServer(TlsServer &&other) noexcept = default;
97 
98 TlsServer &TlsServer::operator=(TlsServer &&other) noexcept = default;
99 
100 TlsServer::~TlsServer() noexcept = default;
101 
102 void TlsServer::Initialize() noexcept { tls_server_impl_->Initialize(); }
103 
104 void TlsServer::DeInitialize() noexcept { tls_server_impl_->DeInitialize(); }
105 
107  tls_server_impl_->SetReadHandler(std::move(read_handler));
108 }
109 
111  return tls_server_impl_->Transmit(std::move(tcp_message));
112 }
113 } // namespace tls
114 } // namespace server
115 } // namespace boost_support
TlsServerImpl(const TlsServerImpl &other) noexcept=delete
Deleted copy assignment and copy constructor.
TlsServerImpl & operator=(TlsServerImpl &&other) noexcept=delete
TlsServerImpl(TlsServerImpl &&other) noexcept=delete
Deleted move assignment and move constructor.
~TlsServerImpl() noexcept=default
Destruct an instance of TcpServerImpl.
void Initialize() noexcept
Initialize the TcpServerImpl.
Definition: tls_server.cpp:59
TcpConnectionSecured tcp_connection_
Store the tcp connection.
Definition: tls_server.cpp:90
void SetReadHandler(HandlerRead read_handler) noexcept
Function to set the read handler that is invoked when message is received.
Definition: tls_server.cpp:72
TlsServerImpl & operator=(const TlsServerImpl &other) noexcept=delete
core_type::Result< void > Transmit(MessageConstPtr tcp_message)
Function to transmit the provided tcp message.
Definition: tls_server.cpp:82
void DeInitialize() noexcept
De-initialize the TcpServerImpl.
Definition: tls_server.cpp:64
TlsServerImpl(std::string_view server_name, TlsSocket tcp_socket) noexcept
Constructs an instance of TcpServerImpl.
Definition: tls_server.cpp:36
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::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() noexcept
Destruct an instance of TcpServer.
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
Class type to contains a value (of type ValueType), or an error (of type ErrorType)
Definition: result.h:29