Class HsmEventDispatcherSTD

Public Member Functions

 
virtual voidemitEvent (const HandlerID_t handlerID)
 See IHsmEventDispatcher::emitEvent()
 
virtual boolstart ()
 Start events dispatching.
 
virtual voidstop ()
 Stop dispatching events.
 
voidjoin ()
 Blocks current thread until dispatcher is stopped.
 
static std::shared_ptr<HsmEventDispatcherSTD>create (const size_t eventsCacheSize = (10))
 Create dispatcher instance.
 

Inheritance Relationships

Base Type

Class Documentation

class HsmEventDispatcherSTD : public hsmcpp::HsmEventDispatcherBase

HsmEventDispatcherSTD provides platform independent dispatcher implementation based on standard C++ library.

See HsmEventDispatcherSTD for details.

Public Functions


virtual void emitEvent(const HandlerID_t handlerID) override

See IHsmEventDispatcher::emitEvent()

Concurrency

thread-safe


virtual bool start() override

Start events dispatching.

Is called by HierarchicalStateMachine::initialize(). Implementation of this method is optional and depends on individual dispatcher design. Calling this function multiple times should have no effect. In case there is no special start up logic dispatcher implementation must return true.

Function starts a new std::thread for dispatching events. Thread can be stopped by calling stop().

Remark

Implementation should be non blocking and doesn’t have to be threadsafe.

Not Thread Safe

This API is intended to be called only once during startup.

Return values
  • true – dispatching was successfully started or it is already running

  • false – failed to start events dispatching


virtual void stop() override

Stop dispatching events.

Future calls to dispatchEvents() will have no effect.

Wakes up dispatcher thread and instructs it to stop. Has not effect if thread is not running.

Remark

Operation is performed asynchronously. It does not interrupt currently handled event, but will cancel all other pending events.

Concurrency

thread-safe

Remark

Operation is performed asynchronously. Call join() if you need to wait for dispatcher to fully stop.


void join()

Blocks current thread until dispatcher is stopped.

This API can be useful if you want to block your main() function until HSM is operable. See ./examples/00_helloworld/00_helloworld_std.cpp for a reference.

Remark

: Make sure you call stop() before you use join() API.

Public Static Functions


static std::shared_ptr<HsmEventDispatcherSTD> create(const size_t eventsCacheSize = (10))

Create dispatcher instance.

Concurrency

thread-safe

Instance can be safely created and destroyed from any thread.

Parameters

eventsCacheSize – size of the queue preallocated for delayed events

Returns

New dispatcher instance.