/* tracker-game-source.c generated by valac 0.35.5, the Vala compiler
 * generated from tracker-game-source.vala, do not modify */

/* This file is part of GNOME Games. License: GPLv3*/

#include <glib.h>
#include <glib-object.h>
#include <gio/gio.h>
#include <stdlib.h>
#include <string.h>
#include <gtk/gtk.h>
#include <libtracker-sparql/tracker-sparql.h>


#define GAMES_TYPE_GAME_SOURCE (games_game_source_get_type ())
#define GAMES_GAME_SOURCE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GAMES_TYPE_GAME_SOURCE, GamesGameSource))
#define GAMES_IS_GAME_SOURCE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GAMES_TYPE_GAME_SOURCE))
#define GAMES_GAME_SOURCE_GET_INTERFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), GAMES_TYPE_GAME_SOURCE, GamesGameSourceIface))

typedef struct _GamesGameSource GamesGameSource;
typedef struct _GamesGameSourceIface GamesGameSourceIface;

#define GAMES_TYPE_GAME (games_game_get_type ())
#define GAMES_GAME(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GAMES_TYPE_GAME, GamesGame))
#define GAMES_IS_GAME(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GAMES_TYPE_GAME))
#define GAMES_GAME_GET_INTERFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), GAMES_TYPE_GAME, GamesGameIface))

typedef struct _GamesGame GamesGame;
typedef struct _GamesGameIface GamesGameIface;

#define GAMES_TYPE_ICON (games_icon_get_type ())
#define GAMES_ICON(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GAMES_TYPE_ICON, GamesIcon))
#define GAMES_IS_ICON(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GAMES_TYPE_ICON))
#define GAMES_ICON_GET_INTERFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), GAMES_TYPE_ICON, GamesIconIface))

typedef struct _GamesIcon GamesIcon;
typedef struct _GamesIconIface GamesIconIface;

#define GAMES_TYPE_COVER (games_cover_get_type ())
#define GAMES_COVER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GAMES_TYPE_COVER, GamesCover))
#define GAMES_IS_COVER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GAMES_TYPE_COVER))
#define GAMES_COVER_GET_INTERFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), GAMES_TYPE_COVER, GamesCoverIface))

typedef struct _GamesCover GamesCover;
typedef struct _GamesCoverIface GamesCoverIface;

#define GAMES_TYPE_RUNNER (games_runner_get_type ())
#define GAMES_RUNNER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GAMES_TYPE_RUNNER, GamesRunner))
#define GAMES_IS_RUNNER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GAMES_TYPE_RUNNER))
#define GAMES_RUNNER_GET_INTERFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), GAMES_TYPE_RUNNER, GamesRunnerIface))

typedef struct _GamesRunner GamesRunner;
typedef struct _GamesRunnerIface GamesRunnerIface;

#define GAMES_TYPE_MEDIA_SET (games_media_set_get_type ())
#define GAMES_MEDIA_SET(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GAMES_TYPE_MEDIA_SET, GamesMediaSet))
#define GAMES_MEDIA_SET_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GAMES_TYPE_MEDIA_SET, GamesMediaSetClass))
#define GAMES_IS_MEDIA_SET(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GAMES_TYPE_MEDIA_SET))
#define GAMES_IS_MEDIA_SET_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GAMES_TYPE_MEDIA_SET))
#define GAMES_MEDIA_SET_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GAMES_TYPE_MEDIA_SET, GamesMediaSetClass))

typedef struct _GamesMediaSet GamesMediaSet;
typedef struct _GamesMediaSetClass GamesMediaSetClass;

#define GAMES_TYPE_TRACKER_GAME_SOURCE (games_tracker_game_source_get_type ())
#define GAMES_TRACKER_GAME_SOURCE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GAMES_TYPE_TRACKER_GAME_SOURCE, GamesTrackerGameSource))
#define GAMES_TRACKER_GAME_SOURCE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GAMES_TYPE_TRACKER_GAME_SOURCE, GamesTrackerGameSourceClass))
#define GAMES_IS_TRACKER_GAME_SOURCE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GAMES_TYPE_TRACKER_GAME_SOURCE))
#define GAMES_IS_TRACKER_GAME_SOURCE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GAMES_TYPE_TRACKER_GAME_SOURCE))
#define GAMES_TRACKER_GAME_SOURCE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GAMES_TYPE_TRACKER_GAME_SOURCE, GamesTrackerGameSourceClass))

typedef struct _GamesTrackerGameSource GamesTrackerGameSource;
typedef struct _GamesTrackerGameSourceClass GamesTrackerGameSourceClass;
typedef struct _GamesTrackerGameSourcePrivate GamesTrackerGameSourcePrivate;

#define GAMES_TYPE_TRACKER_QUERY (games_tracker_query_get_type ())
#define GAMES_TRACKER_QUERY(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GAMES_TYPE_TRACKER_QUERY, GamesTrackerQuery))
#define GAMES_IS_TRACKER_QUERY(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GAMES_TYPE_TRACKER_QUERY))
#define GAMES_TRACKER_QUERY_GET_INTERFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), GAMES_TYPE_TRACKER_QUERY, GamesTrackerQueryIface))

typedef struct _GamesTrackerQuery GamesTrackerQuery;
typedef struct _GamesTrackerQueryIface GamesTrackerQueryIface;
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
typedef struct _GamesTrackerGameSourceEachGameData GamesTrackerGameSourceEachGameData;
#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))
#define _g_free0(var) (var = (g_free (var), NULL))
typedef struct _GamesTrackerGameSourceEachGameForQueryData GamesTrackerGameSourceEachGameForQueryData;

struct _GamesIconIface {
	GTypeInterface parent_iface;
	GIcon* (*get_icon) (GamesIcon* self);
};

struct _GamesCoverIface {
	GTypeInterface parent_iface;
	GIcon* (*get_cover) (GamesCover* self);
};

struct _GamesRunnerIface {
	GTypeInterface parent_iface;
	gboolean (*check_is_valid) (GamesRunner* self, gchar* * error_message, GError** error);
	GtkWidget* (*get_display) (GamesRunner* self);
	void (*start) (GamesRunner* self, GError** error);
	void (*resume) (GamesRunner* self, GError** error);
	void (*pause) (GamesRunner* self);
	void (*stop) (GamesRunner* self);
	gboolean (*get_can_fullscreen) (GamesRunner* self);
	gboolean (*get_can_quit_safely) (GamesRunner* self);
	gboolean (*get_can_resume) (GamesRunner* self);
	GamesMediaSet* (*get_media_set) (GamesRunner* self);
};

struct _GamesGameIface {
	GTypeInterface parent_iface;
	GamesIcon* (*get_icon) (GamesGame* self);
	GamesCover* (*get_cover) (GamesGame* self);
	GamesRunner* (*get_runner) (GamesGame* self, GError** error);
	const gchar* (*get_name) (GamesGame* self);
};

typedef void (*GamesGameCallback) (GamesGame* game, void* user_data);
struct _GamesGameSourceIface {
	GTypeInterface parent_iface;
	void (*each_game) (GamesGameSource* self, GamesGameCallback callback, void* callback_target, GAsyncReadyCallback _callback_, gpointer _user_data_);
	void (*each_game_finish) (GamesGameSource* self, GAsyncResult* _res_);
};

struct _GamesTrackerGameSource {
	GObject parent_instance;
	GamesTrackerGameSourcePrivate * priv;
};

struct _GamesTrackerGameSourceClass {
	GObjectClass parent_class;
};

struct _GamesTrackerQueryIface {
	GTypeInterface parent_iface;
	gboolean (*is_cursor_valid) (GamesTrackerQuery* self, TrackerSparqlCursor* cursor);
	gchar* (*get_query) (GamesTrackerQuery* self);
	void (*process_cursor) (GamesTrackerQuery* self, TrackerSparqlCursor* cursor);
	void (*foreach_game) (GamesTrackerQuery* self, GamesGameCallback game_callback, void* game_callback_target, GAsyncReadyCallback _callback_, gpointer _user_data_);
	void (*foreach_game_finish) (GamesTrackerQuery* self, GAsyncResult* _res_);
};

struct _GamesTrackerGameSourcePrivate {
	TrackerSparqlConnection* _connection;
	GamesTrackerQuery** queries;
	gint queries_length1;
	gint _queries_size_;
};

struct _GamesTrackerGameSourceEachGameData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	gboolean _task_complete_;
	GamesTrackerGameSource* self;
	GamesGameCallback game_callback;
	gpointer game_callback_target;
	gsize i;
	gboolean _tmp0_;
	gsize _tmp1_;
	gsize _tmp2_;
	GamesTrackerQuery** _tmp3_;
	gint _tmp3__length1;
	GamesGameCallback _tmp4_;
	void* _tmp4__target;
	GamesTrackerQuery** _tmp5_;
	gint _tmp5__length1;
	gsize _tmp6_;
	GamesTrackerQuery* _tmp7_;
};

struct _GamesTrackerGameSourceEachGameForQueryData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	gboolean _task_complete_;
	GamesTrackerGameSource* self;
	GamesGameCallback game_callback;
	gpointer game_callback_target;
	GamesTrackerQuery* query;
	gchar* sparql;
	GamesTrackerQuery* _tmp0_;
	gchar* _tmp1_;
	TrackerSparqlCursor* cursor;
	TrackerSparqlCursor* _tmp2_;
	TrackerSparqlConnection* _tmp3_;
	const gchar* _tmp4_;
	TrackerSparqlCursor* _tmp5_;
	TrackerSparqlCursor* _tmp6_;
	GError* e;
	GError* _tmp7_;
	const gchar* _tmp8_;
	gboolean is_cursor_valid;
	guint handled_cursors;
	gboolean _tmp9_;
	TrackerSparqlCursor* _tmp10_;
	gboolean _tmp11_;
	GError* _vala1_e;
	GError* _tmp12_;
	const gchar* _tmp13_;
	gboolean _tmp14_;
	GamesTrackerQuery* _tmp15_;
	TrackerSparqlCursor* _tmp16_;
	gboolean _tmp17_;
	GamesTrackerQuery* _tmp18_;
	TrackerSparqlCursor* _tmp19_;
	guint _tmp20_;
	guint _tmp21_;
	gboolean _tmp22_;
	TrackerSparqlCursor* _tmp23_;
	gboolean _tmp24_;
	GError* _vala2_e;
	GError* _tmp25_;
	const gchar* _tmp26_;
	GamesTrackerQuery* _tmp27_;
	GamesGameCallback _tmp28_;
	void* _tmp28__target;
	GError * _inner_error_;
};

typedef enum  {
	TRACKER_ERROR_FILE_NOT_FOUND
} TrackerError;
#define TRACKER_ERROR tracker_error_quark ()

static gpointer games_tracker_game_source_parent_class = NULL;
static GamesGameSourceIface * games_tracker_game_source_games_game_source_parent_iface = NULL;

GType games_icon_get_type (void) G_GNUC_CONST;
GType games_cover_get_type (void) G_GNUC_CONST;
GType games_media_set_get_type (void) G_GNUC_CONST;
GType games_runner_get_type (void) G_GNUC_CONST;
GType games_game_get_type (void) G_GNUC_CONST;
GType games_game_source_get_type (void) G_GNUC_CONST;
GType games_tracker_game_source_get_type (void) G_GNUC_CONST;
GType games_tracker_query_get_type (void) G_GNUC_CONST;
#define GAMES_TRACKER_GAME_SOURCE_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GAMES_TYPE_TRACKER_GAME_SOURCE, GamesTrackerGameSourcePrivate))
enum  {
	GAMES_TRACKER_GAME_SOURCE_DUMMY_PROPERTY
};
#define GAMES_TRACKER_GAME_SOURCE_HANDLED_CURSORS_PER_CYCLE ((guint) 5)
GamesTrackerGameSource* games_tracker_game_source_new (TrackerSparqlConnection* connection);
GamesTrackerGameSource* games_tracker_game_source_construct (GType object_type, TrackerSparqlConnection* connection);
static void games_tracker_game_source_set_connection (GamesTrackerGameSource* self, TrackerSparqlConnection* value);
void games_tracker_game_source_add_query (GamesTrackerGameSource* self, GamesTrackerQuery* query);
static void _vala_array_add10 (GamesTrackerQuery** * array, int* length, int* size, GamesTrackerQuery* value);
static void games_tracker_game_source_real_each_game_data_free (gpointer _data);
static void games_tracker_game_source_real_each_game (GamesGameSource* base, GamesGameCallback game_callback, void* game_callback_target, GAsyncReadyCallback _callback_, gpointer _user_data_);
static gboolean games_tracker_game_source_real_each_game_co (GamesTrackerGameSourceEachGameData* _data_);
void games_tracker_game_source_each_game_for_query (GamesTrackerGameSource* self, GamesGameCallback game_callback, void* game_callback_target, GamesTrackerQuery* query, GAsyncReadyCallback _callback_, gpointer _user_data_);
void games_tracker_game_source_each_game_for_query_finish (GamesTrackerGameSource* self, GAsyncResult* _res_);
static void games_tracker_game_source_each_game_ready (GObject* source_object, GAsyncResult* _res_, gpointer _user_data_);
static void games_tracker_game_source_each_game_for_query_data_free (gpointer _data);
static gboolean games_tracker_game_source_each_game_for_query_co (GamesTrackerGameSourceEachGameForQueryData* _data_);
gchar* games_tracker_query_get_query (GamesTrackerQuery* self);
static TrackerSparqlConnection* games_tracker_game_source_get_connection (GamesTrackerGameSource* self);
gboolean games_tracker_query_is_cursor_valid (GamesTrackerQuery* self, TrackerSparqlCursor* cursor);
void games_tracker_query_process_cursor (GamesTrackerQuery* self, TrackerSparqlCursor* cursor);
static gboolean _games_tracker_game_source_each_game_for_query_co_gsource_func (gpointer self);
void games_tracker_query_foreach_game (GamesTrackerQuery* self, GamesGameCallback game_callback, void* game_callback_target, GAsyncReadyCallback _callback_, gpointer _user_data_);
void games_tracker_query_foreach_game_finish (GamesTrackerQuery* self, GAsyncResult* _res_);
static void games_tracker_game_source_each_game_for_query_ready (GObject* source_object, GAsyncResult* _res_, gpointer _user_data_);
static GObject * games_tracker_game_source_constructor (GType type, guint n_construct_properties, GObjectConstructParam * construct_properties);
static void games_tracker_game_source_finalize (GObject * obj);
static void _vala_games_tracker_game_source_get_property (GObject * object, guint property_id, GValue * value, GParamSpec * pspec);
static void _vala_games_tracker_game_source_set_property (GObject * object, guint property_id, const GValue * value, GParamSpec * pspec);
GQuark tracker_error_quark (void);
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);


GamesTrackerGameSource* games_tracker_game_source_construct (GType object_type, TrackerSparqlConnection* connection) {
	GamesTrackerGameSource * self = NULL;
	TrackerSparqlConnection* _tmp0_;
	g_return_val_if_fail (connection != NULL, NULL);
	self = (GamesTrackerGameSource*) g_object_new (object_type, NULL);
	_tmp0_ = connection;
	games_tracker_game_source_set_connection (self, _tmp0_);
	return self;
}


GamesTrackerGameSource* games_tracker_game_source_new (TrackerSparqlConnection* connection) {
	return games_tracker_game_source_construct (GAMES_TYPE_TRACKER_GAME_SOURCE, connection);
}


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


static void _vala_array_add10 (GamesTrackerQuery** * array, int* length, int* size, GamesTrackerQuery* value) {
	if ((*length) == (*size)) {
		*size = (*size) ? (2 * (*size)) : 4;
		*array = g_renew (GamesTrackerQuery*, *array, (*size) + 1);
	}
	(*array)[(*length)++] = value;
	(*array)[*length] = NULL;
}


void games_tracker_game_source_add_query (GamesTrackerGameSource* self, GamesTrackerQuery* query) {
	GamesTrackerQuery** _tmp0_;
	gint _tmp0__length1;
	GamesTrackerQuery* _tmp1_;
	GamesTrackerQuery* _tmp2_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (query != NULL);
	_tmp0_ = self->priv->queries;
	_tmp0__length1 = self->priv->queries_length1;
	_tmp1_ = query;
	_tmp2_ = _g_object_ref0 (_tmp1_);
	_vala_array_add10 (&self->priv->queries, &self->priv->queries_length1, &self->priv->_queries_size_, _tmp2_);
}


static void games_tracker_game_source_real_each_game_data_free (gpointer _data) {
	GamesTrackerGameSourceEachGameData* _data_;
	_data_ = _data;
	_g_object_unref0 (_data_->self);
	g_slice_free (GamesTrackerGameSourceEachGameData, _data_);
}


static void games_tracker_game_source_real_each_game (GamesGameSource* base, GamesGameCallback game_callback, void* game_callback_target, GAsyncReadyCallback _callback_, gpointer _user_data_) {
	GamesTrackerGameSource * self;
	GamesTrackerGameSourceEachGameData* _data_;
	GamesTrackerGameSource* _tmp0_;
	GamesGameCallback _tmp1_;
	void* _tmp1__target;
	self = (GamesTrackerGameSource*) base;
	_data_ = g_slice_new0 (GamesTrackerGameSourceEachGameData);
	_data_->_async_result = g_task_new (G_OBJECT (self), NULL, _callback_, _user_data_);
	if (_callback_ == NULL) {
		_data_->_task_complete_ = TRUE;
	}
	g_task_set_task_data (_data_->_async_result, _data_, games_tracker_game_source_real_each_game_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	_tmp1_ = game_callback;
	_tmp1__target = game_callback_target;
	_data_->game_callback = _tmp1_;
	_data_->game_callback_target = _tmp1__target;
	games_tracker_game_source_real_each_game_co (_data_);
}


static void games_tracker_game_source_real_each_game_finish (GamesGameSource* base, GAsyncResult* _res_) {
	GamesTrackerGameSourceEachGameData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), NULL);
	_data_->_task_complete_ = TRUE;
}


static void games_tracker_game_source_each_game_ready (GObject* source_object, GAsyncResult* _res_, gpointer _user_data_) {
	GamesTrackerGameSourceEachGameData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	_data_->_task_complete_ = TRUE;
	games_tracker_game_source_real_each_game_co (_data_);
}


static gboolean games_tracker_game_source_real_each_game_co (GamesTrackerGameSourceEachGameData* _data_) {
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	{
		_data_->i = (gsize) 0;
		{
			_data_->_tmp0_ = TRUE;
			while (TRUE) {
				if (!_data_->_tmp0_) {
					_data_->_tmp1_ = _data_->i;
					_data_->i = _data_->_tmp1_ + 1;
				}
				_data_->_tmp0_ = FALSE;
				_data_->_tmp2_ = _data_->i;
				_data_->_tmp3_ = _data_->self->priv->queries;
				_data_->_tmp3__length1 = _data_->self->priv->queries_length1;
				if (!(_data_->_tmp2_ < ((gsize) _data_->_tmp3__length1))) {
					break;
				}
				_data_->_tmp4_ = _data_->game_callback;
				_data_->_tmp4__target = _data_->game_callback_target;
				_data_->_tmp5_ = _data_->self->priv->queries;
				_data_->_tmp5__length1 = _data_->self->priv->queries_length1;
				_data_->_tmp6_ = _data_->i;
				_data_->_tmp7_ = _data_->_tmp5_[_data_->_tmp6_];
				_data_->_state_ = 1;
				games_tracker_game_source_each_game_for_query (_data_->self, _data_->_tmp4_, _data_->_tmp4__target, _data_->_tmp7_, games_tracker_game_source_each_game_ready, _data_);
				return FALSE;
				_state_1:
				games_tracker_game_source_each_game_for_query_finish (_data_->self, _data_->_res_);
			}
		}
	}
	g_task_return_pointer (_data_->_async_result, _data_, NULL);
	if (_data_->_state_ != 0) {
		while (_data_->_task_complete_ != TRUE) {
			g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
		}
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
}


static void games_tracker_game_source_each_game_for_query_data_free (gpointer _data) {
	GamesTrackerGameSourceEachGameForQueryData* _data_;
	_data_ = _data;
	_g_object_unref0 (_data_->query);
	_g_object_unref0 (_data_->self);
	g_slice_free (GamesTrackerGameSourceEachGameForQueryData, _data_);
}


void games_tracker_game_source_each_game_for_query (GamesTrackerGameSource* self, GamesGameCallback game_callback, void* game_callback_target, GamesTrackerQuery* query, GAsyncReadyCallback _callback_, gpointer _user_data_) {
	GamesTrackerGameSourceEachGameForQueryData* _data_;
	GamesTrackerGameSource* _tmp0_;
	GamesGameCallback _tmp1_;
	void* _tmp1__target;
	GamesTrackerQuery* _tmp2_;
	GamesTrackerQuery* _tmp3_;
	_data_ = g_slice_new0 (GamesTrackerGameSourceEachGameForQueryData);
	_data_->_async_result = g_task_new (G_OBJECT (self), NULL, _callback_, _user_data_);
	if (_callback_ == NULL) {
		_data_->_task_complete_ = TRUE;
	}
	g_task_set_task_data (_data_->_async_result, _data_, games_tracker_game_source_each_game_for_query_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	_tmp1_ = game_callback;
	_tmp1__target = game_callback_target;
	_data_->game_callback = _tmp1_;
	_data_->game_callback_target = _tmp1__target;
	_tmp2_ = query;
	_tmp3_ = _g_object_ref0 (_tmp2_);
	_g_object_unref0 (_data_->query);
	_data_->query = _tmp3_;
	games_tracker_game_source_each_game_for_query_co (_data_);
}


void games_tracker_game_source_each_game_for_query_finish (GamesTrackerGameSource* self, GAsyncResult* _res_) {
	GamesTrackerGameSourceEachGameForQueryData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), NULL);
	_data_->_task_complete_ = TRUE;
}


static gboolean _games_tracker_game_source_each_game_for_query_co_gsource_func (gpointer self) {
	gboolean result;
	result = games_tracker_game_source_each_game_for_query_co (self);
	return result;
}


static void games_tracker_game_source_each_game_for_query_ready (GObject* source_object, GAsyncResult* _res_, gpointer _user_data_) {
	GamesTrackerGameSourceEachGameForQueryData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	_data_->_task_complete_ = TRUE;
	games_tracker_game_source_each_game_for_query_co (_data_);
}


static gboolean games_tracker_game_source_each_game_for_query_co (GamesTrackerGameSourceEachGameForQueryData* _data_) {
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		case 2:
		goto _state_2;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_tmp0_ = _data_->query;
	_data_->_tmp1_ = games_tracker_query_get_query (_data_->_tmp0_);
	_data_->sparql = _data_->_tmp1_;
	{
		_data_->_tmp3_ = _data_->self->priv->_connection;
		_data_->_tmp4_ = _data_->sparql;
		_data_->_tmp5_ = tracker_sparql_connection_query (_data_->_tmp3_, _data_->_tmp4_, NULL, &_data_->_inner_error_);
		_data_->_tmp2_ = _data_->_tmp5_;
		if (G_UNLIKELY (_data_->_inner_error_ != NULL)) {
			goto __catch23_g_error;
		}
		_data_->_tmp6_ = _data_->_tmp2_;
		_data_->_tmp2_ = NULL;
		_g_object_unref0 (_data_->cursor);
		_data_->cursor = _data_->_tmp6_;
		_g_object_unref0 (_data_->_tmp2_);
	}
	goto __finally23;
	__catch23_g_error:
	{
		_data_->e = _data_->_inner_error_;
		_data_->_inner_error_ = NULL;
		_data_->_tmp7_ = _data_->e;
		_data_->_tmp8_ = _data_->_tmp7_->message;
		g_warning ("tracker-game-source.vala:34: Error: %s\n", _data_->_tmp8_);
		_g_error_free0 (_data_->e);
		_g_object_unref0 (_data_->cursor);
		_g_free0 (_data_->sparql);
		g_task_return_pointer (_data_->_async_result, _data_, NULL);
		if (_data_->_state_ != 0) {
			while (_data_->_task_complete_ != TRUE) {
				g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
			}
		}
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	__finally23:
	if (G_UNLIKELY (_data_->_inner_error_ != NULL)) {
		_g_object_unref0 (_data_->cursor);
		_g_free0 (_data_->sparql);
		g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _data_->_inner_error_->message, g_quark_to_string (_data_->_inner_error_->domain), _data_->_inner_error_->code);
		g_clear_error (&_data_->_inner_error_);
		return FALSE;
	}
	_data_->is_cursor_valid = FALSE;
	_data_->handled_cursors = (guint) 0;
	{
		_data_->_tmp10_ = _data_->cursor;
		_data_->_tmp11_ = tracker_sparql_cursor_next (_data_->_tmp10_, NULL, &_data_->_inner_error_);
		_data_->_tmp9_ = _data_->_tmp11_;
		if (G_UNLIKELY (_data_->_inner_error_ != NULL)) {
			goto __catch24_g_error;
		}
		_data_->is_cursor_valid = _data_->_tmp9_;
	}
	goto __finally24;
	__catch24_g_error:
	{
		_data_->_vala1_e = _data_->_inner_error_;
		_data_->_inner_error_ = NULL;
		_data_->is_cursor_valid = FALSE;
		_data_->_tmp12_ = _data_->_vala1_e;
		_data_->_tmp13_ = _data_->_tmp12_->message;
		g_warning ("tracker-game-source.vala:46: Error: %s\n", _data_->_tmp13_);
		_g_error_free0 (_data_->_vala1_e);
	}
	__finally24:
	if (G_UNLIKELY (_data_->_inner_error_ != NULL)) {
		_g_object_unref0 (_data_->cursor);
		_g_free0 (_data_->sparql);
		g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _data_->_inner_error_->message, g_quark_to_string (_data_->_inner_error_->domain), _data_->_inner_error_->code);
		g_clear_error (&_data_->_inner_error_);
		return FALSE;
	}
	while (TRUE) {
		_data_->_tmp14_ = _data_->is_cursor_valid;
		if (!_data_->_tmp14_) {
			break;
		}
		_data_->_tmp15_ = _data_->query;
		_data_->_tmp16_ = _data_->cursor;
		_data_->_tmp17_ = games_tracker_query_is_cursor_valid (_data_->_tmp15_, _data_->_tmp16_);
		if (_data_->_tmp17_) {
			_data_->_tmp18_ = _data_->query;
			_data_->_tmp19_ = _data_->cursor;
			games_tracker_query_process_cursor (_data_->_tmp18_, _data_->_tmp19_);
			_data_->_tmp20_ = _data_->handled_cursors;
			_data_->handled_cursors = _data_->_tmp20_ + 1;
			_data_->_tmp21_ = _data_->handled_cursors;
			if (_data_->_tmp21_ >= GAMES_TRACKER_GAME_SOURCE_HANDLED_CURSORS_PER_CYCLE) {
				_data_->handled_cursors = (guint) 0;
				g_idle_add_full (G_PRIORITY_DEFAULT_IDLE, _games_tracker_game_source_each_game_for_query_co_gsource_func, _data_, NULL);
				_data_->_state_ = 1;
				return FALSE;
				_state_1:
				;
			}
		}
		{
			_data_->_tmp23_ = _data_->cursor;
			_data_->_tmp24_ = tracker_sparql_cursor_next (_data_->_tmp23_, NULL, &_data_->_inner_error_);
			_data_->_tmp22_ = _data_->_tmp24_;
			if (G_UNLIKELY (_data_->_inner_error_ != NULL)) {
				goto __catch25_g_error;
			}
			_data_->is_cursor_valid = _data_->_tmp22_;
		}
		goto __finally25;
		__catch25_g_error:
		{
			_data_->_vala2_e = _data_->_inner_error_;
			_data_->_inner_error_ = NULL;
			_data_->is_cursor_valid = FALSE;
			_data_->_tmp25_ = _data_->_vala2_e;
			_data_->_tmp26_ = _data_->_tmp25_->message;
			g_warning ("tracker-game-source.vala:69: Error: %s\n", _data_->_tmp26_);
			_g_error_free0 (_data_->_vala2_e);
			continue;
		}
		__finally25:
		if (G_UNLIKELY (_data_->_inner_error_ != NULL)) {
			_g_object_unref0 (_data_->cursor);
			_g_free0 (_data_->sparql);
			g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _data_->_inner_error_->message, g_quark_to_string (_data_->_inner_error_->domain), _data_->_inner_error_->code);
			g_clear_error (&_data_->_inner_error_);
			return FALSE;
		}
	}
	_data_->_tmp27_ = _data_->query;
	_data_->_tmp28_ = _data_->game_callback;
	_data_->_tmp28__target = _data_->game_callback_target;
	_data_->_state_ = 2;
	games_tracker_query_foreach_game (_data_->_tmp27_, _data_->_tmp28_, _data_->_tmp28__target, games_tracker_game_source_each_game_for_query_ready, _data_);
	return FALSE;
	_state_2:
	games_tracker_query_foreach_game_finish (_data_->_tmp27_, _data_->_res_);
	_g_object_unref0 (_data_->cursor);
	_g_free0 (_data_->sparql);
	g_task_return_pointer (_data_->_async_result, _data_, NULL);
	if (_data_->_state_ != 0) {
		while (_data_->_task_complete_ != TRUE) {
			g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
		}
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
}


static TrackerSparqlConnection* games_tracker_game_source_get_connection (GamesTrackerGameSource* self) {
	TrackerSparqlConnection* result;
	TrackerSparqlConnection* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_connection;
	result = _tmp0_;
	return result;
}


static void games_tracker_game_source_set_connection (GamesTrackerGameSource* self, TrackerSparqlConnection* value) {
	TrackerSparqlConnection* _tmp0_;
	TrackerSparqlConnection* _tmp1_;
	g_return_if_fail (self != NULL);
	_tmp0_ = value;
	_tmp1_ = _g_object_ref0 (_tmp0_);
	_g_object_unref0 (self->priv->_connection);
	self->priv->_connection = _tmp1_;
}


static GObject * games_tracker_game_source_constructor (GType type, guint n_construct_properties, GObjectConstructParam * construct_properties) {
	GObject * obj;
	GObjectClass * parent_class;
	GamesTrackerGameSource * self;
	GamesTrackerQuery** _tmp0_;
	parent_class = G_OBJECT_CLASS (games_tracker_game_source_parent_class);
	obj = parent_class->constructor (type, n_construct_properties, construct_properties);
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, GAMES_TYPE_TRACKER_GAME_SOURCE, GamesTrackerGameSource);
	_tmp0_ = g_new0 (GamesTrackerQuery*, 0 + 1);
	self->priv->queries = (_vala_array_free (self->priv->queries, self->priv->queries_length1, (GDestroyNotify) g_object_unref), NULL);
	self->priv->queries = _tmp0_;
	self->priv->queries_length1 = 0;
	self->priv->_queries_size_ = self->priv->queries_length1;
	return obj;
}


static void games_tracker_game_source_class_init (GamesTrackerGameSourceClass * klass) {
	games_tracker_game_source_parent_class = g_type_class_peek_parent (klass);
	g_type_class_add_private (klass, sizeof (GamesTrackerGameSourcePrivate));
	G_OBJECT_CLASS (klass)->get_property = _vala_games_tracker_game_source_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_games_tracker_game_source_set_property;
	G_OBJECT_CLASS (klass)->constructor = games_tracker_game_source_constructor;
	G_OBJECT_CLASS (klass)->finalize = games_tracker_game_source_finalize;
}


static void games_tracker_game_source_games_game_source_interface_init (GamesGameSourceIface * iface) {
	games_tracker_game_source_games_game_source_parent_iface = g_type_interface_peek_parent (iface);
	iface->each_game = (void (*) (GamesGameSource *, GamesGameCallback, void*)) games_tracker_game_source_real_each_game;
	iface->each_game_finish = games_tracker_game_source_real_each_game_finish;
}


static void games_tracker_game_source_instance_init (GamesTrackerGameSource * self) {
	self->priv = GAMES_TRACKER_GAME_SOURCE_GET_PRIVATE (self);
}


static void games_tracker_game_source_finalize (GObject * obj) {
	GamesTrackerGameSource * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, GAMES_TYPE_TRACKER_GAME_SOURCE, GamesTrackerGameSource);
	_g_object_unref0 (self->priv->_connection);
	self->priv->queries = (_vala_array_free (self->priv->queries, self->priv->queries_length1, (GDestroyNotify) g_object_unref), NULL);
	G_OBJECT_CLASS (games_tracker_game_source_parent_class)->finalize (obj);
}


GType games_tracker_game_source_get_type (void) {
	static volatile gsize games_tracker_game_source_type_id__volatile = 0;
	if (g_once_init_enter (&games_tracker_game_source_type_id__volatile)) {
		static const GTypeInfo g_define_type_info = { sizeof (GamesTrackerGameSourceClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) games_tracker_game_source_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (GamesTrackerGameSource), 0, (GInstanceInitFunc) games_tracker_game_source_instance_init, NULL };
		static const GInterfaceInfo games_game_source_info = { (GInterfaceInitFunc) games_tracker_game_source_games_game_source_interface_init, (GInterfaceFinalizeFunc) NULL, NULL};
		GType games_tracker_game_source_type_id;
		games_tracker_game_source_type_id = g_type_register_static (G_TYPE_OBJECT, "GamesTrackerGameSource", &g_define_type_info, 0);
		g_type_add_interface_static (games_tracker_game_source_type_id, GAMES_TYPE_GAME_SOURCE, &games_game_source_info);
		g_once_init_leave (&games_tracker_game_source_type_id__volatile, games_tracker_game_source_type_id);
	}
	return games_tracker_game_source_type_id__volatile;
}


static void _vala_games_tracker_game_source_get_property (GObject * object, guint property_id, GValue * value, GParamSpec * pspec) {
	GamesTrackerGameSource * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, GAMES_TYPE_TRACKER_GAME_SOURCE, GamesTrackerGameSource);
	switch (property_id) {
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}


static void _vala_games_tracker_game_source_set_property (GObject * object, guint property_id, const GValue * value, GParamSpec * pspec) {
	GamesTrackerGameSource * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, GAMES_TYPE_TRACKER_GAME_SOURCE, GamesTrackerGameSource);
	switch (property_id) {
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}


GQuark tracker_error_quark (void) {
	return g_quark_from_static_string ("tracker_error-quark");
}


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



