|
Script accessible version of Dispatcher::IMessageListener. Often used in conjunction with EventManager. More...
Public Member Functions | |
Callbacks | |
void | onAdd () |
Script callback when a listener is first created and registered. | |
void | onAddToQueue (string queue) |
Callback for when the listener is added to a queue. | |
bool | onMessageObjectReceived (string queue, Message msg) |
Called when a message object (not just the message data) is passed to a listener. | |
bool | onMessageReceived (string queue, string event, string data) |
Called when the listener has received a message. | |
void | onRemove () |
Script callback when a listener is deleted. | |
void | onRemoveFromQueue (string queue) |
Callback for when the listener is removed from a queue. |
Script accessible version of Dispatcher::IMessageListener. Often used in conjunction with EventManager.
The main use of ScriptMsgListener is to allow script to listen formessages. You can subclass ScriptMsgListener in script to receivethe Dispatcher::IMessageListener callbacks.
Alternatively, you can derive from it in C++ instead of SimObject toget an object that implements Dispatcher::IMessageListener with scriptcallbacks. If you need to derive from something other then SimObject,then you will need to implement the Dispatcher::IMessageListenerinterface yourself.
// 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" );
void ScriptMsgListener::onAdd | ( | ) |
Script callback when a listener is first created and registered.
function ScriptMsgListener::onAdd(%this) { // Perform on add code here }
void ScriptMsgListener::onAddToQueue | ( | string | queue | ) |
Callback for when the listener is added to a queue.
The default implementation of onAddToQueue() and onRemoveFromQueue() provide tracking of the queues this listener is added to through the mQueues member. Overrides of onAddToQueue() or onRemoveFromQueue() should ensure they call the parent implementation in any overrides.
queue | The name of the queue that the listener added to |
bool ScriptMsgListener::onMessageObjectReceived | ( | string | queue, | |
Message | msg | |||
) |
Called when a message object (not just the message data) is passed to a listener.
queue | The name of the queue the message was dispatched to | |
msg | The message object |
bool ScriptMsgListener::onMessageReceived | ( | string | queue, | |
string | event, | |||
string | data | |||
) |
Called when the listener has received a message.
queue | The name of the queue the message was dispatched to | |
event | The name of the event (function) that was triggered | |
data | The data (parameters) for the message |
void ScriptMsgListener::onRemove | ( | ) |
Script callback when a listener is deleted.
function ScriptMsgListener::onRemove(%this) { // Perform on remove code here }
void ScriptMsgListener::onRemoveFromQueue | ( | string | queue | ) |
Callback for when the listener is removed from a queue.
The default implementation of onAddToQueue() and onRemoveFromQueue() provide tracking of the queues this listener is added to through the mQueues member. Overrides of onAddToQueue() or onRemoveFromQueue() should ensure they call the parent implementation in any overrides.
queue | The name of the queue that the listener was removed from |