/* plugin-register-iterator.c generated by valac 0.36.6.6-c7bee, 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.h>
#include <glib-object.h>
#include <gio/gio.h>
#include <stdlib.h>
#include <string.h>
#include <gobject/gvaluecollector.h>


#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 gpointer games_plugin_register_iterator_parent_class = NULL;

gpointer games_plugin_register_iterator_ref (gpointer instance);
void games_plugin_register_iterator_unref (gpointer instance);
GParamSpec* games_param_spec_plugin_register_iterator (const gchar* name, const gchar* nick, const gchar* blurb, GType object_type, GParamFlags flags);
void games_value_set_plugin_register_iterator (GValue* value, gpointer v_object);
void games_value_take_plugin_register_iterator (GValue* value, gpointer v_object);
gpointer games_value_get_plugin_register_iterator (const GValue* value);
GType games_plugin_register_iterator_get_type (void) G_GNUC_CONST;
GType games_plugin_register_get_type (void) G_GNUC_CONST;
GType games_plugin_registrar_get_type (void) G_GNUC_CONST;
#define GAMES_PLUGIN_REGISTER_ITERATOR_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GAMES_TYPE_PLUGIN_REGISTER_ITERATOR, GamesPluginRegisterIteratorPrivate))
enum  {
	GAMES_PLUGIN_REGISTER_ITERATOR_0_PROPERTY
};
GamesPluginRegisterIterator* games_plugin_register_iterator_new (GamesPluginRegister* plugin_register);
GamesPluginRegisterIterator* games_plugin_register_iterator_construct (GType object_type, GamesPluginRegister* plugin_register);
GamesPluginRegistrar* games_plugin_register_iterator_get (GamesPluginRegisterIterator* self);
gboolean games_plugin_register_iterator_next (GamesPluginRegisterIterator* self);
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 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_;
	GamesPluginRegister* _tmp1_;
	g_return_val_if_fail (plugin_register != NULL, NULL);
	self = (GamesPluginRegisterIterator*) g_type_create_instance (object_type);
	_tmp0_ = plugin_register;
	_tmp1_ = _g_object_ref0 (_tmp0_);
	_g_object_unref0 (self->priv->plugin_register);
	self->priv->plugin_register = _tmp1_;
	_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* result = NULL;
	GamesPluginRegistrar* _tmp0_;
	GamesPluginRegistrar* _tmp1_;
	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) {
	gboolean result = FALSE;
	GError * _inner_error_ = NULL;
	g_return_val_if_fail (self != NULL, FALSE);
	{
		GFile* directory = NULL;
		GFile* _tmp0_;
		GFileEnumerator* _tmp1_;
		GFileInfo* info = NULL;
		_tmp0_ = g_file_new_for_path (GAMES_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_error_);
			_tmp2_ = _tmp4_;
			if (G_UNLIKELY (_inner_error_ != NULL)) {
				_g_object_unref0 (directory);
				goto __catch3_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_;
			gboolean _tmp15_;
			GFile* descriptor = NULL;
			GFile* _tmp16_;
			const gchar* _tmp17_;
			GFile* _tmp18_;
			gchar* descriptor_path = NULL;
			GFile* _tmp19_;
			gchar* _tmp20_;
			GamesPluginRegistrar* _tmp21_ = NULL;
			GamesPluginRegister* _tmp22_;
			const gchar* _tmp23_;
			GamesPluginRegistrar* _tmp24_;
			GamesPluginRegistrar* _tmp25_;
			_tmp7_ = self->priv->enumerator;
			_tmp8_ = g_file_enumerator_next_file (_tmp7_, NULL, &_inner_error_);
			_tmp6_ = _tmp8_;
			if (G_UNLIKELY (_inner_error_ != NULL)) {
				_g_object_unref0 (info);
				_g_object_unref0 (directory);
				goto __catch3_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;
			_tmp15_ = g_str_has_suffix (_tmp14_, ".plugin");
			if (!_tmp15_) {
				_g_free0 (name);
				_g_object_unref0 (_tmp6_);
				continue;
			}
			_tmp16_ = directory;
			_tmp17_ = name;
			_tmp18_ = g_file_get_child (_tmp16_, _tmp17_);
			descriptor = _tmp18_;
			_tmp19_ = descriptor;
			_tmp20_ = g_file_get_path (_tmp19_);
			descriptor_path = _tmp20_;
			_tmp22_ = self->priv->plugin_register;
			_tmp23_ = descriptor_path;
			_tmp24_ = games_plugin_register_get_plugin_registrar (_tmp22_, _tmp23_, &_inner_error_);
			_tmp21_ = _tmp24_;
			if (G_UNLIKELY (_inner_error_ != 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 __catch3_g_error;
			}
			_tmp25_ = _tmp21_;
			_tmp21_ = NULL;
			_g_object_unref0 (self->priv->plugins_registrar);
			self->priv->plugins_registrar = _tmp25_;
			result = TRUE;
			_g_object_unref0 (_tmp21_);
			_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 __finally3;
	__catch3_g_error:
	{
		GError* e = NULL;
		GError* _tmp26_;
		const gchar* _tmp27_;
		e = _inner_error_;
		_inner_error_ = NULL;
		_tmp26_ = e;
		_tmp27_ = _tmp26_->message;
		g_debug ("plugin-register-iterator.vala:38: %s", _tmp27_);
		_g_error_free0 (e);
	}
	__finally3:
	if (G_UNLIKELY (_inner_error_ != NULL)) {
		gboolean _tmp28_ = FALSE;
		g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
		g_clear_error (&_inner_error_);
		return _tmp28_;
	}
	_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) {
	games_plugin_register_iterator_parent_class = g_type_class_peek_parent (klass);
	((GamesPluginRegisterIteratorClass *) klass)->finalize = games_plugin_register_iterator_finalize;
	g_type_class_add_private (klass, sizeof (GamesPluginRegisterIteratorPrivate));
}


static void games_plugin_register_iterator_instance_init (GamesPluginRegisterIterator * self) {
	self->priv = GAMES_PLUGIN_REGISTER_ITERATOR_GET_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);
}


GType games_plugin_register_iterator_get_type (void) {
	static volatile gsize games_plugin_register_iterator_type_id__volatile = 0;
	if (g_once_init_enter (&games_plugin_register_iterator_type_id__volatile)) {
		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);
		g_once_init_leave (&games_plugin_register_iterator_type_id__volatile, games_plugin_register_iterator_type_id);
	}
	return games_plugin_register_iterator_type_id__volatile;
}


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);
	}
}



