2019-02-10 13:28:39 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <AK/Function.h>
|
2019-07-16 18:31:14 +00:00
|
|
|
#include "CObject.h"
|
2019-02-10 13:28:39 +00:00
|
|
|
|
2019-07-16 18:31:14 +00:00
|
|
|
class CNotifier : public CObject {
|
2019-07-25 17:49:28 +00:00
|
|
|
C_OBJECT(CNotifier)
|
2019-02-10 13:28:39 +00:00
|
|
|
public:
|
2019-06-07 15:13:23 +00:00
|
|
|
enum Event {
|
2019-05-28 09:53:16 +00:00
|
|
|
None = 0,
|
|
|
|
Read = 1,
|
|
|
|
Write = 2,
|
2019-02-10 13:28:39 +00:00
|
|
|
Exceptional = 4,
|
|
|
|
};
|
2019-08-18 09:54:39 +00:00
|
|
|
CNotifier(int fd, unsigned event_mask, CObject* parent = nullptr);
|
2019-07-25 17:49:28 +00:00
|
|
|
virtual ~CNotifier() override;
|
2019-02-10 13:28:39 +00:00
|
|
|
|
2019-07-16 13:02:22 +00:00
|
|
|
void set_enabled(bool);
|
|
|
|
|
2019-04-10 15:35:43 +00:00
|
|
|
Function<void()> on_ready_to_read;
|
|
|
|
Function<void()> on_ready_to_write;
|
2019-02-10 13:28:39 +00:00
|
|
|
|
|
|
|
int fd() const { return m_fd; }
|
|
|
|
unsigned event_mask() const { return m_event_mask; }
|
2019-04-08 02:53:45 +00:00
|
|
|
void set_event_mask(unsigned event_mask) { m_event_mask = event_mask; }
|
2019-02-10 13:28:39 +00:00
|
|
|
|
2019-07-25 17:49:28 +00:00
|
|
|
void event(CEvent&) override;
|
2019-07-16 18:31:14 +00:00
|
|
|
|
2019-02-10 13:28:39 +00:00
|
|
|
private:
|
|
|
|
int m_fd { -1 };
|
|
|
|
unsigned m_event_mask { 0 };
|
|
|
|
};
|