2019-02-10 14:28:39 +01:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <AK/Function.h>
|
2019-09-20 15:39:15 +02:00
|
|
|
#include <LibCore/CObject.h>
|
2019-02-10 14:28:39 +01:00
|
|
|
|
2019-07-16 20:31:14 +02:00
|
|
|
class CNotifier : public CObject {
|
2019-07-25 19:49:28 +02:00
|
|
|
C_OBJECT(CNotifier)
|
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
|
|
|
|
2019-07-25 19:49:28 +02:00
|
|
|
virtual ~CNotifier() 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
|
|
|
|
|
|
|
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
|
|
|
|
2019-07-25 19:49:28 +02:00
|
|
|
void event(CEvent&) override;
|
2019-07-16 20:31:14 +02:00
|
|
|
|
2019-02-10 14:28:39 +01:00
|
|
|
private:
|
2019-09-21 15:18:12 +02:00
|
|
|
CNotifier(int fd, unsigned event_mask, CObject* 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 };
|
|
|
|
};
|