summaryrefslogtreecommitdiff
path: root/Libraries/LibCore/CNotifier.h
blob: a21516725b004c8ed0d21080bd613df6b4e61e66 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#pragma once

#include <AK/Function.h>
#include <LibCore/CObject.h>
#include <LibCore/ObjectPtr.h>

class CNotifier : public CObject {
    C_OBJECT(CNotifier)
public:
    enum Event {
        None = 0,
        Read = 1,
        Write = 2,
        Exceptional = 4,
    };

    static ObjectPtr<CNotifier> create(int fd, unsigned event_mask, CObject* parent = nullptr)
    {
        return new CNotifier(fd, event_mask, parent);
    }

    virtual ~CNotifier() override;

    void set_enabled(bool);

    Function<void()> on_ready_to_read;
    Function<void()> on_ready_to_write;

    int fd() const { return m_fd; }
    unsigned event_mask() const { return m_event_mask; }
    void set_event_mask(unsigned event_mask) { m_event_mask = event_mask; }

    void event(CEvent&) override;

private:
    CNotifier(int fd, unsigned event_mask, CObject* parent);

    int m_fd { -1 };
    unsigned m_event_mask { 0 };
};