SRS-control 0.1.4
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 ()
 Constructor of the App class.
 App (const App &)=delete
 App (App &&)=delete
Appoperator= (const App &)=delete
Appoperator= (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_finish ()
 Manually wait for the working thread to finish.
void wait_for_workflow ()
void set_fec_data_receiv_port (int port_num)
 Set the 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 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 &
void action_after_destructor ()

Private Types

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

Private Member Functions

void wait_for_reading_finish ()
void set_remote_fec_endpoints ()
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

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_
io_context_type io_context_ { 4 }
 Asio io_context that manages the task scheduling and network IO.
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::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::Handlerworkflow_handler_
 The handler to the analysis working flow.
std::shared_ptr< connection::DataSocketdata_socket_
 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 80 of file Application.hpp.

Member Typedef Documentation

◆ SwitchFutureStatusType

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

Definition at line 208 of file Application.hpp.

◆ SwitchFutureType

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

Definition at line 207 of file Application.hpp.

◆ udp

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

Definition at line 206 of file Application.hpp.

Constructor & Destructor Documentation

◆ App() [1/3]

srs::App::App ( )

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 32 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 74 of file Application.cpp.

Member Function Documentation

◆ action_after_destructor()

void srs::App::action_after_destructor ( )

Definition at line 41 of file Application.cpp.

◆ add_remote_fec_endpoint()

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

Definition at line 162 of file Application.cpp.

◆ configure_fec()

void srs::App::configure_fec ( )
inline

Definition at line 128 of file Application.hpp.

◆ exit_and_switch_off()

void srs::App::exit_and_switch_off ( )

Definition at line 124 of file Application.cpp.

◆ get_channel_address()

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

Definition at line 195 of file Application.hpp.

◆ get_config()

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

Definition at line 199 of file Application.hpp.

◆ get_config_ref()

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

Definition at line 200 of file Application.hpp.

◆ get_fec_strand()

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

Definition at line 197 of file Application.hpp.

◆ get_io_context()

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

Definition at line 196 of file Application.hpp.

◆ get_workflow_handler()

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

Definition at line 198 of file Application.hpp.

◆ init()

void srs::App::init ( )

Initialization of internal members.

Definition at line 82 of file Application.cpp.

◆ operator=() [1/2]

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

◆ operator=() [2/2]

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

◆ 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 208 of file Application.cpp.

◆ set_fec_data_receiv_port()

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

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

Definition at line 172 of file Application.hpp.

◆ set_options()

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

Set the configuration values.

Definition at line 187 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 156 of file Application.cpp.

◆ set_print_mode()

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

Set the print mode.

Definition at line 155 of file Application.cpp.

◆ set_remote_fec_endpoints()

void srs::App::set_remote_fec_endpoints ( )
private

Definition at line 255 of file Application.cpp.

◆ 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 226 of file Application.cpp.

◆ switch_FECs()

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

Definition at line 177 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 202 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 196 of file Application.cpp.

◆ wait_for_finish()

void srs::App::wait_for_finish ( )

Manually wait for the working thread to finish.

This method is called automatically in the destructor and shouldn't be called if not necessary. It blocks the program until the working thread exits.

Definition at line 236 of file Application.cpp.

◆ wait_for_reading_finish()

void srs::App::wait_for_reading_finish ( )
private

Definition at line 109 of file Application.cpp.

◆ wait_for_switch_action()

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

Definition at line 238 of file Application.cpp.

◆ wait_for_workflow()

void srs::App::wait_for_workflow ( )
inline

Definition at line 166 of file Application.hpp.

Member Data Documentation

◆ channel_address_

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

Definition at line 210 of file Application.hpp.

◆ config_

Config srs::App::config_
private

Definition at line 211 of file Application.hpp.

◆ data_socket_

std::shared_ptr<connection::DataSocket> srs::App::data_socket_
private

Communication to the main input data stream.

Definition at line 261 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 251 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 233 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 217 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 221 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 225 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 229 of file Application.hpp.

◆ switch_off_future_

SwitchFutureType srs::App::switch_off_future_
private

Definition at line 245 of file Application.hpp.

◆ switch_on_future_

SwitchFutureType srs::App::switch_on_future_
private

Definition at line 243 of file Application.hpp.

◆ workflow_handler_

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

The handler to the analysis working flow.

Definition at line 255 of file Application.hpp.

◆ workflow_thread_

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

Main thread to run workflow.

Definition at line 241 of file Application.hpp.

◆ working_thread_

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

Main working thread.

Definition at line 237 of file Application.hpp.


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