From 42f2696355e70de0146c772cc17bf5b238aded4b Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Thu, 5 Mar 2020 15:46:00 +0100 Subject: LibCore: Add a way to set an individual Core::Object property remotely --- Libraries/LibCore/EventLoop.cpp | 17 +++++++++++++++++ Libraries/LibCore/Object.cpp | 9 +++++++++ Libraries/LibCore/Object.h | 1 + 3 files changed, 27 insertions(+) (limited to 'Libraries/LibCore') diff --git a/Libraries/LibCore/EventLoop.cpp b/Libraries/LibCore/EventLoop.cpp index 741ddda934..74532d6b44 100644 --- a/Libraries/LibCore/EventLoop.cpp +++ b/Libraries/LibCore/EventLoop.cpp @@ -171,8 +171,25 @@ public: m_inspected_object->decrement_inspector_count({}); m_inspected_object = object.make_weak_ptr(); m_inspected_object->increment_inspector_count({}); + break; } } + return; + } + + if (type == "SetProperty") { + auto address = request.get("address").to_number(); + for (auto& object : Object::all_objects()) { + if ((uintptr_t)&object == address) { + bool success = object.set_property(request.get("name").to_string(), request.get("value")); + JsonObject response; + response.set("type", "SetProperty"); + response.set("success", success); + send_response(response); + break; + } + } + return; } if (type == "Disconnect") { diff --git a/Libraries/LibCore/Object.cpp b/Libraries/LibCore/Object.cpp index ff7e7150ac..c503a23d02 100644 --- a/Libraries/LibCore/Object.cpp +++ b/Libraries/LibCore/Object.cpp @@ -173,6 +173,15 @@ void Object::save_to(JsonObject& json) json.set("parent", (uintptr_t)parent()); } +bool Object::set_property(const StringView& name, const JsonValue& value) +{ + if (name == "name") { + set_name(value.to_string()); + return true; + } + return false; +} + bool Object::is_ancestor_of(const Object& other) const { if (&other == this) diff --git a/Libraries/LibCore/Object.h b/Libraries/LibCore/Object.h index bacee96d0a..53852ef820 100644 --- a/Libraries/LibCore/Object.h +++ b/Libraries/LibCore/Object.h @@ -111,6 +111,7 @@ public: virtual bool is_window() const { return false; } virtual void save_to(AK::JsonObject&); + virtual bool set_property(const StringView& name, const JsonValue& value); static IntrusiveList& all_objects(); -- cgit v1.2.3