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

LibCore: Put all classes in the Core namespace and remove the leading C

I've been wanting to do this for a long time. It's time we start being
consistent about how this stuff works.

The new convention is:

- "LibFoo" is a userspace library that provides the "Foo" namespace.

That's it :^) This was pretty tedious to convert and I didn't even
start on LibGUI yet. But it's coming up next.
This commit is contained in:
Andreas Kling 2020-02-02 12:34:39 +01:00
parent b7e3810b5c
commit 2d39da5405
265 changed files with 1380 additions and 1167 deletions

View file

@ -31,9 +31,9 @@
#include <limits>
AWavLoader::AWavLoader(const StringView& path)
: m_file(CFile::construct(path))
: m_file(Core::File::construct(path))
{
if (!m_file->open(CIODevice::ReadOnly)) {
if (!m_file->open(Core::IODevice::ReadOnly)) {
m_error_string = String::format("Can't open file: %s", m_file->error_string());
return;
}
@ -75,7 +75,7 @@ void AWavLoader::reset()
bool AWavLoader::parse_header()
{
CIODeviceStreamReader stream(*m_file);
Core::IODeviceStreamReader stream(*m_file);
#define CHECK_OK(msg) \
do { \

View file

@ -56,11 +56,11 @@ public:
u32 sample_rate() const { return m_sample_rate; }
u16 num_channels() const { return m_num_channels; }
u16 bits_per_sample() const { return m_bits_per_sample; }
RefPtr<CFile> file() const { return m_file; }
RefPtr<Core::File> file() const { return m_file; }
private:
bool parse_header();
RefPtr<CFile> m_file;
RefPtr<Core::File> m_file;
String m_error_string;
OwnPtr<AResampleHelper> m_resampler;

View file

@ -30,12 +30,14 @@
#include <limits.h>
#include <stdio.h>
CArgsParser::CArgsParser()
namespace Core {
ArgsParser::ArgsParser()
{
add_option(m_show_help, "Display this message", "help", 0);
}
void CArgsParser::parse(int argc, char** argv)
void ArgsParser::parse(int argc, char** argv)
{
auto print_usage_and_exit = [this, argv] {
print_usage(stderr, argv[0]);
@ -148,7 +150,7 @@ void CArgsParser::parse(int argc, char** argv)
}
}
void CArgsParser::print_usage(FILE* file, const char* argv0)
void ArgsParser::print_usage(FILE* file, const char* argv0)
{
fprintf(file, "Usage:\n\t%s", argv0);
@ -214,12 +216,12 @@ void CArgsParser::print_usage(FILE* file, const char* argv0)
}
}
void CArgsParser::add_option(Option&& option)
void ArgsParser::add_option(Option&& option)
{
m_options.append(move(option));
}
void CArgsParser::add_option(bool& value, const char* help_string, const char* long_name, char short_name)
void ArgsParser::add_option(bool& value, const char* help_string, const char* long_name, char short_name)
{
Option option {
false,
@ -236,7 +238,7 @@ void CArgsParser::add_option(bool& value, const char* help_string, const char* l
add_option(move(option));
}
void CArgsParser::add_option(const char*& value, const char* help_string, const char* long_name, char short_name, const char* value_name)
void ArgsParser::add_option(const char*& value, const char* help_string, const char* long_name, char short_name, const char* value_name)
{
Option option {
true,
@ -252,7 +254,7 @@ void CArgsParser::add_option(const char*& value, const char* help_string, const
add_option(move(option));
}
void CArgsParser::add_option(int& value, const char* help_string, const char* long_name, char short_name, const char* value_name)
void ArgsParser::add_option(int& value, const char* help_string, const char* long_name, char short_name, const char* value_name)
{
Option option {
true,
@ -269,12 +271,12 @@ void CArgsParser::add_option(int& value, const char* help_string, const char* lo
add_option(move(option));
}
void CArgsParser::add_positional_argument(Arg&& arg)
void ArgsParser::add_positional_argument(Arg&& arg)
{
m_positional_args.append(move(arg));
}
void CArgsParser::add_positional_argument(const char*& value, const char* help_string, const char* name, Required required)
void ArgsParser::add_positional_argument(const char*& value, const char* help_string, const char* name, Required required)
{
Arg arg {
help_string,
@ -289,7 +291,7 @@ void CArgsParser::add_positional_argument(const char*& value, const char* help_s
add_positional_argument(move(arg));
}
void CArgsParser::add_positional_argument(int& value, const char* help_string, const char* name, Required required)
void ArgsParser::add_positional_argument(int& value, const char* help_string, const char* name, Required required)
{
Arg arg {
help_string,
@ -305,7 +307,7 @@ void CArgsParser::add_positional_argument(int& value, const char* help_string, c
add_positional_argument(move(arg));
}
void CArgsParser::add_positional_argument(Vector<const char*>& values, const char* help_string, const char* name, Required required)
void ArgsParser::add_positional_argument(Vector<const char*>& values, const char* help_string, const char* name, Required required)
{
Arg arg {
help_string,
@ -319,3 +321,5 @@ void CArgsParser::add_positional_argument(Vector<const char*>& values, const cha
};
add_positional_argument(move(arg));
}
}

View file

@ -31,9 +31,11 @@
#include <AK/Vector.h>
#include <stdio.h>
class CArgsParser {
namespace Core {
class ArgsParser {
public:
CArgsParser();
ArgsParser();
enum class Required {
Yes,
@ -83,3 +85,5 @@ private:
bool m_show_help { false };
};
}

View file

@ -32,43 +32,45 @@
#include <stdio.h>
#include <unistd.h>
NonnullRefPtr<CConfigFile> CConfigFile::get_for_app(const String& app_name)
namespace Core {
NonnullRefPtr<ConfigFile> ConfigFile::get_for_app(const String& app_name)
{
String home_path = get_current_user_home_path();
if (home_path == "/")
home_path = String::format("/tmp");
auto path = String::format("%s/%s.ini", home_path.characters(), app_name.characters());
return adopt(*new CConfigFile(path));
return adopt(*new ConfigFile(path));
}
NonnullRefPtr<CConfigFile> CConfigFile::get_for_system(const String& app_name)
NonnullRefPtr<ConfigFile> ConfigFile::get_for_system(const String& app_name)
{
auto path = String::format("/etc/%s.ini", app_name.characters());
return adopt(*new CConfigFile(path));
return adopt(*new ConfigFile(path));
}
NonnullRefPtr<CConfigFile> CConfigFile::open(const String& path)
NonnullRefPtr<ConfigFile> ConfigFile::open(const String& path)
{
return adopt(*new CConfigFile(path));
return adopt(*new ConfigFile(path));
}
CConfigFile::CConfigFile(const String& file_name)
ConfigFile::ConfigFile(const String& file_name)
: m_file_name(file_name)
{
reparse();
}
CConfigFile::~CConfigFile()
ConfigFile::~ConfigFile()
{
sync();
}
void CConfigFile::reparse()
void ConfigFile::reparse()
{
m_groups.clear();
auto file = CFile::construct(m_file_name);
if (!file->open(CIODevice::OpenMode::ReadOnly))
auto file = File::construct(m_file_name);
if (!file->open(IODevice::OpenMode::ReadOnly))
return;
HashMap<String, String>* current_group = nullptr;
@ -111,10 +113,10 @@ void CConfigFile::reparse()
}
}
String CConfigFile::read_entry(const String& group, const String& key, const String& default_value) const
String ConfigFile::read_entry(const String& group, const String& key, const String& default_value) const
{
if (!has_key(group, key)) {
const_cast<CConfigFile&>(*this).write_entry(group, key, default_value);
const_cast<ConfigFile&>(*this).write_entry(group, key, default_value);
return default_value;
}
auto it = m_groups.find(group);
@ -122,10 +124,10 @@ String CConfigFile::read_entry(const String& group, const String& key, const Str
return jt->value;
}
int CConfigFile::read_num_entry(const String& group, const String& key, int default_value) const
int ConfigFile::read_num_entry(const String& group, const String& key, int default_value) const
{
if (!has_key(group, key)) {
const_cast<CConfigFile&>(*this).write_num_entry(group, key, default_value);
const_cast<ConfigFile&>(*this).write_num_entry(group, key, default_value);
return default_value;
}
@ -136,31 +138,31 @@ int CConfigFile::read_num_entry(const String& group, const String& key, int defa
return value;
}
bool CConfigFile::read_bool_entry(const String& group, const String& key, bool default_value) const
bool ConfigFile::read_bool_entry(const String& group, const String& key, bool default_value) const
{
return read_entry(group, key, default_value ? "1" : "0") == "1";
}
void CConfigFile::write_entry(const String& group, const String& key, const String& value)
void ConfigFile::write_entry(const String& group, const String& key, const String& value)
{
m_groups.ensure(group).ensure(key) = value;
m_dirty = true;
}
void CConfigFile::write_num_entry(const String& group, const String& key, int value)
void ConfigFile::write_num_entry(const String& group, const String& key, int value)
{
write_entry(group, key, String::number(value));
}
void CConfigFile::write_bool_entry(const String& group, const String& key, bool value)
void ConfigFile::write_bool_entry(const String& group, const String& key, bool value)
{
write_entry(group, key, value ? "1" : "0");
}
void CConfigFile::write_color_entry(const String& group, const String& key, Color value)
void ConfigFile::write_color_entry(const String& group, const String& key, Color value)
{
write_entry(group, key, String::format("%d,%d,%d,%d", value.red(), value.green(), value.blue(), value.alpha()));
}
bool CConfigFile::sync()
bool ConfigFile::sync()
{
if (!m_dirty)
return true;
@ -182,7 +184,7 @@ bool CConfigFile::sync()
return true;
}
void CConfigFile::dump() const
void ConfigFile::dump() const
{
for (auto& it : m_groups) {
printf("[%s]\n", it.key.characters());
@ -192,12 +194,12 @@ void CConfigFile::dump() const
}
}
Vector<String> CConfigFile::groups() const
Vector<String> ConfigFile::groups() const
{
return m_groups.keys();
}
Vector<String> CConfigFile::keys(const String& group) const
Vector<String> ConfigFile::keys(const String& group) const
{
auto it = m_groups.find(group);
if (it == m_groups.end())
@ -205,7 +207,7 @@ Vector<String> CConfigFile::keys(const String& group) const
return it->value.keys();
}
bool CConfigFile::has_key(const String& group, const String& key) const
bool ConfigFile::has_key(const String& group, const String& key) const
{
auto it = m_groups.find(group);
if (it == m_groups.end())
@ -213,18 +215,18 @@ bool CConfigFile::has_key(const String& group, const String& key) const
return it->value.contains(key);
}
bool CConfigFile::has_group(const String& group) const
bool ConfigFile::has_group(const String& group) const
{
return m_groups.contains(group);
}
void CConfigFile::remove_group(const String& group)
void ConfigFile::remove_group(const String& group)
{
m_groups.remove(group);
m_dirty = true;
}
void CConfigFile::remove_entry(const String& group, const String& key)
void ConfigFile::remove_entry(const String& group, const String& key)
{
auto it = m_groups.find(group);
if (it == m_groups.end())
@ -232,3 +234,5 @@ void CConfigFile::remove_entry(const String& group, const String& key)
it->value.remove(key);
m_dirty = true;
}
}

View file

@ -26,19 +26,21 @@
#pragma once
#include <AK/String.h>
#include <AK/HashMap.h>
#include <AK/RefPtr.h>
#include <AK/RefCounted.h>
#include <AK/RefPtr.h>
#include <AK/String.h>
#include <AK/Vector.h>
#include <LibDraw/Color.h>
class CConfigFile : public RefCounted<CConfigFile> {
namespace Core {
class ConfigFile : public RefCounted<ConfigFile> {
public:
static NonnullRefPtr<CConfigFile> get_for_app(const String& app_name);
static NonnullRefPtr<CConfigFile> get_for_system(const String& app_name);
static NonnullRefPtr<CConfigFile> open(const String& path);
~CConfigFile();
static NonnullRefPtr<ConfigFile> get_for_app(const String& app_name);
static NonnullRefPtr<ConfigFile> get_for_system(const String& app_name);
static NonnullRefPtr<ConfigFile> open(const String& path);
~ConfigFile();
bool has_group(const String&) const;
bool has_key(const String& group, const String& key) const;
@ -67,7 +69,7 @@ public:
String file_name() const { return m_file_name; }
private:
explicit CConfigFile(const String& file_name);
explicit ConfigFile(const String& file_name);
void reparse();
@ -75,3 +77,5 @@ private:
HashMap<String, HashMap<String, String>> m_groups;
bool m_dirty { false };
};
}

View file

@ -25,9 +25,11 @@
*/
#include "CDirIterator.h"
#include <cerrno>
#include <errno.h>
CDirIterator::CDirIterator(const StringView& path, Flags flags)
namespace Core {
DirIterator::DirIterator(const StringView& path, Flags flags)
: m_flags(flags)
{
m_dir = opendir(String(path).characters());
@ -36,7 +38,7 @@ CDirIterator::CDirIterator(const StringView& path, Flags flags)
}
}
CDirIterator::~CDirIterator()
DirIterator::~DirIterator()
{
if (m_dir != nullptr) {
closedir(m_dir);
@ -44,7 +46,7 @@ CDirIterator::~CDirIterator()
}
}
bool CDirIterator::advance_next()
bool DirIterator::advance_next()
{
if (m_dir == nullptr)
return false;
@ -74,7 +76,7 @@ bool CDirIterator::advance_next()
return m_next.length() > 0;
}
bool CDirIterator::has_next()
bool DirIterator::has_next()
{
if (!m_next.is_null())
return true;
@ -82,7 +84,7 @@ bool CDirIterator::has_next()
return advance_next();
}
String CDirIterator::next_path()
String DirIterator::next_path()
{
if (m_next.is_null())
advance_next();
@ -91,3 +93,5 @@ String CDirIterator::next_path()
m_next = String();
return tmp;
}
}

View file

@ -29,15 +29,17 @@
#include <AK/String.h>
#include <dirent.h>
class CDirIterator {
namespace Core {
class DirIterator {
public:
enum Flags {
NoFlags = 0x0,
SkipDots = 0x1,
};
CDirIterator(const StringView& path, Flags = Flags::NoFlags);
~CDirIterator();
DirIterator(const StringView& path, Flags = Flags::NoFlags);
~DirIterator();
bool has_error() const { return m_error != 0; }
int error() const { return m_error; }
@ -53,3 +55,5 @@ private:
bool advance_next();
};
}

View file

@ -29,13 +29,15 @@
#include <LibCore/CElapsedTimer.h>
#include <sys/time.h>
void CElapsedTimer::start()
namespace Core {
void ElapsedTimer::start()
{
m_valid = true;
gettimeofday(&m_start_time, nullptr);
}
int CElapsedTimer::elapsed() const
int ElapsedTimer::elapsed() const
{
ASSERT(is_valid());
struct timeval now;
@ -44,3 +46,5 @@ int CElapsedTimer::elapsed() const
timeval_sub(now, m_start_time, diff);
return diff.tv_sec * 1000 + diff.tv_usec / 1000;
}
}

View file

@ -28,9 +28,11 @@
#include <sys/time.h>
class CElapsedTimer {
namespace Core {
class ElapsedTimer {
public:
CElapsedTimer() {}
ElapsedTimer() {}
bool is_valid() const { return m_valid; }
void start();
@ -42,3 +44,5 @@ private:
0, 0
};
};
}

View file

@ -27,13 +27,17 @@
#include <LibCore/CEvent.h>
#include <LibCore/CObject.h>
CChildEvent::CChildEvent(Type type, CObject& child, CObject* insertion_before_child)
: CEvent(type)
namespace Core {
ChildEvent::ChildEvent(Type type, Object& child, Object* insertion_before_child)
: Core::Event(type)
, m_child(child.make_weak_ptr())
, m_insertion_before_child(insertion_before_child ? insertion_before_child->make_weak_ptr() : nullptr)
{
}
CChildEvent::~CChildEvent()
ChildEvent::~ChildEvent()
{
}
}

View file

@ -26,14 +26,16 @@
#pragma once
#include <AK/String.h>
#include <AK/Function.h>
#include <AK/String.h>
#include <AK/Types.h>
#include <AK/WeakPtr.h>
class CObject;
namespace Core {
class CEvent {
class Object;
class Event {
public:
enum Type {
Invalid = 0,
@ -47,12 +49,12 @@ public:
Custom,
};
CEvent() {}
explicit CEvent(unsigned type)
Event() {}
explicit Event(unsigned type)
: m_type(type)
{
}
virtual ~CEvent() {}
virtual ~Event() {}
unsigned type() const { return m_type; }
@ -65,28 +67,28 @@ private:
bool m_accepted { true };
};
class CDeferredInvocationEvent : public CEvent {
friend class CEventLoop;
class DeferredInvocationEvent : public Event {
friend class EventLoop;
public:
CDeferredInvocationEvent(Function<void(CObject&)> invokee)
: CEvent(CEvent::Type::DeferredInvoke)
DeferredInvocationEvent(Function<void(Object&)> invokee)
: Event(Event::Type::DeferredInvoke)
, m_invokee(move(invokee))
{
}
private:
Function<void(CObject&)> m_invokee;
Function<void(Object&)> m_invokee;
};
class CTimerEvent final : public CEvent {
class TimerEvent final : public Event {
public:
explicit CTimerEvent(int timer_id)
: CEvent(CEvent::Timer)
explicit TimerEvent(int timer_id)
: Event(Event::Timer)
, m_timer_id(timer_id)
{
}
~CTimerEvent() {}
~TimerEvent() {}
int timer_id() const { return m_timer_id; }
@ -94,14 +96,14 @@ private:
int m_timer_id;
};
class CNotifierReadEvent final : public CEvent {
class NotifierReadEvent final : public Event {
public:
explicit CNotifierReadEvent(int fd)
: CEvent(CEvent::NotifierRead)
explicit NotifierReadEvent(int fd)
: Event(Event::NotifierRead)
, m_fd(fd)
{
}
~CNotifierReadEvent() {}
~NotifierReadEvent() {}
int fd() const { return m_fd; }
@ -109,14 +111,14 @@ private:
int m_fd;
};
class CNotifierWriteEvent final : public CEvent {
class NotifierWriteEvent final : public Event {
public:
explicit CNotifierWriteEvent(int fd)
: CEvent(CEvent::NotifierWrite)
explicit NotifierWriteEvent(int fd)
: Event(Event::NotifierWrite)
, m_fd(fd)
{
}
~CNotifierWriteEvent() {}
~NotifierWriteEvent() {}
int fd() const { return m_fd; }
@ -124,31 +126,31 @@ private:
int m_fd;
};
class CChildEvent final : public CEvent {
class ChildEvent final : public Event {
public:
CChildEvent(Type, CObject& child, CObject* insertion_before_child = nullptr);
~CChildEvent();
ChildEvent(Type, Object& child, Object* insertion_before_child = nullptr);
~ChildEvent();
CObject* child() { return m_child.ptr(); }
const CObject* child() const { return m_child.ptr(); }
Object* child() { return m_child.ptr(); }
const Object* child() const { return m_child.ptr(); }
CObject* insertion_before_child() { return m_insertion_before_child.ptr(); }
const CObject* insertion_before_child() const { return m_insertion_before_child.ptr(); }
Object* insertion_before_child() { return m_insertion_before_child.ptr(); }
const Object* insertion_before_child() const { return m_insertion_before_child.ptr(); }
private:
WeakPtr<CObject> m_child;
WeakPtr<CObject> m_insertion_before_child;
WeakPtr<Object> m_child;
WeakPtr<Object> m_insertion_before_child;
};
class CCustomEvent : public CEvent {
class CustomEvent : public Event {
public:
CCustomEvent(int custom_type, void* data = nullptr)
: CEvent(CEvent::Type::Custom)
CustomEvent(int custom_type, void* data = nullptr)
: Event(Event::Type::Custom)
, m_custom_type(custom_type)
, m_data(data)
{
}
~CCustomEvent() {}
~CustomEvent() {}
int custom_type() const { return m_custom_type; }
void* data() { return m_data; }
@ -158,3 +160,5 @@ private:
int m_custom_type { 0 };
void* m_data { nullptr };
};
}

View file

@ -49,21 +49,23 @@
//#define CEVENTLOOP_DEBUG
//#define DEFERRED_INVOKE_DEBUG
namespace Core {
class RPCClient;
static CEventLoop* s_main_event_loop;
static Vector<CEventLoop*>* s_event_loop_stack;
static EventLoop* s_main_event_loop;
static Vector<EventLoop*>* s_event_loop_stack;
static IDAllocator s_id_allocator;
HashMap<int, NonnullOwnPtr<CEventLoop::EventLoopTimer>>* CEventLoop::s_timers;
HashTable<CNotifier*>* CEventLoop::s_notifiers;
int CEventLoop::s_wake_pipe_fds[2];
RefPtr<CLocalServer> CEventLoop::s_rpc_server;
HashMap<int, NonnullOwnPtr<EventLoop::EventLoopTimer>>* EventLoop::s_timers;
HashTable<Notifier*>* EventLoop::s_notifiers;
int EventLoop::s_wake_pipe_fds[2];
RefPtr<LocalServer> EventLoop::s_rpc_server;
HashMap<int, RefPtr<RPCClient>> s_rpc_clients;
class RPCClient : public CObject {
class RPCClient : public Object {
C_OBJECT(RPCClient)
public:
explicit RPCClient(RefPtr<CLocalSocket> socket)
explicit RPCClient(RefPtr<LocalSocket> socket)
: m_socket(move(socket))
, m_client_id(s_id_allocator.allocate())
{
@ -131,7 +133,7 @@ public:
JsonObject response;
response.set("type", type);
JsonArray objects;
for (auto& object : CObject::all_objects()) {
for (auto& object : Object::all_objects()) {
JsonObject json_object;
object.save_to(json_object);
objects.append(move(json_object));
@ -154,16 +156,16 @@ public:
}
private:
RefPtr<CLocalSocket> m_socket;
RefPtr<LocalSocket> m_socket;
int m_client_id { -1 };
};
CEventLoop::CEventLoop()
EventLoop::EventLoop()
{
if (!s_event_loop_stack) {
s_event_loop_stack = new Vector<CEventLoop*>;
s_timers = new HashMap<int, NonnullOwnPtr<CEventLoop::EventLoopTimer>>;
s_notifiers = new HashTable<CNotifier*>;
s_event_loop_stack = new Vector<EventLoop*>;
s_timers = new HashMap<int, NonnullOwnPtr<EventLoop::EventLoopTimer>>;
s_notifiers = new HashTable<Notifier*>;
}
if (!s_main_event_loop) {
@ -185,8 +187,8 @@ CEventLoop::CEventLoop()
perror("unlink");
ASSERT_NOT_REACHED();
}
s_rpc_server = CLocalServer::construct();
s_rpc_server->set_name("CEventLoop_RPC_server");
s_rpc_server = LocalServer::construct();
s_rpc_server->set_name("Core::EventLoop_RPC_server");
bool listening = s_rpc_server->listen(rpc_path);
ASSERT(listening);
@ -196,66 +198,66 @@ CEventLoop::CEventLoop()
}
#ifdef CEVENTLOOP_DEBUG
dbg() << getpid() << " CEventLoop constructed :)";
dbg() << getpid() << " Core::EventLoop constructed :)";
#endif
}
CEventLoop::~CEventLoop()
EventLoop::~EventLoop()
{
}
CEventLoop& CEventLoop::main()
EventLoop& EventLoop::main()
{
ASSERT(s_main_event_loop);
return *s_main_event_loop;
}
CEventLoop& CEventLoop::current()
EventLoop& EventLoop::current()
{
CEventLoop* event_loop = s_event_loop_stack->last();
EventLoop* event_loop = s_event_loop_stack->last();
ASSERT(event_loop != nullptr);
return *event_loop;
}
void CEventLoop::quit(int code)
void EventLoop::quit(int code)
{
dbg() << "CEventLoop::quit(" << code << ")";
dbg() << "Core::EventLoop::quit(" << code << ")";
m_exit_requested = true;
m_exit_code = code;
}
void CEventLoop::unquit()
void EventLoop::unquit()
{
dbg() << "CEventLoop::unquit()";
dbg() << "Core::EventLoop::unquit()";
m_exit_requested = false;
m_exit_code = 0;
}
struct CEventLoopPusher {
struct EventLoopPusher {
public:
CEventLoopPusher(CEventLoop& event_loop)
EventLoopPusher(EventLoop& event_loop)
: m_event_loop(event_loop)
{
if (&m_event_loop != s_main_event_loop) {
m_event_loop.take_pending_events_from(CEventLoop::current());
m_event_loop.take_pending_events_from(EventLoop::current());
s_event_loop_stack->append(&event_loop);
}
}
~CEventLoopPusher()
~EventLoopPusher()
{
if (&m_event_loop != s_main_event_loop) {
s_event_loop_stack->take_last();
CEventLoop::current().take_pending_events_from(m_event_loop);
EventLoop::current().take_pending_events_from(m_event_loop);
}
}
private:
CEventLoop& m_event_loop;
EventLoop& m_event_loop;
};
int CEventLoop::exec()
int EventLoop::exec()
{
CEventLoopPusher pusher(*this);
EventLoopPusher pusher(*this);
for (;;) {
if (m_exit_requested)
return m_exit_code;
@ -264,7 +266,7 @@ int CEventLoop::exec()
ASSERT_NOT_REACHED();
}
void CEventLoop::pump(WaitMode mode)
void EventLoop::pump(WaitMode mode)
{
if (m_queued_events.is_empty())
wait_for_event(mode);
@ -284,30 +286,30 @@ void CEventLoop::pump(WaitMode mode)
auto& event = *queued_event.event;
#ifdef CEVENTLOOP_DEBUG
if (receiver)
dbg() << "CEventLoop: " << *receiver << " event " << (int)event.type();
dbg() << "Core::EventLoop: " << *receiver << " event " << (int)event.type();
#endif
if (!receiver) {
switch (event.type()) {
case CEvent::Quit:
case Event::Quit:
ASSERT_NOT_REACHED();
return;
default:
dbg() << "Event type " << event.type() << " with no receiver :(";
}
} else if (event.type() == CEvent::Type::DeferredInvoke) {
} else if (event.type() == Event::Type::DeferredInvoke) {
#ifdef DEFERRED_INVOKE_DEBUG
printf("DeferredInvoke: receiver=%s{%p}\n", receiver->class_name(), receiver);
#endif
static_cast<CDeferredInvocationEvent&>(event).m_invokee(*receiver);
static_cast<DeferredInvocationEvent&>(event).m_invokee(*receiver);
} else {
NonnullRefPtr<CObject> protector(*receiver);
NonnullRefPtr<Object> protector(*receiver);
receiver->dispatch_event(event);
}
if (m_exit_requested) {
LOCKER(m_lock);
#ifdef CEVENTLOOP_DEBUG
dbg() << "CEventLoop: Exit requested. Rejigging " << (events.size() - i) << " events.";
dbg() << "Core::EventLoop: Exit requested. Rejigging " << (events.size() - i) << " events.";
#endif
decltype(m_queued_events) new_event_queue;
new_event_queue.ensure_capacity(m_queued_events.size() + events.size());
@ -320,16 +322,16 @@ void CEventLoop::pump(WaitMode mode)
}
}
void CEventLoop::post_event(CObject& receiver, NonnullOwnPtr<CEvent>&& event)
void EventLoop::post_event(Object& receiver, NonnullOwnPtr<Event>&& event)
{
LOCKER(m_lock);
#ifdef CEVENTLOOP_DEBUG
dbg() << "CEventLoop::post_event: {" << m_queued_events.size() << "} << receiver=" << receiver << ", event=" << event;
dbg() << "Core::EventLoop::post_event: {" << m_queued_events.size() << "} << receiver=" << receiver << ", event=" << event;
#endif
m_queued_events.append({ receiver.make_weak_ptr(), move(event) });
}
void CEventLoop::wait_for_event(WaitMode mode)
void EventLoop::wait_for_event(WaitMode mode)
{
fd_set rfds;
fd_set wfds;
@ -347,11 +349,11 @@ void CEventLoop::wait_for_event(WaitMode mode)
add_fd_to_set(s_wake_pipe_fds[0], rfds);
max_fd = max(max_fd, max_fd_added);
for (auto& notifier : *s_notifiers) {
if (notifier->event_mask() & CNotifier::Read)
if (notifier->event_mask() & Notifier::Read)
add_fd_to_set(notifier->fd(), rfds);
if (notifier->event_mask() & CNotifier::Write)
if (notifier->event_mask() & Notifier::Write)
add_fd_to_set(notifier->fd(), wfds);
if (notifier->event_mask() & CNotifier::Exceptional)
if (notifier->event_mask() & Notifier::Exceptional)
ASSERT_NOT_REACHED();
}
@ -401,9 +403,9 @@ void CEventLoop::wait_for_event(WaitMode mode)
continue;
}
#ifdef CEVENTLOOP_DEBUG
dbg() << "CEventLoop: Timer " << timer.timer_id << " has expired, sending CTimerEvent to " << timer.owner;
dbg() << "Core::EventLoop: Timer " << timer.timer_id << " has expired, sending Core::TimerEvent to " << timer.owner;
#endif
post_event(*timer.owner, make<CTimerEvent>(timer.timer_id));
post_event(*timer.owner, make<TimerEvent>(timer.timer_id));
if (timer.should_reload) {
timer.reload(now);
} else {
@ -418,28 +420,28 @@ void CEventLoop::wait_for_event(WaitMode mode)
for (auto& notifier : *s_notifiers) {
if (FD_ISSET(notifier->fd(), &rfds)) {
if (notifier->on_ready_to_read)
post_event(*notifier, make<CNotifierReadEvent>(notifier->fd()));
post_event(*notifier, make<NotifierReadEvent>(notifier->fd()));
}
if (FD_ISSET(notifier->fd(), &wfds)) {
if (notifier->on_ready_to_write)
post_event(*notifier, make<CNotifierWriteEvent>(notifier->fd()));
post_event(*notifier, make<NotifierWriteEvent>(notifier->fd()));
}
}
}
bool CEventLoop::EventLoopTimer::has_expired(const timeval& now) const
bool EventLoop::EventLoopTimer::has_expired(const timeval& now) const
{
return now.tv_sec > fire_time.tv_sec || (now.tv_sec == fire_time.tv_sec && now.tv_usec >= fire_time.tv_usec);
}
void CEventLoop::EventLoopTimer::reload(const timeval& now)
void EventLoop::EventLoopTimer::reload(const timeval& now)
{
fire_time = now;
fire_time.tv_sec += interval / 1000;
fire_time.tv_usec += (interval % 1000) * 1000;
}
void CEventLoop::get_next_timer_expiration(timeval& soonest)
void EventLoop::get_next_timer_expiration(timeval& soonest)
{
ASSERT(!s_timers->is_empty());
bool has_checked_any = false;
@ -456,7 +458,7 @@ void CEventLoop::get_next_timer_expiration(timeval& soonest)
}
}
int CEventLoop::register_timer(CObject& object, int milliseconds, bool should_reload, TimerShouldFireWhenNotVisible fire_when_not_visible)
int EventLoop::register_timer(Object& object, int milliseconds, bool should_reload, TimerShouldFireWhenNotVisible fire_when_not_visible)
{
ASSERT(milliseconds >= 0);
auto timer = make<EventLoopTimer>();
@ -473,7 +475,7 @@ int CEventLoop::register_timer(CObject& object, int milliseconds, bool should_re
return timer_id;
}
bool CEventLoop::unregister_timer(int timer_id)
bool EventLoop::unregister_timer(int timer_id)
{
s_id_allocator.deallocate(timer_id);
auto it = s_timers->find(timer_id);
@ -483,22 +485,24 @@ bool CEventLoop::unregister_timer(int timer_id)
return true;
}
void CEventLoop::register_notifier(Badge<CNotifier>, CNotifier& notifier)
void EventLoop::register_notifier(Badge<Notifier>, Notifier& notifier)
{
s_notifiers->set(&notifier);
}
void CEventLoop::unregister_notifier(Badge<CNotifier>, CNotifier& notifier)
void EventLoop::unregister_notifier(Badge<Notifier>, Notifier& notifier)
{
s_notifiers->remove(&notifier);
}
void CEventLoop::wake()
void EventLoop::wake()
{
char ch = '!';
int nwritten = write(s_wake_pipe_fds[1], &ch, 1);
if (nwritten < 0) {
perror("CEventLoop::wake: write");
perror("EventLoop::wake: write");
ASSERT_NOT_REACHED();
}
}
}

View file

@ -38,13 +38,15 @@
#include <sys/time.h>
#include <time.h>
class CObject;
class CNotifier;
namespace Core {
class CEventLoop {
class Object;
class Notifier;
class EventLoop {
public:
CEventLoop();
~CEventLoop();
EventLoop();
~EventLoop();
int exec();
@ -57,23 +59,23 @@ public:
// this should really only be used for integrating with other event loops
void pump(WaitMode = WaitMode::WaitForEvents);
void post_event(CObject& receiver, NonnullOwnPtr<CEvent>&&);
void post_event(Object& receiver, NonnullOwnPtr<Event>&&);
static CEventLoop& main();
static CEventLoop& current();
static EventLoop& main();
static EventLoop& current();
bool was_exit_requested() const { return m_exit_requested; }
static int register_timer(CObject&, int milliseconds, bool should_reload, TimerShouldFireWhenNotVisible);
static int register_timer(Object&, int milliseconds, bool should_reload, TimerShouldFireWhenNotVisible);
static bool unregister_timer(int timer_id);
static void register_notifier(Badge<CNotifier>, CNotifier&);
static void unregister_notifier(Badge<CNotifier>, CNotifier&);
static void register_notifier(Badge<Notifier>, Notifier&);
static void unregister_notifier(Badge<Notifier>, Notifier&);
void quit(int);
void unquit();
void take_pending_events_from(CEventLoop& other)
void take_pending_events_from(EventLoop& other)
{
m_queued_events.append(move(other.m_queued_events));
}
@ -85,8 +87,8 @@ private:
void get_next_timer_expiration(timeval&);
struct QueuedEvent {
WeakPtr<CObject> receiver;
NonnullOwnPtr<CEvent> event;
WeakPtr<Object> receiver;
NonnullOwnPtr<Event> event;
};
Vector<QueuedEvent, 64> m_queued_events;
@ -104,7 +106,7 @@ private:
timeval fire_time { 0, 0 };
bool should_reload { false };
TimerShouldFireWhenNotVisible fire_when_not_visible { TimerShouldFireWhenNotVisible::No };
WeakPtr<CObject> owner;
WeakPtr<Object> owner;
void reload(const timeval& now);
bool has_expired(const timeval& now) const;
@ -112,7 +114,9 @@ private:
static HashMap<int, NonnullOwnPtr<EventLoopTimer>>* s_timers;
static HashTable<CNotifier*>* s_notifiers;
static HashTable<Notifier*>* s_notifiers;
static RefPtr<CLocalServer> s_rpc_server;
static RefPtr<LocalServer> s_rpc_server;
};
}

View file

@ -30,19 +30,21 @@
#include <stdio.h>
#include <unistd.h>
CFile::CFile(const StringView& filename, CObject* parent)
: CIODevice(parent)
namespace Core {
File::File(const StringView& filename, Object* parent)
: IODevice(parent)
, m_filename(filename)
{
}
CFile::~CFile()
File::~File()
{
if (m_should_close_file_descriptor == ShouldCloseFileDescription::Yes && mode() != NotOpen)
close();
}
bool CFile::open(int fd, CIODevice::OpenMode mode, ShouldCloseFileDescription should_close)
bool File::open(int fd, IODevice::OpenMode mode, ShouldCloseFileDescription should_close)
{
set_fd(fd);
set_mode(mode);
@ -50,25 +52,25 @@ bool CFile::open(int fd, CIODevice::OpenMode mode, ShouldCloseFileDescription sh
return true;
}
bool CFile::open(CIODevice::OpenMode mode)
bool File::open(IODevice::OpenMode mode)
{
ASSERT(!m_filename.is_null());
int flags = 0;
if ((mode & CIODevice::ReadWrite) == CIODevice::ReadWrite) {
if ((mode & IODevice::ReadWrite) == IODevice::ReadWrite) {
flags |= O_RDWR | O_CREAT;
} else if (mode & CIODevice::ReadOnly) {
} else if (mode & IODevice::ReadOnly) {
flags |= O_RDONLY;
} else if (mode & CIODevice::WriteOnly) {
} else if (mode & IODevice::WriteOnly) {
flags |= O_WRONLY | O_CREAT;
bool should_truncate = !((mode & CIODevice::Append) || (mode & CIODevice::MustBeNew));
bool should_truncate = !((mode & IODevice::Append) || (mode & IODevice::MustBeNew));
if (should_truncate)
flags |= O_TRUNC;
}
if (mode & CIODevice::Append)
if (mode & IODevice::Append)
flags |= O_APPEND;
if (mode & CIODevice::Truncate)
if (mode & IODevice::Truncate)
flags |= O_TRUNC;
if (mode & CIODevice::MustBeNew)
if (mode & IODevice::MustBeNew)
flags |= O_EXCL;
int fd = ::open(m_filename.characters(), flags, 0666);
if (fd < 0) {
@ -80,3 +82,5 @@ bool CFile::open(CIODevice::OpenMode mode)
set_mode(mode);
return true;
}
}

View file

@ -29,29 +29,33 @@
#include <AK/String.h>
#include <LibCore/CIODevice.h>
class CFile final : public CIODevice {
C_OBJECT(CFile)
namespace Core {
class File final : public IODevice {
C_OBJECT(File)
public:
virtual ~CFile() override;
virtual ~File() override;
String filename() const { return m_filename; }
void set_filename(const StringView& filename) { m_filename = filename; }
virtual bool open(CIODevice::OpenMode) override;
virtual bool open(IODevice::OpenMode) override;
enum class ShouldCloseFileDescription {
No = 0,
Yes
};
bool open(int fd, CIODevice::OpenMode, ShouldCloseFileDescription);
bool open(int fd, IODevice::OpenMode, ShouldCloseFileDescription);
private:
CFile(CObject* parent = nullptr)
: CIODevice(parent)
File(Object* parent = nullptr)
: IODevice(parent)
{
}
explicit CFile(const StringView&, CObject* parent = nullptr);
explicit File(const StringView&, Object* parent = nullptr);
String m_filename;
ShouldCloseFileDescription m_should_close_file_descriptor { ShouldCloseFileDescription::Yes };
};
}

View file

@ -33,6 +33,8 @@
//#define CHTTPJOB_DEBUG
namespace Core {
static ByteBuffer handle_content_encoding(const ByteBuffer& buf, const String& content_encoding)
{
#ifdef CHTTPJOB_DEBUG
@ -66,16 +68,16 @@ static ByteBuffer handle_content_encoding(const ByteBuffer& buf, const String& c
return buf;
}
CHttpJob::CHttpJob(const CHttpRequest& request)
HttpJob::HttpJob(const HttpRequest& request)
: m_request(request)
{
}
CHttpJob::~CHttpJob()
HttpJob::~HttpJob()
{
}
void CHttpJob::on_socket_connected()
void HttpJob::on_socket_connected()
{
auto raw_request = m_request.to_raw_request();
#if 0
@ -85,7 +87,7 @@ void CHttpJob::on_socket_connected()
bool success = m_socket->send(raw_request);
if (!success)
return deferred_invoke([this](auto&) { did_fail(CNetworkJob::Error::TransmissionFailed); });
return deferred_invoke([this](auto&) { did_fail(NetworkJob::Error::TransmissionFailed); });
m_socket->on_ready_to_read = [&] {
if (is_cancelled())
@ -96,18 +98,18 @@ void CHttpJob::on_socket_connected()
auto line = m_socket->read_line(PAGE_SIZE);
if (line.is_null()) {
fprintf(stderr, "CHttpJob: Expected HTTP status\n");
return deferred_invoke([this](auto&) { did_fail(CNetworkJob::Error::TransmissionFailed); });
return deferred_invoke([this](auto&) { did_fail(NetworkJob::Error::TransmissionFailed); });
}
auto parts = String::copy(line, Chomp).split(' ');
if (parts.size() < 3) {
fprintf(stderr, "CHttpJob: Expected 3-part HTTP status, got '%s'\n", line.data());
return deferred_invoke([this](auto&) { did_fail(CNetworkJob::Error::ProtocolFailed); });
return deferred_invoke([this](auto&) { did_fail(NetworkJob::Error::ProtocolFailed); });
}
bool ok;
m_code = parts[1].to_uint(ok);
if (!ok) {
fprintf(stderr, "CHttpJob: Expected numeric HTTP status\n");
return deferred_invoke([this](auto&) { did_fail(CNetworkJob::Error::ProtocolFailed); });
return deferred_invoke([this](auto&) { did_fail(NetworkJob::Error::ProtocolFailed); });
}
m_state = State::InHeaders;
return;
@ -118,7 +120,7 @@ void CHttpJob::on_socket_connected()
auto line = m_socket->read_line(PAGE_SIZE);
if (line.is_null()) {
fprintf(stderr, "CHttpJob: Expected HTTP header\n");
return did_fail(CNetworkJob::Error::ProtocolFailed);
return did_fail(NetworkJob::Error::ProtocolFailed);
}
auto chomped_line = String::copy(line, Chomp);
if (chomped_line.is_empty()) {
@ -128,12 +130,12 @@ void CHttpJob::on_socket_connected()
auto parts = chomped_line.split(':');
if (parts.is_empty()) {
fprintf(stderr, "CHttpJob: Expected HTTP header with key/value\n");
return deferred_invoke([this](auto&) { did_fail(CNetworkJob::Error::ProtocolFailed); });
return deferred_invoke([this](auto&) { did_fail(NetworkJob::Error::ProtocolFailed); });
}
auto name = parts[0];
if (chomped_line.length() < name.length() + 2) {
fprintf(stderr, "CHttpJob: Malformed HTTP header: '%s' (%zu)\n", chomped_line.characters(), chomped_line.length());
return deferred_invoke([this](auto&) { did_fail(CNetworkJob::Error::ProtocolFailed); });
return deferred_invoke([this](auto&) { did_fail(NetworkJob::Error::ProtocolFailed); });
}
auto value = chomped_line.substring(name.length() + 2, chomped_line.length() - name.length() - 2);
m_headers.set(name, value);
@ -148,7 +150,7 @@ void CHttpJob::on_socket_connected()
if (!payload) {
if (m_socket->eof())
return finish_up();
return deferred_invoke([this](auto&) { did_fail(CNetworkJob::Error::ProtocolFailed); });
return deferred_invoke([this](auto&) { did_fail(NetworkJob::Error::ProtocolFailed); });
}
m_received_buffers.append(payload);
m_received_size += payload.size();
@ -162,7 +164,7 @@ void CHttpJob::on_socket_connected()
};
}
void CHttpJob::finish_up()
void HttpJob::finish_up()
{
m_state = State::Finished;
auto flattened_buffer = ByteBuffer::create_uninitialized(m_received_size);
@ -178,16 +180,16 @@ void CHttpJob::finish_up()
flattened_buffer = handle_content_encoding(flattened_buffer, content_encoding.value());
}
auto response = CHttpResponse::create(m_code, move(m_headers), move(flattened_buffer));
auto response = HttpResponse::create(m_code, move(m_headers), move(flattened_buffer));
deferred_invoke([this, response](auto&) {
did_finish(move(response));
});
}
void CHttpJob::start()
void HttpJob::start()
{
ASSERT(!m_socket);
m_socket = CTCPSocket::construct(this);
m_socket = TCPSocket::construct(this);
m_socket->on_connected = [this] {
#ifdef CHTTPJOB_DEBUG
dbg() << "CHttpJob: on_connected callback";
@ -197,12 +199,12 @@ void CHttpJob::start()
bool success = m_socket->connect(m_request.url().host(), m_request.url().port());
if (!success) {
deferred_invoke([this](auto&) {
return did_fail(CNetworkJob::Error::ConnectionFailed);
return did_fail(NetworkJob::Error::ConnectionFailed);
});
}
}
void CHttpJob::shutdown()
void HttpJob::shutdown()
{
if (!m_socket)
return;
@ -211,3 +213,4 @@ void CHttpJob::shutdown()
remove_child(*m_socket);
m_socket = nullptr;
}
}

View file

@ -31,19 +31,21 @@
#include <LibCore/CHttpResponse.h>
#include <LibCore/CNetworkJob.h>
class CTCPSocket;
namespace Core {
class CHttpJob final : public CNetworkJob {
C_OBJECT(CHttpJob)
class TCPSocket;
class HttpJob final : public NetworkJob {
C_OBJECT(HttpJob)
public:
explicit CHttpJob(const CHttpRequest&);
virtual ~CHttpJob() override;
explicit HttpJob(const HttpRequest&);
virtual ~HttpJob() override;
virtual void start() override;
virtual void shutdown() override;
CHttpResponse* response() { return static_cast<CHttpResponse*>(CNetworkJob::response()); }
const CHttpResponse* response() const { return static_cast<const CHttpResponse*>(CNetworkJob::response()); }
HttpResponse* response() { return static_cast<HttpResponse*>(NetworkJob::response()); }
const HttpResponse* response() const { return static_cast<const HttpResponse*>(NetworkJob::response()); }
private:
void on_socket_connected();
@ -56,11 +58,13 @@ private:
Finished,
};
CHttpRequest m_request;
RefPtr<CTCPSocket> m_socket;
HttpRequest m_request;
RefPtr<TCPSocket> m_socket;
State m_state { State::InStatus };
int m_code { -1 };
HashMap<String, String> m_headers;
Vector<ByteBuffer> m_received_buffers;
size_t m_received_size { 0 };
};
}

View file

@ -28,22 +28,24 @@
#include <LibCore/CHttpJob.h>
#include <LibCore/CHttpRequest.h>
CHttpRequest::CHttpRequest()
namespace Core {
HttpRequest::HttpRequest()
{
}
CHttpRequest::~CHttpRequest()
HttpRequest::~HttpRequest()
{
}
RefPtr<CNetworkJob> CHttpRequest::schedule()
RefPtr<NetworkJob> HttpRequest::schedule()
{
auto job = CHttpJob::construct(*this);
auto job = HttpJob::construct(*this);
job->start();
return job;
}
String CHttpRequest::method_name() const
String HttpRequest::method_name() const
{
switch (m_method) {
case Method::GET:
@ -57,7 +59,7 @@ String CHttpRequest::method_name() const
}
}
ByteBuffer CHttpRequest::to_raw_request() const
ByteBuffer HttpRequest::to_raw_request() const
{
StringBuilder builder;
builder.append(method_name());
@ -68,3 +70,5 @@ ByteBuffer CHttpRequest::to_raw_request() const
builder.append("\r\n\r\n");
return builder.to_byte_buffer();
}
}

View file

@ -29,9 +29,11 @@
#include <AK/String.h>
#include <AK/URL.h>
class CNetworkJob;
namespace Core {
class CHttpRequest {
class NetworkJob;
class HttpRequest {
public:
enum Method {
Invalid,
@ -40,8 +42,8 @@ public:
POST
};
CHttpRequest();
~CHttpRequest();
HttpRequest();
~HttpRequest();
const URL& url() const { return m_url; }
void set_url(const URL& url) { m_url = url; }
@ -52,9 +54,11 @@ public:
String method_name() const;
ByteBuffer to_raw_request() const;
RefPtr<CNetworkJob> schedule();
RefPtr<NetworkJob> schedule();
private:
URL m_url;
Method m_method { GET };
};
}

View file

@ -26,13 +26,17 @@
#include <LibCore/CHttpResponse.h>
CHttpResponse::CHttpResponse(int code, HashMap<String, String>&& headers, ByteBuffer&& payload)
: CNetworkResponse(move(payload))
namespace Core {
HttpResponse::HttpResponse(int code, HashMap<String, String>&& headers, ByteBuffer&& payload)
: NetworkResponse(move(payload))
, m_code(code)
, m_headers(move(headers))
{
}
CHttpResponse::~CHttpResponse()
HttpResponse::~HttpResponse()
{
}
}

View file

@ -26,24 +26,28 @@
#pragma once
#include <AK/String.h>
#include <AK/HashMap.h>
#include <AK/String.h>
#include <LibCore/CNetworkResponse.h>
class CHttpResponse : public CNetworkResponse {
namespace Core {
class HttpResponse : public NetworkResponse {
public:
virtual ~CHttpResponse() override;
static NonnullRefPtr<CHttpResponse> create(int code, HashMap<String, String>&& headers, ByteBuffer&& payload)
virtual ~HttpResponse() override;
static NonnullRefPtr<HttpResponse> create(int code, HashMap<String, String>&& headers, ByteBuffer&& payload)
{
return adopt(*new CHttpResponse(code, move(headers), move(payload)));
return adopt(*new HttpResponse(code, move(headers), move(payload)));
}
int code() const { return m_code; }
const HashMap<String, String>& headers() const { return m_headers; }
private:
CHttpResponse(int code, HashMap<String, String>&&, ByteBuffer&&);
HttpResponse(int code, HashMap<String, String>&&, ByteBuffer&&);
int m_code { 0 };
HashMap<String, String> m_headers;
};
}

View file

@ -34,21 +34,23 @@
#include <sys/time.h>
#include <unistd.h>
CIODevice::CIODevice(CObject* parent)
: CObject(parent)
namespace Core {
IODevice::IODevice(Object* parent)
: Object(parent)
{
}
CIODevice::~CIODevice()
IODevice::~IODevice()
{
}
const char* CIODevice::error_string() const
const char* IODevice::error_string() const
{
return strerror(m_error);
}
int CIODevice::read(u8* buffer, int length)
int IODevice::read(u8* buffer, int length)
{
auto read_buffer = read(length);
if (read_buffer.is_null())
@ -57,7 +59,7 @@ int CIODevice::read(u8* buffer, int length)
return read_buffer.size();
}
ByteBuffer CIODevice::read(int max_size)
ByteBuffer IODevice::read(int max_size)
{
if (m_fd < 0)
return {};
@ -99,7 +101,7 @@ ByteBuffer CIODevice::read(int max_size)
return buffer;
}
bool CIODevice::can_read_from_fd() const
bool IODevice::can_read_from_fd() const
{
// FIXME: Can we somehow remove this once CSocket is implemented using non-blocking sockets?
fd_set rfds;
@ -111,13 +113,13 @@ bool CIODevice::can_read_from_fd() const
int rc = CSyscallUtils::safe_syscall(select, m_fd + 1, &rfds, nullptr, nullptr, &timeout);
if (rc < 0) {
// NOTE: We don't set m_error here.
perror("CIODevice::can_read: select");
perror("IODevice::can_read: select");
return false;
}
return FD_ISSET(m_fd, &rfds);
}
bool CIODevice::can_read_line()
bool IODevice::can_read_line()
{
if (m_eof && !m_buffered_data.is_empty())
return true;
@ -129,12 +131,12 @@ bool CIODevice::can_read_line()
return m_buffered_data.contains_slow('\n');
}
bool CIODevice::can_read() const
bool IODevice::can_read() const
{
return !m_buffered_data.is_empty() || can_read_from_fd();
}
ByteBuffer CIODevice::read_all()
ByteBuffer IODevice::read_all()
{
off_t file_size = 0;
struct stat st;
@ -168,7 +170,7 @@ ByteBuffer CIODevice::read_all()
return ByteBuffer::copy(data.data(), data.size());
}
ByteBuffer CIODevice::read_line(int max_size)
ByteBuffer IODevice::read_line(int max_size)
{
if (m_fd < 0)
return {};
@ -178,7 +180,7 @@ ByteBuffer CIODevice::read_line(int max_size)
return {};
if (m_eof) {
if (m_buffered_data.size() > max_size) {
dbgprintf("CIODevice::read_line: At EOF but there's more than max_size(%d) buffered\n", max_size);
dbgprintf("IODevice::read_line: At EOF but there's more than max_size(%d) buffered\n", max_size);
return {};
}
auto buffer = ByteBuffer::copy(m_buffered_data.data(), m_buffered_data.size());
@ -202,7 +204,7 @@ ByteBuffer CIODevice::read_line(int max_size)
return {};
}
bool CIODevice::populate_read_buffer()
bool IODevice::populate_read_buffer()
{
if (m_fd < 0)
return false;
@ -220,7 +222,7 @@ bool CIODevice::populate_read_buffer()
return true;
}
bool CIODevice::close()
bool IODevice::close()
{
if (fd() < 0 || mode() == NotOpen)
return false;
@ -230,11 +232,11 @@ bool CIODevice::close()
return false;
}
set_fd(-1);
set_mode(CIODevice::NotOpen);
set_mode(IODevice::NotOpen);
return true;
}
bool CIODevice::seek(i64 offset, SeekMode mode, off_t* pos)
bool IODevice::seek(i64 offset, SeekMode mode, off_t* pos)
{
int m = SEEK_SET;
switch (mode) {
@ -262,18 +264,18 @@ bool CIODevice::seek(i64 offset, SeekMode mode, off_t* pos)
return true;
}
bool CIODevice::write(const u8* data, int size)
bool IODevice::write(const u8* data, int size)
{
int rc = ::write(m_fd, data, size);
if (rc < 0) {
perror("CIODevice::write: write");
perror("IODevice::write: write");
set_error(errno);
return false;
}
return rc == size;
}
int CIODevice::printf(const char* format, ...)
int IODevice::printf(const char* format, ...)
{
va_list ap;
va_start(ap, format);
@ -286,7 +288,7 @@ int CIODevice::printf(const char* format, ...)
return ret;
}
void CIODevice::set_fd(int fd)
void IODevice::set_fd(int fd)
{
if (m_fd == fd)
return;
@ -294,3 +296,4 @@ void CIODevice::set_fd(int fd)
m_fd = fd;
did_update_fd(fd);
}
}

View file

@ -30,8 +30,10 @@
#include <AK/StringView.h>
#include <LibCore/CObject.h>
class CIODevice : public CObject {
C_OBJECT_ABSTRACT(CIODevice)
namespace Core {
class IODevice : public Object {
C_OBJECT_ABSTRACT(IODevice)
public:
enum OpenMode {
NotOpen = 0,
@ -43,7 +45,7 @@ public:
MustBeNew = 16,
};
virtual ~CIODevice() override;
virtual ~IODevice() override;
int fd() const { return m_fd; }
unsigned mode() const { return m_mode; }
@ -55,7 +57,6 @@ public:
bool has_error() const { return m_error != 0; }
int read(u8* buffer, int length);
ByteBuffer read(int max_size);
@ -78,13 +79,13 @@ public:
bool seek(i64, SeekMode = SeekMode::SetPosition, off_t* = nullptr);
virtual bool open(CIODevice::OpenMode) = 0;
virtual bool open(IODevice::OpenMode) = 0;
virtual bool close();
int printf(const char*, ...);
protected:
explicit CIODevice(CObject* parent = nullptr);
explicit IODevice(Object* parent = nullptr);
void set_fd(int);
void set_mode(OpenMode mode) { m_mode = mode; }
@ -103,3 +104,5 @@ private:
OpenMode m_mode { NotOpen };
Vector<u8> m_buffered_data;
};
}

View file

@ -29,9 +29,11 @@
#include <AK/StdLibExtras.h>
#include <LibCore/CIODevice.h>
class CIODeviceStreamReader {
namespace Core {
class IODeviceStreamReader {
public:
CIODeviceStreamReader(CIODevice& device)
IODeviceStreamReader(IODevice& device)
: m_device(device)
{
}
@ -42,7 +44,7 @@ public:
}
template<typename T>
CIODeviceStreamReader& operator>>(T& value)
IODeviceStreamReader& operator>>(T& value)
{
int nread = m_device.read((u8*)&value, sizeof(T));
ASSERT(nread == sizeof(T));
@ -52,6 +54,8 @@ public:
}
private:
CIODevice& m_device;
IODevice& m_device;
bool m_had_failure { false };
};
}

View file

@ -35,16 +35,18 @@
#include <sys/ioctl.h>
#endif
CLocalServer::CLocalServer(CObject* parent)
: CObject(parent)
namespace Core {
LocalServer::LocalServer(Object* parent)
: Object(parent)
{
}
CLocalServer::~CLocalServer()
LocalServer::~LocalServer()
{
}
bool CLocalServer::take_over_from_system_server()
bool LocalServer::take_over_from_system_server()
{
if (m_listening)
return false;
@ -84,16 +86,16 @@ bool CLocalServer::take_over_from_system_server()
return false;
}
void CLocalServer::setup_notifier()
void LocalServer::setup_notifier()
{
m_notifier = CNotifier::construct(m_fd, CNotifier::Event::Read, this);
m_notifier = Notifier::construct(m_fd, Notifier::Event::Read, this);
m_notifier->on_ready_to_read = [this] {
if (on_ready_to_accept)
on_ready_to_accept();
};
}
bool CLocalServer::listen(const String& address)
bool LocalServer::listen(const String& address)
{
if (m_listening)
return false;
@ -116,7 +118,7 @@ bool CLocalServer::listen(const String& address)
ASSERT_NOT_REACHED();
}
auto socket_address = CSocketAddress::local(address);
auto socket_address = SocketAddress::local(address);
auto un = socket_address.to_sockaddr_un();
rc = ::bind(m_fd, (const sockaddr*)&un, sizeof(un));
if (rc < 0) {
@ -135,7 +137,7 @@ bool CLocalServer::listen(const String& address)
return true;
}
RefPtr<CLocalSocket> CLocalServer::accept()
RefPtr<LocalSocket> LocalServer::accept()
{
ASSERT(m_listening);
sockaddr_un un;
@ -146,5 +148,7 @@ RefPtr<CLocalSocket> CLocalServer::accept()
return nullptr;
}
return CLocalSocket::construct(accepted_fd);
return LocalSocket::construct(accepted_fd);
}
}

View file

@ -29,27 +29,31 @@
#include <LibCore/CNotifier.h>
#include <LibCore/CObject.h>
class CLocalSocket;
namespace Core {
class CLocalServer : public CObject {
C_OBJECT(CLocalServer)
class LocalSocket;
class LocalServer : public Object {
C_OBJECT(LocalServer)
public:
virtual ~CLocalServer() override;
virtual ~LocalServer() override;
bool take_over_from_system_server();
bool is_listening() const { return m_listening; }
bool listen(const String& address);
RefPtr<CLocalSocket> accept();
RefPtr<LocalSocket> accept();
Function<void()> on_ready_to_accept;
private:
explicit CLocalServer(CObject* parent = nullptr);
explicit LocalServer(Object* parent = nullptr);
void setup_notifier();
int m_fd { -1 };
bool m_listening { false };
RefPtr<CNotifier> m_notifier;
RefPtr<Notifier> m_notifier;
};
}

View file

@ -25,27 +25,29 @@
*/
#include <LibCore/CLocalSocket.h>
#include <sys/socket.h>
#include <errno.h>
#include <sys/socket.h>
#ifndef SOCK_NONBLOCK
#include <sys/ioctl.h>
# include <sys/ioctl.h>
#endif
CLocalSocket::CLocalSocket(int fd, CObject* parent)
: CSocket(CSocket::Type::Local, parent)
namespace Core {
LocalSocket::LocalSocket(int fd, Object* parent)
: Socket(Socket::Type::Local, parent)
{
// NOTE: This constructor is used by CLocalServer::accept(), so the socket is already connected.
m_connected = true;
set_fd(fd);
set_mode(CIODevice::ReadWrite);
set_mode(IODevice::ReadWrite);
set_error(0);
}
CLocalSocket::CLocalSocket(CObject* parent)
: CSocket(CSocket::Type::Local, parent)
LocalSocket::LocalSocket(Object* parent)
: Socket(Socket::Type::Local, parent)
{
#ifdef SOCK_NONBLOCK
int fd = socket(AF_LOCAL, SOCK_STREAM | SOCK_NONBLOCK | SOCK_CLOEXEC, 0);
#else
@ -59,11 +61,13 @@ CLocalSocket::CLocalSocket(CObject* parent)
set_error(errno);
} else {
set_fd(fd);
set_mode(CIODevice::ReadWrite);
set_mode(IODevice::ReadWrite);
set_error(0);
}
}
CLocalSocket::~CLocalSocket()
LocalSocket::~LocalSocket()
{
}
}

View file

@ -29,14 +29,18 @@
#include <AK/Badge.h>
#include <LibCore/CSocket.h>
class CLocalServer;
namespace Core {
class CLocalSocket final : public CSocket {
C_OBJECT(CLocalSocket)
class LocalServer;
class LocalSocket final : public Socket {
C_OBJECT(LocalSocket)
public:
virtual ~CLocalSocket() override;
virtual ~LocalSocket() override;
private:
explicit CLocalSocket(CObject* parent = nullptr);
CLocalSocket(int fd, CObject* parent = nullptr);
explicit LocalSocket(Object* parent = nullptr);
LocalSocket(int fd, Object* parent = nullptr);
};
}

View file

@ -30,19 +30,21 @@
//#define CNETWORKJOB_DEBUG
CNetworkJob::CNetworkJob()
namespace Core {
NetworkJob::NetworkJob()
{
}
CNetworkJob::~CNetworkJob()
NetworkJob::~NetworkJob()
{
}
void CNetworkJob::did_finish(NonnullRefPtr<CNetworkResponse>&& response)
void NetworkJob::did_finish(NonnullRefPtr<NetworkResponse>&& response)
{
// NOTE: We protect ourselves here, since the on_finish callback may otherwise
// trigger destruction of this job somehow.
NonnullRefPtr<CNetworkJob> protector(*this);
NonnullRefPtr<NetworkJob> protector(*this);
m_response = move(response);
#ifdef CNETWORKJOB_DEBUG
@ -53,11 +55,11 @@ void CNetworkJob::did_finish(NonnullRefPtr<CNetworkResponse>&& response)
shutdown();
}
void CNetworkJob::did_fail(Error error)
void NetworkJob::did_fail(Error error)
{
// NOTE: We protect ourselves here, since the on_finish callback may otherwise
// trigger destruction of this job somehow.
NonnullRefPtr<CNetworkJob> protector(*this);
NonnullRefPtr<NetworkJob> protector(*this);
m_error = error;
#ifdef CNETWORKJOB_DEBUG
@ -68,18 +70,20 @@ void CNetworkJob::did_fail(Error error)
shutdown();
}
const char* to_string(CNetworkJob::Error error)
const char* to_string(NetworkJob::Error error)
{
switch (error) {
case CNetworkJob::Error::ProtocolFailed:
case NetworkJob::Error::ProtocolFailed:
return "ProtocolFailed";
case CNetworkJob::Error::ConnectionFailed:
case NetworkJob::Error::ConnectionFailed:
return "ConnectionFailed";
case CNetworkJob::Error::TransmissionFailed:
case NetworkJob::Error::TransmissionFailed:
return "TransmissionFailed";
case CNetworkJob::Error::Cancelled:
case NetworkJob::Error::Cancelled:
return "Cancelled";
default:
return "(Unknown error)";
}
}
}

View file

@ -29,10 +29,12 @@
#include <AK/Function.h>
#include <LibCore/CObject.h>
class CNetworkResponse;
namespace Core {
class CNetworkJob : public CObject {
C_OBJECT(CNetworkJob)
class NetworkResponse;
class NetworkJob : public Object {
C_OBJECT_ABSTRACT(NetworkJob)
public:
enum class Error {
None,
@ -41,15 +43,15 @@ public:
ProtocolFailed,
Cancelled,
};
virtual ~CNetworkJob() override;
virtual ~NetworkJob() override;
Function<void(bool success)> on_finish;
bool is_cancelled() const { return m_error == Error::Cancelled; }
bool has_error() const { return m_error != Error::None; }
Error error() const { return m_error; }
CNetworkResponse* response() { return m_response.ptr(); }
const CNetworkResponse* response() const { return m_response.ptr(); }
NetworkResponse* response() { return m_response.ptr(); }
const NetworkResponse* response() const { return m_response.ptr(); }
virtual void start() = 0;
virtual void shutdown() = 0;
@ -61,13 +63,15 @@ public:
}
protected:
CNetworkJob();
void did_finish(NonnullRefPtr<CNetworkResponse>&&);
NetworkJob();
void did_finish(NonnullRefPtr<NetworkResponse>&&);
void did_fail(Error);
private:
RefPtr<CNetworkResponse> m_response;
RefPtr<NetworkResponse> m_response;
Error m_error { Error::None };
};
const char* to_string(CNetworkJob::Error);
const char* to_string(NetworkJob::Error);
}

View file

@ -26,11 +26,15 @@
#include <LibCore/CNetworkResponse.h>
CNetworkResponse::CNetworkResponse(ByteBuffer&& payload)
namespace Core {
NetworkResponse::NetworkResponse(ByteBuffer&& payload)
: m_payload(payload)
{
}
CNetworkResponse::~CNetworkResponse()
NetworkResponse::~NetworkResponse()
{
}
}

View file

@ -29,16 +29,20 @@
#include <AK/ByteBuffer.h>
#include <AK/RefCounted.h>
class CNetworkResponse : public RefCounted<CNetworkResponse> {
namespace Core {
class NetworkResponse : public RefCounted<NetworkResponse> {
public:
virtual ~CNetworkResponse();
virtual ~NetworkResponse();
bool is_error() const { return m_error; }
const ByteBuffer& payload() const { return m_payload; }
protected:
explicit CNetworkResponse(ByteBuffer&&);
explicit NetworkResponse(ByteBuffer&&);
bool m_error { false };
ByteBuffer m_payload;
};
}

View file

@ -28,34 +28,38 @@
#include <LibCore/CEventLoop.h>
#include <LibCore/CNotifier.h>
CNotifier::CNotifier(int fd, unsigned event_mask, CObject* parent)
: CObject(parent)
namespace Core {
Notifier::Notifier(int fd, unsigned event_mask, Object* parent)
: Object(parent)
, m_fd(fd)
, m_event_mask(event_mask)
{
set_enabled(true);
}
CNotifier::~CNotifier()
Notifier::~Notifier()
{
set_enabled(false);
}
void CNotifier::set_enabled(bool enabled)
void Notifier::set_enabled(bool enabled)
{
if (enabled)
CEventLoop::register_notifier({}, *this);
Core::EventLoop::register_notifier({}, *this);
else
CEventLoop::unregister_notifier({}, *this);
Core::EventLoop::unregister_notifier({}, *this);
}
void CNotifier::event(CEvent& event)
void Notifier::event(Core::Event& event)
{
if (event.type() == CEvent::NotifierRead && on_ready_to_read) {
if (event.type() == Core::Event::NotifierRead && on_ready_to_read) {
on_ready_to_read();
} else if (event.type() == CEvent::NotifierWrite && on_ready_to_write) {
} else if (event.type() == Core::Event::NotifierWrite && on_ready_to_write) {
on_ready_to_write();
} else {
CObject::event(event);
Object::event(event);
}
}
}

View file

@ -29,8 +29,10 @@
#include <AK/Function.h>
#include <LibCore/CObject.h>
class CNotifier : public CObject {
C_OBJECT(CNotifier)
namespace Core {
class Notifier : public Object {
C_OBJECT(Notifier)
public:
enum Event {
None = 0,
@ -39,7 +41,7 @@ public:
Exceptional = 4,
};
virtual ~CNotifier() override;
virtual ~Notifier() override;
void set_enabled(bool);
@ -50,11 +52,13 @@ public:
unsigned event_mask() const { return m_event_mask; }
void set_event_mask(unsigned event_mask) { m_event_mask = event_mask; }
void event(CEvent&) override;
void event(Core::Event&) override;
private:
CNotifier(int fd, unsigned event_mask, CObject* parent = nullptr);
Notifier(int fd, unsigned event_mask, Object* parent = nullptr);
int m_fd { -1 };
unsigned m_event_mask { 0 };
};
}

View file

@ -32,13 +32,15 @@
#include <LibCore/CObject.h>
#include <stdio.h>
IntrusiveList<CObject, &CObject::m_all_objects_list_node>& CObject::all_objects()
namespace Core {
IntrusiveList<Object, &Object::m_all_objects_list_node>& Object::all_objects()
{
static IntrusiveList<CObject, &CObject::m_all_objects_list_node> objects;
static IntrusiveList<Object, &Object::m_all_objects_list_node> objects;
return objects;
}
CObject::CObject(CObject* parent, bool is_widget)
Object::Object(Object* parent, bool is_widget)
: m_parent(parent)
, m_widget(is_widget)
{
@ -47,7 +49,7 @@ CObject::CObject(CObject* parent, bool is_widget)
m_parent->add_child(*this);
}
CObject::~CObject()
Object::~Object()
{
// NOTE: We move our children out to a stack vector to prevent other
// code from trying to iterate over them.
@ -63,89 +65,89 @@ CObject::~CObject()
m_parent->remove_child(*this);
}
void CObject::event(CEvent& event)
void Object::event(Core::Event& event)
{
switch (event.type()) {
case CEvent::Timer:
return timer_event(static_cast<CTimerEvent&>(event));
case CEvent::ChildAdded:
case CEvent::ChildRemoved:
return child_event(static_cast<CChildEvent&>(event));
case CEvent::Invalid:
case Core::Event::Timer:
return timer_event(static_cast<TimerEvent&>(event));
case Core::Event::ChildAdded:
case Core::Event::ChildRemoved:
return child_event(static_cast<ChildEvent&>(event));
case Core::Event::Invalid:
ASSERT_NOT_REACHED();
break;
case CEvent::Custom:
return custom_event(static_cast<CCustomEvent&>(event));
case Core::Event::Custom:
return custom_event(static_cast<CustomEvent&>(event));
default:
break;
}
}
void CObject::add_child(CObject& object)
void Object::add_child(Object& object)
{
// FIXME: Should we support reparenting objects?
ASSERT(!object.parent() || object.parent() == this);
object.m_parent = this;
m_children.append(object);
event(*make<CChildEvent>(CEvent::ChildAdded, object));
event(*make<Core::ChildEvent>(Core::Event::ChildAdded, object));
}
void CObject::insert_child_before(CObject& new_child, CObject& before_child)
void Object::insert_child_before(Object& new_child, Object& before_child)
{
// FIXME: Should we support reparenting objects?
ASSERT(!new_child.parent() || new_child.parent() == this);
new_child.m_parent = this;
m_children.insert_before_matching(new_child, [&](auto& existing_child) { return existing_child.ptr() == &before_child; });
event(*make<CChildEvent>(CEvent::ChildAdded, new_child, &before_child));
event(*make<Core::ChildEvent>(Core::Event::ChildAdded, new_child, &before_child));
}
void CObject::remove_child(CObject& object)
void Object::remove_child(Object& object)
{
for (int i = 0; i < m_children.size(); ++i) {
if (m_children.ptr_at(i).ptr() == &object) {
// NOTE: We protect the child so it survives the handling of ChildRemoved.
NonnullRefPtr<CObject> protector = object;
NonnullRefPtr<Object> protector = object;
object.m_parent = nullptr;
m_children.remove(i);
event(*make<CChildEvent>(CEvent::ChildRemoved, object));
event(*make<Core::ChildEvent>(Core::Event::ChildRemoved, object));
return;
}
}
ASSERT_NOT_REACHED();
}
void CObject::timer_event(CTimerEvent&)
void Object::timer_event(Core::TimerEvent&)
{
}
void CObject::child_event(CChildEvent&)
void Object::child_event(Core::ChildEvent&)
{
}
void CObject::custom_event(CCustomEvent&)
void Object::custom_event(CustomEvent&)
{
}
void CObject::start_timer(int ms, TimerShouldFireWhenNotVisible fire_when_not_visible)
void Object::start_timer(int ms, TimerShouldFireWhenNotVisible fire_when_not_visible)
{
if (m_timer_id) {
dbgprintf("CObject{%p} already has a timer!\n", this);
dbgprintf("Object{%p} already has a timer!\n", this);
ASSERT_NOT_REACHED();
}
m_timer_id = CEventLoop::register_timer(*this, ms, true, fire_when_not_visible);
m_timer_id = Core::EventLoop::register_timer(*this, ms, true, fire_when_not_visible);
}
void CObject::stop_timer()
void Object::stop_timer()
{
if (!m_timer_id)
return;
bool success = CEventLoop::unregister_timer(m_timer_id);
bool success = Core::EventLoop::unregister_timer(m_timer_id);
ASSERT(success);
m_timer_id = 0;
}
void CObject::dump_tree(int indent)
void Object::dump_tree(int indent)
{
for (int i = 0; i < indent; ++i) {
printf(" ");
@ -158,12 +160,12 @@ void CObject::dump_tree(int indent)
});
}
void CObject::deferred_invoke(Function<void(CObject&)> invokee)
void Object::deferred_invoke(Function<void(Object&)> invokee)
{
CEventLoop::current().post_event(*this, make<CDeferredInvocationEvent>(move(invokee)));
Core::EventLoop::current().post_event(*this, make<Core::DeferredInvocationEvent>(move(invokee)));
}
void CObject::save_to(JsonObject& json)
void Object::save_to(JsonObject& json)
{
json.set("class_name", class_name());
json.set("address", String::format("%p", this));
@ -171,7 +173,7 @@ void CObject::save_to(JsonObject& json)
json.set("parent", String::format("%p", parent()));
}
bool CObject::is_ancestor_of(const CObject& other) const
bool Object::is_ancestor_of(const Object& other) const
{
if (&other == this)
return false;
@ -182,7 +184,7 @@ bool CObject::is_ancestor_of(const CObject& other) const
return false;
}
void CObject::dispatch_event(CEvent& e, CObject* stay_within)
void Object::dispatch_event(Core::Event& e, Object* stay_within)
{
ASSERT(!stay_within || stay_within == this || stay_within->is_ancestor_of(*this));
auto* target = this;
@ -197,9 +199,11 @@ void CObject::dispatch_event(CEvent& e, CObject* stay_within)
} while (target && !e.is_accepted());
}
bool CObject::is_visible_for_timer_purposes() const
bool Object::is_visible_for_timer_purposes() const
{
if (parent())
return parent()->is_visible_for_timer_purposes();
return true;
}
}

View file

@ -40,16 +40,18 @@ namespace AK {
class JsonObject;
}
namespace Core {
enum class TimerShouldFireWhenNotVisible {
No = 0,
Yes
};
class CEvent;
class CEventLoop;
class CChildEvent;
class CCustomEvent;
class CTimerEvent;
class ChildEvent;
class CustomEvent;
class Event;
class EventLoop;
class TimerEvent;
#define C_OBJECT(klass) \
public: \
@ -64,26 +66,26 @@ public: \
public: \
virtual const char* class_name() const override { return #klass; }
class CObject
: public RefCounted<CObject>
, public Weakable<CObject> {
// NOTE: No C_OBJECT macro for CObject itself.
class Object
: public RefCounted<Object>
, public Weakable<Object> {
// NOTE: No C_OBJECT macro for Core::Object itself.
AK_MAKE_NONCOPYABLE(CObject)
AK_MAKE_NONMOVABLE(CObject)
AK_MAKE_NONCOPYABLE(Object)
AK_MAKE_NONMOVABLE(Object)
public:
IntrusiveListNode m_all_objects_list_node;
virtual ~CObject();
virtual ~Object();
virtual const char* class_name() const = 0;
virtual void event(CEvent&);
virtual void event(Core::Event&);
const String& name() const { return m_name; }
void set_name(const StringView& name) { m_name = name; }
NonnullRefPtrVector<CObject>& children() { return m_children; }
const NonnullRefPtrVector<CObject>& children() const { return m_children; }
NonnullRefPtrVector<Object>& children() { return m_children; }
const NonnullRefPtrVector<Object>& children() const { return m_children; }
template<typename Callback>
void for_each_child(Callback callback)
@ -97,22 +99,22 @@ public:
template<typename T, typename Callback>
void for_each_child_of_type(Callback callback);
bool is_ancestor_of(const CObject&) const;
bool is_ancestor_of(const Object&) const;
CObject* parent() { return m_parent; }
const CObject* parent() const { return m_parent; }
Object* parent() { return m_parent; }
const Object* parent() const { return m_parent; }
void start_timer(int ms, TimerShouldFireWhenNotVisible = TimerShouldFireWhenNotVisible::No);
void stop_timer();
bool has_timer() const { return m_timer_id; }
void add_child(CObject&);
void insert_child_before(CObject& new_child, CObject& before_child);
void remove_child(CObject&);
void add_child(Object&);
void insert_child_before(Object& new_child, Object& before_child);
void remove_child(Object&);
void dump_tree(int indent = 0);
void deferred_invoke(Function<void(CObject&)>);
void deferred_invoke(Function<void(Object&)>);
bool is_widget() const { return m_widget; }
virtual bool is_action() const { return false; }
@ -120,9 +122,9 @@ public:
virtual void save_to(AK::JsonObject&);
static IntrusiveList<CObject, &CObject::m_all_objects_list_node>& all_objects();
static IntrusiveList<Object, &Object::m_all_objects_list_node>& all_objects();
void dispatch_event(CEvent&, CObject* stay_within = nullptr);
void dispatch_event(Core::Event&, Object* stay_within = nullptr);
void remove_from_parent()
{
@ -133,41 +135,41 @@ public:
virtual bool is_visible_for_timer_purposes() const;
protected:
explicit CObject(CObject* parent = nullptr, bool is_widget = false);
explicit Object(Object* parent = nullptr, bool is_widget = false);
virtual void timer_event(CTimerEvent&);
virtual void custom_event(CCustomEvent&);
virtual void timer_event(TimerEvent&);
virtual void custom_event(CustomEvent&);
// NOTE: You may get child events for children that are not yet fully constructed!
virtual void child_event(CChildEvent&);
virtual void child_event(ChildEvent&);
private:
CObject* m_parent { nullptr };
Object* m_parent { nullptr };
String m_name;
int m_timer_id { 0 };
bool m_widget { false };
NonnullRefPtrVector<CObject> m_children;
NonnullRefPtrVector<Object> m_children;
};
template<typename T>
inline bool is(const CObject&) { return false; }
inline bool is(const Object&) { return false; }
template<typename T>
inline T& to(CObject& object)
inline T& to(Object& object)
{
ASSERT(is<typename RemoveConst<T>::Type>(object));
return static_cast<T&>(object);
}
template<typename T>
inline const T& to(const CObject& object)
inline const T& to(const Object& object)
{
ASSERT(is<typename RemoveConst<T>::Type>(object));
return static_cast<const T&>(object);
}
template<typename T, typename Callback>
inline void CObject::for_each_child_of_type(Callback callback)
inline void Object::for_each_child_of_type(Callback callback)
{
for_each_child([&](auto& child) {
if (is<T>(child))
@ -176,7 +178,9 @@ inline void CObject::for_each_child_of_type(Callback callback)
});
}
inline const LogStream& operator<<(const LogStream& stream, const CObject& object)
inline const LogStream& operator<<(const LogStream& stream, const Object& object)
{
return stream << object.class_name() << '{' << &object << '}';
}
}

View file

@ -32,23 +32,25 @@
#include <pwd.h>
#include <stdio.h>
HashMap<uid_t, String> CProcessStatisticsReader::s_usernames;
namespace Core {
HashMap<pid_t, CProcessStatistics> CProcessStatisticsReader::get_all()
HashMap<uid_t, String> ProcessStatisticsReader::s_usernames;
HashMap<pid_t, Core::ProcessStatistics> ProcessStatisticsReader::get_all()
{
auto file = CFile::construct("/proc/all");
if (!file->open(CIODevice::ReadOnly)) {
auto file = Core::File::construct("/proc/all");
if (!file->open(Core::IODevice::ReadOnly)) {
fprintf(stderr, "CProcessStatisticsReader: Failed to open /proc/all: %s\n", file->error_string());
return {};
}
HashMap<pid_t, CProcessStatistics> map;
HashMap<pid_t, Core::ProcessStatistics> map;
auto file_contents = file->read_all();
auto json = JsonValue::from_string({ file_contents.data(), (size_t)file_contents.size() });
json.as_array().for_each([&](auto& value) {
const JsonObject& process_object = value.as_object();
CProcessStatistics process;
Core::ProcessStatistics process;
// kernel data first
process.pid = process_object.get("pid").to_u32();
@ -76,7 +78,7 @@ HashMap<pid_t, CProcessStatistics> CProcessStatisticsReader::get_all()
process.threads.ensure_capacity(thread_array.size());
thread_array.for_each([&](auto& value) {
auto& thread_object = value.as_object();
CThreadStatistics thread;
Core::ThreadStatistics thread;
thread.tid = thread_object.get("tid").to_u32();
thread.times_scheduled = thread_object.get("times_scheduled").to_u32();
thread.name = thread_object.get("name").to_string();
@ -105,7 +107,7 @@ HashMap<pid_t, CProcessStatistics> CProcessStatisticsReader::get_all()
return map;
}
String CProcessStatisticsReader::username_from_uid(uid_t uid)
String ProcessStatisticsReader::username_from_uid(uid_t uid)
{
if (s_usernames.is_empty()) {
setpwent();
@ -119,3 +121,4 @@ String CProcessStatisticsReader::username_from_uid(uid_t uid)
return (*it).value;
return String::number(uid);
}
}

View file

@ -30,7 +30,9 @@
#include <AK/String.h>
#include <unistd.h>
struct CThreadStatistics {
namespace Core {
struct ThreadStatistics {
int tid;
unsigned times_scheduled;
unsigned ticks;
@ -50,7 +52,7 @@ struct CThreadStatistics {
String name;
};
struct CProcessStatistics {
struct ProcessStatistics {
// Keep this in sync with /proc/all.
// From the kernel side:
pid_t pid;
@ -74,17 +76,19 @@ struct CProcessStatistics {
size_t amount_purgeable_nonvolatile;
int icon_id;
Vector<CThreadStatistics> threads;
Vector<Core::ThreadStatistics> threads;
// synthetic
String username;
};
class CProcessStatisticsReader {
class ProcessStatisticsReader {
public:
static HashMap<pid_t, CProcessStatistics> get_all();
static HashMap<pid_t, Core::ProcessStatistics> get_all();
private:
static String username_from_uid(uid_t);
static HashMap<uid_t, String> s_usernames;
};
}

View file

@ -38,33 +38,35 @@
//#define CSOCKET_DEBUG
CSocket::CSocket(Type type, CObject* parent)
: CIODevice(parent)
namespace Core {
Socket::Socket(Type type, Object* parent)
: IODevice(parent)
, m_type(type)
{
}
CSocket::~CSocket()
Socket::~Socket()
{
close();
}
bool CSocket::connect(const String& hostname, int port)
bool Socket::connect(const String& hostname, int port)
{
auto* hostent = gethostbyname(hostname.characters());
if (!hostent) {
dbg() << "CSocket::connect: Unable to resolve '" << hostname << "'";
dbg() << "Socket::connect: Unable to resolve '" << hostname << "'";
return false;
}
IPv4Address host_address((const u8*)hostent->h_addr_list[0]);
#ifdef CSOCKET_DEBUG
dbg() << "CSocket::connect: Resolved '" << hostname << "' to " << host_address;
dbg() << "Socket::connect: Resolved '" << hostname << "' to " << host_address;
#endif
return connect(host_address, port);
}
void CSocket::set_blocking(bool blocking)
void Socket::set_blocking(bool blocking)
{
int flags = fcntl(fd(), F_GETFL, 0);
ASSERT(flags >= 0);
@ -75,10 +77,10 @@ void CSocket::set_blocking(bool blocking)
ASSERT(flags == 0);
}
bool CSocket::connect(const CSocketAddress& address, int port)
bool Socket::connect(const SocketAddress& address, int port)
{
ASSERT(!is_connected());
ASSERT(address.type() == CSocketAddress::Type::IPv4);
ASSERT(address.type() == SocketAddress::Type::IPv4);
#ifdef CSOCKET_DEBUG
dbg() << *this << " connecting to " << address << "...";
#endif
@ -98,10 +100,10 @@ bool CSocket::connect(const CSocketAddress& address, int port)
return common_connect((struct sockaddr*)&addr, sizeof(addr));
}
bool CSocket::connect(const CSocketAddress& address)
bool Socket::connect(const SocketAddress& address)
{
ASSERT(!is_connected());
ASSERT(address.type() == CSocketAddress::Type::Local);
ASSERT(address.type() == SocketAddress::Type::Local);
#ifdef CSOCKET_DEBUG
dbg() << *this << " connecting to " << address << "...";
#endif
@ -113,7 +115,7 @@ bool CSocket::connect(const CSocketAddress& address)
return common_connect((const sockaddr*)&saddr, sizeof(saddr));
}
bool CSocket::common_connect(const struct sockaddr* addr, socklen_t addrlen)
bool Socket::common_connect(const struct sockaddr* addr, socklen_t addrlen)
{
int rc = ::connect(fd(), addr, addrlen);
if (rc < 0) {
@ -121,20 +123,20 @@ bool CSocket::common_connect(const struct sockaddr* addr, socklen_t addrlen)
#ifdef CSOCKET_DEBUG
dbg() << *this << " connection in progress (EINPROGRESS)";
#endif
m_notifier = CNotifier::construct(fd(), CNotifier::Event::Write, this);
m_notifier = Notifier::construct(fd(), Notifier::Event::Write, this);
m_notifier->on_ready_to_write = [this] {
#ifdef CSOCKET_DEBUG
dbg() << *this << " connected!";
#endif
m_connected = true;
ensure_read_notifier();
m_notifier->set_event_mask(CNotifier::Event::None);
m_notifier->set_event_mask(Notifier::Event::None);
if (on_connected)
on_connected();
};
return true;
}
perror("CSocket::common_connect: connect");
perror("Socket::common_connect: connect");
return false;
}
#ifdef CSOCKET_DEBUG
@ -147,7 +149,7 @@ bool CSocket::common_connect(const struct sockaddr* addr, socklen_t addrlen)
return true;
}
ByteBuffer CSocket::receive(int max_size)
ByteBuffer Socket::receive(int max_size)
{
auto buffer = read(max_size);
if (eof()) {
@ -157,7 +159,7 @@ ByteBuffer CSocket::receive(int max_size)
return buffer;
}
bool CSocket::send(const ByteBuffer& data)
bool Socket::send(const ByteBuffer& data)
{
int nsent = ::send(fd(), data.data(), data.size(), 0);
if (nsent < 0) {
@ -168,7 +170,7 @@ bool CSocket::send(const ByteBuffer& data)
return true;
}
void CSocket::did_update_fd(int fd)
void Socket::did_update_fd(int fd)
{
if (fd < 0) {
m_read_notifier = nullptr;
@ -182,12 +184,14 @@ void CSocket::did_update_fd(int fd)
}
}
void CSocket::ensure_read_notifier()
void Socket::ensure_read_notifier()
{
ASSERT(m_connected);
m_read_notifier = CNotifier::construct(fd(), CNotifier::Event::Read, this);
m_read_notifier = Notifier::construct(fd(), Notifier::Event::Read, this);
m_read_notifier->on_ready_to_read = [this] {
if (on_ready_to_read)
on_ready_to_read();
};
}
}

View file

@ -29,10 +29,12 @@
#include <LibCore/CIODevice.h>
#include <LibCore/CSocketAddress.h>
class CNotifier;
namespace Core {
class CSocket : public CIODevice {
C_OBJECT(CSocket)
class Notifier;
class Socket : public IODevice {
C_OBJECT(Socket)
public:
enum class Type {
Invalid,
@ -40,13 +42,13 @@ public:
UDP,
Local,
};
virtual ~CSocket() override;
virtual ~Socket() override;
Type type() const { return m_type; }
bool connect(const String& hostname, int port);
bool connect(const CSocketAddress&, int port);
bool connect(const CSocketAddress&);
bool connect(const SocketAddress&, int port);
bool connect(const SocketAddress&);
ByteBuffer receive(int max_size);
bool send(const ByteBuffer&);
@ -54,20 +56,20 @@ public:
bool is_connected() const { return m_connected; }
void set_blocking(bool blocking);
CSocketAddress source_address() const { return m_source_address; }
SocketAddress source_address() const { return m_source_address; }
int source_port() const { return m_source_port; }
CSocketAddress destination_address() const { return m_source_address; }
SocketAddress destination_address() const { return m_source_address; }
int destination_port() const { return m_destination_port; }
Function<void()> on_connected;
Function<void()> on_ready_to_read;
protected:
CSocket(Type, CObject* parent);
Socket(Type, Object* parent);
CSocketAddress m_source_address;
CSocketAddress m_destination_address;
SocketAddress m_source_address;
SocketAddress m_destination_address;
int m_source_port { -1 };
int m_destination_port { -1 };
bool m_connected { false };
@ -75,11 +77,13 @@ protected:
virtual void did_update_fd(int) override;
private:
virtual bool open(CIODevice::OpenMode) override { ASSERT_NOT_REACHED(); }
virtual bool open(IODevice::OpenMode) override { ASSERT_NOT_REACHED(); }
bool common_connect(const struct sockaddr*, socklen_t);
void ensure_read_notifier();
Type m_type { Type::Invalid };
RefPtr<CNotifier> m_notifier;
RefPtr<CNotifier> m_read_notifier;
RefPtr<Notifier> m_notifier;
RefPtr<Notifier> m_read_notifier;
};
}

View file

@ -32,7 +32,9 @@
#include <sys/socket.h>
#include <sys/un.h>
class CSocketAddress {
namespace Core {
class SocketAddress {
public:
enum class Type {
Invalid,
@ -40,23 +42,23 @@ public:
Local
};
CSocketAddress() {}
CSocketAddress(const IPv4Address& address)
SocketAddress() {}
SocketAddress(const IPv4Address& address)
: m_type(Type::IPv4)
, m_ipv4_address(address)
{
}
CSocketAddress(const IPv4Address& address, u16 port)
SocketAddress(const IPv4Address& address, u16 port)
: m_type(Type::IPv4)
, m_ipv4_address(address)
, m_port(port)
{
}
static CSocketAddress local(const String& address)
static SocketAddress local(const String& address)
{
CSocketAddress addr;
SocketAddress addr;
addr.m_type = Type::Local;
addr.m_local_address = address;
return addr;
@ -106,7 +108,9 @@ private:
String m_local_address;
};
inline const LogStream& operator<<(const LogStream& stream, const CSocketAddress& value)
inline const LogStream& operator<<(const LogStream& stream, const SocketAddress& value)
{
return stream << value.to_string();
}
}

View file

@ -32,24 +32,26 @@
#include <stdio.h>
#include <sys/socket.h>
CTCPServer::CTCPServer(CObject* parent)
: CObject(parent)
namespace Core {
TCPServer::TCPServer(Object* parent)
: Object(parent)
{
m_fd = socket(AF_INET, SOCK_STREAM | SOCK_NONBLOCK | SOCK_CLOEXEC, 0);
ASSERT(m_fd >= 0);
}
CTCPServer::~CTCPServer()
TCPServer::~TCPServer()
{
}
bool CTCPServer::listen(const IPv4Address& address, u16 port)
bool TCPServer::listen(const IPv4Address& address, u16 port)
{
if (m_listening)
return false;
int rc;
auto socket_address = CSocketAddress(address, port);
auto socket_address = SocketAddress(address, port);
auto in = socket_address.to_sockaddr_in();
rc = ::bind(m_fd, (const sockaddr*)&in, sizeof(in));
ASSERT(rc == 0);
@ -58,7 +60,7 @@ bool CTCPServer::listen(const IPv4Address& address, u16 port)
ASSERT(rc == 0);
m_listening = true;
m_notifier = CNotifier::construct(m_fd, CNotifier::Event::Read);
m_notifier = Notifier::construct(m_fd, Notifier::Event::Read);
m_notifier->on_ready_to_read = [this] {
if (on_ready_to_accept)
on_ready_to_accept();
@ -66,7 +68,7 @@ bool CTCPServer::listen(const IPv4Address& address, u16 port)
return true;
}
RefPtr<CTCPSocket> CTCPServer::accept()
RefPtr<TCPSocket> TCPServer::accept()
{
ASSERT(m_listening);
sockaddr_in in;
@ -77,10 +79,10 @@ RefPtr<CTCPSocket> CTCPServer::accept()
return nullptr;
}
return CTCPSocket::construct(accepted_fd);
return TCPSocket::construct(accepted_fd);
}
Optional<IPv4Address> CTCPServer::local_address() const
Optional<IPv4Address> TCPServer::local_address() const
{
if (m_fd == -1)
return {};
@ -93,7 +95,7 @@ Optional<IPv4Address> CTCPServer::local_address() const
return IPv4Address(address.sin_addr.s_addr);
}
Optional<u16> CTCPServer::local_port() const
Optional<u16> TCPServer::local_port() const
{
if (m_fd == -1)
return {};
@ -105,3 +107,5 @@ Optional<u16> CTCPServer::local_port() const
return ntohs(address.sin_port);
}
}

View file

@ -30,17 +30,19 @@
#include <LibCore/CNotifier.h>
#include <LibCore/CObject.h>
class CTCPSocket;
namespace Core {
class CTCPServer : public CObject {
C_OBJECT(CTCPServer)
class TCPSocket;
class TCPServer : public Object {
C_OBJECT(TCPServer)
public:
virtual ~CTCPServer() override;
virtual ~TCPServer() override;
bool is_listening() const { return m_listening; }
bool listen(const IPv4Address& address, u16 port);
RefPtr<CTCPSocket> accept();
RefPtr<TCPSocket> accept();
Optional<IPv4Address> local_address() const;
Optional<u16> local_port() const;
@ -48,9 +50,11 @@ public:
Function<void()> on_ready_to_accept;
private:
explicit CTCPServer(CObject* parent = nullptr);
explicit TCPServer(Object* parent = nullptr);
int m_fd { -1 };
bool m_listening { false };
RefPtr<CNotifier> m_notifier;
RefPtr<Notifier> m_notifier;
};
}

View file

@ -25,32 +25,36 @@
*/
#include <LibCore/CTCPSocket.h>
#include <sys/socket.h>
#include <errno.h>
#include <sys/socket.h>
CTCPSocket::CTCPSocket(int fd, CObject* parent)
: CSocket(CSocket::Type::TCP, parent)
namespace Core {
TCPSocket::TCPSocket(int fd, Object* parent)
: Socket(Socket::Type::TCP, parent)
{
// NOTE: This constructor is used by CTCPServer::accept(), so the socket is already connected.
m_connected = true;
set_fd(fd);
set_mode(CIODevice::ReadWrite);
set_mode(IODevice::ReadWrite);
set_error(0);
}
CTCPSocket::CTCPSocket(CObject* parent)
: CSocket(CSocket::Type::TCP, parent)
TCPSocket::TCPSocket(Object* parent)
: Socket(Socket::Type::TCP, parent)
{
int fd = socket(AF_INET, SOCK_STREAM | SOCK_NONBLOCK, 0);
if (fd < 0) {
set_error(errno);
} else {
set_fd(fd);
set_mode(CIODevice::ReadWrite);
set_mode(IODevice::ReadWrite);
set_error(0);
}
}
CTCPSocket::~CTCPSocket()
TCPSocket::~TCPSocket()
{
}
}

View file

@ -29,14 +29,18 @@
#include <AK/Badge.h>
#include <LibCore/CSocket.h>
class CTCPServer;
namespace Core {
class CTCPSocket final : public CSocket {
C_OBJECT(CTCPSocket)
class TCPServer;
class TCPSocket final : public Socket {
C_OBJECT(TCPSocket)
public:
virtual ~CTCPSocket() override;
virtual ~TCPSocket() override;
private:
CTCPSocket(int fd, CObject* parent = nullptr);
explicit CTCPSocket(CObject* parent = nullptr);
TCPSocket(int fd, Object* parent = nullptr);
explicit TCPSocket(Object* parent = nullptr);
};
}

View file

@ -26,28 +26,30 @@
#include <LibCore/CTimer.h>
CTimer::CTimer(CObject* parent)
: CObject(parent)
namespace Core {
Timer::Timer(Object* parent)
: Object(parent)
{
}
CTimer::CTimer(int interval, Function<void()>&& timeout_handler, CObject* parent)
: CObject(parent)
Timer::Timer(int interval, Function<void()>&& timeout_handler, Object* parent)
: Object(parent)
, on_timeout(move(timeout_handler))
{
start(interval);
}
CTimer::~CTimer()
Timer::~Timer()
{
}
void CTimer::start()
void Timer::start()
{
start(m_interval);
}
void CTimer::start(int interval)
void Timer::start(int interval)
{
if (m_active)
return;
@ -56,14 +58,14 @@ void CTimer::start(int interval)
m_active = true;
}
void CTimer::restart(int interval)
void Timer::restart(int interval)
{
if (m_active)
stop();
start(interval);
}
void CTimer::stop()
void Timer::stop()
{
if (!m_active)
return;
@ -71,7 +73,7 @@ void CTimer::stop()
m_active = false;
}
void CTimer::timer_event(CTimerEvent&)
void Timer::timer_event(TimerEvent&)
{
if (m_single_shot)
stop();
@ -85,3 +87,5 @@ void CTimer::timer_event(CTimerEvent&)
if (on_timeout)
on_timeout();
}
}

View file

@ -29,10 +29,12 @@
#include <AK/Function.h>
#include <LibCore/CObject.h>
class CTimer final : public CObject {
C_OBJECT(CTimer)
namespace Core {
class Timer final : public Object {
C_OBJECT(Timer)
public:
virtual ~CTimer() override;
virtual ~Timer() override;
void start();
void start(int interval);
@ -55,13 +57,15 @@ public:
Function<void()> on_timeout;
private:
explicit CTimer(CObject* parent = nullptr);
CTimer(int interval, Function<void()>&& timeout_handler, CObject* parent = nullptr);
explicit Timer(Object* parent = nullptr);
Timer(int interval, Function<void()>&& timeout_handler, Object* parent = nullptr);
virtual void timer_event(CTimerEvent&) override;
virtual void timer_event(TimerEvent&) override;
bool m_active { false };
bool m_single_shot { false };
bool m_interval_dirty { false };
int m_interval { 0 };
};
}

View file

@ -32,24 +32,26 @@
#include <stdio.h>
#include <sys/socket.h>
CUdpServer::CUdpServer(CObject* parent)
: CObject(parent)
namespace Core {
UdpServer::UdpServer(Object* parent)
: Object(parent)
{
m_fd = socket(AF_INET, SOCK_DGRAM | SOCK_NONBLOCK | SOCK_CLOEXEC, 0);
ASSERT(m_fd >= 0);
}
CUdpServer::~CUdpServer()
UdpServer::~UdpServer()
{
}
bool CUdpServer::listen(const IPv4Address& address, u16 port)
bool UdpServer::listen(const IPv4Address& address, u16 port)
{
if (m_listening)
return false;
int rc;
auto socket_address = CSocketAddress(address, port);
auto socket_address = SocketAddress(address, port);
auto in = socket_address.to_sockaddr_in();
rc = ::bind(m_fd, (const sockaddr*)&in, sizeof(in));
ASSERT(rc == 0);
@ -58,7 +60,7 @@ bool CUdpServer::listen(const IPv4Address& address, u16 port)
ASSERT(rc == 0);
m_listening = true;
m_notifier = CNotifier::construct(m_fd, CNotifier::Event::Read);
m_notifier = Notifier::construct(m_fd, Notifier::Event::Read);
m_notifier->on_ready_to_read = [this] {
if (on_ready_to_accept)
on_ready_to_accept();
@ -66,7 +68,7 @@ bool CUdpServer::listen(const IPv4Address& address, u16 port)
return true;
}
RefPtr<CUdpSocket> CUdpServer::accept()
RefPtr<UdpSocket> UdpServer::accept()
{
ASSERT(m_listening);
sockaddr_in in;
@ -77,10 +79,10 @@ RefPtr<CUdpSocket> CUdpServer::accept()
return nullptr;
}
return CUdpSocket::construct(accepted_fd);
return UdpSocket::construct(accepted_fd);
}
Optional<IPv4Address> CUdpServer::local_address() const
Optional<IPv4Address> UdpServer::local_address() const
{
if (m_fd == -1)
return {};
@ -93,7 +95,7 @@ Optional<IPv4Address> CUdpServer::local_address() const
return IPv4Address(address.sin_addr.s_addr);
}
Optional<u16> CUdpServer::local_port() const
Optional<u16> UdpServer::local_port() const
{
if (m_fd == -1)
return {};
@ -105,3 +107,5 @@ Optional<u16> CUdpServer::local_port() const
return ntohs(address.sin_port);
}
}

View file

@ -30,17 +30,19 @@
#include <LibCore/CNotifier.h>
#include <LibCore/CObject.h>
class CUdpSocket;
namespace Core {
class CUdpServer : public CObject {
C_OBJECT(CUdpServer)
class UdpSocket;
class UdpServer : public Object {
C_OBJECT(UdpServer)
public:
virtual ~CUdpServer() override;
virtual ~UdpServer() override;
bool is_listening() const { return m_listening; }
bool listen(const IPv4Address& address, u16 port);
RefPtr<CUdpSocket> accept();
RefPtr<UdpSocket> accept();
Optional<IPv4Address> local_address() const;
Optional<u16> local_port() const;
@ -48,9 +50,11 @@ public:
Function<void()> on_ready_to_accept;
private:
explicit CUdpServer(CObject* parent = nullptr);
explicit UdpServer(Object* parent = nullptr);
int m_fd { -1 };
bool m_listening { false };
RefPtr<CNotifier> m_notifier;
RefPtr<Notifier> m_notifier;
};
}

View file

@ -25,32 +25,36 @@
*/
#include <LibCore/CUdpSocket.h>
#include <sys/socket.h>
#include <errno.h>
#include <sys/socket.h>
CUdpSocket::CUdpSocket(int fd, CObject* parent)
: CSocket(CSocket::Type::UDP, parent)
namespace Core {
UdpSocket::UdpSocket(int fd, Object* parent)
: Socket(Socket::Type::UDP, parent)
{
// NOTE: This constructor is used by CUdpServer::accept(), so the socket is already connected.
m_connected = true;
set_fd(fd);
set_mode(CIODevice::ReadWrite);
set_mode(IODevice::ReadWrite);
set_error(0);
}
CUdpSocket::CUdpSocket(CObject* parent)
: CSocket(CSocket::Type::UDP, parent)
UdpSocket::UdpSocket(Object* parent)
: Socket(Socket::Type::UDP, parent)
{
int fd = socket(AF_INET, SOCK_DGRAM | SOCK_NONBLOCK, 0);
if (fd < 0) {
set_error(errno);
} else {
set_fd(fd);
set_mode(CIODevice::ReadWrite);
set_mode(IODevice::ReadWrite);
set_error(0);
}
}
CUdpSocket::~CUdpSocket()
UdpSocket::~UdpSocket()
{
}
}

View file

@ -29,12 +29,16 @@
#include <AK/Badge.h>
#include <LibCore/CSocket.h>
class CUdpSocket final : public CSocket {
C_OBJECT(CUdpSocket)
namespace Core {
class UdpSocket final : public Socket {
C_OBJECT(UdpSocket)
public:
virtual ~CUdpSocket() override;
virtual ~UdpSocket() override;
private:
CUdpSocket(int fd, CObject* parent = nullptr);
explicit CUdpSocket(CObject* parent = nullptr);
UdpSocket(int fd, Object* parent = nullptr);
explicit UdpSocket(Object* parent = nullptr);
};
}

View file

@ -51,7 +51,7 @@ void set_system_theme(SharedBuffer& buffer)
RefPtr<SharedBuffer> load_system_theme(const String& path)
{
auto file = CConfigFile::open(path);
auto file = Core::ConfigFile::open(path);
auto buffer = SharedBuffer::create_with_size(sizeof(SystemTheme));
auto* data = (SystemTheme*)buffer->data();

View file

@ -30,7 +30,7 @@
#include <LibGUI/GLabel.h>
#include <LibGUI/GWidget.h>
GAboutDialog::GAboutDialog(const StringView& name, const GraphicsBitmap* icon, CObject* parent)
GAboutDialog::GAboutDialog(const StringView& name, const GraphicsBitmap* icon, Core::Object* parent)
: GDialog(parent)
, m_name(name)
, m_icon(icon)

View file

@ -33,14 +33,14 @@ class GAboutDialog final : public GDialog {
public:
virtual ~GAboutDialog() override;
static void show(const StringView& name, const GraphicsBitmap* icon = nullptr, CObject* parent = nullptr)
static void show(const StringView& name, const GraphicsBitmap* icon = nullptr, Core::Object* parent = nullptr)
{
auto dialog = GAboutDialog::construct(name, icon, parent);
dialog->exec();
}
private:
GAboutDialog(const StringView& name, const GraphicsBitmap* icon = nullptr, CObject* parent = nullptr);
GAboutDialog(const StringView& name, const GraphicsBitmap* icon = nullptr, Core::Object* parent = nullptr);
String m_name;
RefPtr<GraphicsBitmap> m_icon;

View file

@ -37,7 +37,7 @@ GAbstractButton::GAbstractButton(const StringView& text, GWidget* parent)
: GWidget(parent)
, m_text(text)
{
m_auto_repeat_timer = CTimer::construct(this);
m_auto_repeat_timer = Core::Timer::construct(this);
m_auto_repeat_timer->on_timeout = [this] {
click();
};
@ -147,13 +147,13 @@ void GAbstractButton::mouseup_event(GMouseEvent& event)
GWidget::mouseup_event(event);
}
void GAbstractButton::enter_event(CEvent&)
void GAbstractButton::enter_event(Core::Event&)
{
m_hovered = true;
update();
}
void GAbstractButton::leave_event(CEvent&)
void GAbstractButton::leave_event(Core::Event&)
{
m_hovered = false;
update();

View file

@ -33,7 +33,7 @@
class GPainter;
class GAbstractButton : public GWidget {
C_OBJECT(GAbstractButton)
C_OBJECT_ABSTRACT(GAbstractButton)
public:
virtual ~GAbstractButton() override;
@ -69,8 +69,8 @@ protected:
virtual void mousemove_event(GMouseEvent&) override;
virtual void mouseup_event(GMouseEvent&) override;
virtual void keydown_event(GKeyEvent&) override;
virtual void enter_event(CEvent&) override;
virtual void leave_event(CEvent&) override;
virtual void enter_event(Core::Event&) override;
virtual void leave_event(Core::Event&) override;
virtual void change_event(GEvent&) override;
void paint_text(GPainter&, const Rect&, const Font&, TextAlignment);
@ -86,11 +86,11 @@ private:
bool m_exclusive { false };
int m_auto_repeat_interval { 0 };
RefPtr<CTimer> m_auto_repeat_timer;
RefPtr<Core::Timer> m_auto_repeat_timer;
};
template<>
inline bool is<GAbstractButton>(const CObject& object)
inline bool Core::is<GAbstractButton>(const Core::Object& object)
{
if (!is<GWidget>(object))
return false;

View file

@ -517,7 +517,7 @@ void GAbstractTableView::context_menu_event(GContextMenuEvent& event)
on_context_menu_request(index, event);
}
void GAbstractTableView::leave_event(CEvent&)
void GAbstractTableView::leave_event(Core::Event&)
{
window()->set_override_cursor(GStandardCursor::None);
set_hovered_header_index(-1);

View file

@ -81,7 +81,7 @@ protected:
virtual void mousemove_event(GMouseEvent&) override;
virtual void doubleclick_event(GMouseEvent&) override;
virtual void keydown_event(GKeyEvent&) override;
virtual void leave_event(CEvent&) override;
virtual void leave_event(Core::Event&) override;
virtual void context_menu_event(GContextMenuEvent&) override;
virtual void toggle_index(const GModelIndex&) {}

View file

@ -32,52 +32,52 @@
namespace GCommonActions {
NonnullRefPtr<GAction> make_open_action(Function<void(GAction&)> callback, CObject* parent)
NonnullRefPtr<GAction> make_open_action(Function<void(GAction&)> callback, Core::Object* parent)
{
return GAction::create("Open...", { Mod_Ctrl, Key_O }, GraphicsBitmap::load_from_file("/res/icons/16x16/open.png"), move(callback), parent);
}
NonnullRefPtr<GAction> make_move_to_front_action(Function<void(GAction&)> callback, CObject* parent)
NonnullRefPtr<GAction> make_move_to_front_action(Function<void(GAction&)> callback, Core::Object* parent)
{
return GAction::create("Move to front", { Mod_Ctrl | Mod_Shift, Key_Up }, GraphicsBitmap::load_from_file("/res/icons/16x16/move-to-front.png"), move(callback), parent);
}
NonnullRefPtr<GAction> make_move_to_back_action(Function<void(GAction&)> callback, CObject* parent)
NonnullRefPtr<GAction> make_move_to_back_action(Function<void(GAction&)> callback, Core::Object* parent)
{
return GAction::create("Move to back", { Mod_Ctrl | Mod_Shift, Key_Down }, GraphicsBitmap::load_from_file("/res/icons/16x16/move-to-back.png"), move(callback), parent);
}
NonnullRefPtr<GAction> make_undo_action(Function<void(GAction&)> callback, CObject* parent)
NonnullRefPtr<GAction> make_undo_action(Function<void(GAction&)> callback, Core::Object* parent)
{
return GAction::create("Undo", { Mod_Ctrl, Key_Z }, GraphicsBitmap::load_from_file("/res/icons/16x16/undo.png"), move(callback), parent);
}
NonnullRefPtr<GAction> make_redo_action(Function<void(GAction&)> callback, CObject* parent)
NonnullRefPtr<GAction> make_redo_action(Function<void(GAction&)> callback, Core::Object* parent)
{
return GAction::create("Redo", { Mod_Ctrl, Key_Y }, GraphicsBitmap::load_from_file("/res/icons/16x16/redo.png"), move(callback), parent);
}
NonnullRefPtr<GAction> make_delete_action(Function<void(GAction&)> callback, CObject* parent)
NonnullRefPtr<GAction> make_delete_action(Function<void(GAction&)> callback, Core::Object* parent)
{
return GAction::create("Delete", { Mod_None, Key_Delete }, GraphicsBitmap::load_from_file("/res/icons/16x16/delete.png"), move(callback), parent);
}
NonnullRefPtr<GAction> make_cut_action(Function<void(GAction&)> callback, CObject* parent)
NonnullRefPtr<GAction> make_cut_action(Function<void(GAction&)> callback, Core::Object* parent)
{
return GAction::create("Cut", { Mod_Ctrl, Key_X }, GraphicsBitmap::load_from_file("/res/icons/cut16.png"), move(callback), parent);
}
NonnullRefPtr<GAction> make_copy_action(Function<void(GAction&)> callback, CObject* parent)
NonnullRefPtr<GAction> make_copy_action(Function<void(GAction&)> callback, Core::Object* parent)
{
return GAction::create("Copy", { Mod_Ctrl, Key_C }, GraphicsBitmap::load_from_file("/res/icons/16x16/edit-copy.png"), move(callback), parent);
}
NonnullRefPtr<GAction> make_paste_action(Function<void(GAction&)> callback, CObject* parent)
NonnullRefPtr<GAction> make_paste_action(Function<void(GAction&)> callback, Core::Object* parent)
{
return GAction::create("Paste", { Mod_Ctrl, Key_V }, GraphicsBitmap::load_from_file("/res/icons/paste16.png"), move(callback), parent);
}
NonnullRefPtr<GAction> make_fullscreen_action(Function<void(GAction&)> callback, CObject* parent)
NonnullRefPtr<GAction> make_fullscreen_action(Function<void(GAction&)> callback, Core::Object* parent)
{
return GAction::create("Fullscreen", { Mod_None, Key_F11 }, move(callback), parent);
}
@ -87,58 +87,58 @@ NonnullRefPtr<GAction> make_quit_action(Function<void(GAction&)> callback)
return GAction::create("Quit", { Mod_Alt, Key_F4 }, move(callback));
}
NonnullRefPtr<GAction> make_go_back_action(Function<void(GAction&)> callback, CObject* parent)
NonnullRefPtr<GAction> make_go_back_action(Function<void(GAction&)> callback, Core::Object* parent)
{
return GAction::create("Go back", { Mod_Alt, Key_Left }, GraphicsBitmap::load_from_file("/res/icons/16x16/go-back.png"), move(callback), parent);
}
NonnullRefPtr<GAction> make_go_forward_action(Function<void(GAction&)> callback, CObject* parent)
NonnullRefPtr<GAction> make_go_forward_action(Function<void(GAction&)> callback, Core::Object* parent)
{
return GAction::create("Go forward", { Mod_Alt, Key_Right }, GraphicsBitmap::load_from_file("/res/icons/16x16/go-forward.png"), move(callback), parent);
}
NonnullRefPtr<GAction> make_go_home_action(Function<void(GAction&)> callback, CObject* parent)
NonnullRefPtr<GAction> make_go_home_action(Function<void(GAction&)> callback, Core::Object* parent)
{
return GAction::create("Go home", { Mod_Alt, Key_Home }, GraphicsBitmap::load_from_file("/res/icons/16x16/go-home.png"), move(callback), parent);
}
NonnullRefPtr<GAction> make_reload_action(Function<void(GAction&)> callback, CObject* parent)
NonnullRefPtr<GAction> make_reload_action(Function<void(GAction&)> callback, Core::Object* parent)
{
return GAction::create("Reload", { Mod_Ctrl, Key_R }, GraphicsBitmap::load_from_file("/res/icons/16x16/reload.png"), move(callback), parent);
}
}
GAction::GAction(const StringView& text, Function<void(GAction&)> on_activation_callback, CObject* parent)
: CObject(parent)
GAction::GAction(const StringView& text, Function<void(GAction&)> on_activation_callback, Core::Object* parent)
: Core::Object(parent)
, on_activation(move(on_activation_callback))
, m_text(text)
{
}
GAction::GAction(const StringView& text, RefPtr<GraphicsBitmap>&& icon, Function<void(GAction&)> on_activation_callback, CObject* parent)
: CObject(parent)
GAction::GAction(const StringView& text, RefPtr<GraphicsBitmap>&& icon, Function<void(GAction&)> on_activation_callback, Core::Object* parent)
: Core::Object(parent)
, on_activation(move(on_activation_callback))
, m_text(text)
, m_icon(move(icon))
{
}
GAction::GAction(const StringView& text, const GShortcut& shortcut, Function<void(GAction&)> on_activation_callback, CObject* parent)
GAction::GAction(const StringView& text, const GShortcut& shortcut, Function<void(GAction&)> on_activation_callback, Core::Object* parent)
: GAction(text, shortcut, nullptr, move(on_activation_callback), parent)
{
}
GAction::GAction(const StringView& text, const GShortcut& shortcut, RefPtr<GraphicsBitmap>&& icon, Function<void(GAction&)> on_activation_callback, CObject* parent)
: CObject(parent)
GAction::GAction(const StringView& text, const GShortcut& shortcut, RefPtr<GraphicsBitmap>&& icon, Function<void(GAction&)> on_activation_callback, Core::Object* parent)
: Core::Object(parent)
, on_activation(move(on_activation_callback))
, m_text(text)
, m_icon(move(icon))
, m_shortcut(shortcut)
{
if (parent && is<GWidget>(*parent)) {
if (parent && Core::is<GWidget>(*parent)) {
m_scope = ShortcutScope::WidgetLocal;
} else if (parent && is<GWindow>(*parent)) {
} else if (parent && Core::is<GWindow>(*parent)) {
m_scope = ShortcutScope::WindowLocal;
} else {
m_scope = ShortcutScope::ApplicationGlobal;
@ -152,7 +152,7 @@ GAction::~GAction()
GApplication::the().unregister_global_shortcut_action({}, *this);
}
void GAction::activate(CObject* activator)
void GAction::activate(Core::Object* activator)
{
if (activator)
m_activator = activator->make_weak_ptr();

View file

@ -44,24 +44,24 @@ class GButton;
class GMenuItem;
namespace GCommonActions {
NonnullRefPtr<GAction> make_open_action(Function<void(GAction&)>, CObject* parent = nullptr);
NonnullRefPtr<GAction> make_undo_action(Function<void(GAction&)>, CObject* parent = nullptr);
NonnullRefPtr<GAction> make_redo_action(Function<void(GAction&)>, CObject* parent = nullptr);
NonnullRefPtr<GAction> make_cut_action(Function<void(GAction&)>, CObject* parent = nullptr);
NonnullRefPtr<GAction> make_copy_action(Function<void(GAction&)>, CObject* parent = nullptr);
NonnullRefPtr<GAction> make_paste_action(Function<void(GAction&)>, CObject* parent = nullptr);
NonnullRefPtr<GAction> make_delete_action(Function<void(GAction&)>, CObject* parent = nullptr);
NonnullRefPtr<GAction> make_move_to_front_action(Function<void(GAction&)>, CObject* parent = nullptr);
NonnullRefPtr<GAction> make_move_to_back_action(Function<void(GAction&)>, CObject* parent = nullptr);
NonnullRefPtr<GAction> make_fullscreen_action(Function<void(GAction&)>, CObject* parent = nullptr);
NonnullRefPtr<GAction> make_open_action(Function<void(GAction&)>, Core::Object* parent = nullptr);
NonnullRefPtr<GAction> make_undo_action(Function<void(GAction&)>, Core::Object* parent = nullptr);
NonnullRefPtr<GAction> make_redo_action(Function<void(GAction&)>, Core::Object* parent = nullptr);
NonnullRefPtr<GAction> make_cut_action(Function<void(GAction&)>, Core::Object* parent = nullptr);
NonnullRefPtr<GAction> make_copy_action(Function<void(GAction&)>, Core::Object* parent = nullptr);
NonnullRefPtr<GAction> make_paste_action(Function<void(GAction&)>, Core::Object* parent = nullptr);
NonnullRefPtr<GAction> make_delete_action(Function<void(GAction&)>, Core::Object* parent = nullptr);
NonnullRefPtr<GAction> make_move_to_front_action(Function<void(GAction&)>, Core::Object* parent = nullptr);
NonnullRefPtr<GAction> make_move_to_back_action(Function<void(GAction&)>, Core::Object* parent = nullptr);
NonnullRefPtr<GAction> make_fullscreen_action(Function<void(GAction&)>, Core::Object* parent = nullptr);
NonnullRefPtr<GAction> make_quit_action(Function<void(GAction&)>);
NonnullRefPtr<GAction> make_go_back_action(Function<void(GAction&)>, CObject* parent = nullptr);
NonnullRefPtr<GAction> make_go_forward_action(Function<void(GAction&)>, CObject* parent = nullptr);
NonnullRefPtr<GAction> make_go_home_action(Function<void(GAction&)> callback, CObject* parent = nullptr);
NonnullRefPtr<GAction> make_reload_action(Function<void(GAction&)>, CObject* parent = nullptr);
NonnullRefPtr<GAction> make_go_back_action(Function<void(GAction&)>, Core::Object* parent = nullptr);
NonnullRefPtr<GAction> make_go_forward_action(Function<void(GAction&)>, Core::Object* parent = nullptr);
NonnullRefPtr<GAction> make_go_home_action(Function<void(GAction&)> callback, Core::Object* parent = nullptr);
NonnullRefPtr<GAction> make_reload_action(Function<void(GAction&)>, Core::Object* parent = nullptr);
};
class GAction final : public CObject {
class GAction final : public Core::Object {
C_OBJECT(GAction)
public:
enum class ShortcutScope {
@ -70,19 +70,19 @@ public:
WindowLocal,
ApplicationGlobal,
};
static NonnullRefPtr<GAction> create(const StringView& text, Function<void(GAction&)> callback, CObject* parent = nullptr)
static NonnullRefPtr<GAction> create(const StringView& text, Function<void(GAction&)> callback, Core::Object* parent = nullptr)
{
return adopt(*new GAction(text, move(callback), parent));
}
static NonnullRefPtr<GAction> create(const StringView& text, RefPtr<GraphicsBitmap>&& icon, Function<void(GAction&)> callback, CObject* parent = nullptr)
static NonnullRefPtr<GAction> create(const StringView& text, RefPtr<GraphicsBitmap>&& icon, Function<void(GAction&)> callback, Core::Object* parent = nullptr)
{
return adopt(*new GAction(text, move(icon), move(callback), parent));
}
static NonnullRefPtr<GAction> create(const StringView& text, const GShortcut& shortcut, Function<void(GAction&)> callback, CObject* parent = nullptr)
static NonnullRefPtr<GAction> create(const StringView& text, const GShortcut& shortcut, Function<void(GAction&)> callback, Core::Object* parent = nullptr)
{
return adopt(*new GAction(text, shortcut, move(callback), parent));
}
static NonnullRefPtr<GAction> create(const StringView& text, const GShortcut& shortcut, RefPtr<GraphicsBitmap>&& icon, Function<void(GAction&)> callback, CObject* parent = nullptr)
static NonnullRefPtr<GAction> create(const StringView& text, const GShortcut& shortcut, RefPtr<GraphicsBitmap>&& icon, Function<void(GAction&)> callback, Core::Object* parent = nullptr)
{
return adopt(*new GAction(text, shortcut, move(icon), move(callback), parent));
}
@ -93,12 +93,12 @@ public:
const GraphicsBitmap* icon() const { return m_icon.ptr(); }
void set_icon(const GraphicsBitmap* icon) { m_icon = icon; }
const CObject* activator() const { return m_activator.ptr(); }
CObject* activator() { return m_activator.ptr(); }
const Core::Object* activator() const { return m_activator.ptr(); }
Core::Object* activator() { return m_activator.ptr(); }
Function<void(GAction&)> on_activation;
void activate(CObject* activator = nullptr);
void activate(Core::Object* activator = nullptr);
bool is_enabled() const { return m_enabled; }
void set_enabled(bool);
@ -124,10 +124,10 @@ public:
private:
virtual bool is_action() const override { return true; }
GAction(const StringView& text, Function<void(GAction&)> = nullptr, CObject* = nullptr);
GAction(const StringView& text, const GShortcut&, Function<void(GAction&)> = nullptr, CObject* = nullptr);
GAction(const StringView& text, const GShortcut&, RefPtr<GraphicsBitmap>&& icon, Function<void(GAction&)> = nullptr, CObject* = nullptr);
GAction(const StringView& text, RefPtr<GraphicsBitmap>&& icon, Function<void(GAction&)> = nullptr, CObject* = nullptr);
GAction(const StringView& text, Function<void(GAction&)> = nullptr, Core::Object* = nullptr);
GAction(const StringView& text, const GShortcut&, Function<void(GAction&)> = nullptr, Core::Object* = nullptr);
GAction(const StringView& text, const GShortcut&, RefPtr<GraphicsBitmap>&& icon, Function<void(GAction&)> = nullptr, Core::Object* = nullptr);
GAction(const StringView& text, RefPtr<GraphicsBitmap>&& icon, Function<void(GAction&)> = nullptr, Core::Object* = nullptr);
template<typename Callback>
void for_each_toolbar_button(Callback);
@ -145,11 +145,11 @@ private:
HashTable<GButton*> m_buttons;
HashTable<GMenuItem*> m_menu_items;
WeakPtr<GActionGroup> m_action_group;
WeakPtr<CObject> m_activator;
WeakPtr<Core::Object> m_activator;
};
template<>
inline bool is<GAction>(const CObject& object)
inline bool Core::is<GAction>(const Core::Object& object)
{
return object.is_action();
}

View file

@ -48,7 +48,7 @@ GApplication::GApplication(int argc, char** argv)
(void)argv;
ASSERT(!s_the);
s_the = this;
m_event_loop = make<CEventLoop>();
m_event_loop = make<Core::EventLoop>();
GWindowServerConnection::the();
if (argc > 0)
m_invoked_as = argv[0];

View file

@ -35,8 +35,10 @@
namespace AK {
class SharedBuffer;
}
namespace Core {
class EventLoop;
}
class CEventLoop;
class GAction;
class GKeyEvent;
class GMenuBar;
@ -78,7 +80,7 @@ public:
void set_system_palette(SharedBuffer&);
private:
OwnPtr<CEventLoop> m_event_loop;
OwnPtr<Core::EventLoop> m_event_loop;
OwnPtr<GMenuBar> m_menubar;
RefPtr<PaletteImpl> m_palette;
RefPtr<PaletteImpl> m_system_palette;

View file

@ -31,7 +31,7 @@
#include <LibGUI/GSpinBox.h>
#include <LibGUI/GWidget.h>
GColorPicker::GColorPicker(Color color, CObject* parent)
GColorPicker::GColorPicker(Color color, Core::Object* parent)
: GDialog(parent)
, m_color(color)
{

View file

@ -38,7 +38,7 @@ public:
Color color() const { return m_color; }
private:
explicit GColorPicker(Color, CObject* parent = nullptr);
explicit GColorPicker(Color, Core::Object* parent = nullptr);
void build();

View file

@ -28,7 +28,7 @@
#include <LibGUI/GDialog.h>
#include <LibGUI/GEvent.h>
GDialog::GDialog(CObject* parent)
GDialog::GDialog(Core::Object* parent)
: GWindow(parent)
{
set_modal(true);
@ -41,7 +41,7 @@ GDialog::~GDialog()
int GDialog::exec()
{
ASSERT(!m_event_loop);
m_event_loop = make<CEventLoop>();
m_event_loop = make<Core::EventLoop>();
auto new_rect = rect();
if (parent() && parent()->is_window()) {
auto& parent_window = *static_cast<GWindow*>(parent());
@ -67,7 +67,7 @@ void GDialog::done(int result)
m_event_loop->quit(result);
}
void GDialog::event(CEvent& event)
void GDialog::event(Core::Event& event)
{
if (event.type() == GEvent::KeyUp) {
auto& key_event = static_cast<GKeyEvent&>(event);

View file

@ -45,14 +45,14 @@ public:
int result() const { return m_result; }
void done(int result);
virtual void event(CEvent&) override;
virtual void event(Core::Event&) override;
virtual void close() override;
protected:
explicit GDialog(CObject* parent);
explicit GDialog(Core::Object* parent);
private:
OwnPtr<CEventLoop> m_event_loop;
OwnPtr<Core::EventLoop> m_event_loop;
int m_result { ExecAborted };
};

View file

@ -30,8 +30,8 @@
static GDragOperation* s_current_drag_operation;
GDragOperation::GDragOperation(CObject* parent)
: CObject(parent)
GDragOperation::GDragOperation(Core::Object* parent)
: Core::Object(parent)
{
}
@ -61,7 +61,7 @@ GDragOperation::Outcome GDragOperation::exec()
}
s_current_drag_operation = this;
m_event_loop = make<CEventLoop>();
m_event_loop = make<Core::EventLoop>();
auto result = m_event_loop->exec();
m_event_loop = nullptr;
dbgprintf("%s: event loop returned with result %d\n", class_name(), result);

View file

@ -32,7 +32,7 @@
class GraphicsBitmap;
class GWindowServerConnection;
class GDragOperation : public CObject {
class GDragOperation : public Core::Object {
C_OBJECT(GDragOperation)
public:
enum class Outcome {
@ -58,12 +58,12 @@ public:
static void notify_cancelled(Badge<GWindowServerConnection>);
protected:
explicit GDragOperation(CObject* parent = nullptr);
explicit GDragOperation(Core::Object* parent = nullptr);
private:
void done(Outcome);
OwnPtr<CEventLoop> m_event_loop;
OwnPtr<Core::EventLoop> m_event_loop;
Outcome m_outcome { Outcome::None };
String m_text;
String m_data_type;

View file

@ -32,9 +32,7 @@
#include <LibDraw/Rect.h>
#include <LibGUI/GWindowType.h>
class CObject;
class GEvent : public CEvent {
class GEvent : public Core::Event {
public:
enum Type {
Show = 1000,
@ -72,7 +70,7 @@ public:
GEvent() {}
explicit GEvent(Type type)
: CEvent(type)
: Core::Event(type)
{
}
virtual ~GEvent() {}

View file

@ -72,7 +72,7 @@ Optional<String> GFilePicker::get_save_filepath(const String& title, const Strin
return {};
}
GFilePicker::GFilePicker(Mode mode, const StringView& file_name, const StringView& path, CObject* parent)
GFilePicker::GFilePicker(Mode mode, const StringView& file_name, const StringView& path, Core::Object* parent)
: GDialog(parent)
, m_model(GFileSystemModel::create())
, m_mode(mode)

View file

@ -55,7 +55,7 @@ private:
void clear_preview();
void on_file_return();
GFilePicker(Mode type = Mode::Open, const StringView& file_name = "Untitled", const StringView& path = String(get_current_user_home_path()), CObject* parent = nullptr);
GFilePicker(Mode type = Mode::Open, const StringView& file_name = "Untitled", const StringView& path = String(get_current_user_home_path()), Core::Object* parent = nullptr);
static String ok_button_name(Mode mode)
{

View file

@ -91,7 +91,7 @@ void GFileSystemModel::Node::traverse_if_needed(const GFileSystemModel& model)
total_size = 0;
auto full_path = this->full_path(model);
CDirIterator di(full_path, CDirIterator::SkipDots);
Core::DirIterator di(full_path, Core::DirIterator::SkipDots);
if (di.has_error()) {
fprintf(stderr, "CDirIterator: %s\n", di.error_string());
return;
@ -122,7 +122,7 @@ void GFileSystemModel::Node::traverse_if_needed(const GFileSystemModel& model)
}
fcntl(m_watch_fd, F_SETFD, FD_CLOEXEC);
dbg() << "Watching " << full_path << " for changes, m_watch_fd = " << m_watch_fd;
m_notifier = CNotifier::construct(m_watch_fd, CNotifier::Event::Read);
m_notifier = Core::Notifier::construct(m_watch_fd, Core::Notifier::Event::Read);
m_notifier->on_ready_to_read = [this, &model] {
char buffer[32];
int rc = read(m_notifier->fd(), buffer, sizeof(buffer));

View file

@ -85,7 +85,7 @@ public:
bool has_traversed { false };
int m_watch_fd { -1 };
RefPtr<CNotifier> m_notifier;
RefPtr<Core::Notifier> m_notifier;
GModelIndex index(const GFileSystemModel&, int column) const;
void traverse_if_needed(const GFileSystemModel&);

View file

@ -43,7 +43,7 @@ GFontDatabase& GFontDatabase::the()
GFontDatabase::GFontDatabase()
{
CDirIterator di("/res/fonts", CDirIterator::SkipDots);
Core::DirIterator di("/res/fonts", Core::DirIterator::SkipDots);
if (di.has_error()) {
fprintf(stderr, "CDirIterator: %s\n", di.error_string());
exit(1);

View file

@ -31,7 +31,7 @@
#include <LibGUI/GTextEditor.h>
#include <stdio.h>
GInputBox::GInputBox(const StringView& prompt, const StringView& title, CObject* parent)
GInputBox::GInputBox(const StringView& prompt, const StringView& title, Core::Object* parent)
: GDialog(parent)
, m_prompt(prompt)
{

View file

@ -34,7 +34,7 @@ class GTextEditor;
class GInputBox : public GDialog {
C_OBJECT(GInputBox)
public:
explicit GInputBox(const StringView& prompt, const StringView& title, CObject* parent = nullptr);
explicit GInputBox(const StringView& prompt, const StringView& title, Core::Object* parent = nullptr);
virtual ~GInputBox() override;
String text_value() const { return m_text_value; }

View file

@ -30,8 +30,8 @@
void GJsonArrayModel::update()
{
auto file = CFile::construct(m_json_path);
if (!file->open(CIODevice::ReadOnly)) {
auto file = Core::File::construct(m_json_path);
if (!file->open(Core::IODevice::ReadOnly)) {
dbg() << "Unable to open " << file->filename();
m_array.clear();
did_update();

View file

@ -35,7 +35,7 @@
class GAction;
class Point;
class GMenu final : public CObject {
class GMenu final : public Core::Object {
C_OBJECT(GMenu)
public:
explicit GMenu(const StringView& name = "");

View file

@ -30,13 +30,13 @@
#include <LibGUI/GMessageBox.h>
#include <stdio.h>
int GMessageBox::show(const StringView& text, const StringView& title, Type type, InputType input_type, CObject* parent)
int GMessageBox::show(const StringView& text, const StringView& title, Type type, InputType input_type, Core::Object* parent)
{
auto box = GMessageBox::construct(text, title, type, input_type, parent);
return box->exec();
}
GMessageBox::GMessageBox(const StringView& text, const StringView& title, Type type, InputType input_type, CObject* parent)
GMessageBox::GMessageBox(const StringView& text, const StringView& title, Type type, InputType input_type, Core::Object* parent)
: GDialog(parent)
, m_text(text)
, m_type(type)

View file

@ -45,10 +45,10 @@ public:
virtual ~GMessageBox() override;
static int show(const StringView& text, const StringView& title, Type type = Type::None, InputType = InputType::OK, CObject* parent = nullptr);
static int show(const StringView& text, const StringView& title, Type type = Type::None, InputType = InputType::OK, Core::Object* parent = nullptr);
private:
explicit GMessageBox(const StringView& text, const StringView& title, Type type = Type::None, InputType = InputType::OK, CObject* parent = nullptr);
explicit GMessageBox(const StringView& text, const StringView& title, Type type = Type::None, InputType = InputType::OK, Core::Object* parent = nullptr);
bool should_include_ok_button() const;
bool should_include_cancel_button() const;

View file

@ -53,7 +53,7 @@ private:
};
template<>
inline bool is<GRadioButton>(const CObject& object)
inline bool Core::is<GRadioButton>(const Core::Object& object)
{
if (!is<GWidget>(object))
return false;

View file

@ -60,13 +60,13 @@ void GResizeCorner::mousedown_event(GMouseEvent& event)
GWidget::mousedown_event(event);
}
void GResizeCorner::enter_event(CEvent& event)
void GResizeCorner::enter_event(Core::Event& event)
{
window()->set_override_cursor(GStandardCursor::ResizeDiagonalTLBR);
GWidget::enter_event(event);
}
void GResizeCorner::leave_event(CEvent& event)
void GResizeCorner::leave_event(Core::Event& event)
{
window()->set_override_cursor(GStandardCursor::None);
GWidget::leave_event(event);

View file

@ -36,8 +36,8 @@ protected:
virtual void paint_event(GPaintEvent&) override;
virtual void mousedown_event(GMouseEvent&) override;
virtual void enter_event(CEvent&) override;
virtual void leave_event(CEvent&) override;
virtual void enter_event(Core::Event&) override;
virtual void leave_event(Core::Event&) override;
private:
RefPtr<GraphicsBitmap> m_bitmap;

View file

@ -93,7 +93,7 @@ GScrollBar::GScrollBar(Orientation orientation, GWidget* parent)
: GWidget(parent)
, m_orientation(orientation)
{
m_automatic_scrolling_timer = CTimer::construct(this);
m_automatic_scrolling_timer = Core::Timer::construct(this);
if (!s_up_arrow_bitmap)
s_up_arrow_bitmap = &CharacterBitmap::create_from_ascii(s_up_arrow_bitmap_data, 9, 9).leak_ref();
if (!s_down_arrow_bitmap)
@ -355,7 +355,7 @@ void GScrollBar::mousemove_event(GMouseEvent& event)
set_value(new_value);
}
void GScrollBar::leave_event(CEvent&)
void GScrollBar::leave_event(Core::Event&)
{
if (m_hovered_component != Component::Invalid) {
m_hovered_component = Component::Invalid;

View file

@ -72,7 +72,7 @@ private:
virtual void mouseup_event(GMouseEvent&) override;
virtual void mousemove_event(GMouseEvent&) override;
virtual void mousewheel_event(GMouseEvent&) override;
virtual void leave_event(CEvent&) override;
virtual void leave_event(Core::Event&) override;
virtual void change_event(GEvent&) override;
int default_button_size() const { return 16; }
@ -110,5 +110,5 @@ private:
};
AutomaticScrollingDirection m_automatic_scrolling_direction { AutomaticScrollingDirection::None };
RefPtr<CTimer> m_automatic_scrolling_timer;
RefPtr<Core::Timer> m_automatic_scrolling_timer;
};

View file

@ -162,7 +162,7 @@ void GSlider::mouseup_event(GMouseEvent& event)
return GWidget::mouseup_event(event);
}
void GSlider::leave_event(CEvent& event)
void GSlider::leave_event(Core::Event& event)
{
if (!is_enabled())
return;

View file

@ -77,7 +77,7 @@ protected:
virtual void mousedown_event(GMouseEvent&) override;
virtual void mousemove_event(GMouseEvent&) override;
virtual void mouseup_event(GMouseEvent&) override;
virtual void leave_event(CEvent&) override;
virtual void leave_event(Core::Event&) override;
virtual void change_event(GEvent&) override;
private:

View file

@ -43,14 +43,14 @@ GSplitter::~GSplitter()
{
}
void GSplitter::enter_event(CEvent&)
void GSplitter::enter_event(Core::Event&)
{
set_background_role(ColorRole::HoverHighlight);
window()->set_override_cursor(m_orientation == Orientation::Horizontal ? GStandardCursor::ResizeHorizontal : GStandardCursor::ResizeVertical);
update();
}
void GSplitter::leave_event(CEvent&)
void GSplitter::leave_event(Core::Event&)
{
set_background_role(ColorRole::Button);
if (!m_resizing)

View file

@ -39,8 +39,8 @@ protected:
virtual void mousedown_event(GMouseEvent&) override;
virtual void mousemove_event(GMouseEvent&) override;
virtual void mouseup_event(GMouseEvent&) override;
virtual void enter_event(CEvent&) override;
virtual void leave_event(CEvent&) override;
virtual void enter_event(Core::Event&) override;
virtual void leave_event(Core::Event&) override;
private:
Orientation m_orientation;

View file

@ -59,11 +59,11 @@ void GStackWidget::resize_event(GResizeEvent& event)
m_active_widget->set_relative_rect({ {}, event.size() });
}
void GStackWidget::child_event(CChildEvent& event)
void GStackWidget::child_event(Core::ChildEvent& event)
{
if (!event.child() || !is<GWidget>(*event.child()))
if (!event.child() || !Core::is<GWidget>(*event.child()))
return GWidget::child_event(event);
auto& child = to<GWidget>(*event.child());
auto& child = Core::to<GWidget>(*event.child());
if (event.type() == GEvent::ChildAdded) {
if (!m_active_widget)
set_active_widget(&child);

View file

@ -41,7 +41,7 @@ public:
protected:
explicit GStackWidget(GWidget* parent);
virtual void child_event(CChildEvent&) override;
virtual void child_event(Core::ChildEvent&) override;
virtual void resize_event(GResizeEvent&) override;
private:

View file

@ -84,11 +84,11 @@ Rect GTabWidget::child_rect_for_size(const Size& size) const
return rect;
}
void GTabWidget::child_event(CChildEvent& event)
void GTabWidget::child_event(Core::ChildEvent& event)
{
if (!event.child() || !is<GWidget>(*event.child()))
if (!event.child() || !Core::is<GWidget>(*event.child()))
return GWidget::child_event(event);
auto& child = to<GWidget>(*event.child());
auto& child = Core::to<GWidget>(*event.child());
if (event.type() == GEvent::ChildAdded) {
if (!m_active_widget)
set_active_widget(&child);
@ -214,7 +214,7 @@ void GTabWidget::mousemove_event(GMouseEvent& event)
update_bar();
}
void GTabWidget::leave_event(CEvent&)
void GTabWidget::leave_event(Core::Event&)
{
if (m_hovered_tab_index != -1) {
m_hovered_tab_index = -1;

View file

@ -55,11 +55,11 @@ public:
protected:
virtual void paint_event(GPaintEvent&) override;
virtual void child_event(CChildEvent&) override;
virtual void child_event(Core::ChildEvent&) override;
virtual void resize_event(GResizeEvent&) override;
virtual void mousedown_event(GMouseEvent&) override;
virtual void mousemove_event(GMouseEvent&) override;
virtual void leave_event(CEvent&) override;
virtual void leave_event(Core::Event&) override;
private:
Rect child_rect_for_size(const Size&) const;

View file

@ -37,7 +37,7 @@ GTextDocument::GTextDocument(Client* client)
append_line(make<GTextDocumentLine>(*this));
// TODO: Instead of a repating timer, this we should call a delayed 2 sec timer when the user types.
m_undo_timer = CTimer::construct(
m_undo_timer = Core::Timer::construct(
2000, [this] {
update_undo_timer();
});

View file

@ -146,7 +146,7 @@ private:
bool m_client_notifications_enabled { true };
GUndoStack m_undo_stack;
RefPtr<CTimer> m_undo_timer;
RefPtr<Core::Timer> m_undo_timer;
};
class GTextDocumentLine {

View file

@ -235,7 +235,7 @@ void GTextEditor::mousedown_event(GMouseEvent& event)
}
if (m_triple_click_timer.is_valid() && m_triple_click_timer.elapsed() < 250) {
m_triple_click_timer = CElapsedTimer();
m_triple_click_timer = Core::ElapsedTimer();
GTextPosition start;
GTextPosition end;
@ -1030,18 +1030,18 @@ void GTextEditor::set_cursor(const GTextPosition& a_position)
on_cursor_change();
}
void GTextEditor::focusin_event(CEvent&)
void GTextEditor::focusin_event(Core::Event&)
{
update_cursor();
start_timer(500);
}
void GTextEditor::focusout_event(CEvent&)
void GTextEditor::focusout_event(Core::Event&)
{
stop_timer();
}
void GTextEditor::timer_event(CTimerEvent&)
void GTextEditor::timer_event(Core::TimerEvent&)
{
m_cursor_state = !m_cursor_state;
if (is_focused())
@ -1171,13 +1171,13 @@ void GTextEditor::paste()
insert_at_cursor_or_replace_selection(paste_text);
}
void GTextEditor::enter_event(CEvent&)
void GTextEditor::enter_event(Core::Event&)
{
ASSERT(window());
window()->set_override_cursor(GStandardCursor::IBeam);
}
void GTextEditor::leave_event(CEvent&)
void GTextEditor::leave_event(Core::Event&)
{
ASSERT(window());
window()->set_override_cursor(GStandardCursor::None);

View file

@ -142,12 +142,12 @@ protected:
virtual void mousemove_event(GMouseEvent&) override;
virtual void doubleclick_event(GMouseEvent&) override;
virtual void keydown_event(GKeyEvent&) override;
virtual void focusin_event(CEvent&) override;
virtual void focusout_event(CEvent&) override;
virtual void timer_event(CTimerEvent&) override;
virtual void focusin_event(Core::Event&) override;
virtual void focusout_event(Core::Event&) override;
virtual void timer_event(Core::TimerEvent&) override;
virtual bool accepts_focus() const override { return true; }
virtual void enter_event(CEvent&) override;
virtual void leave_event(CEvent&) override;
virtual void enter_event(Core::Event&) override;
virtual void leave_event(Core::Event&) override;
virtual void context_menu_event(GContextMenuEvent&) override;
virtual void resize_event(GResizeEvent&) override;
virtual void cursor_did_change() {}
@ -232,7 +232,7 @@ private:
RefPtr<GAction> m_paste_action;
RefPtr<GAction> m_delete_action;
RefPtr<GAction> m_go_to_line_action;
CElapsedTimer m_triple_click_timer;
Core::ElapsedTimer m_triple_click_timer;
NonnullRefPtrVector<GAction> m_custom_context_menu_actions;
RefPtr<GTextDocument> m_document;

View file

@ -91,7 +91,7 @@ const GWidgetClassRegistration* GWidgetClassRegistration::find(const String& cla
}
GWidget::GWidget(GWidget* parent)
: CObject(parent, true)
: Core::Object(parent, true)
, m_font(Font::default_font())
, m_palette(GApplication::the().palette().impl())
{
@ -101,26 +101,26 @@ GWidget::~GWidget()
{
}
void GWidget::child_event(CChildEvent& event)
void GWidget::child_event(Core::ChildEvent& event)
{
if (event.type() == GEvent::ChildAdded) {
if (event.child() && is<GWidget>(*event.child()) && layout()) {
if (event.child() && Core::is<GWidget>(*event.child()) && layout()) {
if (event.insertion_before_child() && event.insertion_before_child()->is_widget())
layout()->insert_widget_before(to<GWidget>(*event.child()), to<GWidget>(*event.insertion_before_child()));
layout()->insert_widget_before(Core::to<GWidget>(*event.child()), Core::to<GWidget>(*event.insertion_before_child()));
else
layout()->add_widget(to<GWidget>(*event.child()));
layout()->add_widget(Core::to<GWidget>(*event.child()));
}
}
if (event.type() == GEvent::ChildRemoved) {
if (layout()) {
if (event.child() && is<GWidget>(*event.child()))
layout()->remove_widget(to<GWidget>(*event.child()));
if (event.child() && Core::is<GWidget>(*event.child()))
layout()->remove_widget(Core::to<GWidget>(*event.child()));
else
invalidate_layout();
}
update();
}
return CObject::child_event(event);
return Core::Object::child_event(event);
}
void GWidget::set_relative_rect(const Rect& a_rect)
@ -151,7 +151,7 @@ void GWidget::set_relative_rect(const Rect& a_rect)
update();
}
void GWidget::event(CEvent& event)
void GWidget::event(Core::Event& event)
{
switch (event.type()) {
case GEvent::Paint:
@ -189,7 +189,7 @@ void GWidget::event(CEvent& event)
case GEvent::EnabledChange:
return change_event(static_cast<GEvent&>(event));
default:
return CObject::event(event);
return Core::Object::event(event);
}
}
@ -278,14 +278,14 @@ void GWidget::handle_mousedoubleclick_event(GMouseEvent& event)
doubleclick_event(event);
}
void GWidget::handle_enter_event(CEvent& event)
void GWidget::handle_enter_event(Core::Event& event)
{
if (has_tooltip())
GApplication::the().show_tooltip(m_tooltip, screen_relative_rect().center().translated(0, height() / 2));
enter_event(event);
}
void GWidget::handle_leave_event(CEvent& event)
void GWidget::handle_leave_event(Core::Event& event)
{
GApplication::the().hide_tooltip();
leave_event(event);
@ -356,19 +356,19 @@ void GWidget::context_menu_event(GContextMenuEvent&)
{
}
void GWidget::focusin_event(CEvent&)
void GWidget::focusin_event(Core::Event&)
{
}
void GWidget::focusout_event(CEvent&)
void GWidget::focusout_event(Core::Event&)
{
}
void GWidget::enter_event(CEvent&)
void GWidget::enter_event(Core::Event&)
{
}
void GWidget::leave_event(CEvent&)
void GWidget::leave_event(Core::Event&)
{
}
@ -426,9 +426,9 @@ Rect GWidget::screen_relative_rect() const
GWidget* GWidget::child_at(const Point& point) const
{
for (int i = children().size() - 1; i >= 0; --i) {
if (!is<GWidget>(children()[i]))
if (!Core::is<GWidget>(children()[i]))
continue;
auto& child = to<GWidget>(children()[i]);
auto& child = Core::to<GWidget>(children()[i]);
if (!child.is_visible())
continue;
if (child.relative_rect().contains(point))
@ -701,7 +701,7 @@ void GWidget::save_to(AK::JsonObject& json)
json.set("foreground_color", foreground_color().to_string());
json.set("preferred_size", preferred_size().to_string());
json.set("size_policy", String::format("[%s,%s]", to_string(horizontal_size_policy()), to_string(vertical_size_policy())));
CObject::save_to(json);
Core::Object::save_to(json);
}
Vector<GWidget*> GWidget::child_widgets() const

View file

@ -94,7 +94,7 @@ private:
Function<NonnullRefPtr<GWidget>(GWidget*)> m_factory;
};
class GWidget : public CObject {
class GWidget : public Core::Object {
C_OBJECT(GWidget)
public:
virtual ~GWidget() override;
@ -123,7 +123,7 @@ public:
bool updates_enabled() const { return m_updates_enabled; }
void set_updates_enabled(bool);
virtual void event(CEvent&) override;
virtual void event(Core::Event&) override;
// This is called after children have been painted.
virtual void second_paint_event(GPaintEvent&);
@ -245,8 +245,8 @@ public:
void for_each_child_widget(Callback callback)
{
for_each_child([&](auto& child) {
if (is<GWidget>(child))
return callback(to<GWidget>(child));
if (Core::is<GWidget>(child))
return callback(Core::to<GWidget>(child));
return IterationDecision::Continue;
});
}
@ -281,11 +281,11 @@ protected:
virtual void click_event(GMouseEvent&);
virtual void doubleclick_event(GMouseEvent&);
virtual void context_menu_event(GContextMenuEvent&);
virtual void focusin_event(CEvent&);
virtual void focusout_event(CEvent&);
virtual void enter_event(CEvent&);
virtual void leave_event(CEvent&);
virtual void child_event(CChildEvent&) override;
virtual void focusin_event(Core::Event&);
virtual void focusout_event(Core::Event&);
virtual void enter_event(Core::Event&);
virtual void leave_event(Core::Event&);
virtual void child_event(Core::ChildEvent&) override;
virtual void change_event(GEvent&);
virtual void drop_event(GDropEvent&);
@ -295,8 +295,8 @@ private:
void handle_mousedown_event(GMouseEvent&);
void handle_mousedoubleclick_event(GMouseEvent&);
void handle_mouseup_event(GMouseEvent&);
void handle_enter_event(CEvent&);
void handle_leave_event(CEvent&);
void handle_enter_event(Core::Event&);
void handle_leave_event(Core::Event&);
void focus_previous_widget();
void focus_next_widget();
@ -326,20 +326,20 @@ private:
};
template<>
inline bool is<GWidget>(const CObject& object)
inline bool Core::is<GWidget>(const Core::Object& object)
{
return object.is_widget();
}
inline GWidget* GWidget::parent_widget()
{
if (parent() && is<GWidget>(*parent()))
return &to<GWidget>(*parent());
if (parent() && Core::is<GWidget>(*parent()))
return &Core::to<GWidget>(*parent());
return nullptr;
}
inline const GWidget* GWidget::parent_widget() const
{
if (parent() && is<GWidget>(*parent()))
return &to<const GWidget>(*parent());
if (parent() && Core::is<GWidget>(*parent()))
return &Core::to<const GWidget>(*parent());
return nullptr;
}

Some files were not shown because too many files have changed in this diff Show more