BsMessageHandlerFwd.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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, and instead use a unique message identifier for
  14. * compare. Generally you want to create one of these using the message name, and then store it for later use.
  15. * @note
  16. * This class is not thread safe and should only be used on the sim thread.
  17. */
  18. class BS_UTILITY_EXPORT MessageId
  19. {
  20. public:
  21. MessageId();
  22. MessageId(const String& name);
  23. bool operator== (const MessageId& rhs) const
  24. {
  25. return (mMsgIdentifier == rhs.mMsgIdentifier);
  26. }
  27. private:
  28. friend class MessageHandler;
  29. static Map<String, UINT32> UniqueMessageIds;
  30. static UINT32 NextMessageId;
  31. UINT32 mMsgIdentifier;
  32. };
  33. /** Handle to a subscription for a specific message in the global messaging system. */
  34. class BS_UTILITY_EXPORT HMessage
  35. {
  36. public:
  37. HMessage();
  38. /** Disconnects the message listener so it will no longer receive events from the messaging system. */
  39. void disconnect();
  40. private:
  41. friend class MessageHandler;
  42. HMessage(UINT32 id);
  43. UINT32 mId;
  44. };
  45. /**
  46. * Sends a message using the global messaging system.
  47. *
  48. * @note Sim thread only.
  49. */
  50. void BS_UTILITY_EXPORT sendMessage(MessageId message);
  51. class MessageHandler;
  52. /** @} */
  53. }