21 #ifndef GF_MESSAGE_MANAGER_H 22 #define GF_MESSAGE_MANAGER_H 26 #include <type_traits> 31 #include "Portability.h" 34 #ifndef DOXYGEN_SHOULD_SKIP_THIS 128 static_assert(std::is_base_of<Message, E>::value,
"E must be an Message");
129 static_assert(E::type !=
InvalidId,
"E must define its type");
130 return registerHandler(E::type, handler);
160 template<
typename R,
typename T>
162 return registerHandler(type, [pm, obj](
Id id,
Message *msg) {
163 return (obj->*pm)(
id, msg);
193 template<
typename E,
typename R,
typename T>
195 static_assert(std::is_base_of<Message, E>::value,
"E must be an Message");
196 static_assert(E::type !=
InvalidId,
"E must define its type");
197 return registerHandler(E::type, [pm, obj](
Id id,
Message *msg) {
198 return (obj->*pm)(
id, msg);
222 for (
auto id : ids) {
257 void sendMessage(
Id type,
Message *message);
283 static_assert(std::is_base_of<Message, E>::value,
"E must be an Message");
284 static_assert(E::type !=
InvalidId,
"E must define its type");
285 sendMessage(E::type, message);
297 std::map<Id, std::vector<Handler>> m_handlers;
300 #ifndef DOXYGEN_SHOULD_SKIP_THIS 305 #endif // GF_MESSAGE_MANAGER_H std::function< MessageStatus(Id, Message *)> MessageHandler
A message handler.
Definition: Message.h:121
MessageHandlerId registerHandler(MessageHandler handler)
Register a message handler for a type of message.
Definition: MessageManager.h:127
void sendMessage(E *message)
Send a message.
Definition: MessageManager.h:282
uint64_t Id
An identifier.
Definition: Id.h:39
A message manager.
Definition: MessageManager.h:75
uint64_t MessageHandlerId
An identifier for a message handler.
Definition: MessageManager.h:44
MessageHandlerId registerHandler(R T::*pm, T *obj)
Register a message handler for a type of message.
Definition: MessageManager.h:194
The namespace for gf classes.
Definition: Action.h:35
A constant reference to an array and its size.
Definition: ArrayRef.h:43
MessageHandlerId registerHandler(Id type, R T::*pm, T *obj)
Register a message handler for a type of message.
Definition: MessageManager.h:161
The base class for all messages.
Definition: Message.h:53
void removeHandlers(ArrayRef< MessageHandlerId > ids)
Remove a list of handlers.
Definition: MessageManager.h:221
constexpr Id InvalidId
The invalid id (which is 0)
Definition: Id.h:45