Skip to main content

EventManager Class

An abstract EventManager managing the buffering and dispatching of events, acting as a central hub for event management. More...

Declaration

class helios::event::EventManager { ... }

Derived Classes

classBasicEventManager

Basic implementation of the EventManager. More...

Public Constructors Index

EventManager (std::unique_ptr< EventQueue > eventQueue, std::unique_ptr< Dispatcher > dispatcher)

Creates a new EventManager using the specified EventQueue and Dispatcher. More...

Protected Constructors Index

EventManager ()=default

Public Destructor Index

~EventManager ()=default

Public Member Functions Index

EventManager &post (std::unique_ptr< const Event > event)

Posts the event to the queue using the APPEND policy, passing ownership of the event to the underlying queue. More...

EventManager &post (std::unique_ptr< const Event > event, PostPolicy policy)

Posts the event to the queue, passing ownership of the event to the underlying queue. More...

EventManager &post (std::unique_ptr< const Event > event, PostPolicy policy, const std::function< bool(const std::unique_ptr< const Event > &event, const std::unique_ptr< const Event > &evt)> &func)=0

Posts the event to the underlying EventQueue using the specified policy and the specified func. More...

EventManager &dispatchAll ()=0

Dispatches all events currently held in the event queue. More...

template <typename EventType>
EventManager &subscribe (std::function< void(const EventType &)> callback)

Subscribes a callback to the specified EventType. More...

Dispatcher &dispatcher () const noexcept

Returns a reference to the dispatcher used with this EventManager. More...

Protected Member Attributes Index

std::unique_ptr< EventQueue >eventQueue_

A unique_ptr to the EventQueue this EventManager owns. More...

std::unique_ptr< Dispatcher >dispatcher_

A unique_ptr to the Dispatcher this EventManager owns. More...

Protected Static Attributes Index

static const helios::util::log::Logger &logger_ = helios::util::log::LogManager::loggerForScope(HELIOS_LOG_SCOPE)

Description

An abstract EventManager managing the buffering and dispatching of events, acting as a central hub for event management.

Concrete implementations take care of `dispatchAll()`, that is, the logic for dispatching all events to the subscribed callbacks.

Definition at line 56 of file EventManager.ixx.

Public Constructors

EventManager()

helios::event::EventManager::EventManager (std::unique_ptr< EventQueue > eventQueue, std::unique_ptr< Dispatcher > dispatcher)
inline explicit

Creates a new EventManager using the specified EventQueue and Dispatcher.

The EventManger takes onwership of the EventQueue and the Dispatcher.

Parameters
eventQueue
dispatcher

Definition at line 86 of file EventManager.ixx.

86 explicit EventManager(
87 std::unique_ptr<EventQueue> eventQueue,
88 std::unique_ptr<Dispatcher> dispatcher
89 ) :
90 eventQueue_(std::move(eventQueue)),
91 dispatcher_(std::move(dispatcher))
92 {}

References dispatcher, dispatcher_ and eventQueue_.

Protected Constructors

EventManager()

helios::event::EventManager::EventManager ()
protected default

Public Destructor

~EventManager()

virtual helios::event::EventManager::~EventManager ()
virtual default

Definition at line 76 of file EventManager.ixx.

Public Member Functions

dispatchAll()

virtual EventManager & helios::event::EventManager::dispatchAll ()

Dispatches all events currently held in the event queue.

This method retrieves and removes events one by one from the underlying `EventQueue`, passing ownership to the underlying Dispatcher.

Returns

EventManager

Definition at line 161 of file EventManager.ixx.

Reference EventManager.

dispatcher()

Dispatcher & helios::event::EventManager::dispatcher ()
inline nodiscard noexcept

Returns a reference to the dispatcher used with this EventManager.

Provides direct access to the dispatcher, allowing for modification of the Dispatcher, e.g. managing subscriptions.

Returns

Dispatcher

Definition at line 191 of file EventManager.ixx.

191 [[nodiscard]] Dispatcher& dispatcher() const noexcept {
192 return *dispatcher_;
193 }

Reference dispatcher_.

Referenced by helios::event::BasicEventManager::BasicEventManager and EventManager.

post()

EventManager & helios::event::EventManager::post (std::unique_ptr< const Event > event)
inline

Posts the event to the queue using the APPEND policy, passing ownership of the event to the underlying queue.

Calling this function is functionally identical to calling post() with the second argument set to APPEND.

Parameters
event

The event to post to the EventQueue.

Returns

EventManager

Definition at line 106 of file EventManager.ixx.

106 EventManager& post(std::unique_ptr<const Event> event) {
107 return post(std::move(event), APPEND, nullptr);
108 }

References helios::event::APPEND, EventManager and post.

Referenced by post and post.

post()

EventManager & helios::event::EventManager::post (std::unique_ptr< const Event > event, PostPolicy policy)
inline

Posts the event to the queue, passing ownership of the event to the underlying queue.

Calling this function is identical to calling post() with the third argument func set to nullptr, relying on the default implementations.

Parameters
event

The event to post to the EventQueue.

policy

The policy to use for posting the event.

Returns

EventManager

Definition at line 123 of file EventManager.ixx.

123 EventManager& post(std::unique_ptr<const Event> event, PostPolicy policy) {
124 logger_.debug(std::format("Posting Event {0}", event->toString()));
125 return post(std::move(event), policy, nullptr);
126 }

References EventManager, logger_ and post.

post()

virtual EventManager & helios::event::EventManager::post (std::unique_ptr< const Event > event, PostPolicy policy, const std::function< bool(const std::unique_ptr< const Event > &event, const std::unique_ptr< const Event > &evt)> & func)

Posts the event to the underlying EventQueue using the specified policy and the specified func.

Implementing classes are responsible to treating func according to the specified policy, e.g. APPEND for adding the event to the queue, LATEST_WINS for removing a particular event in favor of the submitted event.

Parameters
event

A unique_ptr to the event to be posted. Will be the first argument passed to func.

policy

The post policy for the event (

See Also

PostPolicy)

Parameters
func

The function used with the PostPolicy.

Returns

Definition at line 144 of file EventManager.ixx.

Reference EventManager.

subscribe()

template <typename EventType>
EventManager & helios::event::EventManager::subscribe (std::function< void(const EventType &)> callback)
inline

Subscribes a callback to the specified EventType.

Delegates to the subscribe() method of the underlying dispatcher.

Template Parameters
EventType

The specific tyoe of the event to subscribe to.

Parameters
callback

The callback function that should be called when an event of the specific type is triggered.

Returns

EventManager

Definition at line 176 of file EventManager.ixx.

176 EventManager& subscribe(std::function<void(const EventType&)> callback) {
177 dispatcher_->subscribe(callback);
178
179 return *this;
180 }

References dispatcher_ and EventManager.

Protected Member Attributes

dispatcher_

std::unique_ptr<Dispatcher> helios::event::EventManager::dispatcher_
protected

A unique_ptr to the Dispatcher this EventManager owns.

Definition at line 70 of file EventManager.ixx.

70 std::unique_ptr<Dispatcher> dispatcher_;

Referenced by helios::event::BasicEventManager::dispatchAll, dispatcher, EventManager and subscribe.

eventQueue_

std::unique_ptr<EventQueue> helios::event::EventManager::eventQueue_
protected

A unique_ptr to the EventQueue this EventManager owns.

Definition at line 65 of file EventManager.ixx.

65 std::unique_ptr<EventQueue> eventQueue_;

Referenced by helios::event::BasicEventManager::dispatchAll, EventManager and helios::event::BasicEventManager::post.

Protected Static Attributes

logger_

const helios::util::log::Logger& helios::event::EventManager::logger_ = helios::util::log::LogManager::loggerForScope(HELIOS_LOG_SCOPE)
protected static

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


Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.15.0.