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

/*
 * Copyright (c) 2017 elementary, Inc. (https://elementary.io)
 *
 * 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 "power.h"
#include <stdlib.h>
#include <string.h>
#include <glib.h>
#include <gio/gio.h>
#include <glib-object.h>
#include <gobject/gvaluecollector.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

#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 _PowerParamSpecLogindHelper PowerParamSpecLogindHelper;

struct _PowerParamSpecLogindHelper {
	GParamSpec parent_instance;
};

static gpointer power_logind_helper_parent_class = NULL;
static PowerLogindHelperIface* power_logind_helper_instance;
static PowerLogindHelperIface* power_logind_helper_instance = NULL;

static void power_logind_helper_finalize (PowerLogindHelper * obj);
static GType power_logind_helper_get_type_once (void);

PowerLogindHelperAction
power_logind_helper_action_from_string (const gchar* str)
{
	const gchar* _tmp0_;
	GQuark _tmp2_ = 0U;
	static GQuark _tmp1_label0 = 0;
	static GQuark _tmp1_label1 = 0;
	static GQuark _tmp1_label2 = 0;
	static GQuark _tmp1_label3 = 0;
	static GQuark _tmp1_label4 = 0;
	PowerLogindHelperAction result;
	g_return_val_if_fail (str != NULL, 0);
	_tmp0_ = str;
	_tmp2_ = (NULL == _tmp0_) ? 0 : g_quark_from_string (_tmp0_);
	if (_tmp2_ == ((0 != _tmp1_label0) ? _tmp1_label0 : (_tmp1_label0 = g_quark_from_static_string ("ignore")))) {
		switch (0) {
			default:
			{
				result = POWER_LOGIND_HELPER_ACTION_IGNORE;
				return result;
			}
		}
	} else if (_tmp2_ == ((0 != _tmp1_label1) ? _tmp1_label1 : (_tmp1_label1 = g_quark_from_static_string ("poweroff")))) {
		switch (0) {
			default:
			{
				result = POWER_LOGIND_HELPER_ACTION_POWEROFF;
				return result;
			}
		}
	} else if (_tmp2_ == ((0 != _tmp1_label2) ? _tmp1_label2 : (_tmp1_label2 = g_quark_from_static_string ("lock")))) {
		switch (0) {
			default:
			{
				result = POWER_LOGIND_HELPER_ACTION_LOCK;
				return result;
			}
		}
	} else if (_tmp2_ == ((0 != _tmp1_label3) ? _tmp1_label3 : (_tmp1_label3 = g_quark_from_static_string ("suspend")))) {
		switch (0) {
			default:
			{
				result = POWER_LOGIND_HELPER_ACTION_SUSPEND;
				return result;
			}
		}
	} else if (_tmp2_ == ((0 != _tmp1_label4) ? _tmp1_label4 : (_tmp1_label4 = g_quark_from_static_string ("halt")))) {
		switch (0) {
			default:
			{
				result = POWER_LOGIND_HELPER_ACTION_HALT;
				return result;
			}
		}
	} else {
		switch (0) {
			default:
			{
				result = POWER_LOGIND_HELPER_ACTION_UNKNOWN;
				return result;
			}
		}
	}
}

gchar*
power_logind_helper_action_to_string (PowerLogindHelperAction self)
{
	gchar* result;
	switch (self) {
		case POWER_LOGIND_HELPER_ACTION_IGNORE:
		{
			gchar* _tmp0_;
			_tmp0_ = g_strdup ("ignore");
			result = _tmp0_;
			return result;
		}
		case POWER_LOGIND_HELPER_ACTION_POWEROFF:
		{
			gchar* _tmp1_;
			_tmp1_ = g_strdup ("poweroff");
			result = _tmp1_;
			return result;
		}
		case POWER_LOGIND_HELPER_ACTION_LOCK:
		{
			gchar* _tmp2_;
			_tmp2_ = g_strdup ("lock");
			result = _tmp2_;
			return result;
		}
		case POWER_LOGIND_HELPER_ACTION_SUSPEND:
		{
			gchar* _tmp3_;
			_tmp3_ = g_strdup ("suspend");
			result = _tmp3_;
			return result;
		}
		case POWER_LOGIND_HELPER_ACTION_HALT:
		{
			gchar* _tmp4_;
			_tmp4_ = g_strdup ("halt");
			result = _tmp4_;
			return result;
		}
		default:
		{
			gchar* _tmp5_;
			_tmp5_ = g_strdup ("unknown");
			result = _tmp5_;
			return result;
		}
	}
}

static GType
power_logind_helper_action_get_type_once (void)
{
	static const GEnumValue values[] = {{POWER_LOGIND_HELPER_ACTION_IGNORE, "POWER_LOGIND_HELPER_ACTION_IGNORE", "ignore"}, {POWER_LOGIND_HELPER_ACTION_POWEROFF, "POWER_LOGIND_HELPER_ACTION_POWEROFF", "poweroff"}, {POWER_LOGIND_HELPER_ACTION_LOCK, "POWER_LOGIND_HELPER_ACTION_LOCK", "lock"}, {POWER_LOGIND_HELPER_ACTION_SUSPEND, "POWER_LOGIND_HELPER_ACTION_SUSPEND", "suspend"}, {POWER_LOGIND_HELPER_ACTION_HALT, "POWER_LOGIND_HELPER_ACTION_HALT", "halt"}, {POWER_LOGIND_HELPER_ACTION_UNKNOWN, "POWER_LOGIND_HELPER_ACTION_UNKNOWN", "unknown"}, {0, NULL, NULL}};
	GType power_logind_helper_action_type_id;
	power_logind_helper_action_type_id = g_enum_register_static ("PowerLogindHelperAction", values);
	return power_logind_helper_action_type_id;
}

GType
power_logind_helper_action_get_type (void)
{
	static volatile gsize power_logind_helper_action_type_id__once = 0;
	if (g_once_init_enter (&power_logind_helper_action_type_id__once)) {
		GType power_logind_helper_action_type_id;
		power_logind_helper_action_type_id = power_logind_helper_action_get_type_once ();
		g_once_init_leave (&power_logind_helper_action_type_id__once, power_logind_helper_action_type_id);
	}
	return power_logind_helper_action_type_id__once;
}

PowerLogindHelperIface*
power_logind_helper_get_logind_helper (void)
{
	PowerLogindHelperIface* _tmp0_;
	PowerLogindHelperIface* _tmp6_;
	GError* _inner_error0_ = NULL;
	PowerLogindHelperIface* result;
	_tmp0_ = power_logind_helper_instance;
	if (_tmp0_ == NULL) {
		{
			PowerLogindHelperIface* _tmp1_ = NULL;
			PowerLogindHelperIface* _tmp2_;
			PowerLogindHelperIface* _tmp3_;
			_tmp2_ = (PowerLogindHelperIface*) g_initable_new (POWER_TYPE_LOGIND_HELPER_IFACE_PROXY, NULL, &_inner_error0_, "g-flags", 0, "g-name", POWER_LOGIND_HELPER_NAME, "g-bus-type", G_BUS_TYPE_SYSTEM, "g-object-path", POWER_LOGIND_HELPER_OBJECT_PATH, "g-interface-name", "io.elementary.logind.helper", NULL);
			_tmp1_ = (PowerLogindHelperIface*) _tmp2_;
			if (G_UNLIKELY (_inner_error0_ != NULL)) {
				goto __catch0_g_error;
			}
			_tmp3_ = _tmp1_;
			_tmp1_ = NULL;
			_g_object_unref0 (power_logind_helper_instance);
			power_logind_helper_instance = _tmp3_;
			_g_object_unref0 (_tmp1_);
		}
		goto __finally0;
		__catch0_g_error:
		{
			GError* e = NULL;
			GError* _tmp4_;
			const gchar* _tmp5_;
			e = _inner_error0_;
			_inner_error0_ = NULL;
			_tmp4_ = e;
			_tmp5_ = _tmp4_->message;
			g_warning ("LogindHelper.vala:71: %s", _tmp5_);
			_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 NULL;
		}
	}
	_tmp6_ = power_logind_helper_instance;
	result = _tmp6_;
	return result;
}

PowerLogindHelper*
power_logind_helper_construct (GType object_type)
{
	PowerLogindHelper* self = NULL;
	self = (PowerLogindHelper*) g_type_create_instance (object_type);
	return self;
}

PowerLogindHelper*
power_logind_helper_new (void)
{
	return power_logind_helper_construct (POWER_TYPE_LOGIND_HELPER);
}

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

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

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

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

static gchar*
power_value_logind_helper_collect_value (GValue* value,
                                         guint n_collect_values,
                                         GTypeCValue* collect_values,
                                         guint collect_flags)
{
	if (collect_values[0].v_pointer) {
		PowerLogindHelper * 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 = power_logind_helper_ref (object);
	} else {
		value->data[0].v_pointer = NULL;
	}
	return NULL;
}

static gchar*
power_value_logind_helper_lcopy_value (const GValue* value,
                                       guint n_collect_values,
                                       GTypeCValue* collect_values,
                                       guint collect_flags)
{
	PowerLogindHelper ** 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 = power_logind_helper_ref (value->data[0].v_pointer);
	}
	return NULL;
}

GParamSpec*
power_param_spec_logind_helper (const gchar* name,
                                const gchar* nick,
                                const gchar* blurb,
                                GType object_type,
                                GParamFlags flags)
{
	PowerParamSpecLogindHelper* spec;
	g_return_val_if_fail (g_type_is_a (object_type, POWER_TYPE_LOGIND_HELPER), 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
power_value_get_logind_helper (const GValue* value)
{
	g_return_val_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, POWER_TYPE_LOGIND_HELPER), NULL);
	return value->data[0].v_pointer;
}

void
power_value_set_logind_helper (GValue* value,
                               gpointer v_object)
{
	PowerLogindHelper * old;
	g_return_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, POWER_TYPE_LOGIND_HELPER));
	old = value->data[0].v_pointer;
	if (v_object) {
		g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (v_object, POWER_TYPE_LOGIND_HELPER));
		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;
		power_logind_helper_ref (value->data[0].v_pointer);
	} else {
		value->data[0].v_pointer = NULL;
	}
	if (old) {
		power_logind_helper_unref (old);
	}
}

void
power_value_take_logind_helper (GValue* value,
                                gpointer v_object)
{
	PowerLogindHelper * old;
	g_return_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, POWER_TYPE_LOGIND_HELPER));
	old = value->data[0].v_pointer;
	if (v_object) {
		g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (v_object, POWER_TYPE_LOGIND_HELPER));
		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) {
		power_logind_helper_unref (old);
	}
}

static void
power_logind_helper_class_init (PowerLogindHelperClass * klass,
                                gpointer klass_data)
{
	power_logind_helper_parent_class = g_type_class_peek_parent (klass);
	((PowerLogindHelperClass *) klass)->finalize = power_logind_helper_finalize;
}

static void
power_logind_helper_instance_init (PowerLogindHelper * self,
                                   gpointer klass)
{
	self->ref_count = 1;
}

static void
power_logind_helper_finalize (PowerLogindHelper * obj)
{
	PowerLogindHelper * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, POWER_TYPE_LOGIND_HELPER, PowerLogindHelper);
	g_signal_handlers_destroy (self);
}

static GType
power_logind_helper_get_type_once (void)
{
	static const GTypeValueTable g_define_type_value_table = { power_value_logind_helper_init, power_value_logind_helper_free_value, power_value_logind_helper_copy_value, power_value_logind_helper_peek_pointer, "p", power_value_logind_helper_collect_value, "p", power_value_logind_helper_lcopy_value };
	static const GTypeInfo g_define_type_info = { sizeof (PowerLogindHelperClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) power_logind_helper_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (PowerLogindHelper), 0, (GInstanceInitFunc) power_logind_helper_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 power_logind_helper_type_id;
	power_logind_helper_type_id = g_type_register_fundamental (g_type_fundamental_next (), "PowerLogindHelper", &g_define_type_info, &g_define_type_fundamental_info, 0);
	return power_logind_helper_type_id;
}

GType
power_logind_helper_get_type (void)
{
	static volatile gsize power_logind_helper_type_id__once = 0;
	if (g_once_init_enter (&power_logind_helper_type_id__once)) {
		GType power_logind_helper_type_id;
		power_logind_helper_type_id = power_logind_helper_get_type_once ();
		g_once_init_leave (&power_logind_helper_type_id__once, power_logind_helper_type_id);
	}
	return power_logind_helper_type_id__once;
}

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

void
power_logind_helper_unref (gpointer instance)
{
	PowerLogindHelper * self;
	self = instance;
	if (g_atomic_int_dec_and_test (&self->ref_count)) {
		POWER_LOGIND_HELPER_GET_CLASS (self)->finalize (self);
		g_type_free_instance ((GTypeInstance *) self);
	}
}

