10 #include <sys/types.h> 16 #include "eventloopinterface.h" 28 : impl_(std::move(impl)) {
30 throw std::runtime_error(
"No available event loop implementation.");
34 std::unique_ptr<EventLoopInterface> impl_;
36 static EventLoopFactory factory_;
39 EventLoopFactory EventLoopPrivate::factory_ = createDefaultEventLoop;
43 EventLoopPrivate::factory_ = std::move(factory);
45 EventLoopPrivate::factory_ = createDefaultEventLoop;
49 EventLoop::EventLoop() :
EventLoop(EventLoopPrivate::factory_()) {}
51 EventLoop::EventLoop(std::unique_ptr<EventLoopInterface> impl)
52 : d_ptr(std::make_unique<EventLoopPrivate>(std::move(impl))) {}
54 EventLoop::~EventLoop() =
default;
60 return d->impl_->implementation();
63 void *EventLoop::nativeHandle() {
65 return d->impl_->nativeHandle();
68 bool EventLoop::exec() {
70 return d->impl_->exec();
73 void EventLoop::exit() {
78 std::unique_ptr<EventSourceIO> EventLoop::addIOEvent(
int fd,
IOEventFlags flags,
79 IOCallback callback) {
81 return d->impl_->addIOEvent(fd, flags, std::move(callback));
84 std::unique_ptr<EventSourceTime>
85 EventLoop::addTimeEvent(clockid_t clock, uint64_t usec, uint64_t accuracy,
86 TimeCallback callback) {
88 return d->impl_->addTimeEvent(clock, usec, accuracy, std::move(callback));
91 std::unique_ptr<EventSource> EventLoop::addExitEvent(EventCallback callback) {
93 return d->impl_->addExitEvent(std::move(callback));
96 std::unique_ptr<EventSource> EventLoop::addDeferEvent(EventCallback callback) {
98 return d->impl_->addDeferEvent(std::move(callback));
101 std::unique_ptr<EventSource> EventLoop::addPostEvent(EventCallback callback) {
103 return d->impl_->addPostEvent(std::move(callback));
106 std::unique_ptr<EventSourceAsync>
109 if (
auto *v2 = dynamic_cast<EventLoopInterfaceV2 *>(d->impl_.get())) {
110 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.