SRS-control 0.1.4
Loading...
Searching...
No Matches
Connections.hpp
Go to the documentation of this file.
1#pragma once
2
3#include "ConnectionBase.hpp"
4
5namespace srs::workflow
6{
7 class Handler;
8}
9
10namespace srs::connection
11{
12 class Starter : public Base<>
13 {
14 public:
15 explicit Starter(const Info& info)
16 : Base(info, "Starter")
17 {
18 }
19
20 void close();
21 void acq_on()
22 {
23 spdlog::info("Requesting data from the FEC with the IP: {}", get_remote_endpoint().address().to_string());
24 const auto data = std::vector<CommunicateEntryType>{ 0, 15, 1 };
26 }
27 void on_fail()
28 {
30 const auto& endpoint = get_remote_endpoint();
31 spdlog::critical("Cannot establish a connection to the FEC with the IP: \"{}:{}\"!",
32 endpoint.address().to_string(),
33 endpoint.port());
34 }
35 };
36
37 class Stopper : public Base<>
38 {
39 public:
43 Stopper(const Stopper&) = delete;
44
48 Stopper(Stopper&&) = delete;
49
53 Stopper& operator=(const Stopper&) = delete;
54
59
65 explicit Stopper(const Info& info)
66 : Base(info, "Stopper")
67 {
68 }
69
76 ~Stopper() = default;
77
81 void on_fail()
82 {
83 spdlog::debug("on_fail of stopper is called");
85 }
86
95 void acq_off();
96 // void close() {}
97 };
98
99 class DataReader : public Base<common::LARGE_READ_MSG_BUFFER_SIZE>
100 {
101 public:
102 DataReader(const Info& info, workflow::Handler* processor)
103 : workflow_handler_{ processor }
104 , Base(info, "DataReader")
105 {
108 }
109
110 DataReader(const DataReader&) = delete;
112 DataReader& operator=(const DataReader&) = delete;
114 ~DataReader() = default;
115
116 void start(bool is_non_stop = true)
117 {
119 const auto& is_on_exit = get_app().get_status().is_on_exit;
120 if (not is_on_exit.load())
121 {
122 get_app().set_status_is_reading(true);
123 spdlog::info("UDP data reading has been started");
124 listen(is_non_stop);
125 }
126 else
127 {
128 spdlog::debug("Program is alreay on exit!");
129 }
130 }
131 void close();
132
133 void read_data_handle(std::span<BufferElementType> read_data);
134
135 private:
136 gsl::not_null<workflow::Handler*> workflow_handler_;
137 };
138
139} // namespace srs::connection
void set_socket(std::unique_ptr< asio::ip::udp::socket > socket)
void listen(this auto &&self, bool is_non_stop=false)
auto get_remote_endpoint() -> const udp::endpoint &
void communicate(this auto &&self, const std::vector< CommunicateEntryType > &data, uint16_t address)
auto new_shared_socket(int port_number) -> std::unique_ptr< udp::socket >
Base(const Info &info, std::string name)
gsl::not_null< workflow::Handler * > workflow_handler_
void read_data_handle(std::span< BufferElementType > read_data)
DataReader(DataReader &&)=delete
DataReader(const DataReader &)=delete
DataReader & operator=(DataReader &&)=delete
DataReader(const Info &info, workflow::Handler *processor)
DataReader & operator=(const DataReader &)=delete
void start(bool is_non_stop=true)
Starter(const Info &info)
~Stopper()=default
Destructor for Stopper connection class.
Stopper(Stopper &&)=delete
Deleted move constructor (rule of 5).
Stopper & operator=(const Stopper &)=delete
Deleted copy assignment operator (rule of 5).
void acq_off()
Turn off the data acquisition from SRS system.
Stopper(const Stopper &)=delete
Deleted copy constructor (rule of 5).
Stopper & operator=(Stopper &&)=delete
Deleted move assignment operator (rule of 5).
void on_fail()
called if an error occurs
Stopper(const Info &info)
Constructor for Stopper connection class.
constexpr auto NULL_ADDRESS