glib/glib/gvariant.h

295 lines
21 KiB
C
Raw Normal View History

2010-02-10 17:13:06 +01:00
/*
* Copyright © 2007, 2008 Ryan Lortie
* Copyright © 2009, 2010 Codethink Limited
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the licence, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*
* Author: Ryan Lortie <desrt@desrt.ca>
*/
#ifndef __G_VARIANT_H__
#define __G_VARIANT_H__
#if !defined (__GLIB_H_INSIDE__) && !defined (GLIB_COMPILATION)
#error "Only <glib.h> can be included directly."
#endif
2010-02-10 17:13:06 +01:00
#include <glib/gvarianttype.h>
2010-02-19 16:42:53 +01:00
#include <glib/gstring.h>
#include <glib/gbytes.h>
2010-02-10 17:13:06 +01:00
G_BEGIN_DECLS
typedef struct _GVariant GVariant;
2010-02-19 16:42:53 +01:00
typedef enum
{
G_VARIANT_CLASS_BOOLEAN = 'b',
G_VARIANT_CLASS_BYTE = 'y',
G_VARIANT_CLASS_INT16 = 'n',
G_VARIANT_CLASS_UINT16 = 'q',
G_VARIANT_CLASS_INT32 = 'i',
G_VARIANT_CLASS_UINT32 = 'u',
G_VARIANT_CLASS_INT64 = 'x',
G_VARIANT_CLASS_UINT64 = 't',
G_VARIANT_CLASS_HANDLE = 'h',
G_VARIANT_CLASS_DOUBLE = 'd',
G_VARIANT_CLASS_STRING = 's',
G_VARIANT_CLASS_OBJECT_PATH = 'o',
G_VARIANT_CLASS_SIGNATURE = 'g',
G_VARIANT_CLASS_VARIANT = 'v',
G_VARIANT_CLASS_MAYBE = 'm',
G_VARIANT_CLASS_ARRAY = 'a',
G_VARIANT_CLASS_TUPLE = '(',
G_VARIANT_CLASS_DICT_ENTRY = '{'
} GVariantClass;
2010-02-10 17:13:06 +01:00
void g_variant_unref (GVariant *value);
GVariant * g_variant_ref (GVariant *value);
GVariant * g_variant_ref_sink (GVariant *value);
2010-06-19 16:42:11 +02:00
gboolean g_variant_is_floating (GVariant *value);
GVariant * g_variant_take_ref (GVariant *value);
2010-02-10 17:13:06 +01:00
2010-02-19 16:42:53 +01:00
const GVariantType * g_variant_get_type (GVariant *value);
const gchar * g_variant_get_type_string (GVariant *value);
gboolean g_variant_is_of_type (GVariant *value,
const GVariantType *type);
gboolean g_variant_is_container (GVariant *value);
GVariantClass g_variant_classify (GVariant *value);
GVariant * g_variant_new_boolean (gboolean value);
GVariant * g_variant_new_byte (guchar value);
GVariant * g_variant_new_int16 (gint16 value);
GVariant * g_variant_new_uint16 (guint16 value);
GVariant * g_variant_new_int32 (gint32 value);
GVariant * g_variant_new_uint32 (guint32 value);
GVariant * g_variant_new_int64 (gint64 value);
GVariant * g_variant_new_uint64 (guint64 value);
GVariant * g_variant_new_handle (gint32 value);
GVariant * g_variant_new_double (gdouble value);
2010-02-19 16:42:53 +01:00
GVariant * g_variant_new_string (const gchar *string);
GVariant * g_variant_new_object_path (const gchar *object_path);
gboolean g_variant_is_object_path (const gchar *string);
GVariant * g_variant_new_signature (const gchar *signature);
gboolean g_variant_is_signature (const gchar *string);
GVariant * g_variant_new_variant (GVariant *value);
GVariant * g_variant_new_strv (const gchar * const *strv,
gssize length);
GLIB_AVAILABLE_IN_2_30
GVariant * g_variant_new_objv (const gchar * const *strv,
gssize length);
GVariant * g_variant_new_bytestring (const gchar *string);
GVariant * g_variant_new_bytestring_array (const gchar * const *strv,
gssize length);
GVariant * g_variant_new_fixed_array (const GVariantType *element_type,
gconstpointer elements,
2011-10-06 18:19:58 +02:00
gsize n_elements,
gsize element_size);
2010-02-19 16:42:53 +01:00
gboolean g_variant_get_boolean (GVariant *value);
guchar g_variant_get_byte (GVariant *value);
gint16 g_variant_get_int16 (GVariant *value);
guint16 g_variant_get_uint16 (GVariant *value);
gint32 g_variant_get_int32 (GVariant *value);
guint32 g_variant_get_uint32 (GVariant *value);
gint64 g_variant_get_int64 (GVariant *value);
guint64 g_variant_get_uint64 (GVariant *value);
gint32 g_variant_get_handle (GVariant *value);
gdouble g_variant_get_double (GVariant *value);
GVariant * g_variant_get_variant (GVariant *value);
const gchar * g_variant_get_string (GVariant *value,
gsize *length);
gchar * g_variant_dup_string (GVariant *value,
gsize *length);
const gchar ** g_variant_get_strv (GVariant *value,
gsize *length);
gchar ** g_variant_dup_strv (GVariant *value,
gsize *length);
GLIB_AVAILABLE_IN_2_30
const gchar ** g_variant_get_objv (GVariant *value,
gsize *length);
gchar ** g_variant_dup_objv (GVariant *value,
gsize *length);
const gchar * g_variant_get_bytestring (GVariant *value);
gchar * g_variant_dup_bytestring (GVariant *value,
gsize *length);
const gchar ** g_variant_get_bytestring_array (GVariant *value,
gsize *length);
gchar ** g_variant_dup_bytestring_array (GVariant *value,
gsize *length);
2010-02-19 16:42:53 +01:00
GVariant * g_variant_new_maybe (const GVariantType *child_type,
GVariant *child);
GVariant * g_variant_new_array (const GVariantType *child_type,
GVariant * const *children,
gsize n_children);
GVariant * g_variant_new_tuple (GVariant * const *children,
gsize n_children);
GVariant * g_variant_new_dict_entry (GVariant *key,
GVariant *value);
GVariant * g_variant_get_maybe (GVariant *value);
2010-02-10 17:13:06 +01:00
gsize g_variant_n_children (GVariant *value);
void g_variant_get_child (GVariant *value,
gsize index_,
const gchar *format_string,
...);
2010-02-10 17:13:06 +01:00
GVariant * g_variant_get_child_value (GVariant *value,
2010-02-19 16:42:53 +01:00
gsize index_);
2010-11-27 12:45:45 +01:00
gboolean g_variant_lookup (GVariant *dictionary,
const gchar *key,
const gchar *format_string,
...);
2010-11-27 12:45:45 +01:00
GVariant * g_variant_lookup_value (GVariant *dictionary,
const gchar *key,
2010-11-27 12:45:45 +01:00
const GVariantType *expected_type);
2010-02-19 16:42:53 +01:00
gconstpointer g_variant_get_fixed_array (GVariant *value,
gsize *n_elements,
gsize element_size);
2010-02-10 17:13:06 +01:00
gsize g_variant_get_size (GVariant *value);
gconstpointer g_variant_get_data (GVariant *value);
GLIB_AVAILABLE_IN_2_36
GBytes * g_variant_get_data_as_bytes (GVariant *value);
2010-02-10 17:13:06 +01:00
void g_variant_store (GVariant *value,
gpointer data);
2010-02-19 16:42:53 +01:00
gchar * g_variant_print (GVariant *value,
gboolean type_annotate);
GString * g_variant_print_string (GVariant *value,
GString *string,
gboolean type_annotate);
guint g_variant_hash (gconstpointer value);
gboolean g_variant_equal (gconstpointer one,
gconstpointer two);
2010-03-21 19:46:09 +01:00
GVariant * g_variant_get_normal_form (GVariant *value);
gboolean g_variant_is_normal_form (GVariant *value);
GVariant * g_variant_byteswap (GVariant *value);
GLIB_AVAILABLE_IN_2_36
GVariant * g_variant_new_from_bytes (const GVariantType *type,
GBytes *bytes,
gboolean trusted);
GVariant * g_variant_new_from_data (const GVariantType *type,
gconstpointer data,
gsize size,
gboolean trusted,
GDestroyNotify notify,
gpointer user_data);
2010-02-22 06:39:01 +01:00
typedef struct _GVariantIter GVariantIter;
struct _GVariantIter {
/*< private >*/
gsize x[16];
2010-02-22 06:39:01 +01:00
};
GVariantIter * g_variant_iter_new (GVariant *value);
gsize g_variant_iter_init (GVariantIter *iter,
GVariant *value);
GVariantIter * g_variant_iter_copy (GVariantIter *iter);
gsize g_variant_iter_n_children (GVariantIter *iter);
void g_variant_iter_free (GVariantIter *iter);
GVariant * g_variant_iter_next_value (GVariantIter *iter);
gboolean g_variant_iter_next (GVariantIter *iter,
const gchar *format_string,
...);
gboolean g_variant_iter_loop (GVariantIter *iter,
const gchar *format_string,
...);
typedef struct _GVariantBuilder GVariantBuilder;
struct _GVariantBuilder {
/*< private >*/
gsize x[16];
};
2010-02-22 06:39:01 +01:00
2010-06-20 18:30:27 +02:00
typedef enum
{
G_VARIANT_PARSE_ERROR_FAILED,
G_VARIANT_PARSE_ERROR_BASIC_TYPE_EXPECTED,
G_VARIANT_PARSE_ERROR_CANNOT_INFER_TYPE,
G_VARIANT_PARSE_ERROR_DEFINITE_TYPE_EXPECTED,
G_VARIANT_PARSE_ERROR_INPUT_NOT_AT_END,
G_VARIANT_PARSE_ERROR_INVALID_CHARACTER,
G_VARIANT_PARSE_ERROR_INVALID_FORMAT_STRING,
G_VARIANT_PARSE_ERROR_INVALID_OBJECT_PATH,
G_VARIANT_PARSE_ERROR_INVALID_SIGNATURE,
G_VARIANT_PARSE_ERROR_INVALID_TYPE_STRING,
G_VARIANT_PARSE_ERROR_NO_COMMON_TYPE,
G_VARIANT_PARSE_ERROR_NUMBER_OUT_OF_RANGE,
G_VARIANT_PARSE_ERROR_NUMBER_TOO_BIG,
G_VARIANT_PARSE_ERROR_TYPE_ERROR,
G_VARIANT_PARSE_ERROR_UNEXPECTED_TOKEN,
G_VARIANT_PARSE_ERROR_UNKNOWN_KEYWORD,
G_VARIANT_PARSE_ERROR_UNTERMINATED_STRING_CONSTANT,
G_VARIANT_PARSE_ERROR_VALUE_EXPECTED
2010-06-20 18:30:27 +02:00
} GVariantParseError;
2010-03-21 18:31:46 +01:00
#define G_VARIANT_PARSE_ERROR (g_variant_parser_get_error_quark ())
2010-06-20 18:30:27 +02:00
2010-03-21 18:31:46 +01:00
GQuark g_variant_parser_get_error_quark (void);
GVariantBuilder * g_variant_builder_new (const GVariantType *type);
2010-02-22 06:39:01 +01:00
void g_variant_builder_unref (GVariantBuilder *builder);
GVariantBuilder * g_variant_builder_ref (GVariantBuilder *builder);
void g_variant_builder_init (GVariantBuilder *builder,
const GVariantType *type);
2010-02-22 06:39:01 +01:00
GVariant * g_variant_builder_end (GVariantBuilder *builder);
void g_variant_builder_clear (GVariantBuilder *builder);
void g_variant_builder_open (GVariantBuilder *builder,
2010-02-22 06:39:01 +01:00
const GVariantType *type);
void g_variant_builder_close (GVariantBuilder *builder);
2010-02-22 06:39:01 +01:00
void g_variant_builder_add_value (GVariantBuilder *builder,
GVariant *value);
void g_variant_builder_add (GVariantBuilder *builder,
const gchar *format_string,
...);
void g_variant_builder_add_parsed (GVariantBuilder *builder,
const gchar *format,
...);
2010-02-22 06:39:01 +01:00
GVariant * g_variant_new (const gchar *format_string,
...);
void g_variant_get (GVariant *value,
const gchar *format_string,
...);
GVariant * g_variant_new_va (const gchar *format_string,
const gchar **endptr,
va_list *app);
void g_variant_get_va (GVariant *value,
const gchar *format_string,
const gchar **endptr,
va_list *app);
gboolean g_variant_check_format_string (GVariant *value,
const gchar *format_string,
gboolean copy_only);
2010-03-21 18:31:46 +01:00
GVariant * g_variant_parse (const GVariantType *type,
const gchar *text,
const gchar *limit,
const gchar **endptr,
GError **error);
GVariant * g_variant_new_parsed (const gchar *format,
...);
GVariant * g_variant_new_parsed_va (const gchar *format,
va_list *app);
2010-04-23 02:48:24 +02:00
gint g_variant_compare (gconstpointer one,
gconstpointer two);
2010-02-10 17:13:06 +01:00
G_END_DECLS
#endif /* __G_VARIANT_H__ */