2020-01-18 09:38:21 +01:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
|
|
|
|
*
|
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>
|
2020-02-06 15:04:03 +01:00
|
|
|
#include <LibCore/Object.h>
|
2019-02-10 14:28:39 +01:00
|
|
|
|
2020-02-02 12:34:39 +01:00
|
|
|
namespace Core {
|
|
|
|
|
|
|
|
|
|
class Notifier : public Object {
|
|
|
|
|
C_OBJECT(Notifier)
|
2019-02-10 14:28:39 +01:00
|
|
|
public:
|
2019-06-07 17:13:23 +02:00
|
|
|
enum Event {
|
2019-05-28 11:53:16 +02:00
|
|
|
None = 0,
|
|
|
|
|
Read = 1,
|
|
|
|
|
Write = 2,
|
2019-02-10 14:28:39 +01:00
|
|
|
Exceptional = 4,
|
|
|
|
|
};
|
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);
|
|
|
|
|
|
2019-04-10 17:35:43 +02:00
|
|
|
Function<void()> on_ready_to_read;
|
|
|
|
|
Function<void()> on_ready_to_write;
|
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; }
|
|
|
|
|
unsigned event_mask() const { return m_event_mask; }
|
2019-04-08 04:53:45 +02:00
|
|
|
void set_event_mask(unsigned event_mask) { m_event_mask = event_mask; }
|
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
|
|
|
|
2019-02-10 14:28:39 +01:00
|
|
|
private:
|
2020-02-02 12:34:39 +01:00
|
|
|
Notifier(int fd, unsigned event_mask, Object* parent = nullptr);
|
2019-09-20 15:39:15 +02:00
|
|
|
|
2019-02-10 14:28:39 +01:00
|
|
|
int m_fd { -1 };
|
|
|
|
|
unsigned m_event_mask { 0 };
|
|
|
|
|
};
|
2020-02-02 12:34:39 +01:00
|
|
|
|
|
|
|
|
}
|