mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 23:07:35 +00:00
Userland: Rename Core::Object to Core::EventReceiver
This is a more precise description of what this class actually does.
This commit is contained in:
parent
bdf696e488
commit
ddbe6bd7b4
128 changed files with 399 additions and 401 deletions
|
@ -12,13 +12,13 @@ set(SOURCES
|
|||
EventLoop.cpp
|
||||
EventLoopImplementation.cpp
|
||||
EventLoopImplementationUnix.cpp
|
||||
EventReceiver.cpp
|
||||
File.cpp
|
||||
LockFile.cpp
|
||||
MappedFile.cpp
|
||||
MimeData.cpp
|
||||
NetworkJob.cpp
|
||||
Notifier.cpp
|
||||
Object.cpp
|
||||
Process.cpp
|
||||
ProcessStatisticsReader.cpp
|
||||
SecretString.cpp
|
||||
|
|
|
@ -7,11 +7,11 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <LibCore/Object.h>
|
||||
#include <LibCore/EventReceiver.h>
|
||||
|
||||
namespace Core {
|
||||
|
||||
class DeferredInvocationContext final : public Core::Object {
|
||||
class DeferredInvocationContext final : public Core::EventReceiver {
|
||||
C_OBJECT(DeferredInvocationContext)
|
||||
private:
|
||||
DeferredInvocationContext() = default;
|
||||
|
|
|
@ -7,39 +7,39 @@
|
|||
|
||||
#include <AK/WeakPtr.h>
|
||||
#include <LibCore/Event.h>
|
||||
#include <LibCore/Object.h>
|
||||
#include <LibCore/EventReceiver.h>
|
||||
|
||||
namespace Core {
|
||||
|
||||
ChildEvent::ChildEvent(Type type, Object& child, Object* insertion_before_child)
|
||||
ChildEvent::ChildEvent(Type type, EventReceiver& child, EventReceiver* insertion_before_child)
|
||||
: Core::Event(type)
|
||||
, m_child(child.make_weak_ptr())
|
||||
, m_insertion_before_child(AK::make_weak_ptr_if_nonnull(insertion_before_child))
|
||||
{
|
||||
}
|
||||
|
||||
Object* ChildEvent::child()
|
||||
EventReceiver* ChildEvent::child()
|
||||
{
|
||||
if (auto ref = m_child.strong_ref())
|
||||
return ref.ptr();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
Object const* ChildEvent::child() const
|
||||
EventReceiver const* ChildEvent::child() const
|
||||
{
|
||||
if (auto ref = m_child.strong_ref())
|
||||
return ref.ptr();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
Object* ChildEvent::insertion_before_child()
|
||||
EventReceiver* ChildEvent::insertion_before_child()
|
||||
{
|
||||
if (auto ref = m_insertion_before_child.strong_ref())
|
||||
return ref.ptr();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
Object const* ChildEvent::insertion_before_child() const
|
||||
EventReceiver const* ChildEvent::insertion_before_child() const
|
||||
{
|
||||
if (auto ref = m_insertion_before_child.strong_ref())
|
||||
return ref.ptr();
|
||||
|
|
|
@ -95,18 +95,18 @@ private:
|
|||
|
||||
class ChildEvent final : public Event {
|
||||
public:
|
||||
ChildEvent(Type, Object& child, Object* insertion_before_child = nullptr);
|
||||
ChildEvent(Type, EventReceiver& child, EventReceiver* insertion_before_child = nullptr);
|
||||
~ChildEvent() = default;
|
||||
|
||||
Object* child();
|
||||
Object const* child() const;
|
||||
EventReceiver* child();
|
||||
EventReceiver const* child() const;
|
||||
|
||||
Object* insertion_before_child();
|
||||
Object const* insertion_before_child() const;
|
||||
EventReceiver* insertion_before_child();
|
||||
EventReceiver const* insertion_before_child() const;
|
||||
|
||||
private:
|
||||
WeakPtr<Object> m_child;
|
||||
WeakPtr<Object> m_insertion_before_child;
|
||||
WeakPtr<EventReceiver> m_child;
|
||||
WeakPtr<EventReceiver> m_insertion_before_child;
|
||||
};
|
||||
|
||||
class CustomEvent : public Event {
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
#include <LibCore/Event.h>
|
||||
#include <LibCore/EventLoop.h>
|
||||
#include <LibCore/EventLoopImplementationUnix.h>
|
||||
#include <LibCore/Object.h>
|
||||
#include <LibCore/EventReceiver.h>
|
||||
#include <LibCore/Promise.h>
|
||||
#include <LibCore/ThreadEventQueue.h>
|
||||
|
||||
|
@ -98,12 +98,12 @@ size_t EventLoop::pump(WaitMode mode)
|
|||
return m_impl->pump(mode == WaitMode::WaitForEvents ? EventLoopImplementation::PumpMode::WaitForEvents : EventLoopImplementation::PumpMode::DontWaitForEvents);
|
||||
}
|
||||
|
||||
void EventLoop::post_event(Object& receiver, NonnullOwnPtr<Event>&& event)
|
||||
void EventLoop::post_event(EventReceiver& receiver, NonnullOwnPtr<Event>&& event)
|
||||
{
|
||||
m_impl->post_event(receiver, move(event));
|
||||
}
|
||||
|
||||
void EventLoop::add_job(NonnullRefPtr<Promise<NonnullRefPtr<Object>>> job_promise)
|
||||
void EventLoop::add_job(NonnullRefPtr<Promise<NonnullRefPtr<EventReceiver>>> job_promise)
|
||||
{
|
||||
ThreadEventQueue::current().add_job(move(job_promise));
|
||||
}
|
||||
|
@ -123,7 +123,7 @@ void EventLoop::notify_forked(ForkEvent)
|
|||
current().m_impl->notify_forked_and_in_child();
|
||||
}
|
||||
|
||||
int EventLoop::register_timer(Object& object, int milliseconds, bool should_reload, TimerShouldFireWhenNotVisible fire_when_not_visible)
|
||||
int EventLoop::register_timer(EventReceiver& object, int milliseconds, bool should_reload, TimerShouldFireWhenNotVisible fire_when_not_visible)
|
||||
{
|
||||
return EventLoopManager::the().register_timer(object, milliseconds, should_reload, fire_when_not_visible);
|
||||
}
|
||||
|
|
|
@ -63,9 +63,9 @@ public:
|
|||
void spin_until(Function<bool()>);
|
||||
|
||||
// Post an event to this event loop.
|
||||
void post_event(Object& receiver, NonnullOwnPtr<Event>&&);
|
||||
void post_event(EventReceiver& receiver, NonnullOwnPtr<Event>&&);
|
||||
|
||||
void add_job(NonnullRefPtr<Promise<NonnullRefPtr<Object>>> job_promise);
|
||||
void add_job(NonnullRefPtr<Promise<NonnullRefPtr<EventReceiver>>> job_promise);
|
||||
|
||||
void deferred_invoke(Function<void()>);
|
||||
|
||||
|
@ -76,7 +76,7 @@ public:
|
|||
bool was_exit_requested() const;
|
||||
|
||||
// The registration functions act upon the current loop of the current thread.
|
||||
static int register_timer(Object&, int milliseconds, bool should_reload, TimerShouldFireWhenNotVisible);
|
||||
static int register_timer(EventReceiver&, int milliseconds, bool should_reload, TimerShouldFireWhenNotVisible);
|
||||
static bool unregister_timer(int timer_id);
|
||||
|
||||
static void register_notifier(Badge<Notifier>, Notifier&);
|
||||
|
|
|
@ -23,7 +23,7 @@ public:
|
|||
|
||||
virtual NonnullOwnPtr<EventLoopImplementation> make_implementation() = 0;
|
||||
|
||||
virtual int register_timer(Object&, int milliseconds, bool should_reload, TimerShouldFireWhenNotVisible) = 0;
|
||||
virtual int register_timer(EventReceiver&, int milliseconds, bool should_reload, TimerShouldFireWhenNotVisible) = 0;
|
||||
virtual bool unregister_timer(int timer_id) = 0;
|
||||
|
||||
virtual void register_notifier(Notifier&) = 0;
|
||||
|
@ -53,7 +53,7 @@ public:
|
|||
virtual void quit(int) = 0;
|
||||
virtual void wake() = 0;
|
||||
|
||||
virtual void post_event(Object& receiver, NonnullOwnPtr<Event>&&) = 0;
|
||||
virtual void post_event(EventReceiver& receiver, NonnullOwnPtr<Event>&&) = 0;
|
||||
|
||||
// FIXME: These APIs only exist for obscure use-cases inside SerenityOS. Try to get rid of them.
|
||||
virtual void unquit() = 0;
|
||||
|
|
|
@ -11,8 +11,8 @@
|
|||
#include <AK/WeakPtr.h>
|
||||
#include <LibCore/Event.h>
|
||||
#include <LibCore/EventLoopImplementationUnix.h>
|
||||
#include <LibCore/EventReceiver.h>
|
||||
#include <LibCore/Notifier.h>
|
||||
#include <LibCore/Object.h>
|
||||
#include <LibCore/Socket.h>
|
||||
#include <LibCore/System.h>
|
||||
#include <LibCore/ThreadEventQueue.h>
|
||||
|
@ -33,7 +33,7 @@ struct EventLoopTimer {
|
|||
MonotonicTime fire_time { MonotonicTime::now_coarse() };
|
||||
bool should_reload { false };
|
||||
TimerShouldFireWhenNotVisible fire_when_not_visible { TimerShouldFireWhenNotVisible::No };
|
||||
WeakPtr<Object> owner;
|
||||
WeakPtr<EventReceiver> owner;
|
||||
|
||||
void reload(MonotonicTime const& now) { fire_time = now + interval; }
|
||||
bool has_expired(MonotonicTime const& now) const { return now > fire_time; }
|
||||
|
@ -126,7 +126,7 @@ bool EventLoopImplementationUnix::was_exit_requested() const
|
|||
return m_exit_requested;
|
||||
}
|
||||
|
||||
void EventLoopImplementationUnix::post_event(Object& receiver, NonnullOwnPtr<Event>&& event)
|
||||
void EventLoopImplementationUnix::post_event(EventReceiver& receiver, NonnullOwnPtr<Event>&& event)
|
||||
{
|
||||
m_thread_event_queue.post_event(receiver, move(event));
|
||||
if (&m_thread_event_queue != &ThreadEventQueue::current())
|
||||
|
@ -481,7 +481,7 @@ void EventLoopManagerUnix::unregister_signal(int handler_id)
|
|||
info.signal_handlers.remove(remove_signal_number);
|
||||
}
|
||||
|
||||
int EventLoopManagerUnix::register_timer(Object& object, int milliseconds, bool should_reload, TimerShouldFireWhenNotVisible fire_when_not_visible)
|
||||
int EventLoopManagerUnix::register_timer(EventReceiver& object, int milliseconds, bool should_reload, TimerShouldFireWhenNotVisible fire_when_not_visible)
|
||||
{
|
||||
VERIFY(milliseconds >= 0);
|
||||
auto& thread_data = ThreadData::the();
|
||||
|
|
|
@ -17,7 +17,7 @@ public:
|
|||
|
||||
virtual NonnullOwnPtr<EventLoopImplementation> make_implementation() override;
|
||||
|
||||
virtual int register_timer(Object&, int milliseconds, bool should_reload, TimerShouldFireWhenNotVisible) override;
|
||||
virtual int register_timer(EventReceiver&, int milliseconds, bool should_reload, TimerShouldFireWhenNotVisible) override;
|
||||
virtual bool unregister_timer(int timer_id) override;
|
||||
|
||||
virtual void register_notifier(Notifier&) override;
|
||||
|
@ -52,7 +52,7 @@ public:
|
|||
virtual void unquit() override;
|
||||
virtual bool was_exit_requested() const override;
|
||||
virtual void notify_forked_and_in_child() override;
|
||||
virtual void post_event(Object& receiver, NonnullOwnPtr<Event>&&) override;
|
||||
virtual void post_event(EventReceiver& receiver, NonnullOwnPtr<Event>&&) override;
|
||||
|
||||
private:
|
||||
bool m_exit_requested { false };
|
||||
|
|
|
@ -10,19 +10,19 @@
|
|||
#include <AK/JsonObject.h>
|
||||
#include <LibCore/Event.h>
|
||||
#include <LibCore/EventLoop.h>
|
||||
#include <LibCore/Object.h>
|
||||
#include <LibCore/EventReceiver.h>
|
||||
#include <stdio.h>
|
||||
|
||||
namespace Core {
|
||||
|
||||
Object::Object(Object* parent)
|
||||
EventReceiver::EventReceiver(EventReceiver* parent)
|
||||
: m_parent(parent)
|
||||
{
|
||||
if (m_parent)
|
||||
m_parent->add_child(*this);
|
||||
}
|
||||
|
||||
Object::~Object()
|
||||
EventReceiver::~EventReceiver()
|
||||
{
|
||||
// NOTE: We move our children out to a stack vector to prevent other
|
||||
// code from trying to iterate over them.
|
||||
|
@ -37,7 +37,7 @@ Object::~Object()
|
|||
m_parent->remove_child(*this);
|
||||
}
|
||||
|
||||
void Object::event(Core::Event& event)
|
||||
void EventReceiver::event(Core::Event& event)
|
||||
{
|
||||
switch (event.type()) {
|
||||
case Core::Event::Timer:
|
||||
|
@ -55,7 +55,7 @@ void Object::event(Core::Event& event)
|
|||
}
|
||||
}
|
||||
|
||||
ErrorOr<void> Object::try_add_child(Object& object)
|
||||
ErrorOr<void> EventReceiver::try_add_child(EventReceiver& object)
|
||||
{
|
||||
// FIXME: Should we support reparenting objects?
|
||||
VERIFY(!object.parent() || object.parent() == this);
|
||||
|
@ -66,12 +66,12 @@ ErrorOr<void> Object::try_add_child(Object& object)
|
|||
return {};
|
||||
}
|
||||
|
||||
void Object::add_child(Object& object)
|
||||
void EventReceiver::add_child(EventReceiver& object)
|
||||
{
|
||||
MUST(try_add_child(object));
|
||||
}
|
||||
|
||||
void Object::insert_child_before(Object& new_child, Object& before_child)
|
||||
void EventReceiver::insert_child_before(EventReceiver& new_child, EventReceiver& before_child)
|
||||
{
|
||||
// FIXME: Should we support reparenting objects?
|
||||
VERIFY(!new_child.parent() || new_child.parent() == this);
|
||||
|
@ -81,12 +81,12 @@ void Object::insert_child_before(Object& new_child, Object& before_child)
|
|||
event(child_event);
|
||||
}
|
||||
|
||||
void Object::remove_child(Object& object)
|
||||
void EventReceiver::remove_child(EventReceiver& object)
|
||||
{
|
||||
for (size_t i = 0; i < m_children.size(); ++i) {
|
||||
if (m_children[i] == &object) {
|
||||
// NOTE: We protect the child so it survives the handling of ChildRemoved.
|
||||
NonnullRefPtr<Object> protector = object;
|
||||
NonnullRefPtr<EventReceiver> protector = object;
|
||||
object.m_parent = nullptr;
|
||||
m_children.remove(i);
|
||||
Core::ChildEvent child_event(Core::Event::ChildRemoved, object);
|
||||
|
@ -97,25 +97,25 @@ void Object::remove_child(Object& object)
|
|||
VERIFY_NOT_REACHED();
|
||||
}
|
||||
|
||||
void Object::remove_all_children()
|
||||
void EventReceiver::remove_all_children()
|
||||
{
|
||||
while (!m_children.is_empty())
|
||||
m_children.first()->remove_from_parent();
|
||||
}
|
||||
|
||||
void Object::timer_event(Core::TimerEvent&)
|
||||
void EventReceiver::timer_event(Core::TimerEvent&)
|
||||
{
|
||||
}
|
||||
|
||||
void Object::child_event(Core::ChildEvent&)
|
||||
void EventReceiver::child_event(Core::ChildEvent&)
|
||||
{
|
||||
}
|
||||
|
||||
void Object::custom_event(CustomEvent&)
|
||||
void EventReceiver::custom_event(CustomEvent&)
|
||||
{
|
||||
}
|
||||
|
||||
void Object::start_timer(int ms, TimerShouldFireWhenNotVisible fire_when_not_visible)
|
||||
void EventReceiver::start_timer(int ms, TimerShouldFireWhenNotVisible fire_when_not_visible)
|
||||
{
|
||||
if (m_timer_id) {
|
||||
dbgln("{} {:p} already has a timer!", class_name(), this);
|
||||
|
@ -125,7 +125,7 @@ void Object::start_timer(int ms, TimerShouldFireWhenNotVisible fire_when_not_vis
|
|||
m_timer_id = Core::EventLoop::register_timer(*this, ms, true, fire_when_not_visible);
|
||||
}
|
||||
|
||||
void Object::stop_timer()
|
||||
void EventReceiver::stop_timer()
|
||||
{
|
||||
if (!m_timer_id)
|
||||
return;
|
||||
|
@ -136,12 +136,12 @@ void Object::stop_timer()
|
|||
m_timer_id = 0;
|
||||
}
|
||||
|
||||
void Object::deferred_invoke(Function<void()> invokee)
|
||||
void EventReceiver::deferred_invoke(Function<void()> invokee)
|
||||
{
|
||||
Core::deferred_invoke([invokee = move(invokee), strong_this = NonnullRefPtr(*this)] { invokee(); });
|
||||
}
|
||||
|
||||
bool Object::is_ancestor_of(Object const& other) const
|
||||
bool EventReceiver::is_ancestor_of(EventReceiver const& other) const
|
||||
{
|
||||
if (&other == this)
|
||||
return false;
|
||||
|
@ -152,7 +152,7 @@ bool Object::is_ancestor_of(Object const& other) const
|
|||
return false;
|
||||
}
|
||||
|
||||
void Object::dispatch_event(Core::Event& e, Object* stay_within)
|
||||
void EventReceiver::dispatch_event(Core::Event& e, EventReceiver* stay_within)
|
||||
{
|
||||
VERIFY(!stay_within || stay_within == this || stay_within->is_ancestor_of(*this));
|
||||
auto* target = this;
|
||||
|
@ -169,14 +169,14 @@ void Object::dispatch_event(Core::Event& e, Object* stay_within)
|
|||
} while (target && !e.is_accepted());
|
||||
}
|
||||
|
||||
bool Object::is_visible_for_timer_purposes() const
|
||||
bool EventReceiver::is_visible_for_timer_purposes() const
|
||||
{
|
||||
if (parent())
|
||||
return parent()->is_visible_for_timer_purposes();
|
||||
return true;
|
||||
}
|
||||
|
||||
void Object::set_event_filter(Function<bool(Core::Event&)> filter)
|
||||
void EventReceiver::set_event_filter(Function<bool(Core::Event&)> filter)
|
||||
{
|
||||
m_event_filter = move(filter);
|
||||
}
|
|
@ -49,16 +49,16 @@ public: \
|
|||
return #klass##sv; \
|
||||
}
|
||||
|
||||
class Object
|
||||
: public RefCounted<Object>
|
||||
, public Weakable<Object> {
|
||||
// NOTE: No C_OBJECT macro for Core::Object itself.
|
||||
class EventReceiver
|
||||
: public RefCounted<EventReceiver>
|
||||
, public Weakable<EventReceiver> {
|
||||
// NOTE: No C_OBJECT macro for Core::EventReceiver itself.
|
||||
|
||||
AK_MAKE_NONCOPYABLE(Object);
|
||||
AK_MAKE_NONMOVABLE(Object);
|
||||
AK_MAKE_NONCOPYABLE(EventReceiver);
|
||||
AK_MAKE_NONMOVABLE(EventReceiver);
|
||||
|
||||
public:
|
||||
virtual ~Object();
|
||||
virtual ~EventReceiver();
|
||||
|
||||
virtual StringView class_name() const = 0;
|
||||
|
||||
|
@ -70,8 +70,8 @@ public:
|
|||
DeprecatedString const& name() const { return m_name; }
|
||||
void set_name(DeprecatedString name) { m_name = move(name); }
|
||||
|
||||
Vector<NonnullRefPtr<Object>>& children() { return m_children; }
|
||||
Vector<NonnullRefPtr<Object>> const& children() const { return m_children; }
|
||||
Vector<NonnullRefPtr<EventReceiver>>& children() { return m_children; }
|
||||
Vector<NonnullRefPtr<EventReceiver>> const& children() const { return m_children; }
|
||||
|
||||
template<typename Callback>
|
||||
void for_each_child(Callback callback)
|
||||
|
@ -84,51 +84,51 @@ public:
|
|||
|
||||
template<typename T, typename Callback>
|
||||
void for_each_child_of_type(Callback callback)
|
||||
requires IsBaseOf<Object, T>;
|
||||
requires IsBaseOf<EventReceiver, T>;
|
||||
|
||||
template<typename T>
|
||||
T* find_child_of_type_named(StringView)
|
||||
requires IsBaseOf<Object, T>;
|
||||
requires IsBaseOf<EventReceiver, T>;
|
||||
|
||||
template<typename T, size_t N>
|
||||
ALWAYS_INLINE T* find_child_of_type_named(char const (&string_literal)[N])
|
||||
requires IsBaseOf<Object, T>
|
||||
requires IsBaseOf<EventReceiver, T>
|
||||
{
|
||||
return find_child_of_type_named<T>(StringView { string_literal, N - 1 });
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
T* find_descendant_of_type_named(StringView)
|
||||
requires IsBaseOf<Object, T>;
|
||||
requires IsBaseOf<EventReceiver, T>;
|
||||
|
||||
template<typename T, size_t N>
|
||||
ALWAYS_INLINE T* find_descendant_of_type_named(char const (&string_literal)[N])
|
||||
requires IsBaseOf<Object, T>
|
||||
requires IsBaseOf<EventReceiver, T>
|
||||
{
|
||||
return find_descendant_of_type_named<T>(StringView { string_literal, N - 1 });
|
||||
}
|
||||
|
||||
bool is_ancestor_of(Object const&) const;
|
||||
bool is_ancestor_of(EventReceiver const&) const;
|
||||
|
||||
Object* parent() { return m_parent; }
|
||||
Object const* parent() const { return m_parent; }
|
||||
EventReceiver* parent() { return m_parent; }
|
||||
EventReceiver const* parent() const { return m_parent; }
|
||||
|
||||
void start_timer(int ms, TimerShouldFireWhenNotVisible = TimerShouldFireWhenNotVisible::No);
|
||||
void stop_timer();
|
||||
bool has_timer() const { return m_timer_id; }
|
||||
|
||||
ErrorOr<void> try_add_child(Object&);
|
||||
ErrorOr<void> try_add_child(EventReceiver&);
|
||||
|
||||
void add_child(Object&);
|
||||
void insert_child_before(Object& new_child, Object& before_child);
|
||||
void remove_child(Object&);
|
||||
void add_child(EventReceiver&);
|
||||
void insert_child_before(EventReceiver& new_child, EventReceiver& before_child);
|
||||
void remove_child(EventReceiver&);
|
||||
void remove_all_children();
|
||||
|
||||
void set_event_filter(Function<bool(Core::Event&)>);
|
||||
|
||||
void deferred_invoke(Function<void()>);
|
||||
|
||||
void dispatch_event(Core::Event&, Object* stay_within = nullptr);
|
||||
void dispatch_event(Core::Event&, EventReceiver* stay_within = nullptr);
|
||||
|
||||
void remove_from_parent()
|
||||
{
|
||||
|
@ -155,7 +155,7 @@ public:
|
|||
virtual bool is_visible_for_timer_purposes() const;
|
||||
|
||||
protected:
|
||||
explicit Object(Object* parent = nullptr);
|
||||
explicit EventReceiver(EventReceiver* parent = nullptr);
|
||||
|
||||
virtual void event(Core::Event&);
|
||||
|
||||
|
@ -166,18 +166,18 @@ protected:
|
|||
virtual void child_event(ChildEvent&);
|
||||
|
||||
private:
|
||||
Object* m_parent { nullptr };
|
||||
EventReceiver* m_parent { nullptr };
|
||||
DeprecatedString m_name;
|
||||
int m_timer_id { 0 };
|
||||
Vector<NonnullRefPtr<Object>> m_children;
|
||||
Vector<NonnullRefPtr<EventReceiver>> m_children;
|
||||
Function<bool(Core::Event&)> m_event_filter;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
template<>
|
||||
struct AK::Formatter<Core::Object> : AK::Formatter<FormatString> {
|
||||
ErrorOr<void> format(FormatBuilder& builder, Core::Object const& value)
|
||||
struct AK::Formatter<Core::EventReceiver> : AK::Formatter<FormatString> {
|
||||
ErrorOr<void> format(FormatBuilder& builder, Core::EventReceiver const& value)
|
||||
{
|
||||
return AK::Formatter<FormatString>::format(builder, "{}({})"sv, value.class_name(), &value);
|
||||
}
|
||||
|
@ -185,8 +185,8 @@ struct AK::Formatter<Core::Object> : AK::Formatter<FormatString> {
|
|||
|
||||
namespace Core {
|
||||
template<typename T, typename Callback>
|
||||
inline void Object::for_each_child_of_type(Callback callback)
|
||||
requires IsBaseOf<Object, T>
|
||||
inline void EventReceiver::for_each_child_of_type(Callback callback)
|
||||
requires IsBaseOf<EventReceiver, T>
|
||||
{
|
||||
for_each_child([&](auto& child) {
|
||||
if (is<T>(child))
|
||||
|
@ -196,8 +196,8 @@ requires IsBaseOf<Object, T>
|
|||
}
|
||||
|
||||
template<typename T>
|
||||
T* Object::find_child_of_type_named(StringView name)
|
||||
requires IsBaseOf<Object, T>
|
||||
T* EventReceiver::find_child_of_type_named(StringView name)
|
||||
requires IsBaseOf<EventReceiver, T>
|
||||
{
|
||||
T* found_child = nullptr;
|
||||
for_each_child_of_type<T>([&](auto& child) {
|
||||
|
@ -212,8 +212,8 @@ requires IsBaseOf<Object, T>
|
|||
}
|
||||
|
||||
template<typename T>
|
||||
T* Object::find_descendant_of_type_named(StringView name)
|
||||
requires IsBaseOf<Object, T>
|
||||
T* EventReceiver::find_descendant_of_type_named(StringView name)
|
||||
requires IsBaseOf<EventReceiver, T>
|
||||
{
|
||||
if (is<T>(*this) && this->name() == name) {
|
||||
return static_cast<T*>(this);
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
||||
* Copyright (c) 2018-2023, Andreas Kling <kling@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
@ -22,6 +22,7 @@ class DeferredInvocationContext;
|
|||
class ElapsedTimer;
|
||||
class Event;
|
||||
class EventLoop;
|
||||
class EventReceiver;
|
||||
class File;
|
||||
class LocalServer;
|
||||
class LocalSocket;
|
||||
|
@ -30,8 +31,6 @@ class MimeData;
|
|||
class NetworkJob;
|
||||
class NetworkResponse;
|
||||
class Notifier;
|
||||
class Object;
|
||||
class ObjectClassRegistration;
|
||||
class ProcessStatisticsReader;
|
||||
class Socket;
|
||||
template<typename Result, typename TError = AK::Error>
|
||||
|
|
|
@ -22,8 +22,8 @@
|
|||
|
||||
namespace Core {
|
||||
|
||||
LocalServer::LocalServer(Object* parent)
|
||||
: Object(parent)
|
||||
LocalServer::LocalServer(EventReceiver* parent)
|
||||
: EventReceiver(parent)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
@ -6,12 +6,12 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <LibCore/EventReceiver.h>
|
||||
#include <LibCore/Notifier.h>
|
||||
#include <LibCore/Object.h>
|
||||
|
||||
namespace Core {
|
||||
|
||||
class LocalServer : public Object {
|
||||
class LocalServer : public EventReceiver {
|
||||
C_OBJECT(LocalServer)
|
||||
public:
|
||||
virtual ~LocalServer() override;
|
||||
|
@ -26,7 +26,7 @@ public:
|
|||
Function<void(Error)> on_accept_error;
|
||||
|
||||
private:
|
||||
explicit LocalServer(Object* parent = nullptr);
|
||||
explicit LocalServer(EventReceiver* parent = nullptr);
|
||||
|
||||
void setup_notifier();
|
||||
|
||||
|
|
|
@ -10,11 +10,11 @@
|
|||
#include <AK/ByteBuffer.h>
|
||||
#include <AK/HashMap.h>
|
||||
#include <AK/URL.h>
|
||||
#include <LibCore/Object.h>
|
||||
#include <LibCore/EventReceiver.h>
|
||||
|
||||
namespace Core {
|
||||
|
||||
class MimeData : public Object {
|
||||
class MimeData : public EventReceiver {
|
||||
C_OBJECT(MimeData);
|
||||
|
||||
public:
|
||||
|
|
|
@ -9,12 +9,12 @@
|
|||
|
||||
#include <AK/Function.h>
|
||||
#include <AK/Stream.h>
|
||||
#include <LibCore/EventReceiver.h>
|
||||
#include <LibCore/Forward.h>
|
||||
#include <LibCore/Object.h>
|
||||
|
||||
namespace Core {
|
||||
|
||||
class NetworkJob : public Object {
|
||||
class NetworkJob : public EventReceiver {
|
||||
C_OBJECT_ABSTRACT(NetworkJob)
|
||||
public:
|
||||
enum class Error {
|
||||
|
@ -70,5 +70,5 @@ char const* to_string(NetworkJob::Error);
|
|||
}
|
||||
|
||||
template<>
|
||||
struct AK::Formatter<Core::NetworkJob> : Formatter<Core::Object> {
|
||||
struct AK::Formatter<Core::NetworkJob> : Formatter<Core::EventReceiver> {
|
||||
};
|
||||
|
|
|
@ -10,8 +10,8 @@
|
|||
|
||||
namespace Core {
|
||||
|
||||
Notifier::Notifier(int fd, Type type, Object* parent)
|
||||
: Object(parent)
|
||||
Notifier::Notifier(int fd, Type type, EventReceiver* parent)
|
||||
: EventReceiver(parent)
|
||||
, m_fd(fd)
|
||||
, m_type(type)
|
||||
{
|
||||
|
@ -48,7 +48,7 @@ void Notifier::event(Core::Event& event)
|
|||
on_activation();
|
||||
return;
|
||||
}
|
||||
Object::event(event);
|
||||
EventReceiver::event(event);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -7,11 +7,11 @@
|
|||
#pragma once
|
||||
|
||||
#include <AK/Function.h>
|
||||
#include <LibCore/Object.h>
|
||||
#include <LibCore/EventReceiver.h>
|
||||
|
||||
namespace Core {
|
||||
|
||||
class Notifier final : public Object {
|
||||
class Notifier final : public EventReceiver {
|
||||
C_OBJECT(Notifier);
|
||||
|
||||
public:
|
||||
|
@ -37,7 +37,7 @@ public:
|
|||
void event(Core::Event&) override;
|
||||
|
||||
private:
|
||||
Notifier(int fd, Type type, Object* parent = nullptr);
|
||||
Notifier(int fd, Type type, EventReceiver* parent = nullptr);
|
||||
|
||||
int m_fd { -1 };
|
||||
Type m_type { Type::None };
|
||||
|
|
|
@ -10,12 +10,12 @@
|
|||
|
||||
#include <AK/Concepts.h>
|
||||
#include <LibCore/EventLoop.h>
|
||||
#include <LibCore/Object.h>
|
||||
#include <LibCore/EventReceiver.h>
|
||||
|
||||
namespace Core {
|
||||
|
||||
template<typename Result, typename TError>
|
||||
class Promise : public Object {
|
||||
class Promise : public EventReceiver {
|
||||
C_OBJECT(Promise);
|
||||
|
||||
public:
|
||||
|
@ -116,8 +116,8 @@ private:
|
|||
}
|
||||
|
||||
Promise() = default;
|
||||
Promise(Object* parent)
|
||||
: Object(parent)
|
||||
Promise(EventReceiver* parent)
|
||||
: EventReceiver(parent)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
|
||||
namespace Core {
|
||||
|
||||
ErrorOr<NonnullRefPtr<TCPServer>> TCPServer::try_create(Object* parent)
|
||||
ErrorOr<NonnullRefPtr<TCPServer>> TCPServer::try_create(EventReceiver* parent)
|
||||
{
|
||||
#ifdef SOCK_NONBLOCK
|
||||
int fd = TRY(Core::System::socket(AF_INET, SOCK_STREAM | SOCK_NONBLOCK | SOCK_CLOEXEC, 0));
|
||||
|
@ -28,8 +28,8 @@ ErrorOr<NonnullRefPtr<TCPServer>> TCPServer::try_create(Object* parent)
|
|||
return adopt_nonnull_ref_or_enomem(new (nothrow) TCPServer(fd, parent));
|
||||
}
|
||||
|
||||
TCPServer::TCPServer(int fd, Object* parent)
|
||||
: Object(parent)
|
||||
TCPServer::TCPServer(int fd, EventReceiver* parent)
|
||||
: EventReceiver(parent)
|
||||
, m_fd(fd)
|
||||
{
|
||||
VERIFY(m_fd >= 0);
|
||||
|
|
|
@ -8,15 +8,15 @@
|
|||
#pragma once
|
||||
|
||||
#include <AK/IPv4Address.h>
|
||||
#include <LibCore/EventReceiver.h>
|
||||
#include <LibCore/Notifier.h>
|
||||
#include <LibCore/Object.h>
|
||||
|
||||
namespace Core {
|
||||
|
||||
class TCPServer : public Object {
|
||||
class TCPServer : public EventReceiver {
|
||||
C_OBJECT_ABSTRACT(TCPServer)
|
||||
public:
|
||||
static ErrorOr<NonnullRefPtr<TCPServer>> try_create(Object* parent = nullptr);
|
||||
static ErrorOr<NonnullRefPtr<TCPServer>> try_create(EventReceiver* parent = nullptr);
|
||||
virtual ~TCPServer() override;
|
||||
|
||||
enum class AllowAddressReuse {
|
||||
|
@ -36,7 +36,7 @@ public:
|
|||
Function<void()> on_ready_to_accept;
|
||||
|
||||
private:
|
||||
explicit TCPServer(int fd, Object* parent = nullptr);
|
||||
explicit TCPServer(int fd, EventReceiver* parent = nullptr);
|
||||
|
||||
int m_fd { -1 };
|
||||
bool m_listening { false };
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
#include <AK/Vector.h>
|
||||
#include <LibCore/DeferredInvocationContext.h>
|
||||
#include <LibCore/EventLoopImplementation.h>
|
||||
#include <LibCore/Object.h>
|
||||
#include <LibCore/EventReceiver.h>
|
||||
#include <LibCore/Promise.h>
|
||||
#include <LibCore/ThreadEventQueue.h>
|
||||
#include <LibThreading/Mutex.h>
|
||||
|
@ -21,7 +21,7 @@ struct ThreadEventQueue::Private {
|
|||
AK_MAKE_DEFAULT_MOVABLE(QueuedEvent);
|
||||
|
||||
public:
|
||||
QueuedEvent(Object& receiver, NonnullOwnPtr<Event> event)
|
||||
QueuedEvent(EventReceiver& receiver, NonnullOwnPtr<Event> event)
|
||||
: receiver(receiver)
|
||||
, event(move(event))
|
||||
{
|
||||
|
@ -29,13 +29,13 @@ struct ThreadEventQueue::Private {
|
|||
|
||||
~QueuedEvent() = default;
|
||||
|
||||
WeakPtr<Object> receiver;
|
||||
WeakPtr<EventReceiver> receiver;
|
||||
NonnullOwnPtr<Event> event;
|
||||
};
|
||||
|
||||
Threading::Mutex mutex;
|
||||
Vector<QueuedEvent, 128> queued_events;
|
||||
Vector<NonnullRefPtr<Promise<NonnullRefPtr<Object>>>, 16> pending_promises;
|
||||
Vector<NonnullRefPtr<Promise<NonnullRefPtr<EventReceiver>>>, 16> pending_promises;
|
||||
bool warned_promise_count { false };
|
||||
};
|
||||
|
||||
|
@ -57,7 +57,7 @@ ThreadEventQueue::ThreadEventQueue()
|
|||
|
||||
ThreadEventQueue::~ThreadEventQueue() = default;
|
||||
|
||||
void ThreadEventQueue::post_event(Core::Object& receiver, NonnullOwnPtr<Core::Event> event)
|
||||
void ThreadEventQueue::post_event(Core::EventReceiver& receiver, NonnullOwnPtr<Core::Event> event)
|
||||
{
|
||||
{
|
||||
Threading::MutexLocker lock(m_private->mutex);
|
||||
|
@ -66,7 +66,7 @@ void ThreadEventQueue::post_event(Core::Object& receiver, NonnullOwnPtr<Core::Ev
|
|||
Core::EventLoopManager::the().did_post_event();
|
||||
}
|
||||
|
||||
void ThreadEventQueue::add_job(NonnullRefPtr<Promise<NonnullRefPtr<Object>>> promise)
|
||||
void ThreadEventQueue::add_job(NonnullRefPtr<Promise<NonnullRefPtr<EventReceiver>>> promise)
|
||||
{
|
||||
Threading::MutexLocker lock(m_private->mutex);
|
||||
m_private->pending_promises.append(move(promise));
|
||||
|
@ -107,7 +107,7 @@ size_t ThreadEventQueue::process()
|
|||
} else if (event.type() == Event::Type::DeferredInvoke) {
|
||||
static_cast<DeferredInvocationEvent&>(event).m_invokee();
|
||||
} else {
|
||||
NonnullRefPtr<Object> protector(*receiver);
|
||||
NonnullRefPtr<EventReceiver> protector(*receiver);
|
||||
receiver->dispatch_event(event);
|
||||
}
|
||||
++processed_events;
|
||||
|
|
|
@ -25,10 +25,10 @@ public:
|
|||
size_t process();
|
||||
|
||||
// Posts an event to the event queue.
|
||||
void post_event(Object& receiver, NonnullOwnPtr<Event>);
|
||||
void post_event(EventReceiver& receiver, NonnullOwnPtr<Event>);
|
||||
|
||||
// Used by Threading::BackgroundAction.
|
||||
void add_job(NonnullRefPtr<Promise<NonnullRefPtr<Object>>>);
|
||||
void add_job(NonnullRefPtr<Promise<NonnullRefPtr<EventReceiver>>>);
|
||||
void cancel_all_pending_jobs();
|
||||
|
||||
// Returns true if there are events waiting to be flushed.
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
#include <AK/AtomicRefCounted.h>
|
||||
#include <AK/Concepts.h>
|
||||
#include <LibCore/EventLoop.h>
|
||||
#include <LibCore/Object.h>
|
||||
#include <LibCore/EventReceiver.h>
|
||||
#include <LibThreading/Mutex.h>
|
||||
|
||||
namespace Core {
|
||||
|
@ -179,8 +179,8 @@ private:
|
|||
}
|
||||
|
||||
ThreadedPromise() = default;
|
||||
ThreadedPromise(Object* parent)
|
||||
: Object(parent)
|
||||
ThreadedPromise(EventReceiver* parent)
|
||||
: EventReceiver(parent)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
@ -9,13 +9,13 @@
|
|||
|
||||
namespace Core {
|
||||
|
||||
Timer::Timer(Object* parent)
|
||||
: Object(parent)
|
||||
Timer::Timer(EventReceiver* parent)
|
||||
: EventReceiver(parent)
|
||||
{
|
||||
}
|
||||
|
||||
Timer::Timer(int interval_ms, Function<void()>&& timeout_handler, Object* parent)
|
||||
: Object(parent)
|
||||
Timer::Timer(int interval_ms, Function<void()>&& timeout_handler, EventReceiver* parent)
|
||||
: EventReceiver(parent)
|
||||
, on_timeout(move(timeout_handler))
|
||||
, m_interval_ms(interval_ms)
|
||||
{
|
||||
|
|
|
@ -8,19 +8,19 @@
|
|||
#pragma once
|
||||
|
||||
#include <AK/Function.h>
|
||||
#include <LibCore/Object.h>
|
||||
#include <LibCore/EventReceiver.h>
|
||||
|
||||
namespace Core {
|
||||
|
||||
class Timer final : public Object {
|
||||
class Timer final : public EventReceiver {
|
||||
C_OBJECT(Timer);
|
||||
|
||||
public:
|
||||
static ErrorOr<NonnullRefPtr<Timer>> create_repeating(int interval_ms, Function<void()>&& timeout_handler, Object* parent = nullptr)
|
||||
static ErrorOr<NonnullRefPtr<Timer>> create_repeating(int interval_ms, Function<void()>&& timeout_handler, EventReceiver* parent = nullptr)
|
||||
{
|
||||
return adopt_nonnull_ref_or_enomem(new Timer(interval_ms, move(timeout_handler), parent));
|
||||
}
|
||||
static ErrorOr<NonnullRefPtr<Timer>> create_single_shot(int interval_ms, Function<void()>&& timeout_handler, Object* parent = nullptr)
|
||||
static ErrorOr<NonnullRefPtr<Timer>> create_single_shot(int interval_ms, Function<void()>&& timeout_handler, EventReceiver* parent = nullptr)
|
||||
{
|
||||
auto timer = TRY(adopt_nonnull_ref_or_enomem(new Timer(interval_ms, move(timeout_handler), parent)));
|
||||
timer->set_single_shot(true);
|
||||
|
@ -53,8 +53,8 @@ public:
|
|||
Function<void()> on_timeout;
|
||||
|
||||
private:
|
||||
explicit Timer(Object* parent = nullptr);
|
||||
Timer(int interval_ms, Function<void()>&& timeout_handler, Object* parent = nullptr);
|
||||
explicit Timer(EventReceiver* parent = nullptr);
|
||||
Timer(int interval_ms, Function<void()>&& timeout_handler, EventReceiver* parent = nullptr);
|
||||
|
||||
virtual void timer_event(TimerEvent&) override;
|
||||
|
||||
|
|
|
@ -21,8 +21,8 @@
|
|||
|
||||
namespace Core {
|
||||
|
||||
UDPServer::UDPServer(Object* parent)
|
||||
: Object(parent)
|
||||
UDPServer::UDPServer(EventReceiver* parent)
|
||||
: EventReceiver(parent)
|
||||
{
|
||||
#ifdef SOCK_NONBLOCK
|
||||
m_fd = socket(AF_INET, SOCK_DGRAM | SOCK_NONBLOCK | SOCK_CLOEXEC, 0);
|
||||
|
|
|
@ -10,13 +10,13 @@
|
|||
#include <AK/ByteBuffer.h>
|
||||
#include <AK/Forward.h>
|
||||
#include <AK/Function.h>
|
||||
#include <LibCore/EventReceiver.h>
|
||||
#include <LibCore/Forward.h>
|
||||
#include <LibCore/Object.h>
|
||||
#include <LibCore/SocketAddress.h>
|
||||
|
||||
namespace Core {
|
||||
|
||||
class UDPServer : public Object {
|
||||
class UDPServer : public EventReceiver {
|
||||
C_OBJECT(UDPServer)
|
||||
public:
|
||||
virtual ~UDPServer() override;
|
||||
|
@ -41,7 +41,7 @@ public:
|
|||
Function<void()> on_ready_to_receive;
|
||||
|
||||
protected:
|
||||
explicit UDPServer(Object* parent = nullptr);
|
||||
explicit UDPServer(EventReceiver* parent = nullptr);
|
||||
|
||||
private:
|
||||
int m_fd { -1 };
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue