Joutsen  v0.4.1
Public Member Functions | List of all members
Joutsen.System.Events.EventBus Interface Reference

An interface describing an event bus that can be used to register to events of other objects or listen to events of other objects without ever holding a reference to them. More...

Public Member Functions

void RegisterReceiver< TPayload > (String name, Action< string, TPayload > receiver)
 Removes a listener for an event. More...
 
void RemoveReceiver< TPayload > (String name, Action< string, TPayload > receiver)
 Removes a listener for an event. More...
 
void SendEvent< TPayload > (String name, TPayload payload)
 Fires the event with the given payload. More...
 
Event< TPayload > GetEvent< TPayload > (String name)
 Fetches the event with the given name and TPayload from the bus. More...
 
void AddEvent< TPayload > (Event< TPayload > newEvent)
 Adds a new event to the bus for other objects listen for. More...
 
Event< TPayload > AddEvent< TPayload > (String newEventName)
 Creates a new Framework.System.Events.Event and adds it to the bus. More...
 
Event< TPayload > TryAddEvent< TPayload > (Event< TPayload > newEvent)
 Adds a new event if no event with the same name and type of payload is registered yet. More...
 
Event< TPayload > TryAddEvent< TPayload > (String newEventName)
 Creates and adds a new event if no event with the same name and type of payload is registered yet. More...
 
bool RemoveEvent< TPayload > (Event< TPayload > existingEvent)
 Removes an event from the bus. More...
 
Event< TPayload > RemoveEvent< TPayload > (String name)
 Removes an event from the bus. More...
 
bool CanHandleEvent< TPayload > (Event< TPayload > existingEvent)
 Checks if an event with the same name and payload is registered on the bus. More...
 
bool CanHandleEvent< TPayload > (String eventName)
 Checks if an event with the given name and payload is registered on the bus. More...
 

Detailed Description

An interface describing an event bus that can be used to register to events of other objects or listen to events of other objects without ever holding a reference to them.

Since
0.2.0

Member Function Documentation

◆ AddEvent< TPayload >() [1/2]

void Joutsen.System.Events.EventBus.AddEvent< TPayload > ( Event< TPayload >  newEvent)

Adds a new event to the bus for other objects listen for.

Template Parameters
TPayloadthe event's payload
Parameters
newEventthe new event that is added to bus
Remarks
Events need to be unique in name and payload.

Implemented in Joutsen.System.Events.DefaultEventBus.

◆ AddEvent< TPayload >() [2/2]

Event<TPayload> Joutsen.System.Events.EventBus.AddEvent< TPayload > ( String  newEventName)

Creates a new Framework.System.Events.Event and adds it to the bus.

Template Parameters
TPayloadthe event's payload
Parameters
newEventNamethe name of the new event
Returns
the new event
Remarks
Events need to be unique in name and payload.

Implemented in Joutsen.System.Events.DefaultEventBus.

◆ CanHandleEvent< TPayload >() [1/2]

bool Joutsen.System.Events.EventBus.CanHandleEvent< TPayload > ( Event< TPayload >  existingEvent)

Checks if an event with the same name and payload is registered on the bus.

Template Parameters
TPayloadthe event's payload
Parameters
existingEventthe existing event to look for on the bus
Returns
true if an event with the same name and payload is registered on the bus, otherwise false

Implemented in Joutsen.System.Events.DefaultEventBus.

◆ CanHandleEvent< TPayload >() [2/2]

bool Joutsen.System.Events.EventBus.CanHandleEvent< TPayload > ( String  eventName)

Checks if an event with the given name and payload is registered on the bus.

Template Parameters
TPayloadthe event's payload
Parameters
eventNamethe name of the event
Returns
true if an event with the given name and payload is registered on the bus, otherwise false

Implemented in Joutsen.System.Events.DefaultEventBus.

◆ GetEvent< TPayload >()

Event<TPayload> Joutsen.System.Events.EventBus.GetEvent< TPayload > ( String  name)

Fetches the event with the given name and TPayload from the bus.

Template Parameters
TPayloadthe event's payload
Parameters
namethe name of the event
Returns
the event with the given name and TPayload

◆ RegisterReceiver< TPayload >()

void Joutsen.System.Events.EventBus.RegisterReceiver< TPayload > ( String  name,
Action< string, TPayload >  receiver 
)

Removes a listener for an event.

Template Parameters
TPayloadthe event's payload
Parameters
namethe name of the event
receiverthe listener that is to be removed

◆ RemoveEvent< TPayload >() [1/2]

bool Joutsen.System.Events.EventBus.RemoveEvent< TPayload > ( Event< TPayload >  existingEvent)

Removes an event from the bus.

Template Parameters
TPayloadthe event's payload
Parameters
existingEventthe event to remove
Returns
true if the event was found on the bus and was removed, otherwise false

Implemented in Joutsen.System.Events.DefaultEventBus.

◆ RemoveEvent< TPayload >() [2/2]

Event<TPayload> Joutsen.System.Events.EventBus.RemoveEvent< TPayload > ( String  name)

Removes an event from the bus.

Template Parameters
TPayloadthe event's payload
Parameters
namethe name of the event
Returns
the removed event

Implemented in Joutsen.System.Events.DefaultEventBus.

◆ RemoveReceiver< TPayload >()

void Joutsen.System.Events.EventBus.RemoveReceiver< TPayload > ( String  name,
Action< string, TPayload >  receiver 
)

Removes a listener for an event.

Template Parameters
TPayloadthe event's payload
Parameters
namethe name of the event
receiverthe listener that is to be removed

◆ SendEvent< TPayload >()

void Joutsen.System.Events.EventBus.SendEvent< TPayload > ( String  name,
TPayload  payload 
)

Fires the event with the given payload.

Template Parameters
TPayloadthe type of the event's payload
Parameters
namethe name of the event
payloadthe payload of the event

◆ TryAddEvent< TPayload >() [1/2]

Event<TPayload> Joutsen.System.Events.EventBus.TryAddEvent< TPayload > ( String  newEventName)

Creates and adds a new event if no event with the same name and type of payload is registered yet.

Template Parameters
TPayloadthe type of the event's payload
Parameters
newEventNamethe name of the event
Returns
the added event if no event with the same name and type of payload was already registered, otherwise the already registered event

Implemented in Joutsen.System.Events.DefaultEventBus.

◆ TryAddEvent< TPayload >() [2/2]

Event<TPayload> Joutsen.System.Events.EventBus.TryAddEvent< TPayload > ( Event< TPayload >  newEvent)

Adds a new event if no event with the same name and type of payload is registered yet.

Template Parameters
TPayloadthe type of the event's payload
Parameters
newEventthe new event
Returns
the added event if no event with the same name and type of payload was already registered, otherwise the already registered event

Implemented in Joutsen.System.Events.DefaultEventBus.