The StateMachineInterface class defines a implementation independent interface to a PackML state machine. More...
#include <abstract_state_machine.h>
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, StateChangedEventArgs > | stateChangedEvent |
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, PackmlStatsItemized > | itemized_error_map_ |
std::map< int16_t, PackmlStatsItemized > | itemized_quality_map_ |
std::chrono::steady_clock::time_point | start_time_ |
std::recursive_mutex | stat_mutex_ |
int | success_count_ = 0 |
The StateMachineInterface class defines a implementation independent interface to a PackML state machine.
Definition at line 35 of file abstract_state_machine.h.
packml_sm::AbstractStateMachine::AbstractStateMachine | ( | ) |
Constructor for AbstractStateMachine.
Triggered during a state changed event.
Definition at line 27 of file abstract_state_machine.cpp.
|
inlinevirtual |
Destructor for AbstractStateMachine.
Definition at line 51 of file abstract_state_machine.h.
|
protectedpure virtual |
Override to call implementations version of the abort command.
Implemented in packml_sm::PackmlStateMachine< T >, packml_sm::PackmlStateMachine< PackmlTransitionsContinuous >, and packml_sm::PackmlStateMachine< PackmlTransitionsSingleCycle >.
|
protectedpure virtual |
Override to call implementations version of clear command.
Implemented in packml_sm::PackmlStateMachine< T >, packml_sm::PackmlStateMachine< PackmlTransitionsContinuous >, and packml_sm::PackmlStateMachine< PackmlTransitionsSingleCycle >.
|
protectedpure virtual |
Override to call implementations version of the hold command.
Implemented in packml_sm::PackmlStateMachine< T >, packml_sm::PackmlStateMachine< PackmlTransitionsContinuous >, and packml_sm::PackmlStateMachine< PackmlTransitionsSingleCycle >.
|
protectedpure virtual |
Override to call implementations version of the reset command.
Implemented in packml_sm::PackmlStateMachine< T >, packml_sm::PackmlStateMachine< PackmlTransitionsContinuous >, and packml_sm::PackmlStateMachine< PackmlTransitionsSingleCycle >.
|
protectedpure virtual |
Override to call implementations version of start command.
Implemented in packml_sm::PackmlStateMachine< T >, packml_sm::PackmlStateMachine< PackmlTransitionsContinuous >, and packml_sm::PackmlStateMachine< PackmlTransitionsSingleCycle >.
|
protectedpure virtual |
Override to call implementations version of the stop command.
Implemented in packml_sm::PackmlStateMachine< T >, packml_sm::PackmlStateMachine< PackmlTransitionsContinuous >, and packml_sm::PackmlStateMachine< PackmlTransitionsSingleCycle >.
|
protectedpure virtual |
Override to call implementations version of the suspend command.
Implemented in packml_sm::PackmlStateMachine< T >, packml_sm::PackmlStateMachine< PackmlTransitionsContinuous >, and packml_sm::PackmlStateMachine< PackmlTransitionsSingleCycle >.
|
protectedpure virtual |
Override to call implementations version of the unhold command.
Implemented in packml_sm::PackmlStateMachine< T >, packml_sm::PackmlStateMachine< PackmlTransitionsContinuous >, and packml_sm::PackmlStateMachine< PackmlTransitionsSingleCycle >.
|
protectedpure virtual |
Override to call implementations version of the unsuspend command.
Implemented in packml_sm::PackmlStateMachine< T >, packml_sm::PackmlStateMachine< PackmlTransitionsContinuous >, and packml_sm::PackmlStateMachine< PackmlTransitionsSingleCycle >.
|
virtual |
Call to send the abort command.
Definition at line 147 of file abstract_state_machine.cpp.
|
pure virtual |
Override to handle activate command.
Implemented in packml_sm::PackmlStateMachine< T >, packml_sm::PackmlStateMachine< PackmlTransitionsContinuous >, and packml_sm::PackmlStateMachine< PackmlTransitionsSingleCycle >.
|
private |
Accessor for the total duration of the state machine.
Definition at line 312 of file abstract_state_machine.cpp.
|
virtual |
Call to send the clear command.
Definition at line 44 of file abstract_state_machine.cpp.
|
pure virtual |
Override to handle deactivate command.
Implemented in packml_sm::PackmlStateMachine< T >, packml_sm::PackmlStateMachine< PackmlTransitionsContinuous >, and packml_sm::PackmlStateMachine< PackmlTransitionsSingleCycle >.
double packml_sm::AbstractStateMachine::getAbortedTime | ( | ) |
Accessor for the duration spent in aborted.
Definition at line 302 of file abstract_state_machine.cpp.
double packml_sm::AbstractStateMachine::getAbortingTime | ( | ) |
Accessor for the duration spent in aborting.
Definition at line 307 of file abstract_state_machine.cpp.
double packml_sm::AbstractStateMachine::getClearingTime | ( | ) |
Accessor for the duration spent in clearing.
Definition at line 292 of file abstract_state_machine.cpp.
double packml_sm::AbstractStateMachine::getCompleteTime | ( | ) |
Accessor for the duration spent in complete.
Definition at line 282 of file abstract_state_machine.cpp.
|
inline |
Accessor for 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.
snapshot_out | Reference 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.
Definition at line 247 of file abstract_state_machine.cpp.
double packml_sm::AbstractStateMachine::getHeldTime | ( | ) |
Accessor for the duration spent in held.
Definition at line 252 of file abstract_state_machine.cpp.
double packml_sm::AbstractStateMachine::getHoldingTime | ( | ) |
Accessor for the duration spent in holding.
Definition at line 257 of file abstract_state_machine.cpp.
double packml_sm::AbstractStateMachine::getIdleTime | ( | ) |
Accessor for the duration spent in idle time.
Definition at line 232 of file abstract_state_machine.cpp.
double packml_sm::AbstractStateMachine::getResettingTime | ( | ) |
Accessor for the duration spent in resetting.
Definition at line 242 of file abstract_state_machine.cpp.
double packml_sm::AbstractStateMachine::getStartingTime | ( | ) |
Accessor for the duration spent in starting.
Definition at line 237 of file abstract_state_machine.cpp.
|
private |
Accessor for the given state duration.
state | The state of interest. |
Definition at line 417 of file abstract_state_machine.cpp.
double packml_sm::AbstractStateMachine::getStoppedTime | ( | ) |
Accessor for the duration spent in stopped.
Definition at line 287 of file abstract_state_machine.cpp.
double packml_sm::AbstractStateMachine::getStoppingTime | ( | ) |
Accessor for the duration spent in stopping.
Definition at line 297 of file abstract_state_machine.cpp.
double packml_sm::AbstractStateMachine::getSuspendedTime | ( | ) |
Accessor for the duration spent in suspended.
Definition at line 267 of file abstract_state_machine.cpp.
double packml_sm::AbstractStateMachine::getSuspendingTime | ( | ) |
Accessor for the duration spent in suspending.
Definition at line 272 of file abstract_state_machine.cpp.
double packml_sm::AbstractStateMachine::getUnholdingTime | ( | ) |
Accessor for the duration spent in unholding.
Definition at line 262 of file abstract_state_machine.cpp.
double packml_sm::AbstractStateMachine::getUnsuspendingTime | ( | ) |
Accessor for the duration spent in unsuspending.
Definition at line 277 of file abstract_state_machine.cpp.
|
virtual |
Call to send the hold command.
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.
|
private |
adds or updates the specific itemized map
start time for the latest state entry
itemized_map | the map to add or update. |
id | the id to add or update. |
count | the number of occurences to add. |
duration | the 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.
|
protected |
Call to invoke a state changed event.
name | The name of the new state. |
value | The name of the new value. |
Definition at line 395 of file abstract_state_machine.cpp.
|
pure virtual |
Override to provide an accessor to whether the state machine is currently active.
Implemented in packml_sm::PackmlStateMachine< T >, packml_sm::PackmlStateMachine< PackmlTransitionsContinuous >, and packml_sm::PackmlStateMachine< PackmlTransitionsSingleCycle >.
|
virtual |
Call to send the reset command.
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.
|
pure virtual |
Override to handle setting the aborting state method.
state_method | The state method to execute when entering the aborting state. |
Implemented in packml_sm::PackmlStateMachine< T >, packml_sm::PackmlStateMachine< PackmlTransitionsContinuous >, and packml_sm::PackmlStateMachine< PackmlTransitionsSingleCycle >.
|
pure virtual |
Override to handle setting the clearing state method.
state_method | The state method to execute when entering the clearing state. |
Implemented in packml_sm::PackmlStateMachine< T >, packml_sm::PackmlStateMachine< PackmlTransitionsContinuous >, and packml_sm::PackmlStateMachine< PackmlTransitionsSingleCycle >.
|
pure virtual |
Override to handle setting the completing state method.
state_method | The state method to execute when entering the completing state. |
Implemented in packml_sm::PackmlStateMachine< T >, packml_sm::PackmlStateMachine< PackmlTransitionsContinuous >, and packml_sm::PackmlStateMachine< PackmlTransitionsSingleCycle >.
|
pure virtual |
Override to handle setting the execute state method.
state_method | The state method to execute when entering the exec state. |
Implemented in packml_sm::PackmlStateMachine< T >, packml_sm::PackmlStateMachine< PackmlTransitionsContinuous >, and packml_sm::PackmlStateMachine< PackmlTransitionsSingleCycle >.
|
pure virtual |
Override to handle setting the holding state method.
state_method | The state method to execute when entering the holding state. |
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.
ideal_cycle_time | The ideal cycle time in operations per second. |
Definition at line 389 of file abstract_state_machine.cpp.
|
pure virtual |
Override to handle setting the resetting state method.
state_method | The state method to execute when entering the resetting state. |
Implemented in packml_sm::PackmlStateMachine< T >, packml_sm::PackmlStateMachine< PackmlTransitionsContinuous >, and packml_sm::PackmlStateMachine< PackmlTransitionsSingleCycle >.
|
pure virtual |
Override to handle setting the starting state method.
state_method | The state method to execute when entering the start state. |
Implemented in packml_sm::PackmlStateMachine< T >, packml_sm::PackmlStateMachine< PackmlTransitionsContinuous >, and packml_sm::PackmlStateMachine< PackmlTransitionsSingleCycle >.
|
pure virtual |
Override to handle setting the stopping state method.
state_method | The state method to execute when entering the stopping state. |
Implemented in packml_sm::PackmlStateMachine< T >, packml_sm::PackmlStateMachine< PackmlTransitionsContinuous >, and packml_sm::PackmlStateMachine< PackmlTransitionsSingleCycle >.
|
pure virtual |
Override to handle setting the suspending state method.
state_method | The state method to execute when entering the suspending state. |
Implemented in packml_sm::PackmlStateMachine< T >, packml_sm::PackmlStateMachine< PackmlTransitionsContinuous >, and packml_sm::PackmlStateMachine< PackmlTransitionsSingleCycle >.
|
pure virtual |
Override to handle setting unholding state method.
state_method | The state method to execute when entering the unholding state. |
Implemented in packml_sm::PackmlStateMachine< T >, packml_sm::PackmlStateMachine< PackmlTransitionsContinuous >, and packml_sm::PackmlStateMachine< PackmlTransitionsSingleCycle >.
|
pure virtual |
Override to handle setting the un-suspending state method.
state_method | The state method to execute when entering the unsuspending state. |
Implemented in packml_sm::PackmlStateMachine< T >, packml_sm::PackmlStateMachine< PackmlTransitionsContinuous >, and packml_sm::PackmlStateMachine< PackmlTransitionsSingleCycle >.
|
virtual |
Call to send the start command.
Definition at line 31 of file abstract_state_machine.cpp.
|
virtual |
Call to send the stop command.
Definition at line 123 of file abstract_state_machine.cpp.
|
virtual |
Call to send the suspend command.
Definition at line 97 of file abstract_state_machine.cpp.
|
virtual |
Call to send the unhold command.
Definition at line 84 of file abstract_state_machine.cpp.
|
virtual |
Call to send the unsuspend command.
Definition at line 110 of file abstract_state_machine.cpp.
|
private |
Updates all of the durations for the states based on the new state.
new_state | The new state entry. |
Definition at line 401 of file abstract_state_machine.cpp.
|
private |
stat mutex for protecting stat operations
Definition at line 464 of file abstract_state_machine.h.
|
private |
cache of the current state
Definition at line 465 of file abstract_state_machine.h.
|
private |
number of successful operations
Definition at line 460 of file abstract_state_machine.h.
|
private |
number of failed operations
Definition at line 461 of file abstract_state_machine.h.
|
private |
Definition at line 457 of file abstract_state_machine.h.
|
private |
Definition at line 458 of file abstract_state_machine.h.
|
private |
container for all of the durations referenced by their state id
Definition at line 466 of file abstract_state_machine.h.
|
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.
|
private |
Definition at line 459 of file abstract_state_machine.h.