EventManager
Engine/source/util/messaging/eventManager.h
The EventManager class is a wrapper for the standard messaging system.
Properties
setMessageQueue(const char * queue)
Registers the message queue and listener with the messaging system.
Event Management
bool
isRegisteredEvent(const char * eventName)
Checks if an event is registered.
bool
registerEvent(const char * eventName)
Registers an event.
unregisterEvent(const char * eventName)
Removes an event.
Removes all events.
bool
Debug Output
Prints all registered events to the console.
Prints all subscribers to the console.
dumpSubscribers(const char * event)
Prints subscribers to a specific event to the console.
Event Manager Tracking
addEventManager(EventManager * em)
Adds an EventManager.
Removes an EventManager.
getEventManager(const char * name)
Retrieves an EventManager.
Prints all the EventManagers to the console.
Private Types
Parent
Private Attributes
Registered events.
The event listener. Listens for all events and dispatches them to the appropriate subscribers.
The name of the message queue.
Private Static Attributes
Vector< EventManager * >
List of all EventManagers.
Private Static Functions
bool
_setMessageQueue(void * obj, const char * index, const char * data)
Sets the message queue.
Public Functions
Public Static Functions
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 EventManagerand specifying a queue name.
Example Usage:
// 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" );
Properties
getMessageQueue()
setMessageQueue(const char * queue)
Registers the message queue and listener with the messaging system.
Parameters:
queue | The name of the queue. Set to "" to destroy the queue. |
Event Management
isRegisteredEvent(const char * eventName)
Checks if an event is registered.
Determines whether or not an event is registered with the EventManager.
Parameters:
event | the event to check. |
registerEvent(const char * eventName)
Registers an event.
Register an event with the EventManager.
Parameters:
event | The event to register. |
Whether or not the event was successfully registered.
unregisterEvent(const char * eventName)
Removes an event.
Removes an event from the EventManager.
Parameters:
event | The event to remove. |
unregisterAllEvents()
Removes all events.
Removes all events from the EventManager.
postEvent(const char * eventName, const char * data)
Triggers an event.
Post an event to the EventManager's queue.
Parameters:
event | The event to post. |
data | Various data associated with the event. |
Whether or not the message was dispatched successfully.
subscribe(SimObject * callbackObj, const char * event, const char * callback)
Adds a subscription to an event.
Subscribe a listener to an event.
Parameters:
listener | The listener to subscribe. |
event | The event to subscribe to. |
callback | Optional callback name to be called when the event is triggered. |
Whether or not the subscription was successful.
remove(SimObject * cbObj, const char * event)
Remove a subscriber from an event.
remove a listener from an event.
Parameters:
listener | The listener to remove from an event callback list. |
event | The event to remove the listener from. |
removeAll(SimObject * cbObj)
Debug Output
dumpEvents()
Prints all registered events to the console.
Print all registered events to the console.
dumpSubscribers()
Prints all subscribers to the console.
Print all registered events and their subscribers to the console.
dumpSubscribers(const char * event)
Prints subscribers to a specific event to the console.
Print the subscribers to an event.
Parameters:
event | The event whose subscribers are to be printed. |
Event Manager Tracking
addEventManager(EventManager * em)
Adds an EventManager.
removeEventManager(EventManager * em)
Removes an EventManager.
getEventManager(const char * name)
Retrieves an EventManager.
printEventManagers()
Prints all the EventManagers to the console.
Private Types
typedef SimObject Parent
Private Attributes
Vector< StringTableEntry > mEvents
Registered events.
EventManagerListener mListener
The event listener. Listens for all events and dispatches them to the appropriate subscribers.
StringTableEntry mQueue
The name of the message queue.
Private Static Attributes
Vector< EventManager * > smEventManagers
List of all EventManagers.
Private Static Functions
_setMessageQueue(void * obj, const char * index, const char * data)
Sets the message queue.