2 * Copyright © 2007, 2008 Ryan Lortie
3 * Copyright © 2009, 2010 Codethink Limited
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the licence, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 * Boston, MA 02111-1307, USA.
20 * Author: Ryan Lortie <desrt@desrt.ca>
23 #ifndef __G_VARIANT_H__
24 #define __G_VARIANT_H__
26 #if !defined (__GLIB_H_INSIDE__) && !defined (GLIB_COMPILATION)
27 #error "Only <glib.h> can be included directly."
30 #include <glib/gvarianttype.h>
31 #include <glib/gstring.h>
32 #include <glib/gbytes.h>
36 typedef struct _GVariant GVariant;
40 G_VARIANT_CLASS_BOOLEAN = 'b',
41 G_VARIANT_CLASS_BYTE = 'y',
42 G_VARIANT_CLASS_INT16 = 'n',
43 G_VARIANT_CLASS_UINT16 = 'q',
44 G_VARIANT_CLASS_INT32 = 'i',
45 G_VARIANT_CLASS_UINT32 = 'u',
46 G_VARIANT_CLASS_INT64 = 'x',
47 G_VARIANT_CLASS_UINT64 = 't',
48 G_VARIANT_CLASS_HANDLE = 'h',
49 G_VARIANT_CLASS_DOUBLE = 'd',
50 G_VARIANT_CLASS_STRING = 's',
51 G_VARIANT_CLASS_OBJECT_PATH = 'o',
52 G_VARIANT_CLASS_SIGNATURE = 'g',
53 G_VARIANT_CLASS_VARIANT = 'v',
54 G_VARIANT_CLASS_MAYBE = 'm',
55 G_VARIANT_CLASS_ARRAY = 'a',
56 G_VARIANT_CLASS_TUPLE = '(',
57 G_VARIANT_CLASS_DICT_ENTRY = '{'
61 void g_variant_unref (GVariant *value);
63 GVariant * g_variant_ref (GVariant *value);
65 GVariant * g_variant_ref_sink (GVariant *value);
67 gboolean g_variant_is_floating (GVariant *value);
69 GVariant * g_variant_take_ref (GVariant *value);
72 const GVariantType * g_variant_get_type (GVariant *value);
74 const gchar * g_variant_get_type_string (GVariant *value);
76 gboolean g_variant_is_of_type (GVariant *value,
77 const GVariantType *type);
79 gboolean g_variant_is_container (GVariant *value);
81 GVariantClass g_variant_classify (GVariant *value);
83 GVariant * g_variant_new_boolean (gboolean value);
85 GVariant * g_variant_new_byte (guchar value);
87 GVariant * g_variant_new_int16 (gint16 value);
89 GVariant * g_variant_new_uint16 (guint16 value);
91 GVariant * g_variant_new_int32 (gint32 value);
93 GVariant * g_variant_new_uint32 (guint32 value);
95 GVariant * g_variant_new_int64 (gint64 value);
97 GVariant * g_variant_new_uint64 (guint64 value);
99 GVariant * g_variant_new_handle (gint32 value);
100 GLIB_AVAILABLE_IN_ALL
101 GVariant * g_variant_new_double (gdouble value);
102 GLIB_AVAILABLE_IN_ALL
103 GVariant * g_variant_new_string (const gchar *string);
104 GLIB_AVAILABLE_IN_2_38
105 GVariant * g_variant_new_take_string (gchar *string);
106 GLIB_AVAILABLE_IN_ALL
107 GVariant * g_variant_new_object_path (const gchar *object_path);
108 GLIB_AVAILABLE_IN_ALL
109 gboolean g_variant_is_object_path (const gchar *string);
110 GLIB_AVAILABLE_IN_ALL
111 GVariant * g_variant_new_signature (const gchar *signature);
112 GLIB_AVAILABLE_IN_ALL
113 gboolean g_variant_is_signature (const gchar *string);
114 GLIB_AVAILABLE_IN_ALL
115 GVariant * g_variant_new_variant (GVariant *value);
116 GLIB_AVAILABLE_IN_ALL
117 GVariant * g_variant_new_strv (const gchar * const *strv,
119 GLIB_AVAILABLE_IN_2_30
120 GVariant * g_variant_new_objv (const gchar * const *strv,
122 GLIB_AVAILABLE_IN_ALL
123 GVariant * g_variant_new_bytestring (const gchar *string);
124 GLIB_AVAILABLE_IN_ALL
125 GVariant * g_variant_new_bytestring_array (const gchar * const *strv,
127 GLIB_AVAILABLE_IN_ALL
128 GVariant * g_variant_new_fixed_array (const GVariantType *element_type,
129 gconstpointer elements,
132 GLIB_AVAILABLE_IN_ALL
133 gboolean g_variant_get_boolean (GVariant *value);
134 GLIB_AVAILABLE_IN_ALL
135 guchar g_variant_get_byte (GVariant *value);
136 GLIB_AVAILABLE_IN_ALL
137 gint16 g_variant_get_int16 (GVariant *value);
138 GLIB_AVAILABLE_IN_ALL
139 guint16 g_variant_get_uint16 (GVariant *value);
140 GLIB_AVAILABLE_IN_ALL
141 gint32 g_variant_get_int32 (GVariant *value);
142 GLIB_AVAILABLE_IN_ALL
143 guint32 g_variant_get_uint32 (GVariant *value);
144 GLIB_AVAILABLE_IN_ALL
145 gint64 g_variant_get_int64 (GVariant *value);
146 GLIB_AVAILABLE_IN_ALL
147 guint64 g_variant_get_uint64 (GVariant *value);
148 GLIB_AVAILABLE_IN_ALL
149 gint32 g_variant_get_handle (GVariant *value);
150 GLIB_AVAILABLE_IN_ALL
151 gdouble g_variant_get_double (GVariant *value);
152 GLIB_AVAILABLE_IN_ALL
153 GVariant * g_variant_get_variant (GVariant *value);
154 GLIB_AVAILABLE_IN_ALL
155 const gchar * g_variant_get_string (GVariant *value,
157 GLIB_AVAILABLE_IN_ALL
158 gchar * g_variant_dup_string (GVariant *value,
160 GLIB_AVAILABLE_IN_ALL
161 const gchar ** g_variant_get_strv (GVariant *value,
163 GLIB_AVAILABLE_IN_ALL
164 gchar ** g_variant_dup_strv (GVariant *value,
166 GLIB_AVAILABLE_IN_2_30
167 const gchar ** g_variant_get_objv (GVariant *value,
169 GLIB_AVAILABLE_IN_ALL
170 gchar ** g_variant_dup_objv (GVariant *value,
172 GLIB_AVAILABLE_IN_ALL
173 const gchar * g_variant_get_bytestring (GVariant *value);
174 GLIB_AVAILABLE_IN_ALL
175 gchar * g_variant_dup_bytestring (GVariant *value,
177 GLIB_AVAILABLE_IN_ALL
178 const gchar ** g_variant_get_bytestring_array (GVariant *value,
180 GLIB_AVAILABLE_IN_ALL
181 gchar ** g_variant_dup_bytestring_array (GVariant *value,
184 GLIB_AVAILABLE_IN_ALL
185 GVariant * g_variant_new_maybe (const GVariantType *child_type,
187 GLIB_AVAILABLE_IN_ALL
188 GVariant * g_variant_new_array (const GVariantType *child_type,
189 GVariant * const *children,
191 GLIB_AVAILABLE_IN_ALL
192 GVariant * g_variant_new_tuple (GVariant * const *children,
194 GLIB_AVAILABLE_IN_ALL
195 GVariant * g_variant_new_dict_entry (GVariant *key,
198 GLIB_AVAILABLE_IN_ALL
199 GVariant * g_variant_get_maybe (GVariant *value);
200 GLIB_AVAILABLE_IN_ALL
201 gsize g_variant_n_children (GVariant *value);
202 GLIB_AVAILABLE_IN_ALL
203 void g_variant_get_child (GVariant *value,
205 const gchar *format_string,
207 GLIB_AVAILABLE_IN_ALL
208 GVariant * g_variant_get_child_value (GVariant *value,
210 GLIB_AVAILABLE_IN_ALL
211 gboolean g_variant_lookup (GVariant *dictionary,
213 const gchar *format_string,
215 GLIB_AVAILABLE_IN_ALL
216 GVariant * g_variant_lookup_value (GVariant *dictionary,
218 const GVariantType *expected_type);
219 GLIB_AVAILABLE_IN_ALL
220 gconstpointer g_variant_get_fixed_array (GVariant *value,
224 GLIB_AVAILABLE_IN_ALL
225 gsize g_variant_get_size (GVariant *value);
226 GLIB_AVAILABLE_IN_ALL
227 gconstpointer g_variant_get_data (GVariant *value);
228 GLIB_AVAILABLE_IN_2_36
229 GBytes * g_variant_get_data_as_bytes (GVariant *value);
230 GLIB_AVAILABLE_IN_ALL
231 void g_variant_store (GVariant *value,
234 GLIB_AVAILABLE_IN_ALL
235 gchar * g_variant_print (GVariant *value,
236 gboolean type_annotate);
237 GLIB_AVAILABLE_IN_ALL
238 GString * g_variant_print_string (GVariant *value,
240 gboolean type_annotate);
242 GLIB_AVAILABLE_IN_ALL
243 guint g_variant_hash (gconstpointer value);
244 GLIB_AVAILABLE_IN_ALL
245 gboolean g_variant_equal (gconstpointer one,
248 GLIB_AVAILABLE_IN_ALL
249 GVariant * g_variant_get_normal_form (GVariant *value);
250 GLIB_AVAILABLE_IN_ALL
251 gboolean g_variant_is_normal_form (GVariant *value);
252 GLIB_AVAILABLE_IN_ALL
253 GVariant * g_variant_byteswap (GVariant *value);
255 GLIB_AVAILABLE_IN_2_36
256 GVariant * g_variant_new_from_bytes (const GVariantType *type,
259 GLIB_AVAILABLE_IN_ALL
260 GVariant * g_variant_new_from_data (const GVariantType *type,
264 GDestroyNotify notify,
267 typedef struct _GVariantIter GVariantIter;
268 struct _GVariantIter {
273 GLIB_AVAILABLE_IN_ALL
274 GVariantIter * g_variant_iter_new (GVariant *value);
275 GLIB_AVAILABLE_IN_ALL
276 gsize g_variant_iter_init (GVariantIter *iter,
278 GLIB_AVAILABLE_IN_ALL
279 GVariantIter * g_variant_iter_copy (GVariantIter *iter);
280 GLIB_AVAILABLE_IN_ALL
281 gsize g_variant_iter_n_children (GVariantIter *iter);
282 GLIB_AVAILABLE_IN_ALL
283 void g_variant_iter_free (GVariantIter *iter);
284 GLIB_AVAILABLE_IN_ALL
285 GVariant * g_variant_iter_next_value (GVariantIter *iter);
286 GLIB_AVAILABLE_IN_ALL
287 gboolean g_variant_iter_next (GVariantIter *iter,
288 const gchar *format_string,
290 GLIB_AVAILABLE_IN_ALL
291 gboolean g_variant_iter_loop (GVariantIter *iter,
292 const gchar *format_string,
296 typedef struct _GVariantBuilder GVariantBuilder;
297 struct _GVariantBuilder {
304 G_VARIANT_PARSE_ERROR_FAILED,
305 G_VARIANT_PARSE_ERROR_BASIC_TYPE_EXPECTED,
306 G_VARIANT_PARSE_ERROR_CANNOT_INFER_TYPE,
307 G_VARIANT_PARSE_ERROR_DEFINITE_TYPE_EXPECTED,
308 G_VARIANT_PARSE_ERROR_INPUT_NOT_AT_END,
309 G_VARIANT_PARSE_ERROR_INVALID_CHARACTER,
310 G_VARIANT_PARSE_ERROR_INVALID_FORMAT_STRING,
311 G_VARIANT_PARSE_ERROR_INVALID_OBJECT_PATH,
312 G_VARIANT_PARSE_ERROR_INVALID_SIGNATURE,
313 G_VARIANT_PARSE_ERROR_INVALID_TYPE_STRING,
314 G_VARIANT_PARSE_ERROR_NO_COMMON_TYPE,
315 G_VARIANT_PARSE_ERROR_NUMBER_OUT_OF_RANGE,
316 G_VARIANT_PARSE_ERROR_NUMBER_TOO_BIG,
317 G_VARIANT_PARSE_ERROR_TYPE_ERROR,
318 G_VARIANT_PARSE_ERROR_UNEXPECTED_TOKEN,
319 G_VARIANT_PARSE_ERROR_UNKNOWN_KEYWORD,
320 G_VARIANT_PARSE_ERROR_UNTERMINATED_STRING_CONSTANT,
321 G_VARIANT_PARSE_ERROR_VALUE_EXPECTED
322 } GVariantParseError;
323 #define G_VARIANT_PARSE_ERROR (g_variant_parser_get_error_quark ())
325 GLIB_AVAILABLE_IN_ALL
326 GQuark g_variant_parser_get_error_quark (void);
328 GLIB_AVAILABLE_IN_ALL
329 GVariantBuilder * g_variant_builder_new (const GVariantType *type);
330 GLIB_AVAILABLE_IN_ALL
331 void g_variant_builder_unref (GVariantBuilder *builder);
332 GLIB_AVAILABLE_IN_ALL
333 GVariantBuilder * g_variant_builder_ref (GVariantBuilder *builder);
334 GLIB_AVAILABLE_IN_ALL
335 void g_variant_builder_init (GVariantBuilder *builder,
336 const GVariantType *type);
337 GLIB_AVAILABLE_IN_ALL
338 GVariant * g_variant_builder_end (GVariantBuilder *builder);
339 GLIB_AVAILABLE_IN_ALL
340 void g_variant_builder_clear (GVariantBuilder *builder);
341 GLIB_AVAILABLE_IN_ALL
342 void g_variant_builder_open (GVariantBuilder *builder,
343 const GVariantType *type);
344 GLIB_AVAILABLE_IN_ALL
345 void g_variant_builder_close (GVariantBuilder *builder);
346 GLIB_AVAILABLE_IN_ALL
347 void g_variant_builder_add_value (GVariantBuilder *builder,
349 GLIB_AVAILABLE_IN_ALL
350 void g_variant_builder_add (GVariantBuilder *builder,
351 const gchar *format_string,
353 GLIB_AVAILABLE_IN_ALL
354 void g_variant_builder_add_parsed (GVariantBuilder *builder,
358 GLIB_AVAILABLE_IN_ALL
359 GVariant * g_variant_new (const gchar *format_string,
361 GLIB_AVAILABLE_IN_ALL
362 void g_variant_get (GVariant *value,
363 const gchar *format_string,
365 GLIB_AVAILABLE_IN_ALL
366 GVariant * g_variant_new_va (const gchar *format_string,
367 const gchar **endptr,
369 GLIB_AVAILABLE_IN_ALL
370 void g_variant_get_va (GVariant *value,
371 const gchar *format_string,
372 const gchar **endptr,
374 GLIB_AVAILABLE_IN_2_34
375 gboolean g_variant_check_format_string (GVariant *value,
376 const gchar *format_string,
379 GLIB_AVAILABLE_IN_ALL
380 GVariant * g_variant_parse (const GVariantType *type,
383 const gchar **endptr,
385 GLIB_AVAILABLE_IN_ALL
386 GVariant * g_variant_new_parsed (const gchar *format,
388 GLIB_AVAILABLE_IN_ALL
389 GVariant * g_variant_new_parsed_va (const gchar *format,
392 GLIB_AVAILABLE_IN_ALL
393 gint g_variant_compare (gconstpointer one,
397 #endif /* __G_VARIANT_H__ */