srs-control
0.2.2
Toggle main menu visibility
Loading...
Searching...
No Matches
ConnectionBase.hpp
Go to the documentation of this file.
1
#pragma once
2
3
#include "
srs/connections/ConnectionTypeDef.hpp
"
4
#include "
srs/connections/FecSwitchSocket.hpp
"
5
#include "
srs/converters/SerializableBuffer.hpp
"
6
#include "
srs/utils/CommonAlias.hpp
"
7
#include "
srs/utils/CommonDefinitions.hpp
"
8
#include "
srs/utils/UDPFormatters.hpp
"
// IWYU pragma: keep
9
#include <algorithm>
10
#include <asio/awaitable.hpp>
11
#include <asio/ip/udp.hpp>
12
#include <cstdint>
13
#include <fmt/base.h>
14
#include <gsl/gsl-lite.hpp>
15
#include <memory>
16
#include <span>
17
#include <spdlog/spdlog.h>
18
#include <string_view>
19
#include <utility>
20
#include <vector>
21
22
namespace
srs::connection
23
{
24
class
FecCommandSocket
;
25
26
class
CommandBase
:
public
std::enable_shared_from_this<CommandBase>
27
{
28
public
:
29
explicit
CommandBase
(
const
std::string_view name)
30
:
name_
{ name }
31
{
32
}
33
40
void
send_message_from
(
this
auto
&& self,
const
std::shared_ptr<FecCommandSocket>& socket)
41
{
42
self.communicate(self.get_suffix(),
common::NULL_ADDRESS
, socket);
43
}
44
45
[[nodiscard]]
auto
check_response
(std::span<char> response_msg)
const
-> bool;
46
47
// Setters:
48
void
set_remote_endpoint
(asio::ip::udp::endpoint endpoint) {
remote_endpoint_
= std::move(endpoint); }
49
50
// Getters:
51
[[nodiscard]]
auto
get_name
() const -> std::string_view {
return
name_
; }
52
auto
get_remote_endpoint
() ->
const
udp::endpoint& {
return
remote_endpoint_
; }
53
[[nodiscard]]
auto
get_response_msg
() const -> std::string_view {
return
write_msg_response_buffer_
.data(); }
54
[[nodiscard]]
auto
get_remote_ip_string
()
const
{
return
remote_endpoint_
.address().to_string(); }
55
[[nodiscard]]
auto
get_remote_port
()
const
{
return
remote_endpoint_
.port(); }
56
57
protected
:
58
void
set_write_response_msg
(
const
std::vector<CommunicateEntryType>& msg, uint16_t address)
59
{
60
encode_write_msg
(
write_msg_response_buffer_
, 0, msg, address);
61
}
62
63
private
:
64
uint32_t
counter_
=
common::INIT_COUNT_VALUE
;
65
udp::endpoint
remote_endpoint_
;
66
process::SerializableMsgBuffer
write_msg_buffer_
;
67
process::SerializableMsgBuffer
write_msg_response_buffer_
;
68
std::string_view
name_
;
69
70
static
void
encode_write_msg
(
process::SerializableMsgBuffer
& buffer,
71
uint32_t counter,
72
std::span<const CommunicateEntryType> data,
73
uint16_t address);
74
75
static
auto
timer_countdown
(
auto
*
connection
) -> asio::awaitable<void>;
76
77
static
auto
send_message
(std::shared_ptr<FecCommandSocket> socket, std::shared_ptr<CommandBase>
connection
)
78
-> asio::awaitable<void>;
79
80
void
communicate
(
this
auto
&& self,
81
std::span<const CommunicateEntryType> data,
82
uint16_t address,
83
const
std::shared_ptr<FecCommandSocket>& socket)
84
{
85
self.encode_write_msg(self.write_msg_buffer_, self.counter_, data, address);
86
auto
send_action =
send_message
(socket, self.shared_from_this());
87
socket->register_send_action(std::move(send_action),
common::get_shared_from_this
(self));
88
}
89
};
90
}
// namespace srs::connection
CommonAlias.hpp
CommonDefinitions.hpp
ConnectionTypeDef.hpp
FecSwitchSocket.hpp
SerializableBuffer.hpp
UDPFormatters.hpp
srs::connection::CommandBase::write_msg_response_buffer_
process::SerializableMsgBuffer write_msg_response_buffer_
Definition
ConnectionBase.hpp:67
srs::connection::CommandBase::send_message
static auto send_message(std::shared_ptr< FecCommandSocket > socket, std::shared_ptr< CommandBase > connection) -> asio::awaitable< void >
Definition
ConnectionBase.cpp:24
srs::connection::CommandBase::name_
std::string_view name_
Definition
ConnectionBase.hpp:68
srs::connection::CommandBase::remote_endpoint_
udp::endpoint remote_endpoint_
Definition
ConnectionBase.hpp:65
srs::connection::CommandBase::set_write_response_msg
void set_write_response_msg(const std::vector< CommunicateEntryType > &msg, uint16_t address)
Definition
ConnectionBase.hpp:58
srs::connection::CommandBase::get_response_msg
auto get_response_msg() const -> std::string_view
Definition
ConnectionBase.hpp:53
srs::connection::CommandBase::check_response
auto check_response(std::span< char > response_msg) const -> bool
Definition
ConnectionBase.cpp:59
srs::connection::CommandBase::counter_
uint32_t counter_
Definition
ConnectionBase.hpp:64
srs::connection::CommandBase::timer_countdown
static auto timer_countdown(auto *connection) -> asio::awaitable< void >
srs::connection::CommandBase::communicate
void communicate(this auto &&self, std::span< const CommunicateEntryType > data, uint16_t address, const std::shared_ptr< FecCommandSocket > &socket)
Definition
ConnectionBase.hpp:80
srs::connection::CommandBase::send_message_from
void send_message_from(this auto &&self, const std::shared_ptr< FecCommandSocket > &socket)
Register the send action in the socket.
Definition
ConnectionBase.hpp:40
srs::connection::CommandBase::get_remote_endpoint
auto get_remote_endpoint() -> const udp::endpoint &
Definition
ConnectionBase.hpp:52
srs::connection::CommandBase::set_remote_endpoint
void set_remote_endpoint(asio::ip::udp::endpoint endpoint)
Definition
ConnectionBase.hpp:48
srs::connection::CommandBase::write_msg_buffer_
process::SerializableMsgBuffer write_msg_buffer_
Definition
ConnectionBase.hpp:66
srs::connection::CommandBase::get_remote_ip_string
auto get_remote_ip_string() const
Definition
ConnectionBase.hpp:54
srs::connection::CommandBase::encode_write_msg
static void encode_write_msg(process::SerializableMsgBuffer &buffer, uint32_t counter, std::span< const CommunicateEntryType > data, uint16_t address)
Definition
ConnectionBase.cpp:44
srs::connection::CommandBase::get_name
auto get_name() const -> std::string_view
Definition
ConnectionBase.hpp:51
srs::connection::CommandBase::CommandBase
CommandBase(const std::string_view name)
Definition
ConnectionBase.hpp:29
srs::connection::CommandBase::get_remote_port
auto get_remote_port() const
Definition
ConnectionBase.hpp:55
srs::connection::FecCommandSocket
Definition
FecSwitchSocket.hpp:29
srs::process::SerializableMsgBuffer
Definition
SerializableBuffer.hpp:14
srs::common::INIT_COUNT_VALUE
constexpr auto INIT_COUNT_VALUE
Definition
CommonDefinitions.hpp:30
srs::common::NULL_ADDRESS
constexpr auto NULL_ADDRESS
Definition
CommonDefinitions.hpp:28
srs::common::get_shared_from_this
constexpr auto get_shared_from_this(auto &&obj)
Definition
CommonFunctions.hpp:97
srs::connection
Definition
Application.hpp:34
backend
srs
connections
ConnectionBase.hpp
Impressum
Datenschutzerklärung
Generated by
1.17.0