-
Notifications
You must be signed in to change notification settings - Fork 120
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor EventLoop class and introduce a new virtual-base class Event…
…LoopInterface (#1175)
- Loading branch information
Showing
9 changed files
with
645 additions
and
385 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
|
||
/* | ||
* SPDX-FileCopyrightText: 2015-2015 CSSlayer <[email protected]> | ||
* | ||
* SPDX-License-Identifier: LGPL-2.1-or-later | ||
* | ||
*/ | ||
|
||
#include "event.h" | ||
#include <cstdint> | ||
#include <cstring> | ||
#include <ctime> | ||
#include <memory> | ||
#include <utility> | ||
#include "event_p.h" | ||
#include "eventloopinterface.h" | ||
#include "macros.h" | ||
|
||
namespace fcitx { | ||
|
||
class EventLoopPrivate { | ||
public: | ||
EventLoopPrivate(std::unique_ptr<EventLoopInterface> impl) | ||
: impl_(std::move(impl)) {} | ||
|
||
std::unique_ptr<EventLoopInterface> impl_; | ||
}; | ||
|
||
EventLoop::EventLoop() : EventLoop(createDefaultEventLoop()) {} | ||
|
||
EventLoop::EventLoop(std::unique_ptr<EventLoopInterface> impl) | ||
: d_ptr(std::make_unique<EventLoopPrivate>(std::move(impl))) {} | ||
|
||
EventLoop::~EventLoop() = default; | ||
|
||
const char *EventLoop::impl() { return defaultEventLoopImplementation(); } | ||
|
||
const char *EventLoop::implementation() const { | ||
FCITX_D(); | ||
return d->impl_->implementation(); | ||
} | ||
|
||
void *EventLoop::nativeHandle() { | ||
FCITX_D(); | ||
return d->impl_->nativeHandle(); | ||
} | ||
|
||
bool EventLoop::exec() { | ||
FCITX_D(); | ||
return d->impl_->exec(); | ||
} | ||
|
||
void EventLoop::exit() { | ||
FCITX_D(); | ||
return d->impl_->exit(); | ||
} | ||
|
||
std::unique_ptr<EventSourceIO> EventLoop::addIOEvent(int fd, IOEventFlags flags, | ||
IOCallback callback) { | ||
FCITX_D(); | ||
return d->impl_->addIOEvent(fd, flags, std::move(callback)); | ||
} | ||
|
||
std::unique_ptr<EventSourceTime> | ||
EventLoop::addTimeEvent(clockid_t clock, uint64_t usec, uint64_t accuracy, | ||
TimeCallback callback) { | ||
FCITX_D(); | ||
return d->impl_->addTimeEvent(clock, usec, accuracy, std::move(callback)); | ||
} | ||
|
||
std::unique_ptr<EventSource> EventLoop::addExitEvent(EventCallback callback) { | ||
FCITX_D(); | ||
return d->impl_->addExitEvent(std::move(callback)); | ||
} | ||
|
||
std::unique_ptr<EventSource> EventLoop::addDeferEvent(EventCallback callback) { | ||
FCITX_D(); | ||
return d->impl_->addDeferEvent(std::move(callback)); | ||
} | ||
|
||
std::unique_ptr<EventSource> EventLoop::addPostEvent(EventCallback callback) { | ||
FCITX_D(); | ||
return d->impl_->addPostEvent(std::move(callback)); | ||
} | ||
|
||
} // namespace fcitx |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.