5 #ifndef DDS_BaseEventHandlersImpl_h 6 #define DDS_BaseEventHandlersImpl_h 8 #include <boost/signals2/signal.hpp> 10 #define DDS_BEGIN_EVENT_HANDLERS(eventType) \ 12 template <class... Args> \ 13 void dispatchHandlers(eventType _cmd, const SSenderInfo& _sender, Args&... args) \ 15 CBaseEventHandlersImpl<eventType>::dispatchHandlersImpl<>(_cmd, _sender, std::forward<Args>(args)...); \ 19 bool handlerExists(eventType _cmd) const \ 21 return CBaseEventHandlersImpl<eventType>::handlerExistsImpl(_cmd); \ 24 #define DDS_END_EVENT_HANDLERS 26 #define DDS_REGISTER_EVENT_HANDLER(eventType, eventID, funcType) \ 28 template <eventType _cmd, typename func_t> \ 29 void registerHandler( \ 31 typename std::enable_if<std::is_same<std::integral_constant<eventType, _cmd>, \ 32 std::integral_constant<eventType, eventID>>::value && \ 33 std::is_convertible<func_t, std::function<funcType>>::value>::type* = nullptr) \ 35 std::function<funcType> funcHandler(_handler); \ 36 CBaseEventHandlersImpl<eventType>::registerHandlerImpl<_cmd>(funcHandler); \ 39 #define DDS_DECLARE_EVENT_HANDLER_CLASS(theClass) \ 40 using theClass::registerHandler; \ 41 using theClass::dispatchHandlers; \ 42 using theClass::handlerExists; 46 namespace protocol_api
68 template <
typename Event_t>
72 typedef std::map<Event_t, std::unique_ptr<SHandlerHlpFunc>> signalsContainer_t;
75 template <Event_t _cmd,
typename R,
typename... Args>
78 typedef boost::signals2::signal<R(Args...)> signal_t;
80 auto it = m_signals.find(_cmd);
81 if (it == m_signals.end())
84 signal->m_signal.connect(_handler);
85 m_signals.insert(std::make_pair(_cmd, std::move(signal)));
91 signal.connect(_handler);
96 template <
class... Args>
99 typedef boost::signals2::signal<void(
const SSenderInfo&, Args...)> signal_t;
100 auto it = m_signals.find(_cmd);
101 if (it != m_signals.end())
105 signal(_sender, std::forward<Args>(args)...);
112 return (m_signals.find(_cmd) != m_signals.end());
116 signalsContainer_t m_signals;
Definition: BaseEventHandlersImpl.h:69
Helpers for event dispatching.
Definition: BaseEventHandlersImpl.h:54
Definition: BaseEventHandlersImpl.h:48
T m_signal
Definition: BaseEventHandlersImpl.h:60
Definition: BaseEventHandlersImpl.h:58
Miscellaneous functions and helpers are located here.
Definition: AgentConnectionManager.h:13
void registerHandlerImpl(std::function< R(Args...)> _handler)
Definition: BaseEventHandlersImpl.h:76
SHandlerHlpBaseFunc()
Definition: BaseEventHandlersImpl.h:62
bool handlerExistsImpl(Event_t _cmd) const
Definition: BaseEventHandlersImpl.h:110
void dispatchHandlersImpl(Event_t _cmd, const SSenderInfo &_sender, Args &&... args)
Definition: BaseEventHandlersImpl.h:97
uint64_t m_ID
Definition: BaseEventHandlersImpl.h:50