ScummVM
Common::EventDispatcher Class Reference

Dispatches events from various sources to various observers. More...

#include <events.h>

Collaboration diagram for Common::EventDispatcher:

Classes

struct  Entry
 
struct  ObserverEntry
 
struct  SourceEntry
 

Public Member Functions

 EventDispatcher ()
 
 ~EventDispatcher ()
 
void dispatch ()
 Tries to catch events from the registered event sources and dispatch them to the observers. More...
 
void clearEvents ()
 Clear all events currently in the event queue. More...
 
void registerMapper (EventMapper *mapper, bool autoFree=true)
 Registers an event mapper with the dispatcher. More...
 
EventMapperqueryMapper () const
 Queries the setup event mapper. More...
 
void registerSource (EventSource *source, bool autoFree)
 Registers a new EventSource with the Dispatcher. More...
 
void unregisterSource (EventSource *source)
 Unregisters a EventSource. More...
 
void registerObserver (EventObserver *obs, uint priority, bool autoFree, bool listenPolls=false)
 Registers a new EventObserver with the Dispatcher. More...
 
void unregisterObserver (EventObserver *obs)
 Unregisters a EventObserver. More...
 

Private Member Functions

void dispatchEvent (const Event &event)
 
void dispatchPoll ()
 

Private Attributes

bool _autoFreeMapper
 
EventMapper_mapper
 
List< SourceEntry_sources
 
List< ObserverEntry_observers
 

Detailed Description

Dispatches events from various sources to various observers.

EventDispatcher is using a priority based approach. Observers with higher priority will be notified before observers with lower priority. Because of the possibility that oberservers might 'eat' events, not all observers might be notified.

Another speciality is the support for a event mapper, which will catch events and create new events out of them. This mapper will be processed before an event is sent to the observers.

Definition at line 336 of file events.h.

Constructor & Destructor Documentation

◆ EventDispatcher()

Common::EventDispatcher::EventDispatcher ( )

Definition at line 27 of file EventDispatcher.cpp.

◆ ~EventDispatcher()

Common::EventDispatcher::~EventDispatcher ( )

Definition at line 30 of file EventDispatcher.cpp.

Member Function Documentation

◆ clearEvents()

void Common::EventDispatcher::clearEvents ( )

Clear all events currently in the event queue.

The cleared events are not dispatched and are simply discarded.

Definition at line 73 of file EventDispatcher.cpp.

◆ dispatch()

void Common::EventDispatcher::dispatch ( )

Tries to catch events from the registered event sources and dispatch them to the observers.

This dispatches all events the sources offer.

Definition at line 47 of file EventDispatcher.cpp.

◆ dispatchEvent()

void Common::EventDispatcher::dispatchEvent ( const Event event)
private

Definition at line 142 of file EventDispatcher.cpp.

◆ dispatchPoll()

void Common::EventDispatcher::dispatchPoll ( )
private

Definition at line 149 of file EventDispatcher.cpp.

◆ queryMapper()

EventMapper* Common::EventDispatcher::queryMapper ( ) const
inline

Queries the setup event mapper.

Definition at line 374 of file events.h.

◆ registerMapper()

void Common::EventDispatcher::registerMapper ( EventMapper mapper,
bool  autoFree = true 
)

Registers an event mapper with the dispatcher.

The ownership of the "mapper" variable will pass to the EventDispatcher, thus it will be deleted with "delete", when EventDispatcher is destroyed.

Parameters
autoFreeDestroy previous mapper [default] Normally we allow only one event mapper to exists, However Event Recorder must intervent into normal event flow without altering its semantics. Thus during Event Recorder playback and recording we allow two mappers.

Definition at line 82 of file EventDispatcher.cpp.

◆ registerObserver()

void Common::EventDispatcher::registerObserver ( EventObserver obs,
uint  priority,
bool  autoFree,
bool  listenPolls = false 
)

Registers a new EventObserver with the Dispatcher.

Parameters
listenPollsif set, then all pollEvent() calls are passed to observer currently it is used by keyMapper

Definition at line 112 of file EventDispatcher.cpp.

◆ registerSource()

void Common::EventDispatcher::registerSource ( EventSource source,
bool  autoFree 
)

Registers a new EventSource with the Dispatcher.

Definition at line 91 of file EventDispatcher.cpp.

◆ unregisterObserver()

void Common::EventDispatcher::unregisterObserver ( EventObserver obs)

Unregisters a EventObserver.

This takes the "autoFree" flag passed to registerObserver into account.

Definition at line 130 of file EventDispatcher.cpp.

◆ unregisterSource()

void Common::EventDispatcher::unregisterSource ( EventSource source)

Unregisters a EventSource.

This takes the "autoFree" flag passed to registerSource into account.

Definition at line 100 of file EventDispatcher.cpp.

Member Data Documentation

◆ _autoFreeMapper

bool Common::EventDispatcher::_autoFreeMapper
private

Definition at line 403 of file events.h.

◆ _mapper

EventMapper* Common::EventDispatcher::_mapper
private

Definition at line 404 of file events.h.

◆ _observers

List<ObserverEntry> Common::EventDispatcher::_observers
private

Definition at line 422 of file events.h.

◆ _sources

List<SourceEntry> Common::EventDispatcher::_sources
private

Definition at line 414 of file events.h.


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