gvariant: Add g_variant_get_fixed_array()
[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 #if defined(G_DISABLE_SINGLE_INCLUDES) && !defined (__GLIB_H_INSIDE__) && !defined (GLIB_COMPILATION)
24 #error "Only <glib.h> can be included directly."
25 #endif
26
27 #ifndef __G_VARIANT_H__
28 #define __G_VARIANT_H__
29
30 #include <glib/gvarianttype.h>
31 #include <glib/gstring.h>
32
33 G_BEGIN_DECLS
34
35 typedef struct _GVariant        GVariant;
36
37 typedef enum
38 {
39   G_VARIANT_CLASS_BOOLEAN       = 'b',
40   G_VARIANT_CLASS_BYTE          = 'y',
41   G_VARIANT_CLASS_INT16         = 'n',
42   G_VARIANT_CLASS_UINT16        = 'q',
43   G_VARIANT_CLASS_INT32         = 'i',
44   G_VARIANT_CLASS_UINT32        = 'u',
45   G_VARIANT_CLASS_INT64         = 'x',
46   G_VARIANT_CLASS_UINT64        = 't',
47   G_VARIANT_CLASS_HANDLE        = 'h',
48   G_VARIANT_CLASS_DOUBLE        = 'd',
49   G_VARIANT_CLASS_STRING        = 's',
50   G_VARIANT_CLASS_OBJECT_PATH   = 'o',
51   G_VARIANT_CLASS_SIGNATURE     = 'g',
52   G_VARIANT_CLASS_VARIANT       = 'v',
53   G_VARIANT_CLASS_MAYBE         = 'm',
54   G_VARIANT_CLASS_ARRAY         = 'a',
55   G_VARIANT_CLASS_TUPLE         = '(',
56   G_VARIANT_CLASS_DICT_ENTRY    = '{'
57 } GVariantClass;
58
59 void                            g_variant_unref                         (GVariant             *value);
60 GVariant *                      g_variant_ref                           (GVariant             *value);
61 GVariant *                      g_variant_ref_sink                      (GVariant             *value);
62 gboolean                        g_variant_is_floating                   (GVariant             *value);
63 GVariant *                      g_variant_take_ref                      (GVariant             *value);
64
65 const GVariantType *            g_variant_get_type                      (GVariant             *value);
66 const gchar *                   g_variant_get_type_string               (GVariant             *value);
67 gboolean                        g_variant_is_of_type                    (GVariant             *value,
68                                                                          const GVariantType   *type);
69 gboolean                        g_variant_is_container                  (GVariant             *value);
70 GVariantClass                   g_variant_classify                      (GVariant             *value);
71 GVariant *                      g_variant_new_boolean                   (gboolean              value);
72 GVariant *                      g_variant_new_byte                      (guchar                value);
73 GVariant *                      g_variant_new_int16                     (gint16                value);
74 GVariant *                      g_variant_new_uint16                    (guint16               value);
75 GVariant *                      g_variant_new_int32                     (gint32                value);
76 GVariant *                      g_variant_new_uint32                    (guint32               value);
77 GVariant *                      g_variant_new_int64                     (gint64                value);
78 GVariant *                      g_variant_new_uint64                    (guint64               value);
79 GVariant *                      g_variant_new_handle                    (gint32                value);
80 GVariant *                      g_variant_new_double                    (gdouble               value);
81 GVariant *                      g_variant_new_string                    (const gchar          *string);
82 GVariant *                      g_variant_new_object_path               (const gchar          *object_path);
83 gboolean                        g_variant_is_object_path                (const gchar          *string);
84 GVariant *                      g_variant_new_signature                 (const gchar          *signature);
85 gboolean                        g_variant_is_signature                  (const gchar          *string);
86 GVariant *                      g_variant_new_variant                   (GVariant             *value);
87 GVariant *                      g_variant_new_strv                      (const gchar * const  *strv,
88                                                                          gssize                length);
89 GVariant *                      g_variant_new_objv                      (const gchar * const  *strv,
90                                                                          gssize                length);
91 GVariant *                      g_variant_new_bytestring                (const gchar          *string);
92 GVariant *                      g_variant_new_bytestring_array          (const gchar * const  *strv,
93                                                                          gssize                length);
94 GVariant *                      g_variant_new_fixed_array               (const GVariantType   *element_type,
95                                                                          gconstpointer         elements,
96                                                                          gsize                 num_elements,
97                                                                          gsize                 element_size);
98 gboolean                        g_variant_get_boolean                   (GVariant             *value);
99 guchar                          g_variant_get_byte                      (GVariant             *value);
100 gint16                          g_variant_get_int16                     (GVariant             *value);
101 guint16                         g_variant_get_uint16                    (GVariant             *value);
102 gint32                          g_variant_get_int32                     (GVariant             *value);
103 guint32                         g_variant_get_uint32                    (GVariant             *value);
104 gint64                          g_variant_get_int64                     (GVariant             *value);
105 guint64                         g_variant_get_uint64                    (GVariant             *value);
106 gint32                          g_variant_get_handle                    (GVariant             *value);
107 gdouble                         g_variant_get_double                    (GVariant             *value);
108 GVariant *                      g_variant_get_variant                   (GVariant             *value);
109 const gchar *                   g_variant_get_string                    (GVariant             *value,
110                                                                          gsize                *length);
111 gchar *                         g_variant_dup_string                    (GVariant             *value,
112                                                                          gsize                *length);
113 const gchar **                  g_variant_get_strv                      (GVariant             *value,
114                                                                          gsize                *length);
115 gchar **                        g_variant_dup_strv                      (GVariant             *value,
116                                                                          gsize                *length);
117 const gchar **                  g_variant_get_objv                      (GVariant             *value,
118                                                                          gsize                *length);
119 gchar **                        g_variant_dup_objv                      (GVariant             *value,
120                                                                          gsize                *length);
121 const gchar *                   g_variant_get_bytestring                (GVariant             *value);
122 gchar *                         g_variant_dup_bytestring                (GVariant             *value,
123                                                                          gsize                *length);
124 const gchar **                  g_variant_get_bytestring_array          (GVariant             *value,
125                                                                          gsize                *length);
126 gchar **                        g_variant_dup_bytestring_array          (GVariant             *value,
127                                                                          gsize                *length);
128
129 GVariant *                      g_variant_new_maybe                     (const GVariantType   *child_type,
130                                                                          GVariant             *child);
131 GVariant *                      g_variant_new_array                     (const GVariantType   *child_type,
132                                                                          GVariant * const     *children,
133                                                                          gsize                 n_children);
134 GVariant *                      g_variant_new_tuple                     (GVariant * const     *children,
135                                                                          gsize                 n_children);
136 GVariant *                      g_variant_new_dict_entry                (GVariant             *key,
137                                                                          GVariant             *value);
138
139 GVariant *                      g_variant_get_maybe                     (GVariant             *value);
140 gsize                           g_variant_n_children                    (GVariant             *value);
141 void                            g_variant_get_child                     (GVariant             *value,
142                                                                          gsize                 index_,
143                                                                          const gchar          *format_string,
144                                                                          ...);
145 GVariant *                      g_variant_get_child_value               (GVariant             *value,
146                                                                          gsize                 index_);
147 gboolean                        g_variant_lookup                        (GVariant             *dictionary,
148                                                                          const gchar          *key,
149                                                                          const gchar          *format_string,
150                                                                          ...);
151 GVariant *                      g_variant_lookup_value                  (GVariant             *dictionary,
152                                                                          const gchar          *key,
153                                                                          const GVariantType   *expected_type);
154 gconstpointer                   g_variant_get_fixed_array               (GVariant             *value,
155                                                                          gsize                *n_elements,
156                                                                          gsize                 element_size);
157
158 gsize                           g_variant_get_size                      (GVariant             *value);
159 gconstpointer                   g_variant_get_data                      (GVariant             *value);
160 void                            g_variant_store                         (GVariant             *value,
161                                                                          gpointer              data);
162
163 gchar *                         g_variant_print                         (GVariant             *value,
164                                                                          gboolean              type_annotate);
165 GString *                       g_variant_print_string                  (GVariant             *value,
166                                                                          GString              *string,
167                                                                          gboolean              type_annotate);
168
169 guint                           g_variant_hash                          (gconstpointer         value);
170 gboolean                        g_variant_equal                         (gconstpointer         one,
171                                                                          gconstpointer         two);
172
173 GVariant *                      g_variant_get_normal_form               (GVariant             *value);
174 gboolean                        g_variant_is_normal_form                (GVariant             *value);
175 GVariant *                      g_variant_byteswap                      (GVariant             *value);
176 GVariant *                      g_variant_new_from_data                 (const GVariantType   *type,
177                                                                          gconstpointer         data,
178                                                                          gsize                 size,
179                                                                          gboolean              trusted,
180                                                                          GDestroyNotify        notify,
181                                                                          gpointer              user_data);
182
183 typedef struct _GVariantIter GVariantIter;
184 struct _GVariantIter {
185   /*< private >*/
186   gsize x[16];
187 };
188
189 GVariantIter *                  g_variant_iter_new                      (GVariant             *value);
190 gsize                           g_variant_iter_init                     (GVariantIter         *iter,
191                                                                          GVariant             *value);
192 GVariantIter *                  g_variant_iter_copy                     (GVariantIter         *iter);
193 gsize                           g_variant_iter_n_children               (GVariantIter         *iter);
194 void                            g_variant_iter_free                     (GVariantIter         *iter);
195 GVariant *                      g_variant_iter_next_value               (GVariantIter         *iter);
196 gboolean                        g_variant_iter_next                     (GVariantIter         *iter,
197                                                                          const gchar          *format_string,
198                                                                          ...);
199 gboolean                        g_variant_iter_loop                     (GVariantIter         *iter,
200                                                                          const gchar          *format_string,
201                                                                          ...);
202
203
204 typedef struct _GVariantBuilder GVariantBuilder;
205 struct _GVariantBuilder {
206   /*< private >*/
207   gsize x[16];
208 };
209
210 typedef enum
211 {
212   G_VARIANT_PARSE_ERROR_FAILED,
213   G_VARIANT_PARSE_ERROR_BASIC_TYPE_EXPECTED,
214   G_VARIANT_PARSE_ERROR_CANNOT_INFER_TYPE,
215   G_VARIANT_PARSE_ERROR_DEFINITE_TYPE_EXPECTED,
216   G_VARIANT_PARSE_ERROR_INPUT_NOT_AT_END,
217   G_VARIANT_PARSE_ERROR_INVALID_CHARACTER,
218   G_VARIANT_PARSE_ERROR_INVALID_FORMAT_STRING,
219   G_VARIANT_PARSE_ERROR_INVALID_OBJECT_PATH,
220   G_VARIANT_PARSE_ERROR_INVALID_SIGNATURE,
221   G_VARIANT_PARSE_ERROR_INVALID_TYPE_STRING,
222   G_VARIANT_PARSE_ERROR_NO_COMMON_TYPE,
223   G_VARIANT_PARSE_ERROR_NUMBER_OUT_OF_RANGE,
224   G_VARIANT_PARSE_ERROR_NUMBER_TOO_BIG,
225   G_VARIANT_PARSE_ERROR_TYPE_ERROR,
226   G_VARIANT_PARSE_ERROR_UNEXPECTED_TOKEN,
227   G_VARIANT_PARSE_ERROR_UNKNOWN_KEYWORD,
228   G_VARIANT_PARSE_ERROR_UNTERMINATED_STRING_CONSTANT,
229   G_VARIANT_PARSE_ERROR_VALUE_EXPECTED
230 } GVariantParseError;
231 #define G_VARIANT_PARSE_ERROR (g_variant_parser_get_error_quark ())
232
233 GQuark                          g_variant_parser_get_error_quark        (void);
234
235 GVariantBuilder *               g_variant_builder_new                   (const GVariantType   *type);
236 void                            g_variant_builder_unref                 (GVariantBuilder      *builder);
237 GVariantBuilder *               g_variant_builder_ref                   (GVariantBuilder      *builder);
238 void                            g_variant_builder_init                  (GVariantBuilder      *builder,
239                                                                          const GVariantType   *type);
240 GVariant *                      g_variant_builder_end                   (GVariantBuilder      *builder);
241 void                            g_variant_builder_clear                 (GVariantBuilder      *builder);
242 void                            g_variant_builder_open                  (GVariantBuilder      *builder,
243                                                                          const GVariantType   *type);
244 void                            g_variant_builder_close                 (GVariantBuilder      *builder);
245 void                            g_variant_builder_add_value             (GVariantBuilder      *builder,
246                                                                          GVariant             *value);
247 void                            g_variant_builder_add                   (GVariantBuilder      *builder,
248                                                                          const gchar          *format_string,
249                                                                          ...);
250 void                            g_variant_builder_add_parsed            (GVariantBuilder      *builder,
251                                                                          const gchar          *format,
252                                                                          ...);
253
254 GVariant *                      g_variant_new                           (const gchar          *format_string,
255                                                                          ...);
256 void                            g_variant_get                           (GVariant             *value,
257                                                                          const gchar          *format_string,
258                                                                          ...);
259 GVariant *                      g_variant_new_va                        (const gchar          *format_string,
260                                                                          const gchar         **endptr,
261                                                                          va_list              *app);
262 void                            g_variant_get_va                        (GVariant             *value,
263                                                                          const gchar          *format_string,
264                                                                          const gchar         **endptr,
265                                                                          va_list              *app);
266
267
268 GVariant *                      g_variant_parse                         (const GVariantType   *type,
269                                                                          const gchar          *text,
270                                                                          const gchar          *limit,
271                                                                          const gchar         **endptr,
272                                                                          GError              **error);
273 GVariant *                      g_variant_new_parsed                    (const gchar          *format,
274                                                                          ...);
275 GVariant *                      g_variant_new_parsed_va                 (const gchar          *format,
276                                                                          va_list              *app);
277
278 gint                            g_variant_compare                       (gconstpointer one,
279                                                                          gconstpointer two);
280 G_END_DECLS
281
282 #endif /* __G_VARIANT_H__ */