message.cpp
Engine/source/util/messaging/message.cpp
Namespaces:
namespace
Public Functions
ConsoleDocClass(Message , "@brief Base class <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">messages\n\n</a>" "<a href="/coding/class/classmessage/">Message</a> is the base class <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> C++ defined messages, and may also be used " "in script <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> script defined messages <a href="/coding/file/tsmeshintrinsics_8cpp/#tsmeshintrinsics_8cpp_1a4e4fa7e3399708e0777b5308db01278c">if</a> no C++subclass is <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">appropriate.\n\n</a>" "Messages are reference counted and will be automatically deleted when " "their reference <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1ad43c3812e6d13e0518d9f8b8f463ffcf">count</a> reaches zero. When you dispatch <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> message, <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> " "reference will be added before the dispatch and freed after the dispatch. " "This allows <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> temporary messages with no additional code. If you want " "<a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> keep the message around, <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> example <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> dispatch it <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> multiple " " queues, call addReference() before dispatching it and freeReference() " "when you are done with it. Never delete <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> <a href="/coding/class/classmessage/">Message</a> object directly " "unless addReference() has not been called or the message has not been " "<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">dispatched.\n\n</a>" "<a href="/coding/class/classmessage/">Message</a> IDs are pooled similarly <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> datablocks, with the exception that " "IDs are reused. If you keep <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> message <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> longer than <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> single dispatch, " "then you should ensure that you clear any script variables that refer " "<a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> it after the last freeReference(). If you don ' t, then it is probable " "that the object ID will become valid again in the future and could cause " "hard <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> track down <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">bugs.\n\n</a>" "Messages have <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> unique type <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> simplify message handling code. For object " " messages, the type is defined as either the script defined class name " "or the C++class name <a href="/coding/file/tsmeshintrinsics_8cpp/#tsmeshintrinsics_8cpp_1a4e4fa7e3399708e0777b5308db01278c">if</a> no script class was defined. The message type " "may be obtained through the getType() <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">method.\n\n</a>" "By convention, any data <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> the message is held in script accessible " "fields. Messages that need <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> be handled in C++as well as script " "provide the relevant data through persistent fields in <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> subclass of " "<a href="/coding/class/classmessage/">Message</a> <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> provide best performance on the C++side. Script defined " "messages usually their through dynamic fields, and may be accessed in " "C++using the <a href="/coding/class/classsimobject/#classsimobject_1a5baf5f02e0c5974417432a6ac2e57e19">SimObject::getDataField</a>() <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">method.\n\n</a>" " @ingroup <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">Messaging\n</a>" )
DefineEngineMethod(Message , addReference , void , () , "() Increment the reference <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1ad43c3812e6d13e0518d9f8b8f463ffcf">count</a> <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> this message" )
DefineEngineMethod(Message , freeReference , void , () , "() Decrement the reference <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1ad43c3812e6d13e0518d9f8b8f463ffcf">count</a> <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> this message" )
DefineEngineMethod(Message , getType , const char * , () , "() Get message type (script class name or C++ class name <a href="/coding/file/tsmeshintrinsics_8cpp/#tsmeshintrinsics_8cpp_1a4e4fa7e3399708e0777b5308db01278c">if</a> no script defined class)" )
IMPLEMENT_CALLBACK(Message , onAdd , void , () , () , "Script callback when <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> message 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/classmessage/#classmessage_1a348600a868ff83cda6d823f8aa09e4ee">Message::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(Message , onRemove , void , () , () , "Script callback when <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> message 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/classmessage/#classmessage_1a2bf013efbb5377d674ac4f18c5e54790">Message::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>" )
Detailed Description
Public Functions
ConsoleDocClass(Message , "@brief Base class <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">messages\n\n</a>" "<a href="/coding/class/classmessage/">Message</a> is the base class <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> C++ defined messages, and may also be used " "in script <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> script defined messages <a href="/coding/file/tsmeshintrinsics_8cpp/#tsmeshintrinsics_8cpp_1a4e4fa7e3399708e0777b5308db01278c">if</a> no C++subclass is <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">appropriate.\n\n</a>" "Messages are reference counted and will be automatically deleted when " "their reference <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1ad43c3812e6d13e0518d9f8b8f463ffcf">count</a> reaches zero. When you dispatch <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> message, <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> " "reference will be added before the dispatch and freed after the dispatch. " "This allows <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> temporary messages with no additional code. If you want " "<a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> keep the message around, <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> example <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> dispatch it <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> multiple " " queues, call addReference() before dispatching it and freeReference() " "when you are done with it. Never delete <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> <a href="/coding/class/classmessage/">Message</a> object directly " "unless addReference() has not been called or the message has not been " "<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">dispatched.\n\n</a>" "<a href="/coding/class/classmessage/">Message</a> IDs are pooled similarly <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> datablocks, with the exception that " "IDs are reused. If you keep <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> message <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> longer than <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> single dispatch, " "then you should ensure that you clear any script variables that refer " "<a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> it after the last freeReference(). If you don ' t, then it is probable " "that the object ID will become valid again in the future and could cause " "hard <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> track down <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">bugs.\n\n</a>" "Messages have <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> unique type <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> simplify message handling code. For object " " messages, the type is defined as either the script defined class name " "or the C++class name <a href="/coding/file/tsmeshintrinsics_8cpp/#tsmeshintrinsics_8cpp_1a4e4fa7e3399708e0777b5308db01278c">if</a> no script class was defined. The message type " "may be obtained through the getType() <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">method.\n\n</a>" "By convention, any data <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> the message is held in script accessible " "fields. Messages that need <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> be handled in C++as well as script " "provide the relevant data through persistent fields in <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> subclass of " "<a href="/coding/class/classmessage/">Message</a> <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> provide best performance on the C++side. Script defined " "messages usually their through dynamic fields, and may be accessed in " "C++using the <a href="/coding/class/classsimobject/#classsimobject_1a5baf5f02e0c5974417432a6ac2e57e19">SimObject::getDataField</a>() <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">method.\n\n</a>" " @ingroup <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">Messaging\n</a>" )
DefineEngineMethod(Message , addReference , void , () , "() Increment the reference <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1ad43c3812e6d13e0518d9f8b8f463ffcf">count</a> <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> this message" )
DefineEngineMethod(Message , freeReference , void , () , "() Decrement the reference <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1ad43c3812e6d13e0518d9f8b8f463ffcf">count</a> <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> this message" )
DefineEngineMethod(Message , getType , const char * , () , "() Get message type (script class name or C++ class name <a href="/coding/file/tsmeshintrinsics_8cpp/#tsmeshintrinsics_8cpp_1a4e4fa7e3399708e0777b5308db01278c">if</a> no script defined class)" )
IMPLEMENT_CALLBACK(Message , onAdd , void , () , () , "Script callback when <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> message 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/classmessage/#classmessage_1a348600a868ff83cda6d823f8aa09e4ee">Message::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(Message , onRemove , void , () , () , "Script callback when <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> message 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/classmessage/#classmessage_1a2bf013efbb5377d674ac4f18c5e54790">Message::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_CONOBJECT(Message )
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/message.h" 26 27#include "console/consoleTypes.h" 28#include "core/util/safeDelete.h" 29#include "core/stream/bitStream.h" 30#include "console/engineAPI.h" 31 32//----------------------------------------------------------------------------- 33 34namespace Sim 35{ 36extern SimIdDictionary *gIdDictionary; 37} 38 39//----------------------------------------------------------------------------- 40// Constructor/Destructor 41//----------------------------------------------------------------------------- 42 43Message::Message() 44{ 45} 46 47 48IMPLEMENT_CONOBJECT(Message); 49 50ConsoleDocClass( Message, 51 "@brief Base class for messages\n\n" 52 53 "Message is the base class for C++ defined messages, and may also be used " 54 "in script for script defined messages if no C++ subclass is appropriate.\n\n" 55 56 "Messages are reference counted and will be automatically deleted when " 57 "their reference count reaches zero. When you dispatch a message, a " 58 "reference will be added before the dispatch and freed after the dispatch. " 59 "This allows for temporary messages with no additional code. If you want " 60 "to keep the message around, for example to dispatch it to multiple " 61 "queues, call addReference() before dispatching it and freeReference() " 62 "when you are done with it. Never delete a Message object directly " 63 "unless addReference() has not been called or the message has not been " 64 "dispatched.\n\n" 65 66 "Message IDs are pooled similarly to datablocks, with the exception that " 67 "IDs are reused. If you keep a message for longer than a single dispatch, " 68 "then you should ensure that you clear any script variables that refer " 69 "to it after the last freeReference(). If you don't, then it is probable " 70 "that the object ID will become valid again in the future and could cause " 71 "hard to track down bugs.\n\n" 72 73 "Messages have a unique type to simplify message handling code. For object " 74 "messages, the type is defined as either the script defined class name " 75 "or the C++ class name if no script class was defined. The message type " 76 "may be obtained through the getType() method.\n\n" 77 78 "By convention, any data for the message is held in script accessible " 79 "fields. Messages that need to be handled in C++ as well as script " 80 "provide the relevant data through persistent fields in a subclass of " 81 "Message to provide best performance on the C++ side. Script defined " 82 "messages usually their through dynamic fields, and may be accessed in " 83 "C++ using the SimObject::getDataField() method.\n\n" 84 85 "@ingroup Messaging\n" 86); 87 88//----------------------------------------------------------------------------- 89IMPLEMENT_CALLBACK(Message, onAdd, void, (),(), 90 "Script callback when a message is first created and registered.\n\n" 91 "@tsexample\n" 92 "function Message::onAdd(%this)\n" 93 "{\n" 94 " // Perform on add code here\n" 95 "}\n" 96 "@endtsexample\n\n" 97 ); 98 99bool Message::onAdd() 100{ 101 if(! Parent::onAdd()) 102 return false; 103 104 onAdd_callback(); 105 //Con::executef(this, "onAdd"); 106 return true; 107} 108 109IMPLEMENT_CALLBACK(Message, onRemove, void, (),(), 110 "Script callback when a message is deleted.\n\n" 111 "@tsexample\n" 112 "function Message::onRemove(%this)\n" 113 "{\n" 114 " // Perform on remove code here\n" 115 "}\n" 116 "@endtsexample\n\n" 117 ); 118 119void Message::onRemove() 120{ 121 onRemove_callback(); 122 //Con::executef(this, "onRemove"); 123 124 Parent::onRemove(); 125} 126 127//----------------------------------------------------------------------------- 128// Public Methods 129//----------------------------------------------------------------------------- 130 131SimObjectId Message::getNextMessageID() 132{ 133 for(S32 i = MessageObjectIdFirst;i < MessageObjectIdLast;i++) 134 { 135 if(Sim::gIdDictionary->find(i) == NULL) 136 return i; 137 } 138 139 // Oh no ... 140 return 0xffffffff; 141} 142 143//----------------------------------------------------------------------------- 144 145const char *Message::getType() 146{ 147 if(mClassName && mClassName[0] != 0) 148 return mClassName; 149 150 return getClassName(); 151} 152 153//----------------------------------------------------------------------------- 154// Console Methods 155//----------------------------------------------------------------------------- 156 157DefineEngineMethod(Message, getType, const char *, (), , "() Get message type (script class name or C++ class name if no script defined class)") 158{ 159 return object->getType(); 160} 161 162//----------------------------------------------------------------------------- 163 164DefineEngineMethod(Message, addReference, void, (), , "() Increment the reference count for this message") 165{ 166 object->addReference(); 167} 168 169DefineEngineMethod(Message, freeReference, void, (), , "() Decrement the reference count for this message") 170{ 171 object->freeReference(); 172} 173