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

/*
 * Copyright (C) 2013-2017 elementary Developers
 *
 * 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/>.
 */

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

#define CONTRACTOR_APPLICATION_DBUS_NAME "org.elementary.Contractor"
#define CONTRACTOR_APPLICATION_DBUS_PATH "/org/elementary/contractor"
#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 CONTRACTOR_TYPE_APPLICATION (contractor_application_get_type ())
#define CONTRACTOR_APPLICATION(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), CONTRACTOR_TYPE_APPLICATION, ContractorApplication))
#define CONTRACTOR_APPLICATION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), CONTRACTOR_TYPE_APPLICATION, ContractorApplicationClass))
#define CONTRACTOR_IS_APPLICATION(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), CONTRACTOR_TYPE_APPLICATION))
#define CONTRACTOR_IS_APPLICATION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), CONTRACTOR_TYPE_APPLICATION))
#define CONTRACTOR_APPLICATION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), CONTRACTOR_TYPE_APPLICATION, ContractorApplicationClass))

typedef struct _ContractorApplication ContractorApplication;
typedef struct _ContractorApplicationClass ContractorApplicationClass;
typedef struct _ContractorApplicationPrivate ContractorApplicationPrivate;

#define CONTRACTOR_TYPE_DBUS_SERVICE (contractor_dbus_service_get_type ())
#define CONTRACTOR_DBUS_SERVICE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), CONTRACTOR_TYPE_DBUS_SERVICE, ContractorDBusService))
#define CONTRACTOR_DBUS_SERVICE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), CONTRACTOR_TYPE_DBUS_SERVICE, ContractorDBusServiceClass))
#define CONTRACTOR_IS_DBUS_SERVICE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), CONTRACTOR_TYPE_DBUS_SERVICE))
#define CONTRACTOR_IS_DBUS_SERVICE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), CONTRACTOR_TYPE_DBUS_SERVICE))
#define CONTRACTOR_DBUS_SERVICE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), CONTRACTOR_TYPE_DBUS_SERVICE, ContractorDBusServiceClass))

typedef struct _ContractorDBusService ContractorDBusService;
typedef struct _ContractorDBusServiceClass ContractorDBusServiceClass;
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_main_loop_unref0(var) ((var == NULL) ? NULL : (var = (g_main_loop_unref (var), NULL)))
#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))
typedef struct _ContractorParamSpecApplication ContractorParamSpecApplication;

struct _ContractorApplication {
	GTypeInstance parent_instance;
	volatile int ref_count;
	ContractorApplicationPrivate * priv;
};

struct _ContractorApplicationClass {
	GTypeClass parent_class;
	void (*finalize) (ContractorApplication *self);
};

struct _ContractorApplicationPrivate {
	ContractorDBusService* dbus_service;
	GMainLoop* main_loop;
};

struct _ContractorParamSpecApplication {
	GParamSpec parent_instance;
};

static gint ContractorApplication_private_offset;
static gpointer contractor_application_parent_class = NULL;

VALA_EXTERN gpointer contractor_application_ref (gpointer instance);
VALA_EXTERN void contractor_application_unref (gpointer instance);
VALA_EXTERN GParamSpec* contractor_param_spec_application (const gchar* name,
                                               const gchar* nick,
                                               const gchar* blurb,
                                               GType object_type,
                                               GParamFlags flags);
VALA_EXTERN void contractor_value_set_application (GValue* value,
                                       gpointer v_object);
VALA_EXTERN void contractor_value_take_application (GValue* value,
                                        gpointer v_object);
VALA_EXTERN gpointer contractor_value_get_application (const GValue* value);
VALA_EXTERN GType contractor_application_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (ContractorApplication, contractor_application_unref)
VALA_EXTERN GType contractor_dbus_service_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (ContractorDBusService, g_object_unref)
VALA_EXTERN guint contractor_dbus_service_register_object (void* object,
                                               GDBusConnection* connection,
                                               const gchar* path,
                                               GError** error);
VALA_EXTERN void contractor_application_run (ContractorApplication* self);
static void contractor_application_init_service (ContractorApplication* self);
static void contractor_application_quit (ContractorApplication* self);
static void contractor_application_on_bus_aquired (ContractorApplication* self,
                                            GDBusConnection* conn);
static void _contractor_application_on_bus_aquired_gbus_acquired_callback (GDBusConnection* connection,
                                                                    const gchar* name,
                                                                    gpointer self);
static void __lambda6_ (ContractorApplication* self);
static void ___lambda6__gbus_name_acquired_callback (GDBusConnection* connection,
                                              const gchar* name,
                                              gpointer self);
static void __lambda7_ (ContractorApplication* self);
static void contractor_application_on_bus_not_aquired (ContractorApplication* self);
static void ___lambda7__gbus_name_lost_callback (GDBusConnection* connection,
                                          const gchar* name,
                                          gpointer self);
VALA_EXTERN ContractorDBusService* contractor_dbus_service_new (void);
VALA_EXTERN ContractorDBusService* contractor_dbus_service_construct (GType object_type);
VALA_EXTERN ContractorApplication* contractor_application_new (void);
VALA_EXTERN ContractorApplication* contractor_application_construct (GType object_type);
static void contractor_application_finalize (ContractorApplication * obj);
static GType contractor_application_get_type_once (void);

static inline gpointer
contractor_application_get_instance_private (ContractorApplication* self)
{
	return G_STRUCT_MEMBER_P (self, ContractorApplication_private_offset);
}

void
contractor_application_run (ContractorApplication* self)
{
	GMainLoop* _tmp0_;
	GMainLoop* _tmp1_;
	g_return_if_fail (self != NULL);
	_tmp0_ = g_main_loop_new (NULL, FALSE);
	_g_main_loop_unref0 (self->priv->main_loop);
	self->priv->main_loop = _tmp0_;
	contractor_application_init_service (self);
	_tmp1_ = self->priv->main_loop;
	g_main_loop_run (_tmp1_);
}

static void
contractor_application_quit (ContractorApplication* self)
{
	GMainLoop* _tmp0_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->main_loop;
	g_main_loop_quit (_tmp0_);
}

static void
_contractor_application_on_bus_aquired_gbus_acquired_callback (GDBusConnection* connection,
                                                               const gchar* name,
                                                               gpointer self)
{
	contractor_application_on_bus_aquired ((ContractorApplication*) self, connection);
}

static void
__lambda6_ (ContractorApplication* self)
{
}

static void
___lambda6__gbus_name_acquired_callback (GDBusConnection* connection,
                                         const gchar* name,
                                         gpointer self)
{
	__lambda6_ ((ContractorApplication*) self);
}

static void
__lambda7_ (ContractorApplication* self)
{
}

static void
___lambda7__gbus_name_lost_callback (GDBusConnection* connection,
                                     const gchar* name,
                                     gpointer self)
{
	__lambda7_ ((ContractorApplication*) self);
}

static void
contractor_application_init_service (ContractorApplication* self)
{
	g_return_if_fail (self != NULL);
	g_bus_own_name_with_closures (G_BUS_TYPE_SESSION, CONTRACTOR_APPLICATION_DBUS_NAME, G_BUS_NAME_OWNER_FLAGS_NONE, (GClosure*) ((_contractor_application_on_bus_aquired_gbus_acquired_callback == NULL) ? NULL : g_cclosure_new ((GCallback) _contractor_application_on_bus_aquired_gbus_acquired_callback, contractor_application_ref (self), (GClosureNotify) contractor_application_unref)), (GClosure*) ((___lambda6__gbus_name_acquired_callback == NULL) ? NULL : g_cclosure_new ((GCallback) ___lambda6__gbus_name_acquired_callback, contractor_application_ref (self), (GClosureNotify) contractor_application_unref)), (GClosure*) ((___lambda7__gbus_name_lost_callback == NULL) ? NULL : g_cclosure_new ((GCallback) ___lambda7__gbus_name_lost_callback, contractor_application_ref (self), (GClosureNotify) contractor_application_unref)));
}

static void
contractor_application_on_bus_aquired (ContractorApplication* self,
                                       GDBusConnection* conn)
{
	ContractorDBusService* _tmp0_;
	GError* _inner_error0_ = NULL;
	g_return_if_fail (self != NULL);
	g_return_if_fail (conn != NULL);
	_tmp0_ = contractor_dbus_service_new ();
	_g_object_unref0 (self->priv->dbus_service);
	self->priv->dbus_service = _tmp0_;
	{
		ContractorDBusService* _tmp1_;
		_tmp1_ = self->priv->dbus_service;
		contractor_dbus_service_register_object (_tmp1_, conn, CONTRACTOR_APPLICATION_DBUS_PATH, &_inner_error0_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			if (_inner_error0_->domain == G_IO_ERROR) {
				goto __catch0_g_io_error;
			}
			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 ("Application.vala:48: Could not register service: %s.", _tmp3_);
		contractor_application_quit (self);
		_g_error_free0 (e);
	}
	__finally0:
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		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;
	}
}

static void
contractor_application_on_bus_not_aquired (ContractorApplication* self)
{
	g_return_if_fail (self != NULL);
	g_critical ("Application.vala:54: Could not aquire Session bus for contractor.");
	contractor_application_quit (self);
}

ContractorApplication*
contractor_application_construct (GType object_type)
{
	ContractorApplication* self = NULL;
	self = (ContractorApplication*) g_type_create_instance (object_type);
	return self;
}

ContractorApplication*
contractor_application_new (void)
{
	return contractor_application_construct (CONTRACTOR_TYPE_APPLICATION);
}

static void
contractor_value_application_init (GValue* value)
{
	value->data[0].v_pointer = NULL;
}

static void
contractor_value_application_free_value (GValue* value)
{
	if (value->data[0].v_pointer) {
		contractor_application_unref (value->data[0].v_pointer);
	}
}

static void
contractor_value_application_copy_value (const GValue* src_value,
                                         GValue* dest_value)
{
	if (src_value->data[0].v_pointer) {
		dest_value->data[0].v_pointer = contractor_application_ref (src_value->data[0].v_pointer);
	} else {
		dest_value->data[0].v_pointer = NULL;
	}
}

static gpointer
contractor_value_application_peek_pointer (const GValue* value)
{
	return value->data[0].v_pointer;
}

static gchar*
contractor_value_application_collect_value (GValue* value,
                                            guint n_collect_values,
                                            GTypeCValue* collect_values,
                                            guint collect_flags)
{
	if (collect_values[0].v_pointer) {
		ContractorApplication * object;
		object = collect_values[0].v_pointer;
		if (object->parent_instance.g_class == NULL) {
			return g_strconcat ("invalid unclassed object pointer for value type `", G_VALUE_TYPE_NAME (value), "'", NULL);
		} else if (!g_value_type_compatible (G_TYPE_FROM_INSTANCE (object), G_VALUE_TYPE (value))) {
			return g_strconcat ("invalid object type `", g_type_name (G_TYPE_FROM_INSTANCE (object)), "' for value type `", G_VALUE_TYPE_NAME (value), "'", NULL);
		}
		value->data[0].v_pointer = contractor_application_ref (object);
	} else {
		value->data[0].v_pointer = NULL;
	}
	return NULL;
}

static gchar*
contractor_value_application_lcopy_value (const GValue* value,
                                          guint n_collect_values,
                                          GTypeCValue* collect_values,
                                          guint collect_flags)
{
	ContractorApplication ** object_p;
	object_p = collect_values[0].v_pointer;
	if (!object_p) {
		return g_strdup_printf ("value location for `%s' passed as NULL", G_VALUE_TYPE_NAME (value));
	}
	if (!value->data[0].v_pointer) {
		*object_p = NULL;
	} else if (collect_flags & G_VALUE_NOCOPY_CONTENTS) {
		*object_p = value->data[0].v_pointer;
	} else {
		*object_p = contractor_application_ref (value->data[0].v_pointer);
	}
	return NULL;
}

GParamSpec*
contractor_param_spec_application (const gchar* name,
                                   const gchar* nick,
                                   const gchar* blurb,
                                   GType object_type,
                                   GParamFlags flags)
{
	ContractorParamSpecApplication* spec;
	g_return_val_if_fail (g_type_is_a (object_type, CONTRACTOR_TYPE_APPLICATION), NULL);
	spec = g_param_spec_internal (G_TYPE_PARAM_OBJECT, name, nick, blurb, flags);
	G_PARAM_SPEC (spec)->value_type = object_type;
	return G_PARAM_SPEC (spec);
}

gpointer
contractor_value_get_application (const GValue* value)
{
	g_return_val_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, CONTRACTOR_TYPE_APPLICATION), NULL);
	return value->data[0].v_pointer;
}

void
contractor_value_set_application (GValue* value,
                                  gpointer v_object)
{
	ContractorApplication * old;
	g_return_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, CONTRACTOR_TYPE_APPLICATION));
	old = value->data[0].v_pointer;
	if (v_object) {
		g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (v_object, CONTRACTOR_TYPE_APPLICATION));
		g_return_if_fail (g_value_type_compatible (G_TYPE_FROM_INSTANCE (v_object), G_VALUE_TYPE (value)));
		value->data[0].v_pointer = v_object;
		contractor_application_ref (value->data[0].v_pointer);
	} else {
		value->data[0].v_pointer = NULL;
	}
	if (old) {
		contractor_application_unref (old);
	}
}

void
contractor_value_take_application (GValue* value,
                                   gpointer v_object)
{
	ContractorApplication * old;
	g_return_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, CONTRACTOR_TYPE_APPLICATION));
	old = value->data[0].v_pointer;
	if (v_object) {
		g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (v_object, CONTRACTOR_TYPE_APPLICATION));
		g_return_if_fail (g_value_type_compatible (G_TYPE_FROM_INSTANCE (v_object), G_VALUE_TYPE (value)));
		value->data[0].v_pointer = v_object;
	} else {
		value->data[0].v_pointer = NULL;
	}
	if (old) {
		contractor_application_unref (old);
	}
}

static void
contractor_application_class_init (ContractorApplicationClass * klass,
                                   gpointer klass_data)
{
	contractor_application_parent_class = g_type_class_peek_parent (klass);
	((ContractorApplicationClass *) klass)->finalize = contractor_application_finalize;
	g_type_class_adjust_private_offset (klass, &ContractorApplication_private_offset);
}

static void
contractor_application_instance_init (ContractorApplication * self,
                                      gpointer klass)
{
	self->priv = contractor_application_get_instance_private (self);
	self->ref_count = 1;
}

static void
contractor_application_finalize (ContractorApplication * obj)
{
	ContractorApplication * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, CONTRACTOR_TYPE_APPLICATION, ContractorApplication);
	g_signal_handlers_destroy (self);
	_g_object_unref0 (self->priv->dbus_service);
	_g_main_loop_unref0 (self->priv->main_loop);
}

static GType
contractor_application_get_type_once (void)
{
	static const GTypeValueTable g_define_type_value_table = { contractor_value_application_init, contractor_value_application_free_value, contractor_value_application_copy_value, contractor_value_application_peek_pointer, "p", contractor_value_application_collect_value, "p", contractor_value_application_lcopy_value };
	static const GTypeInfo g_define_type_info = { sizeof (ContractorApplicationClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) contractor_application_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (ContractorApplication), 0, (GInstanceInitFunc) contractor_application_instance_init, &g_define_type_value_table };
	static const GTypeFundamentalInfo g_define_type_fundamental_info = { (G_TYPE_FLAG_CLASSED | G_TYPE_FLAG_INSTANTIATABLE | G_TYPE_FLAG_DERIVABLE | G_TYPE_FLAG_DEEP_DERIVABLE) };
	GType contractor_application_type_id;
	contractor_application_type_id = g_type_register_fundamental (g_type_fundamental_next (), "ContractorApplication", &g_define_type_info, &g_define_type_fundamental_info, 0);
	ContractorApplication_private_offset = g_type_add_instance_private (contractor_application_type_id, sizeof (ContractorApplicationPrivate));
	return contractor_application_type_id;
}

GType
contractor_application_get_type (void)
{
	static volatile gsize contractor_application_type_id__once = 0;
	if (g_once_init_enter (&contractor_application_type_id__once)) {
		GType contractor_application_type_id;
		contractor_application_type_id = contractor_application_get_type_once ();
		g_once_init_leave (&contractor_application_type_id__once, contractor_application_type_id);
	}
	return contractor_application_type_id__once;
}

gpointer
contractor_application_ref (gpointer instance)
{
	ContractorApplication * self;
	self = instance;
	g_atomic_int_inc (&self->ref_count);
	return instance;
}

void
contractor_application_unref (gpointer instance)
{
	ContractorApplication * self;
	self = instance;
	if (g_atomic_int_dec_and_test (&self->ref_count)) {
		CONTRACTOR_APPLICATION_GET_CLASS (self)->finalize (self);
		g_type_free_instance ((GTypeInstance *) self);
	}
}

