33 #ifndef __H__UG__message_hub__
34 #define __H__UG__message_hub__
40 #include <boost/function.hpp>
41 #include <boost/function_equal.hpp>
42 #include <boost/bind.hpp>
183 template <
class TMsg>
185 bool autoFree =
false);
202 template <
class TMsg,
class TClass>
204 void (TClass::*callback)(
const TMsg&),
205 bool autoFree =
true);
218 template <
class TMsg>
237 template <
class TMsg>
239 boost::function<
void (
const IMessage&)> callback,
The callback-id allows to deregister previously registered callbacks.
Definition: message_hub.h:148
void set_auto_free(bool autoFree)
Definition: message_hub.h:153
bool m_autoFree
Definition: message_hub.h:163
size_t m_msgTypeId
Make sure to only access the iterator while m_hub != NULL.
Definition: message_hub.h:161
MessageHub * m_hub
Definition: message_hub.h:159
CallbackEntryIterator m_callbackEntryIter
Definition: message_hub.h:162
CallbackId(MessageHub *hub, size_t msgTypeId, CallbackEntryIterator callbackEntryIter, bool autoFree)
Definition: message_hub.cpp:47
~CallbackId()
Definition: message_hub.cpp:56
Instances of this class are thrown if an error occurs in MessageHub.
Definition: message_hub.h:121
ErrorIds get_message_hub_error_id()
Definition: message_hub.h:126
ErrorIds m_errorId
Definition: message_hub.h:129
Error(const char *msg, ErrorIds errorId)
Definition: message_hub.h:123
This is the base class of all messages, which may be passed to callbacks.
Definition: message_hub.h:133
IMessage()
Definition: message_hub.h:135
virtual ~IMessage()
Definition: message_hub.h:136
Allows to register callbacks and post messages to those callbacks.
Definition: message_hub.h:81
CallbackEntryList::iterator CallbackEntryIterator
Definition: message_hub.h:103
CallbackMap m_callbackMap
given a msg-type-id, this map returns a list of associated callbacks
Definition: message_hub.h:246
std::list< CallbackEntry > CallbackEntryList
Definition: message_hub.h:102
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:67
void unregister_callback_impl(CallbackId *cbId)
performs unregistration of the given callback
Definition: message_hub.cpp:103
SPCallbackId register_callback_impl(boost::function< void(const IMessage &)> callback, bool autoFree)
registers a callback given a message-id.
Definition: message_hub_impl.hpp:83
SmartPtr< CallbackId > SPCallbackId
Definition: message_hub.h:166
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:53
SPCallbackId register_function_callback(void(*callback)(const TMsg &), bool autoFree=false)
registers a function callback given a message-type.
Definition: message_hub_impl.hpp:42
std::map< size_t, CallbackEntryList > CallbackMap
Definition: message_hub.h:104
boost::function< void(const IMessage &)> Callback
Definition: message_hub.h:85
~MessageHub()
Definition: message_hub.cpp:78
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:108
@ MSG_HUB_BAD_MESSAGE_ID
Definition: message_hub.h:111
@ MSG_HUB_TYPE_MISMATCH
Definition: message_hub.h:110
@ MSG_HUB_BAD_CALLBACK_ID
Definition: message_hub.h:112
@ MSG_HUB_UNKNOWN_ERROR
Definition: message_hub.h:109
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:96
CallbackId * m_callbackId
Definition: message_hub.h:99
Callback m_callback
Definition: message_hub.h:98
CallbackEntry(const Callback &cb, CallbackId *cbId)
Definition: message_hub.cpp:40