BsMessageHandlerFwd.h 1.7 KB

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