6 #include <Poco/Exception.h>
7 #include <Poco/SharedPtr.h>
9 #include "util/AsyncExecutor.h"
10 #include "util/ClassInfo.h"
11 #include "util/Loggable.h"
12 #include "util/Once.h"
23 template <
typename Listener>
29 void setAsyncExecutor(AsyncExecutor::Ptr executor);
30 AsyncExecutor::Ptr asyncExecutor()
const;
32 void addListener(
typename Listener::Ptr listener);
33 void clearListeners();
54 template <
typename Event,
typename Method>
55 void fireEvent(
const Event &e,
const Method &m);
58 AsyncExecutor::Ptr m_executor;
59 std::list<typename Listener::Ptr> m_listeners;
62 template <
typename Listener>
67 template <
typename Listener>
68 EventSource<Listener>::~EventSource()
72 template <
typename Listener>
73 void EventSource<Listener>::setAsyncExecutor(AsyncExecutor::Ptr executor)
75 m_executor = executor;
78 template <
typename Listener>
79 AsyncExecutor::Ptr EventSource<Listener>::asyncExecutor()
const
84 template <
typename Listener>
85 void EventSource<Listener>::addListener(
typename Listener::Ptr listener)
87 m_listeners.push_back(listener);
90 template <
typename Listener>
91 void EventSource<Listener>::clearListeners()
96 template <
typename Listener>
template <
typename Event,
typename Method>
101 if (m_executor.isNull()) {
103 poco_warning(logger(),
"no async executor is set");
108 auto copy = m_listeners;
110 m_executor->invoke([=]() {
111 if (logger().debug()) {
112 logger().debug(
"firing event " +
ClassInfo(e).name(),
116 for (
auto listener : copy) {
120 BEEEON_CATCH_CHAIN_MESSAGE(
122 "failed to deliver event " +
ClassInfo(e).name())
EventSource implements common logic for firing events to listeners.
Definition: EventSource.h:24
void fireEvent(const Event &e, const Method &m)
Definition: EventSource.h:97
Definition: ClassInfo.h:9
Definition: Loggable.h:19