AceSmartSoft API Documentation
Public Member Functions | List of all members
SmartACE::StateMaster Class Reference

Master part of state pattern. More...

#include <smartState.hh>

Public Member Functions

 StateMaster (SmartComponent *component)
 Constructor (not wired with service provider and not exposed as port). More...
 
virtual ~StateMaster ()
 Destructor. More...
 
Smart::StatusCode blocking (const bool b)
 Allow or abort and reject blocking calls. More...
 
Smart::StatusCode setWaitState (const std::string &state, const std::string &server, const std::string &service="state")
 Blocking call to change the main state. More...
 
Smart::StatusCode getCurrentMainState (std::string &MainState, const std::string &server, const std::string &service="state")
 Blocking call which returns the currently active main state. More...
 
Smart::StatusCode getAllMainStates (std::list< std::string > &MainStates, const std::string &server, const std::string &service="state")
 Blocking call which returns a list of valid main states. More...
 
Smart::StatusCode getSubStates (const std::string &MainState, std::list< std::string > &SubStates, const std::string &server, const std::string &service="state")
 Blocking call which returns a list of substates assigned to the specified main state. More...
 

Detailed Description

Master part of state pattern.

The configuration class provides priorized mutexes for protecting configurations. Normally, a complex robotic system requires a lot of different components which can not all run at the same time. Depending on the current task to be executed and depending on the available ressources, one has to be able to activate and deactivate components and activities within components. One the one hand deactivation should be done in such a way that the component can perform cleanup tasks. On the other hand a component must still be interruptable even if it is pending in a blocking call because the corresponding server has already been deactivated.

The configuration class therefore provides mechanisms for graceful activation and deactivation of sets of activities within components.

As is explained in the specification of the state pattern, one can activate one mainstate at a time. A mainstate can however comprise several substates which are all active at the same time. A master can only set mainstates whereas the slave can only acquire substates. This allows the simple management of sets of concurrent activities.

For a complete description see the printed documentation and further details in third example.

Constructor & Destructor Documentation

◆ StateMaster()

SmartACE::StateMaster::StateMaster ( SmartComponent component)

Constructor (not wired with service provider and not exposed as port).

add()/remove() and connect()/disconnect() can always be used to change the status of the instance. Instance is not connected to a service provider and is not exposed as port wireable from outside the component.

(Currently exception not thrown)

Parameters
componentmanagement class of the component

◆ ~StateMaster()

virtual SmartACE::StateMaster::~StateMaster ( )
virtual

Destructor.

Member Function Documentation

◆ blocking()

Smart::StatusCode SmartACE::StateMaster::blocking ( const bool  b)

Allow or abort and reject blocking calls.

If blocking is set to false all blocking calls return with SMART_CANCELLED. This can be used to abort blocking calls.

Parameters
b(blocking) true/false
Returns
status code
  • SMART_OK : new mode set
  • SMART_ERROR : something went wrong

◆ getAllMainStates()

Smart::StatusCode SmartACE::StateMaster::getAllMainStates ( std::list< std::string > &  MainStates,
const std::string &  server,
const std::string &  service = "state" 
)

Blocking call which returns a list of valid main states.

Parameters
MainStatescontain all valid main states of the server (slave)
serverallows to define the slave from which all the mainstates are returned
serviceis an optional parameter in case the slave has a different service name than "state" (mostly for backwards compatibility)
Returns
status code
  • SMART_OK : everything is ok
  • SMART_NOTACTIVATED : state object of server component not yet activated
  • SMART_ERROR_COMMUNICATION : communication problems
  • SMART_ERROR : something went wrong
  • (hint for experts: SMART_CANCELLED can not be returned since a component can always return its list of mainstates even if it is disabled. Therefore there is no need to abort this method call when a request to reach the neutral state is pending)

◆ getCurrentMainState()

Smart::StatusCode SmartACE::StateMaster::getCurrentMainState ( std::string &  MainState,
const std::string &  server,
const std::string &  service = "state" 
)

Blocking call which returns the currently active main state.

Is only for convenience and is not necessary since the master always knows what has been configured.

Parameters
MainStateis set to the current main state as returned by the server (slave)
serverallows to define the slave from which the currently active mainstate is returned
serviceis an optional parameter in case the slave has a different service name than "state" (mostly for backwards compatibility)
Returns
status code
  • SMART_OK : everything is ok
  • SMART_NOTACTIVATED : state object of server component not yet activated
  • SMART_ERROR_COMMUNICATION : communication problems
  • SMART_ERROR : something went wrong
  • (hint for experts: SMART_CANCELLED can not be returned since a component can always return its current state even if it is disabled. Therefore there is no need to abort this method call when a request to reach the neutral state is pending)

◆ getSubStates()

Smart::StatusCode SmartACE::StateMaster::getSubStates ( const std::string &  MainState,
std::list< std::string > &  SubStates,
const std::string &  server,
const std::string &  service = "state" 
)

Blocking call which returns a list of substates assigned to the specified main state.

Parameters
MainStateis the mainstate to which we want to get the list of substates
SubStatesis set to the returned list of substates
serverallows to define the slave from which all the substates (for the given mainstate) are returned
serviceis an optional parameter in case the slave has a different service name than "state" (mostly for backwards compatibility)
Returns
status code
  • SMART_OK : everything is ok
  • SMART_NOTACTIVATED : state object of server component not yet activated
  • SMART_UNKNOWNSTATE : the main state asked for is unknown
  • SMART_ERROR_COMMUNICATION : communication problems
  • SMART_ERROR : something went wrong
  • (hint for experts: SMART_CANCELLED can not be returned since a component can always return its list of mainstates even if it is disabled. Therefore there is no need to abort this method call when a request to reach the neutral state is pending)

◆ setWaitState()

Smart::StatusCode SmartACE::StateMaster::setWaitState ( const std::string &  state,
const std::string &  server,
const std::string &  service = "state" 
)

Blocking call to change the main state.

Parameters
state
  • If "Deactivated" is specified as main state, every blocking query etc. is aborted with SMART_CANCELLED to reach the "neutral" state as fast as possible.
  • If "Neutral" is specified the neutral state will be reached without aborting pending communication calls.
serverallows to define the slave for the state-change
serviceis an optional parameter in case the slave has a different service name than "state" (mostly for backwards compatibility)
Returns
status code
  • SMART_OK : everything is ok
  • SMART_UNKNOWNSTATE : requested mainstate is unknown and therefore no state change has been performed
  • SMART_NOTACTIVATED : state object of server component not yet activated
  • SMART_CANCELLED : component has been requested to reach neutral state, therefore pending setWaitState has been aborted
  • SMART_ERROR_COMMUNICATION : communication problems
  • SMART_ERROR : something went wrong

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