1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 02:57:36 +00:00

LibIPC: Rename base classes to IClientConnection and IServerConnection

This matches what we're already calling the server-side subclasses
better, though we'll probably want to find some better names for the
client-side classes eventually.
This commit is contained in:
Andreas Kling 2019-12-02 09:58:25 +01:00
parent 5d4ee0f58a
commit 4a37bec27c
16 changed files with 254 additions and 275 deletions

View file

@ -3,7 +3,7 @@
#include <SharedBuffer.h> #include <SharedBuffer.h>
AClientConnection::AClientConnection() AClientConnection::AClientConnection()
: ConnectionNG(*this, "/tmp/portal/audio") : IServerConnection(*this, "/tmp/portal/audio")
{ {
} }

View file

@ -6,7 +6,7 @@
class ABuffer; class ABuffer;
class AClientConnection : public IPC::Client::ConnectionNG<AudioClientEndpoint, AudioServerEndpoint> class AClientConnection : public IServerConnection<AudioClientEndpoint, AudioServerEndpoint>
, public AudioClientEndpoint { , public AudioClientEndpoint {
C_OBJECT(AClientConnection) C_OBJECT(AClientConnection)
public: public:

View file

@ -5,12 +5,12 @@
#include <WindowServer/WindowServerEndpoint.h> #include <WindowServer/WindowServerEndpoint.h>
class GWindowServerConnection class GWindowServerConnection
: public IPC::Client::ConnectionNG<WindowClientEndpoint, WindowServerEndpoint> : public IServerConnection<WindowClientEndpoint, WindowServerEndpoint>
, public WindowClientEndpoint { , public WindowClientEndpoint {
C_OBJECT(GWindowServerConnection) C_OBJECT(GWindowServerConnection)
public: public:
GWindowServerConnection() GWindowServerConnection()
: ConnectionNG(*this, "/tmp/portal/window") : IServerConnection(*this, "/tmp/portal/window")
{ {
handshake(); handshake();
} }

View file

@ -1,6 +1,5 @@
#pragma once #pragma once
#include <AK/Queue.h>
#include <LibCore/CEvent.h> #include <LibCore/CEvent.h>
#include <LibCore/CEventLoop.h> #include <LibCore/CEventLoop.h>
#include <LibCore/CIODevice.h> #include <LibCore/CIODevice.h>
@ -10,55 +9,48 @@
#include <LibIPC/IEndpoint.h> #include <LibIPC/IEndpoint.h>
#include <LibIPC/IMessage.h> #include <LibIPC/IMessage.h>
#include <errno.h> #include <errno.h>
#include <sched.h>
#include <stdio.h> #include <stdio.h>
#include <sys/socket.h> #include <sys/socket.h>
#include <sys/types.h> #include <sys/types.h>
#include <sys/uio.h>
#include <unistd.h> #include <unistd.h>
//#define CIPC_DEBUG class IEvent : public CEvent {
public:
namespace IPC {
namespace Server {
class Event : public CEvent {
public:
enum Type { enum Type {
Invalid = 2000, Invalid = 2000,
Disconnected, Disconnected,
}; };
Event() {} IEvent() {}
explicit Event(Type type) explicit IEvent(Type type)
: CEvent(type) : CEvent(type)
{ {
} }
}; };
class DisconnectedEvent : public Event { class IDisconnectedEvent : public IEvent {
public: public:
explicit DisconnectedEvent(int client_id) explicit IDisconnectedEvent(int client_id)
: Event(Disconnected) : IEvent(Disconnected)
, m_client_id(client_id) , m_client_id(client_id)
{ {
} }
int client_id() const { return m_client_id; } int client_id() const { return m_client_id; }
private: private:
int m_client_id { 0 }; int m_client_id { 0 };
}; };
template<typename T, class... Args> template<typename T, class... Args>
NonnullRefPtr<T> new_connection_ng_for_client(Args&&... args) NonnullRefPtr<T> new_client_connection(Args&&... args)
{ {
return T::construct(forward<Args>(args)...) /* arghs */; return T::construct(forward<Args>(args)...) /* arghs */;
} }
template<typename Endpoint> template<typename Endpoint>
class ConnectionNG : public CObject { class IClientConnection : public CObject {
public: public:
ConnectionNG(Endpoint& endpoint, CLocalSocket& socket, int client_id) IClientConnection(Endpoint& endpoint, CLocalSocket& socket, int client_id)
: m_endpoint(endpoint) : m_endpoint(endpoint)
, m_socket(socket) , m_socket(socket)
, m_client_id(client_id) , m_client_id(client_id)
@ -67,7 +59,7 @@ namespace Server {
m_socket->on_ready_to_read = [this] { drain_messages_from_client(); }; m_socket->on_ready_to_read = [this] { drain_messages_from_client(); };
} }
virtual ~ConnectionNG() override virtual ~IClientConnection() override
{ {
} }
@ -103,7 +95,7 @@ namespace Server {
ssize_t nread = recv(m_socket->fd(), buffer, sizeof(buffer), MSG_DONTWAIT); ssize_t nread = recv(m_socket->fd(), buffer, sizeof(buffer), MSG_DONTWAIT);
if (nread == 0 || (nread == -1 && errno == EAGAIN)) { if (nread == 0 || (nread == -1 && errno == EAGAIN)) {
if (bytes.is_empty()) { if (bytes.is_empty()) {
CEventLoop::current().post_event(*this, make<DisconnectedEvent>(client_id())); CEventLoop::current().post_event(*this, make<IDisconnectedEvent>(client_id()));
return; return;
} }
break; break;
@ -148,11 +140,11 @@ namespace Server {
virtual void die() = 0; virtual void die() = 0;
protected: protected:
void event(CEvent& event) override void event(CEvent& event) override
{ {
if (event.type() == Event::Disconnected) { if (event.type() == IEvent::Disconnected) {
int client_id = static_cast<const DisconnectedEvent&>(event).client_id(); int client_id = static_cast<const IDisconnectedEvent&>(event).client_id();
dbgprintf("Connection: Client disconnected: %d\n", client_id); dbgprintf("Connection: Client disconnected: %d\n", client_id);
die(); die();
return; return;
@ -161,12 +153,9 @@ namespace Server {
CObject::event(event); CObject::event(event);
} }
private: private:
Endpoint& m_endpoint; Endpoint& m_endpoint;
RefPtr<CLocalSocket> m_socket; RefPtr<CLocalSocket> m_socket;
int m_client_id { -1 }; int m_client_id { -1 };
int m_client_pid { -1 }; int m_client_pid { -1 };
}; };
} // Server
} // IPC

View file

@ -6,24 +6,17 @@
#include <LibCore/CNotifier.h> #include <LibCore/CNotifier.h>
#include <LibCore/CSyscallUtils.h> #include <LibCore/CSyscallUtils.h>
#include <LibIPC/IMessage.h> #include <LibIPC/IMessage.h>
#include <sched.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <sys/select.h> #include <sys/select.h>
#include <sys/socket.h> #include <sys/socket.h>
#include <sys/types.h> #include <sys/types.h>
#include <sys/uio.h>
#include <unistd.h> #include <unistd.h>
//#define CIPC_DEBUG template<typename LocalEndpoint, typename PeerEndpoint>
class IServerConnection : public CObject {
namespace IPC { public:
namespace Client { IServerConnection(LocalEndpoint& local_endpoint, const StringView& address)
template<typename LocalEndpoint, typename PeerEndpoint>
class ConnectionNG : public CObject {
public:
ConnectionNG(LocalEndpoint& local_endpoint, const StringView& address)
: m_local_endpoint(local_endpoint) : m_local_endpoint(local_endpoint)
, m_connection(CLocalSocket::construct(this)) , m_connection(CLocalSocket::construct(this))
, m_notifier(CNotifier::construct(m_connection->fd(), CNotifier::Read, this)) , m_notifier(CNotifier::construct(m_connection->fd(), CNotifier::Read, this))
@ -111,7 +104,7 @@ namespace Client {
return response; return response;
} }
private: private:
bool drain_messages_from_server() bool drain_messages_from_server()
{ {
Vector<u8> bytes; Vector<u8> bytes;
@ -155,7 +148,4 @@ namespace Client {
Vector<OwnPtr<IMessage>> m_unprocessed_messages; Vector<OwnPtr<IMessage>> m_unprocessed_messages;
int m_server_pid { -1 }; int m_server_pid { -1 };
int m_my_client_id { -1 }; int m_my_client_id { -1 };
}; };
} // Client
} // IPC

View file

@ -5,7 +5,7 @@
namespace LibProtocol { namespace LibProtocol {
Client::Client() Client::Client()
: ConnectionNG(*this, "/tmp/portal/protocol") : IServerConnection(*this, "/tmp/portal/protocol")
{ {
handshake(); handshake();
} }

View file

@ -8,7 +8,7 @@ namespace LibProtocol {
class Download; class Download;
class Client : public IPC::Client::ConnectionNG<ProtocolClientEndpoint, ProtocolServerEndpoint> class Client : public IServerConnection<ProtocolClientEndpoint, ProtocolServerEndpoint>
, public ProtocolClientEndpoint { , public ProtocolClientEndpoint {
C_OBJECT(Client) C_OBJECT(Client)
public: public:

View file

@ -23,7 +23,7 @@ void ASClientConnection::for_each(Function<void(ASClientConnection&)> callback)
} }
ASClientConnection::ASClientConnection(CLocalSocket& client_socket, int client_id, ASMixer& mixer) ASClientConnection::ASClientConnection(CLocalSocket& client_socket, int client_id, ASMixer& mixer)
: ConnectionNG(*this, client_socket, client_id) : IClientConnection(*this, client_socket, client_id)
, m_mixer(mixer) , m_mixer(mixer)
{ {
s_connections.set(client_id, *this); s_connections.set(client_id, *this);

View file

@ -7,7 +7,7 @@ class ABuffer;
class ASBufferQueue; class ASBufferQueue;
class ASMixer; class ASMixer;
class ASClientConnection final : public IPC::Server::ConnectionNG<AudioServerEndpoint> class ASClientConnection final : public IClientConnection<AudioServerEndpoint>
, public AudioServerEndpoint { , public AudioServerEndpoint {
C_OBJECT(ASClientConnection) C_OBJECT(ASClientConnection)
public: public:

View file

@ -17,6 +17,6 @@ ASEventLoop::ASEventLoop()
} }
static int s_next_client_id = 0; static int s_next_client_id = 0;
int client_id = ++s_next_client_id; int client_id = ++s_next_client_id;
IPC::Server::new_connection_ng_for_client<ASClientConnection>(*client_socket, client_id, m_mixer); new_client_connection<ASClientConnection>(*client_socket, client_id, m_mixer);
}; };
} }

View file

@ -7,7 +7,7 @@
static HashMap<int, RefPtr<PSClientConnection>> s_connections; static HashMap<int, RefPtr<PSClientConnection>> s_connections;
PSClientConnection::PSClientConnection(CLocalSocket& socket, int client_id) PSClientConnection::PSClientConnection(CLocalSocket& socket, int client_id)
: ConnectionNG(*this, socket, client_id) : IClientConnection(*this, socket, client_id)
{ {
s_connections.set(client_id, *this); s_connections.set(client_id, *this);
} }

View file

@ -7,7 +7,7 @@
class Download; class Download;
class SharedBuffer; class SharedBuffer;
class PSClientConnection final : public IPC::Server::ConnectionNG<ProtocolServerEndpoint> class PSClientConnection final : public IClientConnection<ProtocolServerEndpoint>
, public ProtocolServerEndpoint { , public ProtocolServerEndpoint {
C_OBJECT(PSClientConnection) C_OBJECT(PSClientConnection)
public: public:

View file

@ -19,7 +19,7 @@ int main(int, char**)
} }
static int s_next_client_id = 0; static int s_next_client_id = 0;
int client_id = ++s_next_client_id; int client_id = ++s_next_client_id;
IPC::Server::new_connection_ng_for_client<PSClientConnection>(*client_socket, client_id); new_client_connection<PSClientConnection>(*client_socket, client_id);
}; };
return event_loop.exec(); return event_loop.exec();
} }

View file

@ -42,7 +42,7 @@ WSClientConnection* WSClientConnection::from_client_id(int client_id)
} }
WSClientConnection::WSClientConnection(CLocalSocket& client_socket, int client_id) WSClientConnection::WSClientConnection(CLocalSocket& client_socket, int client_id)
: ConnectionNG(*this, client_socket, client_id) : IClientConnection(*this, client_socket, client_id)
{ {
if (!s_connections) if (!s_connections)
s_connections = new HashMap<int, NonnullRefPtr<WSClientConnection>>; s_connections = new HashMap<int, NonnullRefPtr<WSClientConnection>>;

View file

@ -15,7 +15,7 @@ class WSMenu;
class WSMenuBar; class WSMenuBar;
class WSClientConnection final class WSClientConnection final
: public IPC::Server::ConnectionNG<WindowServerEndpoint> : public IClientConnection<WindowServerEndpoint>
, public WindowServerEndpoint { , public WindowServerEndpoint {
C_OBJECT(WSClientConnection) C_OBJECT(WSClientConnection)
public: public:

View file

@ -37,7 +37,7 @@ WSEventLoop::WSEventLoop()
} }
static int s_next_client_id = 0; static int s_next_client_id = 0;
int client_id = ++s_next_client_id; int client_id = ++s_next_client_id;
IPC::Server::new_connection_ng_for_client<WSClientConnection>(*client_socket, client_id); new_client_connection<WSClientConnection>(*client_socket, client_id);
}; };
ASSERT(m_keyboard_fd >= 0); ASSERT(m_keyboard_fd >= 0);