LDA++
Public Member Functions | List of all members
ldaplusplus::events::ThreadSafeEventDispatcher Class Reference

#include <Events.hpp>

Inheritance diagram for ldaplusplus::events::ThreadSafeEventDispatcher:
ldaplusplus::events::EventDispatcherInterface ldaplusplus::events::SameThreadEventDispatcher

Public Member Functions

virtual void add_listener (std::shared_ptr< EventListenerInterface > listener) override
 
virtual void remove_listener (std::shared_ptr< EventListenerInterface > listener) override
 
virtual void dispatch (std::shared_ptr< Event > event) override
 
void process_events ()
 
- Public Member Functions inherited from ldaplusplus::events::EventDispatcherInterface
std::shared_ptr< EventListenerInterfaceadd_listener (std::function< void(std::shared_ptr< Event >)> listener)
 
template<class ListenerType , typename... Args>
std::shared_ptr< EventListenerInterfaceadd_listener (Args...args)
 
template<class EventType , typename... Args>
void dispatch (Args...args)
 

Detailed Description

A thread safe event dispatcher that dispatches the events when its process_events method is called and on the thread that the process_events method is called.

Member Function Documentation

void ldaplusplus::events::ThreadSafeEventDispatcher::add_listener ( std::shared_ptr< EventListenerInterface listener)
overridevirtual

Add a listener to this dispatcher so that in subsequent calls to dispatch this listener will be notified.

The interface doesn't define handling of double adds or double removes.

Parameters
listenerThe listener to be added

Implements ldaplusplus::events::EventDispatcherInterface.

void ldaplusplus::events::ThreadSafeEventDispatcher::dispatch ( std::shared_ptr< Event event)
overridevirtual

Call the on_event() function of every listener passing this event as a parameter.

The interface doesn't define when the on_event function will be called and it is not guaranteed that upon return of the dispatch function all listeners will be notified.

Parameters
eventThe event to be sent to the listeners

Implements ldaplusplus::events::EventDispatcherInterface.

Reimplemented in ldaplusplus::events::SameThreadEventDispatcher.

void ldaplusplus::events::ThreadSafeEventDispatcher::process_events ( )

Traverse the listener queue and notify them of any events that occured since the last time.

The listeners will be called on the thread that this method is called.

void ldaplusplus::events::ThreadSafeEventDispatcher::remove_listener ( std::shared_ptr< EventListenerInterface listener)
overridevirtual

Remove a listener from this dispatcher so that in subsequent calls to dispatch this listener will not be notified.

The interface doesn't define handling of double adds or double removes.

Parameters
listenerThe listener to be removed

Implements ldaplusplus::events::EventDispatcherInterface.


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