EventLoopImplementation.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /*
  2. * Copyright (c) 2022-2023, Andreas Kling <kling@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <AK/Function.h>
  8. #include <LibCore/Forward.h>
  9. namespace Core {
  10. class EventLoopImplementation;
  11. class ThreadEventQueue;
  12. class EventLoopManager {
  13. public:
  14. static EventLoopManager& the();
  15. static void install(EventLoopManager&);
  16. virtual ~EventLoopManager();
  17. virtual NonnullOwnPtr<EventLoopImplementation> make_implementation() = 0;
  18. virtual int register_timer(EventReceiver&, int milliseconds, bool should_reload, TimerShouldFireWhenNotVisible) = 0;
  19. virtual bool unregister_timer(int timer_id) = 0;
  20. virtual void register_notifier(Notifier&) = 0;
  21. virtual void unregister_notifier(Notifier&) = 0;
  22. virtual void did_post_event() = 0;
  23. // FIXME: These APIs only exist for obscure use-cases inside SerenityOS. Try to get rid of them.
  24. virtual int register_signal(int signal_number, Function<void(int)> handler) = 0;
  25. virtual void unregister_signal(int handler_id) = 0;
  26. protected:
  27. EventLoopManager();
  28. };
  29. class EventLoopImplementation {
  30. public:
  31. virtual ~EventLoopImplementation();
  32. enum class PumpMode {
  33. WaitForEvents,
  34. DontWaitForEvents,
  35. };
  36. virtual int exec() = 0;
  37. virtual size_t pump(PumpMode) = 0;
  38. virtual void quit(int) = 0;
  39. virtual void wake() = 0;
  40. virtual void post_event(EventReceiver& receiver, NonnullOwnPtr<Event>&&) = 0;
  41. // FIXME: These APIs only exist for obscure use-cases inside SerenityOS. Try to get rid of them.
  42. virtual void unquit() = 0;
  43. virtual bool was_exit_requested() const = 0;
  44. virtual void notify_forked_and_in_child() = 0;
  45. protected:
  46. EventLoopImplementation();
  47. ThreadEventQueue& m_thread_event_queue;
  48. };
  49. }