/* rygel-tracker-selection-query.c generated by valac 0.18.1, the Vala compiler
 * generated from rygel-tracker-selection-query.vala, do not modify */

/*
 * Copyright (C) 2010-2012 Nokia Corporation.
 *
 * Author: Zeeshan Ali <zeenix@gmail.com>
 *         Jens Georg <jensg@openismus.com>
 *
 * This file is part of Rygel.
 *
 * Rygel is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * Rygel is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 */

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


#define RYGEL_TRACKER_TYPE_QUERY (rygel_tracker_query_get_type ())
#define RYGEL_TRACKER_QUERY(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), RYGEL_TRACKER_TYPE_QUERY, RygelTrackerQuery))
#define RYGEL_TRACKER_QUERY_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), RYGEL_TRACKER_TYPE_QUERY, RygelTrackerQueryClass))
#define RYGEL_TRACKER_IS_QUERY(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), RYGEL_TRACKER_TYPE_QUERY))
#define RYGEL_TRACKER_IS_QUERY_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), RYGEL_TRACKER_TYPE_QUERY))
#define RYGEL_TRACKER_QUERY_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), RYGEL_TRACKER_TYPE_QUERY, RygelTrackerQueryClass))

typedef struct _RygelTrackerQuery RygelTrackerQuery;
typedef struct _RygelTrackerQueryClass RygelTrackerQueryClass;
typedef struct _RygelTrackerQueryPrivate RygelTrackerQueryPrivate;

#define RYGEL_TRACKER_TYPE_QUERY_TRIPLETS (rygel_tracker_query_triplets_get_type ())
#define RYGEL_TRACKER_QUERY_TRIPLETS(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), RYGEL_TRACKER_TYPE_QUERY_TRIPLETS, RygelTrackerQueryTriplets))
#define RYGEL_TRACKER_QUERY_TRIPLETS_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), RYGEL_TRACKER_TYPE_QUERY_TRIPLETS, RygelTrackerQueryTripletsClass))
#define RYGEL_TRACKER_IS_QUERY_TRIPLETS(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), RYGEL_TRACKER_TYPE_QUERY_TRIPLETS))
#define RYGEL_TRACKER_IS_QUERY_TRIPLETS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), RYGEL_TRACKER_TYPE_QUERY_TRIPLETS))
#define RYGEL_TRACKER_QUERY_TRIPLETS_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), RYGEL_TRACKER_TYPE_QUERY_TRIPLETS, RygelTrackerQueryTripletsClass))

typedef struct _RygelTrackerQueryTriplets RygelTrackerQueryTriplets;
typedef struct _RygelTrackerQueryTripletsClass RygelTrackerQueryTripletsClass;

#define RYGEL_TRACKER_TYPE_SELECTION_QUERY (rygel_tracker_selection_query_get_type ())
#define RYGEL_TRACKER_SELECTION_QUERY(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), RYGEL_TRACKER_TYPE_SELECTION_QUERY, RygelTrackerSelectionQuery))
#define RYGEL_TRACKER_SELECTION_QUERY_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), RYGEL_TRACKER_TYPE_SELECTION_QUERY, RygelTrackerSelectionQueryClass))
#define RYGEL_TRACKER_IS_SELECTION_QUERY(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), RYGEL_TRACKER_TYPE_SELECTION_QUERY))
#define RYGEL_TRACKER_IS_SELECTION_QUERY_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), RYGEL_TRACKER_TYPE_SELECTION_QUERY))
#define RYGEL_TRACKER_SELECTION_QUERY_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), RYGEL_TRACKER_TYPE_SELECTION_QUERY, RygelTrackerSelectionQueryClass))

typedef struct _RygelTrackerSelectionQuery RygelTrackerSelectionQuery;
typedef struct _RygelTrackerSelectionQueryClass RygelTrackerSelectionQueryClass;
typedef struct _RygelTrackerSelectionQueryPrivate RygelTrackerSelectionQueryPrivate;
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_free0(var) (var = (g_free (var), NULL))
#define _rygel_tracker_query_unref0(var) ((var == NULL) ? NULL : (var = (rygel_tracker_query_unref (var), NULL)))
typedef struct _RygelTrackerSelectionQueryExecuteData RygelTrackerSelectionQueryExecuteData;
#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))

struct _RygelTrackerQuery {
	GTypeInstance parent_instance;
	volatile int ref_count;
	RygelTrackerQueryPrivate * priv;
	RygelTrackerQueryTriplets* triplets;
};

struct _RygelTrackerQueryClass {
	GTypeClass parent_class;
	void (*finalize) (RygelTrackerQuery *self);
	void (*execute) (RygelTrackerQuery* self, TrackerSparqlConnection* resources, GAsyncReadyCallback _callback_, gpointer _user_data_);
	void (*execute_finish) (RygelTrackerQuery* self, GAsyncResult* _res_, GError** error);
	gchar* (*to_string) (RygelTrackerQuery* self);
};

struct _RygelTrackerSelectionQuery {
	RygelTrackerQuery parent_instance;
	RygelTrackerSelectionQueryPrivate * priv;
	GeeArrayList* variables;
	GeeArrayList* filters;
	gchar* order_by;
	gint offset;
	gint max_count;
	TrackerSparqlCursor* result;
};

struct _RygelTrackerSelectionQueryClass {
	RygelTrackerQueryClass parent_class;
};

struct _RygelTrackerSelectionQueryExecuteData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GSimpleAsyncResult* _async_result;
	RygelTrackerSelectionQuery* self;
	TrackerSparqlConnection* resources;
	gchar* _tmp0_;
	gchar* str;
	TrackerSparqlConnection* _tmp1_;
	TrackerSparqlCursor* _tmp2_;
	TrackerSparqlCursor* _tmp3_;
	GError * _inner_error_;
};


static gpointer rygel_tracker_selection_query_parent_class = NULL;

gpointer rygel_tracker_query_ref (gpointer instance);
void rygel_tracker_query_unref (gpointer instance);
GParamSpec* rygel_tracker_param_spec_query (const gchar* name, const gchar* nick, const gchar* blurb, GType object_type, GParamFlags flags);
void rygel_tracker_value_set_query (GValue* value, gpointer v_object);
void rygel_tracker_value_take_query (GValue* value, gpointer v_object);
gpointer rygel_tracker_value_get_query (const GValue* value);
GType rygel_tracker_query_get_type (void) G_GNUC_CONST;
GType rygel_tracker_query_triplets_get_type (void) G_GNUC_CONST;
GType rygel_tracker_selection_query_get_type (void) G_GNUC_CONST;
enum  {
	RYGEL_TRACKER_SELECTION_QUERY_DUMMY_PROPERTY
};
#define RYGEL_TRACKER_SELECTION_QUERY_ITEM_VARIABLE "?item"
#define RYGEL_TRACKER_SELECTION_QUERY_SHARED_FILTER "(!BOUND(nmm:uPnPShared(" RYGEL_TRACKER_SELECTION_QUERY_ITEM_VARIABLE ")) ||" " nmm:uPnPShared(" RYGEL_TRACKER_SELECTION_QUERY_ITEM_VARIABLE ") = true) && " "(BOUND(nie:url(" RYGEL_TRACKER_SELECTION_QUERY_ITEM_VARIABLE ")))"
#define RYGEL_TRACKER_SELECTION_QUERY_STRICT_SHARED_FILTER "(BOUND(nmm:dlnaProfile(" RYGEL_TRACKER_SELECTION_QUERY_ITEM_VARIABLE ")))"
#define RYGEL_TRACKER_SELECTION_QUERY_AVAILABLE_FILTER "(tracker:available(" RYGEL_TRACKER_SELECTION_QUERY_ITEM_VARIABLE ") = true)"
RygelTrackerSelectionQuery* rygel_tracker_selection_query_new (GeeArrayList* variables, RygelTrackerQueryTriplets* triplets, GeeArrayList* filters, const gchar* order_by, gint offset, gint max_count);
RygelTrackerSelectionQuery* rygel_tracker_selection_query_construct (GType object_type, GeeArrayList* variables, RygelTrackerQueryTriplets* triplets, GeeArrayList* filters, const gchar* order_by, gint offset, gint max_count);
RygelTrackerQuery* rygel_tracker_query_construct (GType object_type, RygelTrackerQueryTriplets* triplets);
RygelTrackerSelectionQuery* rygel_tracker_selection_query_new_clone (RygelTrackerSelectionQuery* query);
RygelTrackerSelectionQuery* rygel_tracker_selection_query_construct_clone (GType object_type, RygelTrackerSelectionQuery* query);
static GeeArrayList* rygel_tracker_selection_query_copy_str_list (GeeList* str_list);
RygelTrackerQueryTriplets* rygel_tracker_query_triplets_new_clone (RygelTrackerQueryTriplets* triplets);
RygelTrackerQueryTriplets* rygel_tracker_query_triplets_construct_clone (GType object_type, RygelTrackerQueryTriplets* triplets);
static void rygel_tracker_selection_query_real_execute_data_free (gpointer _data);
static void rygel_tracker_selection_query_real_execute (RygelTrackerQuery* base, TrackerSparqlConnection* resources, GAsyncReadyCallback _callback_, gpointer _user_data_);
static gboolean rygel_tracker_selection_query_real_execute_co (RygelTrackerSelectionQueryExecuteData* _data_);
gchar* rygel_tracker_query_to_string (RygelTrackerQuery* self);
static void rygel_tracker_selection_query_execute_ready (GObject* source_object, GAsyncResult* _res_, gpointer _user_data_);
static gchar* rygel_tracker_selection_query_real_to_string (RygelTrackerQuery* base);
static void rygel_tracker_selection_query_finalize (RygelTrackerQuery* obj);


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


RygelTrackerSelectionQuery* rygel_tracker_selection_query_construct (GType object_type, GeeArrayList* variables, RygelTrackerQueryTriplets* triplets, GeeArrayList* filters, const gchar* order_by, gint offset, gint max_count) {
	RygelTrackerSelectionQuery* self = NULL;
	RygelTrackerQueryTriplets* _tmp0_;
	GeeArrayList* _tmp1_;
	GeeArrayList* _tmp5_;
	GeeArrayList* _tmp6_;
	const gchar* _tmp7_;
	gchar* _tmp8_;
	gint _tmp9_;
	gint _tmp10_;
	g_return_val_if_fail (variables != NULL, NULL);
	g_return_val_if_fail (triplets != NULL, NULL);
	_tmp0_ = triplets;
	self = (RygelTrackerSelectionQuery*) rygel_tracker_query_construct (object_type, _tmp0_);
	_tmp1_ = filters;
	if (_tmp1_ != NULL) {
		GeeArrayList* _tmp2_;
		GeeArrayList* _tmp3_;
		_tmp2_ = filters;
		_tmp3_ = _g_object_ref0 (_tmp2_);
		_g_object_unref0 (self->filters);
		self->filters = _tmp3_;
	} else {
		GeeArrayList* _tmp4_;
		_tmp4_ = gee_array_list_new (G_TYPE_STRING, (GBoxedCopyFunc) g_strdup, g_free, NULL, NULL, NULL);
		_g_object_unref0 (self->filters);
		self->filters = _tmp4_;
	}
	_tmp5_ = variables;
	_tmp6_ = _g_object_ref0 (_tmp5_);
	_g_object_unref0 (self->variables);
	self->variables = _tmp6_;
	_tmp7_ = order_by;
	_tmp8_ = g_strdup (_tmp7_);
	_g_free0 (self->order_by);
	self->order_by = _tmp8_;
	_tmp9_ = offset;
	self->offset = _tmp9_;
	_tmp10_ = max_count;
	self->max_count = _tmp10_;
	return self;
}


RygelTrackerSelectionQuery* rygel_tracker_selection_query_new (GeeArrayList* variables, RygelTrackerQueryTriplets* triplets, GeeArrayList* filters, const gchar* order_by, gint offset, gint max_count) {
	return rygel_tracker_selection_query_construct (RYGEL_TRACKER_TYPE_SELECTION_QUERY, variables, triplets, filters, order_by, offset, max_count);
}


RygelTrackerSelectionQuery* rygel_tracker_selection_query_construct_clone (GType object_type, RygelTrackerSelectionQuery* query) {
	RygelTrackerSelectionQuery* self = NULL;
	RygelTrackerSelectionQuery* _tmp0_;
	GeeArrayList* _tmp1_;
	GeeArrayList* _tmp2_ = NULL;
	GeeArrayList* _tmp3_;
	RygelTrackerSelectionQuery* _tmp4_;
	RygelTrackerQueryTriplets* _tmp5_;
	RygelTrackerQueryTriplets* _tmp6_;
	RygelTrackerQueryTriplets* _tmp7_;
	RygelTrackerSelectionQuery* _tmp8_;
	GeeArrayList* _tmp9_;
	GeeArrayList* _tmp10_ = NULL;
	GeeArrayList* _tmp11_;
	RygelTrackerSelectionQuery* _tmp12_;
	const gchar* _tmp13_;
	RygelTrackerSelectionQuery* _tmp14_;
	gint _tmp15_;
	RygelTrackerSelectionQuery* _tmp16_;
	gint _tmp17_;
	g_return_val_if_fail (query != NULL, NULL);
	_tmp0_ = query;
	_tmp1_ = _tmp0_->variables;
	_tmp2_ = rygel_tracker_selection_query_copy_str_list ((GeeList*) _tmp1_);
	_tmp3_ = _tmp2_;
	_tmp4_ = query;
	_tmp5_ = ((RygelTrackerQuery*) _tmp4_)->triplets;
	_tmp6_ = rygel_tracker_query_triplets_new_clone (_tmp5_);
	_tmp7_ = _tmp6_;
	_tmp8_ = query;
	_tmp9_ = _tmp8_->filters;
	_tmp10_ = rygel_tracker_selection_query_copy_str_list ((GeeList*) _tmp9_);
	_tmp11_ = _tmp10_;
	_tmp12_ = query;
	_tmp13_ = _tmp12_->order_by;
	_tmp14_ = query;
	_tmp15_ = _tmp14_->offset;
	_tmp16_ = query;
	_tmp17_ = _tmp16_->max_count;
	self = (RygelTrackerSelectionQuery*) rygel_tracker_selection_query_construct (object_type, _tmp3_, _tmp7_, _tmp11_, _tmp13_, _tmp15_, _tmp17_);
	_g_object_unref0 (_tmp11_);
	_g_object_unref0 (_tmp7_);
	_g_object_unref0 (_tmp3_);
	return self;
}


RygelTrackerSelectionQuery* rygel_tracker_selection_query_new_clone (RygelTrackerSelectionQuery* query) {
	return rygel_tracker_selection_query_construct_clone (RYGEL_TRACKER_TYPE_SELECTION_QUERY, query);
}


static void rygel_tracker_selection_query_real_execute_data_free (gpointer _data) {
	RygelTrackerSelectionQueryExecuteData* _data_;
	_data_ = _data;
	_g_object_unref0 (_data_->resources);
	_rygel_tracker_query_unref0 (_data_->self);
	g_slice_free (RygelTrackerSelectionQueryExecuteData, _data_);
}


static gpointer _rygel_tracker_query_ref0 (gpointer self) {
	return self ? rygel_tracker_query_ref (self) : NULL;
}


static void rygel_tracker_selection_query_real_execute (RygelTrackerQuery* base, TrackerSparqlConnection* resources, GAsyncReadyCallback _callback_, gpointer _user_data_) {
	RygelTrackerSelectionQuery * self;
	RygelTrackerSelectionQueryExecuteData* _data_;
	RygelTrackerSelectionQuery* _tmp0_;
	TrackerSparqlConnection* _tmp1_;
	TrackerSparqlConnection* _tmp2_;
	self = (RygelTrackerSelectionQuery*) base;
	_data_ = g_slice_new0 (RygelTrackerSelectionQueryExecuteData);
	_data_->_async_result = g_simple_async_result_new (NULL, _callback_, _user_data_, rygel_tracker_selection_query_real_execute);
	g_simple_async_result_set_op_res_gpointer (_data_->_async_result, _data_, rygel_tracker_selection_query_real_execute_data_free);
	_tmp0_ = _rygel_tracker_query_ref0 (self);
	_data_->self = _tmp0_;
	_tmp1_ = resources;
	_tmp2_ = _g_object_ref0 (_tmp1_);
	_g_object_unref0 (_data_->resources);
	_data_->resources = _tmp2_;
	rygel_tracker_selection_query_real_execute_co (_data_);
}


static void rygel_tracker_selection_query_real_execute_finish (RygelTrackerQuery* base, GAsyncResult* _res_, GError** error) {
	RygelTrackerSelectionQueryExecuteData* _data_;
	if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (_res_), error)) {
		return;
	}
	_data_ = g_simple_async_result_get_op_res_gpointer (G_SIMPLE_ASYNC_RESULT (_res_));
}


static void rygel_tracker_selection_query_execute_ready (GObject* source_object, GAsyncResult* _res_, gpointer _user_data_) {
	RygelTrackerSelectionQueryExecuteData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	rygel_tracker_selection_query_real_execute_co (_data_);
}


static gboolean rygel_tracker_selection_query_real_execute_co (RygelTrackerSelectionQueryExecuteData* _data_) {
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_tmp0_ = NULL;
	_data_->_tmp0_ = rygel_tracker_query_to_string ((RygelTrackerQuery*) _data_->self);
	_data_->str = _data_->_tmp0_;
	g_debug ("rygel-tracker-selection-query.vala:88: Executing SPARQL query: %s", _data_->str);
	_data_->_tmp1_ = _data_->resources;
	_data_->_state_ = 1;
	tracker_sparql_connection_query_async (_data_->_tmp1_, _data_->str, NULL, rygel_tracker_selection_query_execute_ready, _data_);
	return FALSE;
	_state_1:
	_data_->_tmp2_ = NULL;
	_data_->_tmp2_ = tracker_sparql_connection_query_finish (_data_->_tmp1_, _data_->_res_, &_data_->_inner_error_);
	_data_->_tmp3_ = _data_->_tmp2_;
	if (_data_->_inner_error_ != NULL) {
		if (((_data_->_inner_error_->domain == G_IO_ERROR) || (_data_->_inner_error_->domain == TRACKER_SPARQL_ERROR)) || (_data_->_inner_error_->domain == G_DBUS_ERROR)) {
			g_simple_async_result_set_from_error (_data_->_async_result, _data_->_inner_error_);
			g_error_free (_data_->_inner_error_);
			_g_free0 (_data_->str);
			if (_data_->_state_ == 0) {
				g_simple_async_result_complete_in_idle (_data_->_async_result);
			} else {
				g_simple_async_result_complete (_data_->_async_result);
			}
			g_object_unref (_data_->_async_result);
			return FALSE;
		} else {
			_g_free0 (_data_->str);
			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;
		}
	}
	_g_object_unref0 (_data_->self->result);
	_data_->self->result = _data_->_tmp3_;
	_g_free0 (_data_->str);
	if (_data_->_state_ == 0) {
		g_simple_async_result_complete_in_idle (_data_->_async_result);
	} else {
		g_simple_async_result_complete (_data_->_async_result);
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
}


static gchar* rygel_tracker_selection_query_real_to_string (RygelTrackerQuery* base) {
	RygelTrackerSelectionQuery * self;
	gchar* result = NULL;
	gchar* _tmp0_;
	gchar* query;
	const gchar* _tmp17_;
	gchar* _tmp18_ = NULL;
	gchar* _tmp19_;
	gchar* _tmp20_;
	gchar* _tmp21_;
	gchar* _tmp22_;
	GeeArrayList* _tmp23_;
	GeeArrayList* filters;
	GeeArrayList* _tmp24_;
	gint _tmp28_;
	gint _tmp29_;
	const gchar* _tmp50_;
	gchar* _tmp51_;
	const gchar* _tmp52_;
	gint _tmp58_;
	gint _tmp66_;
	GError * _inner_error_ = NULL;
	self = (RygelTrackerSelectionQuery*) base;
	_tmp0_ = g_strdup ("SELECT ");
	query = _tmp0_;
	{
		GeeArrayList* _tmp1_;
		GeeArrayList* _tmp2_;
		GeeArrayList* _variable_list;
		GeeArrayList* _tmp3_;
		gint _tmp4_;
		gint _tmp5_;
		gint _variable_size;
		gint _variable_index;
		_tmp1_ = self->variables;
		_tmp2_ = _g_object_ref0 (_tmp1_);
		_variable_list = _tmp2_;
		_tmp3_ = _variable_list;
		_tmp4_ = gee_abstract_collection_get_size ((GeeCollection*) _tmp3_);
		_tmp5_ = _tmp4_;
		_variable_size = _tmp5_;
		_variable_index = -1;
		while (TRUE) {
			gint _tmp6_;
			gint _tmp7_;
			gint _tmp8_;
			GeeArrayList* _tmp9_;
			gint _tmp10_;
			gpointer _tmp11_ = NULL;
			gchar* variable;
			const gchar* _tmp12_;
			const gchar* _tmp13_;
			gchar* _tmp14_;
			gchar* _tmp15_;
			gchar* _tmp16_;
			_tmp6_ = _variable_index;
			_variable_index = _tmp6_ + 1;
			_tmp7_ = _variable_index;
			_tmp8_ = _variable_size;
			if (!(_tmp7_ < _tmp8_)) {
				break;
			}
			_tmp9_ = _variable_list;
			_tmp10_ = _variable_index;
			_tmp11_ = gee_abstract_list_get ((GeeAbstractList*) _tmp9_, _tmp10_);
			variable = (gchar*) _tmp11_;
			_tmp12_ = query;
			_tmp13_ = variable;
			_tmp14_ = g_strconcat (" ", _tmp13_, NULL);
			_tmp15_ = _tmp14_;
			_tmp16_ = g_strconcat (_tmp12_, _tmp15_, NULL);
			_g_free0 (query);
			query = _tmp16_;
			_g_free0 (_tmp15_);
			_g_free0 (variable);
		}
		_g_object_unref0 (_variable_list);
	}
	_tmp17_ = query;
	_tmp18_ = RYGEL_TRACKER_QUERY_CLASS (rygel_tracker_selection_query_parent_class)->to_string (G_TYPE_CHECK_INSTANCE_CAST (self, RYGEL_TRACKER_TYPE_QUERY, RygelTrackerQuery));
	_tmp19_ = _tmp18_;
	_tmp20_ = g_strconcat (" WHERE { ", _tmp19_, NULL);
	_tmp21_ = _tmp20_;
	_tmp22_ = g_strconcat (_tmp17_, _tmp21_, NULL);
	_g_free0 (query);
	query = _tmp22_;
	_g_free0 (_tmp21_);
	_g_free0 (_tmp19_);
	_tmp23_ = gee_array_list_new (G_TYPE_STRING, (GBoxedCopyFunc) g_strdup, g_free, NULL, NULL, NULL);
	filters = _tmp23_;
	_tmp24_ = self->filters;
	gee_array_list_add_all (filters, (GeeCollection*) _tmp24_);
	gee_abstract_collection_add ((GeeAbstractCollection*) filters, RYGEL_TRACKER_SELECTION_QUERY_SHARED_FILTER);
	gee_abstract_collection_add ((GeeAbstractCollection*) filters, RYGEL_TRACKER_SELECTION_QUERY_AVAILABLE_FILTER);
	{
		RygelMetaConfig* _tmp25_ = NULL;
		RygelMetaConfig* config;
		gboolean _tmp26_ = FALSE;
		gboolean _tmp27_;
		_tmp25_ = rygel_meta_config_get_default ();
		config = _tmp25_;
		_tmp26_ = rygel_configuration_get_bool ((RygelConfiguration*) config, "Tracker", "strict-sharing", &_inner_error_);
		_tmp27_ = _tmp26_;
		if (_inner_error_ != NULL) {
			_g_object_unref0 (config);
			goto __catch9_g_error;
		}
		if (_tmp27_) {
			gee_abstract_collection_add ((GeeAbstractCollection*) filters, RYGEL_TRACKER_SELECTION_QUERY_STRICT_SHARED_FILTER);
		}
		_g_object_unref0 (config);
	}
	goto __finally9;
	__catch9_g_error:
	{
		GError* _error_ = NULL;
		_error_ = _inner_error_;
		_inner_error_ = NULL;
		_g_error_free0 (_error_);
	}
	__finally9:
	if (_inner_error_ != NULL) {
		_g_object_unref0 (filters);
		_g_free0 (query);
		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 NULL;
	}
	_tmp28_ = gee_abstract_collection_get_size ((GeeCollection*) filters);
	_tmp29_ = _tmp28_;
	if (_tmp29_ > 0) {
		const gchar* _tmp30_;
		gchar* _tmp31_;
		const gchar* _tmp48_;
		gchar* _tmp49_;
		_tmp30_ = query;
		_tmp31_ = g_strconcat (_tmp30_, " FILTER (", NULL);
		_g_free0 (query);
		query = _tmp31_;
		{
			gint i;
			i = 0;
			{
				gboolean _tmp32_;
				_tmp32_ = TRUE;
				while (TRUE) {
					gboolean _tmp33_;
					gint _tmp35_;
					gint _tmp36_;
					gint _tmp37_;
					const gchar* _tmp38_;
					gint _tmp39_;
					gpointer _tmp40_ = NULL;
					gchar* _tmp41_;
					gchar* _tmp42_;
					gint _tmp43_;
					gint _tmp44_;
					gint _tmp45_;
					_tmp33_ = _tmp32_;
					if (!_tmp33_) {
						gint _tmp34_;
						_tmp34_ = i;
						i = _tmp34_ + 1;
					}
					_tmp32_ = FALSE;
					_tmp35_ = i;
					_tmp36_ = gee_abstract_collection_get_size ((GeeCollection*) filters);
					_tmp37_ = _tmp36_;
					if (!(_tmp35_ < _tmp37_)) {
						break;
					}
					_tmp38_ = query;
					_tmp39_ = i;
					_tmp40_ = gee_abstract_list_get ((GeeAbstractList*) filters, _tmp39_);
					_tmp41_ = (gchar*) _tmp40_;
					_tmp42_ = g_strconcat (_tmp38_, _tmp41_, NULL);
					_g_free0 (query);
					query = _tmp42_;
					_g_free0 (_tmp41_);
					_tmp43_ = i;
					_tmp44_ = gee_abstract_collection_get_size ((GeeCollection*) filters);
					_tmp45_ = _tmp44_;
					if (_tmp43_ < (_tmp45_ - 1)) {
						const gchar* _tmp46_;
						gchar* _tmp47_;
						_tmp46_ = query;
						_tmp47_ = g_strconcat (_tmp46_, " && ", NULL);
						_g_free0 (query);
						query = _tmp47_;
					}
				}
			}
		}
		_tmp48_ = query;
		_tmp49_ = g_strconcat (_tmp48_, ")", NULL);
		_g_free0 (query);
		query = _tmp49_;
	}
	_tmp50_ = query;
	_tmp51_ = g_strconcat (_tmp50_, " }", NULL);
	_g_free0 (query);
	query = _tmp51_;
	_tmp52_ = self->order_by;
	if (_tmp52_ != NULL) {
		const gchar* _tmp53_;
		const gchar* _tmp54_;
		gchar* _tmp55_;
		gchar* _tmp56_;
		gchar* _tmp57_;
		_tmp53_ = query;
		_tmp54_ = self->order_by;
		_tmp55_ = g_strconcat (" ORDER BY ", _tmp54_, NULL);
		_tmp56_ = _tmp55_;
		_tmp57_ = g_strconcat (_tmp53_, _tmp56_, NULL);
		_g_free0 (query);
		query = _tmp57_;
		_g_free0 (_tmp56_);
	}
	_tmp58_ = self->offset;
	if (_tmp58_ > 0) {
		const gchar* _tmp59_;
		gint _tmp60_;
		gchar* _tmp61_ = NULL;
		gchar* _tmp62_;
		gchar* _tmp63_;
		gchar* _tmp64_;
		gchar* _tmp65_;
		_tmp59_ = query;
		_tmp60_ = self->offset;
		_tmp61_ = g_strdup_printf ("%i", _tmp60_);
		_tmp62_ = _tmp61_;
		_tmp63_ = g_strconcat (" OFFSET ", _tmp62_, NULL);
		_tmp64_ = _tmp63_;
		_tmp65_ = g_strconcat (_tmp59_, _tmp64_, NULL);
		_g_free0 (query);
		query = _tmp65_;
		_g_free0 (_tmp64_);
		_g_free0 (_tmp62_);
	}
	_tmp66_ = self->max_count;
	if (_tmp66_ > 0) {
		const gchar* _tmp67_;
		gint _tmp68_;
		gchar* _tmp69_ = NULL;
		gchar* _tmp70_;
		gchar* _tmp71_;
		gchar* _tmp72_;
		gchar* _tmp73_;
		_tmp67_ = query;
		_tmp68_ = self->max_count;
		_tmp69_ = g_strdup_printf ("%i", _tmp68_);
		_tmp70_ = _tmp69_;
		_tmp71_ = g_strconcat (" LIMIT ", _tmp70_, NULL);
		_tmp72_ = _tmp71_;
		_tmp73_ = g_strconcat (_tmp67_, _tmp72_, NULL);
		_g_free0 (query);
		query = _tmp73_;
		_g_free0 (_tmp72_);
		_g_free0 (_tmp70_);
	}
	result = query;
	_g_object_unref0 (filters);
	return result;
}


static GeeArrayList* rygel_tracker_selection_query_copy_str_list (GeeList* str_list) {
	GeeArrayList* result = NULL;
	GeeArrayList* _tmp0_;
	GeeArrayList* copy;
	GeeList* _tmp1_;
	g_return_val_if_fail (str_list != NULL, NULL);
	_tmp0_ = gee_array_list_new (G_TYPE_STRING, (GBoxedCopyFunc) g_strdup, g_free, NULL, NULL, NULL);
	copy = _tmp0_;
	_tmp1_ = str_list;
	gee_array_list_add_all (copy, (GeeCollection*) _tmp1_);
	result = copy;
	return result;
}


static void rygel_tracker_selection_query_class_init (RygelTrackerSelectionQueryClass * klass) {
	rygel_tracker_selection_query_parent_class = g_type_class_peek_parent (klass);
	RYGEL_TRACKER_QUERY_CLASS (klass)->finalize = rygel_tracker_selection_query_finalize;
	RYGEL_TRACKER_QUERY_CLASS (klass)->execute = rygel_tracker_selection_query_real_execute;
	RYGEL_TRACKER_QUERY_CLASS (klass)->execute_finish = rygel_tracker_selection_query_real_execute_finish;
	RYGEL_TRACKER_QUERY_CLASS (klass)->to_string = rygel_tracker_selection_query_real_to_string;
}


static void rygel_tracker_selection_query_instance_init (RygelTrackerSelectionQuery * self) {
}


static void rygel_tracker_selection_query_finalize (RygelTrackerQuery* obj) {
	RygelTrackerSelectionQuery * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, RYGEL_TRACKER_TYPE_SELECTION_QUERY, RygelTrackerSelectionQuery);
	_g_object_unref0 (self->variables);
	_g_object_unref0 (self->filters);
	_g_free0 (self->order_by);
	_g_object_unref0 (self->result);
	RYGEL_TRACKER_QUERY_CLASS (rygel_tracker_selection_query_parent_class)->finalize (obj);
}


/**
 * Represents Tracker SPARQL Selection query
 */
GType rygel_tracker_selection_query_get_type (void) {
	static volatile gsize rygel_tracker_selection_query_type_id__volatile = 0;
	if (g_once_init_enter (&rygel_tracker_selection_query_type_id__volatile)) {
		static const GTypeInfo g_define_type_info = { sizeof (RygelTrackerSelectionQueryClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) rygel_tracker_selection_query_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (RygelTrackerSelectionQuery), 0, (GInstanceInitFunc) rygel_tracker_selection_query_instance_init, NULL };
		GType rygel_tracker_selection_query_type_id;
		rygel_tracker_selection_query_type_id = g_type_register_static (RYGEL_TRACKER_TYPE_QUERY, "RygelTrackerSelectionQuery", &g_define_type_info, 0);
		g_once_init_leave (&rygel_tracker_selection_query_type_id__volatile, rygel_tracker_selection_query_type_id);
	}
	return rygel_tracker_selection_query_type_id__volatile;
}



