srs-control 0.2.2
Loading...
Searching...
No Matches
srs::App Class Reference

The primary interface class of SRS-Control. More...

#include <Application.hpp>

Collaboration diagram for srs::App:

Public Member Functions

 App (Config config)
 Constructor of the App class.
 App (const App &)=delete
 App (App &&)=delete
App & operator= (const App &)=delete
App & operator= (App &&)=delete
 ~App () noexcept
 Destructor of the App class.
void init ()
 Initialization of internal members.
void configure_fec ()
void switch_on ()
 Establish the communications to the available FECs to start the data acquisition.
void switch_off ()
 Establish the communications to the available FECs to stop the data acquisition.
void read_data (bool is_non_stop=true)
 Start reading the input data stream from the port specified by srs::Config::fec_data_receive_port. If is_non_stop is true, the reading process will not be stopped until an interrupt happens, such as pressing "Ctrl-C" from users. If is_non_stop is false, the reading process will be stopped after one frame of data is read.
void start_workflow ()
 Start data analysis workflow, triggering data conversions.
void wait_for_workflow ()
 Wait for the workflow process to finish.
void set_fec_data_receiv_ports (const std::vector< int > &port_nums)
 Set the local listen port numbers for the communications to FEC devices.
void add_fec_data_receiv_port (int port_num)
 Add a local listen port number for the communications to FEC devices.
void set_print_mode (common::DataPrintMode mode)
 Set the print mode.
void set_output_filenames (const std::vector< std::string > &filenames, std::size_t n_lines=1)
 Set the output filenames.
void set_options (Config options)
 Set the configuration values.
void set_runtime_sec (std::size_t runtime_sec)
 Set the runtime in seconds.
void exit_and_switch_off ()
auto get_channel_address () const -> uint16_t
auto get_io_context () -> auto &
auto get_fec_strand () -> auto &
auto get_workflow_handler () const -> const auto &
auto get_config () const -> const auto &
auto get_config_ref () -> auto &
auto get_report () -> AppReport &
void action_after_destructor ()

Private Types

using udp = asio::ip::udp
using SwitchFutureType = std::expected<std::future<void>, std::error_code>
using SwitchFutureStatusType = std::expected<std::future_status, std::error_code>

Private Member Functions

void print_statistics () const
void init_spdlog ()
void wait_for_reading_finish ()
void set_remote_fec_endpoints ()
void set_cancel_method ()
void add_remote_fec_endpoint (std::string_view remote_ip, int port_number)
template<typename T>
auto switch_FECs (std::string_view connection_name) -> SwitchFutureType
auto check_port_number_validity () -> bool

Static Private Member Functions

static auto wait_for_switch_action (const SwitchFutureType &switch_future) -> SwitchFutureStatusType

Private Attributes

uint16_t channel_address_ = common::DEFAULT_CHANNEL_ADDRE
Config config_
std::unique_ptr< AppReport > report_
io_context_type io_context_ { 4 }
 Asio io_context that manages the task scheduling and network IO.
std::size_t runtime_sec_ {}
 Time duration (seconds) to stop the application. If value is zero, the application is in non-stop mode and must be stopped by pressing Ctrl-C.
asio::executor_work_guard< io_context_type::executor_type > io_work_guard_
 Asio io_context work guard.
std::vector< udp::endpoint > remote_fec_endpoints_
 Remote endpoints of FEC devices.
asio::signal_set signal_set_ { io_context_, SIGINT, SIGTERM }
 User signal handler for interrupts.
asio::steady_timer cancel_timer_ { io_context_ }
 Cancelling timer.
asio::strand< io_context_type::executor_type > fec_strand_
 FEC communication strand for synchronous communications.
std::jthread working_thread_
 Main working thread.
std::jthread workflow_thread_
 Main thread to run workflow.
SwitchFutureType switch_on_future_
SwitchFutureType switch_off_future_
internal::AppExitHelper exit_helper_ { this }
 Exit helper for App class. This is called after calling the destructor.
std::unique_ptr< workflow::AnalysisHandle > workflow_handler_
 The handler to the analysis working flow.
std::vector< std::shared_ptr< connection::DataSocket > > data_sockets_
 Communication to the main input data stream.

Detailed Description

The primary interface class of SRS-Control.

Application class should be instantiated only once during the whole program. Public setter methods should be called before calling the init() method.

Definition at line 81 of file Application.hpp.

Member Typedef Documentation

◆ SwitchFutureStatusType

using srs::App::SwitchFutureStatusType = std::expected<std::future_status, std::error_code>
private

Definition at line 218 of file Application.hpp.

◆ SwitchFutureType

using srs::App::SwitchFutureType = std::expected<std::future<void>, std::error_code>
private

Definition at line 217 of file Application.hpp.

◆ udp

using srs::App::udp = asio::ip::udp
private

Definition at line 216 of file Application.hpp.

Constructor & Destructor Documentation

◆ App() [1/3]

srs::App::App ( Config config)

Constructor of the App class.

The constructor contains following actions:

  1. Instantiation of the work guard, which make sure the io_context_ keep accepting new tasks.
  2. Instantiation of strand from the io_context_, which synchronizes the communications among the FECs.
  3. Set the logging format.
  4. Instantiation (memory allocation) of workflow_handler_.

Definition at line 83 of file Application.cpp.

◆ App() [2/3]

srs::App::App ( const App & )
delete

◆ App() [3/3]

srs::App::App ( App && )
delete

◆ ~App()

srs::App::~App ( )
noexcept

Destructor of the App class.

This destructor is called before the destruction of each members. The destructor contains following actions:

  1. Cancel the signal_set_.
  2. Wait for the Status::is_reading to be false, which will be unset from connection::DataReader::close(). The waiting time is set to be common::DEFAULT_STATUS_WAITING_TIME_SECONDS.
  3. Requesting acquisition off to all FEC devices.
  4. Set the Status::is_acq_on to be true.

The exit process of App class also contains the destruction of its member variables. The following order must be kept:

  1. Destruction of connection::DataReader member.
  2. Destruction of workflow::Handler member.
  3. Destruction of internal::AppExitHelper member, which calls end_of_work method.
  4. Destruction of working_thread_ (std::jthread) by waiting for the thread to finish.
  5. Destruction other members. Orders are not important.
  6. Destruction of io_context member. This must be done in the very end.
See also
internal::AppExitHelper

Definition at line 125 of file Application.cpp.

Member Function Documentation

◆ action_after_destructor()

void srs::App::action_after_destructor ( )

Definition at line 92 of file Application.cpp.

◆ add_fec_data_receiv_port()

void srs::App::add_fec_data_receiv_port ( int port_num)
inline

Add a local listen port number for the communications to FEC devices.

Definition at line 176 of file Application.hpp.

◆ add_remote_fec_endpoint()

void srs::App::add_remote_fec_endpoint ( std::string_view remote_ip,
int port_number )
private

Definition at line 271 of file Application.cpp.

◆ check_port_number_validity()

auto srs::App::check_port_number_validity ( ) -> bool
private

Definition at line 315 of file Application.cpp.

◆ configure_fec()

void srs::App::configure_fec ( )
inline

Definition at line 129 of file Application.hpp.

◆ exit_and_switch_off()

void srs::App::exit_and_switch_off ( )

Definition at line 223 of file Application.cpp.

◆ get_channel_address()

auto srs::App::get_channel_address ( ) const -> uint16_t
inlinenodiscard

Definition at line 204 of file Application.hpp.

◆ get_config()

auto srs::App::get_config ( ) const -> const auto &
inlinenodiscard

Definition at line 208 of file Application.hpp.

◆ get_config_ref()

auto srs::App::get_config_ref ( ) -> auto &
inlinenodiscard

Definition at line 209 of file Application.hpp.

◆ get_fec_strand()

auto srs::App::get_fec_strand ( ) -> auto &
inlinenodiscard

Definition at line 206 of file Application.hpp.

◆ get_io_context()

auto srs::App::get_io_context ( ) -> auto &
inlinenodiscard

Definition at line 205 of file Application.hpp.

◆ get_report()

auto srs::App::get_report ( ) -> AppReport &
inlinenodiscard

Definition at line 210 of file Application.hpp.

◆ get_workflow_handler()

auto srs::App::get_workflow_handler ( ) const -> const auto &
inlinenodiscard

Definition at line 207 of file Application.hpp.

◆ init()

void srs::App::init ( )

Initialization of internal members.

Definition at line 175 of file Application.cpp.

◆ init_spdlog()

void srs::App::init_spdlog ( )
private

Definition at line 48 of file Application.cpp.

◆ operator=() [1/2]

App & srs::App::operator= ( App && )
delete

◆ operator=() [2/2]

App & srs::App::operator= ( const App & )
delete

◆ print_statistics()

void srs::App::print_statistics ( ) const
private

Definition at line 132 of file Application.cpp.

◆ read_data()

void srs::App::read_data ( bool is_non_stop = true)

Start reading the input data stream from the port specified by srs::Config::fec_data_receive_port. If is_non_stop is true, the reading process will not be stopped until an interrupt happens, such as pressing "Ctrl-C" from users. If is_non_stop is false, the reading process will be stopped after one frame of data is read.

Parameters
is_non_stopFlag to set non-stop mode.

Definition at line 330 of file Application.cpp.

◆ set_cancel_method()

void srs::App::set_cancel_method ( )
private

Definition at line 140 of file Application.cpp.

◆ set_fec_data_receiv_ports()

void srs::App::set_fec_data_receiv_ports ( const std::vector< int > & port_nums)
inline

Set the local listen port numbers for the communications to FEC devices.

Definition at line 168 of file Application.hpp.

◆ set_options()

void srs::App::set_options ( Config options)
inline

Set the configuration values.

Definition at line 191 of file Application.hpp.

◆ set_output_filenames()

void srs::App::set_output_filenames ( const std::vector< std::string > & filenames,
std::size_t n_lines = 1 )

Set the output filenames.

Definition at line 265 of file Application.cpp.

◆ set_print_mode()

void srs::App::set_print_mode ( common::DataPrintMode mode)

Set the print mode.

Definition at line 264 of file Application.cpp.

◆ set_remote_fec_endpoints()

void srs::App::set_remote_fec_endpoints ( )
private

Definition at line 384 of file Application.cpp.

◆ set_runtime_sec()

void srs::App::set_runtime_sec ( std::size_t runtime_sec)
inline

Set the runtime in seconds.

Definition at line 196 of file Application.hpp.

◆ start_workflow()

void srs::App::start_workflow ( )

Start data analysis workflow, triggering data conversions.

This function call is executed in the main thread.

Definition at line 357 of file Application.cpp.

◆ switch_FECs()

template<typename T>
auto srs::App::switch_FECs ( std::string_view connection_name) -> SwitchFutureType
private

Definition at line 286 of file Application.cpp.

◆ switch_off()

void srs::App::switch_off ( )

Establish the communications to the available FECs to stop the data acquisition.

Definition at line 309 of file Application.cpp.

◆ switch_on()

void srs::App::switch_on ( )

Establish the communications to the available FECs to start the data acquisition.

Definition at line 307 of file Application.cpp.

◆ wait_for_reading_finish()

void srs::App::wait_for_reading_finish ( )
private

Definition at line 203 of file Application.cpp.

◆ wait_for_switch_action()

auto srs::App::wait_for_switch_action ( const SwitchFutureType & switch_future) -> SwitchFutureStatusType
staticprivate

Definition at line 367 of file Application.cpp.

◆ wait_for_workflow()

void srs::App::wait_for_workflow ( )
inline

Wait for the workflow process to finish.

Definition at line 162 of file Application.hpp.

Member Data Documentation

◆ cancel_timer_

asio::steady_timer srs::App::cancel_timer_ { io_context_ }
private

Cancelling timer.

Definition at line 250 of file Application.hpp.

◆ channel_address_

uint16_t srs::App::channel_address_ = common::DEFAULT_CHANNEL_ADDRE
private

Definition at line 220 of file Application.hpp.

◆ config_

Config srs::App::config_
private

Definition at line 221 of file Application.hpp.

◆ data_sockets_

std::vector<std::shared_ptr<connection::DataSocket> > srs::App::data_sockets_
private

Communication to the main input data stream.

Definition at line 282 of file Application.hpp.

◆ exit_helper_

internal::AppExitHelper srs::App::exit_helper_ { this }
private

Exit helper for App class. This is called after calling the destructor.

Definition at line 272 of file Application.hpp.

◆ fec_strand_

asio::strand<io_context_type::executor_type> srs::App::fec_strand_
private

FEC communication strand for synchronous communications.

Definition at line 254 of file Application.hpp.

◆ io_context_

io_context_type srs::App::io_context_ { 4 }
private

Asio io_context that manages the task scheduling and network IO.

Definition at line 229 of file Application.hpp.

◆ io_work_guard_

asio::executor_work_guard<io_context_type::executor_type> srs::App::io_work_guard_
private

Asio io_context work guard.

Definition at line 238 of file Application.hpp.

◆ remote_fec_endpoints_

std::vector<udp::endpoint> srs::App::remote_fec_endpoints_
private

Remote endpoints of FEC devices.

Definition at line 242 of file Application.hpp.

◆ report_

std::unique_ptr<AppReport> srs::App::report_
private

Definition at line 225 of file Application.hpp.

◆ runtime_sec_

std::size_t srs::App::runtime_sec_ {}
private

Time duration (seconds) to stop the application. If value is zero, the application is in non-stop mode and must be stopped by pressing Ctrl-C.

Definition at line 234 of file Application.hpp.

◆ signal_set_

asio::signal_set srs::App::signal_set_ { io_context_, SIGINT, SIGTERM }
private

User signal handler for interrupts.

Definition at line 246 of file Application.hpp.

◆ switch_off_future_

SwitchFutureType srs::App::switch_off_future_
private

Definition at line 266 of file Application.hpp.

◆ switch_on_future_

SwitchFutureType srs::App::switch_on_future_
private

Definition at line 264 of file Application.hpp.

◆ workflow_handler_

std::unique_ptr<workflow::AnalysisHandle> srs::App::workflow_handler_
private

The handler to the analysis working flow.

Definition at line 276 of file Application.hpp.

◆ workflow_thread_

std::jthread srs::App::workflow_thread_
private

Main thread to run workflow.

Definition at line 262 of file Application.hpp.

◆ working_thread_

std::jthread srs::App::working_thread_
private

Main working thread.

Definition at line 258 of file Application.hpp.


The documentation for this class was generated from the following files: