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