/* libretro-uri-iterator.c generated by valac 0.36.9, the Vala compiler
 * generated from libretro-uri-iterator.vala, do not modify */

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

#include <glib.h>
#include <glib-object.h>
#include <libgnome-games.h>
#include <retro-gtk.h>
#include <stdlib.h>
#include <string.h>


#define GAMES_TYPE_LIBRETRO_URI_ITERATOR (games_libretro_uri_iterator_get_type ())
#define GAMES_LIBRETRO_URI_ITERATOR(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GAMES_TYPE_LIBRETRO_URI_ITERATOR, GamesLibretroUriIterator))
#define GAMES_LIBRETRO_URI_ITERATOR_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GAMES_TYPE_LIBRETRO_URI_ITERATOR, GamesLibretroUriIteratorClass))
#define GAMES_IS_LIBRETRO_URI_ITERATOR(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GAMES_TYPE_LIBRETRO_URI_ITERATOR))
#define GAMES_IS_LIBRETRO_URI_ITERATOR_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GAMES_TYPE_LIBRETRO_URI_ITERATOR))
#define GAMES_LIBRETRO_URI_ITERATOR_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GAMES_TYPE_LIBRETRO_URI_ITERATOR, GamesLibretroUriIteratorClass))

typedef struct _GamesLibretroUriIterator GamesLibretroUriIterator;
typedef struct _GamesLibretroUriIteratorClass GamesLibretroUriIteratorClass;
typedef struct _GamesLibretroUriIteratorPrivate GamesLibretroUriIteratorPrivate;
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _games_uri_unref0(var) ((var == NULL) ? NULL : (var = (games_uri_unref (var), NULL)))
#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))
#define _g_free0(var) (var = (g_free (var), NULL))

struct _GamesLibretroUriIterator {
	GObject parent_instance;
	GamesLibretroUriIteratorPrivate * priv;
};

struct _GamesLibretroUriIteratorClass {
	GObjectClass parent_class;
};

struct _GamesLibretroUriIteratorPrivate {
	RetroModuleIterator* iterator;
	GamesUri* uri;
};


static gpointer games_libretro_uri_iterator_parent_class = NULL;
static GamesUriIteratorIface * games_libretro_uri_iterator_games_uri_iterator_parent_iface = NULL;
static GType games_libretro_uri_iterator_type_id = 0;

GType games_libretro_uri_iterator_get_type (void) G_GNUC_CONST;
#define GAMES_LIBRETRO_URI_ITERATOR_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GAMES_TYPE_LIBRETRO_URI_ITERATOR, GamesLibretroUriIteratorPrivate))
enum  {
	GAMES_LIBRETRO_URI_ITERATOR_0_PROPERTY
};
static GamesUri* games_libretro_uri_iterator_real_get (GamesUriIterator* base);
static gboolean games_libretro_uri_iterator_real_next (GamesUriIterator* base);
GamesLibretroUriIterator* games_libretro_uri_iterator_new (void);
GamesLibretroUriIterator* games_libretro_uri_iterator_construct (GType object_type);
static GObject * games_libretro_uri_iterator_constructor (GType type, guint n_construct_properties, GObjectConstructParam * construct_properties);
static void games_libretro_uri_iterator_finalize (GObject * obj);


static gpointer _games_uri_ref0 (gpointer self) {
	return self ? games_uri_ref (self) : NULL;
}


static GamesUri* games_libretro_uri_iterator_real_get (GamesUriIterator* base) {
	GamesLibretroUriIterator * self;
	GamesUri* result = NULL;
	GamesUri* _tmp0_;
	GamesUri* _tmp1_;
	self = (GamesLibretroUriIterator*) base;
	_tmp0_ = self->priv->uri;
	_tmp1_ = _games_uri_ref0 (_tmp0_);
	result = _tmp1_;
	return result;
}


static const gchar* string_to_string (const gchar* self) {
	const gchar* result = NULL;
	g_return_val_if_fail (self != NULL, NULL);
	result = self;
	return result;
}


static gboolean games_libretro_uri_iterator_real_next (GamesUriIterator* base) {
	GamesLibretroUriIterator * self;
	gboolean result = FALSE;
	GError * _inner_error_ = NULL;
	self = (GamesLibretroUriIterator*) base;
	while (TRUE) {
		RetroModuleIterator* _tmp0_;
		gboolean _tmp1_;
		RetroCoreDescriptor* core_descriptor = NULL;
		RetroModuleIterator* _tmp2_;
		RetroCoreDescriptor* _tmp3_;
		gchar* string_uri = NULL;
		RetroCoreDescriptor* _tmp10_;
		gchar* _tmp11_;
		const gchar* _tmp12_;
		const gchar* _tmp13_;
		gchar* _tmp14_;
		gchar* _tmp15_;
		GamesUri* _tmp16_;
		_tmp0_ = self->priv->iterator;
		_tmp1_ = retro_module_iterator_next (_tmp0_);
		if (!_tmp1_) {
			break;
		}
		_tmp2_ = self->priv->iterator;
		_tmp3_ = retro_module_iterator_get (_tmp2_);
		core_descriptor = _tmp3_;
		{
			gboolean _tmp4_ = FALSE;
			RetroCoreDescriptor* _tmp5_;
			gboolean _tmp6_;
			_tmp5_ = core_descriptor;
			_tmp6_ = retro_core_descriptor_get_is_game (_tmp5_, &_inner_error_);
			_tmp4_ = _tmp6_;
			if (G_UNLIKELY (_inner_error_ != NULL)) {
				goto __catch1_g_error;
			}
			if (!_tmp4_) {
				_g_object_unref0 (core_descriptor);
				continue;
			}
		}
		goto __finally1;
		__catch1_g_error:
		{
			GError* e = NULL;
			GError* _tmp7_;
			const gchar* _tmp8_;
			e = _inner_error_;
			_inner_error_ = NULL;
			_tmp7_ = e;
			_tmp8_ = _tmp7_->message;
			g_debug ("libretro-uri-iterator.vala:25: %s", _tmp8_);
			_g_error_free0 (e);
			_g_object_unref0 (core_descriptor);
			continue;
		}
		__finally1:
		if (G_UNLIKELY (_inner_error_ != NULL)) {
			gboolean _tmp9_ = FALSE;
			_g_object_unref0 (core_descriptor);
			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 _tmp9_;
		}
		_tmp10_ = core_descriptor;
		_tmp11_ = retro_core_descriptor_get_uri (_tmp10_);
		string_uri = _tmp11_;
		_tmp12_ = string_uri;
		_tmp13_ = string_to_string (_tmp12_);
		_tmp14_ = g_strconcat ("libretro+", _tmp13_, NULL);
		_tmp15_ = _tmp14_;
		_tmp16_ = games_uri_new (_tmp15_);
		_games_uri_unref0 (self->priv->uri);
		self->priv->uri = _tmp16_;
		_g_free0 (_tmp15_);
		result = TRUE;
		_g_free0 (string_uri);
		_g_object_unref0 (core_descriptor);
		return result;
	}
	_games_uri_unref0 (self->priv->uri);
	self->priv->uri = NULL;
	result = FALSE;
	return result;
}


GamesLibretroUriIterator* games_libretro_uri_iterator_construct (GType object_type) {
	GamesLibretroUriIterator * self = NULL;
	self = (GamesLibretroUriIterator*) g_object_new (object_type, NULL);
	return self;
}


GamesLibretroUriIterator* games_libretro_uri_iterator_new (void) {
	return games_libretro_uri_iterator_construct (GAMES_TYPE_LIBRETRO_URI_ITERATOR);
}


static GObject * games_libretro_uri_iterator_constructor (GType type, guint n_construct_properties, GObjectConstructParam * construct_properties) {
	GObject * obj;
	GObjectClass * parent_class;
	GamesLibretroUriIterator * self;
	RetroModuleQuery* modules = NULL;
	RetroModuleQuery* _tmp0_;
	RetroModuleQuery* _tmp1_;
	RetroModuleIterator* _tmp2_;
	parent_class = G_OBJECT_CLASS (games_libretro_uri_iterator_parent_class);
	obj = parent_class->constructor (type, n_construct_properties, construct_properties);
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, GAMES_TYPE_LIBRETRO_URI_ITERATOR, GamesLibretroUriIterator);
	_tmp0_ = retro_module_query_new (TRUE);
	modules = _tmp0_;
	_tmp1_ = modules;
	_tmp2_ = retro_module_query_iterator (_tmp1_);
	_g_object_unref0 (self->priv->iterator);
	self->priv->iterator = _tmp2_;
	_games_uri_unref0 (self->priv->uri);
	self->priv->uri = NULL;
	_g_object_unref0 (modules);
	return obj;
}


static void games_libretro_uri_iterator_class_init (GamesLibretroUriIteratorClass * klass) {
	games_libretro_uri_iterator_parent_class = g_type_class_peek_parent (klass);
	g_type_class_add_private (klass, sizeof (GamesLibretroUriIteratorPrivate));
	G_OBJECT_CLASS (klass)->constructor = games_libretro_uri_iterator_constructor;
	G_OBJECT_CLASS (klass)->finalize = games_libretro_uri_iterator_finalize;
}


static void games_libretro_uri_iterator_games_uri_iterator_interface_init (GamesUriIteratorIface * iface) {
	games_libretro_uri_iterator_games_uri_iterator_parent_iface = g_type_interface_peek_parent (iface);
	iface->get = (GamesUri* (*) (GamesUriIterator *)) games_libretro_uri_iterator_real_get;
	iface->next = (gboolean (*) (GamesUriIterator *)) games_libretro_uri_iterator_real_next;
}


static void games_libretro_uri_iterator_instance_init (GamesLibretroUriIterator * self) {
	self->priv = GAMES_LIBRETRO_URI_ITERATOR_GET_PRIVATE (self);
}


static void games_libretro_uri_iterator_finalize (GObject * obj) {
	GamesLibretroUriIterator * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, GAMES_TYPE_LIBRETRO_URI_ITERATOR, GamesLibretroUriIterator);
	_g_object_unref0 (self->priv->iterator);
	_games_uri_unref0 (self->priv->uri);
	G_OBJECT_CLASS (games_libretro_uri_iterator_parent_class)->finalize (obj);
}


GType games_libretro_uri_iterator_get_type (void) {
	return games_libretro_uri_iterator_type_id;
}


GType games_libretro_uri_iterator_register_type (GTypeModule * module) {
	static const GTypeInfo g_define_type_info = { sizeof (GamesLibretroUriIteratorClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) games_libretro_uri_iterator_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (GamesLibretroUriIterator), 0, (GInstanceInitFunc) games_libretro_uri_iterator_instance_init, NULL };
	static const GInterfaceInfo games_uri_iterator_info = { (GInterfaceInitFunc) games_libretro_uri_iterator_games_uri_iterator_interface_init, (GInterfaceFinalizeFunc) NULL, NULL};
	games_libretro_uri_iterator_type_id = g_type_module_register_type (module, G_TYPE_OBJECT, "GamesLibretroUriIterator", &g_define_type_info, 0);
	g_type_module_add_interface (module, games_libretro_uri_iterator_type_id, GAMES_TYPE_URI_ITERATOR, &games_uri_iterator_info);
	return games_libretro_uri_iterator_type_id;
}



