SRS-control 0.1.4
Loading...
Searching...
No Matches
FecSwitchSocket.hpp
Go to the documentation of this file.
1#pragma once
2
6#include <boost/asio/awaitable.hpp>
7#include <boost/asio/deferred.hpp>
8#include <boost/asio/impl/co_spawn.hpp>
9#include <boost/asio/strand.hpp>
10#include <boost/asio/system_timer.hpp>
11#include <chrono>
12#include <fmt/ranges.h>
13#include <map>
14#include <memory>
15#include <mutex>
16#include <span>
17#include <spdlog/spdlog.h>
18#include <vector>
19
20namespace srs::connection
21{
22 class CommandBase;
23
25 {
26 public:
29
30 // getters:
31 auto get_strand() -> auto& { return strand_; }
32 auto get_time_us() const -> auto
33 {
34 return std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::steady_clock::now() - start_time_)
35 .count();
36 }
37 void launch_actions();
38
39 private:
41 using SmallConnections = std::vector<std::shared_ptr<SmallConnection>>;
42 asio::strand<io_context_type::executor_type> strand_;
43 std::mutex mut_;
44 std::map<UDPEndpoint, SmallConnections> all_connections_;
45 std::vector<char> read_msg_buffer_;
46 std::chrono::time_point<std::chrono::steady_clock> start_time_ = std::chrono::steady_clock::now();
47
48 using ActionType = decltype(asio::co_spawn(strand_, asio::awaitable<void>(), asio::deferred));
49 std::vector<ActionType> action_queue_;
50
51 void register_send_action_imp(asio::awaitable<void> action, const std::shared_ptr<SmallConnection>& connection);
52 auto get_response_msg_buffer() -> auto& { return read_msg_buffer_; }
53 auto is_finished() -> bool;
54 void print_error() const;
55 void response_handler(const UDPEndpoint& endpoint, std::span<char> response);
56
57 explicit FecCommandSocket(int port_number, io_context_type& io_context);
58 void deregister_connection(const UDPEndpoint& endpoint,
59 std::span<char> response,
60 SmallConnections& connections);
61 void print_available_responses() const;
62 };
63
64} // namespace srs::connection
FecCommandSocket(int port_number, io_context_type &io_context)
void deregister_connection(const UDPEndpoint &endpoint, std::span< char > response, SmallConnections &connections)
std::map< UDPEndpoint, SmallConnections > all_connections_
std::vector< ActionType > action_queue_
void register_send_action_imp(asio::awaitable< void > action, const std::shared_ptr< SmallConnection > &connection)
asio::strand< io_context_type::executor_type > strand_
std::chrono::time_point< std::chrono::steady_clock > start_time_
decltype(asio::co_spawn(strand_, asio::awaitable< void >(), asio::deferred)) ActionType
void response_handler(const UDPEndpoint &endpoint, std::span< char > response)
std::vector< std::shared_ptr< SmallConnection > > SmallConnections
boost::asio::ip::basic_endpoint< boost::asio::ip::udp > UDPEndpoint
asio::thread_pool io_context_type