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

Add clang-format file

Also run it across the whole tree to get everything using the One True Style.
We don't yet run this in an automated fashion as it's a little slow, but
there is a snippet to do so in makeall.sh.
This commit is contained in:
Robin Burchell 2019-05-28 11:53:16 +02:00 committed by Andreas Kling
parent c11351ac50
commit 0dc9af5f7e
286 changed files with 3244 additions and 2424 deletions

View file

@ -19,18 +19,27 @@ const Vector<String>& CArgsParserResult::get_single_values() const
}
CArgsParser::Arg::Arg(const String& name, const String& description, bool required)
: name(name), description(description), required(required)
{}
: name(name)
, description(description)
, required(required)
{
}
CArgsParser::Arg::Arg(const String& name, const String& value_name, const String& description, bool required)
: name(name), description(description), value_name(value_name), required(required)
{}
: name(name)
, description(description)
, value_name(value_name)
, required(required)
{
}
CArgsParser::CArgsParser(const String& program_name)
: m_program_name(program_name), m_prefix("-")
{}
: m_program_name(program_name)
, m_prefix("-")
{
}
CArgsParserResult CArgsParser::parse(const int argc, const char** argv)
CArgsParserResult CArgsParser::parse(const int argc, const char** argv)
{
CArgsParserResult res;
@ -48,7 +57,7 @@ CArgsParserResult CArgsParser::parse(const int argc, const char** argv)
return res;
}
int CArgsParser::parse_next_param(const int index, const char** argv, const int params_left, CArgsParserResult& res)
int CArgsParser::parse_next_param(const int index, const char** argv, const int params_left, CArgsParserResult& res)
{
if (params_left == 0)
return 0;
@ -148,7 +157,7 @@ void CArgsParser::add_arg(const String& name, const String& value_name, const St
void CArgsParser::add_single_value(const String& name)
{
m_single_args.append(SingleArg{name, false});
m_single_args.append(SingleArg { name, false });
}
void CArgsParser::add_required_single_value(const String& name)
@ -157,7 +166,7 @@ void CArgsParser::add_required_single_value(const String& name)
// adding required arguments after non-required arguments would be nonsensical
ASSERT(m_single_args.last().required);
}
m_single_args.append(SingleArg{name, true});
m_single_args.append(SingleArg { name, true });
}
String CArgsParser::get_usage() const
@ -226,4 +235,3 @@ void CArgsParser::print_usage() const
{
printf("%s\n", get_usage().characters());
}

View file

@ -67,4 +67,3 @@ private:
Vector<SingleArg> m_single_args;
HashMap<String, Arg> m_args;
};

View file

@ -1,9 +1,9 @@
#include <AK/StringBuilder.h>
#include <LibCore/CConfigFile.h>
#include <LibCore/CFile.h>
#include <LibCore/CUserInfo.h>
#include <AK/StringBuilder.h>
#include <stdio.h>
#include <pwd.h>
#include <stdio.h>
#include <unistd.h>
Retained<CConfigFile> CConfigFile::get_for_app(const String& app_name)
@ -24,17 +24,17 @@ Retained<CConfigFile> CConfigFile::get_for_system(const String& app_name)
CConfigFile::CConfigFile(const String& file_name)
: m_file_name(file_name)
{
reparse();
reparse();
}
CConfigFile::~CConfigFile()
{
sync();
sync();
}
void CConfigFile::reparse()
{
m_groups.clear();
m_groups.clear();
CFile file(m_file_name);
if (!file.open(CIODevice::OpenMode::ReadOnly))
@ -46,38 +46,38 @@ void CConfigFile::reparse()
auto line = file.read_line(BUFSIZ);
auto* cp = (const char*)line.pointer();
while(*cp && (*cp == ' ' || *cp == '\t' || *cp == '\n'))
++cp;
while (*cp && (*cp == ' ' || *cp == '\t' || *cp == '\n'))
++cp;
switch (*cp) {
case '\0':// EOL...
case '#': // Comment, skip entire line.
case ';': // -||-
continue;
case '[': { // Start of new group.
StringBuilder builder;
++cp; // Skip the '['
while (*cp && (*cp != ']'))
builder.append(*(cp++));
current_group = &m_groups.ensure(builder.to_string());
break;
}
default: { // Start of key{
StringBuilder key_builder;
StringBuilder value_builder;
while (*cp && (*cp != '='))
key_builder.append(*(cp++));
++cp; // Skip the '='
while (*cp && (*cp != '\n'))
value_builder.append(*(cp++));
if (!current_group) {
// We're not in a group yet, create one with the name ""...
current_group = &m_groups.ensure("");
}
current_group->set(key_builder.to_string(), value_builder.to_string());
}
}
}
case '\0': // EOL...
case '#': // Comment, skip entire line.
case ';': // -||-
continue;
case '[': { // Start of new group.
StringBuilder builder;
++cp; // Skip the '['
while (*cp && (*cp != ']'))
builder.append(*(cp++));
current_group = &m_groups.ensure(builder.to_string());
break;
}
default: { // Start of key{
StringBuilder key_builder;
StringBuilder value_builder;
while (*cp && (*cp != '='))
key_builder.append(*(cp++));
++cp; // Skip the '='
while (*cp && (*cp != '\n'))
value_builder.append(*(cp++));
if (!current_group) {
// We're not in a group yet, create one with the name ""...
current_group = &m_groups.ensure("");
}
current_group->set(key_builder.to_string(), value_builder.to_string());
}
}
}
}
String CConfigFile::read_entry(const String& group, const String& key, const String& default_value) const
@ -91,7 +91,7 @@ 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 CConfigFile::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);
@ -105,7 +105,7 @@ int CConfigFile::read_num_entry(const String& group, const String &key, int defa
return value;
}
Color CConfigFile::read_color_entry(const String& group, const String &key, Color default_value) const
Color CConfigFile::read_color_entry(const String& group, const String& key, Color default_value) const
{
if (!has_key(group, key)) {
const_cast<CConfigFile&>(*this).write_color_entry(group, key, default_value);
@ -116,26 +116,26 @@ Color CConfigFile::read_color_entry(const String& group, const String &key, Colo
if (shades.size() < 3)
return default_value;
bool ok1 = true,
ok2 = true,
ok3 = true,
ok4 = true;
ok2 = true,
ok3 = true,
ok4 = true;
Color value;
if (shades.size() == 3) {
value = Color(shades[0].to_uint(ok1),
shades[1].to_uint(ok2),
shades[2].to_uint(ok3));
shades[1].to_uint(ok2),
shades[2].to_uint(ok3));
} else {
value = Color(shades[0].to_uint(ok1),
shades[1].to_uint(ok2),
shades[2].to_uint(ok3),
shades[3].to_uint(ok4));
shades[1].to_uint(ok2),
shades[2].to_uint(ok3),
shades[3].to_uint(ok4));
}
if (!(ok1 && ok2 && ok3 && ok4))
return default_value;
return value;
}
bool CConfigFile::read_bool_entry(const String& group, const String &key, bool default_value) const
bool CConfigFile::read_bool_entry(const String& group, const String& key, bool default_value) const
{
return read_entry(group, key, default_value ? "1" : "0") == "1";
}
@ -143,7 +143,7 @@ bool CConfigFile::read_bool_entry(const String& group, const String &key, bool d
void CConfigFile::write_entry(const String& group, const String& key, const String& value)
{
m_groups.ensure(group).ensure(key) = value;
m_dirty = true;
m_dirty = true;
}
void CConfigFile::write_num_entry(const String& group, const String& key, int value)
@ -152,32 +152,29 @@ void CConfigFile::write_num_entry(const String& group, const String& key, int va
}
void CConfigFile::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()));
write_entry(group, key, String::format("%d,%d,%d,%d", value.red(), value.green(), value.blue(), value.alpha()));
}
bool CConfigFile::sync()
{
if (!m_dirty)
return true;
return true;
FILE *fp = fopen(m_file_name.characters(), "wb");
FILE* fp = fopen(m_file_name.characters(), "wb");
if (!fp)
return false;
return false;
for (auto& it : m_groups) {
fprintf(fp, "[%s]\n", it.key.characters());
for (auto& jt : it.value)
fprintf(fp, "%s=%s\n", jt.key.characters(), jt.value.characters());
fprintf(fp, "\n");
}
}
fclose(fp);
m_dirty = false;
return true;
m_dirty = false;
return true;
}
void CConfigFile::dump() const
@ -187,7 +184,7 @@ void CConfigFile::dump() const
for (auto& jt : it.value)
printf("%s=%s\n", jt.key.characters(), jt.value.characters());
printf("\n");
}
}
}
Vector<String> CConfigFile::groups() const
@ -199,7 +196,7 @@ Vector<String> CConfigFile::keys(const String& group) const
{
auto it = m_groups.find(group);
if (it == m_groups.end())
return { };
return {};
return it->value.keys();
}
@ -207,7 +204,7 @@ bool CConfigFile::has_key(const String& group, const String& key) const
{
auto it = m_groups.find(group);
if (it == m_groups.end())
return { };
return {};
return it->value.contains(key);
}
@ -219,7 +216,7 @@ bool CConfigFile::has_group(const String& group) const
void CConfigFile::remove_group(const String& group)
{
m_groups.remove(group);
m_dirty = true;
m_dirty = true;
}
void CConfigFile::remove_entry(const String& group, const String& key)
@ -228,5 +225,5 @@ void CConfigFile::remove_entry(const String& group, const String& key)
if (it == m_groups.end())
return;
it->value.remove(key);
m_dirty = true;
m_dirty = true;
}

View file

@ -1,11 +1,11 @@
#pragma once
#include <SharedGraphics/Color.h>
#include <AK/Vector.h>
#include <AK/HashMap.h>
#include <AK/AKString.h>
#include <AK/Retainable.h>
#include <AK/HashMap.h>
#include <AK/RetainPtr.h>
#include <AK/Retainable.h>
#include <AK/Vector.h>
#include <SharedGraphics/Color.h>
class CConfigFile : public Retainable<CConfigFile> {
public:
@ -22,18 +22,18 @@ public:
String read_entry(const String& group, const String& key, const String& default_vaule = String()) const;
int read_num_entry(const String& group, const String& key, int default_value = 0) const;
bool read_bool_entry(const String& group, const String& key, bool default_value = false) const;
Color read_color_entry(const String& group, const String &key, Color default_value) const;
Color read_color_entry(const String& group, const String& key, Color default_value) const;
void write_entry(const String& group, const String& key, const String &value);
void write_entry(const String& group, const String& key, const String& value);
void write_num_entry(const String& group, const String& key, int value);
void write_bool_entry(const String& group, const String& key, bool value);
void write_color_entry(const String& group, const String& key, Color value);
void dump() const;
void dump() const;
bool is_dirty() const { return m_dirty; }
bool sync();
bool sync();
void remove_group(const String& group);
void remove_entry(const String& group, const String& key);

View file

@ -65,4 +65,3 @@ String CDirIterator::next_path()
m_next = String();
return tmp;
}

View file

@ -1,11 +1,12 @@
#pragma once
#include <dirent.h>
#include <AK/AKString.h>
#include <dirent.h>
class CDirIterator {
public:
enum Flags {
enum Flags
{
NoFlags = 0x0,
SkipDots = 0x1,
};
@ -27,4 +28,3 @@ private:
bool advance_next();
};

View file

@ -1,6 +1,6 @@
#include <LibCore/CElapsedTimer.h>
#include <AK/Assertions.h>
#include <AK/Time.h>
#include <LibCore/CElapsedTimer.h>
#include <sys/time.h>
void CElapsedTimer::start()

View file

@ -4,7 +4,7 @@
class CElapsedTimer {
public:
CElapsedTimer() { }
CElapsedTimer() {}
bool is_valid() const { return m_valid; }
void start();
@ -12,5 +12,7 @@ public:
private:
bool m_valid { false };
struct timeval m_start_time { 0, 0 };
struct timeval m_start_time {
0, 0
};
};

View file

@ -1,15 +1,16 @@
#pragma once
#include <AK/AKString.h>
#include <AK/Function.h>
#include <AK/Types.h>
#include <AK/WeakPtr.h>
#include <AK/Function.h>
class CObject;
class CEvent {
public:
enum Type {
enum Type
{
Invalid = 0,
Quit,
Timer,
@ -19,9 +20,12 @@ public:
ChildRemoved,
};
CEvent() { }
explicit CEvent(unsigned type) : m_type(type) { }
virtual ~CEvent() { }
CEvent() {}
explicit CEvent(unsigned type)
: m_type(type)
{
}
virtual ~CEvent() {}
unsigned type() const { return m_type; }
@ -31,6 +35,7 @@ private:
class CDeferredInvocationEvent : public CEvent {
friend class CEventLoop;
public:
CDeferredInvocationEvent(Function<void(CObject&)> invokee)
: CEvent(CEvent::Type::DeferredInvoke)
@ -45,10 +50,11 @@ private:
class CTimerEvent final : public CEvent {
public:
explicit CTimerEvent(int timer_id)
: CEvent(CEvent::Timer), m_timer_id(timer_id)
: CEvent(CEvent::Timer)
, m_timer_id(timer_id)
{
}
~CTimerEvent() { }
~CTimerEvent() {}
int timer_id() const { return m_timer_id; }

View file

@ -1,20 +1,19 @@
#include <LibCore/CObject.h>
#include <LibCore/CEventLoop.h>
#include <LibCore/CEvent.h>
#include <LibCore/CLock.h>
#include <LibCore/CNotifier.h>
#include <LibC/unistd.h>
#include <LibC/stdio.h>
#include <AK/Time.h>
#include <LibC/errno.h>
#include <LibC/fcntl.h>
#include <LibC/stdio.h>
#include <LibC/stdlib.h>
#include <LibC/string.h>
#include <LibC/time.h>
#include <LibC/sys/select.h>
#include <LibC/sys/socket.h>
#include <LibC/sys/time.h>
#include <LibC/errno.h>
#include <LibC/string.h>
#include <LibC/stdlib.h>
#include <AK/Time.h>
#include <LibC/time.h>
#include <LibC/unistd.h>
#include <LibCore/CEvent.h>
#include <LibCore/CEventLoop.h>
#include <LibCore/CLock.h>
#include <LibCore/CNotifier.h>
#include <LibCore/CObject.h>
//#define CEVENTLOOP_DEBUG
//#define DEFERRED_INVOKE_DEBUG
@ -66,7 +65,8 @@ void CEventLoop::quit(int code)
struct CEventLoopPusher {
public:
CEventLoopPusher(CEventLoop& event_loop) : m_event_loop(event_loop)
CEventLoopPusher(CEventLoop& event_loop)
: m_event_loop(event_loop)
{
if (&m_event_loop != s_main_event_loop) {
m_event_loop.take_pending_events_from(CEventLoop::current());
@ -80,6 +80,7 @@ public:
CEventLoop::current().take_pending_events_from(m_event_loop);
}
}
private:
CEventLoop& m_event_loop;
};
@ -159,7 +160,7 @@ void CEventLoop::wait_for_event(WaitMode mode)
FD_ZERO(&wfds);
int max_fd = 0;
auto add_fd_to_set = [&max_fd] (int fd, fd_set& set){
auto add_fd_to_set = [&max_fd](int fd, fd_set& set) {
FD_SET(fd, &set);
if (fd > max_fd)
max_fd = fd;
@ -271,8 +272,8 @@ int CEventLoop::register_timer(CObject& object, int milliseconds, bool should_re
gettimeofday(&now, nullptr);
timer->reload(now);
timer->should_reload = should_reload;
int timer_id = ++s_next_timer_id; // FIXME: This will eventually wrap around.
ASSERT(timer_id); // FIXME: Aforementioned wraparound.
int timer_id = ++s_next_timer_id; // FIXME: This will eventually wrap around.
ASSERT(timer_id); // FIXME: Aforementioned wraparound.
timer->timer_id = timer_id;
s_timers->set(timer->timer_id, move(timer));
return timer_id;

View file

@ -21,7 +21,8 @@ public:
int exec();
enum class WaitMode {
enum class WaitMode
{
WaitForEvents,
PollForEvents,
};
@ -52,8 +53,8 @@ public:
protected:
virtual void add_file_descriptors_for_select(fd_set&, int& max_fd) { UNUSED_PARAM(max_fd); }
virtual void process_file_descriptors_after_select(const fd_set&) { }
virtual void do_processing() { }
virtual void process_file_descriptors_after_select(const fd_set&) {}
virtual void do_processing() {}
private:
void wait_for_event(WaitMode);

View file

@ -1,7 +1,7 @@
#include <LibCore/CFile.h>
#include <unistd.h>
#include <fcntl.h>
#include <stdio.h>
#include <unistd.h>
CFile::CFile(const String& filename)
: m_filename(filename)

View file

@ -1,11 +1,11 @@
#pragma once
#include <LibCore/CIODevice.h>
#include <AK/AKString.h>
#include <LibCore/CIODevice.h>
class CFile final : public CIODevice {
public:
CFile() { }
CFile() {}
explicit CFile(const String&);
virtual ~CFile() override;
@ -14,7 +14,11 @@ public:
virtual bool open(CIODevice::OpenMode) override;
enum class ShouldCloseFileDescriptor { No = 0, Yes };
enum class ShouldCloseFileDescriptor
{
No = 0,
Yes
};
bool open(int fd, CIODevice::OpenMode, ShouldCloseFileDescriptor);
virtual const char* class_name() const override { return "CFile"; }

View file

@ -22,7 +22,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(CNetworkJob::Error::TransmissionFailed); });
Vector<byte> buffer;
while (m_socket->is_connected()) {
@ -33,18 +33,18 @@ void CHttpJob::on_socket_connected()
auto line = m_socket->read_line(PAGE_SIZE);
if (line.is_null()) {
printf("Expected HTTP status\n");
return deferred_invoke([this](auto&){ did_fail(CNetworkJob::Error::TransmissionFailed); });
return deferred_invoke([this](auto&) { did_fail(CNetworkJob::Error::TransmissionFailed); });
}
auto parts = String::copy(line, Chomp).split(' ');
if (parts.size() < 3) {
printf("Expected 3-part HTTP status, got '%s'\n", line.pointer());
return deferred_invoke([this](auto&){ did_fail(CNetworkJob::Error::ProtocolFailed); });
return deferred_invoke([this](auto&) { did_fail(CNetworkJob::Error::ProtocolFailed); });
}
bool ok;
m_code = parts[1].to_uint(ok);
if (!ok) {
printf("Expected numeric HTTP status\n");
return deferred_invoke([this](auto&){ did_fail(CNetworkJob::Error::ProtocolFailed); });
return deferred_invoke([this](auto&) { did_fail(CNetworkJob::Error::ProtocolFailed); });
}
m_state = State::InHeaders;
continue;
@ -65,12 +65,12 @@ void CHttpJob::on_socket_connected()
auto parts = chomped_line.split(':');
if (parts.is_empty()) {
printf("Expected HTTP header with key/value\n");
return deferred_invoke([this](auto&){ did_fail(CNetworkJob::Error::ProtocolFailed); });
return deferred_invoke([this](auto&) { did_fail(CNetworkJob::Error::ProtocolFailed); });
}
auto name = parts[0];
if (chomped_line.length() < name.length() + 2) {
printf("Malformed HTTP header: '%s' (%d)\n", chomped_line.characters(), chomped_line.length());
return deferred_invoke([this](auto&){ did_fail(CNetworkJob::Error::ProtocolFailed); });
return deferred_invoke([this](auto&) { did_fail(CNetworkJob::Error::ProtocolFailed); });
}
auto value = chomped_line.substring(name.length() + 2, chomped_line.length() - name.length() - 2);
m_headers.set(name, value);
@ -84,13 +84,13 @@ void CHttpJob::on_socket_connected()
m_state = State::Finished;
break;
}
return deferred_invoke([this](auto&){ did_fail(CNetworkJob::Error::ProtocolFailed); });
return deferred_invoke([this](auto&) { did_fail(CNetworkJob::Error::ProtocolFailed); });
}
buffer.append(payload.pointer(), payload.size());
}
auto response = CHttpResponse::create(m_code, move(m_headers), ByteBuffer::copy(buffer.data(), buffer.size()));
deferred_invoke([this, response] (auto&) {
deferred_invoke([this, response](auto&) {
did_finish(move(response));
});
}

View file

@ -1,8 +1,8 @@
#pragma once
#include <LibCore/CNetworkJob.h>
#include <LibCore/CHttpRequest.h>
#include <AK/HashMap.h>
#include <LibCore/CHttpRequest.h>
#include <LibCore/CNetworkJob.h>
class CTCPSocket;
@ -18,7 +18,8 @@ public:
private:
void on_socket_connected();
enum class State {
enum class State
{
InStatus,
InHeaders,
InBody,

View file

@ -1,6 +1,6 @@
#include <LibCore/CHttpRequest.h>
#include <LibCore/CHttpJob.h>
#include <AK/StringBuilder.h>
#include <LibCore/CHttpJob.h>
#include <LibCore/CHttpRequest.h>
CHttpRequest::CHttpRequest()
{

View file

@ -6,7 +6,13 @@ class CNetworkJob;
class CHttpRequest {
public:
enum Method { Invalid, HEAD, GET, POST };
enum Method
{
Invalid,
HEAD,
GET,
POST
};
CHttpRequest();
~CHttpRequest();

View file

@ -1,8 +1,8 @@
#pragma once
#include <LibCore/CNetworkResponse.h>
#include <AK/AKString.h>
#include <AK/HashMap.h>
#include <LibCore/CNetworkResponse.h>
class CHttpResponse : public CNetworkResponse {
public:

View file

@ -1,18 +1,19 @@
#pragma once
#include <LibCore/CObject.h>
#include <AK/ByteBuffer.h>
#include <LibCore/CObject.h>
class CIODevice : public CObject {
public:
enum OpenMode {
NotOpen = 0,
ReadOnly = 1,
WriteOnly = 2,
ReadWrite = 3,
Append = 4,
Truncate = 8,
MustBeNew = 16,
enum OpenMode
{
NotOpen = 0,
ReadOnly = 1,
WriteOnly = 2,
ReadWrite = 3,
Append = 4,
Truncate = 8,
MustBeNew = 16,
};
virtual ~CIODevice() override;
@ -37,7 +38,8 @@ public:
bool can_read() const;
enum class SeekMode {
enum class SeekMode
{
SetPosition,
FromCurrentPosition,
FromEndPosition,

View file

@ -4,23 +4,24 @@
#include <AK/Types.h>
#include <unistd.h>
#define memory_barrier() asm volatile ("" ::: "memory")
#define memory_barrier() asm volatile("" :: \
: "memory")
static inline dword CAS(volatile dword* mem, dword newval, dword oldval)
{
dword ret;
asm volatile(
"cmpxchgl %2, %1"
:"=a"(ret), "+m"(*mem)
:"r"(newval), "0"(oldval)
:"cc", "memory");
: "=a"(ret), "+m"(*mem)
: "r"(newval), "0"(oldval)
: "cc", "memory");
return ret;
}
class CLock {
public:
CLock() { }
~CLock() { }
CLock() {}
~CLock() {}
void lock();
void unlock();
@ -33,7 +34,11 @@ private:
class CLocker {
public:
[[gnu::always_inline]] inline explicit CLocker(CLock& l) : m_lock(l) { lock(); }
[[gnu::always_inline]] inline explicit CLocker(CLock& l)
: m_lock(l)
{
lock();
}
[[gnu::always_inline]] inline ~CLocker() { unlock(); }
[[gnu::always_inline]] inline void unlock() { m_lock.unlock(); }
[[gnu::always_inline]] inline void lock() { m_lock.lock(); }
@ -86,8 +91,11 @@ inline void CLock::unlock()
template<typename T>
class CLockable {
public:
CLockable() { }
CLockable(T&& resource) : m_resource(move(resource)) { }
CLockable() {}
CLockable(T&& resource)
: m_resource(move(resource))
{
}
CLock& lock() { return m_lock; }
T& resource() { return m_resource; }
@ -101,4 +109,3 @@ private:
T m_resource;
CLock m_lock;
};

View file

@ -1,13 +1,14 @@
#pragma once
#include <LibCore/CObject.h>
#include <AK/Function.h>
#include <LibCore/CObject.h>
class CNetworkResponse;
class CNetworkJob : public CObject {
public:
enum class Error {
enum class Error
{
None,
ConnectionFailed,
TransmissionFailed,

View file

@ -1,7 +1,7 @@
#pragma once
#include <AK/Retainable.h>
#include <AK/ByteBuffer.h>
#include <AK/Retainable.h>
class CNetworkResponse : public Retainable<CNetworkResponse> {
public:

View file

@ -1,6 +1,6 @@
#include <LibCore/CNotifier.h>
#include <LibCore/CEventLoop.h>
#include <LibCore/CEvent.h>
#include <LibCore/CEventLoop.h>
#include <LibCore/CNotifier.h>
CNotifier::CNotifier(int fd, unsigned event_mask)
: m_fd(fd)
@ -13,4 +13,3 @@ CNotifier::~CNotifier()
{
CEventLoop::unregister_notifier(Badge<CNotifier>(), *this);
}

View file

@ -4,10 +4,11 @@
class CNotifier {
public:
enum Event {
None = 0,
Read = 1,
Write = 2,
enum Event
{
None = 0,
Read = 1,
Write = 2,
Exceptional = 4,
};
CNotifier(int fd, unsigned event_mask);

View file

@ -1,7 +1,7 @@
#include <LibCore/CObject.h>
#include <AK/Assertions.h>
#include <LibCore/CEvent.h>
#include <LibCore/CEventLoop.h>
#include <AK/Assertions.h>
#include <LibCore/CObject.h>
#include <stdio.h>
CObject::CObject(CObject* parent, bool is_widget)
@ -100,7 +100,7 @@ void CObject::dump_tree(int indent)
}
printf("%s{%p}\n", class_name(), this);
for_each_child([&] (auto& child) {
for_each_child([&](auto& child) {
child.dump_tree(indent + 2);
return IterationDecision::Continue;
});

View file

@ -29,7 +29,8 @@ public:
}
}
template<typename T, typename Callback> void for_each_child_of_type(Callback callback);
template<typename T, typename Callback>
void for_each_child_of_type(Callback callback);
CObject* parent() { return m_parent; }
const CObject* parent() const { return m_parent; }
@ -61,7 +62,8 @@ private:
Vector<CObject*> m_children;
};
template<typename T> inline bool is(const CObject&) { return true; }
template<typename T>
inline bool is(const CObject&) { return true; }
template<typename T>
inline T& to(CObject& object)
@ -80,7 +82,7 @@ inline const T& to(const CObject& object)
template<typename T, typename Callback>
inline void CObject::for_each_child_of_type(Callback callback)
{
for_each_child([&] (auto& child) {
for_each_child([&](auto& child) {
if (is<T>(child))
return callback(to<T>(child));
return IterationDecision::Continue;

View file

@ -1,8 +1,8 @@
#include "CProcessStatisticsReader.h"
#include "CFile.h"
#include <stdio.h>
#include <pwd.h>
#include <stdio.h>
CProcessStatisticsReader::CProcessStatisticsReader()
{
@ -64,7 +64,7 @@ void CProcessStatisticsReader::update_map(HashMap<pid_t, CProcessStatistics>& ma
process.username = get_username_from_uid(uid);
process.priority = parts[16];
process.syscalls = parts[17].to_uint(ok);
if (!ok) {
fprintf(stderr, "CProcessHelper : couldn't convert %s to a valid syscalls count value\n", parts[17].characters());

View file

@ -24,6 +24,6 @@ public:
private:
void update_map(HashMap<pid_t, CProcessStatistics>& map);
String get_username_from_uid(const uid_t uid);
HashMap<uid_t, String> m_usernames;
};

View file

@ -1,12 +1,12 @@
#include <LibCore/CSocket.h>
#include <LibCore/CNotifier.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <LibCore/CSocket.h>
#include <arpa/inet.h>
#include <stdlib.h>
#include <stdio.h>
#include <netdb.h>
#include <errno.h>
#include <netdb.h>
#include <netinet/in.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/socket.h>
CSocket::CSocket(Type type, CObject* parent)
: CIODevice(parent)

View file

@ -7,7 +7,12 @@ class CNotifier;
class CSocket : public CIODevice {
public:
enum class Type { Invalid, TCP, UDP };
enum class Type
{
Invalid,
TCP,
UDP
};
virtual ~CSocket() override;
bool connect(const String& hostname, int port);

View file

@ -4,9 +4,14 @@
class CSocketAddress {
public:
enum class Type { Invalid, IPv4, Local };
enum class Type
{
Invalid,
IPv4,
Local
};
CSocketAddress() { }
CSocketAddress() {}
CSocketAddress(const IPv4Address& address)
: m_type(Type::IPv4)
, m_ipv4_address(address)
@ -20,8 +25,10 @@ public:
String to_string() const
{
switch (m_type) {
case Type::IPv4: return m_ipv4_address.to_string();
default: return "[CSocketAddress]";
case Type::IPv4:
return m_ipv4_address.to_string();
default:
return "[CSocketAddress]";
}
}

View file

@ -7,4 +7,3 @@ public:
private:
};

View file

@ -1,7 +1,7 @@
#pragma once
#include <LibCore/CObject.h>
#include <AK/Function.h>
#include <LibCore/CObject.h>
class CTimer final : public CObject {
public:

View file

@ -1,7 +1,7 @@
#include "CUserInfo.h"
#include <pwd.h>
#include <stdlib.h>
#include <unistd.h>
#include <pwd.h>
const char* get_current_user_home_path()
{

View file

@ -1 +1 @@
const char *get_current_user_home_path();
const char* get_current_user_home_path();