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)
 Registers an event mapper with the dispatcher. 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

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 328 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 75 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 42 of file EventDispatcher.cpp.

◆ dispatchEvent()

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

Definition at line 140 of file EventDispatcher.cpp.

◆ dispatchPoll()

void Common::EventDispatcher::dispatchPoll ( )
private

Definition at line 147 of file EventDispatcher.cpp.

◆ registerMapper()

void Common::EventDispatcher::registerMapper ( EventMapper mapper)

Registers an event mapper with the dispatcher.

Definition at line 84 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 110 of file EventDispatcher.cpp.

◆ registerSource()

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

Registers a new EventSource with the Dispatcher.

Definition at line 89 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 128 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 98 of file EventDispatcher.cpp.

Member Data Documentation

◆ _mapper

EventMapper* Common::EventDispatcher::_mapper
private

Definition at line 379 of file events.h.

◆ _observers

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

Definition at line 397 of file events.h.

◆ _sources

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

Definition at line 389 of file events.h.


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