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

Slave part of state pattern. More...

#include <smartState.hh>

Public Member Functions

void updateState (void)
 
void updateStateFromThread (void)
 
 StateSlave (SmartComponent *component, StateChangeHandler *hnd=NULL, const std::string &serviceName="state")
 Constructor. More...
 
virtual ~StateSlave ()
 Destructor. More...
 
Smart::StatusCode setWaitState (const std::string &MainState)
 Blocking call to change the current component MainState. More...
 
Smart::StatusCode defineStates (const std::string &MainState, const std::string &SubState)
 Add the SubState to the MainState. More...
 
Smart::StatusCode setUpInitialState (const std::string &MainState="Neutral")
 Set the first MainState which is automatically entered after the pattern switched into Alive state. More...
 
std::string getCurrentMainState () const
 Returns the currently active MainState. More...
 
Smart::StatusCode activate ()
 Activation is necessary since otherwise no states can be set or acquired. More...
 
Smart::StatusCode acquire (const std::string &SubState)
 Wait until specified substate is available and acquire it. More...
 
Smart::StatusCode tryAcquire (const std::string &SubState)
 Acquire specified substate if available, otherwise return immediately. More...
 
Smart::StatusCode release (const std::string &SubState)
 Release specified substate. More...
 

Friends

class SmartComponent
 
class StateSlaveHandler
 

Detailed Description

Slave part of state pattern.

Demonstrated in third example

Constructor & Destructor Documentation

◆ StateSlave()

SmartACE::StateSlave::StateSlave ( SmartComponent component,
StateChangeHandler hnd = NULL,
const std::string &  serviceName = "state" 
)

Constructor.

Parameters
componentmanagement class of the component
hndoptional callback interface which is called on each state-change
serviceNamethe name for the internal communication-port (as will be visible on component hull)

◆ ~StateSlave()

virtual SmartACE::StateSlave::~StateSlave ( )
virtual

Destructor.

Member Function Documentation

◆ acquire()

Smart::StatusCode SmartACE::StateSlave::acquire ( const std::string &  SubState)

Wait until specified substate is available and acquire it.

(hint: acquire(nonneutral) blocks until some main state is set.)

Parameters
SubStateis the name of the substate to be acquired.
Returns
status code
  • SMART_OK : everything is ok
  • SMART_UNKNOWNSTATE : returns immediately if the requested state is unknown
  • SMART_NOTACTIVATED : state object of component not yet activated
  • SMART_ERROR_COMMUNICATION : communication problems
  • SMART_ERROR : something went wrong

◆ activate()

Smart::StatusCode SmartACE::StateSlave::activate ( )

Activation is necessary since otherwise no states can be set or acquired.

No more state definitions are possible after activation.

Returns
status code
  • SMART_OK : configuration has been activated and no more state definitions possible

◆ defineStates()

Smart::StatusCode SmartACE::StateSlave::defineStates ( const std::string &  MainState,
const std::string &  SubState 
)

Add the SubState to the MainState.

As long as the state object within a component is not activated, one can configure the name of the main states and substates which are afterwards visible externally.

If one or both names are used the first time the corresponding states are created automatically.

Parameters
MainStateis the MainState (parent)
SubStateis the SubState to be assigned to the MainState
Returns
status code
  • SMART_OK : everything is ok
  • SMART_ACTIVATED : configuration can not be changed anymore once state object has been activated
  • SMART_NOTALLOWED : tried to assign substates to the neutral state or something similar which is not allowed
  • SMART_ERROR_COMMUNICATION : communication problems
  • SMART_ERROR : something went wrong

◆ getCurrentMainState()

std::string SmartACE::StateSlave::getCurrentMainState ( ) const

Returns the currently active MainState.

If the StateSlave is in progress of a state-change, the MainState to be entered is returned instead of the currently active MainState. This is more convenient for Monitoring state changes!

Returns
MainState string

◆ release()

Smart::StatusCode SmartACE::StateSlave::release ( const std::string &  SubState)

Release specified substate.

Parameters
SubStateis the name of the substate to be released.
Returns
status code
  • SMART_OK : everything is ok
  • SMART_UNKNOWNSTATE : returns immediately if the requested state is unknown
  • SMART_NOTACTIVATED : state object of component not yet activated
  • SMART_ERROR_COMMUNICATION : communication problems
  • SMART_ERROR : something went wrong

◆ setUpInitialState()

Smart::StatusCode SmartACE::StateSlave::setUpInitialState ( const std::string &  MainState = "Neutral")

Set the first MainState which is automatically entered after the pattern switched into Alive state.

Per default the MainState Neutral is entered after StateSlave entered Alive state. If this behavior is not wanted this method can be used to change the initial MainState (which must be one of the previously defined MainStates).

Parameters
MainStateis the initial MainState after reaching Alive state
Returns
status code
  • SMART_OK : everything OK
  • SMART_NOTALLOWED : tried to assign substates to the neutral state or something similar which is not allowed
  • SMART_ERROR : something went wrong

◆ setWaitState()

Smart::StatusCode SmartACE::StateSlave::setWaitState ( const std::string &  MainState)

Blocking call to change the current component MainState.

Parameters
MainState
  • StateSlave is only allowed to change the components lifecycle MainState (Alive, Shutdown and FatalError). Other MainStates are only allowed to be changed from the remote StateMaster.
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 : something went wrong

◆ tryAcquire()

Smart::StatusCode SmartACE::StateSlave::tryAcquire ( const std::string &  SubState)

Acquire specified substate if available, otherwise return immediately.

(hint: tryAcquire(nonneutral) can be used e.g. in a query handler to decide whether to process the query or to immediately return an appropriate status code indicating the components inactivity.)

Parameters
SubStateis the name of the substate to be acquired.
Returns
status code
  • SMART_OK : everything is ok
  • SMART_UNKNOWNSTATE : returns immediately if the requested state is unknown
  • SMART_NOTACTIVATED : state object of component not yet activated
  • SMART_ERROR_COMMUNICATION : communication problems
  • SMART_ERROR : something went wrong

◆ updateState()

void SmartACE::StateSlave::updateState ( void  )

◆ updateStateFromThread()

void SmartACE::StateSlave::updateStateFromThread ( void  )

Friends And Related Function Documentation

◆ SmartComponent

friend class SmartComponent
friend

◆ StateSlaveHandler

friend class StateSlaveHandler
friend

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