1 #ifndef _LDAPLUSPLUS_EVENTS_EVENTS_HPP_ 2 #define _LDAPLUSPLUS_EVENTS_EVENTS_HPP_ 9 #include <unordered_set> 24 Event(std::string
id);
30 const std::string &
id()
const;
46 virtual void on_event(std::shared_ptr<Event> event) = 0;
60 void on_event(std::shared_ptr<Event> event)
override;
63 std::function<void(std::shared_ptr<Event>)> listener_;
82 virtual void add_listener(std::shared_ptr<EventListenerInterface> listener) = 0;
93 virtual void remove_listener(std::shared_ptr<EventListenerInterface> listener) = 0;
105 virtual void dispatch(std::shared_ptr<Event> event) = 0;
117 std::function<
void(std::shared_ptr<Event>)> listener
119 auto l = std::make_shared<FunctionEventListener>(listener);
136 template <
class ListenerType,
typename... Args>
138 auto l = std::make_shared<ListenerType>(args...);
151 template <
class EventType,
typename... Args>
153 auto event = std::make_shared<EventType>(args...);
169 void add_listener(std::shared_ptr<EventListenerInterface> listener)
override;
170 void remove_listener(std::shared_ptr<EventListenerInterface> listener)
override;
171 void dispatch(std::shared_ptr<Event> event)
override;
174 std::list<std::shared_ptr<EventListenerInterface> > listeners_;
186 event_dispatcher_(std::make_shared<EventDispatcher>())
189 std::shared_ptr<EventDispatcherInterface> get_event_dispatcher() {
190 return event_dispatcher_;
193 void set_event_dispatcher(std::shared_ptr<EventDispatcherInterface> dispatcher) {
194 event_dispatcher_ = dispatcher;
198 std::shared_ptr<EventDispatcherInterface> event_dispatcher_;
209 virtual void add_listener(std::shared_ptr<EventListenerInterface> listener)
override;
210 virtual void remove_listener(std::shared_ptr<EventListenerInterface> listener)
override;
211 virtual void dispatch(std::shared_ptr<Event> event)
override;
220 void process_events();
223 std::mutex listeners_mutex_;
224 std::list<std::shared_ptr<EventListenerInterface> > listeners_;
226 std::mutex deleted_listeners_mutex_;
227 std::unordered_set<std::shared_ptr<EventListenerInterface> > deleted_listeners_;
229 std::mutex events_mutex_;
230 std::list<std::shared_ptr<Event> > events_;
246 virtual void dispatch(std::shared_ptr<Event> event)
override;
249 std::thread::id thread_id_;
255 #endif // _LDAPLUSPLUS_EVENTS_EVENTS_HPP_ Definition: Events.hpp:166
void dispatch(Args...args)
Definition: Events.hpp:152
const std::string & id() const
Definition: Events.cpp:11
std::shared_ptr< EventListenerInterface > add_listener(Args...args)
Definition: Events.hpp:137
Definition: Events.hpp:70
Definition: Events.hpp:40
Event(std::string id)
Definition: Events.cpp:8
Definition: Events.hpp:18
Definition: Events.hpp:55
std::shared_ptr< EventListenerInterface > add_listener(std::function< void(std::shared_ptr< Event >)> listener)
Definition: Events.hpp:116
Definition: Events.hpp:241
Definition: Events.hpp:206
Definition: Events.hpp:182
Definition: Document.hpp:11