messageForwarder.cpp 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2012 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. #include "platform/platform.h"
  23. #include "util/messaging/messageForwarder.h"
  24. #include "console/consoleTypes.h"
  25. //-----------------------------------------------------------------------------
  26. // Constructor/Destructor
  27. //-----------------------------------------------------------------------------
  28. MessageForwarder::MessageForwarder()
  29. {
  30. mToQueue = "";
  31. }
  32. MessageForwarder::~MessageForwarder()
  33. {
  34. }
  35. IMPLEMENT_CONOBJECT(MessageForwarder);
  36. ConsoleDocClass( MessageForwarder,
  37. "@brief Forward messages from one queue to another\n\n"
  38. "MessageForwarder is a script class that can be used to forward messages "
  39. "from one queue to another.\n\n"
  40. "@tsexample\n"
  41. "%fwd = new MessageForwarder()\n"
  42. "{\n"
  43. " toQueue = \"QueueToSendTo\";\n"
  44. "};\n\n"
  45. "registerMessageListener(\"FromQueue\", %fwd);\n"
  46. "@endtsexample\n\n"
  47. "Where \"QueueToSendTo\" is the queue you want to forward to, and "
  48. "\"FromQueue\" is the queue you want to forward from.\n\n"
  49. "@ingroup Messaging\n"
  50. );
  51. //-----------------------------------------------------------------------------
  52. void MessageForwarder::initPersistFields()
  53. {
  54. docsURL;
  55. addField("toQueue", TypeCaseString, Offset(mToQueue, MessageForwarder), "Name of queue to forward to");
  56. Parent::initPersistFields();
  57. }
  58. //-----------------------------------------------------------------------------
  59. // Public Methods
  60. //-----------------------------------------------------------------------------
  61. bool MessageForwarder::onMessageReceived(StringTableEntry queue, const char *event, const char *data)
  62. {
  63. if(*mToQueue)
  64. Dispatcher::dispatchMessage(queue, event, data);
  65. return Parent::onMessageReceived(queue, event, data);
  66. }
  67. bool MessageForwarder::onMessageObjectReceived(StringTableEntry queue, Message *msg)
  68. {
  69. if(*mToQueue)
  70. Dispatcher::dispatchMessageObject(mToQueue, msg);
  71. return Parent::onMessageObjectReceived(queue, msg);
  72. }