2019-04-11 22:03:21 +00:00
|
|
|
#include <LibCore/CEvent.h>
|
2019-05-28 09:53:16 +00:00
|
|
|
#include <LibCore/CEventLoop.h>
|
|
|
|
#include <LibCore/CNotifier.h>
|
2019-04-10 15:35:43 +00:00
|
|
|
|
2019-08-18 09:54:39 +00:00
|
|
|
CNotifier::CNotifier(int fd, unsigned event_mask, CObject* parent)
|
|
|
|
: CObject(parent)
|
|
|
|
, m_fd(fd)
|
2019-04-10 15:35:43 +00:00
|
|
|
, m_event_mask(event_mask)
|
|
|
|
{
|
2019-07-16 13:02:22 +00:00
|
|
|
set_enabled(true);
|
2019-04-10 15:35:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
CNotifier::~CNotifier()
|
|
|
|
{
|
2019-07-16 13:02:22 +00:00
|
|
|
set_enabled(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CNotifier::set_enabled(bool enabled)
|
|
|
|
{
|
|
|
|
if (enabled)
|
|
|
|
CEventLoop::register_notifier({}, *this);
|
|
|
|
else
|
|
|
|
CEventLoop::unregister_notifier({}, *this);
|
2019-04-10 15:35:43 +00:00
|
|
|
}
|
2019-07-16 18:31:14 +00:00
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|