1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 06:17:35 +00:00

LibCore+Ladybird: Add EventLoopManager interface for persistent state

Things such as timers and notifiers aren't specific to one instance of
Core::EventLoop, so let's not tie them down to EventLoopImplementation.

Instead, move those APIs + signals & a few other things to a new
EventLoopManager interface. EventLoopManager also knows how to create a
new EventLoopImplementation object.
This commit is contained in:
Andreas Kling 2023-04-25 17:38:48 +02:00
parent c21eb30a2b
commit 7b963e1e98
11 changed files with 177 additions and 118 deletions

View file

@ -16,16 +16,11 @@
namespace Ladybird {
class EventLoopImplementationQt final : public Core::EventLoopImplementation {
class EventLoopManagerQt final : public Core::EventLoopManager {
public:
static NonnullOwnPtr<EventLoopImplementationQt> create() { return adopt_own(*new EventLoopImplementationQt); }
virtual ~EventLoopImplementationQt() override;
virtual int exec() override;
virtual size_t pump(PumpMode) override;
virtual void quit(int) override;
virtual void wake() override;
EventLoopManagerQt();
virtual ~EventLoopManagerQt() override;
virtual NonnullOwnPtr<Core::EventLoopImplementation> make_implementation() override;
virtual void deferred_invoke(Function<void()>) override;
@ -37,21 +32,41 @@ public:
virtual void did_post_event() override;
virtual void wake() override;
// FIXME: These APIs only exist for obscure use-cases inside SerenityOS. Try to get rid of them.
virtual int register_signal(int, Function<void(int)>) override { return 0; }
virtual void unregister_signal(int) override { }
private:
QTimer m_process_core_events_timer;
};
class EventLoopImplementationQt final : public Core::EventLoopImplementation {
public:
static NonnullOwnPtr<EventLoopImplementationQt> create() { return adopt_own(*new EventLoopImplementationQt); }
virtual ~EventLoopImplementationQt() override;
virtual int exec() override;
virtual size_t pump(PumpMode) override;
virtual void quit(int) override;
virtual void wake() override;
// FIXME: These APIs only exist for obscure use-cases inside SerenityOS. Try to get rid of them.
virtual void unquit() override { }
virtual bool was_exit_requested() const override { return false; }
virtual void notify_forked_and_in_child() override { }
virtual int register_signal(int, Function<void(int)>) override { return 0; }
virtual void unregister_signal(int) override { }
void set_main_loop() { m_main_loop = true; }
private:
friend class EventLoopManagerQt;
EventLoopImplementationQt();
bool is_main_loop() const { return m_main_loop; }
QEventLoop m_event_loop;
QTimer m_process_core_events_timer;
bool m_main_loop { false };
};