#include <EventSender.h>
Public Types | |
| typedef Listener< EvType > | TListener |
| Simpler form of Listener<EvType>. | |
Static Public Member Functions | |
| static void | remove (TListener &) |
| static void | add (TListener &) |
| static void | send (const EvType &) |
| static bool | isSending () |
| static bool | hasListeners () |
| static unsigned int | getNumListeners () |
| static unsigned int | getMinNumIgnored () |
Friends | |
| class | Listener< EvType > |
| So Listener<EvType> can call register etc. | |
Classes | |
| class | IllegalSendError |
Usage:
An exception that gets thrown when EventSender<EvType>::send() is called recursively at least once. This situation is more likely in complex systems where events cause other events to be generated.
An example scenario is where you create an Type1Event and call EventSender<Type1Event>::send(Type1Event). This call to send() in turn calls the processEvent() method of a listener of Type1Event's. If this listener's method creates another Type1Event and calls EventSender<Type1Event>::send(Type1Event) on it, this will cause that listener's processEvent() to be called once more, and the process repeats. This is likely to trigger an infinite loop of event generation. The only case where this would not happen is if the listener keeps state information that changes between successive calls to processEvent(), such that it does not generate an event during one of those calls (the recursion ends), or if this listener deregister's itself from listening.
Since an infinite recursion is likely to cause a program crash, and since it is quite easy to make that kind of mistake, EventSender<EvType> forbids calling send() while a send() (for that event type) is in progress. It will throw a EventSender<EvType>::IllegalSendError if such a situation occurs.
Definition at line 34 of file EventSender.h.
| typedef Listener<EvType> EventSender< EvType >::TListener |
| void EventSender< EvType >::remove | ( | TListener & | listener | ) | [inline, static] |
Remove the listener from the registry. Does nothing if the listener is not in the registry.
Definition at line 186 of file EventSender.h.
| void EventSender< EvType >::add | ( | TListener & | listener | ) | [inline, static] |
Add the listener to the registry. Does nothing if the listener is already registered.
Definition at line 196 of file EventSender.h.
| void EventSender< EvType >::send | ( | const EvType & | event | ) | [inline, static] |
Send the event to its listeners.
| IllegalSendError |
Definition at line 166 of file EventSender.h.
| bool EventSender< EvType >::isSending | ( | ) | [inline, static] |
Is this event sender currently sending the event to its listeners? True if yes, false otherwise.
Definition at line 176 of file EventSender.h.
| bool EventSender< EvType >::hasListeners | ( | ) | [inline, static] |
Are there listeners currently registered? If this returns false, creating and send()ing and event just wastes cpu cycles since no one will hear event.
Definition at line 119 of file EventSender.h.
| unsigned int EventSender< EvType >::getNumListeners | ( | ) | [inline, static] |
Get how many listeners are currently registered. Note that if isSending() is true, then this number does not take into account listeners that are queued for registration/removal.
Definition at line 143 of file EventSender.h.
| unsigned int EventSender< EvType >::getMinNumIgnored | ( | ) | [inline, static] |
Get how many listeners have ignored the event that is currently being sent and that they have received. This number is reset to 0 before every call to send(const EvType&). This number is a minimum, since a listener is not required to tell EventSender<EvType> that it is ignoring an event.
Definition at line 132 of file EventSender.h.
friend class Listener< EvType > [friend] |
1.5.6