GVariant: add loading, byteswapping, normalisation
[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 #include <glib/gvarianttype.h>
27 #include <glib/gstring.h>
28
29 G_BEGIN_DECLS
30
31 typedef struct _GVariant        GVariant;
32
33 typedef enum
34 {
35   G_VARIANT_CLASS_BOOLEAN       = 'b',
36   G_VARIANT_CLASS_BYTE          = 'y',
37   G_VARIANT_CLASS_INT16         = 'n',
38   G_VARIANT_CLASS_UINT16        = 'q',
39   G_VARIANT_CLASS_INT32         = 'i',
40   G_VARIANT_CLASS_UINT32        = 'u',
41   G_VARIANT_CLASS_INT64         = 'x',
42   G_VARIANT_CLASS_UINT64        = 't',
43   G_VARIANT_CLASS_HANDLE        = 'h',
44   G_VARIANT_CLASS_DOUBLE        = 'd',
45   G_VARIANT_CLASS_STRING        = 's',
46   G_VARIANT_CLASS_OBJECT_PATH   = 'o',
47   G_VARIANT_CLASS_SIGNATURE     = 'g',
48   G_VARIANT_CLASS_VARIANT       = 'v',
49   G_VARIANT_CLASS_MAYBE         = 'm',
50   G_VARIANT_CLASS_ARRAY         = 'a',
51   G_VARIANT_CLASS_TUPLE         = '(',
52   G_VARIANT_CLASS_DICT_ENTRY    = '{'
53 } GVariantClass;
54
55 void                            g_variant_unref                         (GVariant             *value);
56 GVariant *                      g_variant_ref                           (GVariant             *value);
57 GVariant *                      g_variant_ref_sink                      (GVariant             *value);
58
59 const GVariantType *            g_variant_get_type                      (GVariant             *value);
60 const gchar *                   g_variant_get_type_string               (GVariant             *value);
61 gboolean                        g_variant_is_of_type                    (GVariant             *value,
62                                                                          const GVariantType   *type);
63 gboolean                        g_variant_is_container                  (GVariant             *value);
64 GVariantClass                   g_variant_classify                      (GVariant             *value);
65
66 GVariant *                      g_variant_new_boolean                   (gboolean              boolean);
67 GVariant *                      g_variant_new_byte                      (guchar                byte);
68 GVariant *                      g_variant_new_int16                     (gint16                int16);
69 GVariant *                      g_variant_new_uint16                    (guint16               uint16);
70 GVariant *                      g_variant_new_int32                     (gint32                int32);
71 GVariant *                      g_variant_new_uint32                    (guint32               uint32);
72 GVariant *                      g_variant_new_int64                     (gint64                int64);
73 GVariant *                      g_variant_new_uint64                    (guint64               uint64);
74 GVariant *                      g_variant_new_handle                    (gint32                handle);
75 GVariant *                      g_variant_new_double                    (gdouble               floating);
76 GVariant *                      g_variant_new_string                    (const gchar          *string);
77 GVariant *                      g_variant_new_object_path               (const gchar          *object_path);
78 gboolean                        g_variant_is_object_path                (const gchar          *string);
79 GVariant *                      g_variant_new_signature                 (const gchar          *signature);
80 gboolean                        g_variant_is_signature                  (const gchar          *string);
81 GVariant *                      g_variant_new_variant                   (GVariant             *value);
82 GVariant *                      g_variant_new_strv                      (const gchar * const  *strv,
83                                                                          gssize                length);
84
85 gboolean                        g_variant_get_boolean                   (GVariant             *value);
86 guchar                          g_variant_get_byte                      (GVariant             *value);
87 gint16                          g_variant_get_int16                     (GVariant             *value);
88 guint16                         g_variant_get_uint16                    (GVariant             *value);
89 gint32                          g_variant_get_int32                     (GVariant             *value);
90 guint32                         g_variant_get_uint32                    (GVariant             *value);
91 gint64                          g_variant_get_int64                     (GVariant             *value);
92 guint64                         g_variant_get_uint64                    (GVariant             *value);
93 gint32                          g_variant_get_handle                    (GVariant             *value);
94 gdouble                         g_variant_get_double                    (GVariant             *value);
95 GVariant *                      g_variant_get_variant                   (GVariant             *value);
96 const gchar *                   g_variant_get_string                    (GVariant             *value,
97                                                                          gsize                *length);
98 gchar *                         g_variant_dup_string                    (GVariant             *value,
99                                                                          gsize                *length);
100 const gchar **                  g_variant_get_strv                      (GVariant             *value,
101                                                                          gsize                *length);
102 gchar **                        g_variant_dup_strv                      (GVariant             *value,
103                                                                          gsize                *length);
104
105 GVariant *                      g_variant_new_maybe                     (const GVariantType   *child_type,
106                                                                          GVariant             *child);
107 GVariant *                      g_variant_new_array                     (const GVariantType   *child_type,
108                                                                          GVariant * const     *children,
109                                                                          gsize                 n_children);
110 GVariant *                      g_variant_new_tuple                     (GVariant * const     *children,
111                                                                          gsize                 n_children);
112 GVariant *                      g_variant_new_dict_entry                (GVariant             *key,
113                                                                          GVariant             *value);
114
115 GVariant *                      g_variant_get_maybe                     (GVariant             *value);
116 gsize                           g_variant_n_children                    (GVariant             *value);
117 void                            g_variant_get_child                     (GVariant             *value,
118                                                                          gsize                 index_,
119                                                                          const gchar          *format_string,
120                                                                          ...);
121 GVariant *                      g_variant_get_child_value               (GVariant             *value,
122                                                                          gsize                 index_);
123 gconstpointer                   g_variant_get_fixed_array               (GVariant             *value,
124                                                                          gsize                *n_elements,
125                                                                          gsize                 element_size);
126
127 gsize                           g_variant_get_size                      (GVariant             *value);
128 gconstpointer                   g_variant_get_data                      (GVariant             *value);
129 void                            g_variant_store                         (GVariant             *value,
130                                                                          gpointer              data);
131
132 gchar *                         g_variant_print                         (GVariant             *value,
133                                                                          gboolean              type_annotate);
134 GString *                       g_variant_print_string                  (GVariant             *value,
135                                                                          GString              *string,
136                                                                          gboolean              type_annotate);
137
138 guint                           g_variant_hash                          (gconstpointer         value);
139 gboolean                        g_variant_equal                         (gconstpointer         one,
140                                                                          gconstpointer         two);
141
142 GVariant *                      g_variant_get_normal_form               (GVariant             *variant);
143 gboolean                        g_variant_is_normal_form                (GVariant             *variant);
144 GVariant *                      g_variant_byteswap                      (GVariant             *variant);
145 GVariant *                      g_variant_new_from_data                 (const GVariantType   *type,
146                                                                          gconstpointer         data,
147                                                                          gsize                 size,
148                                                                          gboolean              trusted,
149                                                                          GDestroyNotify        notify,
150                                                                          gpointer              user_data);
151
152 typedef struct _GVariantIter GVariantIter;
153 struct _GVariantIter {
154   /*< private >*/
155   gsize x[16];
156 };
157
158 GVariantIter *                  g_variant_iter_new                      (GVariant             *value);
159 gsize                           g_variant_iter_init                     (GVariantIter         *iter,
160                                                                          GVariant             *value);
161 GVariantIter *                  g_variant_iter_copy                     (GVariantIter         *iter);
162 gsize                           g_variant_iter_n_children               (GVariantIter         *iter);
163 void                            g_variant_iter_free                     (GVariantIter         *iter);
164 GVariant *                      g_variant_iter_next_value               (GVariantIter         *iter);
165 gboolean                        g_variant_iter_next                     (GVariantIter         *iter,
166                                                                          const gchar          *format_string,
167                                                                          ...);
168 gboolean                        g_variant_iter_loop                     (GVariantIter         *iter,
169                                                                          const gchar          *format_string,
170                                                                          ...);
171
172
173 typedef struct _GVariantBuilder GVariantBuilder;
174 struct _GVariantBuilder {
175   /*< private >*/
176   gsize x[16];
177 };
178
179 GVariantBuilder *               g_variant_builder_new                   (const GVariantType   *type);
180 void                            g_variant_builder_unref                 (GVariantBuilder      *builder);
181 GVariantBuilder *               g_variant_builder_ref                   (GVariantBuilder      *builder);
182 void                            g_variant_builder_init                  (GVariantBuilder      *builder,
183                                                                          const GVariantType   *type);
184 GVariant *                      g_variant_builder_end                   (GVariantBuilder      *builder);
185 void                            g_variant_builder_clear                 (GVariantBuilder      *builder);
186 void                            g_variant_builder_open                  (GVariantBuilder      *builder,
187                                                                          const GVariantType   *type);
188 void                            g_variant_builder_close                 (GVariantBuilder      *builder);
189 void                            g_variant_builder_add_value             (GVariantBuilder      *builder,
190                                                                          GVariant             *value);
191 void                            g_variant_builder_add                   (GVariantBuilder      *builder,
192                                                                          const gchar          *format_string,
193                                                                          ...);
194
195 GVariant *                      g_variant_new                           (const gchar          *format_string,
196                                                                          ...);
197 void                            g_variant_get                           (GVariant             *value,
198                                                                          const gchar          *format_string,
199                                                                          ...);
200 GVariant *                      g_variant_new_va                        (const gchar          *format_string,
201                                                                          const gchar         **endptr,
202                                                                          va_list              *app);
203 void                            g_variant_get_va                        (GVariant             *value,
204                                                                          const gchar          *format_string,
205                                                                          const gchar         **endptr,
206                                                                          va_list              *app);
207
208
209 G_END_DECLS
210
211 #endif /* __G_VARIANT_H__ */