summaryrefslogtreecommitdiff
path: root/Userland/Services/InspectorServer/ClientConnection.cpp
blob: ee5346b951fab2b2f0ecd6e083975a2c4ba72093 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/*
 * Copyright (c) 2021, Andreas Kling <kling@serenityos.org>
 *
 * SPDX-License-Identifier: BSD-2-Clause
 */

#include "InspectableProcess.h"
#include <AK/JsonObject.h>
#include <InspectorServer/ClientConnection.h>

namespace InspectorServer {

static HashMap<int, RefPtr<ClientConnection>> s_connections;

ClientConnection::ClientConnection(NonnullOwnPtr<Core::Stream::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());
}

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;
}

Messages::InspectorServer::IsInspectableResponse ClientConnection::is_inspectable(pid_t pid)
{
    auto process = InspectableProcess::from_pid(pid);
    if (!process)
        return false;

    return true;
}

}