Torque3D Documentation / _generateds / scriptMsgListener.cpp

scriptMsgListener.cpp

Engine/source/util/messaging/scriptMsgListener.cpp

More...

Public Functions

ConsoleDoc("@class <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">ScriptMsgListener\n</a>" "@brief Script accessible version of Dispatcher::IMessageListener. Often used in conjunction with <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">EventManager\n\n</a>" "The <a href="/coding/file/x86unixmain_8cpp/#x86unixmain_8cpp_1a217dbf8b442f20279ea00b898af96f52">main</a> use of <a href="/coding/class/classscriptmsglistener/">ScriptMsgListener</a> is <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> allow script <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> listen <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a>" "messages. You can subclass <a href="/coding/class/classscriptmsglistener/">ScriptMsgListener</a> in script <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> receive" "the <a href="/coding/class/classdispatcher_1_1imessagelistener/">Dispatcher::IMessageListener</a> <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">callbacks.\n\n</a>" " Alternatively, you can derive from it in C++instead of <a href="/coding/class/classsimobject/">SimObject</a> <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a>" "get an object that implements <a href="/coding/class/classdispatcher_1_1imessagelistener/">Dispatcher::IMessageListener</a> with script" "callbacks. If you need <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> derive from something other then SimObject)
IMPLEMENT_CALLBACK(ScriptMsgListener , onAdd , void , () , () , "Script callback when <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> listener is first created and <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">registered.\n\n</a>" "@<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">tsexample\n</a>" "function <a href="/coding/class/classscriptmsglistener/#classscriptmsglistener_1ae4831f6416b20c8915c41a0a46227d60">ScriptMsgListener::onAdd</a>(%this)\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "{\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "	// Perform on add code <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">here\n</a>" "}\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "@<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">endtsexample\n\n</a>" )
IMPLEMENT_CALLBACK(ScriptMsgListener , onAddToQueue , void , (const char *queue) , (queue) , "@brief <a href="/coding/file/sqliteobject_8cpp/#sqliteobject_8cpp_1a858cd1af41f1e4420d94dfe65b6a56a4">Callback</a> <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> when the listener is added <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">queue\n\n</a>" "The default implementation of onAddToQueue() and onRemoveFromQueue() " "provide tracking of the queues this listener is added <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> through the " "mQueues member. Overrides of onAddToQueue() or onRemoveFromQueue() " "should ensure they call the parent implementation in any <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">overrides.\n</a>" "@param queue The name of the queue that the listener added <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">to\n</a>" "@see onRemoveFromQueue()" )
IMPLEMENT_CALLBACK(ScriptMsgListener , onMessageObjectReceived , bool , (const char *queue, Message *msg) , (queue, msg) , "Called when <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> message object (not just the message data) is passed <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">listener.\n</a>" "@param queue The name of the queue the message was dispatched <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">to\n</a>" "@param msg The message <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">object\n</a>" "@return false <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> prevent other listeners receiving this message, true <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">otherwise\n</a>" " @see <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">Message\n</a>" " @see onMessageReceived" )
IMPLEMENT_CALLBACK(ScriptMsgListener , onMessageReceived , bool , (const char *queue, const char *event, const char *data) , (queue, event, data) , "Called when the listener has received <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">message.\n</a>" "@param queue The name of the queue the message was dispatched <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">to\n</a>" "@param event The name of the event (function) that was <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">triggered\n</a>" "@param data The data (parameters) <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> the <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">message\n\n</a>" "@return false <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> prevent other listeners receiving this message, true <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">otherwise\n</a>" )
IMPLEMENT_CALLBACK(ScriptMsgListener , onRemove , void , () , () , "Script callback when <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> listener is <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">deleted.\n\n</a>" "@<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">tsexample\n</a>" "function <a href="/coding/class/classscriptmsglistener/#classscriptmsglistener_1a436be729c1ca5700f1829421950f82b9">ScriptMsgListener::onRemove</a>(%this)\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "{\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "	// Perform on remove code <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">here\n</a>" "}\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "@<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">endtsexample\n\n</a>" )
IMPLEMENT_CALLBACK(ScriptMsgListener , onRemoveFromQueue , void , (const char *queue) , (queue) , "@brief <a href="/coding/file/sqliteobject_8cpp/#sqliteobject_8cpp_1a858cd1af41f1e4420d94dfe65b6a56a4">Callback</a> <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> when the listener is removed from <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">queue\n\n</a>" "The default implementation of onAddToQueue() and onRemoveFromQueue() " "provide tracking of the queues this listener is added <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> through the " "mQueues member. Overrides of onAddToQueue() or onRemoveFromQueue() " "should ensure they call the parent implementation in any <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">overrides.\n</a>" "@param queue The name of the queue that the listener was removed <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">from\n</a>" "@see onAddToQueue()" )

Callback for when the listener is removed from a queue.

Detailed Description

Public Functions

ConsoleDoc("@class <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">ScriptMsgListener\n</a>" "@brief Script accessible version of Dispatcher::IMessageListener. Often used in conjunction with <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">EventManager\n\n</a>" "The <a href="/coding/file/x86unixmain_8cpp/#x86unixmain_8cpp_1a217dbf8b442f20279ea00b898af96f52">main</a> use of <a href="/coding/class/classscriptmsglistener/">ScriptMsgListener</a> is <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> allow script <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> listen <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a>" "messages. You can subclass <a href="/coding/class/classscriptmsglistener/">ScriptMsgListener</a> in script <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> receive" "the <a href="/coding/class/classdispatcher_1_1imessagelistener/">Dispatcher::IMessageListener</a> <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">callbacks.\n\n</a>" " Alternatively, you can derive from it in C++instead of <a href="/coding/class/classsimobject/">SimObject</a> <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a>" "get an object that implements <a href="/coding/class/classdispatcher_1_1imessagelistener/">Dispatcher::IMessageListener</a> with script" "callbacks. If you need <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> derive from something other then SimObject)

IMPLEMENT_CALLBACK(ScriptMsgListener , onAdd , void , () , () , "Script callback when <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> listener is first created and <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">registered.\n\n</a>" "@<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">tsexample\n</a>" "function <a href="/coding/class/classscriptmsglistener/#classscriptmsglistener_1ae4831f6416b20c8915c41a0a46227d60">ScriptMsgListener::onAdd</a>(%this)\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "{\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "	// Perform on add code <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">here\n</a>" "}\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "@<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">endtsexample\n\n</a>" )

IMPLEMENT_CALLBACK(ScriptMsgListener , onAddToQueue , void , (const char *queue) , (queue) , "@brief <a href="/coding/file/sqliteobject_8cpp/#sqliteobject_8cpp_1a858cd1af41f1e4420d94dfe65b6a56a4">Callback</a> <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> when the listener is added <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">queue\n\n</a>" "The default implementation of onAddToQueue() and onRemoveFromQueue() " "provide tracking of the queues this listener is added <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> through the " "mQueues member. Overrides of onAddToQueue() or onRemoveFromQueue() " "should ensure they call the parent implementation in any <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">overrides.\n</a>" "@param queue The name of the queue that the listener added <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">to\n</a>" "@see onRemoveFromQueue()" )

IMPLEMENT_CALLBACK(ScriptMsgListener , onMessageObjectReceived , bool , (const char *queue, Message *msg) , (queue, msg) , "Called when <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> message object (not just the message data) is passed <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">listener.\n</a>" "@param queue The name of the queue the message was dispatched <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">to\n</a>" "@param msg The message <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">object\n</a>" "@return false <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> prevent other listeners receiving this message, true <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">otherwise\n</a>" " @see <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">Message\n</a>" " @see onMessageReceived" )

IMPLEMENT_CALLBACK(ScriptMsgListener , onMessageReceived , bool , (const char *queue, const char *event, const char *data) , (queue, event, data) , "Called when the listener has received <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">message.\n</a>" "@param queue The name of the queue the message was dispatched <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">to\n</a>" "@param event The name of the event (function) that was <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">triggered\n</a>" "@param data The data (parameters) <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> the <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">message\n\n</a>" "@return false <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> prevent other listeners receiving this message, true <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">otherwise\n</a>" )

IMPLEMENT_CALLBACK(ScriptMsgListener , onRemove , void , () , () , "Script callback when <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> listener is <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">deleted.\n\n</a>" "@<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">tsexample\n</a>" "function <a href="/coding/class/classscriptmsglistener/#classscriptmsglistener_1a436be729c1ca5700f1829421950f82b9">ScriptMsgListener::onRemove</a>(%this)\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "{\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "	// Perform on remove code <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">here\n</a>" "}\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "@<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">endtsexample\n\n</a>" )

IMPLEMENT_CALLBACK(ScriptMsgListener , onRemoveFromQueue , void , (const char *queue) , (queue) , "@brief <a href="/coding/file/sqliteobject_8cpp/#sqliteobject_8cpp_1a858cd1af41f1e4420d94dfe65b6a56a4">Callback</a> <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> when the listener is removed from <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">queue\n\n</a>" "The default implementation of onAddToQueue() and onRemoveFromQueue() " "provide tracking of the queues this listener is added <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> through the " "mQueues member. Overrides of onAddToQueue() or onRemoveFromQueue() " "should ensure they call the parent implementation in any <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">overrides.\n</a>" "@param queue The name of the queue that the listener was removed <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">from\n</a>" "@see onAddToQueue()" )

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.

Parameters:

queue

The name of the queue the listener was removed from

see:

onAddToQueue()

IMPLEMENT_CONOBJECT(ScriptMsgListener )

  1
  2//-----------------------------------------------------------------------------
  3// Copyright (c) 2012 GarageGames, LLC
  4//
  5// Permission is hereby granted, free of charge, to any person obtaining a copy
  6// of this software and associated documentation files (the "Software"), to
  7// deal in the Software without restriction, including without limitation the
  8// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  9// sell copies of the Software, and to permit persons to whom the Software is
 10// furnished to do so, subject to the following conditions:
 11//
 12// The above copyright notice and this permission notice shall be included in
 13// all copies or substantial portions of the Software.
 14//
 15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 18// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
 21// IN THE SOFTWARE.
 22//-----------------------------------------------------------------------------
 23
 24#include "platform/platform.h"
 25#include "util/messaging/scriptMsgListener.h"
 26
 27#include "console/consoleTypes.h"
 28
 29#include "console/engineAPI.h"
 30
 31//-----------------------------------------------------------------------------
 32// Constructor
 33//-----------------------------------------------------------------------------
 34
 35ScriptMsgListener::ScriptMsgListener()
 36{
 37}
 38
 39IMPLEMENT_CONOBJECT(ScriptMsgListener);
 40
 41ConsoleDoc("@class ScriptMsgListener\n"
 42   "@brief Script accessible version of Dispatcher::IMessageListener. Often used in conjunction with EventManager\n\n"
 43
 44   "The main use of ScriptMsgListener is to allow script to listen for"
 45   "messages. You can subclass ScriptMsgListener in script to receive"
 46   "the Dispatcher::IMessageListener callbacks.\n\n"
 47
 48   "Alternatively, you can derive from it in C++ instead of SimObject to"
 49   "get an object that implements Dispatcher::IMessageListener with script"
 50   "callbacks. If you need to derive from something other then SimObject,"
 51   "then you will need to implement the Dispatcher::IMessageListener"
 52   "interface yourself.\n\n"
 53
 54   "@tsexample\n"
 55   "// Create the EventManager.\n"
 56   "$MyEventManager = new EventManager() { queue = \"MyEventManager\"; };\n\n"
 57   "// Create an event.\n"
 58   "$MyEventManager.registerEvent( \"SomeCoolEvent\" );\n\n"
 59   "// Create a listener and subscribe.\n"
 60   "$MyListener = new ScriptMsgListener() { class = MyListener; };\n"
 61   "$MyEventManager.subscribe( $MyListener, \"SomeCoolEvent\" );\n\n"
 62   "function MyListener::onSomeCoolEvent( %this, %data )\n"
 63   "{\n"
 64   "  echo( \"onSomeCoolEvent Triggered\" );\n"
 65   "}\n\n"
 66   "// Trigger the event.\n"
 67   "$MyEventManager.postEvent( \"SomeCoolEvent\", \"Data\" );\n"
 68   "@endtsexample\n\n"
 69
 70   "@ingroup Messaging\n"
 71);
 72
 73//-----------------------------------------------------------------------------
 74IMPLEMENT_CALLBACK(ScriptMsgListener, onAdd, void, (),(),
 75               "Script callback when a listener is first created and registered.\n\n"
 76               "@tsexample\n"
 77               "function ScriptMsgListener::onAdd(%this)\n"
 78               "{\n"
 79               "  // Perform on add code here\n"
 80               "}\n"
 81               "@endtsexample\n\n"
 82               );
 83
 84bool ScriptMsgListener::onAdd()
 85{
 86   if(! Parent::onAdd())
 87      return false;
 88
 89   onAdd_callback();
 90   //Con::executef(this, "onAdd");
 91   return true;
 92}
 93
 94IMPLEMENT_CALLBACK(ScriptMsgListener, onRemove, void, (),(),
 95               "Script callback when a listener is deleted.\n\n"
 96               "@tsexample\n"
 97               "function ScriptMsgListener::onRemove(%this)\n"
 98               "{\n"
 99               "  // Perform on remove code here\n"
100               "}\n"
101               "@endtsexample\n\n"
102               );
103
104void ScriptMsgListener::onRemove()
105{
106   onRemove_callback();
107   //Con::executef(this, "onRemove");
108   
109   Parent::onRemove();
110}
111
112//-----------------------------------------------------------------------------
113// Public Methods
114//-----------------------------------------------------------------------------
115IMPLEMENT_CALLBACK( ScriptMsgListener, onMessageReceived, bool, ( const char* queue, const char* event, const char* data ), ( queue, event, data ),
116   "Called when the listener has received a message.\n"
117   "@param queue The name of the queue the message was dispatched to\n"
118   "@param event The name of the event (function) that was triggered\n"
119   "@param data The data (parameters) for the message\n\n"
120   "@return false to prevent other listeners receiving this message, true otherwise\n" );
121
122bool ScriptMsgListener::onMessageReceived(StringTableEntry queue, const char* event, const char* data)
123{
124   return onMessageReceived_callback(queue, event, data);
125   //return dAtob(Con::executef(this, "onMessageReceived", queue, event, data));
126}
127
128IMPLEMENT_CALLBACK( ScriptMsgListener, onMessageObjectReceived, bool, ( const char* queue, Message *msg ), ( queue, msg ),
129   "Called when a message object (not just the message data) is passed to a listener.\n"
130   "@param queue The name of the queue the message was dispatched to\n"
131   "@param msg The message object\n"
132   "@return false to prevent other listeners receiving this message, true otherwise\n" 
133   "@see Message\n"
134   "@see onMessageReceived");
135
136bool ScriptMsgListener::onMessageObjectReceived(StringTableEntry queue, Message *msg)
137{
138   return onMessageObjectReceived_callback(queue, msg);
139   //return dAtob(Con::executef(this, "onMessageObjectReceived", queue, Con::getIntArg(msg->getId())));
140}
141
142//-----------------------------------------------------------------------------
143IMPLEMENT_CALLBACK( ScriptMsgListener, onAddToQueue, void, ( const char* queue), ( queue),
144   "@brief Callback for when the listener is added to a queue\n\n"
145   "The default implementation of onAddToQueue() and onRemoveFromQueue() "
146   "provide tracking of the queues this listener is added to through the "
147   "mQueues member. Overrides of onAddToQueue() or onRemoveFromQueue() "
148   "should ensure they call the parent implementation in any overrides.\n"
149   "@param queue The name of the queue that the listener added to\n"
150      "@see onRemoveFromQueue()");
151
152void ScriptMsgListener::onAddToQueue(StringTableEntry queue)
153{
154   //Con::executef(this, "onAddToQueue", queue);
155   onAddToQueue_callback(queue);
156   IMLParent::onAddToQueue(queue);
157}
158
159/// @brief Callback for when the listener is removed from a queue
160   /// 
161   /// The default implementation of onAddToQueue() and onRemoveFromQueue()
162   /// provide tracking of the queues this listener is added to through the
163   /// #mQueues member. Overrides of onAddToQueue() or onRemoveFromQueue()
164   /// should ensure they call the parent implementation in any overrides.
165   /// 
166   /// @param queue The name of the queue the listener was removed from
167   /// @see onAddToQueue()
168   //-----------------------------------------------------------------------------
169IMPLEMENT_CALLBACK( ScriptMsgListener, onRemoveFromQueue, void, ( const char* queue), ( queue),
170   "@brief Callback for when the listener is removed from a queue\n\n"
171   "The default implementation of onAddToQueue() and onRemoveFromQueue() "
172   "provide tracking of the queues this listener is added to through the "
173   "mQueues member. Overrides of onAddToQueue() or onRemoveFromQueue() "
174   "should ensure they call the parent implementation in any overrides.\n"
175   "@param queue The name of the queue that the listener was removed from\n"
176      "@see onAddToQueue()");
177
178void ScriptMsgListener::onRemoveFromQueue(StringTableEntry queue)
179{
180   //Con::executef(this, "onRemoveFromQueue", queue);
181   onRemoveFromQueue_callback(queue);
182   IMLParent::onRemoveFromQueue(queue);
183}
184