2023-04-24 10:25:14 +00:00
|
|
|
/*
|
2024-10-04 11:19:50 +00:00
|
|
|
* Copyright (c) 2023, Andreas Kling <andreas@ladybird.org>
|
2023-04-24 10:25:14 +00:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2023-03-17 18:50:39 +00:00
|
|
|
#include <AK/Time.h>
|
2023-04-24 10:25:14 +00:00
|
|
|
#include <LibCore/EventLoopImplementation.h>
|
|
|
|
|
|
|
|
namespace Core {
|
|
|
|
|
2023-04-25 15:38:48 +00:00
|
|
|
class EventLoopManagerUnix final : public EventLoopManager {
|
2023-04-24 10:25:14 +00:00
|
|
|
public:
|
2023-04-25 15:38:48 +00:00
|
|
|
virtual ~EventLoopManagerUnix() override;
|
2023-04-24 10:25:14 +00:00
|
|
|
|
2023-04-25 15:38:48 +00:00
|
|
|
virtual NonnullOwnPtr<EventLoopImplementation> make_implementation() override;
|
2023-04-24 10:25:14 +00:00
|
|
|
|
2024-02-18 05:11:38 +00:00
|
|
|
virtual intptr_t register_timer(EventReceiver&, int milliseconds, bool should_reload, TimerShouldFireWhenNotVisible) override;
|
|
|
|
virtual void unregister_timer(intptr_t timer_id) override;
|
2023-04-24 10:25:14 +00:00
|
|
|
|
|
|
|
virtual void register_notifier(Notifier&) override;
|
|
|
|
virtual void unregister_notifier(Notifier&) override;
|
|
|
|
|
2023-04-25 14:53:07 +00:00
|
|
|
virtual void did_post_event() override;
|
|
|
|
|
2023-04-24 10:25:14 +00:00
|
|
|
virtual int register_signal(int signal_number, Function<void(int)> handler) override;
|
|
|
|
virtual void unregister_signal(int handler_id) override;
|
|
|
|
|
2023-04-25 15:38:48 +00:00
|
|
|
void wait_for_events(EventLoopImplementation::PumpMode);
|
2023-03-17 18:50:39 +00:00
|
|
|
static Optional<MonotonicTime> get_next_timer_expiration();
|
2023-04-25 15:38:48 +00:00
|
|
|
|
2023-04-24 10:25:14 +00:00
|
|
|
private:
|
|
|
|
void dispatch_signal(int signal_number);
|
|
|
|
static void handle_signal(int signal_number);
|
2023-04-25 15:38:48 +00:00
|
|
|
};
|
2023-04-24 10:25:14 +00:00
|
|
|
|
2023-04-25 15:38:48 +00:00
|
|
|
class EventLoopImplementationUnix final : public EventLoopImplementation {
|
|
|
|
public:
|
|
|
|
static NonnullOwnPtr<EventLoopImplementationUnix> create() { return make<EventLoopImplementationUnix>(); }
|
|
|
|
|
|
|
|
EventLoopImplementationUnix();
|
|
|
|
virtual ~EventLoopImplementationUnix();
|
|
|
|
|
|
|
|
virtual int exec() override;
|
|
|
|
virtual size_t pump(PumpMode) override;
|
|
|
|
virtual void quit(int) override;
|
|
|
|
|
|
|
|
virtual void wake() override;
|
|
|
|
|
|
|
|
virtual void unquit() override;
|
|
|
|
virtual bool was_exit_requested() const override;
|
|
|
|
virtual void notify_forked_and_in_child() override;
|
2023-08-06 16:09:39 +00:00
|
|
|
virtual void post_event(EventReceiver& receiver, NonnullOwnPtr<Event>&&) override;
|
2023-04-25 15:38:48 +00:00
|
|
|
|
|
|
|
private:
|
2023-04-24 10:25:14 +00:00
|
|
|
bool m_exit_requested { false };
|
|
|
|
int m_exit_code { 0 };
|
|
|
|
|
|
|
|
// The wake pipe of this event loop needs to be accessible from other threads.
|
2024-03-12 18:59:17 +00:00
|
|
|
Array<int, 2>& m_wake_pipe_fds;
|
2023-04-24 10:25:14 +00:00
|
|
|
};
|
|
|
|
|
2024-10-31 07:44:19 +00:00
|
|
|
using EventLoopManagerPlatform = EventLoopManagerUnix;
|
|
|
|
|
2023-04-24 10:25:14 +00:00
|
|
|
}
|