4#include <spdlog/spdlog.h>
16 spdlog::set_pattern(
"[%H:%M:%S] [%^%=7l%$] [thread %t] %v");
17 spdlog::info(
"Welcome to SRS Application");
25 spdlog::trace(
"Application: Resetting io context workguard ... ");
27 if (not
status_.is_acq_off.load())
30 "Failed to close srs system! Please manually close the system with\n\nsrs_control --acq-off\n");
36 spdlog::debug(
"Application: Wait until working thread finishes ...");
39 spdlog::debug(
"io context is stoped");
41 spdlog::debug(
"Application: working thread is finished");
42 spdlog::debug(
"Application has exited.");
47 spdlog::debug(
"Calling the destructor of App ... ");
55 spdlog::debug(
"Turning srs system off ...");
69 [
this](
const boost::system::error_code& error,
auto)
71 if (error == asio::error::operation_aborted)
76 spdlog::info(
"Calling SIGINT from monitoring thread");
78 auto monitoring_action = [
this]()
84 catch (
const std::exception& ex)
86 spdlog::critical(
"Exception on working thread occured: {}", ex.what());
95 auto res =
status_.wait_for_status(
96 [](
const auto& status)
98 spdlog::debug(
"Waiting for reading status false");
99 return not status.is_reading.load();
104 spdlog::critical(
"TIMEOUT during waiting for status is_reading false.");
111 spdlog::debug(
"App::exit is called");
112 status_.is_on_exit.store(
true);
126 spdlog::debug(
"Set the remote socket with ip: {} and port: {}", remote_ip, port_number);
127 auto udp_endpoints = resolver.resolve(udp::v4(), remote_ip, fmt::format(
"{}", port_number));
134 spdlog::debug(
"Add the remote FEC with ip: {} and port: {}", remote_ip, port_number);
135 auto udp_endpoints = resolver.resolve(udp::v4(), remote_ip, fmt::format(
"{}", port_number));
137 if (udp_endpoints.begin() == udp_endpoints.end())
139 spdlog::debug(
"Failed to add the FEC remote point");
152 auto fec_connection = std::make_shared<connection::Starter>(connection_info);
153 fec_connection->set_remote_endpoint(remote_endpoint);
154 asio::post(
fec_strand_, [fec_connection = std::move(fec_connection)]() { fec_connection->acq_on(); });
160 const auto waiting_time = std::chrono::seconds{ 4 };
164 spdlog::debug(
"Waiting for acq_on status true ...");
171 throw std::runtime_error(
"TIMEOUT during waiting for status is_acq_on true.");
178 auto fec_connection = std::make_shared<connection::Stopper>(connection_info);
179 fec_connection->set_remote_endpoint(remote_endpoint);
180 fec_connection->acq_off();
182 spdlog::info(
"SRS system is turned off");
~AppExitHelper() noexcept
asio::executor_work_guard< io_context_type::executor_type > io_work_guard_
void read_data(bool is_non_stop=true)
void set_remote_endpoint(std::string_view remote_ip, int port_number)
void set_status_acq_on(bool val=true)
std::shared_ptr< connection::DataReader > data_reader_
void add_remote_fec_endpoint(std::string_view remote_ip, int port_number)
asio::signal_set signal_set_
std::vector< udp::endpoint > remote_fec_endpoints_
std::jthread working_thread_
void set_print_mode(common::DataPrintMode mode)
void set_output_filenames(const std::vector< std::string > &filenames)
std::unique_ptr< workflow::Handler > workflow_handler_
void start_workflow(bool is_blocking=true)
auto wait_for_status(auto &&condition, std::chrono::seconds time_duration=common::DEFAULT_STATUS_WAITING_TIME_SECONDS) -> bool
asio::strand< io_context_type::executor_type > fec_strand_
udp::endpoint remote_endpoint_
void set_remote_fec_endpoints()
io_context_type io_context_
void wait_for_reading_finish()
void set_status_acq_off(bool val=true)
constexpr auto DEFAULT_SRS_CONTROL_PORT
std::atomic< bool > is_acq_on