Public Member Functions | Public Attributes | Protected Member Functions | Private Member Functions | Private Attributes | List of all members
packml_sm::AbstractStateMachine Class Referenceabstract

The StateMachineInterface class defines a implementation independent interface to a PackML state machine. More...

#include <abstract_state_machine.h>

Inheritance diagram for packml_sm::AbstractStateMachine:
Inheritance graph
[legend]

Public Member Functions

virtual bool abort ()
 Call to send the abort command. More...
 
 AbstractStateMachine ()
 Constructor for AbstractStateMachine. More...
 
virtual bool activate ()=0
 Override to handle activate command. More...
 
virtual bool clear ()
 Call to send the clear command. More...
 
virtual bool deactivate ()=0
 Override to handle deactivate command. More...
 
double getAbortedTime ()
 Accessor for the duration spent in aborted. More...
 
double getAbortingTime ()
 Accessor for the duration spent in aborting. More...
 
double getClearingTime ()
 Accessor for the duration spent in clearing. More...
 
double getCompleteTime ()
 Accessor for the duration spent in complete. More...
 
StatesEnum getCurrentState () const
 Accessor for the current state. More...
 
void getCurrentStatSnapshot (PackmlStatsSnapshot &snapshot_out)
 Fills the reference variable with the current stats snapshot. More...
 
double getExecuteTime ()
 Accessor for the duration spent in execute. More...
 
double getHeldTime ()
 Accessor for the duration spent in held. More...
 
double getHoldingTime ()
 Accessor for the duration spent in holding. More...
 
double getIdleTime ()
 Accessor for the duration spent in idle time. More...
 
double getResettingTime ()
 Accessor for the duration spent in resetting. More...
 
double getStartingTime ()
 Accessor for the duration spent in starting. More...
 
double getStoppedTime ()
 Accessor for the duration spent in stopped. More...
 
double getStoppingTime ()
 Accessor for the duration spent in stopping. More...
 
double getSuspendedTime ()
 Accessor for the duration spent in suspended. More...
 
double getSuspendingTime ()
 Accessor for the duration spent in suspending. More...
 
double getUnholdingTime ()
 Accessor for the duration spent in unholding. More...
 
double getUnsuspendingTime ()
 Accessor for the duration spent in unsuspending. More...
 
virtual bool hold ()
 Call to send the hold command. More...
 
void incrementErrorStatItem (int16_t id, int32_t count, double duration)
 Call to increment or add a specific Itemized error stat. More...
 
void incrementFailureCount ()
 Call to increment the failed operation count. More...
 
void incrementQualityStatItem (int16_t id, int32_t count, double duration)
 Call to increment or add a specific Itemized quality stat. More...
 
void incrementSuccessCount ()
 Call to increment the successful operation count. More...
 
virtual bool isActive ()=0
 Override to provide an accessor to whether the state machine is currently active. More...
 
virtual bool reset ()
 Call to send the reset command. More...
 
void resetStats ()
 Reset all of the tracked states. More...
 
virtual bool setAborting (std::function< int()> state_method)=0
 Override to handle setting the aborting state method. More...
 
virtual bool setClearing (std::function< int()> state_method)=0
 Override to handle setting the clearing state method. More...
 
virtual bool setCompleting (std::function< int()> state_method)=0
 Override to handle setting the completing state method. More...
 
virtual bool setExecute (std::function< int()> state_method)=0
 Override to handle setting the execute state method. More...
 
virtual bool setHolding (std::function< int()> state_method)=0
 Override to handle setting the holding state method. More...
 
void setIdealCycleTime (float ideal_cycle_time)
 Sets the ideal cycle time in operations per second. More...
 
virtual bool setResetting (std::function< int()> state_method)=0
 Override to handle setting the resetting state method. More...
 
virtual bool setStarting (std::function< int()> state_method)=0
 Override to handle setting the starting state method. More...
 
virtual bool setStopping (std::function< int()> state_method)=0
 Override to handle setting the stopping state method. More...
 
virtual bool setSuspending (std::function< int()> state_method)=0
 Override to handle setting the suspending state method. More...
 
virtual bool setUnholding (std::function< int()> state_method)=0
 Override to handle setting unholding state method. More...
 
virtual bool setUnsuspending (std::function< int()> state_method)=0
 Override to handle setting the un-suspending state method. More...
 
virtual bool start ()
 Call to send the start command. More...
 
virtual bool stop ()
 Call to send the stop command. More...
 
virtual bool suspend ()
 Call to send the suspend command. More...
 
virtual bool unhold ()
 Call to send the unhold command. More...
 
virtual bool unsuspend ()
 Call to send the unsuspend command. More...
 
virtual ~AbstractStateMachine ()
 Destructor for AbstractStateMachine. More...
 

Public Attributes

EventHandler< AbstractStateMachine, StateChangedEventArgsstateChangedEvent
 

Protected Member Functions

virtual void _abort ()=0
 Override to call implementations version of the abort command. More...
 
virtual void _clear ()=0
 Override to call implementations version of clear command. More...
 
virtual void _hold ()=0
 Override to call implementations version of the hold command. More...
 
virtual void _reset ()=0
 Override to call implementations version of the reset command. More...
 
virtual void _start ()=0
 Override to call implementations version of start command. More...
 
virtual void _stop ()=0
 Override to call implementations version of the stop command. More...
 
virtual void _suspend ()=0
 Override to call implementations version of the suspend command. More...
 
virtual void _unhold ()=0
 Override to call implementations version of the unhold command. More...
 
virtual void _unsuspend ()=0
 Override to call implementations version of the unsuspend command. More...
 
void invokeStateChangedEvent (const std::string &name, StatesEnum value)
 Call to invoke a state changed event. More...
 

Private Member Functions

double calculateTotalTime ()
 Accessor for the total duration of the state machine. More...
 
double getStateDuration (StatesEnum state)
 Accessor for the given state duration. More...
 
void incrementMapStatItem (std::map< int16_t, PackmlStatsItemized > &itemized_map, int16_t id, int32_t count, double duration)
 adds or updates the specific itemized map More...
 
void updateClock (StatesEnum new_state)
 Updates all of the durations for the states based on the new state. More...
 

Private Attributes

StatesEnum current_state_ = StatesEnum::UNDEFINED
 
std::map< StatesEnum, double > duration_map_
 
int failure_count_ = 0
 
float ideal_cycle_time_ = 0.0
 
std::map< int16_t, PackmlStatsItemizeditemized_error_map_
 
std::map< int16_t, PackmlStatsItemizeditemized_quality_map_
 
std::chrono::steady_clock::time_point start_time_
 
std::recursive_mutex stat_mutex_
 
int success_count_ = 0
 

Detailed Description

The StateMachineInterface class defines a implementation independent interface to a PackML state machine.

Definition at line 35 of file abstract_state_machine.h.

Constructor & Destructor Documentation

packml_sm::AbstractStateMachine::AbstractStateMachine ( )

Constructor for AbstractStateMachine.

Triggered during a state changed event.

Definition at line 27 of file abstract_state_machine.cpp.

virtual packml_sm::AbstractStateMachine::~AbstractStateMachine ( )
inlinevirtual

Destructor for AbstractStateMachine.

Definition at line 51 of file abstract_state_machine.h.

Member Function Documentation

virtual void packml_sm::AbstractStateMachine::_abort ( )
protectedpure virtual
virtual void packml_sm::AbstractStateMachine::_clear ( )
protectedpure virtual
virtual void packml_sm::AbstractStateMachine::_hold ( )
protectedpure virtual
virtual void packml_sm::AbstractStateMachine::_reset ( )
protectedpure virtual
virtual void packml_sm::AbstractStateMachine::_start ( )
protectedpure virtual
virtual void packml_sm::AbstractStateMachine::_stop ( )
protectedpure virtual
virtual void packml_sm::AbstractStateMachine::_suspend ( )
protectedpure virtual
virtual void packml_sm::AbstractStateMachine::_unhold ( )
protectedpure virtual
virtual void packml_sm::AbstractStateMachine::_unsuspend ( )
protectedpure virtual
bool packml_sm::AbstractStateMachine::abort ( )
virtual

Call to send the abort command.

Returns
bool Returns true on success.

Definition at line 147 of file abstract_state_machine.cpp.

virtual bool packml_sm::AbstractStateMachine::activate ( )
pure virtual
double packml_sm::AbstractStateMachine::calculateTotalTime ( )
private

Accessor for the total duration of the state machine.

Returns
double Returns the total time spent in the state machine.

Definition at line 312 of file abstract_state_machine.cpp.

bool packml_sm::AbstractStateMachine::clear ( )
virtual

Call to send the clear command.

Returns
bool Returns true on success.

Definition at line 44 of file abstract_state_machine.cpp.

virtual bool packml_sm::AbstractStateMachine::deactivate ( )
pure virtual
double packml_sm::AbstractStateMachine::getAbortedTime ( )

Accessor for the duration spent in aborted.

Returns
double Returns the time spent in the aborted state.

Definition at line 302 of file abstract_state_machine.cpp.

double packml_sm::AbstractStateMachine::getAbortingTime ( )

Accessor for the duration spent in aborting.

Returns
double Returns the time spent in the aborting state.

Definition at line 307 of file abstract_state_machine.cpp.

double packml_sm::AbstractStateMachine::getClearingTime ( )

Accessor for the duration spent in clearing.

Returns
double Returns the time spent in the clearing state.

Definition at line 292 of file abstract_state_machine.cpp.

double packml_sm::AbstractStateMachine::getCompleteTime ( )

Accessor for the duration spent in complete.

Returns
double Returns the time spent in the complete state.

Definition at line 282 of file abstract_state_machine.cpp.

StatesEnum packml_sm::AbstractStateMachine::getCurrentState ( ) const
inline

Accessor for the current state.

Returns
StatesEnum The current state.

Definition at line 169 of file abstract_state_machine.h.

void packml_sm::AbstractStateMachine::getCurrentStatSnapshot ( PackmlStatsSnapshot snapshot_out)

Fills the reference variable with the current stats snapshot.

Parameters
snapshot_outReference to the variable to fill the snapshot data with.

Definition at line 174 of file abstract_state_machine.cpp.

double packml_sm::AbstractStateMachine::getExecuteTime ( )

Accessor for the duration spent in execute.

Returns
double Returns the time spent in the execute state.

Definition at line 247 of file abstract_state_machine.cpp.

double packml_sm::AbstractStateMachine::getHeldTime ( )

Accessor for the duration spent in held.

Returns
double Returns the time spent in the held state.

Definition at line 252 of file abstract_state_machine.cpp.

double packml_sm::AbstractStateMachine::getHoldingTime ( )

Accessor for the duration spent in holding.

Returns
double Returns the time spent in the holding state.

Definition at line 257 of file abstract_state_machine.cpp.

double packml_sm::AbstractStateMachine::getIdleTime ( )

Accessor for the duration spent in idle time.

Returns
double Returns the time spent in the idle state.

Definition at line 232 of file abstract_state_machine.cpp.

double packml_sm::AbstractStateMachine::getResettingTime ( )

Accessor for the duration spent in resetting.

Returns
double Returns the time spent in the resetting state.

Definition at line 242 of file abstract_state_machine.cpp.

double packml_sm::AbstractStateMachine::getStartingTime ( )

Accessor for the duration spent in starting.

Returns
double Returns the time spent in the starting state.

Definition at line 237 of file abstract_state_machine.cpp.

double packml_sm::AbstractStateMachine::getStateDuration ( StatesEnum  state)
private

Accessor for the given state duration.

Parameters
stateThe state of interest.
Returns
double Returns the total time spent in the given state.

Definition at line 417 of file abstract_state_machine.cpp.

double packml_sm::AbstractStateMachine::getStoppedTime ( )

Accessor for the duration spent in stopped.

Returns
double Returns the time spent in the stopped state.

Definition at line 287 of file abstract_state_machine.cpp.

double packml_sm::AbstractStateMachine::getStoppingTime ( )

Accessor for the duration spent in stopping.

Returns
double Returns the time spent in the stopping state.

Definition at line 297 of file abstract_state_machine.cpp.

double packml_sm::AbstractStateMachine::getSuspendedTime ( )

Accessor for the duration spent in suspended.

Returns
double Returns the time spent in the suspended state.

Definition at line 267 of file abstract_state_machine.cpp.

double packml_sm::AbstractStateMachine::getSuspendingTime ( )

Accessor for the duration spent in suspending.

Returns
double Returns the time spent in the suspending state.

Definition at line 272 of file abstract_state_machine.cpp.

double packml_sm::AbstractStateMachine::getUnholdingTime ( )

Accessor for the duration spent in unholding.

Returns
double Returns the time spent in the unholding state.

Definition at line 262 of file abstract_state_machine.cpp.

double packml_sm::AbstractStateMachine::getUnsuspendingTime ( )

Accessor for the duration spent in unsuspending.

Returns
double Returns the time spent in the unsuspending state.

Definition at line 277 of file abstract_state_machine.cpp.

bool packml_sm::AbstractStateMachine::hold ( )
virtual

Call to send the hold command.

Returns
bool Returns true on success.

Definition at line 71 of file abstract_state_machine.cpp.

void packml_sm::AbstractStateMachine::incrementErrorStatItem ( int16_t  id,
int32_t  count,
double  duration 
)

Call to increment or add a specific Itemized error stat.

Definition at line 365 of file abstract_state_machine.cpp.

void packml_sm::AbstractStateMachine::incrementFailureCount ( )

Call to increment the failed operation count.

Definition at line 383 of file abstract_state_machine.cpp.

void packml_sm::AbstractStateMachine::incrementMapStatItem ( std::map< int16_t, PackmlStatsItemized > &  itemized_map,
int16_t  id,
int32_t  count,
double  duration 
)
private

adds or updates the specific itemized map

start time for the latest state entry

Parameters
itemized_mapthe map to add or update.
idthe id to add or update.
countthe number of occurences to add.
durationthe duration to add.

Definition at line 346 of file abstract_state_machine.cpp.

void packml_sm::AbstractStateMachine::incrementQualityStatItem ( int16_t  id,
int32_t  count,
double  duration 
)

Call to increment or add a specific Itemized quality stat.

Definition at line 371 of file abstract_state_machine.cpp.

void packml_sm::AbstractStateMachine::incrementSuccessCount ( )

Call to increment the successful operation count.

Definition at line 377 of file abstract_state_machine.cpp.

void packml_sm::AbstractStateMachine::invokeStateChangedEvent ( const std::string &  name,
StatesEnum  value 
)
protected

Call to invoke a state changed event.

Parameters
nameThe name of the new state.
valueThe name of the new value.

Definition at line 395 of file abstract_state_machine.cpp.

virtual bool packml_sm::AbstractStateMachine::isActive ( )
pure virtual

Override to provide an accessor to whether the state machine is currently active.

Returns
bool Returns true if active.

Implemented in packml_sm::PackmlStateMachine< T >, packml_sm::PackmlStateMachine< PackmlTransitionsContinuous >, and packml_sm::PackmlStateMachine< PackmlTransitionsSingleCycle >.

bool packml_sm::AbstractStateMachine::reset ( )
virtual

Call to send the reset command.

Returns
bool Returns true on success.

Definition at line 57 of file abstract_state_machine.cpp.

void packml_sm::AbstractStateMachine::resetStats ( )

Reset all of the tracked states.

Definition at line 325 of file abstract_state_machine.cpp.

virtual bool packml_sm::AbstractStateMachine::setAborting ( std::function< int()>  state_method)
pure virtual

Override to handle setting the aborting state method.

Parameters
state_methodThe state method to execute when entering the aborting state.
Returns
bool Returns true on success.

Implemented in packml_sm::PackmlStateMachine< T >, packml_sm::PackmlStateMachine< PackmlTransitionsContinuous >, and packml_sm::PackmlStateMachine< PackmlTransitionsSingleCycle >.

virtual bool packml_sm::AbstractStateMachine::setClearing ( std::function< int()>  state_method)
pure virtual

Override to handle setting the clearing state method.

Parameters
state_methodThe state method to execute when entering the clearing state.
Returns
bool Returns true on success.

Implemented in packml_sm::PackmlStateMachine< T >, packml_sm::PackmlStateMachine< PackmlTransitionsContinuous >, and packml_sm::PackmlStateMachine< PackmlTransitionsSingleCycle >.

virtual bool packml_sm::AbstractStateMachine::setCompleting ( std::function< int()>  state_method)
pure virtual

Override to handle setting the completing state method.

Parameters
state_methodThe state method to execute when entering the completing state.
Returns
bool Returns true on success.

Implemented in packml_sm::PackmlStateMachine< T >, packml_sm::PackmlStateMachine< PackmlTransitionsContinuous >, and packml_sm::PackmlStateMachine< PackmlTransitionsSingleCycle >.

virtual bool packml_sm::AbstractStateMachine::setExecute ( std::function< int()>  state_method)
pure virtual

Override to handle setting the execute state method.

Parameters
state_methodThe state method to execute when entering the exec state.
Returns
bool Returns true on success.

Implemented in packml_sm::PackmlStateMachine< T >, packml_sm::PackmlStateMachine< PackmlTransitionsContinuous >, and packml_sm::PackmlStateMachine< PackmlTransitionsSingleCycle >.

virtual bool packml_sm::AbstractStateMachine::setHolding ( std::function< int()>  state_method)
pure virtual

Override to handle setting the holding state method.

Parameters
state_methodThe state method to execute when entering the holding state.
Returns
bool Returns true on success.

Implemented in packml_sm::PackmlStateMachine< T >, packml_sm::PackmlStateMachine< PackmlTransitionsContinuous >, and packml_sm::PackmlStateMachine< PackmlTransitionsSingleCycle >.

void packml_sm::AbstractStateMachine::setIdealCycleTime ( float  ideal_cycle_time)

Sets the ideal cycle time in operations per second.

Parameters
ideal_cycle_timeThe ideal cycle time in operations per second.

Definition at line 389 of file abstract_state_machine.cpp.

virtual bool packml_sm::AbstractStateMachine::setResetting ( std::function< int()>  state_method)
pure virtual

Override to handle setting the resetting state method.

Parameters
state_methodThe state method to execute when entering the resetting state.
Returns
bool Returns true on success.

Implemented in packml_sm::PackmlStateMachine< T >, packml_sm::PackmlStateMachine< PackmlTransitionsContinuous >, and packml_sm::PackmlStateMachine< PackmlTransitionsSingleCycle >.

virtual bool packml_sm::AbstractStateMachine::setStarting ( std::function< int()>  state_method)
pure virtual

Override to handle setting the starting state method.

Parameters
state_methodThe state method to execute when entering the start state.
Returns
bool Returns true on success.

Implemented in packml_sm::PackmlStateMachine< T >, packml_sm::PackmlStateMachine< PackmlTransitionsContinuous >, and packml_sm::PackmlStateMachine< PackmlTransitionsSingleCycle >.

virtual bool packml_sm::AbstractStateMachine::setStopping ( std::function< int()>  state_method)
pure virtual

Override to handle setting the stopping state method.

Parameters
state_methodThe state method to execute when entering the stopping state.
Returns
bool Returns true on success.

Implemented in packml_sm::PackmlStateMachine< T >, packml_sm::PackmlStateMachine< PackmlTransitionsContinuous >, and packml_sm::PackmlStateMachine< PackmlTransitionsSingleCycle >.

virtual bool packml_sm::AbstractStateMachine::setSuspending ( std::function< int()>  state_method)
pure virtual

Override to handle setting the suspending state method.

Parameters
state_methodThe state method to execute when entering the suspending state.
Returns
bool Returns true on success.

Implemented in packml_sm::PackmlStateMachine< T >, packml_sm::PackmlStateMachine< PackmlTransitionsContinuous >, and packml_sm::PackmlStateMachine< PackmlTransitionsSingleCycle >.

virtual bool packml_sm::AbstractStateMachine::setUnholding ( std::function< int()>  state_method)
pure virtual

Override to handle setting unholding state method.

Parameters
state_methodThe state method to execute when entering the unholding state.
Returns
bool Returns true on success.

Implemented in packml_sm::PackmlStateMachine< T >, packml_sm::PackmlStateMachine< PackmlTransitionsContinuous >, and packml_sm::PackmlStateMachine< PackmlTransitionsSingleCycle >.

virtual bool packml_sm::AbstractStateMachine::setUnsuspending ( std::function< int()>  state_method)
pure virtual

Override to handle setting the un-suspending state method.

Parameters
state_methodThe state method to execute when entering the unsuspending state.
Returns
bool Returns true on success.

Implemented in packml_sm::PackmlStateMachine< T >, packml_sm::PackmlStateMachine< PackmlTransitionsContinuous >, and packml_sm::PackmlStateMachine< PackmlTransitionsSingleCycle >.

bool packml_sm::AbstractStateMachine::start ( )
virtual

Call to send the start command.

Returns
bool Returns true on success.

Definition at line 31 of file abstract_state_machine.cpp.

bool packml_sm::AbstractStateMachine::stop ( )
virtual

Call to send the stop command.

Returns
bool Returns true on success.

Definition at line 123 of file abstract_state_machine.cpp.

bool packml_sm::AbstractStateMachine::suspend ( )
virtual

Call to send the suspend command.

Returns
bool Returns true on success.

Definition at line 97 of file abstract_state_machine.cpp.

bool packml_sm::AbstractStateMachine::unhold ( )
virtual

Call to send the unhold command.

Returns
bool Returns true on success.

Definition at line 84 of file abstract_state_machine.cpp.

bool packml_sm::AbstractStateMachine::unsuspend ( )
virtual

Call to send the unsuspend command.

Returns
bool Returns true on success.

Definition at line 110 of file abstract_state_machine.cpp.

void packml_sm::AbstractStateMachine::updateClock ( StatesEnum  new_state)
private

Updates all of the durations for the states based on the new state.

Parameters
new_stateThe new state entry.

Definition at line 401 of file abstract_state_machine.cpp.

Member Data Documentation

StatesEnum packml_sm::AbstractStateMachine::current_state_ = StatesEnum::UNDEFINED
private

stat mutex for protecting stat operations

Definition at line 464 of file abstract_state_machine.h.

std::map<StatesEnum, double> packml_sm::AbstractStateMachine::duration_map_
private

cache of the current state

Definition at line 465 of file abstract_state_machine.h.

int packml_sm::AbstractStateMachine::failure_count_ = 0
private

number of successful operations

Definition at line 460 of file abstract_state_machine.h.

float packml_sm::AbstractStateMachine::ideal_cycle_time_ = 0.0
private

number of failed operations

Definition at line 461 of file abstract_state_machine.h.

std::map<int16_t, PackmlStatsItemized> packml_sm::AbstractStateMachine::itemized_error_map_
private

Definition at line 457 of file abstract_state_machine.h.

std::map<int16_t, PackmlStatsItemized> packml_sm::AbstractStateMachine::itemized_quality_map_
private

Definition at line 458 of file abstract_state_machine.h.

std::chrono::steady_clock::time_point packml_sm::AbstractStateMachine::start_time_
private

container for all of the durations referenced by their state id

Definition at line 466 of file abstract_state_machine.h.

std::recursive_mutex packml_sm::AbstractStateMachine::stat_mutex_
private

ideal cycle time in operations per second

Definition at line 463 of file abstract_state_machine.h.

EventHandler<AbstractStateMachine, StateChangedEventArgs> packml_sm::AbstractStateMachine::stateChangedEvent

Definition at line 38 of file abstract_state_machine.h.

int packml_sm::AbstractStateMachine::success_count_ = 0
private

Definition at line 459 of file abstract_state_machine.h.


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


packml_sm
Author(s): Shaun Edwards
autogenerated on Fri Jul 12 2019 03:30:55