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

LibCore: Use clang-format on CoreIPC{Client,Server}.

This commit is contained in:
Andreas Kling 2019-07-27 10:50:26 +02:00
parent 82446ea701
commit c289e49ee5
2 changed files with 376 additions and 380 deletions

View file

@ -1,27 +1,26 @@
#pragma once
#include <LibCore/CEventLoop.h>
#include <LibCore/CEvent.h>
#include <LibCore/CLocalSocket.h>
#include <LibCore/CSyscallUtils.h>
#include <LibCore/CNotifier.h>
#include <LibAudio/ASAPI.h>
#include <LibCore/CEvent.h>
#include <LibCore/CEventLoop.h>
#include <LibCore/CLocalSocket.h>
#include <LibCore/CNotifier.h>
#include <LibCore/CSyscallUtils.h>
#include <unistd.h>
#include <stdio.h>
#include <sys/select.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <sys/uio.h>
#include <unistd.h>
//#define CIPC_DEBUG
namespace IPC
{
namespace IPC {
namespace Client {
class Event : public CEvent {
public:
class Event : public CEvent {
public:
enum Type {
Invalid = 2000,
PostProcess,
@ -31,10 +30,10 @@ public:
: CEvent(type)
{
}
};
};
class PostProcessEvent : public Event {
public:
class PostProcessEvent : public Event {
public:
explicit PostProcessEvent(int client_id)
: Event(PostProcess)
, m_client_id(client_id)
@ -43,14 +42,14 @@ public:
int client_id() const { return m_client_id; }
private:
private:
int m_client_id { 0 };
};
};
template <typename ServerMessage, typename ClientMessage>
class Connection : public CObject {
template<typename ServerMessage, typename ClientMessage>
class Connection : public CObject {
C_OBJECT(Connection)
public:
public:
Connection(const StringView& address)
: m_notifier(CNotifier(m_connection.fd(), CNotifier::Read))
{
@ -76,7 +75,6 @@ public:
virtual void handshake() = 0;
virtual void event(CEvent& event) override
{
if (event.type() == Event::PostProcess) {
@ -91,7 +89,7 @@ public:
void set_my_client_id(int id) { m_my_client_id = id; }
int my_client_id() const { return m_my_client_id; }
template <typename MessageType>
template<typename MessageType>
bool wait_for_specific_event(MessageType type, ServerMessage& event)
{
// Double check we don't already have the event waiting for us.
@ -157,7 +155,7 @@ public:
return true;
}
template <typename MessageType>
template<typename MessageType>
ServerMessage sync_request(const ClientMessage& request, MessageType response_type)
{
bool success = post_message_to_server(request);
@ -169,7 +167,7 @@ public:
return response;
}
protected:
protected:
struct IncomingMessageBundle {
ServerMessage message;
ByteBuffer extra_data;
@ -177,11 +175,12 @@ protected:
virtual void postprocess_bundles(Vector<IncomingMessageBundle>& new_bundles)
{
dbg() << "Client::Connection: " << " warning: discarding " << new_bundles.size() << " unprocessed bundles; this may not be what you want";
dbg() << "Client::Connection: "
<< " warning: discarding " << new_bundles.size() << " unprocessed bundles; this may not be what you want";
new_bundles.clear();
}
private:
private:
bool drain_messages_from_server()
{
for (;;) {
@ -223,8 +222,7 @@ private:
Vector<IncomingMessageBundle> m_unprocessed_bundles;
int m_server_pid;
int m_my_client_id;
};
};
} // Client
} // IPC

View file

@ -1,26 +1,25 @@
#pragma once
#include <LibCore/CObject.h>
#include <LibCore/CEvent.h>
#include <LibCore/CEventLoop.h>
#include <LibCore/CIODevice.h>
#include <LibCore/CNotifier.h>
#include <LibCore/CObject.h>
#include <errno.h>
#include <unistd.h>
#include <sys/uio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <stdio.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <sys/uio.h>
#include <unistd.h>
//#define CIPC_DEBUG
namespace IPC
{
namespace IPC {
namespace Server {
class Event : public CEvent {
public:
class Event : public CEvent {
public:
enum Type {
Invalid = 2000,
Disconnected,
@ -30,10 +29,10 @@ public:
: CEvent(type)
{
}
};
};
class DisconnectedEvent : public Event {
public:
class DisconnectedEvent : public Event {
public:
explicit DisconnectedEvent(int client_id)
: Event(Disconnected)
, m_client_id(client_id)
@ -42,22 +41,22 @@ public:
int client_id() const { return m_client_id; }
private:
private:
int m_client_id { 0 };
};
};
template <typename T, class... Args>
T* new_connection_for_client(Args&& ... args)
{
template<typename T, class... Args>
T* new_connection_for_client(Args&&... args)
{
auto conn = new T(AK::forward<Args>(args)...) /* arghs */;
conn->send_greeting();
return conn;
};
};
template <typename ServerMessage, typename ClientMessage>
class Connection : public CObject {
template<typename ServerMessage, typename ClientMessage>
class Connection : public CObject {
C_OBJECT(Connection)
public:
public:
Connection(int fd, int client_id)
: m_socket(fd)
, m_notifier(CNotifier(fd, CNotifier::Read))
@ -175,7 +174,7 @@ public:
// ### having this public is sad
virtual void send_greeting() = 0;
protected:
protected:
void event(CEvent& event)
{
if (event.type() == Event::Disconnected) {
@ -190,7 +189,7 @@ protected:
virtual bool handle_message(const ClientMessage&, const ByteBuffer&& = {}) = 0;
private:
private:
// TODO: A way to create some kind of CIODevice with an open FD would be nice.
class COpenedSocket : public CIODevice {
C_OBJECT(COpenedSocket)
@ -214,8 +213,7 @@ private:
CNotifier m_notifier;
int m_client_id;
int m_pid;
};
};
} // Server
} // IPC