2020-01-18 05:38:21 -03:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
|
|
|
|
*
|
2021-04-22 05:24:48 -03:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-01-18 05:38:21 -03:00
|
|
|
*/
|
|
|
|
|
|
2019-02-10 11:28:39 -02:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include <AK/Function.h>
|
2020-02-06 11:04:03 -03:00
|
|
|
#include <LibCore/Object.h>
|
2019-02-10 11:28:39 -02:00
|
|
|
|
2020-02-02 08:34:39 -03:00
|
|
|
namespace Core {
|
|
|
|
|
|
|
|
|
|
class Notifier : public Object {
|
|
|
|
|
C_OBJECT(Notifier)
|
2019-02-10 11:28:39 -02:00
|
|
|
public:
|
2019-06-07 12:13:23 -03:00
|
|
|
enum Event {
|
2019-05-28 06:53:16 -03:00
|
|
|
None = 0,
|
|
|
|
|
Read = 1,
|
|
|
|
|
Write = 2,
|
2019-02-10 11:28:39 -02:00
|
|
|
Exceptional = 4,
|
|
|
|
|
};
|
2019-09-20 10:39:15 -03:00
|
|
|
|
2020-02-02 08:34:39 -03:00
|
|
|
virtual ~Notifier() override;
|
2019-02-10 11:28:39 -02:00
|
|
|
|
2019-07-16 10:02:22 -03:00
|
|
|
void set_enabled(bool);
|
|
|
|
|
|
2019-04-10 12:35:43 -03:00
|
|
|
Function<void()> on_ready_to_read;
|
|
|
|
|
Function<void()> on_ready_to_write;
|
2019-02-10 11:28:39 -02:00
|
|
|
|
2020-09-16 12:42:59 -03:00
|
|
|
void close();
|
|
|
|
|
|
2019-02-10 11:28:39 -02:00
|
|
|
int fd() const { return m_fd; }
|
|
|
|
|
unsigned event_mask() const { return m_event_mask; }
|
2019-04-07 23:53:45 -03:00
|
|
|
void set_event_mask(unsigned event_mask) { m_event_mask = event_mask; }
|
2019-02-10 11:28:39 -02:00
|
|
|
|
2020-02-02 08:34:39 -03:00
|
|
|
void event(Core::Event&) override;
|
2019-07-16 15:31:14 -03:00
|
|
|
|
2019-02-10 11:28:39 -02:00
|
|
|
private:
|
2020-02-02 08:34:39 -03:00
|
|
|
Notifier(int fd, unsigned event_mask, Object* parent = nullptr);
|
2019-09-20 10:39:15 -03:00
|
|
|
|
2019-02-10 11:28:39 -02:00
|
|
|
int m_fd { -1 };
|
|
|
|
|
unsigned m_event_mask { 0 };
|
|
|
|
|
};
|
2020-02-02 08:34:39 -03:00
|
|
|
|
|
|
|
|
}
|