/* localsearch-insertion-query.c generated by valac 0.56.19, the Vala compiler
 * generated from localsearch-insertion-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.1 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 library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 */

#include "rygel-localsearch.h"
#include <stdlib.h>
#include <string.h>
#include <glib.h>
#include <gio/gio.h>
#include <tinysparql.h>
#include <glib-object.h>
#include "rygel-server.h"
#include <gee.h>

#define RYGEL_LOCAL_SEARCH_INSERTION_QUERY_MINER_SERVICE "org.freedesktop.LocalSearch3.Miner.Files.Index"
#define RYGEL_LOCAL_SEARCH_INSERTION_QUERY_MINER_PATH "/org/freedesktop/LocalSearch3/Miner/Files/Index"
#define RYGEL_LOCAL_SEARCH_INSERTION_QUERY_MINER_GRAPH "tracker:FileSystem"
#if !defined(VALA_STRICT_C)
#if !defined(__clang__) && defined(__GNUC__) && (__GNUC__ >= 14)
#pragma GCC diagnostic warning "-Wincompatible-pointer-types"
#elif defined(__clang__) && (__clang_major__ >= 16)
#pragma clang diagnostic ignored "-Wincompatible-function-pointer-types"
#pragma clang diagnostic ignored "-Wincompatible-pointer-types"
#endif
#endif

#define _g_free0(var) (var = (g_free (var), NULL))
#define _rygel_local_search_query_triplet_unref0(var) ((var == NULL) ? NULL : (var = (rygel_local_search_query_triplet_unref (var), NULL)))
#define _g_date_time_unref0(var) ((var == NULL) ? NULL : (var = (g_date_time_unref (var), NULL)))
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _rygel_local_search_query_unref0(var) ((var == NULL) ? NULL : (var = (rygel_local_search_query_unref (var), NULL)))
typedef struct _RygelLocalSearchInsertionQueryExecuteData RygelLocalSearchInsertionQueryExecuteData;

struct _RygelLocalSearchInsertionQueryPrivate {
	gchar* uri;
};

struct _RygelLocalSearchInsertionQueryExecuteData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	RygelLocalSearchInsertionQuery* self;
	TrackerSparqlConnection* resources;
	gchar* str;
	gchar* _tmp0_;
	const gchar* _tmp1_;
	const gchar* _tmp2_;
	GFile* file;
	const gchar* _tmp3_;
	GFile* _tmp4_;
	gboolean _tmp5_;
	GFile* _tmp6_;
	GFile* _tmp7_;
	RygelLocalSearchMinerFilesIndexIface* miner;
	RygelLocalSearchMinerFilesIndexIface* _tmp8_;
	RygelLocalSearchMinerFilesIndexIface* _tmp9_;
	const gchar* _tmp10_;
	const gchar* _tmp11_;
	GError* _inner_error0_;
};

static gint RygelLocalSearchInsertionQuery_private_offset;
static gpointer rygel_local_search_insertion_query_parent_class = NULL;

static void rygel_local_search_insertion_query_real_execute_data_free (gpointer _data);
static void rygel_local_search_insertion_query_real_execute (RygelLocalSearchQuery* base,
                                                      TrackerSparqlConnection* resources,
                                                      GAsyncReadyCallback _callback_,
                                                      gpointer _user_data_);
static gboolean rygel_local_search_insertion_query_real_execute_co (RygelLocalSearchInsertionQueryExecuteData* _data_);
static void rygel_local_search_insertion_query_execute_ready (GObject* source_object,
                                                       GAsyncResult* _res_,
                                                       gpointer _user_data_);
static gchar* rygel_local_search_insertion_query_real_to_string (RygelLocalSearchQuery* base);
static void rygel_local_search_insertion_query_finalize (RygelLocalSearchQuery * obj);
static GType rygel_local_search_insertion_query_get_type_once (void);

static inline gpointer
rygel_local_search_insertion_query_get_instance_private (RygelLocalSearchInsertionQuery* self)
{
	return G_STRUCT_MEMBER_P (self, RygelLocalSearchInsertionQuery_private_offset);
}

RygelLocalSearchInsertionQuery*
rygel_local_search_insertion_query_construct (GType object_type,
                                              RygelMediaFileItem* item,
                                              const gchar* category,
                                              const gchar* graph)
{
	RygelLocalSearchInsertionQuery* self = NULL;
	gchar* uuid = NULL;
	gchar* _tmp0_;
	gchar* id = NULL;
	const gchar* _tmp1_;
	gchar* _tmp2_;
	gchar* type = NULL;
	gchar* _tmp3_;
	GFile* file = NULL;
	gchar* _tmp4_;
	gchar* _tmp5_;
	GFile* _tmp6_;
	GFile* _tmp7_;
	gchar* urn = NULL;
	gchar* _tmp8_;
	gchar* _tmp9_;
	gchar* _tmp10_;
	gchar* _tmp11_;
	GFile* _tmp12_;
	RygelLocalSearchQueryTriplets* triplets = NULL;
	RygelLocalSearchQueryTriplets* _tmp14_;
	RygelLocalSearchQueryTriplets* _tmp15_;
	const gchar* _tmp16_;
	RygelLocalSearchQueryTriplet* _tmp17_;
	RygelLocalSearchQueryTriplet* _tmp18_;
	RygelLocalSearchQueryTriplets* _tmp19_;
	const gchar* _tmp20_;
	const gchar* _tmp21_;
	RygelLocalSearchQueryTriplet* _tmp22_;
	RygelLocalSearchQueryTriplet* _tmp23_;
	RygelLocalSearchQueryTriplets* _tmp24_;
	const gchar* _tmp25_;
	RygelLocalSearchQueryTriplet* _tmp26_;
	RygelLocalSearchQueryTriplet* _tmp27_;
	RygelLocalSearchQueryTriplets* _tmp28_;
	const gchar* _tmp29_;
	const gchar* _tmp30_;
	const gchar* _tmp31_;
	gchar* _tmp32_;
	gchar* _tmp33_;
	gchar* _tmp34_;
	gchar* _tmp35_;
	RygelLocalSearchQueryTriplet* _tmp36_;
	RygelLocalSearchQueryTriplet* _tmp37_;
	gchar* dlna_profile = NULL;
	gchar* _tmp38_;
	const gchar* _tmp39_;
	const gchar* _tmp40_;
	RygelLocalSearchQueryTriplets* _tmp44_;
	const gchar* _tmp45_;
	const gchar* _tmp46_;
	gchar* _tmp47_;
	gchar* _tmp48_;
	gchar* _tmp49_;
	gchar* _tmp50_;
	RygelLocalSearchQueryTriplet* _tmp51_;
	RygelLocalSearchQueryTriplet* _tmp52_;
	RygelLocalSearchQueryTriplets* _tmp53_;
	const gchar* _tmp54_;
	const gchar* _tmp55_;
	const gchar* _tmp56_;
	gchar* _tmp57_;
	gchar* _tmp58_;
	gchar* _tmp59_;
	gchar* _tmp60_;
	RygelLocalSearchQueryTriplet* _tmp61_;
	RygelLocalSearchQueryTriplet* _tmp62_;
	RygelLocalSearchQueryTriplets* _tmp63_;
	const gchar* _tmp64_;
	const gchar* _tmp65_;
	RygelLocalSearchQueryTriplet* _tmp66_;
	RygelLocalSearchQueryTriplet* _tmp67_;
	gchar* date = NULL;
	const gchar* _tmp68_;
	const gchar* _tmp69_;
	RygelLocalSearchQueryTriplets* _tmp78_;
	const gchar* _tmp79_;
	const gchar* _tmp80_;
	gchar* _tmp81_;
	gchar* _tmp82_;
	gchar* _tmp83_;
	gchar* _tmp84_;
	RygelLocalSearchQueryTriplet* _tmp85_;
	RygelLocalSearchQueryTriplet* _tmp86_;
	RygelLocalSearchQueryTriplets* _tmp87_;
	const gchar* _tmp88_;
	RygelLocalSearchQueryTriplet* _tmp89_;
	RygelLocalSearchQueryTriplet* _tmp90_;
	RygelLocalSearchQueryTriplets* _tmp91_;
	const gchar* _tmp92_;
	const gchar* _tmp93_;
	RygelLocalSearchQueryTriplet* _tmp94_;
	RygelLocalSearchQueryTriplet* _tmp95_;
	gint64 _tmp96_;
	gint64 _tmp97_;
	RygelLocalSearchQueryTriplets* _tmp110_;
	gchar* _tmp111_;
	const gchar* _tmp112_;
	gchar* _tmp113_;
	g_return_val_if_fail (item != NULL, NULL);
	g_return_val_if_fail (category != NULL, NULL);
	g_return_val_if_fail (graph != NULL, NULL);
	_tmp0_ = g_uuid_string_random ();
	uuid = _tmp0_;
	_tmp1_ = uuid;
	_tmp2_ = g_strdup_printf ("urn:rygel_upload:%s", _tmp1_);
	id = _tmp2_;
	_tmp3_ = g_strdup ("nie:InformationElement");
	type = _tmp3_;
	_tmp4_ = rygel_media_object_get_primary_uri ((RygelMediaObject*) item);
	_tmp5_ = _tmp4_;
	_tmp6_ = g_file_new_for_uri (_tmp5_);
	_tmp7_ = _tmp6_;
	_g_free0 (_tmp5_);
	file = _tmp7_;
	_tmp8_ = rygel_media_object_get_primary_uri ((RygelMediaObject*) item);
	_tmp9_ = _tmp8_;
	_tmp10_ = g_strdup_printf ("<%s>", _tmp9_);
	_tmp11_ = _tmp10_;
	_g_free0 (_tmp9_);
	urn = _tmp11_;
	_tmp12_ = file;
	if (!g_file_is_native (_tmp12_)) {
		gchar* _tmp13_;
		_tmp13_ = g_strdup ("nfo:RemoteDataObject");
		_g_free0 (type);
		type = _tmp13_;
	}
	_tmp14_ = rygel_local_search_query_triplets_new ();
	triplets = _tmp14_;
	_tmp15_ = triplets;
	_tmp16_ = id;
	_tmp17_ = rygel_local_search_query_triplet_new_with_graph (graph, _tmp16_, "a", category);
	_tmp18_ = _tmp17_;
	gee_abstract_collection_add ((GeeAbstractCollection*) _tmp15_, _tmp18_);
	_rygel_local_search_query_triplet_unref0 (_tmp18_);
	_tmp19_ = triplets;
	_tmp20_ = id;
	_tmp21_ = type;
	_tmp22_ = rygel_local_search_query_triplet_new_with_graph (graph, _tmp20_, "a", _tmp21_);
	_tmp23_ = _tmp22_;
	gee_abstract_collection_add ((GeeAbstractCollection*) _tmp19_, _tmp23_);
	_rygel_local_search_query_triplet_unref0 (_tmp23_);
	_tmp24_ = triplets;
	_tmp25_ = id;
	_tmp26_ = rygel_local_search_query_triplet_new_with_graph (graph, _tmp25_, "nie:generator", "\"rygel\"");
	_tmp27_ = _tmp26_;
	gee_abstract_collection_add ((GeeAbstractCollection*) _tmp24_, _tmp27_);
	_rygel_local_search_query_triplet_unref0 (_tmp27_);
	_tmp28_ = triplets;
	_tmp29_ = id;
	_tmp30_ = rygel_media_object_get_title ((RygelMediaObject*) item);
	_tmp31_ = _tmp30_;
	_tmp32_ = g_strconcat ("\"", _tmp31_, NULL);
	_tmp33_ = _tmp32_;
	_tmp34_ = g_strconcat (_tmp33_, "\"", NULL);
	_tmp35_ = _tmp34_;
	_tmp36_ = rygel_local_search_query_triplet_new_with_graph (graph, _tmp29_, "nie:title", _tmp35_);
	_tmp37_ = _tmp36_;
	gee_abstract_collection_add ((GeeAbstractCollection*) _tmp28_, _tmp37_);
	_rygel_local_search_query_triplet_unref0 (_tmp37_);
	_g_free0 (_tmp35_);
	_g_free0 (_tmp33_);
	_tmp38_ = g_strdup ("");
	dlna_profile = _tmp38_;
	_tmp39_ = rygel_media_file_item_get_dlna_profile (item);
	_tmp40_ = _tmp39_;
	if (_tmp40_ != NULL) {
		const gchar* _tmp41_;
		const gchar* _tmp42_;
		gchar* _tmp43_;
		_tmp41_ = rygel_media_file_item_get_dlna_profile (item);
		_tmp42_ = _tmp41_;
		_tmp43_ = g_strdup (_tmp42_);
		_g_free0 (dlna_profile);
		dlna_profile = _tmp43_;
	}
	_tmp44_ = triplets;
	_tmp45_ = id;
	_tmp46_ = dlna_profile;
	_tmp47_ = g_strconcat ("\"", _tmp46_, NULL);
	_tmp48_ = _tmp47_;
	_tmp49_ = g_strconcat (_tmp48_, "\"", NULL);
	_tmp50_ = _tmp49_;
	_tmp51_ = rygel_local_search_query_triplet_new_with_graph (graph, _tmp45_, "nmm:dlnaProfile", _tmp50_);
	_tmp52_ = _tmp51_;
	gee_abstract_collection_add ((GeeAbstractCollection*) _tmp44_, _tmp52_);
	_rygel_local_search_query_triplet_unref0 (_tmp52_);
	_g_free0 (_tmp50_);
	_g_free0 (_tmp48_);
	_tmp53_ = triplets;
	_tmp54_ = id;
	_tmp55_ = rygel_media_file_item_get_mime_type (item);
	_tmp56_ = _tmp55_;
	_tmp57_ = g_strconcat ("\"", _tmp56_, NULL);
	_tmp58_ = _tmp57_;
	_tmp59_ = g_strconcat (_tmp58_, "\"", NULL);
	_tmp60_ = _tmp59_;
	_tmp61_ = rygel_local_search_query_triplet_new_with_graph (graph, _tmp54_, "nie:mimeType", _tmp60_);
	_tmp62_ = _tmp61_;
	gee_abstract_collection_add ((GeeAbstractCollection*) _tmp53_, _tmp62_);
	_rygel_local_search_query_triplet_unref0 (_tmp62_);
	_g_free0 (_tmp60_);
	_g_free0 (_tmp58_);
	_tmp63_ = triplets;
	_tmp64_ = id;
	_tmp65_ = urn;
	_tmp66_ = rygel_local_search_query_triplet_new_with_graph (graph, _tmp64_, "nie:isStoredAs", _tmp65_);
	_tmp67_ = _tmp66_;
	gee_abstract_collection_add ((GeeAbstractCollection*) _tmp63_, _tmp67_);
	_rygel_local_search_query_triplet_unref0 (_tmp67_);
	_tmp68_ = rygel_media_object_get_date ((RygelMediaObject*) item);
	_tmp69_ = _tmp68_;
	if (_tmp69_ == NULL) {
		GDateTime* now = NULL;
		GDateTime* _tmp70_;
		GDateTime* _tmp71_;
		gchar* _tmp72_;
		gchar* _tmp73_;
		gchar* _tmp74_;
		_tmp70_ = g_date_time_new_now_utc ();
		now = _tmp70_;
		_tmp71_ = now;
		_tmp72_ = g_date_time_format (_tmp71_, "%Y-%m-%dT%H:%M:%S");
		_tmp73_ = _tmp72_;
		_tmp74_ = g_strdup_printf ("%sZ", _tmp73_);
		_g_free0 (date);
		date = _tmp74_;
		_g_free0 (_tmp73_);
		_g_date_time_unref0 (now);
	} else {
		const gchar* _tmp75_;
		const gchar* _tmp76_;
		gchar* _tmp77_;
		_tmp75_ = rygel_media_object_get_date ((RygelMediaObject*) item);
		_tmp76_ = _tmp75_;
		_tmp77_ = g_strdup (_tmp76_);
		_g_free0 (date);
		date = _tmp77_;
	}
	_tmp78_ = triplets;
	_tmp79_ = id;
	_tmp80_ = date;
	_tmp81_ = g_strconcat ("\"", _tmp80_, NULL);
	_tmp82_ = _tmp81_;
	_tmp83_ = g_strconcat (_tmp82_, "\"^^xsd:dateTime", NULL);
	_tmp84_ = _tmp83_;
	_tmp85_ = rygel_local_search_query_triplet_new_with_graph (graph, _tmp79_, "nie:contentCreated", _tmp84_);
	_tmp86_ = _tmp85_;
	gee_abstract_collection_add ((GeeAbstractCollection*) _tmp78_, _tmp86_);
	_rygel_local_search_query_triplet_unref0 (_tmp86_);
	_g_free0 (_tmp84_);
	_g_free0 (_tmp82_);
	_tmp87_ = triplets;
	_tmp88_ = urn;
	_tmp89_ = rygel_local_search_query_triplet_new_with_graph (RYGEL_LOCAL_SEARCH_INSERTION_QUERY_MINER_GRAPH, _tmp88_, "a", "nie:DataObject");
	_tmp90_ = _tmp89_;
	gee_abstract_collection_add ((GeeAbstractCollection*) _tmp87_, _tmp90_);
	_rygel_local_search_query_triplet_unref0 (_tmp90_);
	_tmp91_ = triplets;
	_tmp92_ = urn;
	_tmp93_ = id;
	_tmp94_ = rygel_local_search_query_triplet_new_with_graph (RYGEL_LOCAL_SEARCH_INSERTION_QUERY_MINER_GRAPH, _tmp92_, "nie:interpretedAs", _tmp93_);
	_tmp95_ = _tmp94_;
	gee_abstract_collection_add ((GeeAbstractCollection*) _tmp91_, _tmp95_);
	_rygel_local_search_query_triplet_unref0 (_tmp95_);
	_tmp96_ = rygel_media_file_item_get_size (item);
	_tmp97_ = _tmp96_;
	if (_tmp97_ > ((gint64) 0)) {
		RygelLocalSearchQueryTriplets* _tmp98_;
		const gchar* _tmp99_;
		gint64 _tmp100_;
		gint64 _tmp101_;
		gchar* _tmp102_;
		gchar* _tmp103_;
		gchar* _tmp104_;
		gchar* _tmp105_;
		gchar* _tmp106_;
		gchar* _tmp107_;
		RygelLocalSearchQueryTriplet* _tmp108_;
		RygelLocalSearchQueryTriplet* _tmp109_;
		_tmp98_ = triplets;
		_tmp99_ = urn;
		_tmp100_ = rygel_media_file_item_get_size (item);
		_tmp101_ = _tmp100_;
		_tmp102_ = g_strdup_printf ("%" G_GINT64_FORMAT, _tmp101_);
		_tmp103_ = _tmp102_;
		_tmp104_ = g_strconcat ("\"", _tmp103_, NULL);
		_tmp105_ = _tmp104_;
		_tmp106_ = g_strconcat (_tmp105_, "\"", NULL);
		_tmp107_ = _tmp106_;
		_tmp108_ = rygel_local_search_query_triplet_new_with_graph (RYGEL_LOCAL_SEARCH_INSERTION_QUERY_MINER_GRAPH, _tmp99_, "nie:byteSize", _tmp107_);
		_tmp109_ = _tmp108_;
		gee_abstract_collection_add ((GeeAbstractCollection*) _tmp98_, _tmp109_);
		_rygel_local_search_query_triplet_unref0 (_tmp109_);
		_g_free0 (_tmp107_);
		_g_free0 (_tmp105_);
		_g_free0 (_tmp103_);
	}
	_tmp110_ = triplets;
	self = (RygelLocalSearchInsertionQuery*) rygel_local_search_query_construct (object_type, _tmp110_);
	_tmp111_ = rygel_media_object_get_primary_uri ((RygelMediaObject*) item);
	_g_free0 (self->priv->uri);
	self->priv->uri = _tmp111_;
	_tmp112_ = id;
	_tmp113_ = g_strdup (_tmp112_);
	_g_free0 (self->id);
	self->id = _tmp113_;
	_g_free0 (date);
	_g_free0 (dlna_profile);
	_g_object_unref0 (triplets);
	_g_free0 (urn);
	_g_object_unref0 (file);
	_g_free0 (type);
	_g_free0 (id);
	_g_free0 (uuid);
	return self;
}

RygelLocalSearchInsertionQuery*
rygel_local_search_insertion_query_new (RygelMediaFileItem* item,
                                        const gchar* category,
                                        const gchar* graph)
{
	return rygel_local_search_insertion_query_construct (RYGEL_LOCAL_SEARCH_TYPE_INSERTION_QUERY, item, category, graph);
}

static void
rygel_local_search_insertion_query_real_execute_data_free (gpointer _data)
{
	RygelLocalSearchInsertionQueryExecuteData* _data_;
	_data_ = _data;
	_g_object_unref0 (_data_->resources);
	_rygel_local_search_query_unref0 (_data_->self);
	g_slice_free (RygelLocalSearchInsertionQueryExecuteData, _data_);
}

static gpointer
_rygel_local_search_query_ref0 (gpointer self)
{
	return self ? rygel_local_search_query_ref (self) : NULL;
}

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

static void
rygel_local_search_insertion_query_real_execute (RygelLocalSearchQuery* base,
                                                 TrackerSparqlConnection* resources,
                                                 GAsyncReadyCallback _callback_,
                                                 gpointer _user_data_)
{
	RygelLocalSearchInsertionQuery * self;
	RygelLocalSearchInsertionQueryExecuteData* _data_;
	RygelLocalSearchInsertionQuery* _tmp0_;
	TrackerSparqlConnection* _tmp1_;
	g_return_if_fail (resources != NULL);
	self = (RygelLocalSearchInsertionQuery*) base;
	_data_ = g_slice_new0 (RygelLocalSearchInsertionQueryExecuteData);
	_data_->_async_result = g_task_new (NULL, NULL, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, rygel_local_search_insertion_query_real_execute_data_free);
	_tmp0_ = _rygel_local_search_query_ref0 (self);
	_data_->self = _tmp0_;
	_tmp1_ = _g_object_ref0 (resources);
	_g_object_unref0 (_data_->resources);
	_data_->resources = _tmp1_;
	rygel_local_search_insertion_query_real_execute_co (_data_);
}

static void
rygel_local_search_insertion_query_execute_finish (RygelLocalSearchQuery* base,
                                                   GAsyncResult* _res_,
                                                   GError** error)
{
	RygelLocalSearchInsertionQueryExecuteData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), error);
	if (NULL == _data_) {
		return;
	}
}

static void
rygel_local_search_insertion_query_execute_ready (GObject* source_object,
                                                  GAsyncResult* _res_,
                                                  gpointer _user_data_)
{
	RygelLocalSearchInsertionQueryExecuteData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	rygel_local_search_insertion_query_real_execute_co (_data_);
}

static gboolean
rygel_local_search_insertion_query_real_execute_co (RygelLocalSearchInsertionQueryExecuteData* _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_ = rygel_local_search_query_to_string ((RygelLocalSearchQuery*) _data_->self);
	_data_->str = _data_->_tmp0_;
	_data_->_tmp1_ = _data_->str;
	g_debug ("localsearch-insertion-query.vala:116: Executing SPARQL query: %s", _data_->_tmp1_);
	_data_->_tmp2_ = _data_->str;
	_data_->_state_ = 1;
	tracker_sparql_connection_update_async (_data_->resources, _data_->_tmp2_, NULL, rygel_local_search_insertion_query_execute_ready, _data_);
	return FALSE;
	_state_1:
	tracker_sparql_connection_update_finish (_data_->resources, _data_->_res_, &_data_->_inner_error0_);
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
		_g_free0 (_data_->str);
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_tmp3_ = _data_->self->priv->uri;
	_data_->_tmp4_ = g_file_new_for_uri (_data_->_tmp3_);
	_data_->file = _data_->_tmp4_;
	_data_->_tmp6_ = _data_->file;
	if (g_file_is_native (_data_->_tmp6_)) {
		_data_->_tmp7_ = _data_->file;
		_data_->_tmp5_ = g_file_query_exists (_data_->_tmp7_, NULL);
	} else {
		_data_->_tmp5_ = FALSE;
	}
	if (_data_->_tmp5_) {
		_data_->_state_ = 2;
		g_async_initable_new_async (RYGEL_LOCAL_SEARCH_TYPE_MINER_FILES_INDEX_IFACE_PROXY, 0, NULL, rygel_local_search_insertion_query_execute_ready, _data_, "g-flags", G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES, "g-name", RYGEL_LOCAL_SEARCH_INSERTION_QUERY_MINER_SERVICE, "g-bus-type", G_BUS_TYPE_SESSION, "g-object-path", RYGEL_LOCAL_SEARCH_INSERTION_QUERY_MINER_PATH, "g-interface-name", "org.freedesktop.LocalSearch1.Miner.Files.Index", NULL);
		return FALSE;
		_state_2:
		_data_->_tmp8_ = (RygelLocalSearchMinerFilesIndexIface*) g_async_initable_new_finish ((GAsyncInitable *) _data_->_source_object_, _data_->_res_, &_data_->_inner_error0_);
		_data_->miner = (RygelLocalSearchMinerFilesIndexIface*) _data_->_tmp8_;
		if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
			g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
			_g_object_unref0 (_data_->file);
			_g_free0 (_data_->str);
			g_object_unref (_data_->_async_result);
			return FALSE;
		}
		_data_->_tmp9_ = _data_->miner;
		_data_->_tmp10_ = _data_->self->priv->uri;
		rygel_local_search_miner_files_index_iface_index_file (_data_->_tmp9_, _data_->_tmp10_, NULL, NULL);
		_g_object_unref0 (_data_->miner);
	}
	_data_->_tmp11_ = _data_->self->id;
	g_debug ("localsearch-insertion-query.vala:129: Created item in LocalSearch stor" \
"e with ID '%s'", _data_->_tmp11_);
	_g_object_unref0 (_data_->file);
	_g_free0 (_data_->str);
	g_task_return_pointer (_data_->_async_result, _data_, NULL);
	if (_data_->_state_ != 0) {
		while (!g_task_get_completed (_data_->_async_result)) {
			g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
		}
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
}

static gchar*
rygel_local_search_insertion_query_real_to_string (RygelLocalSearchQuery* base)
{
	RygelLocalSearchInsertionQuery * self;
	gchar* query = NULL;
	gchar* _tmp0_;
	gchar* _tmp1_;
	gchar* _tmp2_;
	gchar* _tmp3_;
	gchar* _tmp4_;
	gchar* _tmp5_;
	gchar* result;
	self = (RygelLocalSearchInsertionQuery*) base;
	_tmp0_ = RYGEL_LOCAL_SEARCH_QUERY_CLASS (rygel_local_search_insertion_query_parent_class)->to_string (G_TYPE_CHECK_INSTANCE_CAST (self, RYGEL_LOCAL_SEARCH_TYPE_QUERY, RygelLocalSearchQuery));
	_tmp1_ = _tmp0_;
	_tmp2_ = g_strconcat ("INSERT { ", _tmp1_, NULL);
	_tmp3_ = _tmp2_;
	_tmp4_ = g_strconcat (_tmp3_, " }", NULL);
	_tmp5_ = _tmp4_;
	_g_free0 (_tmp3_);
	_g_free0 (_tmp1_);
	query = _tmp5_;
	result = query;
	return result;
}

static void
rygel_local_search_insertion_query_class_init (RygelLocalSearchInsertionQueryClass * klass,
                                               gpointer klass_data)
{
	rygel_local_search_insertion_query_parent_class = g_type_class_peek_parent (klass);
	((RygelLocalSearchQueryClass *) klass)->finalize = rygel_local_search_insertion_query_finalize;
	g_type_class_adjust_private_offset (klass, &RygelLocalSearchInsertionQuery_private_offset);
	((RygelLocalSearchQueryClass *) klass)->execute = (void (*) (RygelLocalSearchQuery*, TrackerSparqlConnection*, GAsyncReadyCallback, gpointer)) rygel_local_search_insertion_query_real_execute;
	((RygelLocalSearchQueryClass *) klass)->execute_finish = (void (*) (RygelLocalSearchQuery*, GAsyncResult*, GError**)) rygel_local_search_insertion_query_execute_finish;
	((RygelLocalSearchQueryClass *) klass)->to_string = (gchar* (*) (RygelLocalSearchQuery*)) rygel_local_search_insertion_query_real_to_string;
}

static void
rygel_local_search_insertion_query_instance_init (RygelLocalSearchInsertionQuery * self,
                                                  gpointer klass)
{
	self->priv = rygel_local_search_insertion_query_get_instance_private (self);
	self->id = NULL;
}

static void
rygel_local_search_insertion_query_finalize (RygelLocalSearchQuery * obj)
{
	RygelLocalSearchInsertionQuery * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, RYGEL_LOCAL_SEARCH_TYPE_INSERTION_QUERY, RygelLocalSearchInsertionQuery);
	_g_free0 (self->id);
	_g_free0 (self->priv->uri);
	RYGEL_LOCAL_SEARCH_QUERY_CLASS (rygel_local_search_insertion_query_parent_class)->finalize (obj);
}

/**
 * Represents LocalSearch SPARQL Insertion query
 */
 G_GNUC_NO_INLINE static GType
rygel_local_search_insertion_query_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (RygelLocalSearchInsertionQueryClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) rygel_local_search_insertion_query_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (RygelLocalSearchInsertionQuery), 0, (GInstanceInitFunc) rygel_local_search_insertion_query_instance_init, NULL };
	GType rygel_local_search_insertion_query_type_id;
	rygel_local_search_insertion_query_type_id = g_type_register_static (RYGEL_LOCAL_SEARCH_TYPE_QUERY, "RygelLocalSearchInsertionQuery", &g_define_type_info, 0);
	RygelLocalSearchInsertionQuery_private_offset = g_type_add_instance_private (rygel_local_search_insertion_query_type_id, sizeof (RygelLocalSearchInsertionQueryPrivate));
	return rygel_local_search_insertion_query_type_id;
}

GType
rygel_local_search_insertion_query_get_type (void)
{
	static volatile gsize rygel_local_search_insertion_query_type_id__once = 0;
	if (g_once_init_enter (&rygel_local_search_insertion_query_type_id__once)) {
		GType rygel_local_search_insertion_query_type_id;
		rygel_local_search_insertion_query_type_id = rygel_local_search_insertion_query_get_type_once ();
		g_once_init_leave (&rygel_local_search_insertion_query_type_id__once, rygel_local_search_insertion_query_type_id);
	}
	return rygel_local_search_insertion_query_type_id__once;
}

