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

#include "libdino.h"
#include <glib.h>
#include <gio/gio.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.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  {
	DINO_LOGIN1_MANAGER_PREPARE_FOR_SLEEP_SIGNAL,
	DINO_LOGIN1_MANAGER_NUM_SIGNALS
};
static guint dino_login1_manager_signals[DINO_LOGIN1_MANAGER_NUM_SIGNALS] = {0};
typedef GDBusProxy DinoLogin1ManagerProxy;
typedef GDBusProxyClass DinoLogin1ManagerProxyClass;
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))
typedef struct _DinoGetLogin1Data DinoGetLogin1Data;

struct _DinoGetLogin1Data {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	DinoLogin1Manager* result;
	DinoLogin1Manager* _tmp0_;
	DinoLogin1Manager* _tmp1_;
	DinoLogin1Manager* _tmp2_;
	GError* e;
	FILE* _tmp3_;
	GError* _tmp4_;
	const gchar* _tmp5_;
	GError* _inner_error0_;
};

static GType dino_login1_manager_get_type_once (void);
static void dino_login1_manager_proxy_g_signal (GDBusProxy* proxy,
                                         const gchar* sender_name,
                                         const gchar* signal_name,
                                         GVariant* parameters);
static void _dbus_handle_dino_login1_manager_prepare_for_sleep (DinoLogin1Manager* self,
                                                         GVariant* parameters);
static void dino_login1_manager_proxy_dino_login1_manager_interface_init (DinoLogin1ManagerIface* iface);
static void dino_login1_manager_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* dino_login1_manager_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 dino_login1_manager_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_dino_login1_manager_prepare_for_sleep (GObject* _sender,
                                                  gboolean suspend,
                                                  gpointer* _data);
static void _dino_login1_manager_unregister_object (gpointer user_data);
static void dino_get_login1_data_free (gpointer _data);
static gboolean dino_get_login1_co (DinoGetLogin1Data* _data_);
static void dino_get_login1_ready (GObject* source_object,
                            GAsyncResult* _res_,
                            gpointer _user_data_);

static const GDBusMethodInfo * const _dino_login1_manager_dbus_method_info[] = {NULL};
static const GDBusArgInfo _dino_login1_manager_dbus_arg_info_prepare_for_sleep_suspend = {-1, "suspend", "b", NULL};
static const GDBusArgInfo * const _dino_login1_manager_dbus_arg_info_prepare_for_sleep[] = {&_dino_login1_manager_dbus_arg_info_prepare_for_sleep_suspend, NULL};
static const GDBusSignalInfo _dino_login1_manager_dbus_signal_info_prepare_for_sleep = {-1, "PrepareForSleep", (GDBusArgInfo **) (&_dino_login1_manager_dbus_arg_info_prepare_for_sleep), NULL};
static const GDBusSignalInfo * const _dino_login1_manager_dbus_signal_info[] = {&_dino_login1_manager_dbus_signal_info_prepare_for_sleep, NULL};
static const GDBusPropertyInfo * const _dino_login1_manager_dbus_property_info[] = {NULL};
static const GDBusInterfaceInfo _dino_login1_manager_dbus_interface_info = {-1, "org.freedesktop.login1.Manager", (GDBusMethodInfo **) (&_dino_login1_manager_dbus_method_info), (GDBusSignalInfo **) (&_dino_login1_manager_dbus_signal_info), (GDBusPropertyInfo **) (&_dino_login1_manager_dbus_property_info), NULL};
static const GDBusInterfaceVTable _dino_login1_manager_dbus_interface_vtable = {dino_login1_manager_dbus_interface_method_call, dino_login1_manager_dbus_interface_get_property, dino_login1_manager_dbus_interface_set_property};

static void
dino_login1_manager_default_init (DinoLogin1ManagerIface * iface,
                                  gpointer iface_data)
{
	dino_login1_manager_signals[DINO_LOGIN1_MANAGER_PREPARE_FOR_SLEEP_SIGNAL] = g_signal_new ("prepare-for-sleep", DINO_TYPE_LOGIN1_MANAGER, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__BOOLEAN, G_TYPE_NONE, 1, G_TYPE_BOOLEAN);
}

static GType
dino_login1_manager_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (DinoLogin1ManagerIface), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) dino_login1_manager_default_init, (GClassFinalizeFunc) NULL, NULL, 0, 0, (GInstanceInitFunc) NULL, NULL };
	GType dino_login1_manager_type_id;
	dino_login1_manager_type_id = g_type_register_static (G_TYPE_INTERFACE, "DinoLogin1Manager", &g_define_type_info, 0);
	g_type_interface_add_prerequisite (dino_login1_manager_type_id, G_TYPE_OBJECT);
	g_type_set_qdata (dino_login1_manager_type_id, g_quark_from_static_string ("vala-dbus-proxy-type"), (void*) dino_login1_manager_proxy_get_type);
	g_type_set_qdata (dino_login1_manager_type_id, g_quark_from_static_string ("vala-dbus-interface-name"), "org.freedesktop.login1.Manager");
	g_type_set_qdata (dino_login1_manager_type_id, g_quark_from_static_string ("vala-dbus-interface-info"), (void*) (&_dino_login1_manager_dbus_interface_info));
	g_type_set_qdata (dino_login1_manager_type_id, g_quark_from_static_string ("vala-dbus-register-object"), (void*) dino_login1_manager_register_object);
	return dino_login1_manager_type_id;
}

GType
dino_login1_manager_get_type (void)
{
	static volatile gsize dino_login1_manager_type_id__once = 0;
	if (g_once_init_enter (&dino_login1_manager_type_id__once)) {
		GType dino_login1_manager_type_id;
		dino_login1_manager_type_id = dino_login1_manager_get_type_once ();
		g_once_init_leave (&dino_login1_manager_type_id__once, dino_login1_manager_type_id);
	}
	return dino_login1_manager_type_id__once;
}

G_DEFINE_TYPE_EXTENDED (DinoLogin1ManagerProxy, dino_login1_manager_proxy, G_TYPE_DBUS_PROXY, 0, G_IMPLEMENT_INTERFACE (DINO_TYPE_LOGIN1_MANAGER, dino_login1_manager_proxy_dino_login1_manager_interface_init) )
static void
dino_login1_manager_proxy_class_init (DinoLogin1ManagerProxyClass* klass)
{
	G_DBUS_PROXY_CLASS (klass)->g_signal = dino_login1_manager_proxy_g_signal;
}

static void
_dbus_handle_dino_login1_manager_prepare_for_sleep (DinoLogin1Manager* self,
                                                    GVariant* parameters)
{
	GVariantIter _arguments_iter;
	gboolean suspend = FALSE;
	GVariant* _tmp0_;
	g_variant_iter_init (&_arguments_iter, parameters);
	_tmp0_ = g_variant_iter_next_value (&_arguments_iter);
	suspend = g_variant_get_boolean (_tmp0_);
	g_variant_unref (_tmp0_);
	g_signal_emit_by_name (self, "prepare-for-sleep", suspend);
}

static void
dino_login1_manager_proxy_g_signal (GDBusProxy* proxy,
                                    const gchar* sender_name,
                                    const gchar* signal_name,
                                    GVariant* parameters)
{
	if (strcmp (signal_name, "PrepareForSleep") == 0) {
		_dbus_handle_dino_login1_manager_prepare_for_sleep ((DinoLogin1Manager*) proxy, parameters);
	}
}

static void
dino_login1_manager_proxy_init (DinoLogin1ManagerProxy* self)
{
	g_dbus_proxy_set_interface_info (G_DBUS_PROXY (self), (GDBusInterfaceInfo *) (&_dino_login1_manager_dbus_interface_info));
}

static void
dino_login1_manager_proxy_dino_login1_manager_interface_init (DinoLogin1ManagerIface* iface)
{
}

static void
dino_login1_manager_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)
{
	g_object_unref (invocation);
}

static GVariant*
dino_login1_manager_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
dino_login1_manager_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_dino_login1_manager_prepare_for_sleep (GObject* _sender,
                                             gboolean suspend,
                                             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_boolean (suspend));
	_arguments = g_variant_builder_end (&_arguments_builder);
	g_dbus_connection_emit_signal (_connection, NULL, _path, "org.freedesktop.login1.Manager", "PrepareForSleep", _arguments, NULL);
}

guint
dino_login1_manager_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 *) (&_dino_login1_manager_dbus_interface_info), &_dino_login1_manager_dbus_interface_vtable, data, _dino_login1_manager_unregister_object, error);
	if (!result) {
		return 0;
	}
	g_signal_connect (object, "prepare-for-sleep", (GCallback) _dbus_dino_login1_manager_prepare_for_sleep, data);
	return result;
}

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

static void
dino_get_login1_data_free (gpointer _data)
{
	DinoGetLogin1Data* _data_;
	_data_ = _data;
	_g_object_unref0 (_data_->result);
	g_slice_free (DinoGetLogin1Data, _data_);
}

void
dino_get_login1 (GAsyncReadyCallback _callback_,
                 gpointer _user_data_)
{
	DinoGetLogin1Data* _data_;
	_data_ = g_slice_new0 (DinoGetLogin1Data);
	_data_->_async_result = g_task_new (NULL, NULL, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, dino_get_login1_data_free);
	dino_get_login1_co (_data_);
}

DinoLogin1Manager*
dino_get_login1_finish (GAsyncResult* _res_)
{
	DinoLogin1Manager* result;
	DinoGetLogin1Data* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), NULL);
	result = _data_->result;
	_data_->result = NULL;
	return result;
}

static void
dino_get_login1_ready (GObject* source_object,
                       GAsyncResult* _res_,
                       gpointer _user_data_)
{
	DinoGetLogin1Data* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	dino_get_login1_co (_data_);
}

static gboolean
dino_get_login1_co (DinoGetLogin1Data* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	{
		_data_->_state_ = 1;
		g_async_initable_new_async (DINO_TYPE_LOGIN1_MANAGER_PROXY, 0, NULL, dino_get_login1_ready, _data_, "g-flags", 0, "g-name", "org.freedesktop.login1", "g-bus-type", G_BUS_TYPE_SYSTEM, "g-object-path", "/org/freedesktop/login1", "g-interface-name", "org.freedesktop.login1.Manager", NULL);
		return FALSE;
		_state_1:
		_data_->_tmp1_ = (DinoLogin1Manager*) g_async_initable_new_finish ((GAsyncInitable *) _data_->_source_object_, _data_->_res_, &_data_->_inner_error0_);
		_data_->_tmp0_ = (DinoLogin1Manager*) _data_->_tmp1_;
		if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
			if (_data_->_inner_error0_->domain == G_IO_ERROR) {
				goto __catch0_g_io_error;
			}
			g_critical ("file %s: line %d: unexpected error: %s (%s, %d)", __FILE__, __LINE__, _data_->_inner_error0_->message, g_quark_to_string (_data_->_inner_error0_->domain), _data_->_inner_error0_->code);
			g_clear_error (&_data_->_inner_error0_);
			g_object_unref (_data_->_async_result);
			return FALSE;
		}
		_data_->_tmp2_ = _data_->_tmp0_;
		_data_->_tmp0_ = NULL;
		_data_->result = _data_->_tmp2_;
		_g_object_unref0 (_data_->_tmp0_);
		g_task_return_pointer (_data_->_async_result, _data_, NULL);
		if (_data_->_state_ != 0) {
			while (!g_task_get_completed (_data_->_async_result)) {
				g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
			}
		}
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	goto __finally0;
	__catch0_g_io_error:
	{
		_data_->e = _data_->_inner_error0_;
		_data_->_inner_error0_ = NULL;
		_data_->_tmp3_ = stderr;
		_data_->_tmp4_ = _data_->e;
		_data_->_tmp5_ = _data_->_tmp4_->message;
		fprintf (_data_->_tmp3_, "%s\n", _data_->_tmp5_);
		_g_error_free0 (_data_->e);
	}
	__finally0:
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _data_->_inner_error0_->message, g_quark_to_string (_data_->_inner_error0_->domain), _data_->_inner_error0_->code);
		g_clear_error (&_data_->_inner_error0_);
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->result = NULL;
	g_task_return_pointer (_data_->_async_result, _data_, NULL);
	if (_data_->_state_ != 0) {
		while (!g_task_get_completed (_data_->_async_result)) {
			g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
		}
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
}

