summaryrefslogtreecommitdiff
path: root/Libraries/LibCore/CNotifier.cpp
blob: 31870d5b348432185354e67f91dce460e5b67983 (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
#include <LibCore/CEvent.h>
#include <LibCore/CEventLoop.h>
#include <LibCore/CNotifier.h>

CNotifier::CNotifier(int fd, unsigned event_mask)
    : m_fd(fd)
    , m_event_mask(event_mask)
{
    set_enabled(true);
}

CNotifier::~CNotifier()
{
    set_enabled(false);
}

void CNotifier::set_enabled(bool enabled)
{
    if (enabled)
        CEventLoop::register_notifier({}, *this);
    else
        CEventLoop::unregister_notifier({}, *this);
}

void CNotifier::event(CEvent& event)
{
    if (event.type() == CEvent::NotifierRead && on_ready_to_read) {
        on_ready_to_read();
    } else if (event.type() == CEvent::NotifierWrite && on_ready_to_write) {
        on_ready_to_write();
    } else {
        CObject::event(event);
    }
}