From 96b1e6b50f355c04e794ad7366bd33b9c3d1f81b Mon Sep 17 00:00:00 2001 From: Emmanuele Bassi Date: Wed, 1 Jun 2011 12:35:58 +0100 Subject: serializable: Allow introspecting properties This allows a Serializable implementation to override the property list, and the setter and the getter function. --- json-glib/json-serializable.c | 81 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) (limited to 'json-glib/json-serializable.c') diff --git a/json-glib/json-serializable.c b/json-glib/json-serializable.c index c29cf9a..cd8ec1e 100644 --- a/json-glib/json-serializable.c +++ b/json-glib/json-serializable.c @@ -126,6 +126,36 @@ json_serializable_real_serialize (JsonSerializable *serializable, return json_serialize_pspec (value, pspec); } +static GParamSpec * +json_serializable_real_find_property (JsonSerializable *serializable, + const char *name) +{ + return g_object_class_find_property (G_OBJECT_GET_CLASS (serializable), name); +} + +static GParamSpec ** +json_serializable_real_list_properties (JsonSerializable *serializable, + guint *n_pspecs) +{ + return g_object_class_list_properties (G_OBJECT_GET_CLASS (serializable), n_pspecs); +} + +static void +json_serializable_real_set_property (JsonSerializable *serializable, + GParamSpec *pspec, + const GValue *value) +{ + g_object_set_property (G_OBJECT (serializable), pspec->name, value); +} + +static void +json_serializable_real_get_property (JsonSerializable *serializable, + GParamSpec *pspec, + GValue *value) +{ + g_object_get_property (G_OBJECT (serializable), pspec->name, value); +} + /* typedef to satisfy G_DEFINE_INTERFACE's naming */ typedef JsonSerializableIface JsonSerializableInterface; @@ -134,6 +164,10 @@ json_serializable_default_init (JsonSerializableInterface *iface) { iface->serialize_property = json_serializable_real_serialize; iface->deserialize_property = json_serializable_real_deserialize; + iface->find_property = json_serializable_real_find_property; + iface->list_properties = json_serializable_real_list_properties; + iface->set_property = json_serializable_real_set_property; + iface->get_property = json_serializable_real_get_property; } G_DEFINE_INTERFACE (JsonSerializable, json_serializable, G_TYPE_OBJECT); @@ -229,3 +263,50 @@ json_serializable_default_deserialize_property (JsonSerializable *serializable, value, pspec, property_node); } + +GParamSpec * +json_serializable_find_property (JsonSerializable *serializable, + const char *name) +{ + g_return_val_if_fail (JSON_IS_SERIALIZABLE (serializable), NULL); + g_return_val_if_fail (name != NULL, NULL); + + return JSON_SERIALIZABLE_GET_IFACE (serializable)->find_property (serializable, name); +} + +GParamSpec ** +json_serializable_list_properties (JsonSerializable *serializable, + guint *n_pspecs) +{ + g_return_val_if_fail (JSON_IS_SERIALIZABLE (serializable), NULL); + + return JSON_SERIALIZABLE_GET_IFACE (serializable)->list_properties (serializable, n_pspecs); +} + +void +json_serializable_set_property (JsonSerializable *serializable, + GParamSpec *pspec, + const GValue *value) +{ + g_return_if_fail (JSON_IS_SERIALIZABLE (serializable)); + g_return_if_fail (G_IS_PARAM_SPEC (pspec)); + g_return_if_fail (value != NULL); + + JSON_SERIALIZABLE_GET_IFACE (serializable)->set_property (serializable, + pspec, + value); +} + +void +json_serializable_get_property (JsonSerializable *serializable, + GParamSpec *pspec, + GValue *value) +{ + g_return_if_fail (JSON_IS_SERIALIZABLE (serializable)); + g_return_if_fail (G_IS_PARAM_SPEC (pspec)); + g_return_if_fail (value != NULL); + + JSON_SERIALIZABLE_GET_IFACE (serializable)->get_property (serializable, + pspec, + value); +} -- cgit v1.2.1