33#ifndef __H__UG__message_hub__
34#define __H__UG__message_hub__
182 template <
class TMsg>
184 bool autoFree =
false);
201 template <
class TMsg,
class TClass>
203 void (TClass::*callback)(const TMsg&),
204 bool autoFree = true);
217 template <
class TMsg>
236 template <
class TMsg>
238 std::function<
void (
const IMessage&)> callback,
Definition smart_pointer.h:107
The callback-id allows to deregister previously registered callbacks.
Definition message_hub.h:147
void set_auto_free(bool autoFree)
Definition message_hub.h:152
bool m_autoFree
Definition message_hub.h:162
size_t m_msgTypeId
Make sure to only access the iterator while m_hub != NULL.
Definition message_hub.h:160
MessageHub * m_hub
Definition message_hub.h:158
CallbackEntryIterator m_callbackEntryIter
Definition message_hub.h:161
~CallbackId()
Definition message_hub.cpp:56
Instances of this class are thrown if an error occurs in MessageHub.
Definition message_hub.h:120
ErrorIds get_message_hub_error_id()
Definition message_hub.h:125
ErrorIds m_errorId
Definition message_hub.h:128
Error(const char *msg, ErrorIds errorId)
Definition message_hub.h:122
This is the base class of all messages, which may be passed to callbacks.
Definition message_hub.h:132
IMessage()
Definition message_hub.h:134
virtual ~IMessage()
Definition message_hub.h:135
Allows to register callbacks and post messages to those callbacks.
Definition message_hub.h:80
SPCallbackId register_callback_impl(std::function< void(const IMessage &)> callback, bool autoFree)
registers a callback given a message-id.
Definition message_hub_impl.hpp:89
CallbackEntryList::iterator CallbackEntryIterator
Definition message_hub.h:102
CallbackMap m_callbackMap
given a msg-type-id, this map returns a list of associated callbacks
Definition message_hub.h:245
std::list< CallbackEntry > CallbackEntryList
Definition message_hub.h:101
void post_message(const TMsg &msg)
Posts a message to all callbacks which are registered for the given message tpye.
Definition message_hub_impl.hpp:73
void unregister_callback_impl(CallbackId *cbId)
performs unregistration of the given callback
Definition message_hub.cpp:103
SmartPtr< CallbackId > SPCallbackId
Definition message_hub.h:165
MessageHub()
Definition message_hub.cpp:74
SPCallbackId register_class_callback(TClass *cls, void(TClass::*callback)(const TMsg &), bool autoFree=true)
registers a method callback given a message-type.
Definition message_hub_impl.hpp:55
SPCallbackId register_function_callback(void(*callback)(const TMsg &), bool autoFree=false)
registers a function callback given a message-type.
Definition message_hub_impl.hpp:44
std::map< size_t, CallbackEntryList > CallbackMap
Definition message_hub.h:103
~MessageHub()
Definition message_hub.cpp:78
std::function< void(const IMessage &)> Callback
Definition message_hub.h:88
void unregister_callback(SPCallbackId cbId)
Call this method to explicitly unregister a callback.
Definition message_hub.cpp:97
ErrorIds
Error codes which give information on the error-reason.
Definition message_hub.h:107
@ MSG_HUB_BAD_MESSAGE_ID
Definition message_hub.h:110
@ MSG_HUB_TYPE_MISMATCH
Definition message_hub.h:109
@ MSG_HUB_BAD_CALLBACK_ID
Definition message_hub.h:111
@ MSG_HUB_UNKNOWN_ERROR
Definition message_hub.h:108
Instances of this class or of derived classes are thrown if errors arise.
Definition error.h:104
SmartPtr< MessageHub > SPMessageHub
Definition message_hub.h:55
The CallbackEntry holds the actual callback and the associated callback-id.
Definition message_hub.h:95
CallbackId * m_callbackId
Definition message_hub.h:98
Callback m_callback
Definition message_hub.h:97