Base class for dispatchers. Dispatchers are used to publish and subscribe to events represented by IDispatchable objects. More...
Classes | |
class | HandlerDisposable |
A helper class that allows to create a subscription that is active until the caller disposes the result. More... | |
Public Types | |
enum | ListenerStatus |
Status of a listener. Used to determine if a listener is still alive. More... | |
Public Member Functions | |
void | Clear () |
Removes all subscriptions. More... | |
int | GetIndex< TDispatchable > () |
Returns the index of a specific dispatchable type. Throws in case the type is not registered. More... | |
void | RemoveDeadListeners () |
Removes every subscription for which GetListenerStatus returns ListenerStatus.Dead More... | |
DispatcherSubscription | Subscribe< TDispatchable > (object listener, DispatchableHandler< TDispatchable > handler, bool once=false, uint flags=0, DispatchableFilter filter=null) |
Creates a subscription. Subscriptions can be cancelled manually by calling UnsubscribeHandler<TDispatchable>(DispatchableHandler<TDispatchable>), but as long as the derived class overrides GetListenerStatus(object, uint) and calls DispatcherBase.RemoveDeadListeners() periodically, the dispatcher will be free of memory leaks. More... | |
IDisposable | SubscribeManual< TDispatchable > (DispatchableHandler< TDispatchable > handler, bool once=false, DispatchableFilter filter=null) |
Creates a subscription that is active until the caller disposes the result. More... | |
IDisposable | SubscribeManual< TDispatchable > (object listener, DispatchableHandler< TDispatchable > handler, bool once=false, DispatchableFilter filter=null) |
Creates a subscription that is active until the caller disposes the result or calls Unsubscribe. More... | |
bool | Unsubscribe (DispatcherSubscription subscription) |
Cancel a specific subscription. More... | |
bool | UnsubscribeHandler< TDispatchable > (DispatchableHandler< TDispatchable > handler) |
Cancel every subscription using a handler. More... | |
bool | UnsubscribeListener (object listener) |
Cancel every subscription for a listener. More... | |
bool | UnsubscribeListener< TDispatchable > (object listener) |
Cancel every specific subscription type for a listener. More... | |
Protected Member Functions | |
DispatcherBase (Dictionary< Type, Int32 > typeToIndex) | |
Initializes the dispatcher with a mapping of types to ids. The ids are used to quickly find the correct event handler. More... | |
virtual ListenerStatus | GetListenerStatus (object listener, uint flags) |
Returns ListenerStatus.Active if listener is not null , ListenerStatus.Dead otherwise. Override this method to provide custom listener status. More... | |
bool | InvokeMeta (int metaIndex, IDispatchable e) |
Invokes handlers for a specific dispatchable. More... | |
bool | InvokeMeta< TDispatchable > (TDispatchable e) |
Invokes handlers for a specific dispatchable. More... | |
DispatcherSubscription | SubscribeInternal< TDispatchable > (object listener, DispatchableHandler< TDispatchable > handler, DispatchableFilter filter, uint flags) |
Creates a subscription. Subscriptions can be cancelled manually by calling UnsubscribeHandler<TDispatchable>(DispatchableHandler<TDispatchable>). More... | |
IDisposable | SubscribeManualInternal< TDispatchable > (object listener, DispatchableHandler< TDispatchable > handler, DispatchableFilter filter, bool once) |
Creates a subscription that is active until the caller disposes the result. More... | |
bool | UnsubscribeInternal< TDispatchable > (object listener, DispatchableHandler< TDispatchable > handler) |
Unsubscribes a listener from a handler. More... | |
Properties | |
bool | IsEmpty [get] |
Returns true if there are no active subscriptions. More... | |
DispatcherBase | Next [get, set] |
A reference to the next dispatcher in the chain. If set, the dispatcher will forward events to the next dispatcher after. More... | |
Base class for dispatchers. Dispatchers are used to publish and subscribe to events represented by IDispatchable objects.
|
strong |
|
inlineprotected |
Initializes the dispatcher with a mapping of types to ids. The ids are used to quickly find the correct event handler.
typeToIndex | Type-to-index mapping |
>
|
inline |
Returns the index of a specific dispatchable type. Throws in case the type is not registered.
TDispatchable |
TDispatchable | : | IDispatchable |
|
inline |
Creates a subscription. Subscriptions can be cancelled manually by calling UnsubscribeHandler<TDispatchable>(DispatchableHandler<TDispatchable>), but as long as the derived class overrides GetListenerStatus(object, uint) and calls DispatcherBase.RemoveDeadListeners() periodically, the dispatcher will be free of memory leaks.
TDispatchable |
listener | An object listening. A class extending this one decided whether a listener is alive or not in GetListenerStatus(object, uint) |
handler | Actual event handler. |
once | Call handler only once. |
flags | Additional flags. Deriving classes can define their own flags starting with 1 << DispatcherHandlerFlags.CustomFlagsShift and analyze them in method overrides. |
filter | Optional event filter. If returns false , handler will not be invoked. |
TDispatchable | : | IDispatchable |
|
inline |
Cancel a specific subscription.
|
inline |
Cancel every subscription using a handler.
TDispatchable |
handler |
TDispatchable | : | IDispatchable |
|
inline |
Cancel every specific subscription type for a listener.
TDispatchable |
listener |
TDispatchable | : | IDispatchable |
|
inline |
Creates a subscription that is active until the caller disposes the result.
TDispatchable |
handler | |
once | |
filter |
TDispatchable | : | IDispatchable |
|
inline |
Creates a subscription that is active until the caller disposes the result or calls Unsubscribe.
TDispatchable |
listener | |
handler | |
once | |
filter |
TDispatchable | : | IDispatchable |
|
inline |
Removes all subscriptions.
|
inline |
Removes every subscription for which GetListenerStatus returns ListenerStatus.Dead
|
inline |
Cancel every subscription for a listener.
listener |
|
inlineprotectedvirtual |
Returns ListenerStatus.Active if listener is not null
, ListenerStatus.Dead otherwise. Override this method to provide custom listener status.
listener | |
flags |
Reimplemented in Quantum.QuantumUnityCallbackDispatcher, and Quantum.QuantumUnityEventDispatcher.
|
inlineprotected |
Invokes handlers for a specific dispatchable.
e |
TDispatchable |
TDispatchable | : | IDispatchable |
|
inlineprotected |
Invokes handlers for a specific dispatchable.
metaIndex | |
e |
|
inlineprotected |
Creates a subscription. Subscriptions can be cancelled manually by calling UnsubscribeHandler<TDispatchable>(DispatchableHandler<TDispatchable>).
listener | |
handler | |
filter | |
flags |
TDispatchable |
ArgumentNullException |
TDispatchable | : | IDispatchable |
|
inlineprotected |
Creates a subscription that is active until the caller disposes the result.
TDispatchable |
listener | |
handler | |
filter | |
once |
TDispatchable | : | IDispatchable |
|
inlineprotected |
Unsubscribes a listener from a handler.
listener | |
handler |
TDispatchable |
TDispatchable | : | IDispatchable |
|
getset |
A reference to the next dispatcher in the chain. If set, the dispatcher will forward events to the next dispatcher after.
|
get |
Returns true
if there are no active subscriptions.