Notifier.h 990 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /*
  2. * Copyright (c) 2018-2023, Andreas Kling <andreas@ladybird.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <AK/Function.h>
  8. #include <LibCore/Event.h>
  9. #include <LibCore/EventReceiver.h>
  10. #include <pthread.h>
  11. namespace Core {
  12. class Notifier final : public EventReceiver {
  13. C_OBJECT(Notifier);
  14. public:
  15. using Type = NotificationType;
  16. virtual ~Notifier() override;
  17. void set_enabled(bool);
  18. Function<void()> on_activation;
  19. void close();
  20. int fd() const { return m_fd; }
  21. Type type() const { return m_type; }
  22. void set_type(Type type);
  23. void event(Core::Event&) override;
  24. void set_owner_thread(pthread_t owner_thread) { m_owner_thread = owner_thread; }
  25. pthread_t owner_thread() const { return m_owner_thread; }
  26. private:
  27. Notifier(int fd, Type type, EventReceiver* parent = nullptr);
  28. int m_fd { -1 };
  29. bool m_is_enabled { false };
  30. pthread_t m_owner_thread {};
  31. Type m_type { Type::None };
  32. };
  33. }