1 #ifndef LIBFILEZILLA_INVOKER_HEADER
2 #define LIBFILEZILLA_INVOKER_HEADER
13 struct invoker_event_type{};
16 typedef simple_event<invoker_event_type, std::function<void()>> invoker_event;
19 class FZ_PUBLIC_SYMBOL thread_invoker final :
public event_handler
22 thread_invoker(event_loop& loop);
23 virtual ~thread_invoker();
25 virtual void operator()(event_base
const& ev)
override;
29 template<
typename... Args>
30 std::function<void(Args...)> do_make_invoker(event_loop& loop, std::function<
void(Args...)> && f)
32 return [handler = thread_invoker(loop), f](Args&&... args)
mutable {
33 auto cb = [f, targs = std::make_tuple(std::forward<Args>(args)...)] {
36 handler.send_event<invoker_event>(std::move(cb));
43 template<
typename Ret,
typename F,
typename ... Args>
44 constexpr std::function<Ret(Args...)> get_func_type(Ret(F::*)(Args...)
const);
56 return do_make_invoker(loop, decltype(get_func_type(&F::operator()))(std::forward<F>(f)));
61 return do_make_invoker(h.event_loop_, decltype(get_func_type(&F::operator()))(std::forward<F>(f)));
65 typedef std::function<void(std::function<
void()>)> invoker_factory;
76 template<
typename... Args>
77 std::function<void(Args...)> do_make_invoker(invoker_factory
const& inv, std::function<
void(Args...)> && f)
79 return [inv, f](Args&&... args)
mutable {
80 auto cb = [f, targs = std::make_tuple(std::forward<Args>(args)...)] {
97 return do_make_invoker(inv, decltype(get_func_type(&F::operator()))(std::forward<F>(f)));
A threaded event loop that supports sending events and timers.
Definition: event_loop.hpp:34
Declares the event_handler class.
The namespace used by libfilezilla.
Definition: apply.hpp:17
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
invoker_factory get_invoker_factory(event_loop &loop)
Creates an invoker factory.
auto make_invoker(event_loop &loop, F &&f)
Wraps the passed function, so that it is always invoked in the context of the loop.
Definition: invoker.hpp:54