mirror of
https://github.com/RGBCube/serenity
synced 2025-07-24 21:47:43 +00:00
LibCore: Move CObject serialization into CObject::save_to(JsonObject&)
The idea is for subclasses to override this and add whatever properties are relevant for them, then call up to their base class, etc.
This commit is contained in:
parent
a32123f221
commit
c2213449c0
3 changed files with 16 additions and 4 deletions
|
@ -61,10 +61,7 @@ CEventLoop::CEventLoop()
|
||||||
JsonArray objects;
|
JsonArray objects;
|
||||||
for (auto& object : CObject::all_objects()) {
|
for (auto& object : CObject::all_objects()) {
|
||||||
JsonObject json_object;
|
JsonObject json_object;
|
||||||
json_object.set("class_name", object.class_name());
|
object.save_to(json_object);
|
||||||
json_object.set("address", String::format("%p", &object));
|
|
||||||
json_object.set("name", object.name());
|
|
||||||
json_object.set("parent", String::format("%p", object.parent()));
|
|
||||||
objects.append(move(json_object));
|
objects.append(move(json_object));
|
||||||
}
|
}
|
||||||
client->write(objects.to_string());
|
client->write(objects.to_string());
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
#include <AK/Assertions.h>
|
#include <AK/Assertions.h>
|
||||||
|
#include <AK/JsonObject.h>
|
||||||
#include <AK/kstdio.h>
|
#include <AK/kstdio.h>
|
||||||
#include <LibCore/CEvent.h>
|
#include <LibCore/CEvent.h>
|
||||||
#include <LibCore/CEventLoop.h>
|
#include <LibCore/CEventLoop.h>
|
||||||
|
@ -125,3 +126,11 @@ void CObject::deferred_invoke(Function<void(CObject&)> invokee)
|
||||||
{
|
{
|
||||||
CEventLoop::current().post_event(*this, make<CDeferredInvocationEvent>(move(invokee)));
|
CEventLoop::current().post_event(*this, make<CDeferredInvocationEvent>(move(invokee)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CObject::save_to(JsonObject& json)
|
||||||
|
{
|
||||||
|
json.set("class_name", class_name());
|
||||||
|
json.set("address", String::format("%p", this));
|
||||||
|
json.set("name", name());
|
||||||
|
json.set("parent", String::format("%p", parent()));
|
||||||
|
}
|
||||||
|
|
|
@ -7,6 +7,10 @@
|
||||||
#include <AK/Vector.h>
|
#include <AK/Vector.h>
|
||||||
#include <AK/Weakable.h>
|
#include <AK/Weakable.h>
|
||||||
|
|
||||||
|
namespace AK {
|
||||||
|
class JsonObject;
|
||||||
|
}
|
||||||
|
|
||||||
class CEvent;
|
class CEvent;
|
||||||
class CChildEvent;
|
class CChildEvent;
|
||||||
class CCustomEvent;
|
class CCustomEvent;
|
||||||
|
@ -63,6 +67,8 @@ public:
|
||||||
bool is_widget() const { return m_widget; }
|
bool is_widget() const { return m_widget; }
|
||||||
virtual bool is_window() const { return false; }
|
virtual bool is_window() const { return false; }
|
||||||
|
|
||||||
|
virtual void save_to(AK::JsonObject&);
|
||||||
|
|
||||||
static IntrusiveList<CObject, &CObject::m_all_objects_list_node>& all_objects();
|
static IntrusiveList<CObject, &CObject::m_all_objects_list_node>& all_objects();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue