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

/*
 * Copyright (C) 2017 Stéphane Fillion
 * Authors: Stéphane Fillion <stphanef3724@gmail.com>
 *
 * 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. See http://www.gnu.org/copyleft/gpl.html the full text of the
 * license.
 */

#include <glib-object.h>
#include <gio/gio.h>
#include <stdlib.h>
#include <string.h>
#include <glib.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
#if !defined(VALA_EXTERN)
#if defined(_MSC_VER)
#define VALA_EXTERN __declspec(dllexport) extern
#elif __GNUC__ >= 4
#define VALA_EXTERN __attribute__((visibility("default"))) extern
#else
#define VALA_EXTERN extern
#endif
#endif

#define TYPE_FREEDESKTOP_SCREENSAVER (freedesktop_screensaver_get_type ())
#define FREEDESKTOP_SCREENSAVER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_FREEDESKTOP_SCREENSAVER, FreedesktopScreensaver))
#define IS_FREEDESKTOP_SCREENSAVER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_FREEDESKTOP_SCREENSAVER))
#define FREEDESKTOP_SCREENSAVER_GET_INTERFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), TYPE_FREEDESKTOP_SCREENSAVER, FreedesktopScreensaverIface))

typedef struct _FreedesktopScreensaver FreedesktopScreensaver;
typedef struct _FreedesktopScreensaverIface FreedesktopScreensaverIface;

#define TYPE_FREEDESKTOP_SCREENSAVER_PROXY (freedesktop_screensaver_proxy_get_type ())
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
typedef GDBusProxy FreedesktopScreensaverProxy;
typedef GDBusProxyClass FreedesktopScreensaverProxyClass;
#define _g_free0(var) (var = (g_free (var), NULL))

struct _FreedesktopScreensaverIface {
	GTypeInterface parent_iface;
	guint32 (*inhibit) (FreedesktopScreensaver* self, const gchar* application_name, const gchar* reason_for_inhibit, GError** error);
	void (*uninhibit) (FreedesktopScreensaver* self, guint32 cookie, GError** error);
};

VALA_EXTERN GType freedesktop_screensaver_proxy_get_type (void) G_GNUC_CONST ;
VALA_EXTERN guint freedesktop_screensaver_register_object (void* object,
                                               GDBusConnection* connection,
                                               const gchar* path,
                                               GError** error);
VALA_EXTERN GType freedesktop_screensaver_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (FreedesktopScreensaver, g_object_unref)
VALA_EXTERN FreedesktopScreensaver* freedesktop_screensaver_get_proxy (GError** error);
VALA_EXTERN guint32 freedesktop_screensaver_inhibit (FreedesktopScreensaver* self,
                                         const gchar* application_name,
                                         const gchar* reason_for_inhibit,
                                         GError** error);
VALA_EXTERN void freedesktop_screensaver_uninhibit (FreedesktopScreensaver* self,
                                        guint32 cookie,
                                        GError** error);
static GType freedesktop_screensaver_get_type_once (void);
static void freedesktop_screensaver_proxy_g_signal (GDBusProxy* proxy,
                                             const gchar* sender_name,
                                             const gchar* signal_name,
                                             GVariant* parameters);
static guint32 freedesktop_screensaver_proxy_inhibit (FreedesktopScreensaver* self,
                                               const gchar* application_name,
                                               const gchar* reason_for_inhibit,
                                               GError** error);
static void freedesktop_screensaver_proxy_uninhibit (FreedesktopScreensaver* self,
                                              guint32 cookie,
                                              GError** error);
static void freedesktop_screensaver_proxy_freedesktop_screensaver_interface_init (FreedesktopScreensaverIface* iface);
static void _dbus_freedesktop_screensaver_inhibit (FreedesktopScreensaver* self,
                                            GVariant* _parameters_,
                                            GDBusMethodInvocation* invocation);
static void _dbus_freedesktop_screensaver_uninhibit (FreedesktopScreensaver* self,
                                              GVariant* _parameters_,
                                              GDBusMethodInvocation* invocation);
static void freedesktop_screensaver_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* freedesktop_screensaver_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 freedesktop_screensaver_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 _freedesktop_screensaver_unregister_object (gpointer user_data);

static const GDBusArgInfo _freedesktop_screensaver_dbus_arg_info_inhibit_application_name = {-1, "application_name", "s", NULL};
static const GDBusArgInfo _freedesktop_screensaver_dbus_arg_info_inhibit_reason_for_inhibit = {-1, "reason_for_inhibit", "s", NULL};
static const GDBusArgInfo _freedesktop_screensaver_dbus_arg_info_inhibit_result = {-1, "result", "u", NULL};
static const GDBusArgInfo * const _freedesktop_screensaver_dbus_arg_info_inhibit_in[] = {&_freedesktop_screensaver_dbus_arg_info_inhibit_application_name, &_freedesktop_screensaver_dbus_arg_info_inhibit_reason_for_inhibit, NULL};
static const GDBusArgInfo * const _freedesktop_screensaver_dbus_arg_info_inhibit_out[] = {&_freedesktop_screensaver_dbus_arg_info_inhibit_result, NULL};
static const GDBusMethodInfo _freedesktop_screensaver_dbus_method_info_inhibit = {-1, "Inhibit", (GDBusArgInfo **) (&_freedesktop_screensaver_dbus_arg_info_inhibit_in), (GDBusArgInfo **) (&_freedesktop_screensaver_dbus_arg_info_inhibit_out), NULL};
static const GDBusArgInfo _freedesktop_screensaver_dbus_arg_info_uninhibit_cookie = {-1, "cookie", "u", NULL};
static const GDBusArgInfo * const _freedesktop_screensaver_dbus_arg_info_uninhibit_in[] = {&_freedesktop_screensaver_dbus_arg_info_uninhibit_cookie, NULL};
static const GDBusArgInfo * const _freedesktop_screensaver_dbus_arg_info_uninhibit_out[] = {NULL};
static const GDBusMethodInfo _freedesktop_screensaver_dbus_method_info_uninhibit = {-1, "UnInhibit", (GDBusArgInfo **) (&_freedesktop_screensaver_dbus_arg_info_uninhibit_in), (GDBusArgInfo **) (&_freedesktop_screensaver_dbus_arg_info_uninhibit_out), NULL};
static const GDBusMethodInfo * const _freedesktop_screensaver_dbus_method_info[] = {&_freedesktop_screensaver_dbus_method_info_inhibit, &_freedesktop_screensaver_dbus_method_info_uninhibit, NULL};
static const GDBusSignalInfo * const _freedesktop_screensaver_dbus_signal_info[] = {NULL};
static const GDBusPropertyInfo * const _freedesktop_screensaver_dbus_property_info[] = {NULL};
static const GDBusInterfaceInfo _freedesktop_screensaver_dbus_interface_info = {-1, "org.freedesktop.ScreenSaver", (GDBusMethodInfo **) (&_freedesktop_screensaver_dbus_method_info), (GDBusSignalInfo **) (&_freedesktop_screensaver_dbus_signal_info), (GDBusPropertyInfo **) (&_freedesktop_screensaver_dbus_property_info), NULL};
static const GDBusInterfaceVTable _freedesktop_screensaver_dbus_interface_vtable = {freedesktop_screensaver_dbus_interface_method_call, freedesktop_screensaver_dbus_interface_get_property, freedesktop_screensaver_dbus_interface_set_property};

FreedesktopScreensaver*
freedesktop_screensaver_get_proxy (GError** error)
{
	FreedesktopScreensaver* _tmp0_ = NULL;
	FreedesktopScreensaver* _tmp1_;
	FreedesktopScreensaver* _tmp2_;
	GError* _inner_error0_ = NULL;
	FreedesktopScreensaver* result;
	_tmp1_ = (FreedesktopScreensaver*) g_initable_new (TYPE_FREEDESKTOP_SCREENSAVER_PROXY, NULL, &_inner_error0_, "g-flags", 0, "g-name", "org.freedesktop.ScreenSaver", "g-bus-type", G_BUS_TYPE_SESSION, "g-object-path", "/org/freedesktop/ScreenSaver", "g-interface-name", "org.freedesktop.ScreenSaver", NULL);
	_tmp0_ = (FreedesktopScreensaver*) _tmp1_;
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		if (_inner_error0_->domain == G_IO_ERROR) {
			g_propagate_error (error, _inner_error0_);
			return NULL;
		} else {
			g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
			g_clear_error (&_inner_error0_);
			return NULL;
		}
	}
	_tmp2_ = _tmp0_;
	_tmp0_ = NULL;
	result = _tmp2_;
	_g_object_unref0 (_tmp0_);
	return result;
}

guint32
freedesktop_screensaver_inhibit (FreedesktopScreensaver* self,
                                 const gchar* application_name,
                                 const gchar* reason_for_inhibit,
                                 GError** error)
{
	FreedesktopScreensaverIface* _iface_;
	g_return_val_if_fail (self != NULL, 0U);
	_iface_ = FREEDESKTOP_SCREENSAVER_GET_INTERFACE (self);
	if (_iface_->inhibit) {
		return _iface_->inhibit (self, application_name, reason_for_inhibit, error);
	}
	return 0U;
}

void
freedesktop_screensaver_uninhibit (FreedesktopScreensaver* self,
                                   guint32 cookie,
                                   GError** error)
{
	FreedesktopScreensaverIface* _iface_;
	g_return_if_fail (self != NULL);
	_iface_ = FREEDESKTOP_SCREENSAVER_GET_INTERFACE (self);
	if (_iface_->uninhibit) {
		_iface_->uninhibit (self, cookie, error);
	}
}

static void
freedesktop_screensaver_default_init (FreedesktopScreensaverIface * iface,
                                      gpointer iface_data)
{
}

 G_GNUC_NO_INLINE static GType
freedesktop_screensaver_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (FreedesktopScreensaverIface), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) freedesktop_screensaver_default_init, (GClassFinalizeFunc) NULL, NULL, 0, 0, (GInstanceInitFunc) NULL, NULL };
	GType freedesktop_screensaver_type_id;
	freedesktop_screensaver_type_id = g_type_register_static (G_TYPE_INTERFACE, "FreedesktopScreensaver", &g_define_type_info, G_TYPE_FLAG_NONE);
	g_type_interface_add_prerequisite (freedesktop_screensaver_type_id, G_TYPE_OBJECT);
	g_type_set_qdata (freedesktop_screensaver_type_id, g_quark_from_static_string ("vala-dbus-proxy-type"), (void*) freedesktop_screensaver_proxy_get_type);
	g_type_set_qdata (freedesktop_screensaver_type_id, g_quark_from_static_string ("vala-dbus-interface-name"), "org.freedesktop.ScreenSaver");
	g_type_set_qdata (freedesktop_screensaver_type_id, g_quark_from_static_string ("vala-dbus-interface-info"), (void*) (&_freedesktop_screensaver_dbus_interface_info));
	g_type_set_qdata (freedesktop_screensaver_type_id, g_quark_from_static_string ("vala-dbus-register-object"), (void*) freedesktop_screensaver_register_object);
	return freedesktop_screensaver_type_id;
}

GType
freedesktop_screensaver_get_type (void)
{
	static gsize freedesktop_screensaver_type_id__once = 0;
	if (g_once_init_enter (&freedesktop_screensaver_type_id__once)) {
		GType freedesktop_screensaver_type_id;
		freedesktop_screensaver_type_id = freedesktop_screensaver_get_type_once ();
		g_once_init_leave (&freedesktop_screensaver_type_id__once, freedesktop_screensaver_type_id);
	}
	return freedesktop_screensaver_type_id__once;
}

G_DEFINE_TYPE_EXTENDED (FreedesktopScreensaverProxy, freedesktop_screensaver_proxy, G_TYPE_DBUS_PROXY, 0, G_IMPLEMENT_INTERFACE (TYPE_FREEDESKTOP_SCREENSAVER, freedesktop_screensaver_proxy_freedesktop_screensaver_interface_init) )
static void
freedesktop_screensaver_proxy_class_init (FreedesktopScreensaverProxyClass* klass)
{
	G_DBUS_PROXY_CLASS (klass)->g_signal = freedesktop_screensaver_proxy_g_signal;
}

static void
freedesktop_screensaver_proxy_g_signal (GDBusProxy* proxy,
                                        const gchar* sender_name,
                                        const gchar* signal_name,
                                        GVariant* parameters)
{
}

static void
freedesktop_screensaver_proxy_init (FreedesktopScreensaverProxy* self)
{
	g_dbus_proxy_set_interface_info (G_DBUS_PROXY (self), (GDBusInterfaceInfo *) (&_freedesktop_screensaver_dbus_interface_info));
}

static guint32
freedesktop_screensaver_proxy_inhibit (FreedesktopScreensaver* self,
                                       const gchar* application_name,
                                       const gchar* reason_for_inhibit,
                                       GError** error)
{
	GDBusMessage *_message;
	GVariant *_arguments;
	GVariantBuilder _arguments_builder;
	GDBusMessage *_reply_message;
	GVariant *_reply;
	GVariantIter _reply_iter;
	guint32 _result = 0U;
	GVariant* _tmp2_;
	_message = g_dbus_message_new_method_call (g_dbus_proxy_get_name ((GDBusProxy *) self), g_dbus_proxy_get_object_path ((GDBusProxy *) self), "org.freedesktop.ScreenSaver", "Inhibit");
	g_variant_builder_init (&_arguments_builder, G_VARIANT_TYPE_TUPLE);
	g_variant_builder_add_value (&_arguments_builder, g_variant_new_string (application_name));
	g_variant_builder_add_value (&_arguments_builder, g_variant_new_string (reason_for_inhibit));
	_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) {
		guint32 _tmp0_ = 0U;
		return _tmp0_;
	}
	if (g_dbus_message_to_gerror (_reply_message, error)) {
		guint32 _tmp1_ = 0U;
		g_object_unref (_reply_message);
		return _tmp1_;
	}
	_reply = g_dbus_message_get_body (_reply_message);
	g_variant_iter_init (&_reply_iter, _reply);
	_tmp2_ = g_variant_iter_next_value (&_reply_iter);
	_result = g_variant_get_uint32 (_tmp2_);
	g_variant_unref (_tmp2_);
	g_object_unref (_reply_message);
	return _result;
}

static void
freedesktop_screensaver_proxy_uninhibit (FreedesktopScreensaver* self,
                                         guint32 cookie,
                                         GError** error)
{
	GDBusMessage *_message;
	GVariant *_arguments;
	GVariantBuilder _arguments_builder;
	GDBusMessage *_reply_message;
	_message = g_dbus_message_new_method_call (g_dbus_proxy_get_name ((GDBusProxy *) self), g_dbus_proxy_get_object_path ((GDBusProxy *) self), "org.freedesktop.ScreenSaver", "UnInhibit");
	g_variant_builder_init (&_arguments_builder, G_VARIANT_TYPE_TUPLE);
	g_variant_builder_add_value (&_arguments_builder, g_variant_new_uint32 (cookie));
	_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
freedesktop_screensaver_proxy_freedesktop_screensaver_interface_init (FreedesktopScreensaverIface* iface)
{
	iface->inhibit = freedesktop_screensaver_proxy_inhibit;
	iface->uninhibit = freedesktop_screensaver_proxy_uninhibit;
}

static void
_dbus_freedesktop_screensaver_inhibit (FreedesktopScreensaver* self,
                                       GVariant* _parameters_,
                                       GDBusMethodInvocation* invocation)
{
	GError* error = NULL;
	GVariantIter _arguments_iter;
	gchar* application_name = NULL;
	GVariant* _tmp3_;
	gchar* reason_for_inhibit = NULL;
	GVariant* _tmp4_;
	GDBusMessage* _reply_message = NULL;
	GVariant* _reply;
	GVariantBuilder _reply_builder;
	guint32 result;
	g_variant_iter_init (&_arguments_iter, _parameters_);
	_tmp3_ = g_variant_iter_next_value (&_arguments_iter);
	application_name = g_variant_dup_string (_tmp3_, NULL);
	g_variant_unref (_tmp3_);
	_tmp4_ = g_variant_iter_next_value (&_arguments_iter);
	reason_for_inhibit = g_variant_dup_string (_tmp4_, NULL);
	g_variant_unref (_tmp4_);
	result = freedesktop_screensaver_inhibit (self, application_name, reason_for_inhibit, &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_uint32 (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 (application_name);
	_g_free0 (reason_for_inhibit);
	;
}

static void
_dbus_freedesktop_screensaver_uninhibit (FreedesktopScreensaver* self,
                                         GVariant* _parameters_,
                                         GDBusMethodInvocation* invocation)
{
	GError* error = NULL;
	GVariantIter _arguments_iter;
	guint32 cookie = 0U;
	GVariant* _tmp5_;
	GDBusMessage* _reply_message = NULL;
	GVariant* _reply;
	GVariantBuilder _reply_builder;
	g_variant_iter_init (&_arguments_iter, _parameters_);
	_tmp5_ = g_variant_iter_next_value (&_arguments_iter);
	cookie = g_variant_get_uint32 (_tmp5_);
	g_variant_unref (_tmp5_);
	freedesktop_screensaver_uninhibit (self, cookie, &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
freedesktop_screensaver_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, "Inhibit") == 0) {
		_dbus_freedesktop_screensaver_inhibit (object, parameters, invocation);
	} else if (strcmp (method_name, "UnInhibit") == 0) {
		_dbus_freedesktop_screensaver_uninhibit (object, parameters, invocation);
	} else {
		g_object_unref (invocation);
	}
}

static GVariant*
freedesktop_screensaver_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
freedesktop_screensaver_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;
}

guint
freedesktop_screensaver_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 *) (&_freedesktop_screensaver_dbus_interface_info), &_freedesktop_screensaver_dbus_interface_vtable, data, _freedesktop_screensaver_unregister_object, error);
	if (!result) {
		return 0;
	}
	return result;
}

static void
_freedesktop_screensaver_unregister_object (gpointer user_data)
{
	gpointer* data;
	data = user_data;
	g_object_unref (data[0]);
	g_object_unref (data[1]);
	g_free (data[2]);
	g_free (data);
}

