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 const auto data = std::vector<CommunicateEntryType>{ 0, 15, 1 };
25 }
26 void on_fail()
27 {
28 const auto& endpoint = get_remote_endpoint();
29 spdlog::critical(
30 "Cannot start the system: No connection to {}:{}!", endpoint.address().to_string(), endpoint.port());
31 }
32 };
33
34 class Stopper : public Base<>
35 {
36 public:
40 Stopper(const Stopper&) = delete;
41
45 Stopper(Stopper&&) = delete;
46
50 Stopper& operator=(const Stopper&) = delete;
51
56
62 explicit Stopper(const Info& info)
63 : Base(info, "Stopper")
64 {
65 }
66
74 {
75 spdlog::info("SRS system is turned off");
76 get_app().set_status_acq_off();
77 }
78
82 static void on_fail() { spdlog::debug("on_fail of stopper is called"); }
83
92 void acq_off();
93 // void close() {}
94 };
95
96 class DataReader : public Base<common::LARGE_READ_MSG_BUFFER_SIZE>
97 {
98 public:
99 DataReader(const Info& info, workflow::Handler* processor)
100 : workflow_handler_{ processor }
101 , Base(info, "DataReader")
102 {
105 }
106
107 DataReader(const DataReader&) = delete;
109 DataReader& operator=(const DataReader&) = delete;
111 ~DataReader() = default;
112
113 void start(bool is_non_stop = true)
114 {
116 const auto& is_on_exit = get_app().get_status().is_on_exit;
117 if (not is_on_exit.load())
118 {
119 get_app().set_status_is_reading(true);
120 listen(is_non_stop);
121 }
122 else
123 {
124 spdlog::debug("Program is alreay on exit!");
125 }
126 }
127 void close();
128
129 void read_data_handle(std::span<BufferElementType> read_data);
130
131 private:
132 gsl::not_null<workflow::Handler*> workflow_handler_;
133 };
134
135} // 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 >
auto get_app() -> App &
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()
Destructor for Stopper connection class.
static void on_fail()
called if an error occurs
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).
Stopper(const Info &info)
Constructor for Stopper connection class.
constexpr auto NULL_ADDRESS