17 #include "eventloopinterface.h" 25 : impl_(std::move(impl)) {
27 throw std::runtime_error(
"No available event loop implementation.");
31 std::unique_ptr<EventLoopInterface> impl_;
33 static EventLoopFactory factory_;
36 EventLoopFactory EventLoopPrivate::factory_ = createDefaultEventLoop;
40 EventLoopPrivate::factory_ = std::move(factory);
42 EventLoopPrivate::factory_ = createDefaultEventLoop;
46 EventLoop::EventLoop() :
EventLoop(EventLoopPrivate::factory_()) {}
48 EventLoop::EventLoop(std::unique_ptr<EventLoopInterface> impl)
49 : d_ptr(std::make_unique<EventLoopPrivate>(std::move(impl))) {}
51 EventLoop::~EventLoop() =
default;
57 return d->impl_->implementation();
60 void *EventLoop::nativeHandle() {
62 return d->impl_->nativeHandle();
65 bool EventLoop::exec() {
67 return d->impl_->exec();
70 void EventLoop::exit() {
72 return d->impl_->exit();
75 std::unique_ptr<EventSourceIO> EventLoop::addIOEvent(
int fd,
IOEventFlags flags,
76 IOCallback callback) {
78 return d->impl_->addIOEvent(fd, flags, std::move(callback));
81 std::unique_ptr<EventSourceTime>
82 EventLoop::addTimeEvent(clockid_t clock, uint64_t usec, uint64_t accuracy,
83 TimeCallback callback) {
85 return d->impl_->addTimeEvent(clock, usec, accuracy, std::move(callback));
88 std::unique_ptr<EventSource> EventLoop::addExitEvent(EventCallback callback) {
90 return d->impl_->addExitEvent(std::move(callback));
93 std::unique_ptr<EventSource> EventLoop::addDeferEvent(EventCallback callback) {
95 return d->impl_->addDeferEvent(std::move(callback));
98 std::unique_ptr<EventSource> EventLoop::addPostEvent(EventCallback callback) {
100 return d->impl_->addPostEvent(std::move(callback));
103 std::unique_ptr<EventSourceAsync>
106 if (
auto *v2 = dynamic_cast<EventLoopInterfaceV2 *>(d->impl_.get())) {
107 return v2->addAsyncEvent(std::move(callback));
FCITX_NODISCARD std::unique_ptr< EventSourceAsync > addAsyncEvent(EventCallback callback)
Add an async event that is safe to be triggered from another thread.
const char * implementation() const
Return the name of implementation of event loop.
static FCITXUTILS_DEPRECATED const char * impl()
Return the default implementation name.
static void setEventLoopFactory(EventLoopFactory factory)
Set an external event loop implementation.