/* rygel-media-export-query-container-factory.c generated by valac 0.15.1.36-84b2b, the Vala compiler
 * generated from rygel-media-export-query-container-factory.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 <gee.h>
#include <stdlib.h>
#include <string.h>
#include <rygel.h>
#include <libgupnp-av/gupnp-av.h>


#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 _RygelMediaExportQueryContainerFactoryPrivate RygelMediaExportQueryContainerFactoryPrivate;
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_free0(var) (var = (g_free (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)))

#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_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;

#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;

#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;
#define _rygel_search_expression_unref0(var) ((var == NULL) ? NULL : (var = (rygel_search_expression_unref (var), NULL)))

#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;

struct _RygelMediaExportQueryContainerFactory {
	GObject parent_instance;
	RygelMediaExportQueryContainerFactoryPrivate * priv;
};

struct _RygelMediaExportQueryContainerFactoryClass {
	GObjectClass parent_class;
};

struct _RygelMediaExportQueryContainerFactoryPrivate {
	GeeHashMap* virtual_container_map;
};


static gpointer rygel_media_export_query_container_factory_parent_class = NULL;
static RygelMediaExportQueryContainerFactory* rygel_media_export_query_container_factory_instance;
static RygelMediaExportQueryContainerFactory* rygel_media_export_query_container_factory_instance = NULL;

GType rygel_media_export_query_container_factory_get_type (void) G_GNUC_CONST;
#define RYGEL_MEDIA_EXPORT_QUERY_CONTAINER_FACTORY_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), RYGEL_MEDIA_EXPORT_TYPE_QUERY_CONTAINER_FACTORY, RygelMediaExportQueryContainerFactoryPrivate))
enum  {
	RYGEL_MEDIA_EXPORT_QUERY_CONTAINER_FACTORY_DUMMY_PROPERTY
};
RygelMediaExportQueryContainerFactory* rygel_media_export_query_container_factory_get_default (void);
static RygelMediaExportQueryContainerFactory* rygel_media_export_query_container_factory_new (void);
static RygelMediaExportQueryContainerFactory* rygel_media_export_query_container_factory_construct (GType object_type);
void rygel_media_export_query_container_factory_register_id (RygelMediaExportQueryContainerFactory* self, gchar** id);
#define RYGEL_MEDIA_EXPORT_QUERY_CONTAINER_PREFIX "virtual-container:"
gchar* rygel_media_export_query_container_factory_get_virtual_container_definition (RygelMediaExportQueryContainerFactory* self, const gchar* hash);
GType rygel_media_export_media_cache_get_type (void) G_GNUC_CONST;
GType rygel_media_export_db_container_get_type (void) G_GNUC_CONST;
GType rygel_media_export_query_container_get_type (void) G_GNUC_CONST;
RygelMediaExportQueryContainer* rygel_media_export_query_container_factory_create_from_id (RygelMediaExportQueryContainerFactory* self, RygelMediaExportMediaCache* cache, const gchar* id, const gchar* name);
RygelMediaExportQueryContainer* rygel_media_export_query_container_factory_create_from_description (RygelMediaExportQueryContainerFactory* self, RygelMediaExportMediaCache* cache, const gchar* definition, const gchar* name);
static RygelSearchExpression* rygel_media_export_query_container_factory_parse_description (RygelMediaExportQueryContainerFactory* self, const gchar* description, gchar** pattern, gchar** attribute, gchar** name);
RygelMediaExportLeafQueryContainer* rygel_media_export_leaf_query_container_new (RygelMediaExportMediaCache* cache, RygelSearchExpression* expression, const gchar* id, const gchar* name);
RygelMediaExportLeafQueryContainer* rygel_media_export_leaf_query_container_construct (GType object_type, RygelMediaExportMediaCache* cache, RygelSearchExpression* expression, const gchar* id, const gchar* name);
GType rygel_media_export_leaf_query_container_get_type (void) G_GNUC_CONST;
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);
GType rygel_media_export_node_query_container_get_type (void) G_GNUC_CONST;
static void rygel_media_export_query_container_factory_update_search_expression (RygelMediaExportQueryContainerFactory* self, RygelSearchExpression** expression, const gchar* key, const gchar* value);
static void rygel_media_export_query_container_factory_finalize (GObject* obj);
static void _vala_array_destroy (gpointer array, gint array_length, GDestroyNotify destroy_func);
static void _vala_array_free (gpointer array, gint array_length, GDestroyNotify destroy_func);
static gint _vala_array_length (gpointer array);


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


RygelMediaExportQueryContainerFactory* rygel_media_export_query_container_factory_get_default (void) {
	RygelMediaExportQueryContainerFactory* result = NULL;
	RygelMediaExportQueryContainerFactory* _tmp0_;
	gboolean _tmp1_ = FALSE;
	RygelMediaExportQueryContainerFactory* _tmp3_;
	RygelMediaExportQueryContainerFactory* _tmp4_;
	_tmp0_ = rygel_media_export_query_container_factory_instance;
	_tmp1_ = G_UNLIKELY (_tmp0_ == NULL);
	if (_tmp1_) {
		RygelMediaExportQueryContainerFactory* _tmp2_;
		_tmp2_ = rygel_media_export_query_container_factory_new ();
		_g_object_unref0 (rygel_media_export_query_container_factory_instance);
		rygel_media_export_query_container_factory_instance = _tmp2_;
	}
	_tmp3_ = rygel_media_export_query_container_factory_instance;
	_tmp4_ = _g_object_ref0 (_tmp3_);
	result = _tmp4_;
	return result;
}


static RygelMediaExportQueryContainerFactory* rygel_media_export_query_container_factory_construct (GType object_type) {
	RygelMediaExportQueryContainerFactory * self = NULL;
	GeeHashMap* _tmp0_;
	self = (RygelMediaExportQueryContainerFactory*) g_object_new (object_type, NULL);
	_tmp0_ = gee_hash_map_new (G_TYPE_STRING, (GBoxedCopyFunc) g_strdup, g_free, G_TYPE_STRING, (GBoxedCopyFunc) g_strdup, g_free, NULL, NULL, NULL);
	_g_object_unref0 (self->priv->virtual_container_map);
	self->priv->virtual_container_map = _tmp0_;
	return self;
}


static RygelMediaExportQueryContainerFactory* rygel_media_export_query_container_factory_new (void) {
	return rygel_media_export_query_container_factory_construct (RYGEL_MEDIA_EXPORT_TYPE_QUERY_CONTAINER_FACTORY);
}


/**
     * Register a plaintext description for a query container. The passed
     * string will be modified to the checksum id of the container.
     *
     * @param id Originally contains the plaintext id which is replaced with
     *           the hashed id on return.
     */
void rygel_media_export_query_container_factory_register_id (RygelMediaExportQueryContainerFactory* self, gchar** id) {
	const gchar* _tmp0_;
	gchar* _tmp1_ = NULL;
	gchar* md5;
	GeeHashMap* _tmp2_;
	const gchar* _tmp3_;
	gboolean _tmp4_ = FALSE;
	const gchar* _tmp10_;
	gchar* _tmp11_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (*id != NULL);
	_tmp0_ = *id;
	_tmp1_ = g_compute_checksum_for_string (G_CHECKSUM_MD5, _tmp0_, (gsize) (-1));
	md5 = _tmp1_;
	_tmp2_ = self->priv->virtual_container_map;
	_tmp3_ = md5;
	_tmp4_ = gee_abstract_map_has_key ((GeeAbstractMap*) _tmp2_, _tmp3_);
	if (!_tmp4_) {
		GeeHashMap* _tmp5_;
		const gchar* _tmp6_;
		const gchar* _tmp7_;
		const gchar* _tmp8_;
		const gchar* _tmp9_;
		_tmp5_ = self->priv->virtual_container_map;
		_tmp6_ = md5;
		_tmp7_ = *id;
		gee_abstract_map_set ((GeeAbstractMap*) _tmp5_, _tmp6_, _tmp7_);
		_tmp8_ = md5;
		_tmp9_ = *id;
		g_debug ("rygel-media-export-query-container-factory.vala:58: Registering %s for" \
" %s", _tmp8_, _tmp9_);
	}
	_tmp10_ = md5;
	_tmp11_ = g_strconcat (RYGEL_MEDIA_EXPORT_QUERY_CONTAINER_PREFIX, _tmp10_, NULL);
	_g_free0 (*id);
	*id = _tmp11_;
	_g_free0 (md5);
}


/**
     * Get the plaintext definition from a hashed id.
     *
     * Inverse function of register_id().
     *
     * @param hash A hashed id
     * @return the plaintext defintion of the virtual folder
     */
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 __catch38_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 __catch38_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 __finally38;
	__catch38_g_regex_error:
	{
		GError* e = NULL;
		e = _inner_error_;
		_inner_error_ = NULL;
		g_assert_not_reached ();
		_g_error_free0 (e);
	}
	__finally38:
	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;
	}
}


gchar* rygel_media_export_query_container_factory_get_virtual_container_definition (RygelMediaExportQueryContainerFactory* self, const gchar* hash) {
	gchar* result = NULL;
	const gchar* _tmp0_;
	gchar* _tmp1_ = NULL;
	gchar* id;
	GeeHashMap* _tmp2_;
	gpointer _tmp3_ = NULL;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (hash != NULL, NULL);
	_tmp0_ = hash;
	_tmp1_ = string_replace (_tmp0_, RYGEL_MEDIA_EXPORT_QUERY_CONTAINER_PREFIX, "");
	id = _tmp1_;
	_tmp2_ = self->priv->virtual_container_map;
	_tmp3_ = gee_abstract_map_get ((GeeAbstractMap*) _tmp2_, id);
	result = (gchar*) _tmp3_;
	_g_free0 (id);
	return result;
}


/**
     * Factory method.
     *
     * Create a QueryContainer directly from MD5 hashed id.
     *
     * @param cache An instance of the meta-data cache
     * @param id    The hashed id of the container
     * @param name  An the title of the container. If not supplied, it will
     *              be derived from the plain-text description of the
     *              container
     * @return A new instance of QueryContainer
     */
RygelMediaExportQueryContainer* rygel_media_export_query_container_factory_create_from_id (RygelMediaExportQueryContainerFactory* self, RygelMediaExportMediaCache* cache, const gchar* id, const gchar* name) {
	RygelMediaExportQueryContainer* result = NULL;
	const gchar* _tmp0_;
	gchar* _tmp1_ = NULL;
	gchar* definition;
	RygelMediaExportMediaCache* _tmp2_;
	const gchar* _tmp3_;
	RygelMediaExportQueryContainer* _tmp4_ = NULL;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (cache != NULL, NULL);
	g_return_val_if_fail (id != NULL, NULL);
	g_return_val_if_fail (name != NULL, NULL);
	_tmp0_ = id;
	_tmp1_ = rygel_media_export_query_container_factory_get_virtual_container_definition (self, _tmp0_);
	definition = _tmp1_;
	_tmp2_ = cache;
	_tmp3_ = name;
	_tmp4_ = rygel_media_export_query_container_factory_create_from_description (self, _tmp2_, definition, _tmp3_);
	result = _tmp4_;
	_g_free0 (definition);
	return result;
}


/**
     * Factory method.
     *
     * Create a QueryContainer from a plain-text description string.
     *
     * @param cache      An instance of the meta-data cache
     * @param definition Plain-text defintion of the query-container
     * @param name       The title of the container. If not supplied, it
     *                   will be derived from the plain-text description of
     *                   the container
     * @return A new instance of QueryContainer
     */
RygelMediaExportQueryContainer* rygel_media_export_query_container_factory_create_from_description (RygelMediaExportQueryContainerFactory* self, RygelMediaExportMediaCache* cache, const gchar* definition, const gchar* name) {
	RygelMediaExportQueryContainer* result = NULL;
	const gchar* _tmp0_;
	gchar* _tmp1_;
	gchar* title;
	gchar* attribute;
	gchar* pattern;
	const gchar* _tmp2_;
	gchar* _tmp3_;
	gchar* id;
	const gchar* _tmp4_;
	gchar* _tmp5_ = NULL;
	gchar* _tmp6_ = NULL;
	RygelSearchExpression* _tmp7_ = NULL;
	RygelSearchExpression* expression;
	gboolean _tmp8_ = FALSE;
	const gchar* _tmp9_;
	gboolean _tmp11_;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (cache != NULL, NULL);
	g_return_val_if_fail (definition != NULL, NULL);
	g_return_val_if_fail (name != NULL, NULL);
	_tmp0_ = name;
	_tmp1_ = g_strdup (_tmp0_);
	title = _tmp1_;
	attribute = NULL;
	pattern = NULL;
	_tmp2_ = definition;
	_tmp3_ = g_strdup (_tmp2_);
	id = _tmp3_;
	rygel_media_export_query_container_factory_register_id (self, &id);
	_tmp4_ = definition;
	_tmp7_ = rygel_media_export_query_container_factory_parse_description (self, _tmp4_, &_tmp5_, &_tmp6_, &title);
	_g_free0 (pattern);
	pattern = _tmp5_;
	_g_free0 (attribute);
	attribute = _tmp6_;
	expression = _tmp7_;
	_tmp9_ = pattern;
	if (_tmp9_ == NULL) {
		_tmp8_ = TRUE;
	} else {
		const gchar* _tmp10_;
		_tmp10_ = pattern;
		_tmp8_ = g_strcmp0 (_tmp10_, "") == 0;
	}
	_tmp11_ = _tmp8_;
	if (_tmp11_) {
		RygelMediaExportMediaCache* _tmp12_;
		RygelSearchExpression* _tmp13_;
		const gchar* _tmp14_;
		const gchar* _tmp15_;
		RygelMediaExportLeafQueryContainer* _tmp16_;
		RygelMediaExportLeafQueryContainer* container;
		const gchar* _tmp17_;
		const gchar* _tmp18_;
		GQuark _tmp20_ = 0U;
		static GQuark _tmp19_label0 = 0;
		static GQuark _tmp19_label1 = 0;
		static GQuark _tmp19_label2 = 0;
		static GQuark _tmp19_label3 = 0;
		_tmp12_ = cache;
		_tmp13_ = expression;
		_tmp14_ = id;
		_tmp15_ = title;
		_tmp16_ = rygel_media_export_leaf_query_container_new (_tmp12_, _tmp13_, _tmp14_, _tmp15_);
		container = _tmp16_;
		_tmp17_ = attribute;
		_tmp18_ = _tmp17_;
		_tmp20_ = (NULL == _tmp18_) ? 0 : g_quark_from_string (_tmp18_);
		if (_tmp20_ == ((0 != _tmp19_label0) ? _tmp19_label0 : (_tmp19_label0 = g_quark_from_static_string ("upnp:album")))) {
			switch (0) {
				default:
				{
					RygelMediaExportLeafQueryContainer* _tmp21_;
					gchar* _tmp22_;
					_tmp21_ = container;
					_tmp22_ = g_strdup (RYGEL_MEDIA_CONTAINER_MUSIC_ALBUM);
					_g_free0 (((RygelMediaObject*) _tmp21_)->upnp_class);
					((RygelMediaObject*) _tmp21_)->upnp_class = _tmp22_;
					break;
				}
			}
		} else if ((_tmp20_ == ((0 != _tmp19_label1) ? _tmp19_label1 : (_tmp19_label1 = g_quark_from_static_string ("dc:creator")))) || (_tmp20_ == ((0 != _tmp19_label2) ? _tmp19_label2 : (_tmp19_label2 = g_quark_from_static_string ("upnp:artist"))))) {
			switch (0) {
				default:
				{
					RygelMediaExportLeafQueryContainer* _tmp23_;
					gchar* _tmp24_;
					_tmp23_ = container;
					_tmp24_ = g_strdup (RYGEL_MEDIA_CONTAINER_MUSIC_ARTIST);
					_g_free0 (((RygelMediaObject*) _tmp23_)->upnp_class);
					((RygelMediaObject*) _tmp23_)->upnp_class = _tmp24_;
					break;
				}
			}
		} else if (_tmp20_ == ((0 != _tmp19_label3) ? _tmp19_label3 : (_tmp19_label3 = g_quark_from_static_string ("upnp:genre")))) {
			switch (0) {
				default:
				{
					RygelMediaExportLeafQueryContainer* _tmp25_;
					gchar* _tmp26_;
					_tmp25_ = container;
					_tmp26_ = g_strdup (RYGEL_MEDIA_CONTAINER_MUSIC_GENRE);
					_g_free0 (((RygelMediaObject*) _tmp25_)->upnp_class);
					((RygelMediaObject*) _tmp25_)->upnp_class = _tmp26_;
					break;
				}
			}
		} else {
			switch (0) {
				default:
				{
					break;
				}
			}
		}
		result = (RygelMediaExportQueryContainer*) container;
		_rygel_search_expression_unref0 (expression);
		_g_free0 (id);
		_g_free0 (pattern);
		_g_free0 (attribute);
		_g_free0 (title);
		return result;
	} else {
		RygelMediaExportMediaCache* _tmp27_;
		RygelSearchExpression* _tmp28_;
		const gchar* _tmp29_;
		const gchar* _tmp30_;
		const gchar* _tmp31_;
		const gchar* _tmp32_;
		RygelMediaExportNodeQueryContainer* _tmp33_;
		_tmp27_ = cache;
		_tmp28_ = expression;
		_tmp29_ = id;
		_tmp30_ = title;
		_tmp31_ = pattern;
		_tmp32_ = attribute;
		_tmp33_ = rygel_media_export_node_query_container_new (_tmp27_, _tmp28_, _tmp29_, _tmp30_, _tmp31_, _tmp32_);
		result = (RygelMediaExportQueryContainer*) _tmp33_;
		_rygel_search_expression_unref0 (expression);
		_g_free0 (id);
		_g_free0 (pattern);
		_g_free0 (attribute);
		_g_free0 (title);
		return result;
	}
	_rygel_search_expression_unref0 (expression);
	_g_free0 (id);
	_g_free0 (pattern);
	_g_free0 (attribute);
	_g_free0 (title);
}


/**
     * Parse a plaintext container description into a search expression.
     *
     * Also generates a name for the container and other meta-data necessary
     * for node containers.
     *
     * @param description The plaintext container description
     * @param pattern     Contains the pattern used for child containers if
     *                    descrption is for a node container, null otherwise.
     * @param attribute   Contains the UPnP attribute the container describes
     *                    if description is for a node container, null
     *                    otherwise.
     * @param name        If passed empty, name will be generated from the
     *                    description.
     * @return A SearchExpression corresponding to the non-variable part of
     *         the description.
     */
static gpointer _rygel_search_expression_ref0 (gpointer self) {
	return self ? rygel_search_expression_ref (self) : NULL;
}


static RygelSearchExpression* rygel_media_export_query_container_factory_parse_description (RygelMediaExportQueryContainerFactory* self, const gchar* description, gchar** pattern, gchar** attribute, gchar** name) {
	gchar* _vala_pattern = NULL;
	gchar* _vala_attribute = NULL;
	RygelSearchExpression* result = NULL;
	const gchar* _tmp0_;
	gchar** _tmp1_;
	gchar** _tmp2_ = NULL;
	gchar** args;
	gint args_length1;
	gint _args_size_;
	RygelSearchExpression* _tmp3_;
	RygelSearchExpression* expression;
	gint i;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (description != NULL, NULL);
	g_return_val_if_fail (*name != NULL, NULL);
	_tmp0_ = description;
	_tmp2_ = _tmp1_ = g_strsplit (_tmp0_, ",", 0);
	args = _tmp2_;
	args_length1 = _vala_array_length (_tmp1_);
	_args_size_ = args_length1;
	_tmp3_ = _rygel_search_expression_ref0 (RYGEL_IS_SEARCH_EXPRESSION (NULL) ? ((RygelSearchExpression*) NULL) : NULL);
	expression = _tmp3_;
	_g_free0 (_vala_pattern);
	_vala_pattern = NULL;
	_g_free0 (_vala_attribute);
	_vala_attribute = NULL;
	i = 0;
	while (TRUE) {
		gint _tmp4_;
		gchar** _tmp5_;
		gint _tmp5__length1;
		gchar** _tmp6_;
		gint _tmp6__length1;
		gint _tmp7_;
		const gchar* _tmp8_;
		gint _tmp35_;
		_tmp4_ = i;
		_tmp5_ = args;
		_tmp5__length1 = args_length1;
		if (!(_tmp4_ < _tmp5__length1)) {
			break;
		}
		_tmp6_ = args;
		_tmp6__length1 = args_length1;
		_tmp7_ = i;
		_tmp8_ = _tmp6_[_tmp7_ + 1];
		if (g_strcmp0 (_tmp8_, "?") != 0) {
			gchar** _tmp9_;
			gint _tmp9__length1;
			gint _tmp10_;
			const gchar* _tmp11_;
			gchar** _tmp12_;
			gint _tmp12__length1;
			gint _tmp13_;
			const gchar* _tmp14_;
			_tmp9_ = args;
			_tmp9__length1 = args_length1;
			_tmp10_ = i;
			_tmp11_ = _tmp9_[_tmp10_];
			_tmp12_ = args;
			_tmp12__length1 = args_length1;
			_tmp13_ = i;
			_tmp14_ = _tmp12_[_tmp13_ + 1];
			rygel_media_export_query_container_factory_update_search_expression (self, &expression, _tmp11_, _tmp14_);
		} else {
			gchar** _tmp15_;
			gint _tmp15__length1;
			gint _tmp16_;
			gchar* _tmp17_;
			gchar* _tmp18_;
			gchar** _tmp19_;
			gint _tmp19__length1;
			gint _tmp20_;
			const gchar* _tmp21_;
			gchar* _tmp22_ = NULL;
			const gchar* _tmp23_;
			gchar* _tmp24_ = NULL;
			gchar** _tmp25_;
			gint _tmp25__length1;
			gchar* _tmp26_ = NULL;
			gboolean _tmp27_ = FALSE;
			const gchar* _tmp28_;
			gboolean _tmp30_;
			_tmp15_ = args;
			_tmp15__length1 = args_length1;
			_tmp16_ = i;
			_tmp17_ = g_strdup ("%s");
			_g_free0 (_tmp15_[_tmp16_ + 1]);
			_tmp15_[_tmp16_ + 1] = _tmp17_;
			_tmp18_ = _tmp15_[_tmp16_ + 1];
			_tmp19_ = args;
			_tmp19__length1 = args_length1;
			_tmp20_ = i;
			_tmp21_ = _tmp19_[_tmp20_];
			_tmp22_ = string_replace (_tmp21_, RYGEL_MEDIA_EXPORT_QUERY_CONTAINER_PREFIX, "");
			_g_free0 (_vala_attribute);
			_vala_attribute = _tmp22_;
			_tmp23_ = _vala_attribute;
			_tmp24_ = g_uri_unescape_string (_tmp23_, NULL);
			_g_free0 (_vala_attribute);
			_vala_attribute = _tmp24_;
			_tmp25_ = args;
			_tmp25__length1 = args_length1;
			_tmp26_ = g_strjoinv (",", _tmp25_);
			_g_free0 (_vala_pattern);
			_vala_pattern = _tmp26_;
			_tmp28_ = *name;
			if (g_strcmp0 (_tmp28_, "") == 0) {
				gint _tmp29_;
				_tmp29_ = i;
				_tmp27_ = _tmp29_ > 0;
			} else {
				_tmp27_ = FALSE;
			}
			_tmp30_ = _tmp27_;
			if (_tmp30_) {
				gchar** _tmp31_;
				gint _tmp31__length1;
				gint _tmp32_;
				const gchar* _tmp33_;
				gchar* _tmp34_ = NULL;
				_tmp31_ = args;
				_tmp31__length1 = args_length1;
				_tmp32_ = i;
				_tmp33_ = _tmp31_[_tmp32_ - 1];
				_tmp34_ = g_uri_unescape_string (_tmp33_, NULL);
				_g_free0 (*name);
				*name = _tmp34_;
			}
			break;
		}
		_tmp35_ = i;
		i = _tmp35_ + 2;
	}
	result = expression;
	args = (_vala_array_free (args, args_length1, (GDestroyNotify) g_free), NULL);
	if (pattern) {
		*pattern = _vala_pattern;
	} else {
		_g_free0 (_vala_pattern);
	}
	if (attribute) {
		*attribute = _vala_attribute;
	} else {
		_g_free0 (_vala_attribute);
	}
	return result;
}


/**
     * Update a SearchExpression with a new key = value condition.
     *
     * Will modifiy the passed expression to (expression AND (key = value))
     *
     * @param expression The expression to update or null to create a new one
     * @param key        Key of the key/value condition
     * @param value      Value of the key/value condition
     */
static void rygel_media_export_query_container_factory_update_search_expression (RygelMediaExportQueryContainerFactory* self, RygelSearchExpression** expression, const gchar* key, const gchar* value) {
	RygelRelationalExpression* _tmp0_;
	RygelRelationalExpression* subexpression;
	const gchar* _tmp1_;
	gchar* _tmp2_ = NULL;
	gchar* clean_key;
	RygelRelationalExpression* _tmp3_;
	const gchar* _tmp4_;
	gchar* _tmp5_ = NULL;
	RygelRelationalExpression* _tmp6_;
	RygelRelationalExpression* _tmp7_;
	const gchar* _tmp8_;
	gchar* _tmp9_ = NULL;
	RygelSearchExpression* _tmp10_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (key != NULL);
	g_return_if_fail (value != NULL);
	_tmp0_ = rygel_relational_expression_new ();
	subexpression = _tmp0_;
	_tmp1_ = key;
	_tmp2_ = string_replace (_tmp1_, RYGEL_MEDIA_EXPORT_QUERY_CONTAINER_PREFIX, "");
	clean_key = _tmp2_;
	_tmp3_ = subexpression;
	_tmp4_ = clean_key;
	_tmp5_ = g_uri_unescape_string (_tmp4_, NULL);
	_g_free0 (((RygelSearchExpression*) _tmp3_)->operand1);
	((RygelSearchExpression*) _tmp3_)->operand1 = _tmp5_;
	_tmp6_ = subexpression;
	((RygelSearchExpression*) _tmp6_)->op = GINT_TO_POINTER (GUPNP_SEARCH_CRITERIA_OP_EQ);
	_tmp7_ = subexpression;
	_tmp8_ = value;
	_tmp9_ = g_uri_unescape_string (_tmp8_, NULL);
	_g_free0 (((RygelSearchExpression*) _tmp7_)->operand2);
	((RygelSearchExpression*) _tmp7_)->operand2 = _tmp9_;
	_tmp10_ = *expression;
	if (_tmp10_ != NULL) {
		RygelLogicalExpression* _tmp11_;
		RygelLogicalExpression* conjunction;
		RygelLogicalExpression* _tmp12_;
		RygelSearchExpression* _tmp13_;
		RygelSearchExpression* _tmp14_;
		RygelLogicalExpression* _tmp15_;
		RygelRelationalExpression* _tmp16_;
		RygelSearchExpression* _tmp17_;
		RygelLogicalExpression* _tmp18_;
		RygelLogicalExpression* _tmp19_;
		RygelSearchExpression* _tmp20_;
		_tmp11_ = rygel_logical_expression_new ();
		conjunction = _tmp11_;
		_tmp12_ = conjunction;
		_tmp13_ = *expression;
		_tmp14_ = _rygel_search_expression_ref0 (_tmp13_);
		_rygel_search_expression_unref0 (((RygelSearchExpression*) _tmp12_)->operand1);
		((RygelSearchExpression*) _tmp12_)->operand1 = _tmp14_;
		_tmp15_ = conjunction;
		_tmp16_ = subexpression;
		_tmp17_ = _rygel_search_expression_ref0 ((RygelSearchExpression*) _tmp16_);
		_rygel_search_expression_unref0 (((RygelSearchExpression*) _tmp15_)->operand2);
		((RygelSearchExpression*) _tmp15_)->operand2 = _tmp17_;
		_tmp18_ = conjunction;
		((RygelSearchExpression*) _tmp18_)->op = GINT_TO_POINTER (RYGEL_LOGICAL_OPERATOR_AND);
		_tmp19_ = conjunction;
		_tmp20_ = _rygel_search_expression_ref0 ((RygelSearchExpression*) _tmp19_);
		_rygel_search_expression_unref0 (*expression);
		*expression = _tmp20_;
		_rygel_search_expression_unref0 (conjunction);
	} else {
		RygelRelationalExpression* _tmp21_;
		RygelSearchExpression* _tmp22_;
		_tmp21_ = subexpression;
		_tmp22_ = _rygel_search_expression_ref0 ((RygelSearchExpression*) _tmp21_);
		_rygel_search_expression_unref0 (*expression);
		*expression = _tmp22_;
	}
	_g_free0 (clean_key);
	_rygel_search_expression_unref0 (subexpression);
}


static void rygel_media_export_query_container_factory_class_init (RygelMediaExportQueryContainerFactoryClass * klass) {
	rygel_media_export_query_container_factory_parent_class = g_type_class_peek_parent (klass);
	g_type_class_add_private (klass, sizeof (RygelMediaExportQueryContainerFactoryPrivate));
	G_OBJECT_CLASS (klass)->finalize = rygel_media_export_query_container_factory_finalize;
}


static void rygel_media_export_query_container_factory_instance_init (RygelMediaExportQueryContainerFactory * self) {
	self->priv = RYGEL_MEDIA_EXPORT_QUERY_CONTAINER_FACTORY_GET_PRIVATE (self);
}


static void rygel_media_export_query_container_factory_finalize (GObject* obj) {
	RygelMediaExportQueryContainerFactory * self;
	self = RYGEL_MEDIA_EXPORT_QUERY_CONTAINER_FACTORY (obj);
	_g_object_unref0 (self->priv->virtual_container_map);
	G_OBJECT_CLASS (rygel_media_export_query_container_factory_parent_class)->finalize (obj);
}


GType rygel_media_export_query_container_factory_get_type (void) {
	static volatile gsize rygel_media_export_query_container_factory_type_id__volatile = 0;
	if (g_once_init_enter (&rygel_media_export_query_container_factory_type_id__volatile)) {
		static const GTypeInfo g_define_type_info = { sizeof (RygelMediaExportQueryContainerFactoryClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) rygel_media_export_query_container_factory_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (RygelMediaExportQueryContainerFactory), 0, (GInstanceInitFunc) rygel_media_export_query_container_factory_instance_init, NULL };
		GType rygel_media_export_query_container_factory_type_id;
		rygel_media_export_query_container_factory_type_id = g_type_register_static (G_TYPE_OBJECT, "RygelMediaExportQueryContainerFactory", &g_define_type_info, 0);
		g_once_init_leave (&rygel_media_export_query_container_factory_type_id__volatile, rygel_media_export_query_container_factory_type_id);
	}
	return rygel_media_export_query_container_factory_type_id__volatile;
}


static void _vala_array_destroy (gpointer array, gint array_length, GDestroyNotify destroy_func) {
	if ((array != NULL) && (destroy_func != NULL)) {
		int i;
		for (i = 0; i < array_length; i = i + 1) {
			if (((gpointer*) array)[i] != NULL) {
				destroy_func (((gpointer*) array)[i]);
			}
		}
	}
}


static void _vala_array_free (gpointer array, gint array_length, GDestroyNotify destroy_func) {
	_vala_array_destroy (array, array_length, destroy_func);
	g_free (array);
}


static gint _vala_array_length (gpointer array) {
	int length;
	length = 0;
	if (array) {
		while (((gpointer*) array)[length]) {
			length++;
		}
	}
	return length;
}



