summaryrefslogtreecommitdiff
path: root/Libraries/LibCore
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2020-03-05 15:46:00 +0100
committerAndreas Kling <kling@serenityos.org>2020-03-05 15:50:22 +0100
commit42f2696355e70de0146c772cc17bf5b238aded4b (patch)
treebb0c9b360ba418bf4034346230565d717903c158 /Libraries/LibCore
parentca110a6e54c47bd280f27ef092f125fc366a23d9 (diff)
downloadserenity-42f2696355e70de0146c772cc17bf5b238aded4b.zip
LibCore: Add a way to set an individual Core::Object property remotely
Diffstat (limited to 'Libraries/LibCore')
-rw-r--r--Libraries/LibCore/EventLoop.cpp17
-rw-r--r--Libraries/LibCore/Object.cpp9
-rw-r--r--Libraries/LibCore/Object.h1
3 files changed, 27 insertions, 0 deletions
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<uintptr_t>();
+ 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<Object, &Object::m_all_objects_list_node>& all_objects();