1#ifndef LIBFILEZILLA_EVENT_HANDLER
2#define LIBFILEZILLA_EVENT_HANDLER
60class FZ_PUBLIC_SYMBOL event_handler
63 event_handler() =
delete;
65 explicit event_handler(event_loop& loop);
66 virtual ~event_handler();
68 event_handler(event_handler
const& h);
71 event_handler& operator=(event_handler
const&) =
delete;
95 template<
typename T,
typename... Args>
97 event_loop_.send_event(
this,
new T(std::forward<Args>(args)...),
true);
101 void send_event(T* evt) {
102 event_loop_.send_event(
this, evt,
true);
109 event_loop_.send_event(
this, evt,
false);
173 void filter_events(std::function<
bool(
event_base& ev)>
const& filter) {
174 event_loop_.filter_events([&](event_handler*& h,
event_base& ev) {
182 void resend_current_event() {
183 event_loop_.resend_current_event();
186 void remove_events(event_source
const*
const source);
189 void remove_events() {
190 remove_events_of_type(T::type());
193 event_loop & event_loop_;
196 void remove_events_of_type(
size_t t);
198 friend class event_loop;
201 void remove_from_parent();
202 event_handler* parent_{};
203 event_handler* next_{};
204 event_handler* child_{};
221template<
typename T,
typename F>
226 T
const* e =
static_cast<T const*
>(&ev);
227 std::apply(std::forward<F>(f), e->v_);
247template<
typename T,
typename H,
typename F>
252 T
const* e =
static_cast<T const*
>(&ev);
253 apply(h, std::forward<F>(f), e->v_);
276template<
typename T,
typename ... Ts,
typename H,
typename F,
typename ... Fs>
283 return dispatch<Ts...>(ev, h, std::forward<Fs>(fs)...);
The duration class represents a time interval in milliseconds.
Definition time.hpp:291
Common base class for all events.
Definition event.hpp:23
timer_id add_timer(duration const &interval, bool one_shot)
Adds a timer, returns the timer id.
void stop_timer(timer_id id)
void remove_handler()
Deactivates handler, removes all pending events and stops all timers for this handler.
timer_id stop_add_timer(timer_id id, duration const &interval, bool one_shot)
virtual void operator()(event_base const &)=0
Called by the event loop in the worker thread with the event to process.
timer_id add_timer(monotonic_clock const &deadline, duration const &interval={})
Adds a timer, returns the timer id.
void send_event(Args &&... args)
Sends the passed event asynchronously to the handler.
Definition event_handler.hpp:96
void send_persistent_event(T *evt)
Be careful with lifetime.
Definition event_handler.hpp:108
timer_id stop_add_timer(timer_id id, monotonic_clock const &deadline, duration const &interval={})
A monotonic clock (aka steady clock) is independent from walltime.
Definition time.hpp:403
A simple threaded event loop for the typesafe event system.
The namespace used by libfilezilla.
Definition apply.hpp:17
event_handler_option
Simple handler for asynchronous event processing.
Definition event_handler.hpp:56
bool same_type(event_base const &ev)
Definition event.hpp:154
bool dispatch(event_base const &ev, F &&f)
Dispatch for simple_event<> based events to simple functors.
Definition event_handler.hpp:222
auto apply(Obj &&obj, F &&f, Tuple &&args) -> decltype(apply_(std::forward< Obj >(obj), std::forward< F >(f), std::forward< Tuple >(args), Seq()))
Apply tuple to pointer to member.
Definition apply.hpp:48