summaryrefslogtreecommitdiff
path: root/json-glib/json-gobject.c
diff options
context:
space:
mode:
authorEmmanuele Bassi <ebassi@linux.intel.com>2011-06-01 12:35:58 +0100
committerEmmanuele Bassi <ebassi@linux.intel.com>2011-06-01 12:36:55 +0100
commit96b1e6b50f355c04e794ad7366bd33b9c3d1f81b (patch)
tree9c04289022797e2554826a89353b765edd83a607 /json-glib/json-gobject.c
parentc85fc93f6235b8b9d584585215b2fa860f07f2c3 (diff)
downloadjson-glib-96b1e6b50f355c04e794ad7366bd33b9c3d1f81b.tar.gz
serializable: Allow introspecting properties
This allows a Serializable implementation to override the property list, and the setter and the getter function.
Diffstat (limited to 'json-glib/json-gobject.c')
-rw-r--r--json-glib/json-gobject.c43
1 files changed, 34 insertions, 9 deletions
diff --git a/json-glib/json-gobject.c b/json-glib/json-gobject.c
index a653712..fb97bd4 100644
--- a/json-glib/json-gobject.c
+++ b/json-glib/json-gobject.c
@@ -180,7 +180,9 @@ json_gobject_new (GType gtype,
{
JsonSerializableIface *iface = NULL;
JsonSerializable *serializable = NULL;
+ gboolean find_property;
gboolean deserialize_property;
+ gboolean set_property;
GList *members, *members_left, *l;
guint n_members;
GObjectClass *klass;
@@ -268,10 +270,16 @@ json_gobject_new (GType gtype,
{
serializable = JSON_SERIALIZABLE (retval);
iface = JSON_SERIALIZABLE_GET_IFACE (serializable);
+ find_property = (iface->find_property != NULL);
deserialize_property = (iface->deserialize_property != NULL);
+ set_property = (iface->set_property != NULL);
}
else
- deserialize_property = FALSE;
+ {
+ find_property = FALSE;
+ deserialize_property = FALSE;
+ set_property = FALSE;
+ }
g_object_freeze_notify (retval);
@@ -283,8 +291,12 @@ json_gobject_new (GType gtype,
GValue value = { 0, };
gboolean res = FALSE;
- pspec = g_object_class_find_property (klass, member_name);
- if (!pspec)
+ if (find_property)
+ pspec = json_serializable_find_property (serializable, member_name);
+ else
+ pspec = g_object_class_find_property (klass, member_name);
+
+ if (pspec == NULL)
continue;
/* we should have dealt with these above */
@@ -314,15 +326,16 @@ json_gobject_new (GType gtype,
res = json_deserialize_pspec (&value, pspec, val);
}
- /* FIXME - we probably want to be able to have a custom
- * set_property() for Serializable implementations
- */
if (res)
{
JSON_NOTE (GOBJECT, "Calling set_property('%s', '%s')",
pspec->name,
g_type_name (G_VALUE_TYPE (&value)));
- g_object_set_property (retval, pspec->name, &value);
+
+ if (set_property)
+ json_serializable_set_property (serializable, pspec, &value);
+ else
+ g_object_set_property (retval, pspec->name, &value);
}
else
g_warning ("Failed to deserialize \"%s\" property of type \"%s\" for an object of type \"%s\"",
@@ -345,7 +358,9 @@ json_gobject_dump (GObject *gobject)
{
JsonSerializableIface *iface = NULL;
JsonSerializable *serializable = NULL;
+ gboolean list_properties = FALSE;
gboolean serialize_property = FALSE;
+ gboolean get_property = FALSE;
JsonObject *object;
GParamSpec **pspecs;
guint n_pspecs, i;
@@ -354,12 +369,18 @@ json_gobject_dump (GObject *gobject)
{
serializable = JSON_SERIALIZABLE (gobject);
iface = JSON_SERIALIZABLE_GET_IFACE (gobject);
+ list_properties = (iface->list_properties != NULL);
serialize_property = (iface->serialize_property != NULL);
+ get_property = (iface->get_property != NULL);
}
object = json_object_new ();
- pspecs = g_object_class_list_properties (G_OBJECT_GET_CLASS (gobject), &n_pspecs);
+ if (list_properties)
+ pspecs = json_serializable_list_properties (serializable, &n_pspecs);
+ else
+ pspecs = g_object_class_list_properties (G_OBJECT_GET_CLASS (gobject), &n_pspecs);
+
for (i = 0; i < n_pspecs; i++)
{
GParamSpec *pspec = pspecs[i];
@@ -371,7 +392,11 @@ json_gobject_dump (GObject *gobject)
continue;
g_value_init (&value, G_PARAM_SPEC_VALUE_TYPE (pspec));
- g_object_get_property (gobject, pspec->name, &value);
+
+ if (get_property)
+ json_serializable_get_property (serializable, pspec, &value);
+ else
+ g_object_get_property (gobject, pspec->name, &value);
/* if there is a serialization vfunc, then it is completely responsible
* for serializing the property, possibly by calling the implementation