diff --git a/Applications/IRCClient/IRCClient.cpp b/Applications/IRCClient/IRCClient.cpp index 29d0f877bb..2fd70babd3 100644 --- a/Applications/IRCClient/IRCClient.cpp +++ b/Applications/IRCClient/IRCClient.cpp @@ -56,7 +56,7 @@ void IRCClient::set_server(const String& hostname, int port) void IRCClient::on_socket_connected() { - m_notifier = make(m_socket->fd(), CNotifier::Read); + m_notifier = CNotifier::create(m_socket->fd(), CNotifier::Read); m_notifier->on_ready_to_read = [this] { receive_from_server(); }; send_user(); diff --git a/Applications/IRCClient/IRCClient.h b/Applications/IRCClient/IRCClient.h index 64765be375..56a005061f 100644 --- a/Applications/IRCClient/IRCClient.h +++ b/Applications/IRCClient/IRCClient.h @@ -2,12 +2,13 @@ #include "IRCLogBuffer.h" #include "IRCWindow.h" -#include #include #include #include +#include #include #include +#include class IRCChannel; class IRCQuery; @@ -18,6 +19,7 @@ class IRCClient final : public CObject { C_OBJECT(IRCClient) friend class IRCChannel; friend class IRCQuery; + public: IRCClient(); virtual ~IRCClient() override; @@ -138,7 +140,7 @@ private: CTCPSocket* m_socket { nullptr }; String m_nickname; - OwnPtr m_notifier; + ObjectPtr m_notifier; HashMap, CaseInsensitiveStringTraits> m_channels; HashMap, CaseInsensitiveStringTraits> m_queries; diff --git a/Applications/Terminal/TerminalWidget.cpp b/Applications/Terminal/TerminalWidget.cpp index 83d2a44b4a..a82bb27994 100644 --- a/Applications/Terminal/TerminalWidget.cpp +++ b/Applications/Terminal/TerminalWidget.cpp @@ -22,7 +22,7 @@ TerminalWidget::TerminalWidget(int ptm_fd, RefPtr config) : m_terminal(*this) , m_ptm_fd(ptm_fd) - , m_notifier(ptm_fd, CNotifier::Read) + , m_notifier(CNotifier::create(ptm_fd, CNotifier::Read)) , m_config(move(config)) { m_cursor_blink_timer = CTimer::create(); @@ -53,7 +53,7 @@ TerminalWidget::TerminalWidget(int ptm_fd, RefPtr config) else set_font(Font::load_from_file(font_entry)); - m_notifier.on_ready_to_read = [this] { + m_notifier->on_ready_to_read = [this] { u8 buffer[BUFSIZ]; ssize_t nread = read(m_ptm_fd, buffer, sizeof(buffer)); if (nread < 0) { diff --git a/Applications/Terminal/TerminalWidget.h b/Applications/Terminal/TerminalWidget.h index b5caa841ef..5324a15f42 100644 --- a/Applications/Terminal/TerminalWidget.h +++ b/Applications/Terminal/TerminalWidget.h @@ -88,7 +88,7 @@ private: bool m_in_active_window { false }; - CNotifier m_notifier; + ObjectPtr m_notifier; u8 m_opacity { 255 }; bool m_needs_background_fill { true }; diff --git a/Libraries/LibCore/CLocalServer.cpp b/Libraries/LibCore/CLocalServer.cpp index ea9bc5135d..73e56ef453 100644 --- a/Libraries/LibCore/CLocalServer.cpp +++ b/Libraries/LibCore/CLocalServer.cpp @@ -31,7 +31,7 @@ bool CLocalServer::listen(const String& address) ASSERT(rc == 0); m_listening = true; - m_notifier = make(m_fd, CNotifier::Event::Read, this); + m_notifier = CNotifier::create(m_fd, CNotifier::Event::Read, this); m_notifier->on_ready_to_read = [this] { if (on_ready_to_accept) on_ready_to_accept(); diff --git a/Libraries/LibCore/CLocalServer.h b/Libraries/LibCore/CLocalServer.h index ae7768e284..f16e95682c 100644 --- a/Libraries/LibCore/CLocalServer.h +++ b/Libraries/LibCore/CLocalServer.h @@ -21,5 +21,5 @@ public: private: int m_fd { -1 }; bool m_listening { false }; - OwnPtr m_notifier; + ObjectPtr m_notifier; }; diff --git a/Libraries/LibCore/CNotifier.h b/Libraries/LibCore/CNotifier.h index ffe20e129a..a21516725b 100644 --- a/Libraries/LibCore/CNotifier.h +++ b/Libraries/LibCore/CNotifier.h @@ -1,7 +1,8 @@ #pragma once #include -#include "CObject.h" +#include +#include class CNotifier : public CObject { C_OBJECT(CNotifier) @@ -12,7 +13,12 @@ public: Write = 2, Exceptional = 4, }; - CNotifier(int fd, unsigned event_mask, CObject* parent = nullptr); + + static ObjectPtr create(int fd, unsigned event_mask, CObject* parent = nullptr) + { + return new CNotifier(fd, event_mask, parent); + } + virtual ~CNotifier() override; void set_enabled(bool); @@ -27,6 +33,8 @@ public: void event(CEvent&) override; private: + CNotifier(int fd, unsigned event_mask, CObject* parent); + int m_fd { -1 }; unsigned m_event_mask { 0 }; }; diff --git a/Libraries/LibCore/CSocket.cpp b/Libraries/LibCore/CSocket.cpp index 9a6532118d..13b43950e6 100644 --- a/Libraries/LibCore/CSocket.cpp +++ b/Libraries/LibCore/CSocket.cpp @@ -85,7 +85,7 @@ bool CSocket::common_connect(const struct sockaddr* addr, socklen_t addrlen) if (rc < 0) { if (errno == EINPROGRESS) { dbg() << *this << " connection in progress (EINPROGRESS)"; - m_notifier = make(fd(), CNotifier::Event::Write, this); + m_notifier = CNotifier::create(fd(), CNotifier::Event::Write, this); m_notifier->on_ready_to_write = [this] { dbg() << *this << " connected!"; m_connected = true; @@ -132,7 +132,7 @@ void CSocket::did_update_fd(int fd) m_read_notifier = nullptr; return; } - m_read_notifier = make(fd, CNotifier::Event::Read, this); + m_read_notifier = CNotifier::create(fd, CNotifier::Event::Read, this); m_read_notifier->on_ready_to_read = [this] { if (on_ready_to_read) on_ready_to_read(); diff --git a/Libraries/LibCore/CSocket.h b/Libraries/LibCore/CSocket.h index 4cedf7e1fd..a6c2ef454c 100644 --- a/Libraries/LibCore/CSocket.h +++ b/Libraries/LibCore/CSocket.h @@ -2,6 +2,7 @@ #include #include +#include class CNotifier; @@ -53,6 +54,6 @@ private: bool common_connect(const struct sockaddr*, socklen_t); Type m_type { Type::Invalid }; - OwnPtr m_notifier; - OwnPtr m_read_notifier; + ObjectPtr m_notifier; + ObjectPtr m_read_notifier; }; diff --git a/Libraries/LibCore/CTCPServer.cpp b/Libraries/LibCore/CTCPServer.cpp index fa51156246..c1e61994c5 100644 --- a/Libraries/LibCore/CTCPServer.cpp +++ b/Libraries/LibCore/CTCPServer.cpp @@ -32,7 +32,7 @@ bool CTCPServer::listen(const IPv4Address& address, u16 port) ASSERT(rc == 0); m_listening = true; - m_notifier = make(m_fd, CNotifier::Event::Read); + m_notifier = CNotifier::create(m_fd, CNotifier::Event::Read); m_notifier->on_ready_to_read = [this] { if (on_ready_to_accept) on_ready_to_accept(); diff --git a/Libraries/LibCore/CoreIPCClient.h b/Libraries/LibCore/CoreIPCClient.h index 36409d1265..c26e3928fd 100644 --- a/Libraries/LibCore/CoreIPCClient.h +++ b/Libraries/LibCore/CoreIPCClient.h @@ -51,11 +51,11 @@ namespace Client { public: Connection(const StringView& address) : m_connection(this) - , m_notifier(m_connection.fd(), CNotifier::Read, this) + , m_notifier(CNotifier::create(m_connection.fd(), CNotifier::Read, this)) { // We want to rate-limit our clients m_connection.set_blocking(true); - m_notifier.on_ready_to_read = [this] { + m_notifier->on_ready_to_read = [this] { drain_messages_from_server(); CEventLoop::current().post_event(*this, make(m_connection.fd())); }; @@ -230,7 +230,7 @@ namespace Client { } CLocalSocket m_connection; - CNotifier m_notifier; + ObjectPtr m_notifier; Vector m_unprocessed_bundles; int m_server_pid { -1 }; int m_my_client_id { -1 }; @@ -242,11 +242,11 @@ namespace Client { public: ConnectionNG(const StringView& address) : m_connection(this) - , m_notifier(m_connection.fd(), CNotifier::Read, this) + , m_notifier(CNotifier::create(m_connection.fd(), CNotifier::Read, this)) { // We want to rate-limit our clients m_connection.set_blocking(true); - m_notifier.on_ready_to_read = [this] { + m_notifier->on_ready_to_read = [this] { drain_messages_from_server(); CEventLoop::current().post_event(*this, make(m_connection.fd())); }; @@ -374,7 +374,7 @@ namespace Client { } CLocalSocket m_connection; - CNotifier m_notifier; + ObjectPtr m_notifier; Vector> m_unprocessed_messages; int m_server_pid { -1 }; int m_my_client_id { -1 }; diff --git a/Libraries/LibGUI/GDirectoryModel.cpp b/Libraries/LibGUI/GDirectoryModel.cpp index ac7abf59e9..aa6c15c2ff 100644 --- a/Libraries/LibGUI/GDirectoryModel.cpp +++ b/Libraries/LibGUI/GDirectoryModel.cpp @@ -344,7 +344,7 @@ void GDirectoryModel::open(const StringView& a_path) perror("watch_file"); ASSERT_NOT_REACHED(); } - m_notifier = make(watch_fd, CNotifier::Event::Read); + m_notifier = CNotifier::create(watch_fd, CNotifier::Event::Read); m_notifier->on_ready_to_read = [this] { update(); char buffer[32]; diff --git a/Libraries/LibGUI/GDirectoryModel.h b/Libraries/LibGUI/GDirectoryModel.h index ec7fae7314..0a08fd291f 100644 --- a/Libraries/LibGUI/GDirectoryModel.h +++ b/Libraries/LibGUI/GDirectoryModel.h @@ -82,7 +82,7 @@ private: HashMap m_user_names; HashMap m_group_names; - OwnPtr m_notifier; + ObjectPtr m_notifier; unsigned m_thumbnail_progress { 0 }; unsigned m_thumbnail_progress_total { 0 }; diff --git a/Servers/TelnetServer/Client.cpp b/Servers/TelnetServer/Client.cpp index 485bb23134..6c71ac3231 100644 --- a/Servers/TelnetServer/Client.cpp +++ b/Servers/TelnetServer/Client.cpp @@ -14,10 +14,10 @@ Client::Client(int id, CTCPSocket* socket, int ptm_fd) : m_id(id) , m_socket(socket) , m_ptm_fd(ptm_fd) - , m_ptm_notifier(ptm_fd, CNotifier::Read) + , m_ptm_notifier(CNotifier::create(ptm_fd, CNotifier::Read)) { m_socket->on_ready_to_read = [this] { drain_socket(); }; - m_ptm_notifier.on_ready_to_read = [this] { drain_pty(); }; + m_ptm_notifier->on_ready_to_read = [this] { drain_pty(); }; m_parser.on_command = [this](const Command& command) { handle_command(command); }; m_parser.on_data = [this](const StringView& data) { handle_data(data); }; m_parser.on_error = [this]() { handle_error(); }; @@ -154,7 +154,7 @@ void Client::send_commands(Vector commands) void Client::quit() { - m_ptm_notifier.set_enabled(false); + m_ptm_notifier->set_enabled(false); close(m_ptm_fd); m_socket->close(); if (on_exit) diff --git a/Servers/TelnetServer/Client.h b/Servers/TelnetServer/Client.h index 83956f8879..60e222cc98 100644 --- a/Servers/TelnetServer/Client.h +++ b/Servers/TelnetServer/Client.h @@ -39,5 +39,5 @@ private: Parser m_parser; // pty resources int m_ptm_fd { -1 }; - CNotifier m_ptm_notifier; + ObjectPtr m_ptm_notifier; }; diff --git a/Servers/WindowServer/WSEventLoop.cpp b/Servers/WindowServer/WSEventLoop.cpp index df6a2e1a73..544fac4f3a 100644 --- a/Servers/WindowServer/WSEventLoop.cpp +++ b/Servers/WindowServer/WSEventLoop.cpp @@ -43,10 +43,10 @@ WSEventLoop::WSEventLoop() ASSERT(m_keyboard_fd >= 0); ASSERT(m_mouse_fd >= 0); - m_keyboard_notifier = make(m_keyboard_fd, CNotifier::Read); + m_keyboard_notifier = CNotifier::create(m_keyboard_fd, CNotifier::Read); m_keyboard_notifier->on_ready_to_read = [this] { drain_keyboard(); }; - m_mouse_notifier = make(m_mouse_fd, CNotifier::Read); + m_mouse_notifier = CNotifier::create(m_mouse_fd, CNotifier::Read); m_mouse_notifier->on_ready_to_read = [this] { drain_mouse(); }; WSClipboard::the().on_content_change = [&] { diff --git a/Servers/WindowServer/WSEventLoop.h b/Servers/WindowServer/WSEventLoop.h index c7454d9278..93313ee2df 100644 --- a/Servers/WindowServer/WSEventLoop.h +++ b/Servers/WindowServer/WSEventLoop.h @@ -21,9 +21,8 @@ private: CEventLoop m_event_loop; int m_keyboard_fd { -1 }; - OwnPtr m_keyboard_notifier; + ObjectPtr m_keyboard_notifier; int m_mouse_fd { -1 }; - OwnPtr m_mouse_notifier; + ObjectPtr m_mouse_notifier; CLocalServer m_server_sock; - OwnPtr m_server_notifier; };