/* rygel-media-export-leaf-query-container.c generated by valac 0.40.8, the Vala compiler
 * generated from rygel-media-export-leaf-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.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 <glib.h>
#include <glib-object.h>
#include <rygel-server.h>
#include <gio/gio.h>
#include <stdlib.h>
#include <string.h>
#include <gee.h>
#include <glib/gi18n-lib.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_LEAF_QUERY_CONTAINER (rygel_media_export_leaf_query_container_get_type ())
#define RYGEL_MEDIA_EXPORT_LEAF_QUERY_CONTAINER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), RYGEL_MEDIA_EXPORT_TYPE_LEAF_QUERY_CONTAINER, RygelMediaExportLeafQueryContainer))
#define RYGEL_MEDIA_EXPORT_LEAF_QUERY_CONTAINER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), RYGEL_MEDIA_EXPORT_TYPE_LEAF_QUERY_CONTAINER, RygelMediaExportLeafQueryContainerClass))
#define RYGEL_MEDIA_EXPORT_IS_LEAF_QUERY_CONTAINER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), RYGEL_MEDIA_EXPORT_TYPE_LEAF_QUERY_CONTAINER))
#define RYGEL_MEDIA_EXPORT_IS_LEAF_QUERY_CONTAINER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), RYGEL_MEDIA_EXPORT_TYPE_LEAF_QUERY_CONTAINER))
#define RYGEL_MEDIA_EXPORT_LEAF_QUERY_CONTAINER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), RYGEL_MEDIA_EXPORT_TYPE_LEAF_QUERY_CONTAINER, RygelMediaExportLeafQueryContainerClass))

typedef struct _RygelMediaExportLeafQueryContainer RygelMediaExportLeafQueryContainer;
typedef struct _RygelMediaExportLeafQueryContainerClass RygelMediaExportLeafQueryContainerClass;
typedef struct _RygelMediaExportLeafQueryContainerPrivate RygelMediaExportLeafQueryContainerPrivate;
enum  {
	RYGEL_MEDIA_EXPORT_LEAF_QUERY_CONTAINER_0_PROPERTY,
	RYGEL_MEDIA_EXPORT_LEAF_QUERY_CONTAINER_NUM_PROPERTIES
};
static GParamSpec* rygel_media_export_leaf_query_container_properties[RYGEL_MEDIA_EXPORT_LEAF_QUERY_CONTAINER_NUM_PROPERTIES];
#define _g_free0(var) (var = (g_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 _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))
typedef struct _RygelMediaExportLeafQueryContainerGetChildrenData RygelMediaExportLeafQueryContainerGetChildrenData;

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

struct _RygelMediaExportDBContainerClass {
	RygelMediaContainerClass parent_class;
	gint (*count_children) (RygelMediaExportDBContainer* self);
	void (*search) (RygelMediaExportDBContainer* self, RygelSearchExpression* expression, guint offset, guint max_count, const gchar* sort_criteria, 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;
};

struct _RygelMediaExportQueryContainerClass {
	RygelMediaExportDBContainerClass parent_class;
};

struct _RygelMediaExportLeafQueryContainer {
	RygelMediaExportQueryContainer parent_instance;
	RygelMediaExportLeafQueryContainerPrivate * priv;
};

struct _RygelMediaExportLeafQueryContainerClass {
	RygelMediaExportQueryContainerClass parent_class;
};

struct _RygelMediaExportLeafQueryContainerGetChildrenData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	GAsyncReadyCallback _callback_;
	gboolean _task_complete_;
	RygelMediaExportLeafQueryContainer* self;
	guint offset;
	guint max_count;
	gchar* sort_criteria;
	GCancellable* cancellable;
	RygelMediaObjects* result;
	guint total_matches;
	RygelMediaObjects* children;
	RygelMediaExportMediaCache* _tmp0_;
	RygelSearchExpression* _tmp1_;
	RygelSearchExpression* _tmp2_;
	guint _tmp3_;
	RygelMediaObjects* _tmp4_;
	RygelMediaObjects* _child_list;
	RygelMediaObjects* _tmp5_;
	gint _child_size;
	RygelMediaObjects* _tmp6_;
	gint _tmp7_;
	gint _tmp8_;
	gint _child_index;
	gint _tmp9_;
	gint _tmp10_;
	gint _tmp11_;
	RygelMediaObject* child;
	RygelMediaObjects* _tmp12_;
	gint _tmp13_;
	gpointer _tmp14_;
	gchar* container_id;
	const gchar* _tmp15_;
	const gchar* _tmp16_;
	gchar* _tmp17_;
	gchar* _tmp18_;
	gchar* _tmp19_;
	gchar* _tmp20_;
	RygelMediaObject* _tmp21_;
	RygelMediaObject* _tmp22_;
	const gchar* _tmp23_;
	const gchar* _tmp24_;
	RygelMediaObject* _tmp25_;
	const gchar* _tmp26_;
	gchar* _tmp27_;
	gchar* _tmp28_;
	RygelMediaObject* _tmp29_;
	const gchar* _tmp30_;
	const gchar* _tmp31_;
	gchar* _tmp32_;
	gchar* _tmp33_;
	RygelMediaObject* _tmp34_;
	GError * _inner_error_;
};


static gpointer rygel_media_export_leaf_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_leaf_query_container_get_type (void) G_GNUC_CONST;
RygelMediaExportLeafQueryContainer* rygel_media_export_leaf_query_container_new (RygelSearchExpression* expression,
                                                                                 const gchar* id,
                                                                                 const gchar* name);
RygelMediaExportLeafQueryContainer* rygel_media_export_leaf_query_container_construct (GType object_type,
                                                                                       RygelSearchExpression* expression,
                                                                                       const gchar* id,
                                                                                       const gchar* name);
static void rygel_media_export_leaf_query_container_real_get_children_data_free (gpointer _data);
static void rygel_media_export_leaf_query_container_real_get_children_async_ready_wrapper (GObject *source_object,
                                                                                    GAsyncResult *res,
                                                                                    void *user_data);
static void rygel_media_export_leaf_query_container_real_get_children (RygelMediaContainer* base,
                                                                guint offset,
                                                                guint max_count,
                                                                const gchar* sort_criteria,
                                                                GCancellable* cancellable,
                                                                GAsyncReadyCallback _callback_,
                                                                gpointer _user_data_);
static gboolean rygel_media_export_leaf_query_container_real_get_children_co (RygelMediaExportLeafQueryContainerGetChildrenData* _data_);
RygelMediaObjects* rygel_media_export_media_cache_get_objects_by_search_expression (RygelMediaExportMediaCache* self,
                                                                                    RygelSearchExpression* expression,
                                                                                    const gchar* container_id,
                                                                                    const gchar* sort_criteria,
                                                                                    guint offset,
                                                                                    guint max_count,
                                                                                    guint* total_matches,
                                                                                    GError** error);
RygelSearchExpression* rygel_media_export_query_container_get_expression (RygelMediaExportQueryContainer* self);
#define RYGEL_MEDIA_EXPORT_QUERY_CONTAINER_ITEM_PREFIX "virtual-id:"
#define RYGEL_MEDIA_EXPORT_QUERY_CONTAINER_PREFIX "virtual-container:"
static gint rygel_media_export_leaf_query_container_real_count_children (RygelMediaExportDBContainer* base);
glong rygel_media_export_media_cache_get_object_count_by_search_expression (RygelMediaExportMediaCache* self,
                                                                            RygelSearchExpression* expression,
                                                                            const gchar* container_id,
                                                                            GError** error);


RygelMediaExportLeafQueryContainer*
rygel_media_export_leaf_query_container_construct (GType object_type,
                                                   RygelSearchExpression* expression,
                                                   const gchar* id,
                                                   const gchar* name)
{
	RygelMediaExportLeafQueryContainer * self = 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);
	self = (RygelMediaExportLeafQueryContainer*) g_object_new (object_type, "id", id, "title", name, "parent", NULL, "child-count", 0, "expression", expression, NULL);
	return self;
}


RygelMediaExportLeafQueryContainer*
rygel_media_export_leaf_query_container_new (RygelSearchExpression* expression,
                                             const gchar* id,
                                             const gchar* name)
{
	return rygel_media_export_leaf_query_container_construct (RYGEL_MEDIA_EXPORT_TYPE_LEAF_QUERY_CONTAINER, expression, id, name);
}


static void
rygel_media_export_leaf_query_container_real_get_children_data_free (gpointer _data)
{
	RygelMediaExportLeafQueryContainerGetChildrenData* _data_;
	_data_ = _data;
	_g_free0 (_data_->sort_criteria);
	_g_object_unref0 (_data_->cancellable);
	_g_object_unref0 (_data_->result);
	_g_object_unref0 (_data_->self);
	g_slice_free (RygelMediaExportLeafQueryContainerGetChildrenData, _data_);
}


static void
rygel_media_export_leaf_query_container_real_get_children_async_ready_wrapper (GObject *source_object,
                                                                               GAsyncResult *res,
                                                                               void *user_data)
{
	RygelMediaExportLeafQueryContainerGetChildrenData* _task_data_;
	_task_data_ = g_task_get_task_data (G_TASK (res));
	if (_task_data_->_callback_ != NULL) {
		_task_data_->_callback_ (source_object, res, user_data);
	}
	_task_data_->_task_complete_ = TRUE;
}


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


static void
rygel_media_export_leaf_query_container_real_get_children (RygelMediaContainer* base,
                                                           guint offset,
                                                           guint max_count,
                                                           const gchar* sort_criteria,
                                                           GCancellable* cancellable,
                                                           GAsyncReadyCallback _callback_,
                                                           gpointer _user_data_)
{
	RygelMediaExportLeafQueryContainer * self;
	RygelMediaExportLeafQueryContainerGetChildrenData* _data_;
	RygelMediaExportLeafQueryContainer* _tmp0_;
	gchar* _tmp1_;
	GCancellable* _tmp2_;
	self = (RygelMediaExportLeafQueryContainer*) base;
	_data_ = g_slice_new0 (RygelMediaExportLeafQueryContainerGetChildrenData);
	_data_->_callback_ = _callback_;
	_data_->_async_result = g_task_new (G_OBJECT (self), cancellable, rygel_media_export_leaf_query_container_real_get_children_async_ready_wrapper, _user_data_);
	if (_callback_ == NULL) {
		_data_->_task_complete_ = TRUE;
	}
	g_task_set_task_data (_data_->_async_result, _data_, rygel_media_export_leaf_query_container_real_get_children_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	_data_->offset = offset;
	_data_->max_count = max_count;
	_tmp1_ = g_strdup (sort_criteria);
	_g_free0 (_data_->sort_criteria);
	_data_->sort_criteria = _tmp1_;
	_tmp2_ = _g_object_ref0 (cancellable);
	_g_object_unref0 (_data_->cancellable);
	_data_->cancellable = _tmp2_;
	rygel_media_export_leaf_query_container_real_get_children_co (_data_);
}


static RygelMediaObjects*
rygel_media_export_leaf_query_container_real_get_children_finish (RygelMediaContainer* base,
                                                                  GAsyncResult* _res_,
                                                                  GError** error)
{
	RygelMediaObjects* result;
	RygelMediaExportLeafQueryContainerGetChildrenData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), error);
	if (NULL == _data_) {
		return NULL;
	}
	result = _data_->result;
	_data_->result = NULL;
	return result;
}


static gchar*
string_replace (const gchar* self,
                const gchar* old,
                const gchar* replacement)
{
	gchar* result = NULL;
	gboolean _tmp0_ = FALSE;
	gboolean _tmp1_ = FALSE;
	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);
	if ((*((gchar*) self)) == '\0') {
		_tmp1_ = TRUE;
	} else {
		_tmp1_ = (*((gchar*) old)) == '\0';
	}
	if (_tmp1_) {
		_tmp0_ = TRUE;
	} else {
		_tmp0_ = g_strcmp0 (old, replacement) == 0;
	}
	if (_tmp0_) {
		gchar* _tmp2_;
		_tmp2_ = g_strdup (self);
		result = _tmp2_;
		return result;
	}
	{
		GRegex* regex = NULL;
		gchar* _tmp3_;
		gchar* _tmp4_;
		GRegex* _tmp5_;
		GRegex* _tmp6_;
		gchar* _tmp7_ = NULL;
		GRegex* _tmp8_;
		gchar* _tmp9_;
		gchar* _tmp10_;
		_tmp3_ = g_regex_escape_string (old, -1);
		_tmp4_ = _tmp3_;
		_tmp5_ = g_regex_new (_tmp4_, 0, 0, &_inner_error_);
		_tmp6_ = _tmp5_;
		_g_free0 (_tmp4_);
		regex = _tmp6_;
		if (G_UNLIKELY (_inner_error_ != NULL)) {
			if (_inner_error_->domain == G_REGEX_ERROR) {
				goto __catch48_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;
		}
		_tmp8_ = regex;
		_tmp9_ = g_regex_replace_literal (_tmp8_, self, (gssize) -1, 0, replacement, 0, &_inner_error_);
		_tmp7_ = _tmp9_;
		if (G_UNLIKELY (_inner_error_ != NULL)) {
			_g_regex_unref0 (regex);
			if (_inner_error_->domain == G_REGEX_ERROR) {
				goto __catch48_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;
		}
		_tmp10_ = _tmp7_;
		_tmp7_ = NULL;
		result = _tmp10_;
		_g_free0 (_tmp7_);
		_g_regex_unref0 (regex);
		return result;
	}
	goto __finally48;
	__catch48_g_regex_error:
	{
		GError* e = NULL;
		e = _inner_error_;
		_inner_error_ = NULL;
		g_assert_not_reached ();
		_g_error_free0 (e);
	}
	__finally48:
	if (G_UNLIKELY (_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_leaf_query_container_real_get_children_co (RygelMediaExportLeafQueryContainerGetChildrenData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_tmp0_ = ((RygelMediaExportDBContainer*) _data_->self)->media_db;
	_data_->_tmp1_ = rygel_media_export_query_container_get_expression ((RygelMediaExportQueryContainer*) _data_->self);
	_data_->_tmp2_ = _data_->_tmp1_;
	_data_->_tmp3_ = 0U;
	_data_->_tmp4_ = rygel_media_export_media_cache_get_objects_by_search_expression (_data_->_tmp0_, _data_->_tmp2_, "0", _data_->sort_criteria, _data_->offset, _data_->max_count, &_data_->_tmp3_, &_data_->_inner_error_);
	_data_->total_matches = _data_->_tmp3_;
	_data_->children = _data_->_tmp4_;
	if (G_UNLIKELY (_data_->_inner_error_ != NULL)) {
		g_task_return_error (_data_->_async_result, _data_->_inner_error_);
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	{
		_data_->_tmp5_ = _g_object_ref0 (_data_->children);
		_data_->_child_list = _data_->_tmp5_;
		_data_->_tmp6_ = _data_->_child_list;
		_data_->_tmp7_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _data_->_tmp6_);
		_data_->_tmp8_ = _data_->_tmp7_;
		_data_->_child_size = _data_->_tmp8_;
		_data_->_child_index = -1;
		while (TRUE) {
			_data_->_tmp9_ = _data_->_child_index;
			_data_->_child_index = _data_->_tmp9_ + 1;
			_data_->_tmp10_ = _data_->_child_index;
			_data_->_tmp11_ = _data_->_child_size;
			if (!(_data_->_tmp10_ < _data_->_tmp11_)) {
				break;
			}
			_data_->_tmp12_ = _data_->_child_list;
			_data_->_tmp13_ = _data_->_child_index;
			_data_->_tmp14_ = gee_abstract_list_get ((GeeAbstractList*) _data_->_tmp12_, _data_->_tmp13_);
			_data_->child = (RygelMediaObject*) _data_->_tmp14_;
			_data_->_tmp15_ = rygel_media_object_get_id ((RygelMediaObject*) _data_->self);
			_data_->_tmp16_ = _data_->_tmp15_;
			_data_->_tmp17_ = string_replace (_data_->_tmp16_, RYGEL_MEDIA_EXPORT_QUERY_CONTAINER_PREFIX, "");
			_data_->_tmp18_ = _data_->_tmp17_;
			_data_->_tmp19_ = g_strconcat (RYGEL_MEDIA_EXPORT_QUERY_CONTAINER_ITEM_PREFIX, _data_->_tmp18_, NULL);
			_data_->_tmp20_ = _data_->_tmp19_;
			_g_free0 (_data_->_tmp18_);
			_data_->container_id = _data_->_tmp20_;
			_data_->_tmp21_ = _data_->child;
			_data_->_tmp22_ = _data_->child;
			_data_->_tmp23_ = rygel_media_object_get_id (_data_->_tmp22_);
			_data_->_tmp24_ = _data_->_tmp23_;
			rygel_media_object_set_ref_id (_data_->_tmp21_, _data_->_tmp24_);
			_data_->_tmp25_ = _data_->child;
			_data_->_tmp26_ = _data_->container_id;
			_data_->_tmp27_ = g_strconcat (_data_->_tmp26_, ":", NULL);
			_data_->_tmp28_ = _data_->_tmp27_;
			_data_->_tmp29_ = _data_->child;
			_data_->_tmp30_ = rygel_media_object_get_ref_id (_data_->_tmp29_);
			_data_->_tmp31_ = _data_->_tmp30_;
			_data_->_tmp32_ = g_strconcat (_data_->_tmp28_, _data_->_tmp31_, NULL);
			_data_->_tmp33_ = _data_->_tmp32_;
			rygel_media_object_set_id (_data_->_tmp25_, _data_->_tmp33_);
			_g_free0 (_data_->_tmp33_);
			_g_free0 (_data_->_tmp28_);
			_data_->_tmp34_ = _data_->child;
			rygel_media_object_set_parent_ref (_data_->_tmp34_, (RygelMediaContainer*) _data_->self);
			_g_free0 (_data_->container_id);
			_g_object_unref0 (_data_->child);
		}
		_g_object_unref0 (_data_->_child_list);
	}
	_data_->result = _data_->children;
	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 gint
rygel_media_export_leaf_query_container_real_count_children (RygelMediaExportDBContainer* base)
{
	RygelMediaExportLeafQueryContainer * self;
	gint result = 0;
	gint _tmp6_ = -1;
	GError * _inner_error_ = NULL;
	self = (RygelMediaExportLeafQueryContainer*) base;
	{
		glong _tmp0_ = 0L;
		RygelMediaExportMediaCache* _tmp1_;
		RygelSearchExpression* _tmp2_;
		RygelSearchExpression* _tmp3_;
		_tmp1_ = ((RygelMediaExportDBContainer*) self)->media_db;
		_tmp2_ = rygel_media_export_query_container_get_expression ((RygelMediaExportQueryContainer*) self);
		_tmp3_ = _tmp2_;
		_tmp0_ = rygel_media_export_media_cache_get_object_count_by_search_expression (_tmp1_, _tmp3_, NULL, &_inner_error_);
		if (G_UNLIKELY (_inner_error_ != NULL)) {
			goto __catch49_g_error;
		}
		result = (gint) _tmp0_;
		return result;
	}
	goto __finally49;
	__catch49_g_error:
	{
		GError* _error_ = NULL;
		GError* _tmp4_;
		const gchar* _tmp5_;
		_error_ = _inner_error_;
		_inner_error_ = NULL;
		_tmp4_ = _error_;
		_tmp5_ = _tmp4_->message;
		g_warning (_ ("Failed to get child count of query container: %s"), _tmp5_);
		result = 0;
		_g_error_free0 (_error_);
		return result;
	}
	__finally49:
	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 _tmp6_;
}


static void
rygel_media_export_leaf_query_container_class_init (RygelMediaExportLeafQueryContainerClass * klass)
{
	rygel_media_export_leaf_query_container_parent_class = g_type_class_peek_parent (klass);
	((RygelMediaContainerClass *) klass)->get_children = (void (*) (RygelMediaContainer *, guint, guint, const gchar*, GCancellable*, GAsyncReadyCallback, gpointer)) rygel_media_export_leaf_query_container_real_get_children;
	((RygelMediaContainerClass *) klass)->get_children_finish = (RygelMediaObjects* (*) (RygelMediaContainer *, GAsyncResult*, GError**)) rygel_media_export_leaf_query_container_real_get_children_finish;
	((RygelMediaExportDBContainerClass *) klass)->count_children = (gint (*) (RygelMediaExportDBContainer *)) rygel_media_export_leaf_query_container_real_count_children;
}


static void
rygel_media_export_leaf_query_container_instance_init (RygelMediaExportLeafQueryContainer * self)
{
}


GType
rygel_media_export_leaf_query_container_get_type (void)
{
	static volatile gsize rygel_media_export_leaf_query_container_type_id__volatile = 0;
	if (g_once_init_enter (&rygel_media_export_leaf_query_container_type_id__volatile)) {
		static const GTypeInfo g_define_type_info = { sizeof (RygelMediaExportLeafQueryContainerClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) rygel_media_export_leaf_query_container_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (RygelMediaExportLeafQueryContainer), 0, (GInstanceInitFunc) rygel_media_export_leaf_query_container_instance_init, NULL };
		GType rygel_media_export_leaf_query_container_type_id;
		rygel_media_export_leaf_query_container_type_id = g_type_register_static (RYGEL_MEDIA_EXPORT_TYPE_QUERY_CONTAINER, "RygelMediaExportLeafQueryContainer", &g_define_type_info, 0);
		g_once_init_leave (&rygel_media_export_leaf_query_container_type_id__volatile, rygel_media_export_leaf_query_container_type_id);
	}
	return rygel_media_export_leaf_query_container_type_id__volatile;
}



