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_ALL
105 GVariant * g_variant_new_object_path (const gchar *object_path);
106 GLIB_AVAILABLE_IN_ALL
107 gboolean g_variant_is_object_path (const gchar *string);
108 GLIB_AVAILABLE_IN_ALL
109 GVariant * g_variant_new_signature (const gchar *signature);
110 GLIB_AVAILABLE_IN_ALL
111 gboolean g_variant_is_signature (const gchar *string);
112 GLIB_AVAILABLE_IN_ALL
113 GVariant * g_variant_new_variant (GVariant *value);
114 GLIB_AVAILABLE_IN_ALL
115 GVariant * g_variant_new_strv (const gchar * const *strv,
117 GLIB_AVAILABLE_IN_2_30
118 GVariant * g_variant_new_objv (const gchar * const *strv,
120 GLIB_AVAILABLE_IN_ALL
121 GVariant * g_variant_new_bytestring (const gchar *string);
122 GLIB_AVAILABLE_IN_ALL
123 GVariant * g_variant_new_bytestring_array (const gchar * const *strv,
125 GLIB_AVAILABLE_IN_ALL
126 GVariant * g_variant_new_fixed_array (const GVariantType *element_type,
127 gconstpointer elements,
130 GLIB_AVAILABLE_IN_ALL
131 gboolean g_variant_get_boolean (GVariant *value);
132 GLIB_AVAILABLE_IN_ALL
133 guchar g_variant_get_byte (GVariant *value);
134 GLIB_AVAILABLE_IN_ALL
135 gint16 g_variant_get_int16 (GVariant *value);
136 GLIB_AVAILABLE_IN_ALL
137 guint16 g_variant_get_uint16 (GVariant *value);
138 GLIB_AVAILABLE_IN_ALL
139 gint32 g_variant_get_int32 (GVariant *value);
140 GLIB_AVAILABLE_IN_ALL
141 guint32 g_variant_get_uint32 (GVariant *value);
142 GLIB_AVAILABLE_IN_ALL
143 gint64 g_variant_get_int64 (GVariant *value);
144 GLIB_AVAILABLE_IN_ALL
145 guint64 g_variant_get_uint64 (GVariant *value);
146 GLIB_AVAILABLE_IN_ALL
147 gint32 g_variant_get_handle (GVariant *value);
148 GLIB_AVAILABLE_IN_ALL
149 gdouble g_variant_get_double (GVariant *value);
150 GLIB_AVAILABLE_IN_ALL
151 GVariant * g_variant_get_variant (GVariant *value);
152 GLIB_AVAILABLE_IN_ALL
153 const gchar * g_variant_get_string (GVariant *value,
155 GLIB_AVAILABLE_IN_ALL
156 gchar * g_variant_dup_string (GVariant *value,
158 GLIB_AVAILABLE_IN_ALL
159 const gchar ** g_variant_get_strv (GVariant *value,
161 GLIB_AVAILABLE_IN_ALL
162 gchar ** g_variant_dup_strv (GVariant *value,
164 GLIB_AVAILABLE_IN_2_30
165 const gchar ** g_variant_get_objv (GVariant *value,
167 GLIB_AVAILABLE_IN_ALL
168 gchar ** g_variant_dup_objv (GVariant *value,
170 GLIB_AVAILABLE_IN_ALL
171 const gchar * g_variant_get_bytestring (GVariant *value);
172 GLIB_AVAILABLE_IN_ALL
173 gchar * g_variant_dup_bytestring (GVariant *value,
175 GLIB_AVAILABLE_IN_ALL
176 const gchar ** g_variant_get_bytestring_array (GVariant *value,
178 GLIB_AVAILABLE_IN_ALL
179 gchar ** g_variant_dup_bytestring_array (GVariant *value,
182 GLIB_AVAILABLE_IN_ALL
183 GVariant * g_variant_new_maybe (const GVariantType *child_type,
185 GLIB_AVAILABLE_IN_ALL
186 GVariant * g_variant_new_array (const GVariantType *child_type,
187 GVariant * const *children,
189 GLIB_AVAILABLE_IN_ALL
190 GVariant * g_variant_new_tuple (GVariant * const *children,
192 GLIB_AVAILABLE_IN_ALL
193 GVariant * g_variant_new_dict_entry (GVariant *key,
196 GLIB_AVAILABLE_IN_ALL
197 GVariant * g_variant_get_maybe (GVariant *value);
198 GLIB_AVAILABLE_IN_ALL
199 gsize g_variant_n_children (GVariant *value);
200 GLIB_AVAILABLE_IN_ALL
201 void g_variant_get_child (GVariant *value,
203 const gchar *format_string,
205 GLIB_AVAILABLE_IN_ALL
206 GVariant * g_variant_get_child_value (GVariant *value,
208 GLIB_AVAILABLE_IN_ALL
209 gboolean g_variant_lookup (GVariant *dictionary,
211 const gchar *format_string,
213 GLIB_AVAILABLE_IN_ALL
214 GVariant * g_variant_lookup_value (GVariant *dictionary,
216 const GVariantType *expected_type);
217 GLIB_AVAILABLE_IN_ALL
218 gconstpointer g_variant_get_fixed_array (GVariant *value,
222 GLIB_AVAILABLE_IN_ALL
223 gsize g_variant_get_size (GVariant *value);
224 GLIB_AVAILABLE_IN_ALL
225 gconstpointer g_variant_get_data (GVariant *value);
226 GLIB_AVAILABLE_IN_2_36
227 GBytes * g_variant_get_data_as_bytes (GVariant *value);
228 GLIB_AVAILABLE_IN_ALL
229 void g_variant_store (GVariant *value,
232 GLIB_AVAILABLE_IN_ALL
233 gchar * g_variant_print (GVariant *value,
234 gboolean type_annotate);
235 GLIB_AVAILABLE_IN_ALL
236 GString * g_variant_print_string (GVariant *value,
238 gboolean type_annotate);
240 GLIB_AVAILABLE_IN_ALL
241 guint g_variant_hash (gconstpointer value);
242 GLIB_AVAILABLE_IN_ALL
243 gboolean g_variant_equal (gconstpointer one,
246 GLIB_AVAILABLE_IN_ALL
247 GVariant * g_variant_get_normal_form (GVariant *value);
248 GLIB_AVAILABLE_IN_ALL
249 gboolean g_variant_is_normal_form (GVariant *value);
250 GLIB_AVAILABLE_IN_ALL
251 GVariant * g_variant_byteswap (GVariant *value);
253 GLIB_AVAILABLE_IN_2_36
254 GVariant * g_variant_new_from_bytes (const GVariantType *type,
257 GLIB_AVAILABLE_IN_ALL
258 GVariant * g_variant_new_from_data (const GVariantType *type,
262 GDestroyNotify notify,
265 typedef struct _GVariantIter GVariantIter;
266 struct _GVariantIter {
271 GLIB_AVAILABLE_IN_ALL
272 GVariantIter * g_variant_iter_new (GVariant *value);
273 GLIB_AVAILABLE_IN_ALL
274 gsize g_variant_iter_init (GVariantIter *iter,
276 GLIB_AVAILABLE_IN_ALL
277 GVariantIter * g_variant_iter_copy (GVariantIter *iter);
278 GLIB_AVAILABLE_IN_ALL
279 gsize g_variant_iter_n_children (GVariantIter *iter);
280 GLIB_AVAILABLE_IN_ALL
281 void g_variant_iter_free (GVariantIter *iter);
282 GLIB_AVAILABLE_IN_ALL
283 GVariant * g_variant_iter_next_value (GVariantIter *iter);
284 GLIB_AVAILABLE_IN_ALL
285 gboolean g_variant_iter_next (GVariantIter *iter,
286 const gchar *format_string,
288 GLIB_AVAILABLE_IN_ALL
289 gboolean g_variant_iter_loop (GVariantIter *iter,
290 const gchar *format_string,
294 typedef struct _GVariantBuilder GVariantBuilder;
295 struct _GVariantBuilder {
302 G_VARIANT_PARSE_ERROR_FAILED,
303 G_VARIANT_PARSE_ERROR_BASIC_TYPE_EXPECTED,
304 G_VARIANT_PARSE_ERROR_CANNOT_INFER_TYPE,
305 G_VARIANT_PARSE_ERROR_DEFINITE_TYPE_EXPECTED,
306 G_VARIANT_PARSE_ERROR_INPUT_NOT_AT_END,
307 G_VARIANT_PARSE_ERROR_INVALID_CHARACTER,
308 G_VARIANT_PARSE_ERROR_INVALID_FORMAT_STRING,
309 G_VARIANT_PARSE_ERROR_INVALID_OBJECT_PATH,
310 G_VARIANT_PARSE_ERROR_INVALID_SIGNATURE,
311 G_VARIANT_PARSE_ERROR_INVALID_TYPE_STRING,
312 G_VARIANT_PARSE_ERROR_NO_COMMON_TYPE,
313 G_VARIANT_PARSE_ERROR_NUMBER_OUT_OF_RANGE,
314 G_VARIANT_PARSE_ERROR_NUMBER_TOO_BIG,
315 G_VARIANT_PARSE_ERROR_TYPE_ERROR,
316 G_VARIANT_PARSE_ERROR_UNEXPECTED_TOKEN,
317 G_VARIANT_PARSE_ERROR_UNKNOWN_KEYWORD,
318 G_VARIANT_PARSE_ERROR_UNTERMINATED_STRING_CONSTANT,
319 G_VARIANT_PARSE_ERROR_VALUE_EXPECTED
320 } GVariantParseError;
321 #define G_VARIANT_PARSE_ERROR (g_variant_parser_get_error_quark ())
323 GLIB_AVAILABLE_IN_ALL
324 GQuark g_variant_parser_get_error_quark (void);
326 GLIB_AVAILABLE_IN_ALL
327 GVariantBuilder * g_variant_builder_new (const GVariantType *type);
328 GLIB_AVAILABLE_IN_ALL
329 void g_variant_builder_unref (GVariantBuilder *builder);
330 GLIB_AVAILABLE_IN_ALL
331 GVariantBuilder * g_variant_builder_ref (GVariantBuilder *builder);
332 GLIB_AVAILABLE_IN_ALL
333 void g_variant_builder_init (GVariantBuilder *builder,
334 const GVariantType *type);
335 GLIB_AVAILABLE_IN_ALL
336 GVariant * g_variant_builder_end (GVariantBuilder *builder);
337 GLIB_AVAILABLE_IN_ALL
338 void g_variant_builder_clear (GVariantBuilder *builder);
339 GLIB_AVAILABLE_IN_ALL
340 void g_variant_builder_open (GVariantBuilder *builder,
341 const GVariantType *type);
342 GLIB_AVAILABLE_IN_ALL
343 void g_variant_builder_close (GVariantBuilder *builder);
344 GLIB_AVAILABLE_IN_ALL
345 void g_variant_builder_add_value (GVariantBuilder *builder,
347 GLIB_AVAILABLE_IN_ALL
348 void g_variant_builder_add (GVariantBuilder *builder,
349 const gchar *format_string,
351 GLIB_AVAILABLE_IN_ALL
352 void g_variant_builder_add_parsed (GVariantBuilder *builder,
356 GLIB_AVAILABLE_IN_ALL
357 GVariant * g_variant_new (const gchar *format_string,
359 GLIB_AVAILABLE_IN_ALL
360 void g_variant_get (GVariant *value,
361 const gchar *format_string,
363 GLIB_AVAILABLE_IN_ALL
364 GVariant * g_variant_new_va (const gchar *format_string,
365 const gchar **endptr,
367 GLIB_AVAILABLE_IN_ALL
368 void g_variant_get_va (GVariant *value,
369 const gchar *format_string,
370 const gchar **endptr,
372 GLIB_AVAILABLE_IN_2_34
373 gboolean g_variant_check_format_string (GVariant *value,
374 const gchar *format_string,
377 GLIB_AVAILABLE_IN_ALL
378 GVariant * g_variant_parse (const GVariantType *type,
381 const gchar **endptr,
383 GLIB_AVAILABLE_IN_ALL
384 GVariant * g_variant_new_parsed (const gchar *format,
386 GLIB_AVAILABLE_IN_ALL
387 GVariant * g_variant_new_parsed_va (const gchar *format,
390 GLIB_AVAILABLE_IN_ALL
391 gint g_variant_compare (gconstpointer one,
395 #endif /* __G_VARIANT_H__ */