File: invoker.cpp

package info (click to toggle)
libfilezilla 0.54.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 4,504 kB
  • sloc: cpp: 31,105; sh: 4,241; makefile: 375; xml: 37
file content (35 lines) | stat: -rw-r--r-- 680 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include "libfilezilla/invoker.hpp"

#include <optional>

namespace fz {
thread_invoker::thread_invoker(event_loop& loop)
	: event_handler(loop)
{
}

thread_invoker::~thread_invoker()
{
	remove_handler();
}

void thread_invoker::operator()(fz::event_base const& ev)
{
	if (ev.derived_type() == invoker_event::type()) {
		auto const& cb = std::get<0>(static_cast<invoker_event const&>(ev).v_);
		if (cb) {
			cb();
		}
	}
}

invoker_factory get_invoker_factory(event_loop& loop)
{
	return [handler = std::optional<thread_invoker>(), &loop](std::function<void()> const& cb) mutable {
		if (!handler) {
			handler.emplace(loop);
		}
		handler->send_event<invoker_event>(cb);
	};
}
}