1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-28 08:35:09 +00:00

LibCore: Allow RPC clients to specify the currently inspected object

Add a SetInspectedObject call that tells us which Core::Object a remote
client is currently looking it. Objects get notified when they gain
their first inspector, and when they lose their last one.
This commit is contained in:
Andreas Kling 2020-03-05 14:40:47 +01:00
parent 37c71bad8a
commit d16f8214d8
3 changed files with 43 additions and 2 deletions

View file

@ -112,6 +112,8 @@ public:
}
virtual ~RPCClient() override
{
if (m_inspected_object)
m_inspected_object->decrement_inspector_count({});
}
void send_response(const JsonObject& response)
@ -161,6 +163,18 @@ public:
return;
}
if (type == "SetInspectedObject") {
auto address = request.get("address").to_number<uintptr_t>();
for (auto& object : Object::all_objects()) {
if ((uintptr_t)&object == address) {
if (m_inspected_object)
m_inspected_object->decrement_inspector_count({});
m_inspected_object = object.make_weak_ptr();
m_inspected_object->increment_inspector_count({});
}
}
}
if (type == "Disconnect") {
shutdown();
return;
@ -175,6 +189,7 @@ public:
private:
RefPtr<LocalSocket> m_socket;
WeakPtr<Object> m_inspected_object;
int m_client_id { -1 };
};