EventManager

consoledoc.h

The EventManager class is a wrapper for the standard messaging system.

More...

Public Attributes

string

List of events currently waiting.

Public Functions

void

Print all registered events to the console.

void
dumpSubscribers(string listenerName)

Print all subscribers to an event to the console.

bool
isRegisteredEvent(string evt)

Check if an event is registered or not.

bool
postEvent(string evt, string data)

~Trigger an event.

bool
registerEvent(string evt)

Register an event with the event manager.

void
remove(string listenerName, string evt)

Remove a listener from an event.

void
removeAll(string listenerName)

Remove a listener from all events.

bool
subscribe(string listenerName, string evt, string callback)

Subscribe a listener to an event.

void
unregisterEvent(string evt)

Remove an event from the EventManager.

Detailed Description

The EventManager class is a wrapper for the standard messaging system.

It provides functionality for management of event queues, events, and subscriptions. Creating an EventManager is as simple as calling new EventManager and specifying a queue name.

// Create the EventManager.
$MyEventManager = new EventManager() { queue = "MyEventManager"; };

// Create an event.
$MyEventManager.registerEvent( "SomeCoolEvent" );

// Create a listener and subscribe.
$MyListener = new ScriptMsgListener() { class = MyListener; };
$MyEventManager.subscribe( $MyListener, "SomeCoolEvent" );

function MyListener::onSomeCoolEvent( %this, %data )
{
     echo( "onSomeCoolEvent Triggered" );
}

// Trigger the event.
$MyEventManager.postEvent( "SomeCoolEvent", "Data" );

Public Attributes

string queue 

List of events currently waiting.

Public Functions

dumpEvents()

Print all registered events to the console.

dumpSubscribers(string listenerName)

Print all subscribers to an event to the console.

Parameters:

event

The event whose subscribers are to be printed. If this parameter isn't specified, all events will be dumped.

isRegisteredEvent(string evt)

Check if an event is registered or not.

Parameters:

event

The event to check.

return:

Whether or not the event exists.

postEvent(string evt, string data)

~Trigger an event.

Parameters:

event

The event to trigger.

data

The data associated with the event.

return:

Whether or not the event was dispatched successfully.

registerEvent(string evt)

Register an event with the event manager.

Parameters:

event

The event to register.

return:

Whether or not the event was registered successfully.

remove(string listenerName, string evt)

Remove a listener from an event.

Parameters:

listener

The listener to remove.

event

The event to be removed from.

removeAll(string listenerName)

Remove a listener from all events.

Parameters:

listener

The listener to remove.

subscribe(string listenerName, string evt, string callback)

Subscribe a listener to an event.

Parameters:

listener

The listener to subscribe.

event

The event to subscribe to.

callback

Optional method name to receive the event notification. If this is not specified, "on[event]" will be used.

return:

Whether or not the subscription was successful.

unregisterEvent(string evt)

Remove an event from the EventManager.

Parameters:

event

The event to remove.