#pragma once #include "BsPrerequisitesUtil.h" #include "BsModule.h" namespace BansheeEngine { /** @addtogroup General * @{ */ /** * Allows you to transparently pass messages between different systems. * * @note Sim thread only. */ class BS_UTILITY_EXPORT MessageHandler : public Module { struct MessageHandlerData { UINT32 id; std::function callback; }; public: MessageHandler(); /** Sends a message to all subscribed listeners. */ void send(MessageId message); /** * Subscribes a message listener for the specified message. Provided callback will be triggered whenever that * message gets sent. * * @return A handle to the message subscription that you can use to unsubscribe from listening. */ HMessage listen(MessageId message, std::function callback); private: friend class HMessage; void unsubscribe(UINT32 handleId); Map> mMessageHandlers; Map mHandlerIdToMessageMap; UINT32 mNextCallbackId; }; /** @} */ }