1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 03:57:43 +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>
AClientConnection::AClientConnection()
: ConnectionNG(*this, "/tmp/portal/audio")
: IServerConnection(*this, "/tmp/portal/audio")
{
}

View file

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

View file

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

View file

@ -1,6 +1,5 @@
#pragma once
#include <AK/Queue.h>
#include <LibCore/CEvent.h>
#include <LibCore/CEventLoop.h>
#include <LibCore/CIODevice.h>
@ -10,35 +9,28 @@
#include <LibIPC/IEndpoint.h>
#include <LibIPC/IMessage.h>
#include <errno.h>
#include <sched.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 Server {
class Event : public CEvent {
class IEvent : public CEvent {
public:
enum Type {
Invalid = 2000,
Disconnected,
};
Event() {}
explicit Event(Type type)
IEvent() {}
explicit IEvent(Type type)
: CEvent(type)
{
}
};
class DisconnectedEvent : public Event {
class IDisconnectedEvent : public IEvent {
public:
explicit DisconnectedEvent(int client_id)
: Event(Disconnected)
explicit IDisconnectedEvent(int client_id)
: IEvent(Disconnected)
, m_client_id(client_id)
{
}
@ -50,15 +42,15 @@ namespace Server {
};
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 */;
}
template<typename Endpoint>
class ConnectionNG : public CObject {
class IClientConnection : public CObject {
public:
ConnectionNG(Endpoint& endpoint, CLocalSocket& socket, int client_id)
IClientConnection(Endpoint& endpoint, CLocalSocket& socket, int client_id)
: m_endpoint(endpoint)
, m_socket(socket)
, m_client_id(client_id)
@ -67,7 +59,7 @@ namespace Server {
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);
if (nread == 0 || (nread == -1 && errno == EAGAIN)) {
if (bytes.is_empty()) {
CEventLoop::current().post_event(*this, make<DisconnectedEvent>(client_id()));
CEventLoop::current().post_event(*this, make<IDisconnectedEvent>(client_id()));
return;
}
break;
@ -151,8 +143,8 @@ namespace Server {
protected:
void event(CEvent& event) override
{
if (event.type() == Event::Disconnected) {
int client_id = static_cast<const DisconnectedEvent&>(event).client_id();
if (event.type() == IEvent::Disconnected) {
int client_id = static_cast<const IDisconnectedEvent&>(event).client_id();
dbgprintf("Connection: Client disconnected: %d\n", client_id);
die();
return;
@ -167,6 +159,3 @@ namespace Server {
int m_client_id { -1 };
int m_client_pid { -1 };
};
} // Server
} // IPC

View file

@ -6,24 +6,17 @@
#include <LibCore/CNotifier.h>
#include <LibCore/CSyscallUtils.h>
#include <LibIPC/IMessage.h>
#include <sched.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/select.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <sys/uio.h>
#include <unistd.h>
//#define CIPC_DEBUG
namespace IPC {
namespace Client {
template<typename LocalEndpoint, typename PeerEndpoint>
class ConnectionNG : public CObject {
class IServerConnection : public CObject {
public:
ConnectionNG(LocalEndpoint& local_endpoint, const StringView& address)
IServerConnection(LocalEndpoint& local_endpoint, const StringView& address)
: m_local_endpoint(local_endpoint)
, m_connection(CLocalSocket::construct(this))
, m_notifier(CNotifier::construct(m_connection->fd(), CNotifier::Read, this))
@ -156,6 +149,3 @@ namespace Client {
int m_server_pid { -1 };
int m_my_client_id { -1 };
};
} // Client
} // IPC

View file

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

View file

@ -8,7 +8,7 @@ namespace LibProtocol {
class Download;
class Client : public IPC::Client::ConnectionNG<ProtocolClientEndpoint, ProtocolServerEndpoint>
class Client : public IServerConnection<ProtocolClientEndpoint, ProtocolServerEndpoint>
, public ProtocolClientEndpoint {
C_OBJECT(Client)
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)
: ConnectionNG(*this, client_socket, client_id)
: IClientConnection(*this, client_socket, client_id)
, m_mixer(mixer)
{
s_connections.set(client_id, *this);

View file

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

View file

@ -17,6 +17,6 @@ ASEventLoop::ASEventLoop()
}
static int s_next_client_id = 0;
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;
PSClientConnection::PSClientConnection(CLocalSocket& socket, int client_id)
: ConnectionNG(*this, socket, client_id)
: IClientConnection(*this, socket, client_id)
{
s_connections.set(client_id, *this);
}

View file

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

View file

@ -19,7 +19,7 @@ int main(int, char**)
}
static int s_next_client_id = 0;
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();
}

View file

@ -42,7 +42,7 @@ WSClientConnection* WSClientConnection::from_client_id(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)
s_connections = new HashMap<int, NonnullRefPtr<WSClientConnection>>;

View file

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

View file

@ -37,7 +37,7 @@ WSEventLoop::WSEventLoop()
}
static int s_next_client_id = 0;
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);