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

/*
 * Copyright (c) 2011-2015 elementary Developers (https://launchpad.net/elementary)
 *
 * 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 2 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, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA  02110-1301, USA.
 */

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

#define LOGIN_DHELPER_APPLICATION_ACTIVE_TIMEOUT_SECONDS ((guint) 5)
#define POWER_LOGIND_HELPER_OBJECT_PATH "/io/elementary/logind/helper"
#define POWER_LOGIND_HELPER_NAME "io.elementary.logind.helper"
#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 LOGIN_DHELPER_TYPE_APPLICATION (login_dhelper_application_get_type ())
#define LOGIN_DHELPER_APPLICATION(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), LOGIN_DHELPER_TYPE_APPLICATION, LoginDHelperApplication))
#define LOGIN_DHELPER_APPLICATION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), LOGIN_DHELPER_TYPE_APPLICATION, LoginDHelperApplicationClass))
#define LOGIN_DHELPER_IS_APPLICATION(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), LOGIN_DHELPER_TYPE_APPLICATION))
#define LOGIN_DHELPER_IS_APPLICATION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), LOGIN_DHELPER_TYPE_APPLICATION))
#define LOGIN_DHELPER_APPLICATION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), LOGIN_DHELPER_TYPE_APPLICATION, LoginDHelperApplicationClass))

typedef struct _LoginDHelperApplication LoginDHelperApplication;
typedef struct _LoginDHelperApplicationClass LoginDHelperApplicationClass;
typedef struct _LoginDHelperApplicationPrivate LoginDHelperApplicationPrivate;
enum  {
	LOGIN_DHELPER_APPLICATION_0_PROPERTY,
	LOGIN_DHELPER_APPLICATION_NUM_PROPERTIES
};
static GParamSpec* login_dhelper_application_properties[LOGIN_DHELPER_APPLICATION_NUM_PROPERTIES];

#define LOGIN_DHELPER_TYPE_SERVER (login_dhelper_server_get_type ())
#define LOGIN_DHELPER_SERVER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), LOGIN_DHELPER_TYPE_SERVER, LoginDHelperServer))
#define LOGIN_DHELPER_SERVER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), LOGIN_DHELPER_TYPE_SERVER, LoginDHelperServerClass))
#define LOGIN_DHELPER_IS_SERVER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), LOGIN_DHELPER_TYPE_SERVER))
#define LOGIN_DHELPER_IS_SERVER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), LOGIN_DHELPER_TYPE_SERVER))
#define LOGIN_DHELPER_SERVER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), LOGIN_DHELPER_TYPE_SERVER, LoginDHelperServerClass))

typedef struct _LoginDHelperServer LoginDHelperServer;
typedef struct _LoginDHelperServerClass LoginDHelperServerClass;
#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)))

struct _LoginDHelperApplication {
	GApplication parent_instance;
	LoginDHelperApplicationPrivate * priv;
};

struct _LoginDHelperApplicationClass {
	GApplicationClass parent_class;
};

struct _LoginDHelperApplicationPrivate {
	guint timeout_id;
	guint own_id;
};

static gint LoginDHelperApplication_private_offset;
static gpointer login_dhelper_application_parent_class = NULL;

VALA_EXTERN GType login_dhelper_application_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (LoginDHelperApplication, g_object_unref)
static void login_dhelper_application_on_bus_lost (LoginDHelperApplication* self,
                                            GDBusConnection* connection,
                                            const gchar* name);
static void login_dhelper_application_on_bus_acquired (LoginDHelperApplication* self,
                                                GDBusConnection* connection);
VALA_EXTERN GType login_dhelper_server_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (LoginDHelperServer, g_object_unref)
VALA_EXTERN guint login_dhelper_server_register_object (void* object,
                                            GDBusConnection* connection,
                                            const gchar* path,
                                            GError** error);
VALA_EXTERN LoginDHelperServer* login_dhelper_server_get_default (void);
static void login_dhelper_application_on_reset_timeout (LoginDHelperApplication* self);
static void _login_dhelper_application_on_reset_timeout_login_dhelper_server_reset_timeout (LoginDHelperServer* _sender,
                                                                                     gpointer self);
static gboolean __lambda4_ (LoginDHelperApplication* self);
static gboolean ___lambda4__gsource_func (gpointer self);
static void login_dhelper_application_real_activate (GApplication* base);
static void _login_dhelper_application_on_bus_acquired_gbus_acquired_callback (GDBusConnection* connection,
                                                                        const gchar* name,
                                                                        gpointer self);
static void _login_dhelper_application_on_bus_lost_gbus_name_lost_callback (GDBusConnection* connection,
                                                                     const gchar* name,
                                                                     gpointer self);
static void login_dhelper_application_real_shutdown (GApplication* base);
static gint login_dhelper_application_main (gchar** args,
                                     gint args_length1);
VALA_EXTERN LoginDHelperApplication* login_dhelper_application_new (void);
VALA_EXTERN LoginDHelperApplication* login_dhelper_application_construct (GType object_type);
static GObject * login_dhelper_application_constructor (GType type,
                                                 guint n_construct_properties,
                                                 GObjectConstructParam * construct_properties);
static void login_dhelper_application_finalize (GObject * obj);
static GType login_dhelper_application_get_type_once (void);

static inline gpointer
login_dhelper_application_get_instance_private (LoginDHelperApplication* self)
{
	return G_STRUCT_MEMBER_P (self, LoginDHelperApplication_private_offset);
}

static void
login_dhelper_application_on_bus_lost (LoginDHelperApplication* self,
                                       GDBusConnection* connection,
                                       const gchar* name)
{
	g_return_if_fail (self != NULL);
	g_return_if_fail (connection != NULL);
	g_return_if_fail (name != NULL);
	g_warning ("main.vala:30: Could not acquire name: %s", name);
}

static gpointer
_g_object_ref0 (gpointer self)
{
	return self ? g_object_ref (self) : NULL;
}

static void
_login_dhelper_application_on_reset_timeout_login_dhelper_server_reset_timeout (LoginDHelperServer* _sender,
                                                                                gpointer self)
{
	login_dhelper_application_on_reset_timeout ((LoginDHelperApplication*) self);
}

static void
login_dhelper_application_on_bus_acquired (LoginDHelperApplication* self,
                                           GDBusConnection* connection)
{
	LoginDHelperServer* server = NULL;
	LoginDHelperServer* _tmp0_;
	LoginDHelperServer* _tmp1_;
	GError* _inner_error0_ = NULL;
	g_return_if_fail (self != NULL);
	g_return_if_fail (connection != NULL);
	_tmp0_ = login_dhelper_server_get_default ();
	_tmp1_ = _g_object_ref0 (_tmp0_);
	server = _tmp1_;
	g_signal_connect_object (server, "reset-timeout", (GCallback) _login_dhelper_application_on_reset_timeout_login_dhelper_server_reset_timeout, self, 0);
	{
		login_dhelper_server_register_object (server, connection, POWER_LOGIND_HELPER_OBJECT_PATH, &_inner_error0_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			if (_inner_error0_->domain == G_IO_ERROR) {
				goto __catch0_g_io_error;
			}
			_g_object_unref0 (server);
			g_critical ("file %s: line %d: unexpected 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;
		}
	}
	goto __finally0;
	__catch0_g_io_error:
	{
		GError* e = NULL;
		GError* _tmp2_;
		const gchar* _tmp3_;
		e = _inner_error0_;
		_inner_error0_ = NULL;
		_tmp2_ = e;
		_tmp3_ = _tmp2_->message;
		g_warning ("main.vala:40: %s", _tmp3_);
		_g_error_free0 (e);
	}
	__finally0:
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		_g_object_unref0 (server);
		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;
	}
	login_dhelper_application_on_reset_timeout (self);
	_g_object_unref0 (server);
}

static gboolean
__lambda4_ (LoginDHelperApplication* self)
{
	gboolean result;
	self->priv->timeout_id = (guint) 0;
	g_application_release ((GApplication*) self);
	result = FALSE;
	return result;
}

static gboolean
___lambda4__gsource_func (gpointer self)
{
	gboolean result;
	result = __lambda4_ ((LoginDHelperApplication*) self);
	return result;
}

static void
login_dhelper_application_on_reset_timeout (LoginDHelperApplication* self)
{
	g_return_if_fail (self != NULL);
	if (self->priv->timeout_id > ((guint) 0)) {
		g_source_remove (self->priv->timeout_id);
		self->priv->timeout_id = (guint) 0;
	}
	self->priv->timeout_id = g_timeout_add_seconds_full (G_PRIORITY_DEFAULT, LOGIN_DHELPER_APPLICATION_ACTIVE_TIMEOUT_SECONDS, ___lambda4__gsource_func, g_object_ref (self), g_object_unref);
}

static void
_login_dhelper_application_on_bus_acquired_gbus_acquired_callback (GDBusConnection* connection,
                                                                   const gchar* name,
                                                                   gpointer self)
{
	login_dhelper_application_on_bus_acquired ((LoginDHelperApplication*) self, connection);
}

static void
_login_dhelper_application_on_bus_lost_gbus_name_lost_callback (GDBusConnection* connection,
                                                                const gchar* name,
                                                                gpointer self)
{
	login_dhelper_application_on_bus_lost ((LoginDHelperApplication*) self, connection, name);
}

static void
login_dhelper_application_real_activate (GApplication* base)
{
	LoginDHelperApplication * self;
	self = (LoginDHelperApplication*) base;
	self->priv->own_id = g_bus_own_name_with_closures (G_BUS_TYPE_SYSTEM, POWER_LOGIND_HELPER_NAME, G_BUS_NAME_OWNER_FLAGS_REPLACE, (GClosure*) ((_login_dhelper_application_on_bus_acquired_gbus_acquired_callback == NULL) ? NULL : g_cclosure_new ((GCallback) _login_dhelper_application_on_bus_acquired_gbus_acquired_callback, g_object_ref (self), (GClosureNotify) g_object_unref)), (GClosure*) ((NULL == NULL) ? NULL : g_cclosure_new ((GCallback) NULL, NULL, (GClosureNotify) NULL)), (GClosure*) ((_login_dhelper_application_on_bus_lost_gbus_name_lost_callback == NULL) ? NULL : g_cclosure_new ((GCallback) _login_dhelper_application_on_bus_lost_gbus_name_lost_callback, g_object_ref (self), (GClosureNotify) g_object_unref)));
	g_application_hold ((GApplication*) self);
}

static void
login_dhelper_application_real_shutdown (GApplication* base)
{
	LoginDHelperApplication * self;
	self = (LoginDHelperApplication*) base;
	if (self->priv->own_id != ((guint) -1)) {
		g_bus_unown_name (self->priv->own_id);
	}
	G_APPLICATION_CLASS (login_dhelper_application_parent_class)->shutdown (G_TYPE_CHECK_INSTANCE_CAST (self, g_application_get_type (), GApplication));
}

static gint
login_dhelper_application_main (gchar** args,
                                gint args_length1)
{
	LoginDHelperApplication* app = NULL;
	LoginDHelperApplication* _tmp0_;
	gint result;
	_tmp0_ = login_dhelper_application_new ();
	app = _tmp0_;
	result = g_application_run ((GApplication*) app, (gint) args_length1, args);
	_g_object_unref0 (app);
	return result;
}

int
main (int argc,
      char ** argv)
{
	return login_dhelper_application_main (argv, argc);
}

LoginDHelperApplication*
login_dhelper_application_construct (GType object_type)
{
	LoginDHelperApplication * self = NULL;
	self = (LoginDHelperApplication*) g_object_new (object_type, NULL);
	return self;
}

LoginDHelperApplication*
login_dhelper_application_new (void)
{
	return login_dhelper_application_construct (LOGIN_DHELPER_TYPE_APPLICATION);
}

static GObject *
login_dhelper_application_constructor (GType type,
                                       guint n_construct_properties,
                                       GObjectConstructParam * construct_properties)
{
	GObject * obj;
	GObjectClass * parent_class;
	LoginDHelperApplication * self;
	parent_class = G_OBJECT_CLASS (login_dhelper_application_parent_class);
	obj = parent_class->constructor (type, n_construct_properties, construct_properties);
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, LOGIN_DHELPER_TYPE_APPLICATION, LoginDHelperApplication);
	g_application_set_application_id ((GApplication*) self, POWER_LOGIND_HELPER_NAME);
	return obj;
}

static void
login_dhelper_application_class_init (LoginDHelperApplicationClass * klass,
                                      gpointer klass_data)
{
	login_dhelper_application_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &LoginDHelperApplication_private_offset);
	((GApplicationClass *) klass)->activate = (void (*) (GApplication*)) login_dhelper_application_real_activate;
	((GApplicationClass *) klass)->shutdown = (void (*) (GApplication*)) login_dhelper_application_real_shutdown;
	G_OBJECT_CLASS (klass)->constructor = login_dhelper_application_constructor;
	G_OBJECT_CLASS (klass)->finalize = login_dhelper_application_finalize;
}

static void
login_dhelper_application_instance_init (LoginDHelperApplication * self,
                                         gpointer klass)
{
	self->priv = login_dhelper_application_get_instance_private (self);
	self->priv->timeout_id = (guint) 0;
	self->priv->own_id = (guint) -1;
}

static void
login_dhelper_application_finalize (GObject * obj)
{
	LoginDHelperApplication * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, LOGIN_DHELPER_TYPE_APPLICATION, LoginDHelperApplication);
	G_OBJECT_CLASS (login_dhelper_application_parent_class)->finalize (obj);
}

static GType
login_dhelper_application_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (LoginDHelperApplicationClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) login_dhelper_application_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (LoginDHelperApplication), 0, (GInstanceInitFunc) login_dhelper_application_instance_init, NULL };
	GType login_dhelper_application_type_id;
	login_dhelper_application_type_id = g_type_register_static (g_application_get_type (), "LoginDHelperApplication", &g_define_type_info, 0);
	LoginDHelperApplication_private_offset = g_type_add_instance_private (login_dhelper_application_type_id, sizeof (LoginDHelperApplicationPrivate));
	return login_dhelper_application_type_id;
}

GType
login_dhelper_application_get_type (void)
{
	static volatile gsize login_dhelper_application_type_id__once = 0;
	if (g_once_init_enter (&login_dhelper_application_type_id__once)) {
		GType login_dhelper_application_type_id;
		login_dhelper_application_type_id = login_dhelper_application_get_type_once ();
		g_once_init_leave (&login_dhelper_application_type_id__once, login_dhelper_application_type_id);
	}
	return login_dhelper_application_type_id__once;
}

