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

/* This file is part of GNOME Games. License: GPL-3.0+.*/

#include <glib-object.h>
#include <gio/gio.h>
#include <glib.h>
#include "config.h"
#include <stdlib.h>
#include <string.h>
#include <gobject/gvaluecollector.h>
#include "gnome-games.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 GAMES_TYPE_PLUGIN_REGISTER_ITERATOR (games_plugin_register_iterator_get_type ())
#define GAMES_PLUGIN_REGISTER_ITERATOR(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GAMES_TYPE_PLUGIN_REGISTER_ITERATOR, GamesPluginRegisterIterator))
#define GAMES_PLUGIN_REGISTER_ITERATOR_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GAMES_TYPE_PLUGIN_REGISTER_ITERATOR, GamesPluginRegisterIteratorClass))
#define GAMES_IS_PLUGIN_REGISTER_ITERATOR(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GAMES_TYPE_PLUGIN_REGISTER_ITERATOR))
#define GAMES_IS_PLUGIN_REGISTER_ITERATOR_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GAMES_TYPE_PLUGIN_REGISTER_ITERATOR))
#define GAMES_PLUGIN_REGISTER_ITERATOR_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GAMES_TYPE_PLUGIN_REGISTER_ITERATOR, GamesPluginRegisterIteratorClass))

typedef struct _GamesPluginRegisterIterator GamesPluginRegisterIterator;
typedef struct _GamesPluginRegisterIteratorClass GamesPluginRegisterIteratorClass;
typedef struct _GamesPluginRegisterIteratorPrivate GamesPluginRegisterIteratorPrivate;

#define GAMES_TYPE_PLUGIN_REGISTER (games_plugin_register_get_type ())
#define GAMES_PLUGIN_REGISTER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GAMES_TYPE_PLUGIN_REGISTER, GamesPluginRegister))
#define GAMES_PLUGIN_REGISTER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GAMES_TYPE_PLUGIN_REGISTER, GamesPluginRegisterClass))
#define GAMES_IS_PLUGIN_REGISTER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GAMES_TYPE_PLUGIN_REGISTER))
#define GAMES_IS_PLUGIN_REGISTER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GAMES_TYPE_PLUGIN_REGISTER))
#define GAMES_PLUGIN_REGISTER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GAMES_TYPE_PLUGIN_REGISTER, GamesPluginRegisterClass))

typedef struct _GamesPluginRegister GamesPluginRegister;
typedef struct _GamesPluginRegisterClass GamesPluginRegisterClass;

#define GAMES_TYPE_PLUGIN_REGISTRAR (games_plugin_registrar_get_type ())
#define GAMES_PLUGIN_REGISTRAR(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GAMES_TYPE_PLUGIN_REGISTRAR, GamesPluginRegistrar))
#define GAMES_PLUGIN_REGISTRAR_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GAMES_TYPE_PLUGIN_REGISTRAR, GamesPluginRegistrarClass))
#define GAMES_IS_PLUGIN_REGISTRAR(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GAMES_TYPE_PLUGIN_REGISTRAR))
#define GAMES_IS_PLUGIN_REGISTRAR_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GAMES_TYPE_PLUGIN_REGISTRAR))
#define GAMES_PLUGIN_REGISTRAR_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GAMES_TYPE_PLUGIN_REGISTRAR, GamesPluginRegistrarClass))

typedef struct _GamesPluginRegistrar GamesPluginRegistrar;
typedef struct _GamesPluginRegistrarClass GamesPluginRegistrarClass;
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_free0(var) (var = (g_free (var), NULL))
#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))
typedef struct _GamesParamSpecPluginRegisterIterator GamesParamSpecPluginRegisterIterator;

struct _GamesPluginRegisterIterator {
	GTypeInstance parent_instance;
	volatile int ref_count;
	GamesPluginRegisterIteratorPrivate * priv;
};

struct _GamesPluginRegisterIteratorClass {
	GTypeClass parent_class;
	void (*finalize) (GamesPluginRegisterIterator *self);
};

struct _GamesPluginRegisterIteratorPrivate {
	GamesPluginRegister* plugin_register;
	GamesPluginRegistrar* plugins_registrar;
	GFileEnumerator* enumerator;
};

struct _GamesParamSpecPluginRegisterIterator {
	GParamSpec parent_instance;
};

static gint GamesPluginRegisterIterator_private_offset;
static gpointer games_plugin_register_iterator_parent_class = NULL;

VALA_EXTERN gpointer games_plugin_register_iterator_ref (gpointer instance);
VALA_EXTERN void games_plugin_register_iterator_unref (gpointer instance);
VALA_EXTERN GParamSpec* games_param_spec_plugin_register_iterator (const gchar* name,
                                                       const gchar* nick,
                                                       const gchar* blurb,
                                                       GType object_type,
                                                       GParamFlags flags);
VALA_EXTERN void games_value_set_plugin_register_iterator (GValue* value,
                                               gpointer v_object);
VALA_EXTERN void games_value_take_plugin_register_iterator (GValue* value,
                                                gpointer v_object);
VALA_EXTERN gpointer games_value_get_plugin_register_iterator (const GValue* value);
VALA_EXTERN GType games_plugin_register_iterator_get_type (void) G_GNUC_CONST ;
VALA_EXTERN GType games_plugin_register_get_type (void) G_GNUC_CONST ;
VALA_EXTERN GType games_plugin_registrar_get_type (void) G_GNUC_CONST ;
VALA_EXTERN GamesPluginRegisterIterator* games_plugin_register_iterator_new (GamesPluginRegister* plugin_register);
VALA_EXTERN GamesPluginRegisterIterator* games_plugin_register_iterator_construct (GType object_type,
                                                                       GamesPluginRegister* plugin_register);
VALA_EXTERN GamesPluginRegistrar* games_plugin_register_iterator_get (GamesPluginRegisterIterator* self);
VALA_EXTERN gboolean games_plugin_register_iterator_next (GamesPluginRegisterIterator* self);
VALA_EXTERN GamesPluginRegistrar* games_plugin_register_get_plugin_registrar (GamesPluginRegister* self,
                                                                  const gchar* descriptor_filename,
                                                                  GError** error);
static void games_plugin_register_iterator_finalize (GamesPluginRegisterIterator * obj);
static GType games_plugin_register_iterator_get_type_once (void);

static inline gpointer
games_plugin_register_iterator_get_instance_private (GamesPluginRegisterIterator* self)
{
	return G_STRUCT_MEMBER_P (self, GamesPluginRegisterIterator_private_offset);
}

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

GamesPluginRegisterIterator*
games_plugin_register_iterator_construct (GType object_type,
                                          GamesPluginRegister* plugin_register)
{
	GamesPluginRegisterIterator* self = NULL;
	GamesPluginRegister* _tmp0_;
	g_return_val_if_fail (plugin_register != NULL, NULL);
	self = (GamesPluginRegisterIterator*) g_type_create_instance (object_type);
	_tmp0_ = _g_object_ref0 (plugin_register);
	_g_object_unref0 (self->priv->plugin_register);
	self->priv->plugin_register = _tmp0_;
	_g_object_unref0 (self->priv->enumerator);
	self->priv->enumerator = NULL;
	return self;
}

GamesPluginRegisterIterator*
games_plugin_register_iterator_new (GamesPluginRegister* plugin_register)
{
	return games_plugin_register_iterator_construct (GAMES_TYPE_PLUGIN_REGISTER_ITERATOR, plugin_register);
}

GamesPluginRegistrar*
games_plugin_register_iterator_get (GamesPluginRegisterIterator* self)
{
	GamesPluginRegistrar* _tmp0_;
	GamesPluginRegistrar* _tmp1_;
	GamesPluginRegistrar* result;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->plugins_registrar;
	_tmp1_ = _g_object_ref0 (_tmp0_);
	result = _tmp1_;
	return result;
}

gboolean
games_plugin_register_iterator_next (GamesPluginRegisterIterator* self)
{
	GError* _inner_error0_ = NULL;
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	{
		GFile* directory = NULL;
		GFile* _tmp0_;
		GFileEnumerator* _tmp1_;
		GFileInfo* info = NULL;
		_tmp0_ = g_file_new_for_path (PLUGINS_DIR);
		directory = _tmp0_;
		_tmp1_ = self->priv->enumerator;
		if (_tmp1_ == NULL) {
			GFileEnumerator* _tmp2_ = NULL;
			GFile* _tmp3_;
			GFileEnumerator* _tmp4_;
			GFileEnumerator* _tmp5_;
			_tmp3_ = directory;
			_tmp4_ = g_file_enumerate_children (_tmp3_, G_FILE_ATTRIBUTE_STANDARD_NAME, 0, NULL, &_inner_error0_);
			_tmp2_ = _tmp4_;
			if (G_UNLIKELY (_inner_error0_ != NULL)) {
				_g_object_unref0 (directory);
				goto __catch0_g_error;
			}
			_tmp5_ = _tmp2_;
			_tmp2_ = NULL;
			_g_object_unref0 (self->priv->enumerator);
			self->priv->enumerator = _tmp5_;
			_g_object_unref0 (_tmp2_);
		}
		while (TRUE) {
			GFileInfo* _tmp6_ = NULL;
			GFileEnumerator* _tmp7_;
			GFileInfo* _tmp8_;
			GFileInfo* _tmp9_;
			GFileInfo* _tmp10_;
			gchar* name = NULL;
			GFileInfo* _tmp11_;
			const gchar* _tmp12_;
			gchar* _tmp13_;
			const gchar* _tmp14_;
			GFile* descriptor = NULL;
			GFile* _tmp15_;
			const gchar* _tmp16_;
			GFile* _tmp17_;
			gchar* descriptor_path = NULL;
			GFile* _tmp18_;
			gchar* _tmp19_;
			GamesPluginRegistrar* _tmp20_ = NULL;
			GamesPluginRegister* _tmp21_;
			const gchar* _tmp22_;
			GamesPluginRegistrar* _tmp23_;
			GamesPluginRegistrar* _tmp24_;
			_tmp7_ = self->priv->enumerator;
			_tmp8_ = g_file_enumerator_next_file (_tmp7_, NULL, &_inner_error0_);
			_tmp6_ = _tmp8_;
			if (G_UNLIKELY (_inner_error0_ != NULL)) {
				_g_object_unref0 (info);
				_g_object_unref0 (directory);
				goto __catch0_g_error;
			}
			_tmp9_ = _tmp6_;
			_tmp6_ = NULL;
			_g_object_unref0 (info);
			info = _tmp9_;
			_tmp10_ = info;
			if (!(_tmp10_ != NULL)) {
				_g_object_unref0 (_tmp6_);
				break;
			}
			_tmp11_ = info;
			_tmp12_ = g_file_info_get_name (_tmp11_);
			_tmp13_ = g_strdup (_tmp12_);
			name = _tmp13_;
			_tmp14_ = name;
			if (!g_str_has_suffix (_tmp14_, ".plugin")) {
				_g_free0 (name);
				_g_object_unref0 (_tmp6_);
				continue;
			}
			_tmp15_ = directory;
			_tmp16_ = name;
			_tmp17_ = g_file_get_child (_tmp15_, _tmp16_);
			descriptor = _tmp17_;
			_tmp18_ = descriptor;
			_tmp19_ = g_file_get_path (_tmp18_);
			descriptor_path = _tmp19_;
			_tmp21_ = self->priv->plugin_register;
			_tmp22_ = descriptor_path;
			_tmp23_ = games_plugin_register_get_plugin_registrar (_tmp21_, _tmp22_, &_inner_error0_);
			_tmp20_ = _tmp23_;
			if (G_UNLIKELY (_inner_error0_ != NULL)) {
				_g_free0 (descriptor_path);
				_g_object_unref0 (descriptor);
				_g_free0 (name);
				_g_object_unref0 (_tmp6_);
				_g_object_unref0 (info);
				_g_object_unref0 (directory);
				goto __catch0_g_error;
			}
			_tmp24_ = _tmp20_;
			_tmp20_ = NULL;
			_g_object_unref0 (self->priv->plugins_registrar);
			self->priv->plugins_registrar = _tmp24_;
			result = TRUE;
			_g_object_unref0 (_tmp20_);
			_g_free0 (descriptor_path);
			_g_object_unref0 (descriptor);
			_g_free0 (name);
			_g_object_unref0 (_tmp6_);
			_g_object_unref0 (info);
			_g_object_unref0 (directory);
			return result;
		}
		_g_object_unref0 (info);
		_g_object_unref0 (directory);
	}
	goto __finally0;
	__catch0_g_error:
	{
		GError* e = NULL;
		GError* _tmp25_;
		const gchar* _tmp26_;
		e = _inner_error0_;
		_inner_error0_ = NULL;
		_tmp25_ = e;
		_tmp26_ = _tmp25_->message;
		g_debug ("plugin-register-iterator.vala:38: %s", _tmp26_);
		_g_error_free0 (e);
	}
	__finally0:
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		gboolean _tmp27_ = FALSE;
		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 _tmp27_;
	}
	_g_object_unref0 (self->priv->plugins_registrar);
	self->priv->plugins_registrar = NULL;
	result = FALSE;
	return result;
}

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

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

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

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

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

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

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

void
games_value_set_plugin_register_iterator (GValue* value,
                                          gpointer v_object)
{
	GamesPluginRegisterIterator * old;
	g_return_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, GAMES_TYPE_PLUGIN_REGISTER_ITERATOR));
	old = value->data[0].v_pointer;
	if (v_object) {
		g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (v_object, GAMES_TYPE_PLUGIN_REGISTER_ITERATOR));
		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;
		games_plugin_register_iterator_ref (value->data[0].v_pointer);
	} else {
		value->data[0].v_pointer = NULL;
	}
	if (old) {
		games_plugin_register_iterator_unref (old);
	}
}

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

static void
games_plugin_register_iterator_class_init (GamesPluginRegisterIteratorClass * klass,
                                           gpointer klass_data)
{
	games_plugin_register_iterator_parent_class = g_type_class_peek_parent (klass);
	((GamesPluginRegisterIteratorClass *) klass)->finalize = games_plugin_register_iterator_finalize;
	g_type_class_adjust_private_offset (klass, &GamesPluginRegisterIterator_private_offset);
}

static void
games_plugin_register_iterator_instance_init (GamesPluginRegisterIterator * self,
                                              gpointer klass)
{
	self->priv = games_plugin_register_iterator_get_instance_private (self);
	self->ref_count = 1;
}

static void
games_plugin_register_iterator_finalize (GamesPluginRegisterIterator * obj)
{
	GamesPluginRegisterIterator * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, GAMES_TYPE_PLUGIN_REGISTER_ITERATOR, GamesPluginRegisterIterator);
	g_signal_handlers_destroy (self);
	_g_object_unref0 (self->priv->plugin_register);
	_g_object_unref0 (self->priv->plugins_registrar);
	_g_object_unref0 (self->priv->enumerator);
}

static GType
games_plugin_register_iterator_get_type_once (void)
{
	static const GTypeValueTable g_define_type_value_table = { games_value_plugin_register_iterator_init, games_value_plugin_register_iterator_free_value, games_value_plugin_register_iterator_copy_value, games_value_plugin_register_iterator_peek_pointer, "p", games_value_plugin_register_iterator_collect_value, "p", games_value_plugin_register_iterator_lcopy_value };
	static const GTypeInfo g_define_type_info = { sizeof (GamesPluginRegisterIteratorClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) games_plugin_register_iterator_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (GamesPluginRegisterIterator), 0, (GInstanceInitFunc) games_plugin_register_iterator_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 games_plugin_register_iterator_type_id;
	games_plugin_register_iterator_type_id = g_type_register_fundamental (g_type_fundamental_next (), "GamesPluginRegisterIterator", &g_define_type_info, &g_define_type_fundamental_info, 0);
	GamesPluginRegisterIterator_private_offset = g_type_add_instance_private (games_plugin_register_iterator_type_id, sizeof (GamesPluginRegisterIteratorPrivate));
	return games_plugin_register_iterator_type_id;
}

GType
games_plugin_register_iterator_get_type (void)
{
	static volatile gsize games_plugin_register_iterator_type_id__once = 0;
	if (g_once_init_enter (&games_plugin_register_iterator_type_id__once)) {
		GType games_plugin_register_iterator_type_id;
		games_plugin_register_iterator_type_id = games_plugin_register_iterator_get_type_once ();
		g_once_init_leave (&games_plugin_register_iterator_type_id__once, games_plugin_register_iterator_type_id);
	}
	return games_plugin_register_iterator_type_id__once;
}

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

void
games_plugin_register_iterator_unref (gpointer instance)
{
	GamesPluginRegisterIterator * self;
	self = instance;
	if (g_atomic_int_dec_and_test (&self->ref_count)) {
		GAMES_PLUGIN_REGISTER_ITERATOR_GET_CLASS (self)->finalize (self);
		g_type_free_instance ((GTypeInstance *) self);
	}
}

