BsMessageHandlerFwd.h 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #pragma once
  2. namespace BansheeEngine
  3. {
  4. /** @addtogroup General
  5. * @{
  6. */
  7. /**
  8. * Identifier for message used with the global messaging system.
  9. *
  10. * @note
  11. * Primary purpose of this class is to avoid expensive string compare (i.e. button names), and instead use a unique
  12. * message identifier for compare. Generally you want to create one of these using the message name, and then store it
  13. * for later use.
  14. * @note
  15. * This class is not thread safe and should only be used on the sim thread.
  16. */
  17. class BS_UTILITY_EXPORT MessageId
  18. {
  19. public:
  20. MessageId();
  21. MessageId(const String& name);
  22. bool operator== (const MessageId& rhs) const
  23. {
  24. return (mMsgIdentifier == rhs.mMsgIdentifier);
  25. }
  26. private:
  27. friend class MessageHandler;
  28. static Map<String, UINT32> UniqueMessageIds;
  29. static UINT32 NextMessageId;
  30. UINT32 mMsgIdentifier;
  31. };
  32. /** Handle to a subscription for a specific message in the global messaging system. */
  33. class BS_UTILITY_EXPORT HMessage
  34. {
  35. public:
  36. HMessage();
  37. /** Disconnects the message listener so it will no longer receive events from the messaging system. */
  38. void disconnect();
  39. private:
  40. friend class MessageHandler;
  41. HMessage(UINT32 id);
  42. UINT32 mId;
  43. };
  44. /**
  45. * Sends a message using the global messaging system.
  46. *
  47. * @note Sim thread only.
  48. */
  49. void BS_UTILITY_EXPORT sendMessage(MessageId message);
  50. class MessageHandler;
  51. /** @} */
  52. }