mirror of
https://github.com/RGBCube/serenity
synced 2025-07-28 09:17:45 +00:00
Userland: Split IPC endpoints into proxies and stubs
This enables support for automatically generating client methods. With this added the user gets code completion support for all IPC methods which are available on a connection object.
This commit is contained in:
parent
065040872f
commit
78803ce384
20 changed files with 175 additions and 53 deletions
|
@ -1,8 +1,8 @@
|
|||
set(SOURCES
|
||||
Decoder.cpp
|
||||
Encoder.cpp
|
||||
Endpoint.cpp
|
||||
Message.cpp
|
||||
Stub.cpp
|
||||
)
|
||||
|
||||
serenity_lib(LibIPC ipc)
|
||||
|
|
|
@ -17,10 +17,13 @@ NonnullRefPtr<T> new_client_connection(Args&&... args)
|
|||
}
|
||||
|
||||
template<typename ClientEndpoint, typename ServerEndpoint>
|
||||
class ClientConnection : public Connection<ServerEndpoint, ClientEndpoint> {
|
||||
class ClientConnection : public Connection<ServerEndpoint, ClientEndpoint>, public ServerEndpoint::Stub {
|
||||
public:
|
||||
ClientConnection(ServerEndpoint& endpoint, NonnullRefPtr<Core::LocalSocket> socket, int client_id)
|
||||
: IPC::Connection<ServerEndpoint, ClientEndpoint>(endpoint, move(socket))
|
||||
using ClientProxy = typename ClientEndpoint::Proxy;
|
||||
using ServerStub = typename ServerEndpoint::Stub;
|
||||
|
||||
ClientConnection(ServerStub& stub, NonnullRefPtr<Core::LocalSocket> socket, int client_id)
|
||||
: IPC::Connection<ServerEndpoint, ClientEndpoint>(stub, move(socket))
|
||||
, m_client_id(client_id)
|
||||
{
|
||||
VERIFY(this->socket().is_connected());
|
||||
|
|
|
@ -28,8 +28,11 @@ namespace IPC {
|
|||
template<typename LocalEndpoint, typename PeerEndpoint>
|
||||
class Connection : public Core::Object {
|
||||
public:
|
||||
Connection(LocalEndpoint& local_endpoint, NonnullRefPtr<Core::LocalSocket> socket)
|
||||
: m_local_endpoint(local_endpoint)
|
||||
using LocalStub = typename LocalEndpoint::Stub;
|
||||
using PeerProxy = typename PeerEndpoint::Proxy;
|
||||
|
||||
Connection(LocalStub& local_stub, NonnullRefPtr<Core::LocalSocket> socket)
|
||||
: m_local_stub(local_stub)
|
||||
, m_socket(move(socket))
|
||||
, m_notifier(Core::Notifier::construct(m_socket->fd(), Core::Notifier::Read, this))
|
||||
{
|
||||
|
@ -248,13 +251,13 @@ protected:
|
|||
auto messages = move(m_unprocessed_messages);
|
||||
for (auto& message : messages) {
|
||||
if (message.endpoint_magic() == LocalEndpoint::static_magic())
|
||||
if (auto response = m_local_endpoint.handle(message))
|
||||
if (auto response = m_local_stub.handle(message))
|
||||
post_message(*response);
|
||||
}
|
||||
}
|
||||
|
||||
protected:
|
||||
LocalEndpoint& m_local_endpoint;
|
||||
LocalStub& m_local_stub;
|
||||
NonnullRefPtr<Core::LocalSocket> m_socket;
|
||||
RefPtr<Core::Timer> m_responsiveness_timer;
|
||||
|
||||
|
|
|
@ -11,9 +11,12 @@
|
|||
namespace IPC {
|
||||
|
||||
template<typename ClientEndpoint, typename ServerEndpoint>
|
||||
class ServerConnection : public IPC::Connection<ClientEndpoint, ServerEndpoint> {
|
||||
class ServerConnection : public IPC::Connection<ClientEndpoint, ServerEndpoint>, public ClientEndpoint::Stub {
|
||||
public:
|
||||
ServerConnection(ClientEndpoint& local_endpoint, const StringView& address)
|
||||
using ClientStub = typename ClientEndpoint::Stub;
|
||||
using ServerProxy = typename ServerEndpoint::Proxy;
|
||||
|
||||
ServerConnection(ClientStub& local_endpoint, const StringView& address)
|
||||
: Connection<ClientEndpoint, ServerEndpoint>(local_endpoint, Core::LocalSocket::construct())
|
||||
{
|
||||
// We want to rate-limit our clients
|
||||
|
|
|
@ -4,15 +4,15 @@
|
|||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <LibIPC/Endpoint.h>
|
||||
#include <LibIPC/Stub.h>
|
||||
|
||||
namespace IPC {
|
||||
|
||||
Endpoint::Endpoint()
|
||||
Stub::Stub()
|
||||
{
|
||||
}
|
||||
|
||||
Endpoint::~Endpoint()
|
||||
Stub::~Stub()
|
||||
{
|
||||
}
|
||||
|
|
@ -18,16 +18,16 @@ namespace IPC {
|
|||
class Message;
|
||||
class MessageBuffer;
|
||||
|
||||
class Endpoint {
|
||||
class Stub {
|
||||
public:
|
||||
virtual ~Endpoint();
|
||||
virtual ~Stub();
|
||||
|
||||
virtual u32 magic() const = 0;
|
||||
virtual String name() const = 0;
|
||||
virtual OwnPtr<MessageBuffer> handle(const Message&) = 0;
|
||||
|
||||
protected:
|
||||
Endpoint();
|
||||
Stub();
|
||||
|
||||
private:
|
||||
String m_name;
|
Loading…
Add table
Add a link
Reference in a new issue