Hedgehog  0.0.0
A library to generate hybrid pipeline workflow systems
hh::AbstractState< StateOutput, StateInputs > Class Template Reference

State Interface for managing computation, need a corresponding AbstractStateManager to be embedded in a Hedgehog Graph. More...

#include "abstract_state.h"

Inheritance diagram for hh::AbstractState< StateOutput, StateInputs >:
Inheritance graph
Collaboration diagram for hh::AbstractState< StateOutput, StateInputs >:
Collaboration graph

Public Member Functions

 AbstractState ()
 Default constructor, initialize the mutex (AbstractState::stateMutex_) and the ready list (AbstractState::readyList_)
 
virtual ~AbstractState ()=default
 Default destructor.
 
std::unique_ptr< std::queue< std::shared_ptr< StateOutput > > > const & readyList () const
 Ready list accessor. More...
 
void push (std::shared_ptr< StateOutput > const &elem)
 Add an element to the ready list. More...
 
std::shared_ptr< StateOutput > frontAndPop ()
 Used by AbstractStateManager to get the ready list's front element. More...
 
void lock ()
 Lock the state.
 
void unlock ()
 Unlock the state.
 
- Public Member Functions inherited from hh::behavior::Execute< StateInputs >
virtual void execute (std::shared_ptr< StateInputs >)=0
 Virtual declaration of execute function for a data of type Input.
 

Private Attributes

std::unique_ptr< std::shared_mutex > stateMutex_ = nullptr
 State Mutex.
 
std::unique_ptr< std::queue< std::shared_ptr< StateOutput > > > readyList_ = nullptr
 State Ready list.
 

Detailed Description

template<class StateOutput, class ... StateInputs>
class hh::AbstractState< StateOutput, StateInputs >

State Interface for managing computation, need a corresponding AbstractStateManager to be embedded in a Hedgehog Graph.

An AbstractState is a tool used by Hedgehog when data synchronization is needed. When overloaded, data structures that are added to the class can manage the state of computation. AbstractState owns a mutex to guarantee safety, because it can be shared among multiple AbstractStateManager.

The default order of execution is:

  1. The DefaultStateManager will acquire a data,
  2. The DefaultStateManager will lock the AbstractState (with AbstractState::stateMutex_),
  3. The DefaultStateManager will send the data to the possessed AbstractState,
  4. The compatible Execute::execute is called with the data,
  5. During the call of Execute::execute, if the method AbstractState::push is invoked the "result data" is stored in a ready list AbstractState::readyList_,
  6. When the Execute::execute has returned, the waiting list is emptied as output of the AbstractStateManager,
  7. The DefaultStateManager will unlock the AbstractState (with AbstractState::stateMutex_).
Virtual functions
Execute::execute (one for each of StateInputs)
Attention
An AbstractState can be only owned by a compatible AbstractStateManager, i.e. they have the same StateOutput and the same StateInputs.
Template Parameters
StateOutputState output type
StateInputsState input types

Definition at line 58 of file abstract_state.h.

Member Function Documentation

◆ frontAndPop()

template<class StateOutput , class ... StateInputs>
std::shared_ptr<StateOutput> hh::AbstractState< StateOutput, StateInputs >::frontAndPop ( )
inline

Used by AbstractStateManager to get the ready list's front element.

Returns
The ready list's front element

Definition at line 86 of file abstract_state.h.

◆ push()

template<class StateOutput , class ... StateInputs>
void hh::AbstractState< StateOutput, StateInputs >::push ( std::shared_ptr< StateOutput > const &  elem)
inline

Add an element to the ready list.

Parameters
elemElement to add

Definition at line 82 of file abstract_state.h.

◆ readyList()

template<class StateOutput , class ... StateInputs>
std::unique_ptr<std::queue<std::shared_ptr<StateOutput> > > const& hh::AbstractState< StateOutput, StateInputs >::readyList ( ) const
inline

Ready list accessor.

Returns
Ready list

Definition at line 78 of file abstract_state.h.


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