dispatcher_ScriptBinding.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2013 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. /*! @defgroup MessageQueueFunctions Message Queue (Dispatcher)
  23. @ingroup TorqueScriptFunctions
  24. @{
  25. */
  26. using namespace Dispatcher;
  27. /*! Checks whether message queue is registered
  28. @param queueName The name of the queue to check
  29. @return Returns true if registered and false if not
  30. */
  31. ConsoleFunctionWithDocs(isQueueRegistered, ConsoleBool, 2, 2, (queueName))
  32. {
  33. return isQueueRegistered(argv[1]);
  34. }
  35. /*! Registers given message queue
  36. @param queueName The name of the message queue
  37. @return No Return Value
  38. */
  39. ConsoleFunctionWithDocs(registerMessageQueue, ConsoleVoid, 2, 2, (queueName))
  40. {
  41. return registerMessageQueue(argv[1]);
  42. }
  43. /*! Unregisters given message queue
  44. @param The name of the message queue
  45. @return No Return Value
  46. */
  47. ConsoleFunctionWithDocs(unregisterMessageQueue, ConsoleVoid, 2, 2, (queueName))
  48. {
  49. return unregisterMessageQueue(argv[1]);
  50. }
  51. //////////////////////////////////////////////////////////////////////////
  52. /*! Registers a message listener on a message queue
  53. @param queueName The name of the message queue
  54. @param listener The name of the listener to register
  55. @return Returns true on success, and false otherwise (probably not found)
  56. */
  57. ConsoleFunctionWithDocs(registerMessageListener, ConsoleBool, 3, 3, (queueName, listener))
  58. {
  59. IMessageListener *listener = dynamic_cast<IMessageListener *>(Sim::findObject(argv[2]));
  60. if(listener == NULL)
  61. {
  62. Con::errorf("registerMessageListener - Unable to find listener object, not an IMessageListener ?!");
  63. return false;
  64. }
  65. return registerMessageListener(argv[1], listener);
  66. }
  67. /*! Unregisters the message listener on given message queue
  68. @param queueName The name of the message queue
  69. @param listener The name of the listener to unregister
  70. @return No Return Value
  71. */
  72. ConsoleFunctionWithDocs(unregisterMessageListener, ConsoleVoid, 3, 3, (queueName, listener))
  73. {
  74. IMessageListener *listener = dynamic_cast<IMessageListener *>(Sim::findObject(argv[2]));
  75. if(listener == NULL)
  76. {
  77. Con::errorf("unregisterMessageListener - Unable to find listener object, not an IMessageListener ?!");
  78. return;
  79. }
  80. unregisterMessageListener(argv[1], listener);
  81. }
  82. //////////////////////////////////////////////////////////////////////////
  83. /*! Dispatches a message to given message queue
  84. @param queueName The queue to dispatch to
  85. @param event The message you are passing
  86. @param data Data
  87. @return Returns true on success and false otherwise
  88. */
  89. ConsoleFunctionWithDocs(dispatchMessage, ConsoleBool, 3, 4, (queueName, event, data))
  90. {
  91. return dispatchMessage(argv[1], argv[2], argc > 3 ? argv[3] : "" );
  92. }
  93. /*! Dispatches a message object to the given queue
  94. @param queueName The name of the queue to dispatch object to
  95. @param message The message object
  96. */
  97. ConsoleFunctionWithDocs(dispatchMessageObject, ConsoleBool, 3, 3, (queueName, message))
  98. {
  99. Message *msg = dynamic_cast<Message *>(Sim::findObject(argv[2]));
  100. if(msg == NULL)
  101. {
  102. Con::errorf("dispatchMessageObject - Unable to find message object");
  103. return false;
  104. }
  105. return dispatchMessageObject(argv[1], msg);
  106. }
  107. /*! @} */ // group MessageQueueFunctions