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

Services: Add InspectorServer to reverse the direction of Inspector

This service daemon will act as an intermediary between the Inspector
program and the inspectable programs it wants to inspect.

Programs can make themselves available for inspection by connecting
to /tmp/portal/inspectables using the Core::EventLoop RPC protocol.
This commit is contained in:
Andreas Kling 2021-05-13 22:34:57 +02:00
parent 3c3b384c80
commit 3d3a5b431f
11 changed files with 332 additions and 0 deletions

View file

@ -0,0 +1,87 @@
/*
* Copyright (c) 2021, Andreas Kling <kling@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include "InspectableProcess.h"
#include <InspectorServer/ClientConnection.h>
namespace InspectorServer {
static HashMap<int, RefPtr<ClientConnection>> s_connections;
ClientConnection::ClientConnection(NonnullRefPtr<Core::LocalSocket> socket, int client_id)
: IPC::ClientConnection<InspectorClientEndpoint, InspectorServerEndpoint>(*this, move(socket), client_id)
{
s_connections.set(client_id, *this);
}
ClientConnection::~ClientConnection()
{
}
void ClientConnection::die()
{
s_connections.remove(client_id());
}
void ClientConnection::greet()
{
}
Messages::InspectorServer::GetAllObjectsResponse ClientConnection::get_all_objects(pid_t pid)
{
auto process = InspectableProcess::from_pid(pid);
if (!process)
return { String {} };
JsonObject request;
request.set("type", "GetAllObjects");
process->send_request(request);
auto response = process->wait_for_response();
return { response };
}
Messages::InspectorServer::SetInspectedObjectResponse ClientConnection::set_inspected_object(pid_t pid, u64 object_id)
{
auto process = InspectableProcess::from_pid(pid);
if (!process)
return { false };
JsonObject request;
request.set("type", "SetInspectedObject");
request.set("address", object_id);
process->send_request(request);
return { true };
}
Messages::InspectorServer::SetObjectPropertyResponse ClientConnection::set_object_property(pid_t pid, u64 object_id, String const& name, String const& value)
{
auto process = InspectableProcess::from_pid(pid);
if (!process)
return { false };
JsonObject request;
request.set("type", "SetProperty");
request.set("address", object_id);
request.set("name", name);
request.set("value", value);
process->send_request(request);
return { true };
}
Messages::InspectorServer::IdentifyResponse ClientConnection::identify(pid_t pid)
{
auto process = InspectableProcess::from_pid(pid);
if (!process)
return { String {} };
JsonObject request;
request.set("type", "Identify");
process->send_request(request);
auto response = process->wait_for_response();
return { response };
}
}