mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-11 01:06:01 +03:00
d8387f1506
This way, CNotifier can mutate state to its little heart's content without destroying the world when the global CNotifier hash changes during delivery.
35 lines
737 B
C++
35 lines
737 B
C++
#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);
|
|
}
|
|
}
|