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

/*
 * SPDX-License-Identifier: LGPL-2.1-or-later
 * SPDX-FileCopyrightText: 2023 elementary, Inc. (https://elementary.io)
 */

#include <gtk/gtk.h>
#include <glib-object.h>
#include <gcr/gcr.h>
#include <gio/gio.h>
#include <glib.h>
#include <granite-7.h>
#include <polkitagent/polkitagent.h>
#include <polkit/polkit.h>
#include <unistd.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
#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 AG_TYPE_APPLICATION (ag_application_get_type ())
#define AG_APPLICATION(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), AG_TYPE_APPLICATION, AgApplication))
#define AG_APPLICATION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), AG_TYPE_APPLICATION, AgApplicationClass))
#define AG_IS_APPLICATION(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), AG_TYPE_APPLICATION))
#define AG_IS_APPLICATION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), AG_TYPE_APPLICATION))
#define AG_APPLICATION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), AG_TYPE_APPLICATION, AgApplicationClass))

typedef struct _AgApplication AgApplication;
typedef struct _AgApplicationClass AgApplicationClass;
typedef struct _AgApplicationPrivate AgApplicationPrivate;

#define AG_TYPE_GCR_AGENT (ag_gcr_agent_get_type ())
#define AG_GCR_AGENT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), AG_TYPE_GCR_AGENT, AgGcrAgent))
#define AG_GCR_AGENT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), AG_TYPE_GCR_AGENT, AgGcrAgentClass))
#define AG_IS_GCR_AGENT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), AG_TYPE_GCR_AGENT))
#define AG_IS_GCR_AGENT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), AG_TYPE_GCR_AGENT))
#define AG_GCR_AGENT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), AG_TYPE_GCR_AGENT, AgGcrAgentClass))

typedef struct _AgGcrAgent AgGcrAgent;
typedef struct _AgGcrAgentClass AgGcrAgentClass;
enum  {
	AG_APPLICATION_0_PROPERTY,
	AG_APPLICATION_NUM_PROPERTIES
};
static GParamSpec* ag_application_properties[AG_APPLICATION_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))

#define AG_TYPE_AGENT (ag_agent_get_type ())
#define AG_AGENT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), AG_TYPE_AGENT, AgAgent))
#define AG_AGENT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), AG_TYPE_AGENT, AgAgentClass))
#define AG_IS_AGENT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), AG_TYPE_AGENT))
#define AG_IS_AGENT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), AG_TYPE_AGENT))
#define AG_AGENT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), AG_TYPE_AGENT, AgAgentClass))

typedef struct _AgAgent AgAgent;
typedef struct _AgAgentClass AgAgentClass;
#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))

struct _AgApplication {
	GtkApplication parent_instance;
	AgApplicationPrivate * priv;
};

struct _AgApplicationClass {
	GtkApplicationClass parent_class;
};

struct _AgApplicationPrivate {
	AgGcrAgent* gcr_agent;
};

static gint AgApplication_private_offset;
static gpointer ag_application_parent_class = NULL;

VALA_EXTERN GType ag_application_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (AgApplication, g_object_unref)
VALA_EXTERN GType ag_gcr_agent_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (AgGcrAgent, g_object_unref)
VALA_EXTERN AgApplication* ag_application_new (void);
VALA_EXTERN AgApplication* ag_application_construct (GType object_type);
static void ag_application_real_startup (GApplication* base);
VALA_EXTERN GType ag_agent_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (AgAgent, g_object_unref)
VALA_EXTERN AgAgent* ag_agent_new (void);
VALA_EXTERN AgAgent* ag_agent_construct (GType object_type);
VALA_EXTERN AgGcrAgent* ag_gcr_agent_new (void);
VALA_EXTERN AgGcrAgent* ag_gcr_agent_construct (GType object_type);
static gint ag_application_main (gchar** args,
                          gint args_length1);
static void ag_application_finalize (GObject * obj);
static GType ag_application_get_type_once (void);

static inline gpointer
ag_application_get_instance_private (AgApplication* self)
{
	return G_STRUCT_MEMBER_P (self, AgApplication_private_offset);
}

AgApplication*
ag_application_construct (GType object_type)
{
	AgApplication * self = NULL;
	self = (AgApplication*) g_object_new (object_type, "application-id", "io.elementary.PolkitAgent", "flags", G_APPLICATION_IS_SERVICE, "register-session", TRUE, NULL);
	return self;
}

AgApplication*
ag_application_new (void)
{
	return ag_application_construct (AG_TYPE_APPLICATION);
}

static void
ag_application_real_startup (GApplication* base)
{
	AgApplication * self;
	AgAgent* agent = NULL;
	AgAgent* _tmp0_;
	AgGcrAgent* _tmp8_;
	GError* _inner_error0_ = NULL;
	self = (AgApplication*) base;
	G_APPLICATION_CLASS (ag_application_parent_class)->startup ((GApplication*) G_TYPE_CHECK_INSTANCE_CAST (self, gtk_application_get_type (), GtkApplication));
	granite_init ();
	_tmp0_ = ag_agent_new ();
	agent = _tmp0_;
	{
		PolkitUnixSession* subject = NULL;
		PolkitUnixSession* _tmp1_;
		AgAgent* _tmp2_;
		PolkitUnixSession* _tmp3_;
		const gchar* _tmp4_;
		const gchar* _tmp5_;
		_tmp1_ = (PolkitUnixSession*) polkit_unix_session_new_for_process_sync ((gint) getpid (), NULL, &_inner_error0_);
		subject = _tmp1_;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			goto __catch0_g_error;
		}
		_tmp2_ = agent;
		_tmp3_ = subject;
		_tmp4_ = g_application_get_resource_base_path ((GApplication*) self);
		_tmp5_ = _tmp4_;
		polkit_agent_listener_register ((PolkitAgentListener*) _tmp2_, POLKIT_AGENT_REGISTER_FLAGS_NONE, (PolkitSubject*) _tmp3_, _tmp5_, NULL, &_inner_error0_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			_g_object_unref0 (subject);
			goto __catch0_g_error;
		}
		_g_object_unref0 (subject);
	}
	goto __finally0;
	__catch0_g_error:
	{
		GError* e = NULL;
		GError* _tmp6_;
		const gchar* _tmp7_;
		e = _inner_error0_;
		_inner_error0_ = NULL;
		_tmp6_ = e;
		_tmp7_ = _tmp6_->message;
		g_critical ("Application.vala:27: Unable to initiate Polkit: %s", _tmp7_);
		_g_error_free0 (e);
	}
	__finally0:
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		_g_object_unref0 (agent);
		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;
	}
	_tmp8_ = ag_gcr_agent_new ();
	_g_object_unref0 (self->priv->gcr_agent);
	self->priv->gcr_agent = _tmp8_;
	g_application_hold ((GApplication*) self);
	_g_object_unref0 (agent);
}

static gint
ag_application_main (gchar** args,
                     gint args_length1)
{
	AgApplication* _tmp0_;
	AgApplication* _tmp1_;
	gint _tmp2_;
	gint result;
	_tmp0_ = ag_application_new ();
	_tmp1_ = _tmp0_;
	_tmp2_ = g_application_run ((GApplication*) _tmp1_, (gint) args_length1, args);
	_g_object_unref0 (_tmp1_);
	result = _tmp2_;
	return result;
}

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

static void
ag_application_class_init (AgApplicationClass * klass,
                           gpointer klass_data)
{
	ag_application_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &AgApplication_private_offset);
	((GApplicationClass *) klass)->startup = (void (*) (GApplication*)) ag_application_real_startup;
	G_OBJECT_CLASS (klass)->finalize = ag_application_finalize;
}

static void
ag_application_instance_init (AgApplication * self,
                              gpointer klass)
{
	self->priv = ag_application_get_instance_private (self);
}

static void
ag_application_finalize (GObject * obj)
{
	AgApplication * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, AG_TYPE_APPLICATION, AgApplication);
	_g_object_unref0 (self->priv->gcr_agent);
	G_OBJECT_CLASS (ag_application_parent_class)->finalize (obj);
}

static GType
ag_application_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (AgApplicationClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) ag_application_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (AgApplication), 0, (GInstanceInitFunc) ag_application_instance_init, NULL };
	GType ag_application_type_id;
	ag_application_type_id = g_type_register_static (gtk_application_get_type (), "AgApplication", &g_define_type_info, 0);
	AgApplication_private_offset = g_type_add_instance_private (ag_application_type_id, sizeof (AgApplicationPrivate));
	return ag_application_type_id;
}

GType
ag_application_get_type (void)
{
	static volatile gsize ag_application_type_id__once = 0;
	if (g_once_init_enter (&ag_application_type_id__once)) {
		GType ag_application_type_id;
		ag_application_type_id = ag_application_get_type_once ();
		g_once_init_leave (&ag_application_type_id__once, ag_application_type_id);
	}
	return ag_application_type_id__once;
}

