/* Portal.c generated by valac 0.56.18-dirty, the Vala compiler
 * generated from Portal.vala, do not modify */

/*
 * Copyright 2021 elementary, Inc. (https://elementary.io)
 * SPDX-License-Identifier: LGPL-3.0-or-later
 */

#include <stdlib.h>
#include <string.h>
#include <glib.h>
#include <glib-object.h>
#include <gio/gio.h>
#include "granite-7.h"

#define GRANITE_PORTAL_DBUS_DESKTOP_PATH "/org/freedesktop/portal/desktop"
#define GRANITE_PORTAL_DBUS_DESKTOP_NAME "org.freedesktop.portal.Desktop"
#if !defined(VALA_STRICT_C)
#if !defined(__clang__) && defined(__GNUC__) && (__GNUC__ >= 14)
#pragma GCC diagnostic warning "-Wincompatible-pointer-types"
#elif defined(__clang__) && (__clang_major__ >= 16)
#pragma clang diagnostic ignored "-Wincompatible-function-pointer-types"
#pragma clang diagnostic ignored "-Wincompatible-pointer-types"
#endif
#endif

#define GRANITE_PORTAL_TYPE_SETTINGS (granite_portal_settings_get_type ())
#define GRANITE_PORTAL_SETTINGS(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GRANITE_PORTAL_TYPE_SETTINGS, GranitePortalSettings))
#define GRANITE_PORTAL_IS_SETTINGS(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GRANITE_PORTAL_TYPE_SETTINGS))
#define GRANITE_PORTAL_SETTINGS_GET_INTERFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), GRANITE_PORTAL_TYPE_SETTINGS, GranitePortalSettingsIface))

typedef struct _GranitePortalSettings GranitePortalSettings;
typedef struct _GranitePortalSettingsIface GranitePortalSettingsIface;

#define GRANITE_PORTAL_TYPE_SETTINGS_PROXY (granite_portal_settings_proxy_get_type ())
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
enum  {
	GRANITE_PORTAL_SETTINGS_SETTING_CHANGED_SIGNAL,
	GRANITE_PORTAL_SETTINGS_NUM_SIGNALS
};
static guint granite_portal_settings_signals[GRANITE_PORTAL_SETTINGS_NUM_SIGNALS] = {0};
typedef GDBusProxy GranitePortalSettingsProxy;
typedef GDBusProxyClass GranitePortalSettingsProxyClass;
#define _g_free0(var) (var = (g_free (var), NULL))
#define _g_variant_unref0(var) ((var == NULL) ? NULL : (var = (g_variant_unref (var), NULL)))
#define _g_hash_table_unref0(var) ((var == NULL) ? NULL : (var = (g_hash_table_unref (var), NULL)))

struct _GranitePortalSettingsIface {
	GTypeInterface parent_iface;
	GHashTable* (*read_all) (GranitePortalSettings* self, gchar** namespaces, gint namespaces_length1, GError** error);
	GVariant* (*read) (GranitePortalSettings* self, const gchar* namespace, const gchar* key, GError** error);
};

VALA_EXTERN GType granite_portal_settings_proxy_get_type (void) G_GNUC_CONST ;
 G_GNUC_INTERNAL guint granite_portal_settings_register_object (void* object,
                                               GDBusConnection* connection,
                                               const gchar* path,
                                               GError** error);
 G_GNUC_INTERNAL GType granite_portal_settings_get_type (void) G_GNUC_CONST  G_GNUC_UNUSED ;
 G_GNUC_INTERNAL GranitePortalSettings* granite_portal_settings_get (GError** error);
 G_GNUC_INTERNAL GHashTable* granite_portal_settings_read_all (GranitePortalSettings* self,
                                              gchar** namespaces,
                                              gint namespaces_length1,
                                              GError** error);
 G_GNUC_INTERNAL GVariant* granite_portal_settings_read (GranitePortalSettings* self,
                                        const gchar* namespace,
                                        const gchar* key,
                                        GError** error);
static void g_cclosure_user_marshal_VOID__STRING_STRING_VARIANT (GClosure * closure,
                                                          GValue * return_value,
                                                          guint n_param_values,
                                                          const GValue * param_values,
                                                          gpointer invocation_hint,
                                                          gpointer marshal_data);
static GType granite_portal_settings_get_type_once (void);
static void granite_portal_settings_proxy_g_signal (GDBusProxy* proxy,
                                             const gchar* sender_name,
                                             const gchar* signal_name,
                                             GVariant* parameters);
static void _dbus_handle_granite_portal_settings_setting_changed (GranitePortalSettings* self,
                                                           GVariant* parameters);
static GHashTable* granite_portal_settings_proxy_read_all (GranitePortalSettings* self,
                                                    gchar** namespaces,
                                                    gint namespaces_length1,
                                                    GError** error);
static GVariant* granite_portal_settings_proxy_read (GranitePortalSettings* self,
                                              const gchar* namespace,
                                              const gchar* key,
                                              GError** error);
static void granite_portal_settings_proxy_granite_portal_settings_interface_init (GranitePortalSettingsIface* iface);
static void _dbus_granite_portal_settings_read_all (GranitePortalSettings* self,
                                             GVariant* _parameters_,
                                             GDBusMethodInvocation* invocation);
static void _dbus_granite_portal_settings_read (GranitePortalSettings* self,
                                         GVariant* _parameters_,
                                         GDBusMethodInvocation* invocation);
static void granite_portal_settings_dbus_interface_method_call (GDBusConnection* connection,
                                                         const gchar* sender,
                                                         const gchar* object_path,
                                                         const gchar* interface_name,
                                                         const gchar* method_name,
                                                         GVariant* parameters,
                                                         GDBusMethodInvocation* invocation,
                                                         gpointer user_data);
static GVariant* granite_portal_settings_dbus_interface_get_property (GDBusConnection* connection,
                                                               const gchar* sender,
                                                               const gchar* object_path,
                                                               const gchar* interface_name,
                                                               const gchar* property_name,
                                                               GError** error,
                                                               gpointer user_data);
static gboolean granite_portal_settings_dbus_interface_set_property (GDBusConnection* connection,
                                                              const gchar* sender,
                                                              const gchar* object_path,
                                                              const gchar* interface_name,
                                                              const gchar* property_name,
                                                              GVariant* value,
                                                              GError** error,
                                                              gpointer user_data);
static void _dbus_granite_portal_settings_setting_changed (GObject* _sender,
                                                    const gchar* namespace,
                                                    const gchar* key,
                                                    GVariant* value,
                                                    gpointer* _data);
static void _granite_portal_settings_unregister_object (gpointer user_data);
static void _vala_array_destroy (gpointer array,
                          gssize array_length,
                          GDestroyNotify destroy_func);
static void _vala_array_free (gpointer array,
                       gssize array_length,
                       GDestroyNotify destroy_func);

static const GDBusArgInfo _granite_portal_settings_dbus_arg_info_read_all_namespaces = {-1, "namespaces", "as", NULL};
static const GDBusArgInfo _granite_portal_settings_dbus_arg_info_read_all_result = {-1, "result", "a{sa{sv}}", NULL};
static const GDBusArgInfo * const _granite_portal_settings_dbus_arg_info_read_all_in[] = {&_granite_portal_settings_dbus_arg_info_read_all_namespaces, NULL};
static const GDBusArgInfo * const _granite_portal_settings_dbus_arg_info_read_all_out[] = {&_granite_portal_settings_dbus_arg_info_read_all_result, NULL};
static const GDBusMethodInfo _granite_portal_settings_dbus_method_info_read_all = {-1, "ReadAll", (GDBusArgInfo **) (&_granite_portal_settings_dbus_arg_info_read_all_in), (GDBusArgInfo **) (&_granite_portal_settings_dbus_arg_info_read_all_out), NULL};
static const GDBusArgInfo _granite_portal_settings_dbus_arg_info_read_namespace = {-1, "namespace", "s", NULL};
static const GDBusArgInfo _granite_portal_settings_dbus_arg_info_read_key = {-1, "key", "s", NULL};
static const GDBusArgInfo _granite_portal_settings_dbus_arg_info_read_result = {-1, "result", "v", NULL};
static const GDBusArgInfo * const _granite_portal_settings_dbus_arg_info_read_in[] = {&_granite_portal_settings_dbus_arg_info_read_namespace, &_granite_portal_settings_dbus_arg_info_read_key, NULL};
static const GDBusArgInfo * const _granite_portal_settings_dbus_arg_info_read_out[] = {&_granite_portal_settings_dbus_arg_info_read_result, NULL};
static const GDBusMethodInfo _granite_portal_settings_dbus_method_info_read = {-1, "Read", (GDBusArgInfo **) (&_granite_portal_settings_dbus_arg_info_read_in), (GDBusArgInfo **) (&_granite_portal_settings_dbus_arg_info_read_out), NULL};
static const GDBusMethodInfo * const _granite_portal_settings_dbus_method_info[] = {&_granite_portal_settings_dbus_method_info_read_all, &_granite_portal_settings_dbus_method_info_read, NULL};
static const GDBusArgInfo _granite_portal_settings_dbus_arg_info_setting_changed_namespace = {-1, "namespace", "s", NULL};
static const GDBusArgInfo _granite_portal_settings_dbus_arg_info_setting_changed_key = {-1, "key", "s", NULL};
static const GDBusArgInfo _granite_portal_settings_dbus_arg_info_setting_changed_value = {-1, "value", "v", NULL};
static const GDBusArgInfo * const _granite_portal_settings_dbus_arg_info_setting_changed[] = {&_granite_portal_settings_dbus_arg_info_setting_changed_namespace, &_granite_portal_settings_dbus_arg_info_setting_changed_key, &_granite_portal_settings_dbus_arg_info_setting_changed_value, NULL};
static const GDBusSignalInfo _granite_portal_settings_dbus_signal_info_setting_changed = {-1, "SettingChanged", (GDBusArgInfo **) (&_granite_portal_settings_dbus_arg_info_setting_changed), NULL};
static const GDBusSignalInfo * const _granite_portal_settings_dbus_signal_info[] = {&_granite_portal_settings_dbus_signal_info_setting_changed, NULL};
static const GDBusPropertyInfo * const _granite_portal_settings_dbus_property_info[] = {NULL};
static const GDBusInterfaceInfo _granite_portal_settings_dbus_interface_info = {-1, "org.freedesktop.portal.Settings", (GDBusMethodInfo **) (&_granite_portal_settings_dbus_method_info), (GDBusSignalInfo **) (&_granite_portal_settings_dbus_signal_info), (GDBusPropertyInfo **) (&_granite_portal_settings_dbus_property_info), NULL};
static const GDBusInterfaceVTable _granite_portal_settings_dbus_interface_vtable = {granite_portal_settings_dbus_interface_method_call, granite_portal_settings_dbus_interface_get_property, granite_portal_settings_dbus_interface_set_property};

 G_GNUC_INTERNAL GranitePortalSettings*
granite_portal_settings_get (GError** error)
{
	GranitePortalSettings* _tmp0_ = NULL;
	GranitePortalSettings* _tmp1_;
	GranitePortalSettings* _tmp2_;
	GError* _inner_error0_ = NULL;
	GranitePortalSettings* result;
	_tmp1_ = (GranitePortalSettings*) g_initable_new (GRANITE_PORTAL_TYPE_SETTINGS_PROXY, NULL, &_inner_error0_, "g-flags", G_DBUS_PROXY_FLAGS_NONE, "g-name", GRANITE_PORTAL_DBUS_DESKTOP_NAME, "g-bus-type", G_BUS_TYPE_SESSION, "g-object-path", GRANITE_PORTAL_DBUS_DESKTOP_PATH, "g-interface-name", "org.freedesktop.portal.Settings", NULL);
	_tmp0_ = (GranitePortalSettings*) _tmp1_;
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		return NULL;
	}
	_tmp2_ = _tmp0_;
	_tmp0_ = NULL;
	result = _tmp2_;
	_g_object_unref0 (_tmp0_);
	return result;
}

GHashTable*
granite_portal_settings_read_all (GranitePortalSettings* self,
                                  gchar** namespaces,
                                  gint namespaces_length1,
                                  GError** error)
{
	GranitePortalSettingsIface* _iface_;
	g_return_val_if_fail (self != NULL, NULL);
	_iface_ = GRANITE_PORTAL_SETTINGS_GET_INTERFACE (self);
	if (_iface_->read_all) {
		return _iface_->read_all (self, namespaces, namespaces_length1, error);
	}
	return NULL;
}

GVariant*
granite_portal_settings_read (GranitePortalSettings* self,
                              const gchar* namespace,
                              const gchar* key,
                              GError** error)
{
	GranitePortalSettingsIface* _iface_;
	g_return_val_if_fail (self != NULL, NULL);
	_iface_ = GRANITE_PORTAL_SETTINGS_GET_INTERFACE (self);
	if (_iface_->read) {
		return _iface_->read (self, namespace, key, error);
	}
	return NULL;
}

static void
g_cclosure_user_marshal_VOID__STRING_STRING_VARIANT (GClosure * closure,
                                                     GValue * return_value,
                                                     guint n_param_values,
                                                     const GValue * param_values,
                                                     gpointer invocation_hint,
                                                     gpointer marshal_data)
{
	typedef void (*GMarshalFunc_VOID__STRING_STRING_VARIANT) (gpointer data1, const char* arg_1, const char* arg_2, gpointer arg_3, gpointer data2);
	register GMarshalFunc_VOID__STRING_STRING_VARIANT callback;
	register GCClosure * cc;
	register gpointer data1;
	register gpointer data2;
	cc = (GCClosure *) closure;
	g_return_if_fail (n_param_values == 4);
	if (G_CCLOSURE_SWAP_DATA (closure)) {
		data1 = closure->data;
		data2 = param_values->data[0].v_pointer;
	} else {
		data1 = param_values->data[0].v_pointer;
		data2 = closure->data;
	}
	callback = (GMarshalFunc_VOID__STRING_STRING_VARIANT) (marshal_data ? marshal_data : cc->callback);
	callback (data1, g_value_get_string (param_values + 1), g_value_get_string (param_values + 2), g_value_get_variant (param_values + 3), data2);
}

static void
granite_portal_settings_default_init (GranitePortalSettingsIface * iface,
                                      gpointer iface_data)
{
	granite_portal_settings_signals[GRANITE_PORTAL_SETTINGS_SETTING_CHANGED_SIGNAL] = g_signal_new ("setting-changed", GRANITE_PORTAL_TYPE_SETTINGS, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_user_marshal_VOID__STRING_STRING_VARIANT, G_TYPE_NONE, 3, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_VARIANT);
}

static GType
granite_portal_settings_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (GranitePortalSettingsIface), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) granite_portal_settings_default_init, (GClassFinalizeFunc) NULL, NULL, 0, 0, (GInstanceInitFunc) NULL, NULL };
	GType granite_portal_settings_type_id;
	granite_portal_settings_type_id = g_type_register_static (G_TYPE_INTERFACE, "GranitePortalSettings", &g_define_type_info, 0);
	g_type_interface_add_prerequisite (granite_portal_settings_type_id, G_TYPE_OBJECT);
	g_type_set_qdata (granite_portal_settings_type_id, g_quark_from_static_string ("vala-dbus-proxy-type"), (void*) granite_portal_settings_proxy_get_type);
	g_type_set_qdata (granite_portal_settings_type_id, g_quark_from_static_string ("vala-dbus-interface-name"), "org.freedesktop.portal.Settings");
	g_type_set_qdata (granite_portal_settings_type_id, g_quark_from_static_string ("vala-dbus-interface-info"), (void*) (&_granite_portal_settings_dbus_interface_info));
	g_type_set_qdata (granite_portal_settings_type_id, g_quark_from_static_string ("vala-dbus-register-object"), (void*) granite_portal_settings_register_object);
	return granite_portal_settings_type_id;
}

 G_GNUC_INTERNAL GType
granite_portal_settings_get_type (void)
{
	static volatile gsize granite_portal_settings_type_id__once = 0;
	if (g_once_init_enter (&granite_portal_settings_type_id__once)) {
		GType granite_portal_settings_type_id;
		granite_portal_settings_type_id = granite_portal_settings_get_type_once ();
		g_once_init_leave (&granite_portal_settings_type_id__once, granite_portal_settings_type_id);
	}
	return granite_portal_settings_type_id__once;
}

G_DEFINE_TYPE_EXTENDED (GranitePortalSettingsProxy, granite_portal_settings_proxy, G_TYPE_DBUS_PROXY, 0, G_IMPLEMENT_INTERFACE (GRANITE_PORTAL_TYPE_SETTINGS, granite_portal_settings_proxy_granite_portal_settings_interface_init) )
static void
granite_portal_settings_proxy_class_init (GranitePortalSettingsProxyClass* klass)
{
	G_DBUS_PROXY_CLASS (klass)->g_signal = granite_portal_settings_proxy_g_signal;
}

static void
_dbus_handle_granite_portal_settings_setting_changed (GranitePortalSettings* self,
                                                      GVariant* parameters)
{
	GVariantIter _arguments_iter;
	gchar* namespace = NULL;
	GVariant* _tmp68_;
	gchar* key = NULL;
	GVariant* _tmp69_;
	GVariant* value = NULL;
	GVariant* _tmp70_;
	g_variant_iter_init (&_arguments_iter, parameters);
	_tmp68_ = g_variant_iter_next_value (&_arguments_iter);
	namespace = g_variant_dup_string (_tmp68_, NULL);
	g_variant_unref (_tmp68_);
	_tmp69_ = g_variant_iter_next_value (&_arguments_iter);
	key = g_variant_dup_string (_tmp69_, NULL);
	g_variant_unref (_tmp69_);
	_tmp70_ = g_variant_iter_next_value (&_arguments_iter);
	value = g_variant_get_variant (_tmp70_);
	g_variant_unref (_tmp70_);
	g_signal_emit_by_name (self, "setting-changed", namespace, key, value);
	_g_free0 (namespace);
	_g_free0 (key);
	_g_variant_unref0 (value);
}

static void
granite_portal_settings_proxy_g_signal (GDBusProxy* proxy,
                                        const gchar* sender_name,
                                        const gchar* signal_name,
                                        GVariant* parameters)
{
	if (strcmp (signal_name, "SettingChanged") == 0) {
		_dbus_handle_granite_portal_settings_setting_changed ((GranitePortalSettings*) proxy, parameters);
	}
}

static void
granite_portal_settings_proxy_init (GranitePortalSettingsProxy* self)
{
	g_dbus_proxy_set_interface_info (G_DBUS_PROXY (self), (GDBusInterfaceInfo *) (&_granite_portal_settings_dbus_interface_info));
}

static GHashTable*
granite_portal_settings_proxy_read_all (GranitePortalSettings* self,
                                        gchar** namespaces,
                                        gint namespaces_length1,
                                        GError** error)
{
	GDBusMessage *_message;
	GVariant *_arguments;
	GVariantBuilder _arguments_builder;
	gchar** _tmp71_;
	GVariantBuilder _tmp72_;
	gint _tmp73_;
	GDBusMessage *_reply_message;
	GVariant *_reply;
	GVariantIter _reply_iter;
	GHashTable* _result = NULL;
	GVariant* _tmp74_;
	GHashTable* _tmp75_;
	GVariantIter _tmp76_;
	GVariant* _tmp77_;
	GVariant* _tmp78_;
	G_DBUS_ERROR;
	G_IO_ERROR;
	_message = g_dbus_message_new_method_call (g_dbus_proxy_get_name ((GDBusProxy *) self), g_dbus_proxy_get_object_path ((GDBusProxy *) self), "org.freedesktop.portal.Settings", "ReadAll");
	g_variant_builder_init (&_arguments_builder, G_VARIANT_TYPE_TUPLE);
	_tmp71_ = namespaces;
	g_variant_builder_init (&_tmp72_, G_VARIANT_TYPE ("as"));
	for (_tmp73_ = 0; _tmp73_ < namespaces_length1; _tmp73_++) {
		g_variant_builder_add_value (&_tmp72_, g_variant_new_string (*_tmp71_));
		_tmp71_++;
	}
	g_variant_builder_add_value (&_arguments_builder, g_variant_builder_end (&_tmp72_));
	_arguments = g_variant_builder_end (&_arguments_builder);
	g_dbus_message_set_body (_message, _arguments);
	_reply_message = g_dbus_connection_send_message_with_reply_sync (g_dbus_proxy_get_connection ((GDBusProxy *) self), _message, G_DBUS_SEND_MESSAGE_FLAGS_NONE, g_dbus_proxy_get_default_timeout ((GDBusProxy *) self), NULL, NULL, error);
	g_object_unref (_message);
	if (!_reply_message) {
		return NULL;
	}
	if (g_dbus_message_to_gerror (_reply_message, error)) {
		g_object_unref (_reply_message);
		return NULL;
	}
	_reply = g_dbus_message_get_body (_reply_message);
	g_variant_iter_init (&_reply_iter, _reply);
	_tmp74_ = g_variant_iter_next_value (&_reply_iter);
	_tmp75_ = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, (GDestroyNotify) g_hash_table_unref);
	g_variant_iter_init (&_tmp76_, _tmp74_);
	while (g_variant_iter_loop (&_tmp76_, "{?*}", &_tmp77_, &_tmp78_)) {
		GHashTable* _tmp79_;
		GVariantIter _tmp80_;
		GVariant* _tmp81_;
		GVariant* _tmp82_;
		_tmp79_ = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, (GDestroyNotify) g_variant_unref);
		g_variant_iter_init (&_tmp80_, _tmp78_);
		while (g_variant_iter_loop (&_tmp80_, "{?*}", &_tmp81_, &_tmp82_)) {
			g_hash_table_insert (_tmp79_, g_variant_dup_string (_tmp81_, NULL), g_variant_get_variant (_tmp82_));
		}
		g_hash_table_insert (_tmp75_, g_variant_dup_string (_tmp77_, NULL), _tmp79_);
	}
	_result = _tmp75_;
	g_variant_unref (_tmp74_);
	g_object_unref (_reply_message);
	return _result;
}

static GVariant*
granite_portal_settings_proxy_read (GranitePortalSettings* self,
                                    const gchar* namespace,
                                    const gchar* key,
                                    GError** error)
{
	GDBusMessage *_message;
	GVariant *_arguments;
	GVariantBuilder _arguments_builder;
	GDBusMessage *_reply_message;
	GVariant *_reply;
	GVariantIter _reply_iter;
	GVariant* _result = NULL;
	GVariant* _tmp83_;
	G_DBUS_ERROR;
	G_IO_ERROR;
	_message = g_dbus_message_new_method_call (g_dbus_proxy_get_name ((GDBusProxy *) self), g_dbus_proxy_get_object_path ((GDBusProxy *) self), "org.freedesktop.portal.Settings", "Read");
	g_variant_builder_init (&_arguments_builder, G_VARIANT_TYPE_TUPLE);
	g_variant_builder_add_value (&_arguments_builder, g_variant_new_string (namespace));
	g_variant_builder_add_value (&_arguments_builder, g_variant_new_string (key));
	_arguments = g_variant_builder_end (&_arguments_builder);
	g_dbus_message_set_body (_message, _arguments);
	_reply_message = g_dbus_connection_send_message_with_reply_sync (g_dbus_proxy_get_connection ((GDBusProxy *) self), _message, G_DBUS_SEND_MESSAGE_FLAGS_NONE, g_dbus_proxy_get_default_timeout ((GDBusProxy *) self), NULL, NULL, error);
	g_object_unref (_message);
	if (!_reply_message) {
		return NULL;
	}
	if (g_dbus_message_to_gerror (_reply_message, error)) {
		g_object_unref (_reply_message);
		return NULL;
	}
	_reply = g_dbus_message_get_body (_reply_message);
	g_variant_iter_init (&_reply_iter, _reply);
	_tmp83_ = g_variant_iter_next_value (&_reply_iter);
	_result = g_variant_get_variant (_tmp83_);
	g_variant_unref (_tmp83_);
	g_object_unref (_reply_message);
	return _result;
}

static void
granite_portal_settings_proxy_granite_portal_settings_interface_init (GranitePortalSettingsIface* iface)
{
	iface->read_all = granite_portal_settings_proxy_read_all;
	iface->read = granite_portal_settings_proxy_read;
}

static void
_dbus_granite_portal_settings_read_all (GranitePortalSettings* self,
                                        GVariant* _parameters_,
                                        GDBusMethodInvocation* invocation)
{
	GError* error = NULL;
	GVariantIter _arguments_iter;
	gchar** namespaces = NULL;
	gint namespaces_length1 = 0;
	GVariant* _tmp84_;
	gchar** _tmp85_;
	gint _tmp85__length;
	gint _tmp85__size;
	gint _tmp85__length1;
	GVariantIter _tmp86_;
	GVariant* _tmp87_;
	GDBusMessage* _reply_message = NULL;
	GVariant* _reply;
	GVariantBuilder _reply_builder;
	GHashTable* result;
	GVariantBuilder _tmp88_;
	GHashTableIter _tmp89_;
	gpointer _tmp90_;
	gpointer _tmp91_;
	g_variant_iter_init (&_arguments_iter, _parameters_);
	_tmp84_ = g_variant_iter_next_value (&_arguments_iter);
	_tmp85_ = g_new (gchar*, 5);
	_tmp85__length = 0;
	_tmp85__size = 4;
	_tmp85__length1 = 0;
	g_variant_iter_init (&_tmp86_, _tmp84_);
	for (; (_tmp87_ = g_variant_iter_next_value (&_tmp86_)) != NULL; _tmp85__length1++) {
		if (_tmp85__size == _tmp85__length) {
			_tmp85__size = 2 * _tmp85__size;
			_tmp85_ = g_renew (gchar*, _tmp85_, _tmp85__size + 1);
		}
		_tmp85_[_tmp85__length++] = g_variant_dup_string (_tmp87_, NULL);
		g_variant_unref (_tmp87_);
	}
	namespaces_length1 = _tmp85__length1;
	_tmp85_[_tmp85__length] = NULL;
	namespaces = _tmp85_;
	g_variant_unref (_tmp84_);
	result = granite_portal_settings_read_all (self, namespaces, namespaces_length1, &error);
	if (error) {
		g_dbus_method_invocation_take_error (invocation, error);
		goto _error;
	}
	_reply_message = g_dbus_message_new_method_reply (g_dbus_method_invocation_get_message (invocation));
	g_variant_builder_init (&_reply_builder, G_VARIANT_TYPE_TUPLE);
	g_hash_table_iter_init (&_tmp89_, result);
	g_variant_builder_init (&_tmp88_, G_VARIANT_TYPE ("a{sa{sv}}"));
	while (g_hash_table_iter_next (&_tmp89_, &_tmp90_, &_tmp91_)) {
		gchar* _key;
		GHashTable* _value;
		GVariantBuilder _tmp92_;
		GHashTableIter _tmp93_;
		gpointer _tmp94_;
		gpointer _tmp95_;
		_key = (gchar*) _tmp90_;
		_value = (GHashTable*) _tmp91_;
		g_hash_table_iter_init (&_tmp93_, _value);
		g_variant_builder_init (&_tmp92_, G_VARIANT_TYPE ("a{sv}"));
		while (g_hash_table_iter_next (&_tmp93_, &_tmp94_, &_tmp95_)) {
			gchar* _key;
			GVariant* _value;
			_key = (gchar*) _tmp94_;
			_value = (GVariant*) _tmp95_;
			g_variant_builder_add (&_tmp92_, "{?*}", g_variant_new_string (_key), g_variant_new_variant (_value));
		}
		g_variant_builder_add (&_tmp88_, "{?*}", g_variant_new_string (_key), g_variant_builder_end (&_tmp92_));
	}
	g_variant_builder_add_value (&_reply_builder, g_variant_builder_end (&_tmp88_));
	_g_hash_table_unref0 (result);
	_reply = g_variant_builder_end (&_reply_builder);
	g_dbus_message_set_body (_reply_message, _reply);
	g_dbus_connection_send_message (g_dbus_method_invocation_get_connection (invocation), _reply_message, G_DBUS_SEND_MESSAGE_FLAGS_NONE, NULL, NULL);
	g_object_unref (invocation);
	g_object_unref (_reply_message);
	_error:
	namespaces = (_vala_array_free (namespaces, namespaces_length1, (GDestroyNotify) g_free), NULL);
	;
}

static void
_dbus_granite_portal_settings_read (GranitePortalSettings* self,
                                    GVariant* _parameters_,
                                    GDBusMethodInvocation* invocation)
{
	GError* error = NULL;
	GVariantIter _arguments_iter;
	gchar* namespace = NULL;
	GVariant* _tmp96_;
	gchar* key = NULL;
	GVariant* _tmp97_;
	GDBusMessage* _reply_message = NULL;
	GVariant* _reply;
	GVariantBuilder _reply_builder;
	GVariant* result;
	g_variant_iter_init (&_arguments_iter, _parameters_);
	_tmp96_ = g_variant_iter_next_value (&_arguments_iter);
	namespace = g_variant_dup_string (_tmp96_, NULL);
	g_variant_unref (_tmp96_);
	_tmp97_ = g_variant_iter_next_value (&_arguments_iter);
	key = g_variant_dup_string (_tmp97_, NULL);
	g_variant_unref (_tmp97_);
	result = granite_portal_settings_read (self, namespace, key, &error);
	if (error) {
		g_dbus_method_invocation_take_error (invocation, error);
		goto _error;
	}
	_reply_message = g_dbus_message_new_method_reply (g_dbus_method_invocation_get_message (invocation));
	g_variant_builder_init (&_reply_builder, G_VARIANT_TYPE_TUPLE);
	g_variant_builder_add_value (&_reply_builder, g_variant_new_variant (result));
	_g_variant_unref0 (result);
	_reply = g_variant_builder_end (&_reply_builder);
	g_dbus_message_set_body (_reply_message, _reply);
	g_dbus_connection_send_message (g_dbus_method_invocation_get_connection (invocation), _reply_message, G_DBUS_SEND_MESSAGE_FLAGS_NONE, NULL, NULL);
	g_object_unref (invocation);
	g_object_unref (_reply_message);
	_error:
	_g_free0 (namespace);
	_g_free0 (key);
	;
}

static void
granite_portal_settings_dbus_interface_method_call (GDBusConnection* connection,
                                                    const gchar* sender,
                                                    const gchar* object_path,
                                                    const gchar* interface_name,
                                                    const gchar* method_name,
                                                    GVariant* parameters,
                                                    GDBusMethodInvocation* invocation,
                                                    gpointer user_data)
{
	gpointer* data;
	gpointer object;
	data = user_data;
	object = data[0];
	if (strcmp (method_name, "ReadAll") == 0) {
		_dbus_granite_portal_settings_read_all (object, parameters, invocation);
	} else if (strcmp (method_name, "Read") == 0) {
		_dbus_granite_portal_settings_read (object, parameters, invocation);
	} else {
		g_object_unref (invocation);
	}
}

static GVariant*
granite_portal_settings_dbus_interface_get_property (GDBusConnection* connection,
                                                     const gchar* sender,
                                                     const gchar* object_path,
                                                     const gchar* interface_name,
                                                     const gchar* property_name,
                                                     GError** error,
                                                     gpointer user_data)
{
	gpointer* data;
	gpointer object;
	data = user_data;
	object = data[0];
	return NULL;
}

static gboolean
granite_portal_settings_dbus_interface_set_property (GDBusConnection* connection,
                                                     const gchar* sender,
                                                     const gchar* object_path,
                                                     const gchar* interface_name,
                                                     const gchar* property_name,
                                                     GVariant* value,
                                                     GError** error,
                                                     gpointer user_data)
{
	gpointer* data;
	gpointer object;
	data = user_data;
	object = data[0];
	return FALSE;
}

static void
_dbus_granite_portal_settings_setting_changed (GObject* _sender,
                                               const gchar* namespace,
                                               const gchar* key,
                                               GVariant* value,
                                               gpointer* _data)
{
	GDBusConnection * _connection;
	const gchar * _path;
	GVariant *_arguments;
	GVariantBuilder _arguments_builder;
	_connection = _data[1];
	_path = _data[2];
	g_variant_builder_init (&_arguments_builder, G_VARIANT_TYPE_TUPLE);
	g_variant_builder_add_value (&_arguments_builder, g_variant_new_string (namespace));
	g_variant_builder_add_value (&_arguments_builder, g_variant_new_string (key));
	g_variant_builder_add_value (&_arguments_builder, g_variant_new_variant (value));
	_arguments = g_variant_builder_end (&_arguments_builder);
	g_dbus_connection_emit_signal (_connection, NULL, _path, "org.freedesktop.portal.Settings", "SettingChanged", _arguments, NULL);
}

 G_GNUC_INTERNAL guint
granite_portal_settings_register_object (gpointer object,
                                         GDBusConnection* connection,
                                         const gchar* path,
                                         GError** error)
{
	guint result;
	gpointer *data;
	data = g_new (gpointer, 3);
	data[0] = g_object_ref (object);
	data[1] = g_object_ref (connection);
	data[2] = g_strdup (path);
	result = g_dbus_connection_register_object (connection, path, (GDBusInterfaceInfo *) (&_granite_portal_settings_dbus_interface_info), &_granite_portal_settings_dbus_interface_vtable, data, _granite_portal_settings_unregister_object, error);
	if (!result) {
		return 0;
	}
	g_signal_connect (object, "setting-changed", (GCallback) _dbus_granite_portal_settings_setting_changed, data);
	return result;
}

static void
_granite_portal_settings_unregister_object (gpointer user_data)
{
	gpointer* data;
	data = user_data;
	g_signal_handlers_disconnect_by_func (data[0], _dbus_granite_portal_settings_setting_changed, data);
	g_object_unref (data[0]);
	g_object_unref (data[1]);
	g_free (data[2]);
	g_free (data);
}

static void
_vala_array_destroy (gpointer array,
                     gssize array_length,
                     GDestroyNotify destroy_func)
{
	if ((array != NULL) && (destroy_func != NULL)) {
		gssize i;
		for (i = 0; i < array_length; i = i + 1) {
			if (((gpointer*) array)[i] != NULL) {
				destroy_func (((gpointer*) array)[i]);
			}
		}
	}
}

static void
_vala_array_free (gpointer array,
                  gssize array_length,
                  GDestroyNotify destroy_func)
{
	_vala_array_destroy (array, array_length, destroy_func);
	g_free (array);
}

