1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 02:08:11 +00:00

LibCore: Move LibGUI/GNotifier to LibCore/CNotifier.

This commit is contained in:
Andreas Kling 2019-04-10 17:35:43 +02:00
parent b2542414d7
commit fc1d3074de
15 changed files with 53 additions and 53 deletions

View file

@ -4,7 +4,7 @@
#include "IRCLogBuffer.h" #include "IRCLogBuffer.h"
#include "IRCWindow.h" #include "IRCWindow.h"
#include "IRCWindowListModel.h" #include "IRCWindowListModel.h"
#include <LibGUI/GNotifier.h> #include <LibCore/CNotifier.h>
#include <sys/socket.h> #include <sys/socket.h>
#include <netinet/in.h> #include <netinet/in.h>
#include <arpa/inet.h> #include <arpa/inet.h>
@ -47,8 +47,8 @@ void IRCClient::set_server(const String &hostname, int port)
void IRCClient::on_socket_connected() void IRCClient::on_socket_connected()
{ {
m_notifier = make<GNotifier>(m_socket->fd(), GNotifier::Read); m_notifier = make<CNotifier>(m_socket->fd(), CNotifier::Read);
m_notifier->on_ready_to_read = [this] (GNotifier&) { receive_from_server(); }; m_notifier->on_ready_to_read = [this] { receive_from_server(); };
send_user(); send_user();
send_nick(); send_nick();

View file

@ -11,7 +11,7 @@
class IRCChannel; class IRCChannel;
class IRCQuery; class IRCQuery;
class IRCWindowListModel; class IRCWindowListModel;
class GNotifier; class CNotifier;
class IRCClient final : public CObject { class IRCClient final : public CObject {
friend class IRCChannel; friend class IRCChannel;
@ -118,7 +118,7 @@ private:
String m_nickname; String m_nickname;
Vector<char> m_line_buffer; Vector<char> m_line_buffer;
OwnPtr<GNotifier> m_notifier; OwnPtr<CNotifier> m_notifier;
HashMap<String, RetainPtr<IRCChannel>> m_channels; HashMap<String, RetainPtr<IRCChannel>> m_channels;
HashMap<String, RetainPtr<IRCQuery>> m_queries; HashMap<String, RetainPtr<IRCQuery>> m_queries;

View file

@ -19,7 +19,7 @@
Terminal::Terminal(int ptm_fd) Terminal::Terminal(int ptm_fd)
: m_ptm_fd(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.set_interval(500);
m_cursor_blink_timer.on_timeout = [this] { m_cursor_blink_timer.on_timeout = [this] {
@ -28,9 +28,9 @@ Terminal::Terminal(int ptm_fd)
}; };
set_font(Font::default_fixed_width_font()); 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]; 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) { if (nread < 0) {
dbgprintf("Terminal read error: %s\n", strerror(errno)); dbgprintf("Terminal read error: %s\n", strerror(errno));
perror("read(ptm)"); perror("read(ptm)");

View file

@ -6,7 +6,7 @@
#include <SharedGraphics/GraphicsBitmap.h> #include <SharedGraphics/GraphicsBitmap.h>
#include <SharedGraphics/Rect.h> #include <SharedGraphics/Rect.h>
#include <LibGUI/GWidget.h> #include <LibGUI/GWidget.h>
#include <LibGUI/GNotifier.h> #include <LibCore/CNotifier.h>
#include <LibGUI/GTimer.h> #include <LibGUI/GTimer.h>
class Font; class Font;
@ -152,7 +152,7 @@ private:
bool m_in_active_window { false }; bool m_in_active_window { false };
bool m_need_full_flush { false }; bool m_need_full_flush { false };
GNotifier m_notifier; CNotifier m_notifier;
float m_opacity { 1 }; float m_opacity { 1 };
bool m_needs_background_fill { true }; bool m_needs_background_fill { true };

View file

@ -1,7 +1,7 @@
#include <LibCore/CObject.h> #include <LibCore/CObject.h>
#include <LibCore/CEventLoop.h> #include <LibCore/CEventLoop.h>
#include <LibCore/CEvent.h> #include <LibCore/CEvent.h>
#include <LibGUI/GNotifier.h> #include <LibCore/CNotifier.h>
#include <LibC/unistd.h> #include <LibC/unistd.h>
#include <LibC/stdio.h> #include <LibC/stdio.h>
#include <LibC/fcntl.h> #include <LibC/fcntl.h>
@ -19,7 +19,7 @@
static CEventLoop* s_main_event_loop; static CEventLoop* s_main_event_loop;
static Vector<CEventLoop*>* s_event_loop_stack; static Vector<CEventLoop*>* s_event_loop_stack;
HashMap<int, OwnPtr<CEventLoop::EventLoopTimer>>* CEventLoop::s_timers; 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; int CEventLoop::s_next_timer_id = 1;
CEventLoop::CEventLoop() CEventLoop::CEventLoop()
@ -27,7 +27,7 @@ CEventLoop::CEventLoop()
if (!s_event_loop_stack) { if (!s_event_loop_stack) {
s_event_loop_stack = new Vector<CEventLoop*>; s_event_loop_stack = new Vector<CEventLoop*>;
s_timers = new HashMap<int, OwnPtr<CEventLoop::EventLoopTimer>>; s_timers = new HashMap<int, OwnPtr<CEventLoop::EventLoopTimer>>;
s_notifiers = new HashTable<GNotifier*>; s_notifiers = new HashTable<CNotifier*>;
} }
if (!s_main_event_loop) { if (!s_main_event_loop) {
@ -153,11 +153,11 @@ void CEventLoop::wait_for_event()
add_file_descriptors_for_select(rfds, max_fd_added); add_file_descriptors_for_select(rfds, max_fd_added);
max_fd = max(max_fd, max_fd_added); max_fd = max(max_fd, max_fd_added);
for (auto& notifier : *s_notifiers) { for (auto& notifier : *s_notifiers) {
if (notifier->event_mask() & GNotifier::Read) if (notifier->event_mask() & CNotifier::Read)
add_fd_to_set(notifier->fd(), rfds); 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); add_fd_to_set(notifier->fd(), wfds);
if (notifier->event_mask() & GNotifier::Exceptional) if (notifier->event_mask() & CNotifier::Exceptional)
ASSERT_NOT_REACHED(); ASSERT_NOT_REACHED();
} }
@ -189,11 +189,11 @@ void CEventLoop::wait_for_event()
for (auto& notifier : *s_notifiers) { for (auto& notifier : *s_notifiers) {
if (FD_ISSET(notifier->fd(), &rfds)) { if (FD_ISSET(notifier->fd(), &rfds)) {
if (notifier->on_ready_to_read) if (notifier->on_ready_to_read)
notifier->on_ready_to_read(*notifier); notifier->on_ready_to_read();
} }
if (FD_ISSET(notifier->fd(), &wfds)) { if (FD_ISSET(notifier->fd(), &wfds)) {
if (notifier->on_ready_to_write) 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; return true;
} }
void CEventLoop::register_notifier(Badge<GNotifier>, GNotifier& notifier) void CEventLoop::register_notifier(Badge<CNotifier>, CNotifier& notifier)
{ {
s_notifiers->set(&notifier); s_notifiers->set(&notifier);
} }
void CEventLoop::unregister_notifier(Badge<GNotifier>, GNotifier& notifier) void CEventLoop::unregister_notifier(Badge<CNotifier>, CNotifier& notifier)
{ {
s_notifiers->remove(&notifier); s_notifiers->remove(&notifier);
} }

View file

@ -10,7 +10,7 @@
class CEvent; class CEvent;
class CObject; class CObject;
class GNotifier; class CNotifier;
class CEventLoop { class CEventLoop {
public: public:
@ -29,8 +29,8 @@ public:
static int register_timer(CObject&, int milliseconds, bool should_reload); static int register_timer(CObject&, int milliseconds, bool should_reload);
static bool unregister_timer(int timer_id); static bool unregister_timer(int timer_id);
static void register_notifier(Badge<GNotifier>, GNotifier&); static void register_notifier(Badge<CNotifier>, CNotifier&);
static void unregister_notifier(Badge<GNotifier>, GNotifier&); static void unregister_notifier(Badge<CNotifier>, CNotifier&);
void quit(int); void quit(int);
@ -72,5 +72,5 @@ private:
static HashMap<int, OwnPtr<EventLoopTimer>>* s_timers; static HashMap<int, OwnPtr<EventLoopTimer>>* s_timers;
static int s_next_timer_id; static int s_next_timer_id;
static HashTable<GNotifier*>* s_notifiers; static HashTable<CNotifier*>* s_notifiers;
}; };

15
LibCore/CNotifier.cpp Normal file
View 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);
}

View file

@ -2,7 +2,7 @@
#include <AK/Function.h> #include <AK/Function.h>
class GNotifier { class CNotifier {
public: public:
enum Event { enum Event {
None = 0, None = 0,
@ -10,11 +10,11 @@ public:
Write = 2, Write = 2,
Exceptional = 4, Exceptional = 4,
}; };
GNotifier(int fd, unsigned event_mask); CNotifier(int fd, unsigned event_mask);
~GNotifier(); ~CNotifier();
Function<void(GNotifier&)> on_ready_to_read; Function<void()> on_ready_to_read;
Function<void(GNotifier&)> on_ready_to_write; Function<void()> on_ready_to_write;
int fd() const { return m_fd; } int fd() const { return m_fd; }
unsigned event_mask() const { return m_event_mask; } unsigned event_mask() const { return m_event_mask; }

View file

@ -1,5 +1,6 @@
OBJS = \ OBJS = \
CElapsedTimer.o \ CElapsedTimer.o \
CNotifier.o \
CObject.o \ CObject.o \
CEventLoop.o \ CEventLoop.o \
CEvent.o CEvent.o

View file

@ -4,7 +4,7 @@
#include "GWindow.h" #include "GWindow.h"
#include <LibGUI/GApplication.h> #include <LibGUI/GApplication.h>
#include <LibGUI/GAction.h> #include <LibGUI/GAction.h>
#include <LibGUI/GNotifier.h> #include <LibCore/CNotifier.h>
#include <LibGUI/GMenu.h> #include <LibGUI/GMenu.h>
#include <LibGUI/GDesktop.h> #include <LibGUI/GDesktop.h>
#include <LibC/unistd.h> #include <LibC/unistd.h>

View file

@ -6,7 +6,7 @@
class GAction; class GAction;
class CObject; class CObject;
class GNotifier; class CNotifier;
class GWindow; class GWindow;
class GEventLoop final : public CEventLoop { class GEventLoop final : public CEventLoop {

View file

@ -1,15 +0,0 @@
#include <LibGUI/GNotifier.h>
#include <LibGUI/GEventLoop.h>
GNotifier::GNotifier(int fd, unsigned event_mask)
: m_fd(fd)
, m_event_mask(event_mask)
{
GEventLoop::register_notifier(Badge<GNotifier>(), *this);
}
GNotifier::~GNotifier()
{
GEventLoop::unregister_notifier(Badge<GNotifier>(), *this);
}

View file

@ -1,5 +1,5 @@
#include <LibGUI/GSocket.h> #include <LibGUI/GSocket.h>
#include <LibGUI/GNotifier.h> #include <LibCore/CNotifier.h>
#include <sys/socket.h> #include <sys/socket.h>
#include <netinet/in.h> #include <netinet/in.h>
#include <arpa/inet.h> #include <arpa/inet.h>
@ -53,11 +53,11 @@ bool GSocket::connect(const GSocketAddress& address, int port)
if (rc < 0) { if (rc < 0) {
if (errno == EINPROGRESS) { if (errno == EINPROGRESS) {
printf("in progress.\n"); printf("in progress.\n");
m_notifier = make<GNotifier>(fd(), GNotifier::Event::Write); m_notifier = make<CNotifier>(fd(), CNotifier::Event::Write);
m_notifier->on_ready_to_write = [this] (GNotifier&) { m_notifier->on_ready_to_write = [this] {
printf("%s{%p} connected!\n", class_name(), this); printf("%s{%p} connected!\n", class_name(), this);
m_connected = true; m_connected = true;
m_notifier->set_event_mask(GNotifier::Event::None); m_notifier->set_event_mask(CNotifier::Event::None);
if (on_connected) if (on_connected)
on_connected(); on_connected();
}; };

View file

@ -3,7 +3,7 @@
#include <LibGUI/GIODevice.h> #include <LibGUI/GIODevice.h>
#include <LibGUI/GSocketAddress.h> #include <LibGUI/GSocketAddress.h>
class GNotifier; class CNotifier;
class GSocket : public GIODevice { class GSocket : public GIODevice {
public: public:
@ -40,5 +40,5 @@ protected:
private: private:
virtual bool open(GIODevice::OpenMode) override { ASSERT_NOT_REACHED(); } virtual bool open(GIODevice::OpenMode) override { ASSERT_NOT_REACHED(); }
Type m_type { Type::Invalid }; Type m_type { Type::Invalid };
OwnPtr<GNotifier> m_notifier; OwnPtr<CNotifier> m_notifier;
}; };

View file

@ -17,7 +17,6 @@ LIBGUI_OBJS = \
GEventLoop.o \ GEventLoop.o \
GLabel.o \ GLabel.o \
GListBox.o \ GListBox.o \
GNotifier.o \
GTextBox.o \ GTextBox.o \
GScrollBar.o \ GScrollBar.o \
GStatusBar.o \ GStatusBar.o \