Skip to content

Commit

Permalink
LibCore: Add a way to set an individual Core::Object property remotely
Browse files Browse the repository at this point in the history
  • Loading branch information
awesomekling committed Mar 5, 2020
1 parent ca110a6 commit 42f2696
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
17 changes: 17 additions & 0 deletions Libraries/LibCore/EventLoop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,25 @@ class RPCClient : public Object {
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") {
Expand Down
9 changes: 9 additions & 0 deletions Libraries/LibCore/Object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions Libraries/LibCore/Object.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ class Object
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();

Expand Down

0 comments on commit 42f2696

Please sign in to comment.