mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 00:17:46 +00:00
LibCore: Move LibGUI/GNotifier to LibCore/CNotifier.
This commit is contained in:
parent
b2542414d7
commit
fc1d3074de
15 changed files with 53 additions and 53 deletions
|
@ -1,7 +1,7 @@
|
|||
#include <LibCore/CObject.h>
|
||||
#include <LibCore/CEventLoop.h>
|
||||
#include <LibCore/CEvent.h>
|
||||
#include <LibGUI/GNotifier.h>
|
||||
#include <LibCore/CNotifier.h>
|
||||
#include <LibC/unistd.h>
|
||||
#include <LibC/stdio.h>
|
||||
#include <LibC/fcntl.h>
|
||||
|
@ -19,7 +19,7 @@
|
|||
static CEventLoop* s_main_event_loop;
|
||||
static Vector<CEventLoop*>* s_event_loop_stack;
|
||||
HashMap<int, OwnPtr<CEventLoop::EventLoopTimer>>* CEventLoop::s_timers;
|
||||
HashTable<GNotifier*>* CEventLoop::s_notifiers;
|
||||
HashTable<CNotifier*>* CEventLoop::s_notifiers;
|
||||
int CEventLoop::s_next_timer_id = 1;
|
||||
|
||||
CEventLoop::CEventLoop()
|
||||
|
@ -27,7 +27,7 @@ CEventLoop::CEventLoop()
|
|||
if (!s_event_loop_stack) {
|
||||
s_event_loop_stack = new Vector<CEventLoop*>;
|
||||
s_timers = new HashMap<int, OwnPtr<CEventLoop::EventLoopTimer>>;
|
||||
s_notifiers = new HashTable<GNotifier*>;
|
||||
s_notifiers = new HashTable<CNotifier*>;
|
||||
}
|
||||
|
||||
if (!s_main_event_loop) {
|
||||
|
@ -153,11 +153,11 @@ void CEventLoop::wait_for_event()
|
|||
add_file_descriptors_for_select(rfds, max_fd_added);
|
||||
max_fd = max(max_fd, max_fd_added);
|
||||
for (auto& notifier : *s_notifiers) {
|
||||
if (notifier->event_mask() & GNotifier::Read)
|
||||
if (notifier->event_mask() & CNotifier::Read)
|
||||
add_fd_to_set(notifier->fd(), rfds);
|
||||
if (notifier->event_mask() & GNotifier::Write)
|
||||
if (notifier->event_mask() & CNotifier::Write)
|
||||
add_fd_to_set(notifier->fd(), wfds);
|
||||
if (notifier->event_mask() & GNotifier::Exceptional)
|
||||
if (notifier->event_mask() & CNotifier::Exceptional)
|
||||
ASSERT_NOT_REACHED();
|
||||
}
|
||||
|
||||
|
@ -189,11 +189,11 @@ void CEventLoop::wait_for_event()
|
|||
for (auto& notifier : *s_notifiers) {
|
||||
if (FD_ISSET(notifier->fd(), &rfds)) {
|
||||
if (notifier->on_ready_to_read)
|
||||
notifier->on_ready_to_read(*notifier);
|
||||
notifier->on_ready_to_read();
|
||||
}
|
||||
if (FD_ISSET(notifier->fd(), &wfds)) {
|
||||
if (notifier->on_ready_to_write)
|
||||
notifier->on_ready_to_write(*notifier);
|
||||
notifier->on_ready_to_write();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -250,12 +250,12 @@ bool CEventLoop::unregister_timer(int timer_id)
|
|||
return true;
|
||||
}
|
||||
|
||||
void CEventLoop::register_notifier(Badge<GNotifier>, GNotifier& notifier)
|
||||
void CEventLoop::register_notifier(Badge<CNotifier>, CNotifier& notifier)
|
||||
{
|
||||
s_notifiers->set(¬ifier);
|
||||
}
|
||||
|
||||
void CEventLoop::unregister_notifier(Badge<GNotifier>, GNotifier& notifier)
|
||||
void CEventLoop::unregister_notifier(Badge<CNotifier>, CNotifier& notifier)
|
||||
{
|
||||
s_notifiers->remove(¬ifier);
|
||||
}
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
|
||||
class CEvent;
|
||||
class CObject;
|
||||
class GNotifier;
|
||||
class CNotifier;
|
||||
|
||||
class CEventLoop {
|
||||
public:
|
||||
|
@ -29,8 +29,8 @@ public:
|
|||
static int register_timer(CObject&, int milliseconds, bool should_reload);
|
||||
static bool unregister_timer(int timer_id);
|
||||
|
||||
static void register_notifier(Badge<GNotifier>, GNotifier&);
|
||||
static void unregister_notifier(Badge<GNotifier>, GNotifier&);
|
||||
static void register_notifier(Badge<CNotifier>, CNotifier&);
|
||||
static void unregister_notifier(Badge<CNotifier>, CNotifier&);
|
||||
|
||||
void quit(int);
|
||||
|
||||
|
@ -72,5 +72,5 @@ private:
|
|||
static HashMap<int, OwnPtr<EventLoopTimer>>* s_timers;
|
||||
static int s_next_timer_id;
|
||||
|
||||
static HashTable<GNotifier*>* s_notifiers;
|
||||
static HashTable<CNotifier*>* s_notifiers;
|
||||
};
|
||||
|
|
15
LibCore/CNotifier.cpp
Normal file
15
LibCore/CNotifier.cpp
Normal file
|
@ -0,0 +1,15 @@
|
|||
#include <LibCore/CNotifier.h>
|
||||
#include <LibGUI/GEventLoop.h>
|
||||
|
||||
CNotifier::CNotifier(int fd, unsigned event_mask)
|
||||
: m_fd(fd)
|
||||
, m_event_mask(event_mask)
|
||||
{
|
||||
GEventLoop::register_notifier(Badge<CNotifier>(), *this);
|
||||
}
|
||||
|
||||
CNotifier::~CNotifier()
|
||||
{
|
||||
GEventLoop::unregister_notifier(Badge<CNotifier>(), *this);
|
||||
}
|
||||
|
26
LibCore/CNotifier.h
Normal file
26
LibCore/CNotifier.h
Normal file
|
@ -0,0 +1,26 @@
|
|||
#pragma once
|
||||
|
||||
#include <AK/Function.h>
|
||||
|
||||
class CNotifier {
|
||||
public:
|
||||
enum Event {
|
||||
None = 0,
|
||||
Read = 1,
|
||||
Write = 2,
|
||||
Exceptional = 4,
|
||||
};
|
||||
CNotifier(int fd, unsigned event_mask);
|
||||
~CNotifier();
|
||||
|
||||
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; }
|
||||
|
||||
private:
|
||||
int m_fd { -1 };
|
||||
unsigned m_event_mask { 0 };
|
||||
};
|
|
@ -1,5 +1,6 @@
|
|||
OBJS = \
|
||||
CElapsedTimer.o \
|
||||
CNotifier.o \
|
||||
CObject.o \
|
||||
CEventLoop.o \
|
||||
CEvent.o
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue