-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
af9c45b
commit 132217f
Showing
10 changed files
with
276 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
127 changes: 127 additions & 0 deletions
127
diag-client-lib/lib/boost-support/src/boost-support/client/tcp/tcp_client.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
/* Diagnostic Client library | ||
* Copyright (C) 2023 Avijit Dey | ||
* | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
*/ | ||
|
||
#include "boost-support/client/tcp/tcp_client.h" | ||
|
||
#include <variant> | ||
|
||
#include "boost-support/connection/tcp/tcp_connection.h" | ||
#include "boost-support/socket/io_context.h" | ||
#include "boost-support/socket/tcp/tcp_socket.h" | ||
#include "boost-support/socket/tls/tls_socket.h" | ||
|
||
namespace boost_support { | ||
namespace client { | ||
namespace tcp { | ||
|
||
/** | ||
* @brief Class to provide implementation of tcp client | ||
*/ | ||
class TcpClient::TcpClientImpl final { | ||
private: | ||
/** | ||
* @brief Type alias for unsecured tcp connection | ||
*/ | ||
using TcpConnectionUnsecured = | ||
connection::tcp::TcpConnection<connection::tcp::ConnectionType::kClient, socket::tcp::TcpSocket>; | ||
|
||
using TlsSocket12 = socket::tls::TlsSocket<socket::tls::TlsVersionType::kTls12>; | ||
|
||
/** | ||
* @brief Type alias for secured tcp connection with tls version 1.2 | ||
*/ | ||
using TcpConnectionSecuredTls12 = | ||
connection::tcp::TcpConnection<connection::tcp::ConnectionType::kClient, TlsSocket12>; | ||
|
||
/** | ||
* @brief Type alias for secured tcp connection with tls version 1.3 | ||
*/ | ||
using TcpConnectionSecuredTls13 = | ||
connection::tcp::TcpConnection<connection::tcp::ConnectionType::kClient, | ||
socket::tls::TlsSocket<socket::tls::TlsVersionType::kTls13>>; | ||
|
||
/** | ||
* @brief Type alias for boost context | ||
*/ | ||
using IoContext = boost_support::socket::IoContext; | ||
|
||
public: | ||
/** | ||
* @brief Constructs an instance of TcpClient | ||
* @param[in] ClientType | ||
* The type of client | ||
*/ | ||
TcpClientImpl(std::string_view local_ip_address, std::uint16_t local_port_num) noexcept | ||
: io_context_{}, | ||
tcp_connection_{std::in_place_type<TcpConnectionUnsecured>, | ||
socket::tcp::TcpSocket{local_ip_address, local_port_num, io_context_.GetContext()}} {} | ||
|
||
TcpClientImpl(std::string_view local_ip_address, std::uint16_t local_port_num, TlsVersion12, | ||
std::string_view ca_certification_path) noexcept | ||
: io_context_{}, | ||
tcp_connection_{std::in_place_type<TcpConnectionSecuredTls12>, | ||
TlsSocket12{local_ip_address, local_port_num, ca_certification_path, io_context_.GetContext()}} { | ||
//TcpConnectionSecuredTls12 test{TlsSocket12{local_ip_address, local_port_num, ca_certification_path, io_context_.GetContext()}}; | ||
|
||
|
||
|
||
//tcp_connection_.emplace<TcpConnectionSecuredTls12>(TlsSocket12{local_ip_address, local_port_num, ca_certification_path, io_context_.GetContext()}); | ||
} | ||
|
||
/** | ||
* @brief Deleted copy assignment and copy constructor | ||
*/ | ||
TcpClientImpl(const TcpClientImpl &other) noexcept = delete; | ||
TcpClientImpl &operator=(const TcpClientImpl &other) noexcept = delete; | ||
|
||
/** | ||
* @brief Deleted move assignment and move constructor | ||
*/ | ||
TcpClientImpl(TcpClientImpl &&other) noexcept = delete; | ||
TcpClientImpl &operator=(TcpClientImpl &&other) noexcept = delete; | ||
|
||
/** | ||
* @brief Destruct an instance of TcpClient | ||
*/ | ||
~TcpClientImpl() noexcept = default; | ||
|
||
private: | ||
/** | ||
* @brief Stores the io context | ||
*/ | ||
IoContext io_context_; | ||
|
||
/** | ||
* @brief Store the tcp connection | ||
*/ | ||
std::variant<std::monostate, TcpConnectionUnsecured, TcpConnectionSecuredTls12, TcpConnectionSecuredTls13> tcp_connection_; | ||
}; | ||
|
||
TcpClient::TcpClient(std::string_view local_ip_address, std::uint16_t local_port_num) noexcept {} | ||
|
||
TcpClient::TcpClient(std::string_view local_ip_address, std::uint16_t local_port_num, TlsVersion12, | ||
std::string_view ca_certification_path) noexcept {} | ||
|
||
TcpClient::~TcpClient() noexcept = default; | ||
|
||
void TcpClient::Initialize() noexcept { | ||
} | ||
|
||
void TcpClient::DeInitialize() noexcept {} | ||
|
||
core_type::Result<void> TcpClient::ConnectToHost(std::string_view host_ip_address, std::uint16_t host_port_num) { | ||
return core_type::Result<void>(); | ||
} | ||
|
||
core_type::Result<void> TcpClient::DisconnectFromHost() { return core_type::Result<void>(); } | ||
|
||
core_type::Result<void> TcpClient::Transmit(TcpMessageConstPtr tcp_message) { return core_type::Result<void>(); } | ||
|
||
} // namespace tcp | ||
} // namespace client | ||
} // namespace boost_support |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.