/* rygel-media-export-node-query-container.c generated by valac 0.15.1.36-84b2b, the Vala compiler
 * generated from rygel-media-export-node-query-container.vala, do not modify */

/*
 * Copyright (C) 2011 Jens Georg <mail@jensge.org>.
 *
 * 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 <rygel.h>
#include <gio/gio.h>
#include <stdlib.h>
#include <string.h>
#include <gee.h>


#define RYGEL_MEDIA_EXPORT_TYPE_DB_CONTAINER (rygel_media_export_db_container_get_type ())
#define RYGEL_MEDIA_EXPORT_DB_CONTAINER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), RYGEL_MEDIA_EXPORT_TYPE_DB_CONTAINER, RygelMediaExportDBContainer))
#define RYGEL_MEDIA_EXPORT_DB_CONTAINER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), RYGEL_MEDIA_EXPORT_TYPE_DB_CONTAINER, RygelMediaExportDBContainerClass))
#define RYGEL_MEDIA_EXPORT_IS_DB_CONTAINER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), RYGEL_MEDIA_EXPORT_TYPE_DB_CONTAINER))
#define RYGEL_MEDIA_EXPORT_IS_DB_CONTAINER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), RYGEL_MEDIA_EXPORT_TYPE_DB_CONTAINER))
#define RYGEL_MEDIA_EXPORT_DB_CONTAINER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), RYGEL_MEDIA_EXPORT_TYPE_DB_CONTAINER, RygelMediaExportDBContainerClass))

typedef struct _RygelMediaExportDBContainer RygelMediaExportDBContainer;
typedef struct _RygelMediaExportDBContainerClass RygelMediaExportDBContainerClass;
typedef struct _RygelMediaExportDBContainerPrivate RygelMediaExportDBContainerPrivate;

#define RYGEL_MEDIA_EXPORT_TYPE_MEDIA_CACHE (rygel_media_export_media_cache_get_type ())
#define RYGEL_MEDIA_EXPORT_MEDIA_CACHE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), RYGEL_MEDIA_EXPORT_TYPE_MEDIA_CACHE, RygelMediaExportMediaCache))
#define RYGEL_MEDIA_EXPORT_MEDIA_CACHE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), RYGEL_MEDIA_EXPORT_TYPE_MEDIA_CACHE, RygelMediaExportMediaCacheClass))
#define RYGEL_MEDIA_EXPORT_IS_MEDIA_CACHE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), RYGEL_MEDIA_EXPORT_TYPE_MEDIA_CACHE))
#define RYGEL_MEDIA_EXPORT_IS_MEDIA_CACHE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), RYGEL_MEDIA_EXPORT_TYPE_MEDIA_CACHE))
#define RYGEL_MEDIA_EXPORT_MEDIA_CACHE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), RYGEL_MEDIA_EXPORT_TYPE_MEDIA_CACHE, RygelMediaExportMediaCacheClass))

typedef struct _RygelMediaExportMediaCache RygelMediaExportMediaCache;
typedef struct _RygelMediaExportMediaCacheClass RygelMediaExportMediaCacheClass;

#define RYGEL_MEDIA_EXPORT_TYPE_QUERY_CONTAINER (rygel_media_export_query_container_get_type ())
#define RYGEL_MEDIA_EXPORT_QUERY_CONTAINER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), RYGEL_MEDIA_EXPORT_TYPE_QUERY_CONTAINER, RygelMediaExportQueryContainer))
#define RYGEL_MEDIA_EXPORT_QUERY_CONTAINER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), RYGEL_MEDIA_EXPORT_TYPE_QUERY_CONTAINER, RygelMediaExportQueryContainerClass))
#define RYGEL_MEDIA_EXPORT_IS_QUERY_CONTAINER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), RYGEL_MEDIA_EXPORT_TYPE_QUERY_CONTAINER))
#define RYGEL_MEDIA_EXPORT_IS_QUERY_CONTAINER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), RYGEL_MEDIA_EXPORT_TYPE_QUERY_CONTAINER))
#define RYGEL_MEDIA_EXPORT_QUERY_CONTAINER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), RYGEL_MEDIA_EXPORT_TYPE_QUERY_CONTAINER, RygelMediaExportQueryContainerClass))

typedef struct _RygelMediaExportQueryContainer RygelMediaExportQueryContainer;
typedef struct _RygelMediaExportQueryContainerClass RygelMediaExportQueryContainerClass;
typedef struct _RygelMediaExportQueryContainerPrivate RygelMediaExportQueryContainerPrivate;

#define RYGEL_MEDIA_EXPORT_TYPE_NODE_QUERY_CONTAINER (rygel_media_export_node_query_container_get_type ())
#define RYGEL_MEDIA_EXPORT_NODE_QUERY_CONTAINER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), RYGEL_MEDIA_EXPORT_TYPE_NODE_QUERY_CONTAINER, RygelMediaExportNodeQueryContainer))
#define RYGEL_MEDIA_EXPORT_NODE_QUERY_CONTAINER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), RYGEL_MEDIA_EXPORT_TYPE_NODE_QUERY_CONTAINER, RygelMediaExportNodeQueryContainerClass))
#define RYGEL_MEDIA_EXPORT_IS_NODE_QUERY_CONTAINER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), RYGEL_MEDIA_EXPORT_TYPE_NODE_QUERY_CONTAINER))
#define RYGEL_MEDIA_EXPORT_IS_NODE_QUERY_CONTAINER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), RYGEL_MEDIA_EXPORT_TYPE_NODE_QUERY_CONTAINER))
#define RYGEL_MEDIA_EXPORT_NODE_QUERY_CONTAINER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), RYGEL_MEDIA_EXPORT_TYPE_NODE_QUERY_CONTAINER, RygelMediaExportNodeQueryContainerClass))

typedef struct _RygelMediaExportNodeQueryContainer RygelMediaExportNodeQueryContainer;
typedef struct _RygelMediaExportNodeQueryContainerClass RygelMediaExportNodeQueryContainerClass;
typedef struct _RygelMediaExportNodeQueryContainerPrivate RygelMediaExportNodeQueryContainerPrivate;
#define _g_free0(var) (var = (g_free (var), NULL))
#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_regex_unref0(var) ((var == NULL) ? NULL : (var = (g_regex_unref (var), NULL)))

#define RYGEL_MEDIA_EXPORT_TYPE_QUERY_CONTAINER_FACTORY (rygel_media_export_query_container_factory_get_type ())
#define RYGEL_MEDIA_EXPORT_QUERY_CONTAINER_FACTORY(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), RYGEL_MEDIA_EXPORT_TYPE_QUERY_CONTAINER_FACTORY, RygelMediaExportQueryContainerFactory))
#define RYGEL_MEDIA_EXPORT_QUERY_CONTAINER_FACTORY_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), RYGEL_MEDIA_EXPORT_TYPE_QUERY_CONTAINER_FACTORY, RygelMediaExportQueryContainerFactoryClass))
#define RYGEL_MEDIA_EXPORT_IS_QUERY_CONTAINER_FACTORY(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), RYGEL_MEDIA_EXPORT_TYPE_QUERY_CONTAINER_FACTORY))
#define RYGEL_MEDIA_EXPORT_IS_QUERY_CONTAINER_FACTORY_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), RYGEL_MEDIA_EXPORT_TYPE_QUERY_CONTAINER_FACTORY))
#define RYGEL_MEDIA_EXPORT_QUERY_CONTAINER_FACTORY_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), RYGEL_MEDIA_EXPORT_TYPE_QUERY_CONTAINER_FACTORY, RygelMediaExportQueryContainerFactoryClass))

typedef struct _RygelMediaExportQueryContainerFactory RygelMediaExportQueryContainerFactory;
typedef struct _RygelMediaExportQueryContainerFactoryClass RygelMediaExportQueryContainerFactoryClass;
typedef struct _RygelMediaExportNodeQueryContainerGetChildrenData RygelMediaExportNodeQueryContainerGetChildrenData;

struct _RygelMediaExportDBContainer {
	RygelMediaContainer parent_instance;
	RygelMediaExportDBContainerPrivate * priv;
	RygelMediaExportMediaCache* media_db;
};

struct _RygelMediaExportDBContainerClass {
	RygelMediaContainerClass parent_class;
	void (*search) (RygelMediaExportDBContainer* self, RygelSearchExpression* expression, guint offset, guint max_count, GCancellable* cancellable, GAsyncReadyCallback _callback_, gpointer _user_data_);
	RygelMediaObjects* (*search_finish) (RygelMediaExportDBContainer* self, GAsyncResult* _res_, guint* total_matches, GError** error);
};

struct _RygelMediaExportQueryContainer {
	RygelMediaExportDBContainer parent_instance;
	RygelMediaExportQueryContainerPrivate * priv;
	RygelSearchExpression* expression;
};

struct _RygelMediaExportQueryContainerClass {
	RygelMediaExportDBContainerClass parent_class;
	gint (*count_children) (RygelMediaExportQueryContainer* self, GError** error);
};

struct _RygelMediaExportNodeQueryContainer {
	RygelMediaExportQueryContainer parent_instance;
	RygelMediaExportNodeQueryContainerPrivate * priv;
};

struct _RygelMediaExportNodeQueryContainerClass {
	RygelMediaExportQueryContainerClass parent_class;
};

struct _RygelMediaExportNodeQueryContainerPrivate {
	gchar* template;
	gchar* attribute;
};

struct _RygelMediaExportNodeQueryContainerGetChildrenData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GSimpleAsyncResult* _async_result;
	RygelMediaExportNodeQueryContainer* self;
	guint offset;
	guint max_count;
	GCancellable* cancellable;
	RygelMediaObjects* result;
	RygelMediaObjects* _tmp0_;
	RygelMediaObjects* children;
	RygelMediaExportMediaCache* _tmp1_;
	const gchar* _tmp2_;
	RygelSearchExpression* _tmp3_;
	guint _tmp4_;
	guint _tmp5_;
	GeeList* _tmp6_;
	GeeList* data;
	GeeList* _tmp7_;
	GeeList* _meta_data_list;
	GeeList* _tmp8_;
	gint _tmp9_;
	gint _tmp10_;
	gint _meta_data_size;
	gint _meta_data_index;
	gint _tmp11_;
	gint _tmp12_;
	gint _tmp13_;
	GeeList* _tmp14_;
	gint _tmp15_;
	gpointer _tmp16_;
	gchar* meta_data;
	const gchar* _tmp17_;
	gchar* _tmp18_;
	gchar* new_id;
	const gchar* _tmp19_;
	const gchar* _tmp20_;
	gchar* _tmp21_;
	RygelMediaExportQueryContainerFactory* _tmp22_;
	RygelMediaExportQueryContainerFactory* factory;
	RygelMediaExportQueryContainerFactory* _tmp23_;
	RygelMediaExportMediaCache* _tmp24_;
	const gchar* _tmp25_;
	const gchar* _tmp26_;
	RygelMediaExportQueryContainer* _tmp27_;
	RygelMediaExportQueryContainer* container;
	RygelMediaExportQueryContainer* _tmp28_;
	RygelMediaExportQueryContainer* _tmp29_;
	GError * _inner_error_;
};


static gpointer rygel_media_export_node_query_container_parent_class = NULL;

GType rygel_media_export_db_container_get_type (void) G_GNUC_CONST;
GType rygel_media_export_media_cache_get_type (void) G_GNUC_CONST;
GType rygel_media_export_query_container_get_type (void) G_GNUC_CONST;
GType rygel_media_export_node_query_container_get_type (void) G_GNUC_CONST;
#define RYGEL_MEDIA_EXPORT_NODE_QUERY_CONTAINER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), RYGEL_MEDIA_EXPORT_TYPE_NODE_QUERY_CONTAINER, RygelMediaExportNodeQueryContainerPrivate))
enum  {
	RYGEL_MEDIA_EXPORT_NODE_QUERY_CONTAINER_DUMMY_PROPERTY
};
RygelMediaExportNodeQueryContainer* rygel_media_export_node_query_container_new (RygelMediaExportMediaCache* cache, RygelSearchExpression* expression, const gchar* id, const gchar* name, const gchar* template, const gchar* attribute);
RygelMediaExportNodeQueryContainer* rygel_media_export_node_query_container_construct (GType object_type, RygelMediaExportMediaCache* cache, RygelSearchExpression* expression, const gchar* id, const gchar* name, const gchar* template, const gchar* attribute);
RygelMediaExportQueryContainer* rygel_media_export_query_container_construct (GType object_type, RygelMediaExportMediaCache* cache, RygelSearchExpression* expression, const gchar* id, const gchar* name);
gint rygel_media_export_query_container_count_children (RygelMediaExportQueryContainer* self, GError** error);
static void rygel_media_export_node_query_container_real_get_children_data_free (gpointer _data);
static void rygel_media_export_node_query_container_real_get_children (RygelMediaContainer* base, guint offset, guint max_count, GCancellable* cancellable, GAsyncReadyCallback _callback_, gpointer _user_data_);
static gboolean rygel_media_export_node_query_container_real_get_children_co (RygelMediaExportNodeQueryContainerGetChildrenData* _data_);
GeeList* rygel_media_export_media_cache_get_object_attribute_by_search_expression (RygelMediaExportMediaCache* self, const gchar* attribute, RygelSearchExpression* expression, glong offset, guint max_count, GError** error);
GType rygel_media_export_query_container_factory_get_type (void) G_GNUC_CONST;
RygelMediaExportQueryContainerFactory* rygel_media_export_query_container_factory_get_default (void);
RygelMediaExportQueryContainer* rygel_media_export_query_container_factory_create_from_description (RygelMediaExportQueryContainerFactory* self, RygelMediaExportMediaCache* cache, const gchar* definition, const gchar* name);
static gint rygel_media_export_node_query_container_real_count_children (RygelMediaExportQueryContainer* base, GError** error);
static void rygel_media_export_node_query_container_finalize (GObject* obj);


RygelMediaExportNodeQueryContainer* rygel_media_export_node_query_container_construct (GType object_type, RygelMediaExportMediaCache* cache, RygelSearchExpression* expression, const gchar* id, const gchar* name, const gchar* template, const gchar* attribute) {
	RygelMediaExportNodeQueryContainer * self = NULL;
	RygelMediaExportMediaCache* _tmp0_;
	RygelSearchExpression* _tmp1_;
	const gchar* _tmp2_;
	const gchar* _tmp3_;
	const gchar* _tmp4_;
	gchar* _tmp5_;
	const gchar* _tmp6_;
	gchar* _tmp7_;
	GError * _inner_error_ = NULL;
	g_return_val_if_fail (cache != NULL, NULL);
	g_return_val_if_fail (expression != NULL, NULL);
	g_return_val_if_fail (id != NULL, NULL);
	g_return_val_if_fail (name != NULL, NULL);
	g_return_val_if_fail (template != NULL, NULL);
	g_return_val_if_fail (attribute != NULL, NULL);
	_tmp0_ = cache;
	_tmp1_ = expression;
	_tmp2_ = id;
	_tmp3_ = name;
	self = (RygelMediaExportNodeQueryContainer*) rygel_media_export_query_container_construct (object_type, _tmp0_, _tmp1_, _tmp2_, _tmp3_);
	_tmp4_ = template;
	_tmp5_ = g_strdup (_tmp4_);
	_g_free0 (self->priv->template);
	self->priv->template = _tmp5_;
	_tmp6_ = attribute;
	_tmp7_ = g_strdup (_tmp6_);
	_g_free0 (self->priv->attribute);
	self->priv->attribute = _tmp7_;
	{
		gint _tmp8_ = 0;
		gint _tmp9_;
		_tmp8_ = rygel_media_export_query_container_count_children ((RygelMediaExportQueryContainer*) self, &_inner_error_);
		_tmp9_ = _tmp8_;
		if (_inner_error_ != NULL) {
			goto __catch39_g_error;
		}
		((RygelMediaContainer*) self)->child_count = _tmp9_;
	}
	goto __finally39;
	__catch39_g_error:
	{
		GError* _error_ = NULL;
		_error_ = _inner_error_;
		_inner_error_ = NULL;
		_g_error_free0 (_error_);
	}
	__finally39:
	if (_inner_error_ != NULL) {
		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;
	}
	return self;
}


RygelMediaExportNodeQueryContainer* rygel_media_export_node_query_container_new (RygelMediaExportMediaCache* cache, RygelSearchExpression* expression, const gchar* id, const gchar* name, const gchar* template, const gchar* attribute) {
	return rygel_media_export_node_query_container_construct (RYGEL_MEDIA_EXPORT_TYPE_NODE_QUERY_CONTAINER, cache, expression, id, name, template, attribute);
}


static void rygel_media_export_node_query_container_real_get_children_data_free (gpointer _data) {
	RygelMediaExportNodeQueryContainerGetChildrenData* _data_;
	_data_ = _data;
	_g_object_unref0 (_data_->cancellable);
	_g_object_unref0 (_data_->result);
	_g_object_unref0 (_data_->self);
	g_slice_free (RygelMediaExportNodeQueryContainerGetChildrenData, _data_);
}


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


static void rygel_media_export_node_query_container_real_get_children (RygelMediaContainer* base, guint offset, guint max_count, GCancellable* cancellable, GAsyncReadyCallback _callback_, gpointer _user_data_) {
	RygelMediaExportNodeQueryContainer * self;
	RygelMediaExportNodeQueryContainerGetChildrenData* _data_;
	RygelMediaExportNodeQueryContainer* _tmp0_;
	guint _tmp1_;
	guint _tmp2_;
	GCancellable* _tmp3_;
	GCancellable* _tmp4_;
	self = (RygelMediaExportNodeQueryContainer*) base;
	_data_ = g_slice_new0 (RygelMediaExportNodeQueryContainerGetChildrenData);
	_data_->_async_result = g_simple_async_result_new (G_OBJECT (self), _callback_, _user_data_, rygel_media_export_node_query_container_real_get_children);
	g_simple_async_result_set_op_res_gpointer (_data_->_async_result, _data_, rygel_media_export_node_query_container_real_get_children_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	_tmp1_ = offset;
	_data_->offset = _tmp1_;
	_tmp2_ = max_count;
	_data_->max_count = _tmp2_;
	_tmp3_ = cancellable;
	_tmp4_ = _g_object_ref0 (_tmp3_);
	_data_->cancellable = _tmp4_;
	rygel_media_export_node_query_container_real_get_children_co (_data_);
}


static RygelMediaObjects* rygel_media_export_node_query_container_real_get_children_finish (RygelMediaContainer* base, GAsyncResult* _res_, GError** error) {
	RygelMediaObjects* result;
	RygelMediaExportNodeQueryContainerGetChildrenData* _data_;
	if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (_res_), error)) {
		return NULL;
	}
	_data_ = g_simple_async_result_get_op_res_gpointer (G_SIMPLE_ASYNC_RESULT (_res_));
	result = _data_->result;
	_data_->result = NULL;
	return result;
}


static gchar* string_replace (const gchar* self, const gchar* old, const gchar* replacement) {
	gchar* result = NULL;
	GError * _inner_error_ = NULL;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (old != NULL, NULL);
	g_return_val_if_fail (replacement != NULL, NULL);
	{
		const gchar* _tmp0_;
		gchar* _tmp1_ = NULL;
		gchar* _tmp2_;
		GRegex* _tmp3_;
		GRegex* _tmp4_;
		GRegex* regex;
		GRegex* _tmp5_;
		const gchar* _tmp6_;
		gchar* _tmp7_ = NULL;
		gchar* _tmp8_;
		_tmp0_ = old;
		_tmp1_ = g_regex_escape_string (_tmp0_, -1);
		_tmp2_ = _tmp1_;
		_tmp3_ = g_regex_new (_tmp2_, 0, 0, &_inner_error_);
		_tmp4_ = _tmp3_;
		_g_free0 (_tmp2_);
		regex = _tmp4_;
		if (_inner_error_ != NULL) {
			if (_inner_error_->domain == G_REGEX_ERROR) {
				goto __catch40_g_regex_error;
			}
			g_critical ("file %s: line %d: unexpected 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;
		}
		_tmp5_ = regex;
		_tmp6_ = replacement;
		_tmp7_ = g_regex_replace_literal (_tmp5_, self, (gssize) (-1), 0, _tmp6_, 0, &_inner_error_);
		_tmp8_ = _tmp7_;
		if (_inner_error_ != NULL) {
			_g_regex_unref0 (regex);
			if (_inner_error_->domain == G_REGEX_ERROR) {
				goto __catch40_g_regex_error;
			}
			_g_regex_unref0 (regex);
			g_critical ("file %s: line %d: unexpected 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;
		}
		result = _tmp8_;
		_g_regex_unref0 (regex);
		return result;
	}
	goto __finally40;
	__catch40_g_regex_error:
	{
		GError* e = NULL;
		e = _inner_error_;
		_inner_error_ = NULL;
		g_assert_not_reached ();
		_g_error_free0 (e);
	}
	__finally40:
	if (_inner_error_ != NULL) {
		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;
	}
}


static gboolean rygel_media_export_node_query_container_real_get_children_co (RygelMediaExportNodeQueryContainerGetChildrenData* _data_) {
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_tmp0_ = rygel_media_objects_new ();
	_data_->children = _data_->_tmp0_;
	_data_->_tmp1_ = ((RygelMediaExportDBContainer*) _data_->self)->media_db;
	_data_->_tmp2_ = _data_->self->priv->attribute;
	_data_->_tmp3_ = ((RygelMediaExportQueryContainer*) _data_->self)->expression;
	_data_->_tmp4_ = _data_->offset;
	_data_->_tmp5_ = _data_->max_count;
	_data_->_tmp6_ = NULL;
	_data_->_tmp6_ = rygel_media_export_media_cache_get_object_attribute_by_search_expression (_data_->_tmp1_, _data_->_tmp2_, _data_->_tmp3_, (glong) _data_->_tmp4_, _data_->_tmp5_, &_data_->_inner_error_);
	_data_->data = _data_->_tmp6_;
	if (_data_->_inner_error_ != NULL) {
		g_simple_async_result_set_from_error (_data_->_async_result, _data_->_inner_error_);
		g_error_free (_data_->_inner_error_);
		_g_object_unref0 (_data_->children);
		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;
	}
	{
		_data_->_tmp7_ = _g_object_ref0 (_data_->data);
		_data_->_meta_data_list = _data_->_tmp7_;
		_data_->_tmp8_ = _data_->_meta_data_list;
		_data_->_tmp9_ = gee_collection_get_size ((GeeCollection*) _data_->_tmp8_);
		_data_->_tmp10_ = _data_->_tmp9_;
		_data_->_meta_data_size = _data_->_tmp10_;
		_data_->_meta_data_index = -1;
		while (TRUE) {
			_data_->_tmp11_ = _data_->_meta_data_index;
			_data_->_meta_data_index = _data_->_tmp11_ + 1;
			_data_->_tmp12_ = _data_->_meta_data_index;
			_data_->_tmp13_ = _data_->_meta_data_size;
			if (!(_data_->_tmp12_ < _data_->_tmp13_)) {
				break;
			}
			_data_->_tmp14_ = _data_->_meta_data_list;
			_data_->_tmp15_ = _data_->_meta_data_index;
			_data_->_tmp16_ = NULL;
			_data_->_tmp16_ = gee_list_get (_data_->_tmp14_, _data_->_tmp15_);
			_data_->meta_data = (gchar*) _data_->_tmp16_;
			_data_->_tmp17_ = _data_->meta_data;
			_data_->_tmp18_ = NULL;
			_data_->_tmp18_ = g_uri_escape_string (_data_->_tmp17_, "", TRUE);
			_data_->new_id = _data_->_tmp18_;
			_data_->_tmp19_ = _data_->self->priv->template;
			_data_->_tmp20_ = _data_->new_id;
			_data_->_tmp21_ = NULL;
			_data_->_tmp21_ = string_replace (_data_->_tmp19_, "%s", _data_->_tmp20_);
			_g_free0 (_data_->new_id);
			_data_->new_id = _data_->_tmp21_;
			_data_->_tmp22_ = NULL;
			_data_->_tmp22_ = rygel_media_export_query_container_factory_get_default ();
			_data_->factory = _data_->_tmp22_;
			_data_->_tmp23_ = _data_->factory;
			_data_->_tmp24_ = ((RygelMediaExportDBContainer*) _data_->self)->media_db;
			_data_->_tmp25_ = _data_->new_id;
			_data_->_tmp26_ = _data_->meta_data;
			_data_->_tmp27_ = NULL;
			_data_->_tmp27_ = rygel_media_export_query_container_factory_create_from_description (_data_->_tmp23_, _data_->_tmp24_, _data_->_tmp25_, _data_->_tmp26_);
			_data_->container = _data_->_tmp27_;
			_data_->_tmp28_ = _data_->container;
			((RygelMediaObject*) _data_->_tmp28_)->parent = (RygelMediaContainer*) _data_->self;
			_data_->_tmp29_ = _data_->container;
			gee_abstract_collection_add ((GeeAbstractCollection*) _data_->children, (RygelMediaObject*) _data_->_tmp29_);
			_g_object_unref0 (_data_->container);
			_g_object_unref0 (_data_->factory);
			_g_free0 (_data_->new_id);
			_g_free0 (_data_->meta_data);
		}
		_g_object_unref0 (_data_->_meta_data_list);
	}
	_data_->result = _data_->children;
	_g_object_unref0 (_data_->data);
	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;
	_g_object_unref0 (_data_->data);
	_g_object_unref0 (_data_->children);
	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 gint rygel_media_export_node_query_container_real_count_children (RygelMediaExportQueryContainer* base, GError** error) {
	RygelMediaExportNodeQueryContainer * self;
	gint result = 0;
	gboolean _tmp0_ = FALSE;
	const gchar* _tmp1_;
	gboolean _tmp3_;
	RygelMediaExportMediaCache* _tmp4_;
	const gchar* _tmp5_;
	RygelSearchExpression* _tmp6_;
	GeeList* _tmp7_ = NULL;
	GeeList* data;
	GeeList* _tmp8_;
	gint _tmp9_;
	gint _tmp10_;
	GError * _inner_error_ = NULL;
	self = (RygelMediaExportNodeQueryContainer*) base;
	_tmp1_ = self->priv->attribute;
	if (_tmp1_ == NULL) {
		_tmp0_ = TRUE;
	} else {
		RygelSearchExpression* _tmp2_;
		_tmp2_ = ((RygelMediaExportQueryContainer*) self)->expression;
		_tmp0_ = _tmp2_ == NULL;
	}
	_tmp3_ = _tmp0_;
	if (_tmp3_) {
		result = 0;
		return result;
	}
	_tmp4_ = ((RygelMediaExportDBContainer*) self)->media_db;
	_tmp5_ = self->priv->attribute;
	_tmp6_ = ((RygelMediaExportQueryContainer*) self)->expression;
	_tmp7_ = rygel_media_export_media_cache_get_object_attribute_by_search_expression (_tmp4_, _tmp5_, _tmp6_, (glong) 0, (guint) (-1), &_inner_error_);
	data = _tmp7_;
	if (_inner_error_ != NULL) {
		g_propagate_error (error, _inner_error_);
		return 0;
	}
	_tmp8_ = data;
	_tmp9_ = gee_collection_get_size ((GeeCollection*) _tmp8_);
	_tmp10_ = _tmp9_;
	result = _tmp10_;
	_g_object_unref0 (data);
	return result;
}


static void rygel_media_export_node_query_container_class_init (RygelMediaExportNodeQueryContainerClass * klass) {
	rygel_media_export_node_query_container_parent_class = g_type_class_peek_parent (klass);
	g_type_class_add_private (klass, sizeof (RygelMediaExportNodeQueryContainerPrivate));
	RYGEL_MEDIA_CONTAINER_CLASS (klass)->get_children = rygel_media_export_node_query_container_real_get_children;
	RYGEL_MEDIA_CONTAINER_CLASS (klass)->get_children_finish = rygel_media_export_node_query_container_real_get_children_finish;
	RYGEL_MEDIA_EXPORT_QUERY_CONTAINER_CLASS (klass)->count_children = rygel_media_export_node_query_container_real_count_children;
	G_OBJECT_CLASS (klass)->finalize = rygel_media_export_node_query_container_finalize;
}


static void rygel_media_export_node_query_container_instance_init (RygelMediaExportNodeQueryContainer * self) {
	self->priv = RYGEL_MEDIA_EXPORT_NODE_QUERY_CONTAINER_GET_PRIVATE (self);
}


static void rygel_media_export_node_query_container_finalize (GObject* obj) {
	RygelMediaExportNodeQueryContainer * self;
	self = RYGEL_MEDIA_EXPORT_NODE_QUERY_CONTAINER (obj);
	_g_free0 (self->priv->template);
	_g_free0 (self->priv->attribute);
	G_OBJECT_CLASS (rygel_media_export_node_query_container_parent_class)->finalize (obj);
}


GType rygel_media_export_node_query_container_get_type (void) {
	static volatile gsize rygel_media_export_node_query_container_type_id__volatile = 0;
	if (g_once_init_enter (&rygel_media_export_node_query_container_type_id__volatile)) {
		static const GTypeInfo g_define_type_info = { sizeof (RygelMediaExportNodeQueryContainerClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) rygel_media_export_node_query_container_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (RygelMediaExportNodeQueryContainer), 0, (GInstanceInitFunc) rygel_media_export_node_query_container_instance_init, NULL };
		GType rygel_media_export_node_query_container_type_id;
		rygel_media_export_node_query_container_type_id = g_type_register_static (RYGEL_MEDIA_EXPORT_TYPE_QUERY_CONTAINER, "RygelMediaExportNodeQueryContainer", &g_define_type_info, 0);
		g_once_init_leave (&rygel_media_export_node_query_container_type_id__volatile, rygel_media_export_node_query_container_type_id);
	}
	return rygel_media_export_node_query_container_type_id__volatile;
}



