1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 17:17:44 +00:00

LibCore: Convert CNotifier to ObjectPtr

This commit is contained in:
Andreas Kling 2019-09-20 15:39:15 +02:00
parent 50a6560413
commit d1bacb9885
17 changed files with 42 additions and 32 deletions

View file

@ -56,7 +56,7 @@ void IRCClient::set_server(const String& hostname, int port)
void IRCClient::on_socket_connected()
{
m_notifier = make<CNotifier>(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();

View file

@ -2,12 +2,13 @@
#include "IRCLogBuffer.h"
#include "IRCWindow.h"
#include <AK/String.h>
#include <AK/CircularQueue.h>
#include <AK/Function.h>
#include <AK/HashMap.h>
#include <AK/String.h>
#include <LibCore/CConfigFile.h>
#include <LibCore/CTCPSocket.h>
#include <LibCore/ObjectPtr.h>
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<CNotifier> m_notifier;
ObjectPtr<CNotifier> m_notifier;
HashMap<String, RefPtr<IRCChannel>, CaseInsensitiveStringTraits> m_channels;
HashMap<String, RefPtr<IRCQuery>, CaseInsensitiveStringTraits> m_queries;

View file

@ -22,7 +22,7 @@
TerminalWidget::TerminalWidget(int ptm_fd, RefPtr<CConfigFile> 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<CConfigFile> 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) {

View file

@ -88,7 +88,7 @@ private:
bool m_in_active_window { false };
CNotifier m_notifier;
ObjectPtr<CNotifier> m_notifier;
u8 m_opacity { 255 };
bool m_needs_background_fill { true };

View file

@ -31,7 +31,7 @@ bool CLocalServer::listen(const String& address)
ASSERT(rc == 0);
m_listening = true;
m_notifier = make<CNotifier>(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();

View file

@ -21,5 +21,5 @@ public:
private:
int m_fd { -1 };
bool m_listening { false };
OwnPtr<CNotifier> m_notifier;
ObjectPtr<CNotifier> m_notifier;
};

View file

@ -1,7 +1,8 @@
#pragma once
#include <AK/Function.h>
#include "CObject.h"
#include <LibCore/CObject.h>
#include <LibCore/ObjectPtr.h>
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<CNotifier> 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 };
};

View file

@ -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<CNotifier>(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<CNotifier>(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();

View file

@ -2,6 +2,7 @@
#include <LibCore/CIODevice.h>
#include <LibCore/CSocketAddress.h>
#include <LibCore/ObjectPtr.h>
class CNotifier;
@ -53,6 +54,6 @@ private:
bool common_connect(const struct sockaddr*, socklen_t);
Type m_type { Type::Invalid };
OwnPtr<CNotifier> m_notifier;
OwnPtr<CNotifier> m_read_notifier;
ObjectPtr<CNotifier> m_notifier;
ObjectPtr<CNotifier> m_read_notifier;
};

View file

@ -32,7 +32,7 @@ bool CTCPServer::listen(const IPv4Address& address, u16 port)
ASSERT(rc == 0);
m_listening = true;
m_notifier = make<CNotifier>(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();

View file

@ -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<PostProcessEvent>(m_connection.fd()));
};
@ -230,7 +230,7 @@ namespace Client {
}
CLocalSocket m_connection;
CNotifier m_notifier;
ObjectPtr<CNotifier> m_notifier;
Vector<IncomingMessageBundle> 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<PostProcessEvent>(m_connection.fd()));
};
@ -374,7 +374,7 @@ namespace Client {
}
CLocalSocket m_connection;
CNotifier m_notifier;
ObjectPtr<CNotifier> m_notifier;
Vector<OwnPtr<IMessage>> m_unprocessed_messages;
int m_server_pid { -1 };
int m_my_client_id { -1 };

View file

@ -344,7 +344,7 @@ void GDirectoryModel::open(const StringView& a_path)
perror("watch_file");
ASSERT_NOT_REACHED();
}
m_notifier = make<CNotifier>(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];

View file

@ -82,7 +82,7 @@ private:
HashMap<uid_t, String> m_user_names;
HashMap<gid_t, String> m_group_names;
OwnPtr<CNotifier> m_notifier;
ObjectPtr<CNotifier> m_notifier;
unsigned m_thumbnail_progress { 0 };
unsigned m_thumbnail_progress_total { 0 };

View file

@ -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<Command> 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)

View file

@ -39,5 +39,5 @@ private:
Parser m_parser;
// pty resources
int m_ptm_fd { -1 };
CNotifier m_ptm_notifier;
ObjectPtr<CNotifier> m_ptm_notifier;
};

View file

@ -43,10 +43,10 @@ WSEventLoop::WSEventLoop()
ASSERT(m_keyboard_fd >= 0);
ASSERT(m_mouse_fd >= 0);
m_keyboard_notifier = make<CNotifier>(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<CNotifier>(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 = [&] {

View file

@ -21,9 +21,8 @@ private:
CEventLoop m_event_loop;
int m_keyboard_fd { -1 };
OwnPtr<CNotifier> m_keyboard_notifier;
ObjectPtr<CNotifier> m_keyboard_notifier;
int m_mouse_fd { -1 };
OwnPtr<CNotifier> m_mouse_notifier;
ObjectPtr<CNotifier> m_mouse_notifier;
CLocalServer m_server_sock;
OwnPtr<CNotifier> m_server_notifier;
};