2020-01-18 09:38:21 +01:00
|
|
|
/*
|
2024-10-04 13:19:50 +02:00
|
|
|
* Copyright (c) 2018-2023, Andreas Kling <andreas@ladybird.org>
|
2020-01-18 09:38:21 +01:00
|
|
|
*
|
2021-04-22 01:24:48 -07:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-01-18 09:38:21 +01:00
|
|
|
*/
|
|
|
|
|
2019-02-10 14:28:39 +01:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <AK/Function.h>
|
2024-02-01 20:21:15 -05:00
|
|
|
#include <LibCore/Event.h>
|
2023-08-06 18:09:39 +02:00
|
|
|
#include <LibCore/EventReceiver.h>
|
2024-10-31 12:44:19 +05:00
|
|
|
#include <pthread.h>
|
2019-02-10 14:28:39 +01:00
|
|
|
|
2020-02-02 12:34:39 +01:00
|
|
|
namespace Core {
|
|
|
|
|
2023-08-06 18:09:39 +02:00
|
|
|
class Notifier final : public EventReceiver {
|
2023-04-23 20:59:32 +02:00
|
|
|
C_OBJECT(Notifier);
|
|
|
|
|
2019-02-10 14:28:39 +01:00
|
|
|
public:
|
2024-02-01 20:21:15 -05:00
|
|
|
using Type = NotificationType;
|
2019-09-20 15:39:15 +02:00
|
|
|
|
2020-02-02 12:34:39 +01:00
|
|
|
virtual ~Notifier() override;
|
2019-02-10 14:28:39 +01:00
|
|
|
|
2019-07-16 15:02:22 +02:00
|
|
|
void set_enabled(bool);
|
|
|
|
|
2023-04-23 20:59:32 +02:00
|
|
|
Function<void()> on_activation;
|
2019-02-10 14:28:39 +01:00
|
|
|
|
2020-09-16 09:42:59 -06:00
|
|
|
void close();
|
|
|
|
|
2019-02-10 14:28:39 +01:00
|
|
|
int fd() const { return m_fd; }
|
2023-04-23 20:59:32 +02:00
|
|
|
Type type() const { return m_type; }
|
2024-02-01 20:21:15 -05:00
|
|
|
void set_type(Type type);
|
2019-02-10 14:28:39 +01:00
|
|
|
|
2020-02-02 12:34:39 +01:00
|
|
|
void event(Core::Event&) override;
|
2019-07-16 20:31:14 +02:00
|
|
|
|
2024-05-08 20:10:00 +02:00
|
|
|
void set_owner_thread(pthread_t owner_thread) { m_owner_thread = owner_thread; }
|
|
|
|
pthread_t owner_thread() const { return m_owner_thread; }
|
|
|
|
|
2019-02-10 14:28:39 +01:00
|
|
|
private:
|
2023-08-06 18:09:39 +02:00
|
|
|
Notifier(int fd, Type type, EventReceiver* parent = nullptr);
|
2019-09-20 15:39:15 +02:00
|
|
|
|
2019-02-10 14:28:39 +01:00
|
|
|
int m_fd { -1 };
|
2024-02-01 20:21:15 -05:00
|
|
|
bool m_is_enabled { false };
|
2024-11-16 12:44:30 +05:00
|
|
|
pthread_t m_owner_thread {};
|
2023-04-23 20:59:32 +02:00
|
|
|
Type m_type { Type::None };
|
2019-02-10 14:28:39 +01:00
|
|
|
};
|
2020-02-02 12:34:39 +01:00
|
|
|
|
|
|
|
}
|