diff --git a/Applications/IRCClient/IRCClient.cpp b/Applications/IRCClient/IRCClient.cpp index a48f5ca5ac..a6310789b6 100644 --- a/Applications/IRCClient/IRCClient.cpp +++ b/Applications/IRCClient/IRCClient.cpp @@ -4,7 +4,7 @@ #include "IRCLogBuffer.h" #include "IRCWindow.h" #include "IRCWindowListModel.h" -#include +#include #include #include #include @@ -47,8 +47,8 @@ void IRCClient::set_server(const String &hostname, int port) void IRCClient::on_socket_connected() { - m_notifier = make(m_socket->fd(), GNotifier::Read); - m_notifier->on_ready_to_read = [this] (GNotifier&) { receive_from_server(); }; + m_notifier = make(m_socket->fd(), CNotifier::Read); + m_notifier->on_ready_to_read = [this] { receive_from_server(); }; send_user(); send_nick(); diff --git a/Applications/IRCClient/IRCClient.h b/Applications/IRCClient/IRCClient.h index 91522b729b..a493fd2975 100644 --- a/Applications/IRCClient/IRCClient.h +++ b/Applications/IRCClient/IRCClient.h @@ -11,7 +11,7 @@ class IRCChannel; class IRCQuery; class IRCWindowListModel; -class GNotifier; +class CNotifier; class IRCClient final : public CObject { friend class IRCChannel; @@ -118,7 +118,7 @@ private: String m_nickname; Vector m_line_buffer; - OwnPtr m_notifier; + OwnPtr m_notifier; HashMap> m_channels; HashMap> m_queries; diff --git a/Applications/Terminal/Terminal.cpp b/Applications/Terminal/Terminal.cpp index 4fe66c6039..a8e6267858 100644 --- a/Applications/Terminal/Terminal.cpp +++ b/Applications/Terminal/Terminal.cpp @@ -19,7 +19,7 @@ Terminal::Terminal(int ptm_fd) : m_ptm_fd(ptm_fd) - , m_notifier(ptm_fd, GNotifier::Read) + , m_notifier(ptm_fd, CNotifier::Read) { m_cursor_blink_timer.set_interval(500); m_cursor_blink_timer.on_timeout = [this] { @@ -28,9 +28,9 @@ Terminal::Terminal(int ptm_fd) }; set_font(Font::default_fixed_width_font()); - m_notifier.on_ready_to_read = [this] (GNotifier& notifier) { + m_notifier.on_ready_to_read = [this]{ byte buffer[BUFSIZ]; - ssize_t nread = read(notifier.fd(), buffer, sizeof(buffer)); + ssize_t nread = read(m_ptm_fd, buffer, sizeof(buffer)); if (nread < 0) { dbgprintf("Terminal read error: %s\n", strerror(errno)); perror("read(ptm)"); diff --git a/Applications/Terminal/Terminal.h b/Applications/Terminal/Terminal.h index f13eab22e6..3fedf44bdf 100644 --- a/Applications/Terminal/Terminal.h +++ b/Applications/Terminal/Terminal.h @@ -6,7 +6,7 @@ #include #include #include -#include +#include #include class Font; @@ -152,7 +152,7 @@ private: bool m_in_active_window { false }; bool m_need_full_flush { false }; - GNotifier m_notifier; + CNotifier m_notifier; float m_opacity { 1 }; bool m_needs_background_fill { true }; diff --git a/LibCore/CEventLoop.cpp b/LibCore/CEventLoop.cpp index d7b474d276..d18da8fc65 100644 --- a/LibCore/CEventLoop.cpp +++ b/LibCore/CEventLoop.cpp @@ -1,7 +1,7 @@ #include #include #include -#include +#include #include #include #include @@ -19,7 +19,7 @@ static CEventLoop* s_main_event_loop; static Vector* s_event_loop_stack; HashMap>* CEventLoop::s_timers; -HashTable* CEventLoop::s_notifiers; +HashTable* 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; s_timers = new HashMap>; - s_notifiers = new HashTable; + s_notifiers = new HashTable; } 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& notifier) +void CEventLoop::register_notifier(Badge, CNotifier& notifier) { s_notifiers->set(¬ifier); } -void CEventLoop::unregister_notifier(Badge, GNotifier& notifier) +void CEventLoop::unregister_notifier(Badge, CNotifier& notifier) { s_notifiers->remove(¬ifier); } diff --git a/LibCore/CEventLoop.h b/LibCore/CEventLoop.h index 2de219c5cd..9f97461711 100644 --- a/LibCore/CEventLoop.h +++ b/LibCore/CEventLoop.h @@ -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&); - static void unregister_notifier(Badge, GNotifier&); + static void register_notifier(Badge, CNotifier&); + static void unregister_notifier(Badge, CNotifier&); void quit(int); @@ -72,5 +72,5 @@ private: static HashMap>* s_timers; static int s_next_timer_id; - static HashTable* s_notifiers; + static HashTable* s_notifiers; }; diff --git a/LibCore/CNotifier.cpp b/LibCore/CNotifier.cpp new file mode 100644 index 0000000000..59c2a460fe --- /dev/null +++ b/LibCore/CNotifier.cpp @@ -0,0 +1,15 @@ +#include +#include + +CNotifier::CNotifier(int fd, unsigned event_mask) + : m_fd(fd) + , m_event_mask(event_mask) +{ + GEventLoop::register_notifier(Badge(), *this); +} + +CNotifier::~CNotifier() +{ + GEventLoop::unregister_notifier(Badge(), *this); +} + diff --git a/LibGUI/GNotifier.h b/LibCore/CNotifier.h similarity index 69% rename from LibGUI/GNotifier.h rename to LibCore/CNotifier.h index 6876c481f4..baa3532b92 100644 --- a/LibGUI/GNotifier.h +++ b/LibCore/CNotifier.h @@ -2,7 +2,7 @@ #include -class GNotifier { +class CNotifier { public: enum Event { None = 0, @@ -10,11 +10,11 @@ public: Write = 2, Exceptional = 4, }; - GNotifier(int fd, unsigned event_mask); - ~GNotifier(); + CNotifier(int fd, unsigned event_mask); + ~CNotifier(); - Function on_ready_to_read; - Function on_ready_to_write; + Function on_ready_to_read; + Function on_ready_to_write; int fd() const { return m_fd; } unsigned event_mask() const { return m_event_mask; } diff --git a/LibCore/Makefile b/LibCore/Makefile index 2d90c6b16b..35a08edc3b 100644 --- a/LibCore/Makefile +++ b/LibCore/Makefile @@ -1,5 +1,6 @@ OBJS = \ CElapsedTimer.o \ + CNotifier.o \ CObject.o \ CEventLoop.o \ CEvent.o diff --git a/LibGUI/GEventLoop.cpp b/LibGUI/GEventLoop.cpp index 8e1bc69bc0..a7502c0b7e 100644 --- a/LibGUI/GEventLoop.cpp +++ b/LibGUI/GEventLoop.cpp @@ -4,7 +4,7 @@ #include "GWindow.h" #include #include -#include +#include #include #include #include diff --git a/LibGUI/GEventLoop.h b/LibGUI/GEventLoop.h index bf09c4d401..3ee1dfc1fc 100644 --- a/LibGUI/GEventLoop.h +++ b/LibGUI/GEventLoop.h @@ -6,7 +6,7 @@ class GAction; class CObject; -class GNotifier; +class CNotifier; class GWindow; class GEventLoop final : public CEventLoop { diff --git a/LibGUI/GNotifier.cpp b/LibGUI/GNotifier.cpp deleted file mode 100644 index 649cc84bcc..0000000000 --- a/LibGUI/GNotifier.cpp +++ /dev/null @@ -1,15 +0,0 @@ -#include -#include - -GNotifier::GNotifier(int fd, unsigned event_mask) - : m_fd(fd) - , m_event_mask(event_mask) -{ - GEventLoop::register_notifier(Badge(), *this); -} - -GNotifier::~GNotifier() -{ - GEventLoop::unregister_notifier(Badge(), *this); -} - diff --git a/LibGUI/GSocket.cpp b/LibGUI/GSocket.cpp index b1a1f4797d..6b088e2dbe 100644 --- a/LibGUI/GSocket.cpp +++ b/LibGUI/GSocket.cpp @@ -1,5 +1,5 @@ #include -#include +#include #include #include #include @@ -53,11 +53,11 @@ bool GSocket::connect(const GSocketAddress& address, int port) if (rc < 0) { if (errno == EINPROGRESS) { printf("in progress.\n"); - m_notifier = make(fd(), GNotifier::Event::Write); - m_notifier->on_ready_to_write = [this] (GNotifier&) { + m_notifier = make(fd(), CNotifier::Event::Write); + m_notifier->on_ready_to_write = [this] { printf("%s{%p} connected!\n", class_name(), this); m_connected = true; - m_notifier->set_event_mask(GNotifier::Event::None); + m_notifier->set_event_mask(CNotifier::Event::None); if (on_connected) on_connected(); }; diff --git a/LibGUI/GSocket.h b/LibGUI/GSocket.h index f9501eab3f..697845d2d1 100644 --- a/LibGUI/GSocket.h +++ b/LibGUI/GSocket.h @@ -3,7 +3,7 @@ #include #include -class GNotifier; +class CNotifier; class GSocket : public GIODevice { public: @@ -40,5 +40,5 @@ protected: private: virtual bool open(GIODevice::OpenMode) override { ASSERT_NOT_REACHED(); } Type m_type { Type::Invalid }; - OwnPtr m_notifier; + OwnPtr m_notifier; }; diff --git a/LibGUI/Makefile b/LibGUI/Makefile index 37b21c6e62..b687153aa8 100644 --- a/LibGUI/Makefile +++ b/LibGUI/Makefile @@ -17,7 +17,6 @@ LIBGUI_OBJS = \ GEventLoop.o \ GLabel.o \ GListBox.o \ - GNotifier.o \ GTextBox.o \ GScrollBar.o \ GStatusBar.o \