BsMessageHandlerFwd.h 1.7 KB

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