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

#include <smAdapter.hpp>

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

Public Member Functions

 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 is the adapter to the SCXML engine.

Todo
replace raw pointers with smart pointers.

Constructor & Destructor Documentation

◆ SMAdapter() [1/2]

rad::SMAdapter::SMAdapter ( boost::asio::io_context & ios,
scxml4cpp::Context * context,
scxml4cpp::EventQueue & external_events )

Constructor.

Parameters
[in]iosEvent loop.
[in]contextSCXML context.
[in]external_eventsSCXML external event queue.

◆ ~SMAdapter()

rad::SMAdapter::~SMAdapter ( )
virtual

Destructor that deletes the SCXML interpreter and cleanup the SCXML model.

◆ SMAdapter() [2/2]

rad::SMAdapter::SMAdapter ( const SMAdapter & e)
delete

Member Function Documentation

◆ AddEventListener()

void rad::SMAdapter::AddEventListener ( scxml4cpp::EventListener * listener)

Register a listener for the event processed notification.

Parameters
[in]listenerListener to be registered. Note that the listener should be noexcept.

◆ AddStatusListener()

void rad::SMAdapter::AddStatusListener ( scxml4cpp::StatusListener * listener)

Register a listener for a change of SM state notification. The listener is notified every time a new state is entered. If you need to retrieve the state after an event has been processed you should use the Event listener together with the GetStatus method ((

See also
AddEventListener, GetStatus).
Parameters
[in]listenerListener to be registered. Note that the listener should be noexcept.

◆ Append()

void rad::SMAdapter::Append ( const std::string & filename,
std::list< scxml4cpp::Action * > * action_list,
std::list< scxml4cpp::Activity * > * activity_list,
const scxml4cpp::ReplaceRules & replace_rules = scxml4cpp::ReplaceRules() )

Append to a loaded SCXML model an extension via the scxml4cpp::Merger class. If the appended model is valid, it creates the interpreter to execute the model. If the appended model is invalid it keeps the previous model and executor. In case of invalid model, a rad::Exception exception is thrown.

Parameters
[in]filenameSCXML model to load.
[in]action_listList of actions mapped to SCXML model. Note that the actions should be noexcept.
[in]activity_listList of activities mapped to SCXML model.
[in]replace_rulesOptional parameter to replace SCXML identifiers while parsing.

◆ AppendFromString()

void rad::SMAdapter::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() )

Append to a loaded SCXML model an extension via the scxml4cpp::Merger class. If the appended model is valid, it creates the interpreter to execute the model. If the appended model is invalid it keeps the previous model and executor. In case of invalid model, a rad::Exception exception is thrown.

Parameters
[in]nameName given to the SCXML model (used in debug/error messages).
[in]modelSCXML model to parse.
[in]action_listList of actions mapped to SCXML model. Note that the actions should be noexcept.
[in]activity_listList of activities mapped to SCXML model.
[in]replace_rulesOptional parameter to replace SCXML identifiers while parsing.

◆ GetActiveStates()

std::list< scxml4cpp::State * > rad::SMAdapter::GetActiveStates ( )
Returns
the current active SM state configuration returned by the SCXML engine.

◆ GetStateMachineAsString()

std::string rad::SMAdapter::GetStateMachineAsString ( )
Returns
a textual representation of the SCXML model.

◆ GetStatus()

std::string rad::SMAdapter::GetStatus ( ) const
Returns
the current SM state configuration as a formatted string containing the information provided by the "Status" notification.
See also
AddStatusListener.

◆ Load()

void rad::SMAdapter::Load ( const std::string & filename,
std::list< scxml4cpp::Action * > * action_list,
std::list< scxml4cpp::Activity * > * activity_list,
const scxml4cpp::ReplaceRules & replace_rules = scxml4cpp::ReplaceRules() )

Load an SCXML model from file. If the loaded model is valid, it creates the interpreter to execute the model. If the model is invalid it keeps the previous model and executor. In case of invalid model, a rad::Exception exception is thrown.

Parameters
[in]filenameSCXML model to load.
[in]action_listList of actions mapped to SCXML model. Note that the actions should be noexcept.
[in]activity_listList of activities mapped to SCXML model.
[in]replace_rulesOptional parameter to replace SCXML identifiers while parsing.

◆ LoadFromString()

void rad::SMAdapter::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() )

Load an SCXML model from string. If the loaded model is valid, it creates the interpreter to execute the model. If the model is invalid it keeps the previous model and executor. In case of invalid model, a rad::Exception exception is thrown.

Parameters
[in]nameName given to the SCXML model (used in debug/error messages).
[in]modelSCXML model to parse.
[in]action_listList of actions mapped to SCXML model. Note that the actions should be noexcept.
[in]activity_listList of activities mapped to SCXML model.
[in]replace_rulesOptional parameter to replace SCXML identifiers while parsing.

◆ operator=()

SMAdapter & rad::SMAdapter::operator= ( SMAdapter & e)
delete

◆ PostEvent()

void rad::SMAdapter::PostEvent ( SharedEvent e)

Post asynchronously an event to be processed by the SM.

It uses the boost ASIO post function which allows to add a given lambda to boost ASIO execution queue. The lambda, when executed, calls SMAdapter::ProcessEvent(const AnyEvent& e) method.

This function can be used also by threads to trigger the processing of the events.

Note: this method can be invoked also by passing UniqueEvent as argument since C++ will upgrade it SharedEvent automatically.

Parameters
[in]eShared RAD event to post.

◆ ProcessEvent() [1/3]

void rad::SMAdapter::ProcessEvent ( )

Trigger the processing of the events inserted in the SM external event queue.

◆ ProcessEvent() [2/3]

void rad::SMAdapter::ProcessEvent ( const AnyEvent & e)

Method invoked to trigger the processing of an event by the SM.

Parameters
[in]eRAD event to be processed by the SM

◆ ProcessEvent() [3/3]

void rad::SMAdapter::ProcessEvent ( scxml4cpp::Event * e)

Trigger the processing of the given event by the SM. The processing terminates when the SM external event queue is empty.

Parameters
[in]eSCXML event to be processed.

◆ PublishStatus()

void rad::SMAdapter::PublishStatus ( )

This method invokes the configured SM state publisher (

See also
SetStatusPublisher).

◆ RegisterDefaultRequestRejectHandler()

template<typename T >
void rad::SMAdapter::RegisterDefaultRequestRejectHandler ( )
inline

Method to register the reject handler implemented via the free function rad::DefaultRequestRejectHandler() (see above) to be used to reject event associated to requests.

TODO find out why the logging doesn't work in templated inline methods!

◆ RegisterRejectHandler()

void rad::SMAdapter::RegisterRejectHandler ( const std::string & id,
std::function< void(const rad::AnyEvent &, const std::string &state)> handler )

Method to register a handler that can be used to reject an event.

Parameters
idEvent identifier to be rejected.
handlerFunction implementing the rejection handler. Note that the handler should be noexcept.

◆ RemoveEventListener()

void rad::SMAdapter::RemoveEventListener ( scxml4cpp::EventListener * listener)

Deregister a listener for the event processed notification.

Parameters
[in]listenerListener to be deregistered.

◆ RemoveStatusListener()

void rad::SMAdapter::RemoveStatusListener ( scxml4cpp::StatusListener * listener)

Deregister a listener for a change of SM state notification.

Parameters
[in]listenerListener to be deregistered.

◆ Save()

void rad::SMAdapter::Save ( const std::string & filename)

Save the state machine model to file.

Parameters
[in]filenameName of the file used to save the model.

◆ SetLogLevel()

void rad::SMAdapter::SetLogLevel ( const std::string & level)

Sets the log level of the SCXML engine.

Parameters
[in]levelThe desired log level: TRACE, DEBUG, INFO, WARN, ERROR.

◆ SetStatusPublisher()

void rad::SMAdapter::SetStatusPublisher ( std::function< void(const std::string &)> publisher)

Configure a function to be used as publisher for the SM information.

Parameters
publisherCallback function used to publish the current SM state. Note that the callback should be noexcept.

◆ SetStatusRepresentation()

void rad::SMAdapter::SetStatusRepresentation ( const bool use_fully_qualified_state)

Set a flag indicating whether states ID are fully qualified (i.e. include parent states) or not.

Parameters
use_fully_qualified_stateIf true, the string returned by GetStatus will include, for each active state, the parent states. If false, it will include only the name of the leaf state.

◆ Start()

void rad::SMAdapter::Start ( )

Starts the SM model interpretation.

◆ Stop()

void rad::SMAdapter::Stop ( )

Stops the SM model interpretation.


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