/* rygel-media-export-query-container-factory.c generated by valac 0.56.19, 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.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-object.h>
#include <gee.h>
#include <stdlib.h>
#include <string.h>
#include <glib.h>
#include "rygel-media-export.h"
#include "rygel-server.h"
#include <libgupnp-av/gupnp-av.h>

#define RYGEL_MEDIA_EXPORT_QUERY_CONTAINER_PREFIX "virtual-container:"
#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 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;
enum  {
	RYGEL_MEDIA_EXPORT_QUERY_CONTAINER_FACTORY_0_PROPERTY,
	RYGEL_MEDIA_EXPORT_QUERY_CONTAINER_FACTORY_NUM_PROPERTIES
};
static GParamSpec* rygel_media_export_query_container_factory_properties[RYGEL_MEDIA_EXPORT_QUERY_CONTAINER_FACTORY_NUM_PROPERTIES];
#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 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_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;
#define _rygel_search_expression_unref0(var) ((var == NULL) ? NULL : (var = (rygel_search_expression_unref (var), NULL)))

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

struct _RygelMediaExportQueryContainerFactoryClass {
	GObjectClass parent_class;
};

struct _RygelMediaExportQueryContainerFactoryPrivate {
	GeeHashMap* virtual_container_map;
};

static gint RygelMediaExportQueryContainerFactory_private_offset;
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;

VALA_EXTERN GType rygel_media_export_query_container_factory_get_type (void) G_GNUC_CONST ;
VALA_EXTERN 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);
VALA_EXTERN void rygel_media_export_query_container_factory_register_id (RygelMediaExportQueryContainerFactory* self,
                                                             gchar** id);
VALA_EXTERN gchar* rygel_media_export_query_container_factory_get_virtual_container_definition (RygelMediaExportQueryContainerFactory* self,
                                                                                    const gchar* hash);
VALA_EXTERN GType rygel_media_export_query_container_get_type (void) G_GNUC_CONST ;
VALA_EXTERN RygelMediaExportQueryContainer* rygel_media_export_query_container_factory_create_from_hashed_id (RygelMediaExportQueryContainerFactory* self,
                                                                                                  const gchar* id,
                                                                                                  const gchar* name);
VALA_EXTERN RygelMediaExportQueryContainer* rygel_media_export_query_container_factory_create_from_description_id (RygelMediaExportQueryContainerFactory* self,
                                                                                                       const gchar* definition_id,
                                                                                                       const gchar* name);
static RygelSearchExpression* rygel_media_export_query_container_factory_parse_description (const gchar* description,
                                                                                     gchar** pattern,
                                                                                     gchar** attribute,
                                                                                     gchar** upnp_class,
                                                                                     gchar** name);
VALA_EXTERN RygelMediaExportLeafQueryContainer* rygel_media_export_leaf_query_container_new (RygelSearchExpression* expression,
                                                                                 const gchar* id,
                                                                                 const gchar* name);
VALA_EXTERN RygelMediaExportLeafQueryContainer* rygel_media_export_leaf_query_container_construct (GType object_type,
                                                                                       RygelSearchExpression* expression,
                                                                                       const gchar* id,
                                                                                       const gchar* name);
VALA_EXTERN GType rygel_media_export_leaf_query_container_get_type (void) G_GNUC_CONST ;
VALA_EXTERN RygelMediaExportNodeQueryContainer* rygel_media_export_node_query_container_new (RygelSearchExpression* expression,
                                                                                 const gchar* id,
                                                                                 const gchar* name,
                                                                                 const gchar* template,
                                                                                 const gchar* attribute);
VALA_EXTERN RygelMediaExportNodeQueryContainer* rygel_media_export_node_query_container_construct (GType object_type,
                                                                                       RygelSearchExpression* expression,
                                                                                       const gchar* id,
                                                                                       const gchar* name,
                                                                                       const gchar* template,
                                                                                       const gchar* attribute);
VALA_EXTERN GType rygel_media_export_node_query_container_get_type (void) G_GNUC_CONST ;
static gchar* rygel_media_export_query_container_factory_map_upnp_class (const gchar* attribute);
static void rygel_media_export_query_container_factory_update_search_expression (RygelSearchExpression** expression,
                                                                          const gchar* key,
                                                                          const gchar* value);
static void rygel_media_export_query_container_factory_finalize (GObject * obj);
static GType rygel_media_export_query_container_factory_get_type_once (void);
static void _vala_array_destroy (gpointer array,
                          gssize array_length,
                          GDestroyNotify destroy_func);
static void _vala_array_free (gpointer array,
                       gssize array_length,
                       GDestroyNotify destroy_func);
static gssize _vala_array_length (gpointer array);

static inline gpointer
rygel_media_export_query_container_factory_get_instance_private (RygelMediaExportQueryContainerFactory* self)
{
	return G_STRUCT_MEMBER_P (self, RygelMediaExportQueryContainerFactory_private_offset);
}

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* _tmp0_;
	RygelMediaExportQueryContainerFactory* _tmp2_;
	RygelMediaExportQueryContainerFactory* _tmp3_;
	RygelMediaExportQueryContainerFactory* result;
	_tmp0_ = rygel_media_export_query_container_factory_instance;
	if (G_UNLIKELY (_tmp0_ == NULL)) {
		RygelMediaExportQueryContainerFactory* _tmp1_;
		_tmp1_ = rygel_media_export_query_container_factory_new ();
		_g_object_unref0 (rygel_media_export_query_container_factory_instance);
		rygel_media_export_query_container_factory_instance = _tmp1_;
	}
	_tmp2_ = rygel_media_export_query_container_factory_instance;
	_tmp3_ = _g_object_ref0 (_tmp2_);
	result = _tmp3_;
	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, (GDestroyNotify) g_free, G_TYPE_STRING, (GBoxedCopyFunc) g_strdup, (GDestroyNotify) g_free, NULL, NULL, NULL, NULL, NULL, NULL, 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)
{
	gchar* md5 = NULL;
	gchar* _tmp0_;
	GeeHashMap* _tmp1_;
	const gchar* _tmp2_;
	const gchar* _tmp6_;
	gchar* _tmp7_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (*id != NULL);
	_tmp0_ = g_compute_checksum_for_string (G_CHECKSUM_MD5, *id, (gsize) -1);
	md5 = _tmp0_;
	_tmp1_ = self->priv->virtual_container_map;
	_tmp2_ = md5;
	if (!gee_abstract_map_has_key ((GeeAbstractMap*) _tmp1_, _tmp2_)) {
		GeeHashMap* _tmp3_;
		const gchar* _tmp4_;
		const gchar* _tmp5_;
		_tmp3_ = self->priv->virtual_container_map;
		_tmp4_ = md5;
		gee_abstract_map_set ((GeeAbstractMap*) _tmp3_, _tmp4_, *id);
		_tmp5_ = md5;
		g_debug ("rygel-media-export-query-container-factory.vala:61: Registering %s for" \
" %s", _tmp5_, *id);
	}
	_tmp6_ = md5;
	_tmp7_ = g_strconcat (RYGEL_MEDIA_EXPORT_QUERY_CONTAINER_PREFIX, _tmp6_, NULL);
	_g_free0 (*id);
	*id = _tmp7_;
	_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)
{
	gboolean _tmp0_ = FALSE;
	gboolean _tmp1_ = FALSE;
	GError* _inner_error0_ = NULL;
	gchar* result;
	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_error0_);
		_tmp6_ = _tmp5_;
		_g_free0 (_tmp4_);
		regex = _tmp6_;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			if (_inner_error0_->domain == G_REGEX_ERROR) {
				goto __catch0_g_regex_error;
			}
			g_critical ("file %s: line %d: unexpected error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
			g_clear_error (&_inner_error0_);
			return NULL;
		}
		_tmp8_ = regex;
		_tmp9_ = g_regex_replace_literal (_tmp8_, self, (gssize) -1, 0, replacement, 0, &_inner_error0_);
		_tmp7_ = _tmp9_;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			_g_regex_unref0 (regex);
			if (_inner_error0_->domain == G_REGEX_ERROR) {
				goto __catch0_g_regex_error;
			}
			g_critical ("file %s: line %d: unexpected error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
			g_clear_error (&_inner_error0_);
			return NULL;
		}
		_tmp10_ = _tmp7_;
		_tmp7_ = NULL;
		result = _tmp10_;
		_g_free0 (_tmp7_);
		_g_regex_unref0 (regex);
		return result;
	}
	goto __finally0;
	__catch0_g_regex_error:
	{
		g_clear_error (&_inner_error0_);
		g_assert_not_reached ();
	}
	__finally0:
	g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
	g_clear_error (&_inner_error0_);
	return NULL;
}

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

/**
     * Factory method.
     *
     * Create a QueryContainer directly from MD5 hashed id.
     *
     * @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 or null if id does not exist
     */
RygelMediaExportQueryContainer*
rygel_media_export_query_container_factory_create_from_hashed_id (RygelMediaExportQueryContainerFactory* self,
                                                                  const gchar* id,
                                                                  const gchar* name)
{
	gchar* definition_id = NULL;
	gchar* _tmp0_;
	const gchar* _tmp1_;
	const gchar* _tmp2_;
	RygelMediaExportQueryContainer* _tmp3_;
	RygelMediaExportQueryContainer* result;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (id != NULL, NULL);
	g_return_val_if_fail (name != NULL, NULL);
	_tmp0_ = rygel_media_export_query_container_factory_get_virtual_container_definition (self, id);
	definition_id = _tmp0_;
	_tmp1_ = definition_id;
	if (_tmp1_ == NULL) {
		result = NULL;
		_g_free0 (definition_id);
		return result;
	}
	_tmp2_ = definition_id;
	_tmp3_ = rygel_media_export_query_container_factory_create_from_description_id (self, _tmp2_, name);
	result = _tmp3_;
	_g_free0 (definition_id);
	return result;
}

/**
     * Factory method.
     *
     * Create a QueryContainer from a plain-text description string.
     *
     * @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_id (RygelMediaExportQueryContainerFactory* self,
                                                                       const gchar* definition_id,
                                                                       const gchar* name)
{
	gchar* title = NULL;
	gchar* _tmp0_;
	gchar* attribute = NULL;
	gchar* pattern = NULL;
	gchar* upnp_class = NULL;
	RygelMediaExportQueryContainer* container = NULL;
	gchar* id = NULL;
	gchar* _tmp1_;
	RygelSearchExpression* expression = NULL;
	gchar* _tmp2_ = NULL;
	gchar* _tmp3_ = NULL;
	gchar* _tmp4_ = NULL;
	RygelSearchExpression* _tmp5_;
	gboolean _tmp6_ = FALSE;
	const gchar* _tmp7_;
	const gchar* _tmp19_;
	RygelMediaExportQueryContainer* result;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (definition_id != NULL, NULL);
	g_return_val_if_fail (name != NULL, NULL);
	_tmp0_ = g_strdup (name);
	title = _tmp0_;
	attribute = NULL;
	pattern = NULL;
	upnp_class = NULL;
	_tmp1_ = g_strdup (definition_id);
	id = _tmp1_;
	rygel_media_export_query_container_factory_register_id (self, &id);
	_tmp5_ = rygel_media_export_query_container_factory_parse_description (definition_id, &_tmp2_, &_tmp3_, &_tmp4_, &title);
	_g_free0 (pattern);
	pattern = _tmp2_;
	_g_free0 (attribute);
	attribute = _tmp3_;
	_g_free0 (upnp_class);
	upnp_class = _tmp4_;
	expression = _tmp5_;
	_tmp7_ = pattern;
	if (_tmp7_ == NULL) {
		_tmp6_ = TRUE;
	} else {
		const gchar* _tmp8_;
		_tmp8_ = pattern;
		_tmp6_ = g_strcmp0 (_tmp8_, "") == 0;
	}
	if (_tmp6_) {
		RygelSearchExpression* _tmp9_;
		const gchar* _tmp10_;
		const gchar* _tmp11_;
		RygelMediaExportLeafQueryContainer* _tmp12_;
		_tmp9_ = expression;
		_tmp10_ = id;
		_tmp11_ = title;
		_tmp12_ = rygel_media_export_leaf_query_container_new (_tmp9_, _tmp10_, _tmp11_);
		_g_object_unref0 (container);
		container = (RygelMediaExportQueryContainer*) _tmp12_;
	} else {
		RygelSearchExpression* _tmp13_;
		const gchar* _tmp14_;
		const gchar* _tmp15_;
		const gchar* _tmp16_;
		const gchar* _tmp17_;
		RygelMediaExportNodeQueryContainer* _tmp18_;
		_tmp13_ = expression;
		_tmp14_ = id;
		_tmp15_ = title;
		_tmp16_ = pattern;
		_tmp17_ = attribute;
		_tmp18_ = rygel_media_export_node_query_container_new (_tmp13_, _tmp14_, _tmp15_, _tmp16_, _tmp17_);
		_g_object_unref0 (container);
		container = (RygelMediaExportQueryContainer*) _tmp18_;
	}
	_tmp19_ = upnp_class;
	if (_tmp19_ != NULL) {
		RygelMediaExportQueryContainer* _tmp20_;
		const gchar* _tmp21_;
		const gchar* _tmp22_;
		_tmp20_ = container;
		_tmp21_ = upnp_class;
		rygel_media_object_set_upnp_class ((RygelMediaObject*) _tmp20_, _tmp21_);
		_tmp22_ = upnp_class;
		if (g_strcmp0 (_tmp22_, RYGEL_MEDIA_CONTAINER_MUSIC_ALBUM) == 0) {
			RygelMediaExportQueryContainer* _tmp23_;
			_tmp23_ = container;
			rygel_media_container_set_sort_criteria ((RygelMediaContainer*) _tmp23_, RYGEL_MEDIA_CONTAINER_ALBUM_SORT_CRITERIA);
		}
	}
	result = container;
	_rygel_search_expression_unref0 (expression);
	_g_free0 (id);
	_g_free0 (upnp_class);
	_g_free0 (pattern);
	_g_free0 (attribute);
	_g_free0 (title);
	return result;
}

/**
     * Map a DIDL attribute to a UPnP container class.
     *
     * @return A matching UPnP class for the attribute or null if it can't be
     *         mapped.
     */
static gchar*
rygel_media_export_query_container_factory_map_upnp_class (const gchar* attribute)
{
	const gchar* _tmp0_;
	GQuark _tmp2_ = 0U;
	static GQuark _tmp1_label0 = 0;
	static GQuark _tmp1_label1 = 0;
	static GQuark _tmp1_label2 = 0;
	static GQuark _tmp1_label3 = 0;
	gchar* result;
	g_return_val_if_fail (attribute != NULL, NULL);
	_tmp0_ = attribute;
	_tmp2_ = (NULL == _tmp0_) ? 0 : g_quark_from_string (_tmp0_);
	if (_tmp2_ == ((0 != _tmp1_label0) ? _tmp1_label0 : (_tmp1_label0 = g_quark_from_static_string ("upnp:album")))) {
		switch (0) {
			default:
			{
				gchar* _tmp3_;
				_tmp3_ = g_strdup (RYGEL_MEDIA_CONTAINER_MUSIC_ALBUM);
				result = _tmp3_;
				return result;
			}
		}
	} else if ((_tmp2_ == ((0 != _tmp1_label1) ? _tmp1_label1 : (_tmp1_label1 = g_quark_from_static_string ("dc:creator")))) || (_tmp2_ == ((0 != _tmp1_label2) ? _tmp1_label2 : (_tmp1_label2 = g_quark_from_static_string ("upnp:artist"))))) {
		switch (0) {
			default:
			{
				gchar* _tmp4_;
				_tmp4_ = g_strdup (RYGEL_MEDIA_CONTAINER_MUSIC_ARTIST);
				result = _tmp4_;
				return result;
			}
		}
	} else if (_tmp2_ == ((0 != _tmp1_label3) ? _tmp1_label3 : (_tmp1_label3 = g_quark_from_static_string ("dc:genre")))) {
		switch (0) {
			default:
			{
				gchar* _tmp5_;
				_tmp5_ = g_strdup (RYGEL_MEDIA_CONTAINER_MUSIC_GENRE);
				result = _tmp5_;
				return result;
			}
		}
	} else {
		switch (0) {
			default:
			{
				result = NULL;
				return result;
			}
		}
	}
}

/**
     * 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.
     * @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 gchar*
_vala_g_strjoinv (const gchar* separator,
                  gchar** str_array,
                  gint str_array_length1)
{
	gboolean _tmp0_ = FALSE;
	gchar* result;
	if (separator == NULL) {
		separator = "";
	}
	if (str_array != NULL) {
		gboolean _tmp1_ = FALSE;
		if (str_array_length1 > 0) {
			_tmp1_ = TRUE;
		} else {
			gboolean _tmp2_ = FALSE;
			if (str_array_length1 == -1) {
				const gchar* _tmp3_;
				_tmp3_ = str_array[0];
				_tmp2_ = _tmp3_ != NULL;
			} else {
				_tmp2_ = FALSE;
			}
			_tmp1_ = _tmp2_;
		}
		_tmp0_ = _tmp1_;
	} else {
		_tmp0_ = FALSE;
	}
	if (_tmp0_) {
		gint i = 0;
		gsize len = 0UL;
		gint _tmp16_;
		gint _tmp17_;
		const gchar* res = NULL;
		void* _tmp18_;
		const gchar* _tmp19_ = NULL;
		const gchar* _tmp20_;
		void* ptr = NULL;
		const gchar* _tmp22_;
		void* _tmp23_;
		const gchar* _tmp33_;
		len = (gsize) 1;
		{
			gboolean _tmp4_ = FALSE;
			i = 0;
			_tmp4_ = TRUE;
			while (TRUE) {
				gboolean _tmp6_ = FALSE;
				gboolean _tmp7_ = FALSE;
				gint _tmp10_ = 0;
				const gchar* _tmp11_;
				if (!_tmp4_) {
					gint _tmp5_;
					_tmp5_ = i;
					i = _tmp5_ + 1;
				}
				_tmp4_ = FALSE;
				if (str_array_length1 != -1) {
					_tmp7_ = i < str_array_length1;
				} else {
					_tmp7_ = FALSE;
				}
				if (_tmp7_) {
					_tmp6_ = TRUE;
				} else {
					gboolean _tmp8_ = FALSE;
					if (str_array_length1 == -1) {
						const gchar* _tmp9_;
						_tmp9_ = str_array[i];
						_tmp8_ = _tmp9_ != NULL;
					} else {
						_tmp8_ = FALSE;
					}
					_tmp6_ = _tmp8_;
				}
				if (!_tmp6_) {
					break;
				}
				_tmp11_ = str_array[i];
				if (_tmp11_ != NULL) {
					const gchar* _tmp12_;
					gint _tmp13_;
					gint _tmp14_;
					_tmp12_ = str_array[i];
					_tmp13_ = strlen ((const gchar*) _tmp12_);
					_tmp14_ = _tmp13_;
					_tmp10_ = _tmp14_;
				} else {
					_tmp10_ = 0;
				}
				len += (gsize) _tmp10_;
			}
		}
		if (i == 0) {
			gchar* _tmp15_;
			_tmp15_ = g_strdup ("");
			result = _tmp15_;
			return result;
		}
		str_array_length1 = i;
		_tmp16_ = strlen ((const gchar*) separator);
		_tmp17_ = _tmp16_;
		len += (gsize) (_tmp17_ * (i - 1));
		_tmp18_ = g_malloc (len);
		res = _tmp18_;
		_tmp20_ = str_array[0];
		if (_tmp20_ != NULL) {
			const gchar* _tmp21_;
			_tmp21_ = str_array[0];
			_tmp19_ = (const gchar*) _tmp21_;
		} else {
			_tmp19_ = "";
		}
		_tmp22_ = res;
		_tmp23_ = g_stpcpy ((void*) _tmp22_, _tmp19_);
		ptr = _tmp23_;
		{
			gboolean _tmp24_ = FALSE;
			i = 1;
			_tmp24_ = TRUE;
			while (TRUE) {
				void* _tmp26_;
				void* _tmp27_;
				const gchar* _tmp28_ = NULL;
				const gchar* _tmp29_;
				void* _tmp31_;
				void* _tmp32_;
				if (!_tmp24_) {
					gint _tmp25_;
					_tmp25_ = i;
					i = _tmp25_ + 1;
				}
				_tmp24_ = FALSE;
				if (!(i < str_array_length1)) {
					break;
				}
				_tmp26_ = ptr;
				_tmp27_ = g_stpcpy (_tmp26_, (const gchar*) separator);
				ptr = _tmp27_;
				_tmp29_ = str_array[i];
				if (_tmp29_ != NULL) {
					const gchar* _tmp30_;
					_tmp30_ = str_array[i];
					_tmp28_ = (const gchar*) _tmp30_;
				} else {
					_tmp28_ = "";
				}
				_tmp31_ = ptr;
				_tmp32_ = g_stpcpy (_tmp31_, _tmp28_);
				ptr = _tmp32_;
			}
		}
		_tmp33_ = res;
		res = NULL;
		result = (gchar*) _tmp33_;
		return result;
	} else {
		gchar* _tmp34_;
		_tmp34_ = g_strdup ("");
		result = _tmp34_;
		return result;
	}
}

static RygelSearchExpression*
rygel_media_export_query_container_factory_parse_description (const gchar* description,
                                                              gchar** pattern,
                                                              gchar** attribute,
                                                              gchar** upnp_class,
                                                              gchar** name)
{
	gchar* _vala_pattern = NULL;
	gchar* _vala_attribute = NULL;
	gchar* _vala_upnp_class = NULL;
	gchar** args = NULL;
	gchar** _tmp0_;
	gchar** _tmp1_;
	gint args_length1;
	gint _args_size_;
	RygelSearchExpression* expression = NULL;
	gpointer _tmp2_;
	RygelSearchExpression* _tmp3_;
	gint i = 0;
	RygelSearchExpression* result;
	g_return_val_if_fail (description != NULL, NULL);
	g_return_val_if_fail (*name != NULL, NULL);
	_tmp1_ = _tmp0_ = g_strsplit (description, ",", 0);
	args = _tmp1_;
	args_length1 = _vala_array_length (_tmp0_);
	_args_size_ = args_length1;
	_tmp2_ = NULL;
	_tmp3_ = _rygel_search_expression_ref0 (G_TYPE_CHECK_INSTANCE_TYPE (_tmp2_, RYGEL_TYPE_SEARCH_EXPRESSION) ? ((RygelSearchExpression*) _tmp2_) : NULL);
	expression = _tmp3_;
	_g_free0 (_vala_pattern);
	_vala_pattern = NULL;
	_g_free0 (_vala_attribute);
	_vala_attribute = NULL;
	_g_free0 (_vala_upnp_class);
	_vala_upnp_class = NULL;
	i = 0;
	while (TRUE) {
		gchar** _tmp4_;
		gint _tmp4__length1;
		gchar* previous_attribute = NULL;
		const gchar* _tmp5_;
		gchar* _tmp6_;
		gchar** _tmp7_;
		gint _tmp7__length1;
		const gchar* _tmp8_;
		gchar* _tmp9_;
		const gchar* _tmp10_;
		gchar* _tmp11_;
		gchar** _tmp12_;
		gint _tmp12__length1;
		const gchar* _tmp13_;
		_tmp4_ = args;
		_tmp4__length1 = args_length1;
		if (!(i < _tmp4__length1)) {
			break;
		}
		_tmp5_ = _vala_attribute;
		_tmp6_ = g_strdup (_tmp5_);
		previous_attribute = _tmp6_;
		_tmp7_ = args;
		_tmp7__length1 = args_length1;
		_tmp8_ = _tmp7_[i];
		_tmp9_ = string_replace (_tmp8_, RYGEL_MEDIA_EXPORT_QUERY_CONTAINER_PREFIX, "");
		_g_free0 (_vala_attribute);
		_vala_attribute = _tmp9_;
		_tmp10_ = _vala_attribute;
		_tmp11_ = g_uri_unescape_string (_tmp10_, NULL);
		_g_free0 (_vala_attribute);
		_vala_attribute = _tmp11_;
		_tmp12_ = args;
		_tmp12__length1 = args_length1;
		_tmp13_ = _tmp12_[i + 1];
		if (g_strcmp0 (_tmp13_, "?") != 0) {
			gchar** _tmp14_;
			gint _tmp14__length1;
			const gchar* _tmp15_;
			gchar** _tmp16_;
			gint _tmp16__length1;
			const gchar* _tmp17_;
			gchar** _tmp18_;
			gint _tmp18__length1;
			_tmp14_ = args;
			_tmp14__length1 = args_length1;
			_tmp15_ = _tmp14_[i];
			_tmp16_ = args;
			_tmp16__length1 = args_length1;
			_tmp17_ = _tmp16_[i + 1];
			rygel_media_export_query_container_factory_update_search_expression (&expression, _tmp15_, _tmp17_);
			_tmp18_ = args;
			_tmp18__length1 = args_length1;
			if ((i + 2) == _tmp18__length1) {
				const gchar* _tmp19_;
				gchar* _tmp20_;
				_tmp19_ = _vala_attribute;
				_tmp20_ = rygel_media_export_query_container_factory_map_upnp_class (_tmp19_);
				_g_free0 (_vala_upnp_class);
				_vala_upnp_class = _tmp20_;
				if (g_strcmp0 (*name, "") == 0) {
					gchar** _tmp21_;
					gint _tmp21__length1;
					const gchar* _tmp22_;
					gchar* _tmp23_;
					_tmp21_ = args;
					_tmp21__length1 = args_length1;
					_tmp22_ = _tmp21_[i + 1];
					_tmp23_ = g_uri_unescape_string (_tmp22_, NULL);
					_g_free0 (*name);
					*name = _tmp23_;
				}
			}
		} else {
			gchar** _tmp24_;
			gint _tmp24__length1;
			gchar* _tmp25_;
			gchar** _tmp26_;
			gint _tmp26__length1;
			gchar* _tmp27_;
			const gchar* _tmp28_;
			gchar* _tmp29_;
			gboolean _tmp30_ = FALSE;
			_tmp24_ = args;
			_tmp24__length1 = args_length1;
			_tmp25_ = g_strdup ("%s");
			_g_free0 (_tmp24_[i + 1]);
			_tmp24_[i + 1] = _tmp25_;
			_tmp26_ = args;
			_tmp26__length1 = args_length1;
			_tmp27_ = _vala_g_strjoinv (",", _tmp26_, (gint) _tmp26__length1);
			_g_free0 (_vala_pattern);
			_vala_pattern = _tmp27_;
			_tmp28_ = previous_attribute;
			_tmp29_ = rygel_media_export_query_container_factory_map_upnp_class (_tmp28_);
			_g_free0 (_vala_upnp_class);
			_vala_upnp_class = _tmp29_;
			if (g_strcmp0 (*name, "") == 0) {
				_tmp30_ = i > 0;
			} else {
				_tmp30_ = FALSE;
			}
			if (_tmp30_) {
				gchar** _tmp31_;
				gint _tmp31__length1;
				const gchar* _tmp32_;
				gchar* _tmp33_;
				_tmp31_ = args;
				_tmp31__length1 = args_length1;
				_tmp32_ = _tmp31_[i - 1];
				_tmp33_ = g_uri_unescape_string (_tmp32_, NULL);
				_g_free0 (*name);
				*name = _tmp33_;
			}
			_g_free0 (previous_attribute);
			break;
		}
		i += 2;
		_g_free0 (previous_attribute);
	}
	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);
	}
	if (upnp_class) {
		*upnp_class = _vala_upnp_class;
	} else {
		_g_free0 (_vala_upnp_class);
	}
	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 (RygelSearchExpression** expression,
                                                                     const gchar* key,
                                                                     const gchar* value)
{
	RygelRelationalExpression* subexpression = NULL;
	RygelRelationalExpression* _tmp0_;
	gchar* clean_key = NULL;
	gchar* _tmp1_;
	RygelRelationalExpression* _tmp2_;
	const gchar* _tmp3_;
	gchar* _tmp4_;
	RygelRelationalExpression* _tmp5_;
	RygelRelationalExpression* _tmp6_;
	gchar* _tmp7_;
	g_return_if_fail (key != NULL);
	g_return_if_fail (value != NULL);
	_tmp0_ = rygel_relational_expression_new ();
	subexpression = _tmp0_;
	_tmp1_ = string_replace (key, RYGEL_MEDIA_EXPORT_QUERY_CONTAINER_PREFIX, "");
	clean_key = _tmp1_;
	_tmp2_ = subexpression;
	_tmp3_ = clean_key;
	_tmp4_ = g_uri_unescape_string (_tmp3_, NULL);
	_g_free0 (((RygelSearchExpression*) _tmp2_)->operand1);
	((RygelSearchExpression*) _tmp2_)->operand1 = _tmp4_;
	_tmp5_ = subexpression;
	((RygelSearchExpression*) _tmp5_)->op = (gpointer) ((gintptr) GUPNP_SEARCH_CRITERIA_OP_EQ);
	_tmp6_ = subexpression;
	_tmp7_ = g_uri_unescape_string (value, NULL);
	_g_free0 (((RygelSearchExpression*) _tmp6_)->operand2);
	((RygelSearchExpression*) _tmp6_)->operand2 = _tmp7_;
	if ((*expression) != NULL) {
		RygelLogicalExpression* conjunction = NULL;
		RygelLogicalExpression* _tmp8_;
		RygelLogicalExpression* _tmp9_;
		RygelSearchExpression* _tmp10_;
		RygelLogicalExpression* _tmp11_;
		RygelRelationalExpression* _tmp12_;
		RygelSearchExpression* _tmp13_;
		RygelLogicalExpression* _tmp14_;
		RygelLogicalExpression* _tmp15_;
		RygelSearchExpression* _tmp16_;
		_tmp8_ = rygel_logical_expression_new ();
		conjunction = _tmp8_;
		_tmp9_ = conjunction;
		_tmp10_ = _rygel_search_expression_ref0 (*expression);
		_rygel_search_expression_unref0 (((RygelSearchExpression*) _tmp9_)->operand1);
		((RygelSearchExpression*) _tmp9_)->operand1 = _tmp10_;
		_tmp11_ = conjunction;
		_tmp12_ = subexpression;
		_tmp13_ = _rygel_search_expression_ref0 ((RygelSearchExpression*) _tmp12_);
		_rygel_search_expression_unref0 (((RygelSearchExpression*) _tmp11_)->operand2);
		((RygelSearchExpression*) _tmp11_)->operand2 = _tmp13_;
		_tmp14_ = conjunction;
		((RygelSearchExpression*) _tmp14_)->op = (gpointer) ((gintptr) RYGEL_LOGICAL_OPERATOR_AND);
		_tmp15_ = conjunction;
		_tmp16_ = _rygel_search_expression_ref0 ((RygelSearchExpression*) _tmp15_);
		_rygel_search_expression_unref0 (*expression);
		*expression = _tmp16_;
		_rygel_search_expression_unref0 (conjunction);
	} else {
		RygelRelationalExpression* _tmp17_;
		RygelSearchExpression* _tmp18_;
		_tmp17_ = subexpression;
		_tmp18_ = _rygel_search_expression_ref0 ((RygelSearchExpression*) _tmp17_);
		_rygel_search_expression_unref0 (*expression);
		*expression = _tmp18_;
	}
	_g_free0 (clean_key);
	_rygel_search_expression_unref0 (subexpression);
}

static void
rygel_media_export_query_container_factory_class_init (RygelMediaExportQueryContainerFactoryClass * klass,
                                                       gpointer klass_data)
{
	rygel_media_export_query_container_factory_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &RygelMediaExportQueryContainerFactory_private_offset);
	G_OBJECT_CLASS (klass)->finalize = rygel_media_export_query_container_factory_finalize;
}

static void
rygel_media_export_query_container_factory_instance_init (RygelMediaExportQueryContainerFactory * self,
                                                          gpointer klass)
{
	self->priv = rygel_media_export_query_container_factory_get_instance_private (self);
}

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

/**
 * A helper class to create QueryContainer instances based on IDs.
 */
 G_GNUC_NO_INLINE static GType
rygel_media_export_query_container_factory_get_type_once (void)
{
	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);
	RygelMediaExportQueryContainerFactory_private_offset = g_type_add_instance_private (rygel_media_export_query_container_factory_type_id, sizeof (RygelMediaExportQueryContainerFactoryPrivate));
	return rygel_media_export_query_container_factory_type_id;
}

GType
rygel_media_export_query_container_factory_get_type (void)
{
	static volatile gsize rygel_media_export_query_container_factory_type_id__once = 0;
	if (g_once_init_enter (&rygel_media_export_query_container_factory_type_id__once)) {
		GType rygel_media_export_query_container_factory_type_id;
		rygel_media_export_query_container_factory_type_id = rygel_media_export_query_container_factory_get_type_once ();
		g_once_init_leave (&rygel_media_export_query_container_factory_type_id__once, rygel_media_export_query_container_factory_type_id);
	}
	return rygel_media_export_query_container_factory_type_id__once;
}

static void
_vala_array_destroy (gpointer array,
                     gssize array_length,
                     GDestroyNotify destroy_func)
{
	if ((array != NULL) && (destroy_func != NULL)) {
		gssize 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,
                  gssize array_length,
                  GDestroyNotify destroy_func)
{
	_vala_array_destroy (array, array_length, destroy_func);
	g_free (array);
}

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

