Photon Quantum 3.0.0

Classes | Public Types | Public Member Functions | Protected Member Functions | Properties | List of all members
Quantum.DispatcherBase Class Reference

Base class for dispatchers. Dispatchers are used to publish and subscribe to events represented by IDispatchable objects. More...

Inheritance diagram for Quantum.DispatcherBase:
Quantum.CallbackDispatcher Quantum.EventDispatcher Quantum.QuantumUnityCallbackDispatcher Quantum.QuantumUnityEventDispatcher

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...
 

Detailed Description

Base class for dispatchers. Dispatchers are used to publish and subscribe to events represented by IDispatchable objects.

Member Enumeration Documentation

◆ ListenerStatus

Status of a listener. Used to determine if a listener is still alive.

Enumerator
Active 

Listener is active and should be called.

Inactive 

Listener is inactive and should not be called, but not cleaned up.

Dead 

Listener is dead and should be cleaned up.

Constructor & Destructor Documentation

◆ DispatcherBase()

Quantum.DispatcherBase.DispatcherBase ( Dictionary< Type, Int32 >  typeToIndex)
inlineprotected

Initializes the dispatcher with a mapping of types to ids. The ids are used to quickly find the correct event handler.

Parameters
typeToIndexType-to-index mapping

>

Member Function Documentation

◆ GetIndex< TDispatchable >()

int Quantum.DispatcherBase.GetIndex< TDispatchable > ( )
inline

Returns the index of a specific dispatchable type. Throws in case the type is not registered.

Template Parameters
TDispatchable
Returns
Type Constraints
TDispatchable :IDispatchable 

◆ Subscribe< TDispatchable >()

DispatcherSubscription Quantum.DispatcherBase.Subscribe< TDispatchable > ( object  listener,
DispatchableHandler< TDispatchable >  handler,
bool  once = false,
uint  flags = 0,
DispatchableFilter  filter = null 
)
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.

Template Parameters
TDispatchable
Parameters
listenerAn object listening. A class extending this one decided whether a listener is alive or not in GetListenerStatus(object, uint)
handlerActual event handler.
onceCall handler only once.
flagsAdditional flags. Deriving classes can define their own flags starting with 1 << DispatcherHandlerFlags.CustomFlagsShift and analyze them in method overrides.
filterOptional event filter. If returns false, handler will not be invoked.
Returns
Subscription that can be stored and used in Unsubscribe
Type Constraints
TDispatchable :IDispatchable 

◆ Unsubscribe()

bool Quantum.DispatcherBase.Unsubscribe ( DispatcherSubscription  subscription)
inline

Cancel a specific subscription.

Returns

◆ UnsubscribeHandler< TDispatchable >()

bool Quantum.DispatcherBase.UnsubscribeHandler< TDispatchable > ( DispatchableHandler< TDispatchable >  handler)
inline

Cancel every subscription using a handler.

Template Parameters
TDispatchable
Parameters
handler
Returns
Type Constraints
TDispatchable :IDispatchable 

◆ UnsubscribeListener< TDispatchable >()

bool Quantum.DispatcherBase.UnsubscribeListener< TDispatchable > ( object  listener)
inline

Cancel every specific subscription type for a listener.

Template Parameters
TDispatchable
Parameters
listener
Returns
Type Constraints
TDispatchable :IDispatchable 

◆ SubscribeManual< TDispatchable >() [1/2]

IDisposable Quantum.DispatcherBase.SubscribeManual< TDispatchable > ( DispatchableHandler< TDispatchable >  handler,
bool  once = false,
DispatchableFilter  filter = null 
)
inline

Creates a subscription that is active until the caller disposes the result.

Template Parameters
TDispatchable
Parameters
handler
once
filter
Returns
Type Constraints
TDispatchable :IDispatchable 

◆ SubscribeManual< TDispatchable >() [2/2]

IDisposable Quantum.DispatcherBase.SubscribeManual< TDispatchable > ( object  listener,
DispatchableHandler< TDispatchable >  handler,
bool  once = false,
DispatchableFilter  filter = null 
)
inline

Creates a subscription that is active until the caller disposes the result or calls Unsubscribe.

Template Parameters
TDispatchable
Parameters
listener
handler
once
filter
Returns
Type Constraints
TDispatchable :IDispatchable 

◆ Clear()

void Quantum.DispatcherBase.Clear ( )
inline

Removes all subscriptions.

◆ RemoveDeadListeners()

void Quantum.DispatcherBase.RemoveDeadListeners ( )
inline

Removes every subscription for which GetListenerStatus returns ListenerStatus.Dead

◆ UnsubscribeListener()

bool Quantum.DispatcherBase.UnsubscribeListener ( object  listener)
inline

Cancel every subscription for a listener.

Parameters
listener
Returns

◆ GetListenerStatus()

virtual ListenerStatus Quantum.DispatcherBase.GetListenerStatus ( object  listener,
uint  flags 
)
inlineprotectedvirtual

Returns ListenerStatus.Active if listener is not null, ListenerStatus.Dead otherwise. Override this method to provide custom listener status.

Parameters
listener
flags
Returns

Reimplemented in Quantum.QuantumUnityCallbackDispatcher, and Quantum.QuantumUnityEventDispatcher.

◆ InvokeMeta< TDispatchable >()

bool Quantum.DispatcherBase.InvokeMeta< TDispatchable > ( TDispatchable  e)
inlineprotected

Invokes handlers for a specific dispatchable.

Parameters
e
Template Parameters
TDispatchable
Returns
Type Constraints
TDispatchable :IDispatchable 

◆ InvokeMeta()

bool Quantum.DispatcherBase.InvokeMeta ( int  metaIndex,
IDispatchable  e 
)
inlineprotected

Invokes handlers for a specific dispatchable.

Parameters
metaIndex
e
Returns

◆ SubscribeInternal< TDispatchable >()

DispatcherSubscription Quantum.DispatcherBase.SubscribeInternal< TDispatchable > ( object  listener,
DispatchableHandler< TDispatchable >  handler,
DispatchableFilter  filter,
uint  flags 
)
inlineprotected

Creates a subscription. Subscriptions can be cancelled manually by calling UnsubscribeHandler<TDispatchable>(DispatchableHandler<TDispatchable>).

Parameters
listener
handler
filter
flags
Template Parameters
TDispatchable
Returns
Exceptions
ArgumentNullException
Type Constraints
TDispatchable :IDispatchable 

◆ SubscribeManualInternal< TDispatchable >()

IDisposable Quantum.DispatcherBase.SubscribeManualInternal< TDispatchable > ( object  listener,
DispatchableHandler< TDispatchable >  handler,
DispatchableFilter  filter,
bool  once 
)
inlineprotected

Creates a subscription that is active until the caller disposes the result.

Template Parameters
TDispatchable
Parameters
listener
handler
filter
once
Returns
Type Constraints
TDispatchable :IDispatchable 

◆ UnsubscribeInternal< TDispatchable >()

bool Quantum.DispatcherBase.UnsubscribeInternal< TDispatchable > ( object  listener,
DispatchableHandler< TDispatchable >  handler 
)
inlineprotected

Unsubscribes a listener from a handler.

Parameters
listener
handler
Template Parameters
TDispatchable
Returns
Type Constraints
TDispatchable :IDispatchable 

Property Documentation

◆ Next

DispatcherBase Quantum.DispatcherBase.Next
getset

A reference to the next dispatcher in the chain. If set, the dispatcher will forward events to the next dispatcher after.

◆ IsEmpty

bool Quantum.DispatcherBase.IsEmpty
get

Returns true if there are no active subscriptions.