GApplication: set prgname to appid for services
[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_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,
118                                                                          gssize                length);
119 GLIB_AVAILABLE_IN_2_30
120 GVariant *                      g_variant_new_objv                      (const gchar * const  *strv,
121                                                                          gssize                length);
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,
126                                                                          gssize                length);
127 GLIB_AVAILABLE_IN_ALL
128 GVariant *                      g_variant_new_fixed_array               (const GVariantType   *element_type,
129                                                                          gconstpointer         elements,
130                                                                          gsize                 n_elements,
131                                                                          gsize                 element_size);
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,
156                                                                          gsize                *length);
157 GLIB_AVAILABLE_IN_ALL
158 gchar *                         g_variant_dup_string                    (GVariant             *value,
159                                                                          gsize                *length);
160 GLIB_AVAILABLE_IN_ALL
161 const gchar **                  g_variant_get_strv                      (GVariant             *value,
162                                                                          gsize                *length);
163 GLIB_AVAILABLE_IN_ALL
164 gchar **                        g_variant_dup_strv                      (GVariant             *value,
165                                                                          gsize                *length);
166 GLIB_AVAILABLE_IN_2_30
167 const gchar **                  g_variant_get_objv                      (GVariant             *value,
168                                                                          gsize                *length);
169 GLIB_AVAILABLE_IN_ALL
170 gchar **                        g_variant_dup_objv                      (GVariant             *value,
171                                                                          gsize                *length);
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,
176                                                                          gsize                *length);
177 GLIB_AVAILABLE_IN_ALL
178 const gchar **                  g_variant_get_bytestring_array          (GVariant             *value,
179                                                                          gsize                *length);
180 GLIB_AVAILABLE_IN_ALL
181 gchar **                        g_variant_dup_bytestring_array          (GVariant             *value,
182                                                                          gsize                *length);
183
184 GLIB_AVAILABLE_IN_ALL
185 GVariant *                      g_variant_new_maybe                     (const GVariantType   *child_type,
186                                                                          GVariant             *child);
187 GLIB_AVAILABLE_IN_ALL
188 GVariant *                      g_variant_new_array                     (const GVariantType   *child_type,
189                                                                          GVariant * const     *children,
190                                                                          gsize                 n_children);
191 GLIB_AVAILABLE_IN_ALL
192 GVariant *                      g_variant_new_tuple                     (GVariant * const     *children,
193                                                                          gsize                 n_children);
194 GLIB_AVAILABLE_IN_ALL
195 GVariant *                      g_variant_new_dict_entry                (GVariant             *key,
196                                                                          GVariant             *value);
197
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,
204                                                                          gsize                 index_,
205                                                                          const gchar          *format_string,
206                                                                          ...);
207 GLIB_AVAILABLE_IN_ALL
208 GVariant *                      g_variant_get_child_value               (GVariant             *value,
209                                                                          gsize                 index_);
210 GLIB_AVAILABLE_IN_ALL
211 gboolean                        g_variant_lookup                        (GVariant             *dictionary,
212                                                                          const gchar          *key,
213                                                                          const gchar          *format_string,
214                                                                          ...);
215 GLIB_AVAILABLE_IN_ALL
216 GVariant *                      g_variant_lookup_value                  (GVariant             *dictionary,
217                                                                          const gchar          *key,
218                                                                          const GVariantType   *expected_type);
219 GLIB_AVAILABLE_IN_ALL
220 gconstpointer                   g_variant_get_fixed_array               (GVariant             *value,
221                                                                          gsize                *n_elements,
222                                                                          gsize                 element_size);
223
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,
232                                                                          gpointer              data);
233
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,
239                                                                          GString              *string,
240                                                                          gboolean              type_annotate);
241
242 GLIB_AVAILABLE_IN_ALL
243 guint                           g_variant_hash                          (gconstpointer         value);
244 GLIB_AVAILABLE_IN_ALL
245 gboolean                        g_variant_equal                         (gconstpointer         one,
246                                                                          gconstpointer         two);
247
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);
254
255 GLIB_AVAILABLE_IN_2_36
256 GVariant *                      g_variant_new_from_bytes                (const GVariantType   *type,
257                                                                          GBytes               *bytes,
258                                                                          gboolean              trusted);
259 GLIB_AVAILABLE_IN_ALL
260 GVariant *                      g_variant_new_from_data                 (const GVariantType   *type,
261                                                                          gconstpointer         data,
262                                                                          gsize                 size,
263                                                                          gboolean              trusted,
264                                                                          GDestroyNotify        notify,
265                                                                          gpointer              user_data);
266
267 typedef struct _GVariantIter GVariantIter;
268 struct _GVariantIter {
269   /*< private >*/
270   gsize x[16];
271 };
272
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,
277                                                                          GVariant             *value);
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,
289                                                                          ...);
290 GLIB_AVAILABLE_IN_ALL
291 gboolean                        g_variant_iter_loop                     (GVariantIter         *iter,
292                                                                          const gchar          *format_string,
293                                                                          ...);
294
295
296 typedef struct _GVariantBuilder GVariantBuilder;
297 struct _GVariantBuilder {
298   /*< private >*/
299   gsize x[16];
300 };
301
302 typedef enum
303 {
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 ())
324
325 GLIB_AVAILABLE_IN_ALL
326 GQuark                          g_variant_parser_get_error_quark        (void);
327
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,
348                                                                          GVariant             *value);
349 GLIB_AVAILABLE_IN_ALL
350 void                            g_variant_builder_add                   (GVariantBuilder      *builder,
351                                                                          const gchar          *format_string,
352                                                                          ...);
353 GLIB_AVAILABLE_IN_ALL
354 void                            g_variant_builder_add_parsed            (GVariantBuilder      *builder,
355                                                                          const gchar          *format,
356                                                                          ...);
357
358 GLIB_AVAILABLE_IN_ALL
359 GVariant *                      g_variant_new                           (const gchar          *format_string,
360                                                                          ...);
361 GLIB_AVAILABLE_IN_ALL
362 void                            g_variant_get                           (GVariant             *value,
363                                                                          const gchar          *format_string,
364                                                                          ...);
365 GLIB_AVAILABLE_IN_ALL
366 GVariant *                      g_variant_new_va                        (const gchar          *format_string,
367                                                                          const gchar         **endptr,
368                                                                          va_list              *app);
369 GLIB_AVAILABLE_IN_ALL
370 void                            g_variant_get_va                        (GVariant             *value,
371                                                                          const gchar          *format_string,
372                                                                          const gchar         **endptr,
373                                                                          va_list              *app);
374 GLIB_AVAILABLE_IN_2_34
375 gboolean                        g_variant_check_format_string           (GVariant             *value,
376                                                                          const gchar          *format_string,
377                                                                          gboolean              copy_only);
378
379 GLIB_AVAILABLE_IN_ALL
380 GVariant *                      g_variant_parse                         (const GVariantType   *type,
381                                                                          const gchar          *text,
382                                                                          const gchar          *limit,
383                                                                          const gchar         **endptr,
384                                                                          GError              **error);
385 GLIB_AVAILABLE_IN_ALL
386 GVariant *                      g_variant_new_parsed                    (const gchar          *format,
387                                                                          ...);
388 GLIB_AVAILABLE_IN_ALL
389 GVariant *                      g_variant_new_parsed_va                 (const gchar          *format,
390                                                                          va_list              *app);
391
392 GLIB_AVAILABLE_IN_ALL
393 gint                            g_variant_compare                       (gconstpointer one,
394                                                                          gconstpointer two);
395 G_END_DECLS
396
397 #endif /* __G_VARIANT_H__ */