1//************************************ bs::framework - Copyright 2018 Marko Pintera **************************************//
2//*********** Licensed under the MIT license. See LICENSE.md for full terms. This notice is not to be removed. ***********//
3#pragma once
4
5#include "Prerequisites/BsTypes.h"
6#include "String/BsString.h"
7
8namespace bs
9{
10 /** @addtogroup General
11 * @{
12 */
13
14 /**
15 * Identifier for message used with the global messaging system.
16 *
17 * @note
18 * Primary purpose of this class is to avoid expensive string compare, and instead use a unique message identifier for
19 * compare. Generally you want to create one of these using the message name, and then store it for later use.
20 * @note
21 * This class is not thread safe and should only be used on the sim thread.
22 */
23 class BS_UTILITY_EXPORT MessageId
24 {
25 public:
26 MessageId() = default;
27 MessageId(const String& name);
28
29 bool operator== (const MessageId& rhs) const
30 {
31 return (mMsgIdentifier == rhs.mMsgIdentifier);
32 }
33 private:
34 friend class MessageHandler;
35
36 static Map<String, UINT32> UniqueMessageIds;
37 static UINT32 NextMessageId;
38
39 UINT32 mMsgIdentifier = 0;
40 };
41
42 /** Handle to a subscription for a specific message in the global messaging system. */
43 class BS_UTILITY_EXPORT HMessage
44 {
45 public:
46 HMessage() = default;
47
48 /** Disconnects the message listener so it will no longer receive events from the messaging system. */
49 void disconnect();
50
51 private:
52 friend class MessageHandler;
53
54 HMessage(UINT32 id);
55
56 UINT32 mId = 0;
57 };
58
59 /**
60 * Sends a message using the global messaging system.
61 *
62 * @note Sim thread only.
63 */
64 void BS_UTILITY_EXPORT sendMessage(MessageId message);
65
66 class MessageHandler;
67
68 /** @} */
69}
70