/* rygel-media-export-db-container.c generated by valac 0.32.1, the Vala compiler
 * generated from rygel-media-export-db-container.vala, do not modify */

/*
 * Copyright (C) 2009 Jens Georg <mail@jensge.org>.
 *
 * Author: 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 <rygel-db.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 _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))
#define _g_free0(var) (var = (g_free (var), NULL))
typedef struct _RygelMediaExportDbContainerGetChildrenData RygelMediaExportDbContainerGetChildrenData;
#define _rygel_search_expression_unref0(var) ((var == NULL) ? NULL : (var = (rygel_search_expression_unref (var), NULL)))
typedef struct _RygelMediaExportDbContainerSearchData RygelMediaExportDbContainerSearchData;
typedef struct _RygelMediaExportDbContainerFindObjectData RygelMediaExportDbContainerFindObjectData;

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 _RygelMediaExportDBContainerPrivate {
	GeeArrayList* _search_classes;
};

struct _RygelMediaExportDbContainerGetChildrenData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GSimpleAsyncResult* _async_result;
	RygelMediaExportDBContainer* self;
	guint offset;
	guint max_count;
	gchar* sort_criteria;
	GCancellable* cancellable;
	RygelMediaObjects* result;
	RygelMediaObjects* _tmp0_;
	RygelMediaExportMediaCache* _tmp1_;
	const gchar* _tmp2_;
	guint _tmp3_;
	guint _tmp4_;
	RygelMediaObjects* _tmp5_;
	RygelMediaObjects* _tmp6_;
	GError * _inner_error_;
};

typedef enum  {
	RYGEL_MEDIA_EXPORT_MEDIA_CACHE_ERROR_SQLITE_ERROR,
	RYGEL_MEDIA_EXPORT_MEDIA_CACHE_ERROR_GENERAL_ERROR,
	RYGEL_MEDIA_EXPORT_MEDIA_CACHE_ERROR_INVALID_TYPE,
	RYGEL_MEDIA_EXPORT_MEDIA_CACHE_ERROR_UNSUPPORTED_SEARCH
} RygelMediaExportMediaCacheError;
#define RYGEL_MEDIA_EXPORT_MEDIA_CACHE_ERROR rygel_media_export_media_cache_error_quark ()
struct _RygelMediaExportDbContainerSearchData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GSimpleAsyncResult* _async_result;
	RygelMediaExportDBContainer* self;
	RygelSearchExpression* expression;
	guint offset;
	guint max_count;
	guint total_matches;
	gchar* sort_criteria;
	GCancellable* cancellable;
	RygelMediaObjects* result;
	RygelMediaObjects* children;
	RygelMediaObjects* _tmp0_;
	RygelMediaExportMediaCache* _tmp1_;
	RygelSearchExpression* _tmp2_;
	const gchar* _tmp3_;
	const gchar* _tmp4_;
	const gchar* _tmp5_;
	guint _tmp6_;
	guint _tmp7_;
	guint _tmp8_;
	RygelMediaObjects* _tmp9_;
	RygelMediaObjects* _tmp10_;
	GError* _error_;
	GError* _tmp11_;
	RygelMediaObjects* _tmp12_;
	RygelSearchExpression* _tmp13_;
	guint _tmp14_;
	guint _tmp15_;
	const gchar* _tmp16_;
	GCancellable* _tmp17_;
	guint _tmp18_;
	RygelMediaObjects* _tmp19_;
	RygelMediaObjects* _tmp20_;
	GError* _tmp21_;
	GError* _tmp22_;
	GError * _inner_error_;
};

struct _RygelMediaExportDbContainerFindObjectData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GSimpleAsyncResult* _async_result;
	RygelMediaExportDBContainer* self;
	gchar* id;
	GCancellable* cancellable;
	RygelMediaObject* result;
	RygelMediaObject* _tmp0_;
	RygelMediaExportMediaCache* _tmp1_;
	const gchar* _tmp2_;
	RygelMediaObject* _tmp3_;
	RygelMediaObject* _tmp4_;
	GError * _inner_error_;
};


static gpointer rygel_media_export_db_container_parent_class = NULL;
static RygelSearchableContainerIface* rygel_media_export_db_container_rygel_searchable_container_parent_iface = 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;
#define RYGEL_MEDIA_EXPORT_DB_CONTAINER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), RYGEL_MEDIA_EXPORT_TYPE_DB_CONTAINER, RygelMediaExportDBContainerPrivate))
enum  {
	RYGEL_MEDIA_EXPORT_DB_CONTAINER_DUMMY_PROPERTY,
	RYGEL_MEDIA_EXPORT_DB_CONTAINER_SEARCH_CLASSES
};
RygelMediaExportDBContainer* rygel_media_export_db_container_new (const gchar* id, const gchar* title);
RygelMediaExportDBContainer* rygel_media_export_db_container_construct (GType object_type, const gchar* id, const gchar* title);
static void rygel_media_export_db_container_real_constructed (GObject* base);
RygelMediaExportMediaCache* rygel_media_export_media_cache_get_default (void);
static void __lambda5_ (RygelMediaExportDBContainer* self);
gint rygel_media_export_db_container_count_children (RygelMediaExportDBContainer* self);
static void ___lambda5__rygel_media_container_container_updated (RygelMediaContainer* _sender, RygelMediaContainer* container, RygelMediaObject* object, RygelObjectEventType event_type, gboolean sub_tree_update, gpointer self);
static gint rygel_media_export_db_container_real_count_children (RygelMediaExportDBContainer* self);
gint rygel_media_export_media_cache_get_child_count (RygelMediaExportMediaCache* self, const gchar* container_id, GError** error);
static void rygel_media_export_db_container_real_get_children_data_free (gpointer _data);
static void rygel_media_export_db_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_db_container_real_get_children_co (RygelMediaExportDbContainerGetChildrenData* _data_);
RygelMediaObjects* rygel_media_export_media_cache_get_children (RygelMediaExportMediaCache* self, RygelMediaContainer* container, const gchar* sort_criteria, glong offset, glong max_count, GError** error);
static void rygel_media_export_db_container_real_search_data_free (gpointer _data);
static void rygel_media_export_db_container_real_search (RygelMediaExportDBContainer* self, RygelSearchExpression* expression, guint offset, guint max_count, const gchar* sort_criteria, GCancellable* cancellable, GAsyncReadyCallback _callback_, gpointer _user_data_);
void rygel_media_export_db_container_search (RygelMediaExportDBContainer* self, RygelSearchExpression* expression, guint offset, guint max_count, const gchar* sort_criteria, GCancellable* cancellable, GAsyncReadyCallback _callback_, gpointer _user_data_);
RygelMediaObjects* rygel_media_export_db_container_search_finish (RygelMediaExportDBContainer* self, GAsyncResult* _res_, guint* total_matches, GError** error);
static gboolean rygel_media_export_db_container_real_search_co (RygelMediaExportDbContainerSearchData* _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);
GQuark rygel_media_export_media_cache_error_quark (void);
static void rygel_media_export_db_container_search_ready (GObject* source_object, GAsyncResult* _res_, gpointer _user_data_);
static void rygel_media_export_db_container_real_find_object_data_free (gpointer _data);
static void rygel_media_export_db_container_real_find_object (RygelMediaContainer* base, const gchar* id, GCancellable* cancellable, GAsyncReadyCallback _callback_, gpointer _user_data_);
static gboolean rygel_media_export_db_container_real_find_object_co (RygelMediaExportDbContainerFindObjectData* _data_);
RygelMediaObject* rygel_media_export_media_cache_get_object (RygelMediaExportMediaCache* self, const gchar* object_id, GError** error);
static void rygel_media_export_db_container_finalize (GObject* obj);
static void _vala_rygel_media_export_db_container_get_property (GObject * object, guint property_id, GValue * value, GParamSpec * pspec);
static void _vala_rygel_media_export_db_container_set_property (GObject * object, guint property_id, const GValue * value, GParamSpec * pspec);


RygelMediaExportDBContainer* rygel_media_export_db_container_construct (GType object_type, const gchar* id, const gchar* title) {
	RygelMediaExportDBContainer * self = NULL;
	const gchar* _tmp0_ = NULL;
	const gchar* _tmp1_ = NULL;
	g_return_val_if_fail (id != NULL, NULL);
	g_return_val_if_fail (title != NULL, NULL);
	_tmp0_ = id;
	_tmp1_ = title;
	self = (RygelMediaExportDBContainer*) g_object_new (object_type, "id", _tmp0_, "parent", NULL, "title", _tmp1_, "child-count", 0, NULL);
	return self;
}


RygelMediaExportDBContainer* rygel_media_export_db_container_new (const gchar* id, const gchar* title) {
	return rygel_media_export_db_container_construct (RYGEL_MEDIA_EXPORT_TYPE_DB_CONTAINER, id, title);
}


static void __lambda5_ (RygelMediaExportDBContainer* self) {
	gint _tmp0_ = 0;
	_tmp0_ = rygel_media_export_db_container_count_children (self);
	rygel_media_container_set_child_count ((RygelMediaContainer*) self, _tmp0_);
}


static void ___lambda5__rygel_media_container_container_updated (RygelMediaContainer* _sender, RygelMediaContainer* container, RygelMediaObject* object, RygelObjectEventType event_type, gboolean sub_tree_update, gpointer self) {
	__lambda5_ ((RygelMediaExportDBContainer*) self);
}


static void rygel_media_export_db_container_real_constructed (GObject* base) {
	RygelMediaExportDBContainer * self;
	RygelMediaExportMediaCache* _tmp0_ = NULL;
	GeeArrayList* _tmp1_ = NULL;
	GeeArrayList* _tmp2_ = NULL;
	GeeArrayList* _tmp3_ = NULL;
	GeeArrayList* _tmp4_ = NULL;
	GeeArrayList* _tmp5_ = NULL;
	GeeArrayList* _tmp6_ = NULL;
	GeeArrayList* _tmp7_ = NULL;
	GeeArrayList* _tmp8_ = NULL;
	GeeArrayList* _tmp9_ = NULL;
	GeeArrayList* _tmp10_ = NULL;
	GeeArrayList* _tmp11_ = NULL;
	GeeArrayList* _tmp12_ = NULL;
	GeeArrayList* _tmp13_ = NULL;
	GeeArrayList* _tmp14_ = NULL;
	GeeArrayList* _tmp15_ = NULL;
	GeeArrayList* _tmp16_ = NULL;
	gint _tmp17_ = 0;
	self = (RygelMediaExportDBContainer*) base;
	G_OBJECT_CLASS (rygel_media_export_db_container_parent_class)->constructed ((GObject*) G_TYPE_CHECK_INSTANCE_CAST (self, RYGEL_TYPE_MEDIA_CONTAINER, RygelMediaContainer));
	_tmp0_ = rygel_media_export_media_cache_get_default ();
	_g_object_unref0 (self->media_db);
	self->media_db = _tmp0_;
	_tmp1_ = gee_array_list_new (G_TYPE_STRING, (GBoxedCopyFunc) g_strdup, g_free, NULL, NULL, NULL);
	_tmp2_ = _tmp1_;
	rygel_searchable_container_set_search_classes ((RygelSearchableContainer*) self, _tmp2_);
	_g_object_unref0 (_tmp2_);
	_tmp3_ = rygel_searchable_container_get_search_classes ((RygelSearchableContainer*) self);
	_tmp4_ = _tmp3_;
	gee_abstract_collection_add ((GeeAbstractCollection*) _tmp4_, RYGEL_IMAGE_ITEM_UPNP_CLASS);
	_tmp5_ = rygel_searchable_container_get_search_classes ((RygelSearchableContainer*) self);
	_tmp6_ = _tmp5_;
	gee_abstract_collection_add ((GeeAbstractCollection*) _tmp6_, RYGEL_PHOTO_ITEM_UPNP_CLASS);
	_tmp7_ = rygel_searchable_container_get_search_classes ((RygelSearchableContainer*) self);
	_tmp8_ = _tmp7_;
	gee_abstract_collection_add ((GeeAbstractCollection*) _tmp8_, RYGEL_VIDEO_ITEM_UPNP_CLASS);
	_tmp9_ = rygel_searchable_container_get_search_classes ((RygelSearchableContainer*) self);
	_tmp10_ = _tmp9_;
	gee_abstract_collection_add ((GeeAbstractCollection*) _tmp10_, RYGEL_AUDIO_ITEM_UPNP_CLASS);
	_tmp11_ = rygel_searchable_container_get_search_classes ((RygelSearchableContainer*) self);
	_tmp12_ = _tmp11_;
	gee_abstract_collection_add ((GeeAbstractCollection*) _tmp12_, RYGEL_MUSIC_ITEM_UPNP_CLASS);
	_tmp13_ = rygel_searchable_container_get_search_classes ((RygelSearchableContainer*) self);
	_tmp14_ = _tmp13_;
	gee_abstract_collection_add ((GeeAbstractCollection*) _tmp14_, RYGEL_PLAYLIST_ITEM_UPNP_CLASS);
	_tmp15_ = rygel_searchable_container_get_search_classes ((RygelSearchableContainer*) self);
	_tmp16_ = _tmp15_;
	gee_abstract_collection_add ((GeeAbstractCollection*) _tmp16_, RYGEL_MEDIA_CONTAINER_UPNP_CLASS);
	g_signal_connect_object ((RygelMediaContainer*) self, "container-updated", (GCallback) ___lambda5__rygel_media_container_container_updated, self, 0);
	_tmp17_ = rygel_media_export_db_container_count_children (self);
	rygel_media_container_set_child_count ((RygelMediaContainer*) self, _tmp17_);
}


static gint rygel_media_export_db_container_real_count_children (RygelMediaExportDBContainer* self) {
	gint result = 0;
	GError * _inner_error_ = NULL;
	{
		gint _tmp0_ = 0;
		RygelMediaExportMediaCache* _tmp1_ = NULL;
		const gchar* _tmp2_ = NULL;
		const gchar* _tmp3_ = NULL;
		gint _tmp4_ = 0;
		_tmp1_ = self->media_db;
		_tmp2_ = rygel_media_object_get_id ((RygelMediaObject*) self);
		_tmp3_ = _tmp2_;
		_tmp4_ = rygel_media_export_media_cache_get_child_count (_tmp1_, _tmp3_, &_inner_error_);
		_tmp0_ = _tmp4_;
		if (G_UNLIKELY (_inner_error_ != NULL)) {
			if (_inner_error_->domain == RYGEL_DATABASE_DATABASE_ERROR) {
				goto __catch2_rygel_database_database_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 0;
		}
		result = _tmp0_;
		return result;
	}
	goto __finally2;
	__catch2_rygel_database_database_error:
	{
		GError* _error_ = NULL;
		GError* _tmp5_ = NULL;
		const gchar* _tmp6_ = NULL;
		_error_ = _inner_error_;
		_inner_error_ = NULL;
		_tmp5_ = _error_;
		_tmp6_ = _tmp5_->message;
		g_debug ("rygel-media-export-db-container.vala:63: Could not get child count fro" \
"m database: %s", _tmp6_);
		result = 0;
		_g_error_free0 (_error_);
		return result;
	}
	__finally2:
	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 0;
}


gint rygel_media_export_db_container_count_children (RygelMediaExportDBContainer* self) {
	g_return_val_if_fail (self != NULL, 0);
	return RYGEL_MEDIA_EXPORT_DB_CONTAINER_GET_CLASS (self)->count_children (self);
}


static void rygel_media_export_db_container_real_get_children_data_free (gpointer _data) {
	RygelMediaExportDbContainerGetChildrenData* _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 (RygelMediaExportDbContainerGetChildrenData, _data_);
}


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


static void rygel_media_export_db_container_real_get_children (RygelMediaContainer* base, guint offset, guint max_count, const gchar* sort_criteria, GCancellable* cancellable, GAsyncReadyCallback _callback_, gpointer _user_data_) {
	RygelMediaExportDBContainer * self;
	RygelMediaExportDbContainerGetChildrenData* _data_;
	RygelMediaExportDBContainer* _tmp0_ = NULL;
	guint _tmp1_ = 0U;
	guint _tmp2_ = 0U;
	const gchar* _tmp3_ = NULL;
	gchar* _tmp4_ = NULL;
	GCancellable* _tmp5_ = NULL;
	GCancellable* _tmp6_ = NULL;
	self = (RygelMediaExportDBContainer*) base;
	_data_ = g_slice_new0 (RygelMediaExportDbContainerGetChildrenData);
	_data_->_async_result = g_simple_async_result_new (G_OBJECT (self), _callback_, _user_data_, rygel_media_export_db_container_real_get_children);
	g_simple_async_result_set_op_res_gpointer (_data_->_async_result, _data_, rygel_media_export_db_container_real_get_children_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	_tmp1_ = offset;
	_data_->offset = _tmp1_;
	_tmp2_ = max_count;
	_data_->max_count = _tmp2_;
	_tmp3_ = sort_criteria;
	_tmp4_ = g_strdup (_tmp3_);
	_g_free0 (_data_->sort_criteria);
	_data_->sort_criteria = _tmp4_;
	_tmp5_ = cancellable;
	_tmp6_ = _g_object_ref0 (_tmp5_);
	_g_object_unref0 (_data_->cancellable);
	_data_->cancellable = _tmp6_;
	rygel_media_export_db_container_real_get_children_co (_data_);
}


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


static gboolean rygel_media_export_db_container_real_get_children_co (RygelMediaExportDbContainerGetChildrenData* _data_) {
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_tmp1_ = NULL;
	_data_->_tmp1_ = _data_->self->media_db;
	_data_->_tmp2_ = NULL;
	_data_->_tmp2_ = _data_->sort_criteria;
	_data_->_tmp3_ = 0U;
	_data_->_tmp3_ = _data_->offset;
	_data_->_tmp4_ = 0U;
	_data_->_tmp4_ = _data_->max_count;
	_data_->_tmp5_ = NULL;
	_data_->_tmp5_ = rygel_media_export_media_cache_get_children (_data_->_tmp1_, (RygelMediaContainer*) _data_->self, _data_->_tmp2_, (glong) _data_->_tmp3_, (glong) _data_->_tmp4_, &_data_->_inner_error_);
	_data_->_tmp0_ = _data_->_tmp5_;
	if (G_UNLIKELY (_data_->_inner_error_ != NULL)) {
		g_simple_async_result_set_from_error (_data_->_async_result, _data_->_inner_error_);
		g_error_free (_data_->_inner_error_);
		if (_data_->_state_ == 0) {
			g_simple_async_result_complete_in_idle (_data_->_async_result);
		} else {
			g_simple_async_result_complete (_data_->_async_result);
		}
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_tmp6_ = NULL;
	_data_->_tmp6_ = _data_->_tmp0_;
	_data_->_tmp0_ = NULL;
	_data_->result = _data_->_tmp6_;
	_g_object_unref0 (_data_->_tmp0_);
	if (_data_->_state_ == 0) {
		g_simple_async_result_complete_in_idle (_data_->_async_result);
	} else {
		g_simple_async_result_complete (_data_->_async_result);
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
	_g_object_unref0 (_data_->_tmp0_);
	if (_data_->_state_ == 0) {
		g_simple_async_result_complete_in_idle (_data_->_async_result);
	} else {
		g_simple_async_result_complete (_data_->_async_result);
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
}


static void rygel_media_export_db_container_real_search_data_free (gpointer _data) {
	RygelMediaExportDbContainerSearchData* _data_;
	_data_ = _data;
	_rygel_search_expression_unref0 (_data_->expression);
	_g_free0 (_data_->sort_criteria);
	_g_object_unref0 (_data_->cancellable);
	_g_object_unref0 (_data_->result);
	_g_object_unref0 (_data_->self);
	g_slice_free (RygelMediaExportDbContainerSearchData, _data_);
}


static gpointer _rygel_search_expression_ref0 (gpointer self) {
	return self ? rygel_search_expression_ref (self) : NULL;
}


static void rygel_media_export_db_container_real_search (RygelMediaExportDBContainer* self, RygelSearchExpression* expression, guint offset, guint max_count, const gchar* sort_criteria, GCancellable* cancellable, GAsyncReadyCallback _callback_, gpointer _user_data_) {
	RygelMediaExportDbContainerSearchData* _data_;
	RygelMediaExportDBContainer* _tmp0_ = NULL;
	RygelSearchExpression* _tmp1_ = NULL;
	RygelSearchExpression* _tmp2_ = NULL;
	guint _tmp3_ = 0U;
	guint _tmp4_ = 0U;
	const gchar* _tmp5_ = NULL;
	gchar* _tmp6_ = NULL;
	GCancellable* _tmp7_ = NULL;
	GCancellable* _tmp8_ = NULL;
	_data_ = g_slice_new0 (RygelMediaExportDbContainerSearchData);
	_data_->_async_result = g_simple_async_result_new (G_OBJECT (self), _callback_, _user_data_, rygel_media_export_db_container_real_search);
	g_simple_async_result_set_op_res_gpointer (_data_->_async_result, _data_, rygel_media_export_db_container_real_search_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	_tmp1_ = expression;
	_tmp2_ = _rygel_search_expression_ref0 (_tmp1_);
	_rygel_search_expression_unref0 (_data_->expression);
	_data_->expression = _tmp2_;
	_tmp3_ = offset;
	_data_->offset = _tmp3_;
	_tmp4_ = max_count;
	_data_->max_count = _tmp4_;
	_tmp5_ = sort_criteria;
	_tmp6_ = g_strdup (_tmp5_);
	_g_free0 (_data_->sort_criteria);
	_data_->sort_criteria = _tmp6_;
	_tmp7_ = cancellable;
	_tmp8_ = _g_object_ref0 (_tmp7_);
	_g_object_unref0 (_data_->cancellable);
	_data_->cancellable = _tmp8_;
	rygel_media_export_db_container_real_search_co (_data_);
}


static RygelMediaObjects* rygel_media_export_db_container_real_search_finish (RygelMediaExportDBContainer* self, GAsyncResult* _res_, guint* total_matches, GError** error) {
	RygelMediaObjects* result;
	RygelMediaExportDbContainerSearchData* _data_;
	if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (_res_), error)) {
		return NULL;
	}
	_data_ = g_simple_async_result_get_op_res_gpointer (G_SIMPLE_ASYNC_RESULT (_res_));
	if (total_matches) {
		*total_matches = _data_->total_matches;
	}
	result = _data_->result;
	_data_->result = NULL;
	return result;
}


static void rygel_media_export_db_container_search_ready (GObject* source_object, GAsyncResult* _res_, gpointer _user_data_) {
	RygelMediaExportDbContainerSearchData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	rygel_media_export_db_container_real_search_co (_data_);
}


static gpointer _g_error_copy0 (gpointer self) {
	return self ? g_error_copy (self) : NULL;
}


static gboolean rygel_media_export_db_container_real_search_co (RygelMediaExportDbContainerSearchData* _data_) {
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->children = NULL;
	{
		_data_->_tmp1_ = NULL;
		_data_->_tmp1_ = _data_->self->media_db;
		_data_->_tmp2_ = NULL;
		_data_->_tmp2_ = _data_->expression;
		_data_->_tmp3_ = NULL;
		_data_->_tmp3_ = rygel_media_object_get_id ((RygelMediaObject*) _data_->self);
		_data_->_tmp4_ = NULL;
		_data_->_tmp4_ = _data_->_tmp3_;
		_data_->_tmp5_ = NULL;
		_data_->_tmp5_ = _data_->sort_criteria;
		_data_->_tmp6_ = 0U;
		_data_->_tmp6_ = _data_->offset;
		_data_->_tmp7_ = 0U;
		_data_->_tmp7_ = _data_->max_count;
		_data_->_tmp8_ = 0U;
		_data_->_tmp9_ = NULL;
		_data_->_tmp9_ = rygel_media_export_media_cache_get_objects_by_search_expression (_data_->_tmp1_, _data_->_tmp2_, _data_->_tmp4_, _data_->_tmp5_, _data_->_tmp6_, _data_->_tmp7_, &_data_->_tmp8_, &_data_->_inner_error_);
		_data_->total_matches = _data_->_tmp8_;
		_data_->_tmp0_ = _data_->_tmp9_;
		if (G_UNLIKELY (_data_->_inner_error_ != NULL)) {
			if (_data_->_inner_error_->domain == RYGEL_MEDIA_EXPORT_MEDIA_CACHE_ERROR) {
				goto __catch3_rygel_media_export_media_cache_error;
			}
			goto __finally3;
		}
		_data_->_tmp10_ = NULL;
		_data_->_tmp10_ = _data_->_tmp0_;
		_data_->_tmp0_ = NULL;
		_g_object_unref0 (_data_->children);
		_data_->children = _data_->_tmp10_;
		_g_object_unref0 (_data_->_tmp0_);
	}
	goto __finally3;
	__catch3_rygel_media_export_media_cache_error:
	{
		_data_->_error_ = _data_->_inner_error_;
		_data_->_inner_error_ = NULL;
		_data_->_tmp11_ = NULL;
		_data_->_tmp11_ = _data_->_error_;
		if (g_error_matches (_data_->_tmp11_, RYGEL_MEDIA_EXPORT_MEDIA_CACHE_ERROR, RYGEL_MEDIA_EXPORT_MEDIA_CACHE_ERROR_UNSUPPORTED_SEARCH)) {
			_data_->_tmp13_ = NULL;
			_data_->_tmp13_ = _data_->expression;
			_data_->_tmp14_ = 0U;
			_data_->_tmp14_ = _data_->offset;
			_data_->_tmp15_ = 0U;
			_data_->_tmp15_ = _data_->max_count;
			_data_->_tmp16_ = NULL;
			_data_->_tmp16_ = _data_->sort_criteria;
			_data_->_tmp17_ = NULL;
			_data_->_tmp17_ = _data_->cancellable;
			_data_->_tmp18_ = 0U;
			_data_->_state_ = 1;
			rygel_searchable_container_simple_search ((RygelSearchableContainer*) _data_->self, _data_->_tmp13_, _data_->_tmp14_, _data_->_tmp15_, _data_->_tmp16_, _data_->_tmp17_, rygel_media_export_db_container_search_ready, _data_);
			return FALSE;
			_state_1:
			_data_->_tmp19_ = NULL;
			_data_->_tmp19_ = rygel_searchable_container_simple_search_finish ((RygelSearchableContainer*) _data_->self, _data_->_res_, &_data_->_tmp18_, &_data_->_inner_error_);
			_data_->total_matches = _data_->_tmp18_;
			_data_->_tmp12_ = _data_->_tmp19_;
			if (G_UNLIKELY (_data_->_inner_error_ != NULL)) {
				_g_error_free0 (_data_->_error_);
				goto __finally3;
			}
			_data_->_tmp20_ = NULL;
			_data_->_tmp20_ = _data_->_tmp12_;
			_data_->_tmp12_ = NULL;
			_g_object_unref0 (_data_->children);
			_data_->children = _data_->_tmp20_;
			_g_object_unref0 (_data_->_tmp12_);
		} else {
			_data_->_tmp21_ = NULL;
			_data_->_tmp21_ = _data_->_error_;
			_data_->_tmp22_ = NULL;
			_data_->_tmp22_ = _g_error_copy0 (_data_->_tmp21_);
			_data_->_inner_error_ = _data_->_tmp22_;
			_g_error_free0 (_data_->_error_);
			goto __finally3;
		}
		_g_error_free0 (_data_->_error_);
	}
	__finally3:
	if (G_UNLIKELY (_data_->_inner_error_ != NULL)) {
		g_simple_async_result_set_from_error (_data_->_async_result, _data_->_inner_error_);
		g_error_free (_data_->_inner_error_);
		_g_object_unref0 (_data_->children);
		if (_data_->_state_ == 0) {
			g_simple_async_result_complete_in_idle (_data_->_async_result);
		} else {
			g_simple_async_result_complete (_data_->_async_result);
		}
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->result = _data_->children;
	if (_data_->_state_ == 0) {
		g_simple_async_result_complete_in_idle (_data_->_async_result);
	} else {
		g_simple_async_result_complete (_data_->_async_result);
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
	_g_object_unref0 (_data_->children);
	if (_data_->_state_ == 0) {
		g_simple_async_result_complete_in_idle (_data_->_async_result);
	} else {
		g_simple_async_result_complete (_data_->_async_result);
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
}


void rygel_media_export_db_container_search (RygelMediaExportDBContainer* self, RygelSearchExpression* expression, guint offset, guint max_count, const gchar* sort_criteria, GCancellable* cancellable, GAsyncReadyCallback _callback_, gpointer _user_data_) {
	RYGEL_MEDIA_EXPORT_DB_CONTAINER_GET_CLASS (self)->search (self, expression, offset, max_count, sort_criteria, cancellable, _callback_, _user_data_);
}


RygelMediaObjects* rygel_media_export_db_container_search_finish (RygelMediaExportDBContainer* self, GAsyncResult* _res_, guint* total_matches, GError** error) {
	return RYGEL_MEDIA_EXPORT_DB_CONTAINER_GET_CLASS (self)->search_finish (self, _res_, total_matches, error);
}


static void rygel_media_export_db_container_real_find_object_data_free (gpointer _data) {
	RygelMediaExportDbContainerFindObjectData* _data_;
	_data_ = _data;
	_g_free0 (_data_->id);
	_g_object_unref0 (_data_->cancellable);
	_g_object_unref0 (_data_->result);
	_g_object_unref0 (_data_->self);
	g_slice_free (RygelMediaExportDbContainerFindObjectData, _data_);
}


static void rygel_media_export_db_container_real_find_object (RygelMediaContainer* base, const gchar* id, GCancellable* cancellable, GAsyncReadyCallback _callback_, gpointer _user_data_) {
	RygelMediaExportDBContainer * self;
	RygelMediaExportDbContainerFindObjectData* _data_;
	RygelMediaExportDBContainer* _tmp0_ = NULL;
	const gchar* _tmp1_ = NULL;
	gchar* _tmp2_ = NULL;
	GCancellable* _tmp3_ = NULL;
	GCancellable* _tmp4_ = NULL;
	self = (RygelMediaExportDBContainer*) base;
	_data_ = g_slice_new0 (RygelMediaExportDbContainerFindObjectData);
	_data_->_async_result = g_simple_async_result_new (G_OBJECT (self), _callback_, _user_data_, rygel_media_export_db_container_real_find_object);
	g_simple_async_result_set_op_res_gpointer (_data_->_async_result, _data_, rygel_media_export_db_container_real_find_object_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	_tmp1_ = id;
	_tmp2_ = g_strdup (_tmp1_);
	_g_free0 (_data_->id);
	_data_->id = _tmp2_;
	_tmp3_ = cancellable;
	_tmp4_ = _g_object_ref0 (_tmp3_);
	_g_object_unref0 (_data_->cancellable);
	_data_->cancellable = _tmp4_;
	rygel_media_export_db_container_real_find_object_co (_data_);
}


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


static gboolean rygel_media_export_db_container_real_find_object_co (RygelMediaExportDbContainerFindObjectData* _data_) {
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_tmp1_ = NULL;
	_data_->_tmp1_ = _data_->self->media_db;
	_data_->_tmp2_ = NULL;
	_data_->_tmp2_ = _data_->id;
	_data_->_tmp3_ = NULL;
	_data_->_tmp3_ = rygel_media_export_media_cache_get_object (_data_->_tmp1_, _data_->_tmp2_, &_data_->_inner_error_);
	_data_->_tmp0_ = _data_->_tmp3_;
	if (G_UNLIKELY (_data_->_inner_error_ != NULL)) {
		g_simple_async_result_set_from_error (_data_->_async_result, _data_->_inner_error_);
		g_error_free (_data_->_inner_error_);
		if (_data_->_state_ == 0) {
			g_simple_async_result_complete_in_idle (_data_->_async_result);
		} else {
			g_simple_async_result_complete (_data_->_async_result);
		}
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_tmp4_ = NULL;
	_data_->_tmp4_ = _data_->_tmp0_;
	_data_->_tmp0_ = NULL;
	_data_->result = _data_->_tmp4_;
	_g_object_unref0 (_data_->_tmp0_);
	if (_data_->_state_ == 0) {
		g_simple_async_result_complete_in_idle (_data_->_async_result);
	} else {
		g_simple_async_result_complete (_data_->_async_result);
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
	_g_object_unref0 (_data_->_tmp0_);
	if (_data_->_state_ == 0) {
		g_simple_async_result_complete_in_idle (_data_->_async_result);
	} else {
		g_simple_async_result_complete (_data_->_async_result);
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
}


static GeeArrayList* rygel_media_export_db_container_real_get_search_classes (RygelSearchableContainer* base) {
	GeeArrayList* result;
	RygelMediaExportDBContainer* self;
	GeeArrayList* _tmp0_ = NULL;
	self = (RygelMediaExportDBContainer*) base;
	_tmp0_ = self->priv->_search_classes;
	result = _tmp0_;
	return result;
}


static void rygel_media_export_db_container_real_set_search_classes (RygelSearchableContainer* base, GeeArrayList* value) {
	RygelMediaExportDBContainer* self;
	GeeArrayList* _tmp0_ = NULL;
	GeeArrayList* _tmp1_ = NULL;
	self = (RygelMediaExportDBContainer*) base;
	_tmp0_ = value;
	_tmp1_ = _g_object_ref0 (_tmp0_);
	_g_object_unref0 (self->priv->_search_classes);
	self->priv->_search_classes = _tmp1_;
	g_object_notify ((GObject *) self, "search-classes");
}


static void rygel_media_export_db_container_class_init (RygelMediaExportDBContainerClass * klass) {
	rygel_media_export_db_container_parent_class = g_type_class_peek_parent (klass);
	g_type_class_add_private (klass, sizeof (RygelMediaExportDBContainerPrivate));
	((GObjectClass *) klass)->constructed = rygel_media_export_db_container_real_constructed;
	((RygelMediaExportDBContainerClass *) klass)->count_children = rygel_media_export_db_container_real_count_children;
	((RygelMediaContainerClass *) klass)->get_children = rygel_media_export_db_container_real_get_children;
	((RygelMediaContainerClass *) klass)->get_children_finish = rygel_media_export_db_container_real_get_children_finish;
	((RygelMediaExportDBContainerClass *) klass)->search = rygel_media_export_db_container_real_search;
	((RygelMediaExportDBContainerClass *) klass)->search_finish = rygel_media_export_db_container_real_search_finish;
	((RygelMediaContainerClass *) klass)->find_object = rygel_media_export_db_container_real_find_object;
	((RygelMediaContainerClass *) klass)->find_object_finish = rygel_media_export_db_container_real_find_object_finish;
	G_OBJECT_CLASS (klass)->get_property = _vala_rygel_media_export_db_container_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_rygel_media_export_db_container_set_property;
	G_OBJECT_CLASS (klass)->finalize = rygel_media_export_db_container_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), RYGEL_MEDIA_EXPORT_DB_CONTAINER_SEARCH_CLASSES, g_param_spec_object ("search-classes", "search-classes", "search-classes", GEE_TYPE_ARRAY_LIST, G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_READABLE | G_PARAM_WRITABLE));
}


static void rygel_media_export_db_container_rygel_searchable_container_interface_init (RygelSearchableContainerIface * iface) {
	rygel_media_export_db_container_rygel_searchable_container_parent_iface = g_type_interface_peek_parent (iface);
	iface->search = (RygelMediaObjects* (*)(RygelSearchableContainer*, RygelSearchExpression*, guint, guint, guint*, const gchar*, GCancellable*, GError**)) rygel_media_export_db_container_search;
	iface->search_finish = rygel_media_export_db_container_search_finish;
	iface->get_search_classes = rygel_media_export_db_container_real_get_search_classes;
	iface->set_search_classes = rygel_media_export_db_container_real_set_search_classes;
}


static void rygel_media_export_db_container_instance_init (RygelMediaExportDBContainer * self) {
	self->priv = RYGEL_MEDIA_EXPORT_DB_CONTAINER_GET_PRIVATE (self);
}


static void rygel_media_export_db_container_finalize (GObject* obj) {
	RygelMediaExportDBContainer * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, RYGEL_MEDIA_EXPORT_TYPE_DB_CONTAINER, RygelMediaExportDBContainer);
	_g_object_unref0 (self->media_db);
	_g_object_unref0 (self->priv->_search_classes);
	G_OBJECT_CLASS (rygel_media_export_db_container_parent_class)->finalize (obj);
}


GType rygel_media_export_db_container_get_type (void) {
	static volatile gsize rygel_media_export_db_container_type_id__volatile = 0;
	if (g_once_init_enter (&rygel_media_export_db_container_type_id__volatile)) {
		static const GTypeInfo g_define_type_info = { sizeof (RygelMediaExportDBContainerClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) rygel_media_export_db_container_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (RygelMediaExportDBContainer), 0, (GInstanceInitFunc) rygel_media_export_db_container_instance_init, NULL };
		static const GInterfaceInfo rygel_searchable_container_info = { (GInterfaceInitFunc) rygel_media_export_db_container_rygel_searchable_container_interface_init, (GInterfaceFinalizeFunc) NULL, NULL};
		GType rygel_media_export_db_container_type_id;
		rygel_media_export_db_container_type_id = g_type_register_static (RYGEL_TYPE_MEDIA_CONTAINER, "RygelMediaExportDBContainer", &g_define_type_info, 0);
		g_type_add_interface_static (rygel_media_export_db_container_type_id, RYGEL_TYPE_SEARCHABLE_CONTAINER, &rygel_searchable_container_info);
		g_once_init_leave (&rygel_media_export_db_container_type_id__volatile, rygel_media_export_db_container_type_id);
	}
	return rygel_media_export_db_container_type_id__volatile;
}


static void _vala_rygel_media_export_db_container_get_property (GObject * object, guint property_id, GValue * value, GParamSpec * pspec) {
	RygelMediaExportDBContainer * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, RYGEL_MEDIA_EXPORT_TYPE_DB_CONTAINER, RygelMediaExportDBContainer);
	switch (property_id) {
		case RYGEL_MEDIA_EXPORT_DB_CONTAINER_SEARCH_CLASSES:
		g_value_set_object (value, rygel_searchable_container_get_search_classes ((RygelSearchableContainer*) self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}


static void _vala_rygel_media_export_db_container_set_property (GObject * object, guint property_id, const GValue * value, GParamSpec * pspec) {
	RygelMediaExportDBContainer * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, RYGEL_MEDIA_EXPORT_TYPE_DB_CONTAINER, RygelMediaExportDBContainer);
	switch (property_id) {
		case RYGEL_MEDIA_EXPORT_DB_CONTAINER_SEARCH_CLASSES:
		rygel_searchable_container_set_search_classes ((RygelSearchableContainer*) self, g_value_get_object (value));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}



