rad 6.2.0
Loading...
Searching...
No Matches
Public Member Functions | List of all members
rad::Application Class Reference

#include <application.hpp>

Inheritance diagram for rad::Application:
rad::SMAdapter scxml4cpp::EventListener scxml4cpp::StatusListener rad::utest::Application

Public Member Functions

 Application (const std::string &name, rad::DataContext &data)
 
 ~Application () override
 
virtual bool Config (int argc, char *argv[])
 
virtual void Init (rad::ConfigurableActionMgr &action_mgr)
 
virtual bool Init (int argc, char *argv[], rad::ConfigurableActionMgr &action_mgr)
 
void RegisterMalDds (const elt::mal::Mal::Properties &mal_properties)
 
virtual void RegisterMalDds ()
 
virtual void Run ()
 
void StopEventLoop ()
 
const std::string & GetName () const
 
rad::DataContextGetDataContext ()
 
boost::asio::io_context & GetEventLoop ()
 
std::shared_ptr< elt::mal::Mal > GetMalInstance ()
 
std::shared_ptr< elt::mal::Mal > GetMalDdsInstance ()
 
void CreateReplier (const std::string &uri)
 
template<typename IF , typename IF_IMPL >
void RegisterService (const std::string &name, std::shared_ptr< IF_IMPL > if_impl)
 
 Application (const Application &)=delete
 
Applicationoperator= (const Application &)=delete
 Disable copy constructor.
 
- Public Member Functions inherited from rad::SMAdapter
 SMAdapter (boost::asio::io_context &ios, scxml4cpp::Context *context, scxml4cpp::EventQueue &external_events)
 
virtual ~SMAdapter ()
 
void Load (const std::string &filename, std::list< scxml4cpp::Action * > *action_list, std::list< scxml4cpp::Activity * > *activity_list, const scxml4cpp::ReplaceRules &replace_rules=scxml4cpp::ReplaceRules())
 
void LoadFromString (const std::string &name, const std::string &model, std::list< scxml4cpp::Action * > *action_list, std::list< scxml4cpp::Activity * > *activity_list, const scxml4cpp::ReplaceRules &replace_rules=scxml4cpp::ReplaceRules())
 
void Append (const std::string &filename, std::list< scxml4cpp::Action * > *action_list, std::list< scxml4cpp::Activity * > *activity_list, const scxml4cpp::ReplaceRules &replace_rules=scxml4cpp::ReplaceRules())
 
void AppendFromString (const std::string &name, const std::string &model, std::list< scxml4cpp::Action * > *action_list, std::list< scxml4cpp::Activity * > *activity_list, const scxml4cpp::ReplaceRules &replace_rules=scxml4cpp::ReplaceRules())
 
void Save (const std::string &filename)
 
std::string GetStateMachineAsString ()
 
void Start ()
 
void Stop ()
 
void PostEvent (SharedEvent e)
 
void ProcessEvent ()
 
void ProcessEvent (scxml4cpp::Event *e)
 
void ProcessEvent (const AnyEvent &e)
 
void SetStatusRepresentation (const bool use_fully_qualified_state)
 
std::string GetStatus () const
 
std::list< scxml4cpp::State * > GetActiveStates ()
 
void AddStatusListener (scxml4cpp::StatusListener *listener)
 
void RemoveStatusListener (scxml4cpp::StatusListener *listener)
 
void AddEventListener (scxml4cpp::EventListener *listener)
 
void RemoveEventListener (scxml4cpp::EventListener *listener)
 
void SetStatusPublisher (std::function< void(const std::string &)> publisher)
 
void PublishStatus ()
 
void RegisterRejectHandler (const std::string &id, std::function< void(const rad::AnyEvent &, const std::string &state)> handler)
 
template<typename T >
void RegisterDefaultRequestRejectHandler ()
 
void SetLogLevel (const std::string &level)
 
 SMAdapter (const SMAdapter &e)=delete
 
SMAdapteroperator= (SMAdapter &e)=delete
 

Detailed Description

This class can be used as skeleton application that integrates the Boost ASIO event loop and the scxml4cpp State Machine interpreter.

It allows to reuse the application start-up/initialization code.

The Application object should be created:

Constructor & Destructor Documentation

◆ Application() [1/2]

rad::Application::Application ( const std::string & name,
rad::DataContext & data )

Default constructor.

Parameters
nameName of the SW module used as main logger and log filename.
dataData used and produced by the application.

◆ ~Application()

rad::Application::~Application ( )
override

Destructor

◆ Application() [2/2]

rad::Application::Application ( const Application & )
delete

Member Function Documentation

◆ Config()

bool rad::Application::Config ( int argc,
char * argv[] )
virtual

Configure the application using: 1) the default hard-coded configuration values 2) environment variables 3) configuration file (if given) 4) command line parameters

Parameters
argcNumber of command line arguments.
argvVector of arguments.
Returns
false If the request for help (-h) was requested, true otherwise.

◆ CreateReplier()

void rad::Application::CreateReplier ( const std::string & uri)

Creates the rad::cii::Replier object used to process the requests/commands sent to the application.

Ideally this method can be reused also to re-configured the application with a different URI. TODO unfortunately URI reconfiguration doesn't seem to work check CII/MAL.

Parameters
uriCII/MAL endpoint to be used when sending commands to the application.

Switch the replier to a different URI.

TODO works only at the very beginning, changing to a different URI seems not to work, investigate MAL?

◆ GetDataContext()

rad::DataContext & rad::Application::GetDataContext ( )
inline
Returns
Return the application's data context.

◆ GetEventLoop()

boost::asio::io_context & rad::Application::GetEventLoop ( )
inline
Returns
a reference to the Boost ASIO event loop.

◆ GetMalDdsInstance()

std::shared_ptr< elt::mal::Mal > rad::Application::GetMalDdsInstance ( )
inline
Returns
a reference to MAL DDS instance.

◆ GetMalInstance()

std::shared_ptr< elt::mal::Mal > rad::Application::GetMalInstance ( )
inline
Returns
a reference to MAL ZPB instance.

◆ GetName()

const std::string & rad::Application::GetName ( ) const
inline
Returns
Return the application name.

◆ Init() [1/2]

bool rad::Application::Init ( int argc,
char * argv[],
rad::ConfigurableActionMgr & action_mgr )
virtual

Initialize and configure the application using: 1) the default hard-coded configuration values 2) environment variables 3) configuration file (if given) 4) command line parameters

It also creates the actions and activities provided by the ActionMgr. Note that the ActionMgr should be created before invoking this method but after the creation of the Application.

Parameters
argcNumber of command line arguments.
argvVector of arguments.
action_mgrReference to the ActionMgr object used to create the actions and activities.
Returns
false If the request for help (-h) was requested, true otherwise.

◆ Init() [2/2]

void rad::Application::Init ( rad::ConfigurableActionMgr & action_mgr)
virtual

This method initializes the application by:

  • Writing the (already loaded) configuration into the OLDB.
  • Creating the actions and activities provided by the ActionMgr.
  • Creating Replier object to process incoming command.
  • Loading State Machine model(s).
  • Registering default reject request handlers.
  • Registering state publisher to OLDB.

Note that the ActionMgr should be created before invoking this method but after the creation of the Application.

Parameters
action_mgrReference to the ActionMgr object used to create the actions and activities.

◆ operator=()

Application & rad::Application::operator= ( const Application & )
delete

Disable copy constructor.

◆ RegisterMalDds() [1/2]

void rad::Application::RegisterMalDds ( )
virtual

Load and register MAL DDS configured with the properties defined in the Config class. It is assumed that the following configuration parameters are available:

  • "cfg/dds_qos_profile" (KEY_CONFIG_DDS_QOS_PROFILE)
  • "cfg/dds_qos_participant" (KEY_CONFIG_DDS_QOS_PARTICIPANT)

This method throws a rad::Exception if the parameters above are not available in the configuration or they are available but empty since the MAL DDS won't work.

Deprecated

◆ RegisterMalDds() [2/2]

void rad::Application::RegisterMalDds ( const elt::mal::Mal::Properties & mal_properties)

Load and register MAL DDS configured with the given properties.

At least the following properties should be provided for a publisher application:

  • "dds.domain" or
  • "dds.qos.profile.library - "dds.qos.profile.name.participant" At least the following properties should be provided for a subscriber application: - "dds.qos.profile.library
  • "dds.qos.profile.name.participant"
Parameters
mal_propertiesMAL properties to configure DDS.

◆ RegisterService()

template<typename IF , typename IF_IMPL >
void rad::Application::RegisterService ( const std::string & name,
std::shared_ptr< IF_IMPL > if_impl )

Register the requests/commands to be processed by the application. Note that if no rad::cii::Replier object has been created, the method returns immediately.

Parameters
namename of the service corresponding to a MAL interface.
if_implImplementation of a MAL interface.

◆ Run()

void rad::Application::Run ( )
virtual

Starts the State Machine interpreter and the Boost ASIO event loop. This method returns only when the Boost ASIO event loop is stopped (e.g. when StopEventLoop() is invoked).

If the event loop is stopped, also the State Machine interpreter is terminated.

◆ StopEventLoop()

void rad::Application::StopEventLoop ( )

Stops the Boost ASIO event loop and force the application to quit.


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