Corrected a GLIB_AVAILABLE_IN_*
[platform/upstream/glib.git] / glib / gvariant.h
1 /*
2  * Copyright © 2007, 2008 Ryan Lortie
3  * Copyright © 2009, 2010 Codethink Limited
4  *
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.
9  *
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.
14  *
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.
19  *
20  * Author: Ryan Lortie <desrt@desrt.ca>
21  */
22
23 #ifndef __G_VARIANT_H__
24 #define __G_VARIANT_H__
25
26 #if !defined (__GLIB_H_INSIDE__) && !defined (GLIB_COMPILATION)
27 #error "Only <glib.h> can be included directly."
28 #endif
29
30 #include <glib/gvarianttype.h>
31 #include <glib/gstring.h>
32 #include <glib/gbytes.h>
33
34 G_BEGIN_DECLS
35
36 typedef struct _GVariant        GVariant;
37
38 typedef enum
39 {
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    = '{'
58 } GVariantClass;
59
60 GLIB_AVAILABLE_IN_ALL
61 void                            g_variant_unref                         (GVariant             *value);
62 GLIB_AVAILABLE_IN_ALL
63 GVariant *                      g_variant_ref                           (GVariant             *value);
64 GLIB_AVAILABLE_IN_ALL
65 GVariant *                      g_variant_ref_sink                      (GVariant             *value);
66 GLIB_AVAILABLE_IN_ALL
67 gboolean                        g_variant_is_floating                   (GVariant             *value);
68 GLIB_AVAILABLE_IN_ALL
69 GVariant *                      g_variant_take_ref                      (GVariant             *value);
70
71 GLIB_AVAILABLE_IN_ALL
72 const GVariantType *            g_variant_get_type                      (GVariant             *value);
73 GLIB_AVAILABLE_IN_ALL
74 const gchar *                   g_variant_get_type_string               (GVariant             *value);
75 GLIB_AVAILABLE_IN_ALL
76 gboolean                        g_variant_is_of_type                    (GVariant             *value,
77                                                                          const GVariantType   *type);
78 GLIB_AVAILABLE_IN_ALL
79 gboolean                        g_variant_is_container                  (GVariant             *value);
80 GLIB_AVAILABLE_IN_ALL
81 GVariantClass                   g_variant_classify                      (GVariant             *value);
82 GLIB_AVAILABLE_IN_ALL
83 GVariant *                      g_variant_new_boolean                   (gboolean              value);
84 GLIB_AVAILABLE_IN_ALL
85 GVariant *                      g_variant_new_byte                      (guchar                value);
86 GLIB_AVAILABLE_IN_ALL
87 GVariant *                      g_variant_new_int16                     (gint16                value);
88 GLIB_AVAILABLE_IN_ALL
89 GVariant *                      g_variant_new_uint16                    (guint16               value);
90 GLIB_AVAILABLE_IN_ALL
91 GVariant *                      g_variant_new_int32                     (gint32                value);
92 GLIB_AVAILABLE_IN_ALL
93 GVariant *                      g_variant_new_uint32                    (guint32               value);
94 GLIB_AVAILABLE_IN_ALL
95 GVariant *                      g_variant_new_int64                     (gint64                value);
96 GLIB_AVAILABLE_IN_ALL
97 GVariant *                      g_variant_new_uint64                    (guint64               value);
98 GLIB_AVAILABLE_IN_ALL
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,
116                                                                          gssize                length);
117 GLIB_AVAILABLE_IN_2_30
118 GVariant *                      g_variant_new_objv                      (const gchar * const  *strv,
119                                                                          gssize                length);
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,
124                                                                          gssize                length);
125 GLIB_AVAILABLE_IN_ALL
126 GVariant *                      g_variant_new_fixed_array               (const GVariantType   *element_type,
127                                                                          gconstpointer         elements,
128                                                                          gsize                 n_elements,
129                                                                          gsize                 element_size);
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,
154                                                                          gsize                *length);
155 GLIB_AVAILABLE_IN_ALL
156 gchar *                         g_variant_dup_string                    (GVariant             *value,
157                                                                          gsize                *length);
158 GLIB_AVAILABLE_IN_ALL
159 const gchar **                  g_variant_get_strv                      (GVariant             *value,
160                                                                          gsize                *length);
161 GLIB_AVAILABLE_IN_ALL
162 gchar **                        g_variant_dup_strv                      (GVariant             *value,
163                                                                          gsize                *length);
164 GLIB_AVAILABLE_IN_2_30
165 const gchar **                  g_variant_get_objv                      (GVariant             *value,
166                                                                          gsize                *length);
167 GLIB_AVAILABLE_IN_ALL
168 gchar **                        g_variant_dup_objv                      (GVariant             *value,
169                                                                          gsize                *length);
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,
174                                                                          gsize                *length);
175 GLIB_AVAILABLE_IN_ALL
176 const gchar **                  g_variant_get_bytestring_array          (GVariant             *value,
177                                                                          gsize                *length);
178 GLIB_AVAILABLE_IN_ALL
179 gchar **                        g_variant_dup_bytestring_array          (GVariant             *value,
180                                                                          gsize                *length);
181
182 GLIB_AVAILABLE_IN_ALL
183 GVariant *                      g_variant_new_maybe                     (const GVariantType   *child_type,
184                                                                          GVariant             *child);
185 GLIB_AVAILABLE_IN_ALL
186 GVariant *                      g_variant_new_array                     (const GVariantType   *child_type,
187                                                                          GVariant * const     *children,
188                                                                          gsize                 n_children);
189 GLIB_AVAILABLE_IN_ALL
190 GVariant *                      g_variant_new_tuple                     (GVariant * const     *children,
191                                                                          gsize                 n_children);
192 GLIB_AVAILABLE_IN_ALL
193 GVariant *                      g_variant_new_dict_entry                (GVariant             *key,
194                                                                          GVariant             *value);
195
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,
202                                                                          gsize                 index_,
203                                                                          const gchar          *format_string,
204                                                                          ...);
205 GLIB_AVAILABLE_IN_ALL
206 GVariant *                      g_variant_get_child_value               (GVariant             *value,
207                                                                          gsize                 index_);
208 GLIB_AVAILABLE_IN_ALL
209 gboolean                        g_variant_lookup                        (GVariant             *dictionary,
210                                                                          const gchar          *key,
211                                                                          const gchar          *format_string,
212                                                                          ...);
213 GLIB_AVAILABLE_IN_ALL
214 GVariant *                      g_variant_lookup_value                  (GVariant             *dictionary,
215                                                                          const gchar          *key,
216                                                                          const GVariantType   *expected_type);
217 GLIB_AVAILABLE_IN_ALL
218 gconstpointer                   g_variant_get_fixed_array               (GVariant             *value,
219                                                                          gsize                *n_elements,
220                                                                          gsize                 element_size);
221
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,
230                                                                          gpointer              data);
231
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,
237                                                                          GString              *string,
238                                                                          gboolean              type_annotate);
239
240 GLIB_AVAILABLE_IN_ALL
241 guint                           g_variant_hash                          (gconstpointer         value);
242 GLIB_AVAILABLE_IN_ALL
243 gboolean                        g_variant_equal                         (gconstpointer         one,
244                                                                          gconstpointer         two);
245
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);
252
253 GLIB_AVAILABLE_IN_2_36
254 GVariant *                      g_variant_new_from_bytes                (const GVariantType   *type,
255                                                                          GBytes               *bytes,
256                                                                          gboolean              trusted);
257 GLIB_AVAILABLE_IN_ALL
258 GVariant *                      g_variant_new_from_data                 (const GVariantType   *type,
259                                                                          gconstpointer         data,
260                                                                          gsize                 size,
261                                                                          gboolean              trusted,
262                                                                          GDestroyNotify        notify,
263                                                                          gpointer              user_data);
264
265 typedef struct _GVariantIter GVariantIter;
266 struct _GVariantIter {
267   /*< private >*/
268   gsize x[16];
269 };
270
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,
275                                                                          GVariant             *value);
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,
287                                                                          ...);
288 GLIB_AVAILABLE_IN_ALL
289 gboolean                        g_variant_iter_loop                     (GVariantIter         *iter,
290                                                                          const gchar          *format_string,
291                                                                          ...);
292
293
294 typedef struct _GVariantBuilder GVariantBuilder;
295 struct _GVariantBuilder {
296   /*< private >*/
297   gsize x[16];
298 };
299
300 typedef enum
301 {
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 ())
322
323 GLIB_AVAILABLE_IN_ALL
324 GQuark                          g_variant_parser_get_error_quark        (void);
325
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,
346                                                                          GVariant             *value);
347 GLIB_AVAILABLE_IN_ALL
348 void                            g_variant_builder_add                   (GVariantBuilder      *builder,
349                                                                          const gchar          *format_string,
350                                                                          ...);
351 GLIB_AVAILABLE_IN_ALL
352 void                            g_variant_builder_add_parsed            (GVariantBuilder      *builder,
353                                                                          const gchar          *format,
354                                                                          ...);
355
356 GLIB_AVAILABLE_IN_ALL
357 GVariant *                      g_variant_new                           (const gchar          *format_string,
358                                                                          ...);
359 GLIB_AVAILABLE_IN_ALL
360 void                            g_variant_get                           (GVariant             *value,
361                                                                          const gchar          *format_string,
362                                                                          ...);
363 GLIB_AVAILABLE_IN_ALL
364 GVariant *                      g_variant_new_va                        (const gchar          *format_string,
365                                                                          const gchar         **endptr,
366                                                                          va_list              *app);
367 GLIB_AVAILABLE_IN_ALL
368 void                            g_variant_get_va                        (GVariant             *value,
369                                                                          const gchar          *format_string,
370                                                                          const gchar         **endptr,
371                                                                          va_list              *app);
372 GLIB_AVAILABLE_IN_2_34
373 gboolean                        g_variant_check_format_string           (GVariant             *value,
374                                                                          const gchar          *format_string,
375                                                                          gboolean              copy_only);
376
377 GLIB_AVAILABLE_IN_ALL
378 GVariant *                      g_variant_parse                         (const GVariantType   *type,
379                                                                          const gchar          *text,
380                                                                          const gchar          *limit,
381                                                                          const gchar         **endptr,
382                                                                          GError              **error);
383 GLIB_AVAILABLE_IN_ALL
384 GVariant *                      g_variant_new_parsed                    (const gchar          *format,
385                                                                          ...);
386 GLIB_AVAILABLE_IN_ALL
387 GVariant *                      g_variant_new_parsed_va                 (const gchar          *format,
388                                                                          va_list              *app);
389
390 GLIB_AVAILABLE_IN_ALL
391 gint                            g_variant_compare                       (gconstpointer one,
392                                                                          gconstpointer two);
393 G_END_DECLS
394
395 #endif /* __G_VARIANT_H__ */