17 #ifndef BERRYMESSAGE_H_
18 #define BERRYMESSAGE_H_
21 #include <Poco/Mutex.h>
27 #define berryNewMessageMacro(msgHandleObject) \
28 private: Message<> m_ ## msgHandleObject ## Message; \
30 inline void Add ## msgHandleObject ## Listener(const MessageAbstractDelegate<>& delegate) \
31 { m_ ## msgHandleObject ## Message += delegate; } \
32 inline void Remove ## msgHandleObject ## Listener(const MessageAbstractDelegate<>& delegate) \
33 { m_ ## msgHandleObject ## Message -= delegate; } \
36 #define berryNewMessageWithReturnMacro(msgHandleObject, returnType) \
37 private: Message<returnType> m_ ## msgHandleObject ## Message; \
39 inline void Add ## msgHandleObject ## Listener(const MessageAbstractDelegate<returnType>& delegate) \
40 { m_ ## msgHandleObject ## Message += delegate; } \
41 inline void Remove ## msgHandleObject ## Listener(const MessageAbstractDelegate<returnType>& delegate) \
42 { m_ ## msgHandleObject ## Message -= delegate; } \
45 #define berryNewMessage1Macro(msgHandleObject, type1) \
46 private: Message1< type1 > m_msgHandleObject ## Message; \
48 void Add ## msgHandleObject ## Listener(const MessageAbstractDelegate1< type1 >& delegate) \
49 { m_ ## msgHandleObject ## Message += delegate; } \
50 void Remove ## msgHandleObject ## Listener(const MessageAbstractDelegate1< type1 >& delegate) \
51 { m_ ## msgHandleObject ## Message -= delegate; } \
57 template<
typename A =
void>
71 template<
typename T,
typename A =
void>
85 template<
typename T,
typename U,
typename A =
void>
94 virtual A
Execute(T t, U u)
const = 0;
99 template<
typename T,
typename U,
typename V,
typename A =
void>
108 virtual A
Execute(T t, U u, V v)
const = 0;
113 template<
typename T,
typename U,
typename V,
typename W,
typename A =
void>
122 virtual A
Execute(T t, U u, V v, W w)
const = 0;
127 template<
class R,
typename A =
void>
135 m_Object(object), m_MemberFunctionPointer(memberFunctionPointer)
146 return (m_Object->*m_MemberFunctionPointer)();
156 if ((
void*) this->m_Object != (
void*) cmd->m_Object)
158 if (this->m_MemberFunctionPointer != cmd->m_MemberFunctionPointer)
170 A (R::*m_MemberFunctionPointer)();
173 template<
class R,
typename T,
typename A =
void>
181 m_Object(object), m_MemberFunctionPointer(memberFunctionPointer)
192 return (m_Object->*m_MemberFunctionPointer)(t);
202 if ((
void*) this->m_Object != (
void*) cmd->m_Object)
204 if (this->m_MemberFunctionPointer != cmd->m_MemberFunctionPointer)
216 A (R::*m_MemberFunctionPointer)(T);
219 template<
class R,
typename T,
typename U,
typename A =
void>
227 m_Object(object), m_MemberFunctionPointer(memberFunctionPointer)
238 return (m_Object->*m_MemberFunctionPointer)(t, u);
248 if ((
void*) this->m_Object != (
void*) cmd->m_Object)
250 if (this->m_MemberFunctionPointer != cmd->m_MemberFunctionPointer)
262 A (R::*m_MemberFunctionPointer)(T, U);
265 template<
class R,
typename T,
typename U,
typename V,
typename A =
void>
273 m_Object(object), m_MemberFunctionPointer(memberFunctionPointer)
284 return (m_Object->*m_MemberFunctionPointer)(t, u, v);
294 if ((
void*) this->m_Object != (
void*) cmd->m_Object)
296 if (this->m_MemberFunctionPointer != cmd->m_MemberFunctionPointer)
308 A (R::*m_MemberFunctionPointer)(T, U, V);
311 template<
class R,
typename T,
typename U,
typename V,
typename W,
320 m_Object(object), m_MemberFunctionPointer(memberFunctionPointer)
331 return (m_Object->*m_MemberFunctionPointer)(t, u, v, w);
341 if ((
void*) this->m_Object != (
void*) cmd->m_Object)
343 if (this->m_MemberFunctionPointer != cmd->m_MemberFunctionPointer)
355 A (R::*m_MemberFunctionPointer)(T, U, V, W);
374 m_Object(r), m_ExceptionCallback(c)
380 (m_Object->*m_ExceptionCallback)(exc);
385 if (!m_Object)
return nullptr;
405 m_ExcHandler(nullptr)
412 for (
auto iter = m_Delegates.begin(); iter
413 != m_Delegates.end(); ++iter)
421 void Add(
const Delegate& d)
const
423 Delegate* copy = d.
Clone();
425 Poco::FastMutex::ScopedLock lock(m_Mutex);
426 for (
auto iter = m_Delegates.begin(); iter
427 != m_Delegates.end(); ++iter)
429 if ((*iter)->operator==(copy))
435 m_Delegates.push_back(copy);
440 Poco::FastMutex::ScopedLock lock(m_Mutex);
441 for (
auto iter = m_Delegates.begin(); iter
442 != m_Delegates.end(); ++iter)
444 if ((*iter)->operator==(&d))
447 m_Delegates.erase(iter);
455 return m_Delegates.empty();
458 template<
typename Dummy>
464 Poco::FastMutex::ScopedLock lock(m_Mutex);
465 delegates.assign(m_Delegates.begin(), m_Delegates.end());
468 for (
auto iter = delegates.begin(); iter
469 != delegates.end(); ++iter)
476 catch (
const std::exception& e)
505 Poco::FastMutex::ScopedLock lock(m_Mutex);
506 delegates.assign(m_Delegates.begin(), m_Delegates.end());
509 for (
auto iter = delegates.begin(); iter
510 != delegates.end(); ++iter)
517 catch (
const std::exception& e)
539 template<
typename T,
typename U>
545 Poco::FastMutex::ScopedLock lock(m_Mutex);
546 delegates.assign(m_Delegates.begin(), m_Delegates.end());
549 for (
auto iter = delegates.begin(); iter
550 != delegates.end(); ++iter)
555 (*iter)->Execute(t, u);
557 catch (
const std::exception& e)
579 template<
typename T,
typename U,
typename V>
585 Poco::FastMutex::ScopedLock lock(m_Mutex);
586 delegates.assign(m_Delegates.begin(), m_Delegates.end());
589 for (
auto iter = delegates.begin(); iter
590 != delegates.end(); ++iter)
595 (*iter)->Execute(t, u, v);
597 catch (
const std::exception& e)
619 template<
typename T,
typename U,
typename V,
typename W>
620 void Send4(T t, U u, V v, W w)
const
625 Poco::FastMutex::ScopedLock lock(m_Mutex);
626 delegates.assign(m_Delegates.begin(), m_Delegates.end());
629 for (
auto iter = delegates.begin(); iter
630 != delegates.end(); ++iter)
635 (*iter)->Execute(t, u, v, w);
637 catch (
const std::exception& e)
661 Poco::FastMutex::ScopedLock lock(m_Mutex);
663 m_ExcHandler = handler.
Clone();
668 Poco::FastMutex::ScopedLock lock(m_Mutex);
669 if (m_ExcHandler)
return m_ExcHandler->
Clone();
675 Poco::FastMutex::ScopedLock lock(m_Mutex);
698 mutable std::vector<Delegate*> m_Delegates;
701 mutable Poco::FastMutex m_Mutex;
719 template<
typename A =
void>
790 template<
typename T,
typename A =
void>
861 template<
typename T,
typename U,
typename A =
void>
932 template<
typename T,
typename U,
typename V,
typename A =
void>
1003 template<
typename T,
typename U,
typename V,
typename W,
typename A =
void>
1032 void Send(T t, U u, V v, W w)
const
1039 this->
Send(t, u , v, w);
static MsgHandler handler
void AddListener(const AbstractDelegate &delegate) const
AbstractExceptionHandler * GetExceptionHandler() const
virtual A Execute(T t, U u) const
bool HasListeners() const
DelegateList< AbstractDelegate >::ListType ListenerList
bool HasListeners() const
void operator-=(const AbstractDelegate &delegate) const
virtual ~MessageAbstractDelegate4()
void operator()(T t, U u) const
AbstractExceptionHandler * GetExceptionHandler() const
MessageDelegate3(R *object, A(R::*memberFunctionPointer)(T, U, V))
virtual MessageAbstractDelegate3 * Clone() const =0
void Add(const Delegate &d) const
virtual bool operator==(const MessageAbstractDelegate1 *cmd)=0
void SetExceptionHandler(const AbstractExceptionHandler &handler)
virtual ~MessageDelegate1()
DelegateList< AbstractDelegate > delegates
virtual ~MessageDelegate3()
void operator-=(const AbstractDelegate &delegate) const
void operator()(T t) const
MessageAbstractDelegate3< T, U, V, A > AbstractDelegate
void operator()(T t, U u, V v, W w) const
void SetExceptionHandler(const AbstractExceptionHandler &handler)
void AddListener(const AbstractDelegate &delegate) const
void Send2(T t, U u) const
MessageDelegate(R *object, A(R::*memberFunctionPointer)())
AbstractExceptionHandler * Clone() const override
DelegateList< AbstractDelegate > delegates
virtual A Execute(T t, U u, V v, W w) const
bool HasListeners() const
virtual bool operator==(const MessageAbstractDelegate3 *cmd)=0
virtual A Execute(T t, U u, V v) const =0
void Send3(T t, U u, V v) const
MessageDelegate4(R *object, A(R::*memberFunctionPointer)(T, U, V, W))
virtual bool operator==(const MessageAbstractDelegate4 *cmd)=0
AbstractExceptionHandler * GetExceptionHandler() const
MessageAbstractDelegate4< T, U, V, W, A > * Clone() const
virtual ~MessageAbstractDelegate3()
void SetExceptionHandler(const AbstractExceptionHandler &handler)
AbstractExceptionHandler * GetExceptionHandler() const
virtual ~MessageDelegate()
virtual MessageAbstractDelegate2 * Clone() const =0
void Send(T t, U u) const
std::vector< Delegate * > ListType
MessageDelegate2(R *object, A(R::*memberFunctionPointer)(T, U))
AbstractExceptionHandler * GetExceptionHandler() const
DelegateList< AbstractDelegate >::ListType ListenerList
DelegateList< AbstractDelegate >::ListType ListenerList
void SetExceptionHandler(const AbstractExceptionHandler &handler)
virtual bool operator==(const MessageAbstractDelegate *cmd)=0
bool operator==(const MessageAbstractDelegate1< T, A > *c)
MessageAbstractDelegate< A > * Clone() const
virtual ~MessageDelegate4()
void operator-=(const AbstractDelegate &delegate) const
virtual A Execute(T t, U u, V v, W w) const =0
ListenerList GetListeners() const
virtual A Execute(T t, U u) const =0
void RemoveListener(const AbstractDelegate &delegate) const
MessageDelegate1(R *object, A(R::*memberFunctionPointer)(T))
void SetExceptionHandler(const AbstractExceptionHandler &handler)
bool HasListeners() const
MessageAbstractDelegate4< T, U, V, W, A > AbstractDelegate
void operator+=(const AbstractDelegate &delegate) const
DelegateList< AbstractDelegate > delegates
void SetExceptionHandler(const AbstractExceptionHandler &handler)
bool operator==(const MessageAbstractDelegate3< T, U, V, A > *c)
ListenerList GetListeners() const
bool HasListeners() const
MessageAbstractDelegate2< T, U, A > * Clone() const
MessageExceptionHandler(R *r, HandleExceptionCallback c)
void Send(T t, U u, V v) const
MessageAbstractDelegate< A > AbstractDelegate
MessageAbstractDelegate1< T, A > AbstractDelegate
virtual MessageAbstractDelegate1 * Clone() const =0
virtual ~MessageAbstractDelegate()
void operator+=(const AbstractDelegate &delegate) const
virtual A Execute(T t, U u, V v) const
void RemoveListener(const AbstractDelegate &delegate) const
MessageAbstractDelegate2< T, U, A > AbstractDelegate
void Send(T t, U u, V v, W w) const
void operator+=(const AbstractDelegate &delegate) const
void RemoveListener(const AbstractDelegate &delegate) const
virtual ~MessageDelegate2()
virtual MessageAbstractDelegate * Clone() const =0
void operator-=(const AbstractDelegate &delegate) const
ListenerList GetListeners() const
void Send4(T t, U u, V v, W w) const
ListType GetDelegates() const
ListenerList GetListeners() const
DelegateList< AbstractDelegate > delegates
virtual void HandleException(const std::exception &exc)=0
MessageAbstractDelegate1< T, A > * Clone() const
DelegateList< AbstractDelegate > delegates
virtual MessageAbstractDelegate4 * Clone() const =0
void operator()(T t, U u, V v) const
bool operator==(const MessageAbstractDelegate4< T, U, V, W, A > *c)
void(R::* HandleExceptionCallback)(const std::exception &)
Event/message/notification class.
virtual AbstractExceptionHandler * Clone() const =0
MessageAbstractDelegate3< T, U, V, A > * Clone() const
virtual ~MessageAbstractDelegate2()
void HandleException(const std::exception &exc) override
void AddListener(const AbstractDelegate &delegate) const
void AddListener(const AbstractDelegate &delegate) const
void RemoveListener(const AbstractDelegate &delegate) const
DelegateList< AbstractDelegate >::ListType ListenerList
void operator-=(const AbstractDelegate &delegate) const
void operator+=(const AbstractDelegate &delegate) const
void RemoveListener(const AbstractDelegate &delegate) const
void AddListener(const AbstractDelegate &delegate) const
bool operator==(const MessageAbstractDelegate< A > *c)
void Remove(const Delegate &d) const
DelegateList< AbstractDelegate >::ListType ListenerList
AbstractExceptionHandler * GetExceptionHandler() const
virtual ~AbstractExceptionHandler()
virtual bool operator==(const MessageAbstractDelegate2 *cmd)=0
bool operator==(const MessageAbstractDelegate2< T, U, A > *c)
ListenerList GetListeners() const
virtual ~MessageAbstractDelegate1()
void operator+=(const AbstractDelegate &delegate) const