/* tracker-uri-iterator.c generated by valac 0.36.1.39-72bb2, the Vala compiler
 * generated from tracker-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 <libtracker-sparql/tracker-sparql.h>
#include <stdlib.h>
#include <string.h>


#define GAMES_TYPE_URI_ITERATOR (games_uri_iterator_get_type ())
#define GAMES_URI_ITERATOR(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GAMES_TYPE_URI_ITERATOR, GamesUriIterator))
#define GAMES_IS_URI_ITERATOR(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GAMES_TYPE_URI_ITERATOR))
#define GAMES_URI_ITERATOR_GET_INTERFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), GAMES_TYPE_URI_ITERATOR, GamesUriIteratorIface))

typedef struct _GamesUriIterator GamesUriIterator;
typedef struct _GamesUriIteratorIface GamesUriIteratorIface;

#define GAMES_TYPE_URI (games_uri_get_type ())
#define GAMES_URI(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GAMES_TYPE_URI, GamesUri))
#define GAMES_URI_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GAMES_TYPE_URI, GamesUriClass))
#define GAMES_IS_URI(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GAMES_TYPE_URI))
#define GAMES_IS_URI_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GAMES_TYPE_URI))
#define GAMES_URI_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GAMES_TYPE_URI, GamesUriClass))

typedef struct _GamesUri GamesUri;
typedef struct _GamesUriClass GamesUriClass;

#define GAMES_TYPE_TRACKER_URI_ITERATOR (games_tracker_uri_iterator_get_type ())
#define GAMES_TRACKER_URI_ITERATOR(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GAMES_TYPE_TRACKER_URI_ITERATOR, GamesTrackerUriIterator))
#define GAMES_TRACKER_URI_ITERATOR_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GAMES_TYPE_TRACKER_URI_ITERATOR, GamesTrackerUriIteratorClass))
#define GAMES_IS_TRACKER_URI_ITERATOR(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GAMES_TYPE_TRACKER_URI_ITERATOR))
#define GAMES_IS_TRACKER_URI_ITERATOR_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GAMES_TYPE_TRACKER_URI_ITERATOR))
#define GAMES_TRACKER_URI_ITERATOR_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GAMES_TYPE_TRACKER_URI_ITERATOR, GamesTrackerUriIteratorClass))

typedef struct _GamesTrackerUriIterator GamesTrackerUriIterator;
typedef struct _GamesTrackerUriIteratorClass GamesTrackerUriIteratorClass;
typedef struct _GamesTrackerUriIteratorPrivate GamesTrackerUriIteratorPrivate;

#define GAMES_TYPE_TRACKER_URI_QUERY (games_tracker_uri_query_get_type ())
#define GAMES_TRACKER_URI_QUERY(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GAMES_TYPE_TRACKER_URI_QUERY, GamesTrackerUriQuery))
#define GAMES_IS_TRACKER_URI_QUERY(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GAMES_TYPE_TRACKER_URI_QUERY))
#define GAMES_TRACKER_URI_QUERY_GET_INTERFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), GAMES_TYPE_TRACKER_URI_QUERY, GamesTrackerUriQueryIface))

typedef struct _GamesTrackerUriQuery GamesTrackerUriQuery;
typedef struct _GamesTrackerUriQueryIface GamesTrackerUriQueryIface;
enum  {
	GAMES_TRACKER_URI_ITERATOR_DUMMY_PROPERTY,
	GAMES_TRACKER_URI_ITERATOR_LAST_PROPERTY
};
static GParamSpec* games_tracker_uri_iterator_properties[GAMES_TRACKER_URI_ITERATOR_LAST_PROPERTY];
#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 _GamesUriIteratorIface {
	GTypeInterface parent_iface;
	GamesUri* (*get) (GamesUriIterator* self);
	gboolean (*next) (GamesUriIterator* self);
};

struct _GamesTrackerUriIterator {
	GObject parent_instance;
	GamesTrackerUriIteratorPrivate * priv;
};

struct _GamesTrackerUriIteratorClass {
	GObjectClass parent_class;
};

struct _GamesTrackerUriQueryIface {
	GTypeInterface parent_iface;
	gchar* (*get_query) (GamesTrackerUriQuery* self);
};

struct _GamesTrackerUriIteratorPrivate {
	TrackerSparqlConnection* connection;
	GamesTrackerUriQuery** queries;
	gint queries_length1;
	gint _queries_size_;
	gint query_index;
	GamesUri* uri;
	TrackerSparqlCursor* cursor;
};


static gpointer games_tracker_uri_iterator_parent_class = NULL;
static GamesUriIteratorIface * games_tracker_uri_iterator_games_uri_iterator_parent_iface = NULL;

gpointer games_uri_ref (gpointer instance);
void games_uri_unref (gpointer instance);
GParamSpec* games_param_spec_uri (const gchar* name, const gchar* nick, const gchar* blurb, GType object_type, GParamFlags flags);
void games_value_set_uri (GValue* value, gpointer v_object);
void games_value_take_uri (GValue* value, gpointer v_object);
gpointer games_value_get_uri (const GValue* value);
GType games_uri_get_type (void) G_GNUC_CONST;
GType games_uri_iterator_get_type (void) G_GNUC_CONST;
GType games_tracker_uri_iterator_get_type (void) G_GNUC_CONST;
GType games_tracker_uri_query_get_type (void) G_GNUC_CONST;
#define GAMES_TRACKER_URI_ITERATOR_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GAMES_TYPE_TRACKER_URI_ITERATOR, GamesTrackerUriIteratorPrivate))
GamesTrackerUriIterator* games_tracker_uri_iterator_new (TrackerSparqlConnection* connection, GamesTrackerUriQuery** queries, int queries_length1);
GamesTrackerUriIterator* games_tracker_uri_iterator_construct (GType object_type, TrackerSparqlConnection* connection, GamesTrackerUriQuery** queries, int queries_length1);
static GamesTrackerUriQuery** _vala_array_dup8 (GamesTrackerUriQuery** self, int length);
static GamesUri* games_tracker_uri_iterator_real_get (GamesUriIterator* base);
static gboolean games_tracker_uri_iterator_real_next (GamesUriIterator* base);
static gboolean games_tracker_uri_iterator_try_next_for_query (GamesTrackerUriIterator* self, GamesTrackerUriQuery* query);
static gboolean games_tracker_uri_iterator_next_for_query (GamesTrackerUriIterator* self, GamesTrackerUriQuery* query, GError** error);
gchar* games_tracker_uri_query_get_query (GamesTrackerUriQuery* self);
GamesUri* games_uri_new (const gchar* uri);
GamesUri* games_uri_construct (GType object_type, const gchar* uri);
static void games_tracker_uri_iterator_finalize (GObject * obj);
static void _vala_array_destroy (gpointer array, gint array_length, GDestroyNotify destroy_func);
static void _vala_array_free (gpointer array, gint array_length, GDestroyNotify destroy_func);


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


static GamesTrackerUriQuery** _vala_array_dup8 (GamesTrackerUriQuery** self, int length) {
	GamesTrackerUriQuery** result;
	int i;
	result = g_new0 (GamesTrackerUriQuery*, length + 1);
	for (i = 0; i < length; i++) {
		GamesTrackerUriQuery* _tmp0_;
		_tmp0_ = _g_object_ref0 (self[i]);
		result[i] = _tmp0_;
	}
	return result;
}


GamesTrackerUriIterator* games_tracker_uri_iterator_construct (GType object_type, TrackerSparqlConnection* connection, GamesTrackerUriQuery** queries, int queries_length1) {
	GamesTrackerUriIterator * self = NULL;
	TrackerSparqlConnection* _tmp0_;
	TrackerSparqlConnection* _tmp1_;
	GamesTrackerUriQuery** _tmp2_;
	gint _tmp2__length1;
	GamesTrackerUriQuery** _tmp3_;
	gint _tmp3__length1;
	g_return_val_if_fail (connection != NULL, NULL);
	self = (GamesTrackerUriIterator*) g_object_new (object_type, NULL);
	_tmp0_ = connection;
	_tmp1_ = _g_object_ref0 (_tmp0_);
	_g_object_unref0 (self->priv->connection);
	self->priv->connection = _tmp1_;
	_tmp2_ = queries;
	_tmp2__length1 = queries_length1;
	_tmp3_ = (_tmp2_ != NULL) ? _vala_array_dup8 (_tmp2_, _tmp2__length1) : ((gpointer) _tmp2_);
	_tmp3__length1 = _tmp2__length1;
	self->priv->queries = (_vala_array_free (self->priv->queries, self->priv->queries_length1, (GDestroyNotify) g_object_unref), NULL);
	self->priv->queries = _tmp3_;
	self->priv->queries_length1 = _tmp3__length1;
	self->priv->_queries_size_ = self->priv->queries_length1;
	self->priv->query_index = 0;
	_games_uri_unref0 (self->priv->uri);
	self->priv->uri = NULL;
	_g_object_unref0 (self->priv->cursor);
	self->priv->cursor = NULL;
	return self;
}


GamesTrackerUriIterator* games_tracker_uri_iterator_new (TrackerSparqlConnection* connection, GamesTrackerUriQuery** queries, int queries_length1) {
	return games_tracker_uri_iterator_construct (GAMES_TYPE_TRACKER_URI_ITERATOR, connection, queries, queries_length1);
}


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


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


static gboolean games_tracker_uri_iterator_real_next (GamesUriIterator* base) {
	GamesTrackerUriIterator * self;
	gboolean result = FALSE;
	self = (GamesTrackerUriIterator*) base;
	while (TRUE) {
		gint _tmp0_;
		GamesTrackerUriQuery** _tmp1_;
		gint _tmp1__length1;
		GamesTrackerUriQuery** _tmp2_;
		gint _tmp2__length1;
		gint _tmp3_;
		GamesTrackerUriQuery* _tmp4_;
		gboolean _tmp5_;
		gint _tmp6_;
		_tmp0_ = self->priv->query_index;
		_tmp1_ = self->priv->queries;
		_tmp1__length1 = self->priv->queries_length1;
		if (!(_tmp0_ < _tmp1__length1)) {
			break;
		}
		_tmp2_ = self->priv->queries;
		_tmp2__length1 = self->priv->queries_length1;
		_tmp3_ = self->priv->query_index;
		_tmp4_ = _tmp2_[_tmp3_];
		_tmp5_ = games_tracker_uri_iterator_try_next_for_query (self, _tmp4_);
		if (_tmp5_) {
			result = TRUE;
			return result;
		}
		_tmp6_ = self->priv->query_index;
		self->priv->query_index = _tmp6_ + 1;
	}
	result = FALSE;
	return result;
}


static gboolean games_tracker_uri_iterator_try_next_for_query (GamesTrackerUriIterator* self, GamesTrackerUriQuery* query) {
	gboolean result = FALSE;
	GError * _inner_error_ = NULL;
	g_return_val_if_fail (self != NULL, FALSE);
	g_return_val_if_fail (query != NULL, FALSE);
	{
		gboolean _tmp0_ = FALSE;
		GamesTrackerUriQuery* _tmp1_;
		gboolean _tmp2_;
		_tmp1_ = query;
		_tmp2_ = games_tracker_uri_iterator_next_for_query (self, _tmp1_, &_inner_error_);
		_tmp0_ = _tmp2_;
		if (G_UNLIKELY (_inner_error_ != NULL)) {
			goto __catch22_g_error;
		}
		if (_tmp0_) {
			result = TRUE;
			return result;
		}
	}
	goto __finally22;
	__catch22_g_error:
	{
		GError* e = NULL;
		GError* _tmp3_;
		const gchar* _tmp4_;
		e = _inner_error_;
		_inner_error_ = NULL;
		_tmp3_ = e;
		_tmp4_ = _tmp3_->message;
		g_debug ("tracker-uri-iterator.vala:39: %s", _tmp4_);
		_g_error_free0 (e);
	}
	__finally22:
	if (G_UNLIKELY (_inner_error_ != NULL)) {
		gboolean _tmp5_ = 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 _tmp5_;
	}
	_games_uri_unref0 (self->priv->uri);
	self->priv->uri = NULL;
	_g_object_unref0 (self->priv->cursor);
	self->priv->cursor = NULL;
	result = FALSE;
	return result;
}


static gboolean games_tracker_uri_iterator_next_for_query (GamesTrackerUriIterator* self, GamesTrackerUriQuery* query, GError** error) {
	gboolean result = FALSE;
	TrackerSparqlCursor* _tmp0_;
	gboolean _tmp9_ = FALSE;
	TrackerSparqlCursor* _tmp10_;
	gboolean _tmp11_;
	TrackerSparqlCursor* _tmp13_;
	const gchar* _tmp14_;
	GamesUri* _tmp15_;
	GError * _inner_error_ = NULL;
	g_return_val_if_fail (self != NULL, FALSE);
	g_return_val_if_fail (query != NULL, FALSE);
	_tmp0_ = self->priv->cursor;
	if (_tmp0_ == NULL) {
		gchar* sparql = NULL;
		GamesTrackerUriQuery* _tmp1_;
		gchar* _tmp2_;
		TrackerSparqlCursor* _tmp3_ = NULL;
		TrackerSparqlConnection* _tmp4_;
		const gchar* _tmp5_;
		TrackerSparqlCursor* _tmp6_;
		TrackerSparqlCursor* _tmp8_;
		_tmp1_ = query;
		_tmp2_ = games_tracker_uri_query_get_query (_tmp1_);
		sparql = _tmp2_;
		_tmp4_ = self->priv->connection;
		_tmp5_ = sparql;
		_tmp6_ = tracker_sparql_connection_query (_tmp4_, _tmp5_, NULL, &_inner_error_);
		_tmp3_ = _tmp6_;
		if (G_UNLIKELY (_inner_error_ != NULL)) {
			gboolean _tmp7_ = FALSE;
			g_propagate_error (error, _inner_error_);
			_g_free0 (sparql);
			return _tmp7_;
		}
		_tmp8_ = _tmp3_;
		_tmp3_ = NULL;
		_g_object_unref0 (self->priv->cursor);
		self->priv->cursor = _tmp8_;
		_g_object_unref0 (_tmp3_);
		_g_free0 (sparql);
	}
	_tmp10_ = self->priv->cursor;
	_tmp11_ = tracker_sparql_cursor_next (_tmp10_, NULL, &_inner_error_);
	_tmp9_ = _tmp11_;
	if (G_UNLIKELY (_inner_error_ != NULL)) {
		gboolean _tmp12_ = FALSE;
		g_propagate_error (error, _inner_error_);
		return _tmp12_;
	}
	if (!_tmp9_) {
		result = FALSE;
		return result;
	}
	_tmp13_ = self->priv->cursor;
	_tmp14_ = tracker_sparql_cursor_get_string (_tmp13_, 0, NULL);
	_tmp15_ = games_uri_new (_tmp14_);
	_games_uri_unref0 (self->priv->uri);
	self->priv->uri = _tmp15_;
	result = TRUE;
	return result;
}


static void games_tracker_uri_iterator_class_init (GamesTrackerUriIteratorClass * klass) {
	games_tracker_uri_iterator_parent_class = g_type_class_peek_parent (klass);
	g_type_class_add_private (klass, sizeof (GamesTrackerUriIteratorPrivate));
	G_OBJECT_CLASS (klass)->finalize = games_tracker_uri_iterator_finalize;
}


static void games_tracker_uri_iterator_games_uri_iterator_interface_init (GamesUriIteratorIface * iface) {
	games_tracker_uri_iterator_games_uri_iterator_parent_iface = g_type_interface_peek_parent (iface);
	iface->get = (GamesUri* (*) (GamesUriIterator *)) games_tracker_uri_iterator_real_get;
	iface->next = (gboolean (*) (GamesUriIterator *)) games_tracker_uri_iterator_real_next;
}


static void games_tracker_uri_iterator_instance_init (GamesTrackerUriIterator * self) {
	self->priv = GAMES_TRACKER_URI_ITERATOR_GET_PRIVATE (self);
}


static void games_tracker_uri_iterator_finalize (GObject * obj) {
	GamesTrackerUriIterator * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, GAMES_TYPE_TRACKER_URI_ITERATOR, GamesTrackerUriIterator);
	_g_object_unref0 (self->priv->connection);
	self->priv->queries = (_vala_array_free (self->priv->queries, self->priv->queries_length1, (GDestroyNotify) g_object_unref), NULL);
	_games_uri_unref0 (self->priv->uri);
	_g_object_unref0 (self->priv->cursor);
	G_OBJECT_CLASS (games_tracker_uri_iterator_parent_class)->finalize (obj);
}


GType games_tracker_uri_iterator_get_type (void) {
	static volatile gsize games_tracker_uri_iterator_type_id__volatile = 0;
	if (g_once_init_enter (&games_tracker_uri_iterator_type_id__volatile)) {
		static const GTypeInfo g_define_type_info = { sizeof (GamesTrackerUriIteratorClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) games_tracker_uri_iterator_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (GamesTrackerUriIterator), 0, (GInstanceInitFunc) games_tracker_uri_iterator_instance_init, NULL };
		static const GInterfaceInfo games_uri_iterator_info = { (GInterfaceInitFunc) games_tracker_uri_iterator_games_uri_iterator_interface_init, (GInterfaceFinalizeFunc) NULL, NULL};
		GType games_tracker_uri_iterator_type_id;
		games_tracker_uri_iterator_type_id = g_type_register_static (G_TYPE_OBJECT, "GamesTrackerUriIterator", &g_define_type_info, 0);
		g_type_add_interface_static (games_tracker_uri_iterator_type_id, GAMES_TYPE_URI_ITERATOR, &games_uri_iterator_info);
		g_once_init_leave (&games_tracker_uri_iterator_type_id__volatile, games_tracker_uri_iterator_type_id);
	}
	return games_tracker_uri_iterator_type_id__volatile;
}


static void _vala_array_destroy (gpointer array, gint array_length, GDestroyNotify destroy_func) {
	if ((array != NULL) && (destroy_func != NULL)) {
		int i;
		for (i = 0; i < array_length; i = i + 1) {
			if (((gpointer*) array)[i] != NULL) {
				destroy_func (((gpointer*) array)[i]);
			}
		}
	}
}


static void _vala_array_free (gpointer array, gint array_length, GDestroyNotify destroy_func) {
	_vala_array_destroy (array, array_length, destroy_func);
	g_free (array);
}



