/* IPortalRequest.c generated by valac 0.56.19, the Vala compiler
 * generated from IPortalRequest.vala, do not modify */

/* IPortalRequest.vala
 *
 * Copyright 2020 Dylan McCall <dylan@dylanmccall.ca>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program 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 General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * SPDX-License-Identifier: GPL-3.0-or-later
 */

#include "common.h"
#include <gio/gio.h>
#include <glib.h>
#include <stdlib.h>
#include <string.h>

#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

enum  {
	BREAK_TIMER_COMMON_IPORTAL_REQUEST_RESPONSE_SIGNAL,
	BREAK_TIMER_COMMON_IPORTAL_REQUEST_NUM_SIGNALS
};
static guint break_timer_common_iportal_request_signals[BREAK_TIMER_COMMON_IPORTAL_REQUEST_NUM_SIGNALS] = {0};
typedef GDBusProxy BreakTimerCommonIPortalRequestProxy;
typedef GDBusProxyClass BreakTimerCommonIPortalRequestProxyClass;
#define _g_hash_table_unref0(var) ((var == NULL) ? NULL : (var = (g_hash_table_unref (var), NULL)))

static void g_cclosure_user_marshal_VOID__UINT_BOXED (GClosure * closure,
                                               GValue * return_value,
                                               guint n_param_values,
                                               const GValue * param_values,
                                               gpointer invocation_hint,
                                               gpointer marshal_data);
static GType break_timer_common_iportal_request_get_type_once (void);
static void break_timer_common_iportal_request_proxy_g_signal (GDBusProxy* proxy,
                                                        const gchar* sender_name,
                                                        const gchar* signal_name,
                                                        GVariant* parameters);
static void _dbus_handle_break_timer_common_iportal_request_response (BreakTimerCommonIPortalRequest* self,
                                                               GVariant* parameters);
static void break_timer_common_iportal_request_proxy_close (BreakTimerCommonIPortalRequest* self,
                                                     GError** error);
static void break_timer_common_iportal_request_proxy_break_timer_common_iportal_request_interface_init (BreakTimerCommonIPortalRequestIface* iface);
static void _dbus_break_timer_common_iportal_request_close (BreakTimerCommonIPortalRequest* self,
                                                     GVariant* _parameters_,
                                                     GDBusMethodInvocation* invocation);
static void break_timer_common_iportal_request_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* break_timer_common_iportal_request_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 break_timer_common_iportal_request_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_break_timer_common_iportal_request_response (GObject* _sender,
                                                        guint32 response,
                                                        GHashTable* results,
                                                        gpointer* _data);
static void _break_timer_common_iportal_request_unregister_object (gpointer user_data);

static const GDBusArgInfo * const _break_timer_common_iportal_request_dbus_arg_info_close_in[] = {NULL};
static const GDBusArgInfo * const _break_timer_common_iportal_request_dbus_arg_info_close_out[] = {NULL};
static const GDBusMethodInfo _break_timer_common_iportal_request_dbus_method_info_close = {-1, "Close", (GDBusArgInfo **) (&_break_timer_common_iportal_request_dbus_arg_info_close_in), (GDBusArgInfo **) (&_break_timer_common_iportal_request_dbus_arg_info_close_out), NULL};
static const GDBusMethodInfo * const _break_timer_common_iportal_request_dbus_method_info[] = {&_break_timer_common_iportal_request_dbus_method_info_close, NULL};
static const GDBusArgInfo _break_timer_common_iportal_request_dbus_arg_info_response_response = {-1, "response", "u", NULL};
static const GDBusArgInfo _break_timer_common_iportal_request_dbus_arg_info_response_results = {-1, "results", "a{sv}", NULL};
static const GDBusArgInfo * const _break_timer_common_iportal_request_dbus_arg_info_response[] = {&_break_timer_common_iportal_request_dbus_arg_info_response_response, &_break_timer_common_iportal_request_dbus_arg_info_response_results, NULL};
static const GDBusSignalInfo _break_timer_common_iportal_request_dbus_signal_info_response = {-1, "Response", (GDBusArgInfo **) (&_break_timer_common_iportal_request_dbus_arg_info_response), NULL};
static const GDBusSignalInfo * const _break_timer_common_iportal_request_dbus_signal_info[] = {&_break_timer_common_iportal_request_dbus_signal_info_response, NULL};
static const GDBusPropertyInfo * const _break_timer_common_iportal_request_dbus_property_info[] = {NULL};
static const GDBusInterfaceInfo _break_timer_common_iportal_request_dbus_interface_info = {-1, "org.freedesktop.portal.Request", (GDBusMethodInfo **) (&_break_timer_common_iportal_request_dbus_method_info), (GDBusSignalInfo **) (&_break_timer_common_iportal_request_dbus_signal_info), (GDBusPropertyInfo **) (&_break_timer_common_iportal_request_dbus_property_info), NULL};
static const GDBusInterfaceVTable _break_timer_common_iportal_request_dbus_interface_vtable = {break_timer_common_iportal_request_dbus_interface_method_call, break_timer_common_iportal_request_dbus_interface_get_property, break_timer_common_iportal_request_dbus_interface_set_property};

void
break_timer_common_iportal_request_close (BreakTimerCommonIPortalRequest* self,
                                          GError** error)
{
	BreakTimerCommonIPortalRequestIface* _iface_;
	g_return_if_fail (self != NULL);
	_iface_ = BREAK_TIMER_COMMON_IPORTAL_REQUEST_GET_INTERFACE (self);
	if (_iface_->close) {
		_iface_->close (self, error);
	}
}

static void
g_cclosure_user_marshal_VOID__UINT_BOXED (GClosure * closure,
                                          GValue * return_value,
                                          guint n_param_values,
                                          const GValue * param_values,
                                          gpointer invocation_hint,
                                          gpointer marshal_data)
{
	typedef void (*GMarshalFunc_VOID__UINT_BOXED) (gpointer data1, guint32 arg_1, gpointer arg_2, gpointer data2);
	register GMarshalFunc_VOID__UINT_BOXED callback;
	register GCClosure * cc;
	register gpointer data1;
	register gpointer data2;
	cc = (GCClosure *) closure;
	g_return_if_fail (n_param_values == 3);
	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__UINT_BOXED) (marshal_data ? marshal_data : cc->callback);
	callback (data1, g_value_get_uint (param_values + 1), g_value_get_boxed (param_values + 2), data2);
}

static void
break_timer_common_iportal_request_default_init (BreakTimerCommonIPortalRequestIface * iface,
                                                 gpointer iface_data)
{
	break_timer_common_iportal_request_signals[BREAK_TIMER_COMMON_IPORTAL_REQUEST_RESPONSE_SIGNAL] = g_signal_new ("response", BREAK_TIMER_COMMON_TYPE_IPORTAL_REQUEST, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_user_marshal_VOID__UINT_BOXED, G_TYPE_NONE, 2, G_TYPE_UINT, G_TYPE_HASH_TABLE);
}

static GType
break_timer_common_iportal_request_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (BreakTimerCommonIPortalRequestIface), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) break_timer_common_iportal_request_default_init, (GClassFinalizeFunc) NULL, NULL, 0, 0, (GInstanceInitFunc) NULL, NULL };
	GType break_timer_common_iportal_request_type_id;
	break_timer_common_iportal_request_type_id = g_type_register_static (G_TYPE_INTERFACE, "BreakTimerCommonIPortalRequest", &g_define_type_info, 0);
	g_type_interface_add_prerequisite (break_timer_common_iportal_request_type_id, G_TYPE_OBJECT);
	g_type_set_qdata (break_timer_common_iportal_request_type_id, g_quark_from_static_string ("vala-dbus-proxy-type"), (void*) break_timer_common_iportal_request_proxy_get_type);
	g_type_set_qdata (break_timer_common_iportal_request_type_id, g_quark_from_static_string ("vala-dbus-interface-name"), "org.freedesktop.portal.Request");
	g_type_set_qdata (break_timer_common_iportal_request_type_id, g_quark_from_static_string ("vala-dbus-interface-info"), (void*) (&_break_timer_common_iportal_request_dbus_interface_info));
	g_type_set_qdata (break_timer_common_iportal_request_type_id, g_quark_from_static_string ("vala-dbus-register-object"), (void*) break_timer_common_iportal_request_register_object);
	return break_timer_common_iportal_request_type_id;
}

GType
break_timer_common_iportal_request_get_type (void)
{
	static volatile gsize break_timer_common_iportal_request_type_id__once = 0;
	if (g_once_init_enter (&break_timer_common_iportal_request_type_id__once)) {
		GType break_timer_common_iportal_request_type_id;
		break_timer_common_iportal_request_type_id = break_timer_common_iportal_request_get_type_once ();
		g_once_init_leave (&break_timer_common_iportal_request_type_id__once, break_timer_common_iportal_request_type_id);
	}
	return break_timer_common_iportal_request_type_id__once;
}

G_DEFINE_TYPE_EXTENDED (BreakTimerCommonIPortalRequestProxy, break_timer_common_iportal_request_proxy, G_TYPE_DBUS_PROXY, 0, G_IMPLEMENT_INTERFACE (BREAK_TIMER_COMMON_TYPE_IPORTAL_REQUEST, break_timer_common_iportal_request_proxy_break_timer_common_iportal_request_interface_init) )
static void
break_timer_common_iportal_request_proxy_class_init (BreakTimerCommonIPortalRequestProxyClass* klass)
{
	G_DBUS_PROXY_CLASS (klass)->g_signal = break_timer_common_iportal_request_proxy_g_signal;
}

static void
_dbus_handle_break_timer_common_iportal_request_response (BreakTimerCommonIPortalRequest* self,
                                                          GVariant* parameters)
{
	GVariantIter _arguments_iter;
	guint32 response = 0U;
	GVariant* _tmp89_;
	GHashTable* results = NULL;
	GVariant* _tmp90_;
	GHashTable* _tmp91_;
	GVariantIter _tmp92_;
	GVariant* _tmp93_;
	GVariant* _tmp94_;
	g_variant_iter_init (&_arguments_iter, parameters);
	_tmp89_ = g_variant_iter_next_value (&_arguments_iter);
	response = g_variant_get_uint32 (_tmp89_);
	g_variant_unref (_tmp89_);
	_tmp90_ = g_variant_iter_next_value (&_arguments_iter);
	_tmp91_ = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, (GDestroyNotify) g_variant_unref);
	g_variant_iter_init (&_tmp92_, _tmp90_);
	while (g_variant_iter_loop (&_tmp92_, "{?*}", &_tmp93_, &_tmp94_)) {
		g_hash_table_insert (_tmp91_, g_variant_dup_string (_tmp93_, NULL), g_variant_get_variant (_tmp94_));
	}
	results = _tmp91_;
	g_variant_unref (_tmp90_);
	g_signal_emit_by_name (self, "response", response, results);
	_g_hash_table_unref0 (results);
}

static void
break_timer_common_iportal_request_proxy_g_signal (GDBusProxy* proxy,
                                                   const gchar* sender_name,
                                                   const gchar* signal_name,
                                                   GVariant* parameters)
{
	if (strcmp (signal_name, "Response") == 0) {
		_dbus_handle_break_timer_common_iportal_request_response ((BreakTimerCommonIPortalRequest*) proxy, parameters);
	}
}

static void
break_timer_common_iportal_request_proxy_init (BreakTimerCommonIPortalRequestProxy* self)
{
	g_dbus_proxy_set_interface_info (G_DBUS_PROXY (self), (GDBusInterfaceInfo *) (&_break_timer_common_iportal_request_dbus_interface_info));
}

static void
break_timer_common_iportal_request_proxy_close (BreakTimerCommonIPortalRequest* self,
                                                GError** error)
{
	GDBusMessage *_message;
	GVariant *_arguments;
	GVariantBuilder _arguments_builder;
	GDBusMessage *_reply_message;
	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.Request", "Close");
	g_variant_builder_init (&_arguments_builder, G_VARIANT_TYPE_TUPLE);
	_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;
	}
	if (g_dbus_message_to_gerror (_reply_message, error)) {
		g_object_unref (_reply_message);
		return;
	}
	g_object_unref (_reply_message);
}

static void
break_timer_common_iportal_request_proxy_break_timer_common_iportal_request_interface_init (BreakTimerCommonIPortalRequestIface* iface)
{
	iface->close = break_timer_common_iportal_request_proxy_close;
}

static void
_dbus_break_timer_common_iportal_request_close (BreakTimerCommonIPortalRequest* self,
                                                GVariant* _parameters_,
                                                GDBusMethodInvocation* invocation)
{
	GError* error = NULL;
	GVariantIter _arguments_iter;
	GDBusMessage* _reply_message = NULL;
	GVariant* _reply;
	GVariantBuilder _reply_builder;
	g_variant_iter_init (&_arguments_iter, _parameters_);
	break_timer_common_iportal_request_close (self, &error);
	if (error) {
		g_dbus_method_invocation_take_error (invocation, error);
		return;
	}
	_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);
	_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);
}

static void
break_timer_common_iportal_request_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, "Close") == 0) {
		_dbus_break_timer_common_iportal_request_close (object, parameters, invocation);
	} else {
		g_object_unref (invocation);
	}
}

static GVariant*
break_timer_common_iportal_request_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)
{
	return NULL;
}

static gboolean
break_timer_common_iportal_request_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)
{
	return FALSE;
}

static void
_dbus_break_timer_common_iportal_request_response (GObject* _sender,
                                                   guint32 response,
                                                   GHashTable* results,
                                                   gpointer* _data)
{
	GDBusConnection * _connection;
	const gchar * _path;
	GVariant *_arguments;
	GVariantBuilder _arguments_builder;
	GVariantBuilder _tmp95_;
	GHashTableIter _tmp96_;
	gpointer _tmp97_;
	gpointer _tmp98_;
	_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_uint32 (response));
	g_hash_table_iter_init (&_tmp96_, results);
	g_variant_builder_init (&_tmp95_, G_VARIANT_TYPE ("a{sv}"));
	while (g_hash_table_iter_next (&_tmp96_, &_tmp97_, &_tmp98_)) {
		gchar* _key;
		GVariant* _value;
		_key = (gchar*) _tmp97_;
		_value = (GVariant*) _tmp98_;
		g_variant_builder_add (&_tmp95_, "{?*}", g_variant_new_string (_key), g_variant_new_variant (_value));
	}
	g_variant_builder_add_value (&_arguments_builder, g_variant_builder_end (&_tmp95_));
	_arguments = g_variant_builder_end (&_arguments_builder);
	g_dbus_connection_emit_signal (_connection, NULL, _path, "org.freedesktop.portal.Request", "Response", _arguments, NULL);
}

guint
break_timer_common_iportal_request_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 *) (&_break_timer_common_iportal_request_dbus_interface_info), &_break_timer_common_iportal_request_dbus_interface_vtable, data, _break_timer_common_iportal_request_unregister_object, error);
	if (!result) {
		return 0;
	}
	g_signal_connect (object, "response", (GCallback) _dbus_break_timer_common_iportal_request_response, data);
	return result;
}

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

