1 /* json-gobject.h - JSON GObject integration
3 * This file is part of JSON-GLib
4 * Copyright (C) 2007 OpenedHand Ltd.
5 * Copyright (C) 2009 Intel Corp.
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
21 * Emmanuele Bassi <ebassi@linux.intel.com>
24 #ifndef __JSON_GOBJECT_H__
25 #define __JSON_GOBJECT_H__
27 #include <json-glib/json-types.h>
31 #define JSON_TYPE_SERIALIZABLE (json_serializable_get_type ())
32 #define JSON_SERIALIZABLE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), JSON_TYPE_SERIALIZABLE, JsonSerializable))
33 #define JSON_IS_SERIALIZABLE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), JSON_TYPE_SERIALIZABLE))
34 #define JSON_SERIALIZABLE_GET_IFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), JSON_TYPE_SERIALIZABLE, JsonSerializableIface))
36 typedef struct _JsonSerializable JsonSerializable; /* dummy */
37 typedef struct _JsonSerializableIface JsonSerializableIface;
40 * JsonSerializableIface:
41 * @serialize_property: virtual function for serializing a #GObject property
43 * @deserialize_property: virtual function for deserializing a #JsonNode
44 * into a #GObject property
45 * @find_property: virtual function for finding a property definition using
47 * @list_properties: virtual function for listing the installed property
49 * @set_property: virtual function for setting a property
50 * @get_property: virtual function for getting a property
52 * Interface that allows serializing and deserializing #GObject instances
53 * with properties storing complex data types. The json_serialize_gobject()
54 * function will check if the passed #GObject implements this interface,
55 * so it can also be used to override the default property serialization
58 struct _JsonSerializableIface
61 GTypeInterface g_iface;
64 JsonNode *(* serialize_property) (JsonSerializable *serializable,
65 const gchar *property_name,
68 gboolean (* deserialize_property) (JsonSerializable *serializable,
69 const gchar *property_name,
72 JsonNode *property_node);
74 GParamSpec * (* find_property) (JsonSerializable *serializable,
76 GParamSpec **(* list_properties) (JsonSerializable *serializable,
78 void (* set_property) (JsonSerializable *serializable,
81 void (* get_property) (JsonSerializable *serializable,
87 GType json_serializable_get_type (void) G_GNUC_CONST;
90 JsonNode *json_serializable_serialize_property (JsonSerializable *serializable,
91 const gchar *property_name,
95 gboolean json_serializable_deserialize_property (JsonSerializable *serializable,
96 const gchar *property_name,
99 JsonNode *property_node);
101 JSON_AVAILABLE_IN_1_0
102 GParamSpec * json_serializable_find_property (JsonSerializable *serializable,
104 JSON_AVAILABLE_IN_1_0
105 GParamSpec ** json_serializable_list_properties (JsonSerializable *serializable,
107 JSON_AVAILABLE_IN_1_0
108 void json_serializable_set_property (JsonSerializable *serializable,
110 const GValue *value);
111 JSON_AVAILABLE_IN_1_0
112 void json_serializable_get_property (JsonSerializable *serializable,
116 JSON_AVAILABLE_IN_1_0
117 JsonNode *json_serializable_default_serialize_property (JsonSerializable *serializable,
118 const gchar *property_name,
121 JSON_AVAILABLE_IN_1_0
122 gboolean json_serializable_default_deserialize_property (JsonSerializable *serializable,
123 const gchar *property_name,
126 JsonNode *property_node);
129 * JsonBoxedSerializeFunc:
132 * Serializes the passed #GBoxed and stores it inside a #JsonNode
134 * Return value: the newly created #JsonNode
138 typedef JsonNode *(* JsonBoxedSerializeFunc) (gconstpointer boxed);
141 * JsonBoxedDeserializeFunc:
144 * Deserializes the contents of the passed #JsonNode into a #GBoxed
146 * Return value: the newly created boxed type
150 typedef gpointer (* JsonBoxedDeserializeFunc) (JsonNode *node);
152 JSON_AVAILABLE_IN_1_0
153 void json_boxed_register_serialize_func (GType gboxed_type,
154 JsonNodeType node_type,
155 JsonBoxedSerializeFunc serialize_func);
156 JSON_AVAILABLE_IN_1_0
157 void json_boxed_register_deserialize_func (GType gboxed_type,
158 JsonNodeType node_type,
159 JsonBoxedDeserializeFunc deserialize_func);
160 JSON_AVAILABLE_IN_1_0
161 gboolean json_boxed_can_serialize (GType gboxed_type,
162 JsonNodeType *node_type);
163 JSON_AVAILABLE_IN_1_0
164 gboolean json_boxed_can_deserialize (GType gboxed_type,
165 JsonNodeType node_type);
166 JSON_AVAILABLE_IN_1_0
167 JsonNode *json_boxed_serialize (GType gboxed_type,
168 gconstpointer boxed);
169 JSON_AVAILABLE_IN_1_0
170 gpointer json_boxed_deserialize (GType gboxed_type,
173 JSON_AVAILABLE_IN_1_0
174 JsonNode *json_gobject_serialize (GObject *gobject);
175 JSON_AVAILABLE_IN_1_0
176 GObject * json_gobject_deserialize (GType gtype,
179 JSON_AVAILABLE_IN_1_0
180 GObject * json_gobject_from_data (GType gtype,
184 JSON_AVAILABLE_IN_1_0
185 gchar * json_gobject_to_data (GObject *gobject,
188 JSON_DEPRECATED_IN_1_0_FOR(json_gobject_from_data)
189 GObject * json_construct_gobject (GType gtype,
193 JSON_DEPRECATED_IN_1_0_FOR(json_gobject_to_data)
194 gchar * json_serialize_gobject (GObject *gobject,
195 gsize *length) G_GNUC_MALLOC;
197 #ifdef G_DEFINE_AUTOPTR_CLEANUP_FUNC
198 G_DEFINE_AUTOPTR_CLEANUP_FUNC (JsonSerializable, g_object_unref)
203 #endif /* __JSON_GOBJECT_H__ */