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

/*
 * Copyright (C) 2015 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 "rygel-server.h"
#include "rygel-media-export.h"
#include <glib-object.h>
#include <stdlib.h>
#include <string.h>
#include <glib.h>
#include <libgupnp/gupnp.h>
#include <gio/gio.h>
#include <libxml/tree.h>
#include <libxml/parser.h>
#include <libxml/xpath.h>
#include <glib/gstdio.h>
#include <glib/gi18n-lib.h>

#define RYGEL_MEDIA_EXPORT_DVD_CONTAINER_UPNP_CLASS RYGEL_MEDIA_CONTAINER_PLAYLIST ".DVD"
#define RYGEL_MEDIA_EXPORT_DVD_CONTAINER_PREFIX "dvd"
#define RYGEL_MEDIA_EXPORT_DVD_CONTAINER_TRACK_PREFIX "dvd-track"
#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_DVD_CONTAINER (rygel_media_export_dvd_container_get_type ())
#define RYGEL_MEDIA_EXPORT_DVD_CONTAINER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), RYGEL_MEDIA_EXPORT_TYPE_DVD_CONTAINER, RygelMediaExportDVDContainer))
#define RYGEL_MEDIA_EXPORT_DVD_CONTAINER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), RYGEL_MEDIA_EXPORT_TYPE_DVD_CONTAINER, RygelMediaExportDVDContainerClass))
#define RYGEL_MEDIA_EXPORT_IS_DVD_CONTAINER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), RYGEL_MEDIA_EXPORT_TYPE_DVD_CONTAINER))
#define RYGEL_MEDIA_EXPORT_IS_DVD_CONTAINER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), RYGEL_MEDIA_EXPORT_TYPE_DVD_CONTAINER))
#define RYGEL_MEDIA_EXPORT_DVD_CONTAINER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), RYGEL_MEDIA_EXPORT_TYPE_DVD_CONTAINER, RygelMediaExportDVDContainerClass))

typedef struct _RygelMediaExportDVDContainer RygelMediaExportDVDContainer;
typedef struct _RygelMediaExportDVDContainerClass RygelMediaExportDVDContainerClass;
typedef struct _RygelMediaExportDVDContainerPrivate RygelMediaExportDVDContainerPrivate;
enum  {
	RYGEL_MEDIA_EXPORT_DVD_CONTAINER_0_PROPERTY,
	RYGEL_MEDIA_EXPORT_DVD_CONTAINER_PATH_PROPERTY,
	RYGEL_MEDIA_EXPORT_DVD_CONTAINER_NUM_PROPERTIES
};
static GParamSpec* rygel_media_export_dvd_container_properties[RYGEL_MEDIA_EXPORT_DVD_CONTAINER_NUM_PROPERTIES];
#define _g_free0(var) (var = (g_free (var), NULL))
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _xmlXPathFreeObject0(var) ((var == NULL) ? NULL : (var = (xmlXPathFreeObject (var), NULL)))
#define _xmlXPathFreeContext0(var) ((var == NULL) ? NULL : (var = (xmlXPathFreeContext (var), NULL)))
typedef struct _RygelMediaExportDvdContainerFindObjectData RygelMediaExportDvdContainerFindObjectData;
typedef struct _RygelMediaExportDvdContainerCommitCustomData RygelMediaExportDvdContainerCommitCustomData;

#define RYGEL_MEDIA_EXPORT_TYPE_VIDEO_ITEM (rygel_media_export_video_item_get_type ())
#define RYGEL_MEDIA_EXPORT_VIDEO_ITEM(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), RYGEL_MEDIA_EXPORT_TYPE_VIDEO_ITEM, RygelMediaExportVideoItem))
#define RYGEL_MEDIA_EXPORT_VIDEO_ITEM_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), RYGEL_MEDIA_EXPORT_TYPE_VIDEO_ITEM, RygelMediaExportVideoItemClass))
#define RYGEL_MEDIA_EXPORT_IS_VIDEO_ITEM(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), RYGEL_MEDIA_EXPORT_TYPE_VIDEO_ITEM))
#define RYGEL_MEDIA_EXPORT_IS_VIDEO_ITEM_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), RYGEL_MEDIA_EXPORT_TYPE_VIDEO_ITEM))
#define RYGEL_MEDIA_EXPORT_VIDEO_ITEM_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), RYGEL_MEDIA_EXPORT_TYPE_VIDEO_ITEM, RygelMediaExportVideoItemClass))

typedef struct _RygelMediaExportVideoItem RygelMediaExportVideoItem;
typedef struct _RygelMediaExportVideoItemClass RygelMediaExportVideoItemClass;

#define RYGEL_MEDIA_EXPORT_TYPE_DVD_TRACK (rygel_media_export_dvd_track_get_type ())
#define RYGEL_MEDIA_EXPORT_DVD_TRACK(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), RYGEL_MEDIA_EXPORT_TYPE_DVD_TRACK, RygelMediaExportDVDTrack))
#define RYGEL_MEDIA_EXPORT_DVD_TRACK_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), RYGEL_MEDIA_EXPORT_TYPE_DVD_TRACK, RygelMediaExportDVDTrackClass))
#define RYGEL_MEDIA_EXPORT_IS_DVD_TRACK(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), RYGEL_MEDIA_EXPORT_TYPE_DVD_TRACK))
#define RYGEL_MEDIA_EXPORT_IS_DVD_TRACK_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), RYGEL_MEDIA_EXPORT_TYPE_DVD_TRACK))
#define RYGEL_MEDIA_EXPORT_DVD_TRACK_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), RYGEL_MEDIA_EXPORT_TYPE_DVD_TRACK, RygelMediaExportDVDTrackClass))

typedef struct _RygelMediaExportDVDTrack RygelMediaExportDVDTrack;
typedef struct _RygelMediaExportDVDTrackClass RygelMediaExportDVDTrackClass;

struct _RygelMediaExportDVDContainer {
	RygelSimpleContainer parent_instance;
	RygelMediaExportDVDContainerPrivate * priv;
};

struct _RygelMediaExportDVDContainerClass {
	RygelSimpleContainerClass parent_class;
};

struct _RygelMediaExportDVDContainerPrivate {
	gchar* _path;
	GUPnPXMLDoc* doc;
};

struct _RygelMediaExportDvdContainerFindObjectData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	RygelMediaExportDVDContainer* self;
	gchar* id;
	GCancellable* cancellable;
	RygelMediaObject* result;
	gchar** parts;
	gchar** _tmp0_;
	gchar** _tmp1_;
	gint parts_length1;
	gint _parts_size_;
	gint track;
	gchar** _tmp2_;
	gint _tmp2__length1;
	const gchar* _tmp3_;
	xmlXPathContext* context;
	GUPnPXMLDoc* _tmp4_;
	xmlDoc* _tmp5_;
	xmlXPathContext* _tmp6_;
	xmlXPathObject* xpo;
	xmlXPathContext* _tmp7_;
	xmlXPathObject* _tmp8_;
	gboolean _tmp9_;
	xmlXPathObject* _tmp10_;
	xmlXPathObject* _tmp11_;
	xmlNodeSet* _tmp12_;
	xmlXPathObject* _tmp13_;
	gchar** _tmp14_;
	gint _tmp14__length1;
	const gchar* _tmp15_;
	RygelMediaFileItem* object;
	gchar** _tmp16_;
	gint _tmp16__length1;
	const gchar* _tmp17_;
	xmlXPathObject* _tmp18_;
	xmlNodeSet* _tmp19_;
	xmlNode* _tmp20_;
	RygelMediaFileItem* _tmp21_;
	xmlXPathObject* _tmp22_;
};

struct _RygelMediaExportDvdContainerCommitCustomData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	RygelMediaExportDVDContainer* self;
	gboolean override_guarded;
	RygelMediaExportMediaCache* _tmp0_;
	RygelMediaExportMediaCache* _tmp1_;
	GError* _inner_error0_;
};

static gint RygelMediaExportDVDContainer_private_offset;
static gpointer rygel_media_export_dvd_container_parent_class = NULL;
static RygelMediaExportUpdatableObjectIface * rygel_media_export_dvd_container_rygel_media_export_updatable_object_parent_iface = NULL;

VALA_EXTERN GType rygel_media_export_dvd_container_get_type (void) G_GNUC_CONST ;
VALA_EXTERN RygelMediaExportDVDContainer* rygel_media_export_dvd_container_new (const gchar* id,
                                                                    RygelMediaContainer* parent,
                                                                    const gchar* title,
                                                                    const gchar* path);
VALA_EXTERN RygelMediaExportDVDContainer* rygel_media_export_dvd_container_construct (GType object_type,
                                                                          const gchar* id,
                                                                          RygelMediaContainer* parent,
                                                                          const gchar* title,
                                                                          const gchar* path);
static void rygel_media_export_dvd_container_real_constructed (GObject* base);
VALA_EXTERN const gchar* rygel_media_export_dvd_container_get_path (RygelMediaExportDVDContainer* self);
static gchar* rygel_media_export_dvd_container_get_cache_path (RygelMediaExportDVDContainer* self,
                                                        const gchar* image_path);
static RygelMediaFileItem* rygel_media_export_dvd_container_get_item_for_xml (RygelMediaExportDVDContainer* self,
                                                                       gint track,
                                                                       xmlNode* node);
static void rygel_media_export_dvd_container_real_find_object_data_free (gpointer _data);
static void rygel_media_export_dvd_container_real_find_object (RygelMediaContainer* base,
                                                        const gchar* id,
                                                        GCancellable* cancellable,
                                                        GAsyncReadyCallback _callback_,
                                                        gpointer _user_data_);
static gboolean rygel_media_export_dvd_container_real_find_object_co (RygelMediaExportDvdContainerFindObjectData* _data_);
static void rygel_media_export_dvd_container_real_commit_custom_data_free (gpointer _data);
static void rygel_media_export_dvd_container_real_commit_custom (RygelMediaExportUpdatableObject* base,
                                                          gboolean override_guarded,
                                                          GAsyncReadyCallback _callback_,
                                                          gpointer _user_data_);
static gboolean rygel_media_export_dvd_container_real_commit_custom_co (RygelMediaExportDvdContainerCommitCustomData* _data_);
static gchar* rygel_media_export_dvd_container_get_track_id (RygelMediaExportDVDContainer* self,
                                                      gint track);
static void _vala_array_add1 (gchar** * array,
                       gint* length,
                       gint* size,
                       gchar* value);
VALA_EXTERN GType rygel_media_export_video_item_get_type (void) G_GNUC_CONST ;
VALA_EXTERN GType rygel_media_export_dvd_track_get_type (void) G_GNUC_CONST ;
VALA_EXTERN RygelMediaExportDVDTrack* rygel_media_export_dvd_track_new (const gchar* id,
                                                            RygelMediaContainer* parent,
                                                            const gchar* title,
                                                            gint track,
                                                            xmlNode* node);
VALA_EXTERN RygelMediaExportDVDTrack* rygel_media_export_dvd_track_construct (GType object_type,
                                                                  const gchar* id,
                                                                  RygelMediaContainer* parent,
                                                                  const gchar* title,
                                                                  gint track,
                                                                  xmlNode* node);
VALA_EXTERN void rygel_media_export_dvd_container_set_path (RygelMediaExportDVDContainer* self,
                                                const gchar* value);
static void rygel_media_export_dvd_container_finalize (GObject * obj);
static GType rygel_media_export_dvd_container_get_type_once (void);
static void _vala_rygel_media_export_dvd_container_get_property (GObject * object,
                                                          guint property_id,
                                                          GValue * value,
                                                          GParamSpec * pspec);
static void _vala_rygel_media_export_dvd_container_set_property (GObject * object,
                                                          guint property_id,
                                                          const GValue * value,
                                                          GParamSpec * pspec);
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_dvd_container_get_instance_private (RygelMediaExportDVDContainer* self)
{
	return G_STRUCT_MEMBER_P (self, RygelMediaExportDVDContainer_private_offset);
}

RygelMediaExportDVDContainer*
rygel_media_export_dvd_container_construct (GType object_type,
                                            const gchar* id,
                                            RygelMediaContainer* parent,
                                            const gchar* title,
                                            const gchar* path)
{
	RygelMediaExportDVDContainer * self = NULL;
	g_return_val_if_fail (id != NULL, NULL);
	g_return_val_if_fail (title != NULL, NULL);
	g_return_val_if_fail (path != NULL, NULL);
	self = (RygelMediaExportDVDContainer*) g_object_new (object_type, "id", id, "upnp-class", RYGEL_MEDIA_EXPORT_DVD_CONTAINER_UPNP_CLASS, "title", title, "parent", parent, "child-count", 0, "path", path, NULL);
	return self;
}

RygelMediaExportDVDContainer*
rygel_media_export_dvd_container_new (const gchar* id,
                                      RygelMediaContainer* parent,
                                      const gchar* title,
                                      const gchar* path)
{
	return rygel_media_export_dvd_container_construct (RYGEL_MEDIA_EXPORT_TYPE_DVD_CONTAINER, id, parent, title, path);
}

static void
rygel_media_export_dvd_container_real_constructed (GObject* base)
{
	RygelMediaExportDVDContainer * self;
	const gchar* _tmp0_;
	GFile* _tmp1_;
	GFile* _tmp2_;
	gchar* _tmp3_;
	gchar* _tmp4_;
	gchar* cache_path = NULL;
	const gchar* _tmp5_;
	gchar* _tmp6_;
	xmlDoc* doc = NULL;
	const gchar* _tmp7_;
	xmlDoc* _tmp8_;
	xmlDoc* _tmp9_;
	GUPnPXMLDoc* _tmp10_;
	xmlXPathContext* context = NULL;
	GUPnPXMLDoc* _tmp11_;
	xmlDoc* _tmp12_;
	xmlXPathContext* _tmp13_;
	xmlXPathObject* xpo = NULL;
	xmlXPathContext* _tmp14_;
	xmlXPathObject* _tmp15_;
	xmlXPathObject* _tmp16_;
	xmlXPathObject* _tmp27_;
	self = (RygelMediaExportDVDContainer*) base;
	G_OBJECT_CLASS (rygel_media_export_dvd_container_parent_class)->constructed ((GObject*) G_TYPE_CHECK_INSTANCE_CAST (self, RYGEL_TYPE_SIMPLE_CONTAINER, RygelSimpleContainer));
	_tmp0_ = self->priv->_path;
	_tmp1_ = g_file_new_for_path (_tmp0_);
	_tmp2_ = _tmp1_;
	_tmp3_ = g_file_get_uri (_tmp2_);
	_tmp4_ = _tmp3_;
	rygel_media_object_add_uri ((RygelMediaObject*) self, _tmp4_);
	_g_free0 (_tmp4_);
	_g_object_unref0 (_tmp2_);
	_tmp5_ = self->priv->_path;
	_tmp6_ = rygel_media_export_dvd_container_get_cache_path (self, _tmp5_);
	cache_path = _tmp6_;
	_tmp7_ = cache_path;
	_tmp8_ = xmlReadFile (_tmp7_, NULL, (gint) (((XML_PARSE_NOERROR | XML_PARSE_NOWARNING) | XML_PARSE_NOBLANKS) | XML_PARSE_NONET));
	doc = _tmp8_;
	_tmp9_ = doc;
	doc = NULL;
	_tmp10_ = gupnp_xml_doc_new (_tmp9_);
	_g_object_unref0 (self->priv->doc);
	self->priv->doc = _tmp10_;
	_tmp11_ = self->priv->doc;
	_tmp12_ = gupnp_xml_doc_get_doc (_tmp11_);
	_tmp13_ = xmlXPathNewContext (_tmp12_);
	context = _tmp13_;
	_tmp14_ = context;
	_tmp15_ = xmlXPathEval ((xmlChar*) "/lsdvd/track", _tmp14_);
	xpo = _tmp15_;
	_tmp16_ = xpo;
	if (_tmp16_->type != XPATH_NODESET) {
		g_warning ("rygel-media-export-dvd-container.vala:62: No tracks found in DVD");
	} else {
		{
			gint i = 0;
			i = 0;
			{
				gboolean _tmp17_ = FALSE;
				_tmp17_ = TRUE;
				while (TRUE) {
					xmlXPathObject* _tmp19_;
					xmlNodeSet* _tmp20_;
					xmlNode* node = NULL;
					xmlXPathObject* _tmp21_;
					xmlNodeSet* _tmp22_;
					xmlNode* _tmp23_;
					RygelMediaFileItem* item = NULL;
					xmlNode* _tmp24_;
					RygelMediaFileItem* _tmp25_;
					RygelMediaFileItem* _tmp26_;
					if (!_tmp17_) {
						gint _tmp18_;
						_tmp18_ = i;
						i = _tmp18_ + 1;
					}
					_tmp17_ = FALSE;
					_tmp19_ = xpo;
					_tmp20_ = _tmp19_->nodesetval;
					if (!(i < xmlXPathNodeSetGetLength (_tmp20_))) {
						break;
					}
					_tmp21_ = xpo;
					_tmp22_ = _tmp21_->nodesetval;
					_tmp23_ = xmlXPathNodeSetItem (_tmp22_, i);
					node = _tmp23_;
					_tmp24_ = node;
					_tmp25_ = rygel_media_export_dvd_container_get_item_for_xml (self, i, _tmp24_);
					item = _tmp25_;
					_tmp26_ = item;
					rygel_simple_container_add_child_item ((RygelSimpleContainer*) self, (RygelMediaItem*) _tmp26_);
					_g_object_unref0 (item);
				}
			}
		}
	}
	_tmp27_ = xpo;
	_xmlXPathFreeObject0 (_tmp27_);
	_xmlXPathFreeContext0 (context);
	_g_free0 (cache_path);
}

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

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

static void
rygel_media_export_dvd_container_real_find_object (RygelMediaContainer* base,
                                                   const gchar* id,
                                                   GCancellable* cancellable,
                                                   GAsyncReadyCallback _callback_,
                                                   gpointer _user_data_)
{
	RygelMediaExportDVDContainer * self;
	RygelMediaExportDvdContainerFindObjectData* _data_;
	RygelMediaExportDVDContainer* _tmp0_;
	gchar* _tmp1_;
	GCancellable* _tmp2_;
	g_return_if_fail (id != NULL);
	self = (RygelMediaExportDVDContainer*) base;
	_data_ = g_slice_new0 (RygelMediaExportDvdContainerFindObjectData);
	_data_->_async_result = g_task_new (G_OBJECT (self), cancellable, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, rygel_media_export_dvd_container_real_find_object_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	_tmp1_ = g_strdup (id);
	_g_free0 (_data_->id);
	_data_->id = _tmp1_;
	_tmp2_ = _g_object_ref0 (cancellable);
	_g_object_unref0 (_data_->cancellable);
	_data_->cancellable = _tmp2_;
	rygel_media_export_dvd_container_real_find_object_co (_data_);
}

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

static gboolean
rygel_media_export_dvd_container_real_find_object_co (RygelMediaExportDvdContainerFindObjectData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	if (!g_str_has_prefix (_data_->id, RYGEL_MEDIA_EXPORT_DVD_CONTAINER_TRACK_PREFIX)) {
		_data_->result = NULL;
		g_task_return_pointer (_data_->_async_result, _data_, NULL);
		if (_data_->_state_ != 0) {
			while (!g_task_get_completed (_data_->_async_result)) {
				g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
			}
		}
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_tmp1_ = _data_->_tmp0_ = g_strsplit (_data_->id, ":", 0);
	_data_->parts = _data_->_tmp1_;
	_data_->parts_length1 = _vala_array_length (_data_->_tmp0_);
	_data_->_parts_size_ = _data_->parts_length1;
	_data_->_tmp2_ = _data_->parts;
	_data_->_tmp2__length1 = _data_->parts_length1;
	_data_->_tmp3_ = _data_->_tmp2_[2];
	_data_->track = atoi (_data_->_tmp3_);
	_data_->_tmp4_ = _data_->self->priv->doc;
	_data_->_tmp5_ = gupnp_xml_doc_get_doc (_data_->_tmp4_);
	_data_->_tmp6_ = xmlXPathNewContext (_data_->_tmp5_);
	_data_->context = _data_->_tmp6_;
	_data_->_tmp7_ = _data_->context;
	_data_->_tmp8_ = xmlXPathEval ((xmlChar*) "/lsdvd/track", _data_->_tmp7_);
	_data_->xpo = _data_->_tmp8_;
	_data_->_tmp10_ = _data_->xpo;
	if (_data_->_tmp10_->type == XPATH_NODESET) {
		_data_->_tmp11_ = _data_->xpo;
		_data_->_tmp12_ = _data_->_tmp11_->nodesetval;
		_data_->_tmp9_ = xmlXPathNodeSetGetLength (_data_->_tmp12_) >= _data_->track;
	} else {
		_data_->_tmp9_ = FALSE;
	}
	if (!_data_->_tmp9_) {
		_data_->_tmp13_ = _data_->xpo;
		_xmlXPathFreeObject0 (_data_->_tmp13_);
		_data_->_tmp14_ = _data_->parts;
		_data_->_tmp14__length1 = _data_->parts_length1;
		_data_->_tmp15_ = _data_->_tmp14_[2];
		g_warning ("rygel-media-export-dvd-container.vala:89: No track %s in DVD", _data_->_tmp15_);
		_data_->result = NULL;
		_xmlXPathFreeContext0 (_data_->context);
		_data_->parts = (_vala_array_free (_data_->parts, _data_->parts_length1, (GDestroyNotify) g_free), NULL);
		g_task_return_pointer (_data_->_async_result, _data_, NULL);
		if (_data_->_state_ != 0) {
			while (!g_task_get_completed (_data_->_async_result)) {
				g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
			}
		}
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_tmp16_ = _data_->parts;
	_data_->_tmp16__length1 = _data_->parts_length1;
	_data_->_tmp17_ = _data_->_tmp16_[2];
	_data_->_tmp18_ = _data_->xpo;
	_data_->_tmp19_ = _data_->_tmp18_->nodesetval;
	_data_->_tmp20_ = xmlXPathNodeSetItem (_data_->_tmp19_, _data_->track);
	_data_->_tmp21_ = rygel_media_export_dvd_container_get_item_for_xml (_data_->self, atoi (_data_->_tmp17_), _data_->_tmp20_);
	_data_->object = _data_->_tmp21_;
	_data_->_tmp22_ = _data_->xpo;
	_xmlXPathFreeObject0 (_data_->_tmp22_);
	_data_->result = (RygelMediaObject*) _data_->object;
	_xmlXPathFreeContext0 (_data_->context);
	_data_->parts = (_vala_array_free (_data_->parts, _data_->parts_length1, (GDestroyNotify) g_free), NULL);
	g_task_return_pointer (_data_->_async_result, _data_, NULL);
	if (_data_->_state_ != 0) {
		while (!g_task_get_completed (_data_->_async_result)) {
			g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
		}
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
}

static gchar*
rygel_media_export_dvd_container_get_cache_path (RygelMediaExportDVDContainer* self,
                                                 const gchar* image_path)
{
	const gchar* user_cache = NULL;
	const gchar* _tmp0_;
	gchar* id = NULL;
	gchar* _tmp1_;
	gchar* cache_folder = NULL;
	gchar* _tmp2_;
	gchar* _tmp3_;
	gchar* result;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (image_path != NULL, NULL);
	_tmp0_ = g_get_user_cache_dir ();
	user_cache = _tmp0_;
	_tmp1_ = g_compute_checksum_for_string (G_CHECKSUM_MD5, image_path, (gsize) -1);
	id = _tmp1_;
	_tmp2_ = g_build_filename (user_cache, "rygel", "dvd-content", NULL);
	cache_folder = _tmp2_;
	g_mkdir_with_parents (cache_folder, 0700);
	_tmp3_ = g_build_filename (cache_folder, id, NULL);
	result = _tmp3_;
	_g_free0 (cache_folder);
	_g_free0 (id);
	return result;
}

static void
rygel_media_export_dvd_container_real_commit_custom_data_free (gpointer _data)
{
	RygelMediaExportDvdContainerCommitCustomData* _data_;
	_data_ = _data;
	_g_object_unref0 (_data_->self);
	g_slice_free (RygelMediaExportDvdContainerCommitCustomData, _data_);
}

static void
rygel_media_export_dvd_container_real_commit_custom (RygelMediaExportUpdatableObject* base,
                                                     gboolean override_guarded,
                                                     GAsyncReadyCallback _callback_,
                                                     gpointer _user_data_)
{
	RygelMediaExportDVDContainer * self;
	RygelMediaExportDvdContainerCommitCustomData* _data_;
	RygelMediaExportDVDContainer* _tmp0_;
	self = (RygelMediaExportDVDContainer*) base;
	_data_ = g_slice_new0 (RygelMediaExportDvdContainerCommitCustomData);
	_data_->_async_result = g_task_new (G_OBJECT (self), NULL, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, rygel_media_export_dvd_container_real_commit_custom_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	_data_->override_guarded = override_guarded;
	rygel_media_export_dvd_container_real_commit_custom_co (_data_);
}

static void
rygel_media_export_dvd_container_commit_custom_finish (RygelMediaExportUpdatableObject* base,
                                                       GAsyncResult* _res_,
                                                       GError** error)
{
	RygelMediaExportDvdContainerCommitCustomData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), error);
	if (NULL == _data_) {
		return;
	}
}

static gboolean
rygel_media_export_dvd_container_real_commit_custom_co (RygelMediaExportDvdContainerCommitCustomData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_tmp0_ = rygel_media_export_media_cache_get_default ();
	_data_->_tmp1_ = _data_->_tmp0_;
	rygel_media_export_media_cache_save_container (_data_->_tmp1_, (RygelMediaContainer*) _data_->self, &_data_->_inner_error0_);
	_g_object_unref0 (_data_->_tmp1_);
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	g_task_return_pointer (_data_->_async_result, _data_, NULL);
	if (_data_->_state_ != 0) {
		while (!g_task_get_completed (_data_->_async_result)) {
			g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
		}
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
}

static void
_vala_array_add1 (gchar** * array,
                  gint* length,
                  gint* size,
                  gchar* value)
{
	if ((*length) == (*size)) {
		*size = (*size) ? (2 * (*size)) : 4;
		*array = g_renew (gchar*, *array, (*size) + 1);
	}
	(*array)[(*length)++] = value;
	(*array)[*length] = 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 gchar*
rygel_media_export_dvd_container_get_track_id (RygelMediaExportDVDContainer* self,
                                               gint track)
{
	gchar** parts = NULL;
	const gchar* _tmp0_;
	const gchar* _tmp1_;
	gchar** _tmp2_;
	gchar** _tmp3_;
	gint parts_length1;
	gint _parts_size_;
	gchar** _tmp4_;
	gint _tmp4__length1;
	gchar* _tmp5_;
	gchar* _tmp6_;
	gchar** _tmp7_;
	gint _tmp7__length1;
	gchar* _tmp8_;
	gchar* result;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = rygel_media_object_get_id ((RygelMediaObject*) self);
	_tmp1_ = _tmp0_;
	_tmp3_ = _tmp2_ = g_strsplit (_tmp1_, ":", 0);
	parts = _tmp3_;
	parts_length1 = _vala_array_length (_tmp2_);
	_parts_size_ = parts_length1;
	_tmp4_ = parts;
	_tmp4__length1 = parts_length1;
	_tmp5_ = g_strdup ("dvd-track");
	_g_free0 (_tmp4_[0]);
	_tmp4_[0] = _tmp5_;
	_tmp6_ = g_strdup_printf ("%i", track);
	_vala_array_add1 (&parts, &parts_length1, &_parts_size_, _tmp6_);
	_tmp7_ = parts;
	_tmp7__length1 = parts_length1;
	_tmp8_ = _vala_g_strjoinv (":", _tmp7_, (gint) _tmp7__length1);
	result = _tmp8_;
	parts = (_vala_array_free (parts, parts_length1, (GDestroyNotify) g_free), NULL);
	return result;
}

static RygelMediaFileItem*
rygel_media_export_dvd_container_get_item_for_xml (RygelMediaExportDVDContainer* self,
                                                   gint track,
                                                   xmlNode* node)
{
	RygelMediaExportDVDTrack* item = NULL;
	gchar* _tmp0_;
	gchar* _tmp1_;
	gchar* _tmp2_;
	gchar* _tmp3_;
	RygelMediaExportDVDTrack* _tmp4_;
	RygelMediaExportDVDTrack* _tmp5_;
	RygelMediaFileItem* result;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = rygel_media_export_dvd_container_get_track_id (self, track);
	_tmp1_ = _tmp0_;
	_tmp2_ = g_strdup_printf (_ ("Title %d"), track + 1);
	_tmp3_ = _tmp2_;
	_tmp4_ = rygel_media_export_dvd_track_new (_tmp1_, (RygelMediaContainer*) self, _tmp3_, track, node);
	_tmp5_ = _tmp4_;
	_g_free0 (_tmp3_);
	_g_free0 (_tmp1_);
	item = _tmp5_;
	rygel_media_object_set_parent_ref ((RygelMediaObject*) item, (RygelMediaContainer*) self);
	result = (RygelMediaFileItem*) item;
	return result;
}

const gchar*
rygel_media_export_dvd_container_get_path (RygelMediaExportDVDContainer* self)
{
	const gchar* result;
	const gchar* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_path;
	result = _tmp0_;
	return result;
}

void
rygel_media_export_dvd_container_set_path (RygelMediaExportDVDContainer* self,
                                           const gchar* value)
{
	gchar* old_value;
	g_return_if_fail (self != NULL);
	old_value = rygel_media_export_dvd_container_get_path (self);
	if (g_strcmp0 (value, old_value) != 0) {
		gchar* _tmp0_;
		_tmp0_ = g_strdup (value);
		_g_free0 (self->priv->_path);
		self->priv->_path = _tmp0_;
		g_object_notify_by_pspec ((GObject *) self, rygel_media_export_dvd_container_properties[RYGEL_MEDIA_EXPORT_DVD_CONTAINER_PATH_PROPERTY]);
	}
}

static void
rygel_media_export_dvd_container_class_init (RygelMediaExportDVDContainerClass * klass,
                                             gpointer klass_data)
{
	rygel_media_export_dvd_container_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &RygelMediaExportDVDContainer_private_offset);
	((GObjectClass *) klass)->constructed = (void (*) (GObject*)) rygel_media_export_dvd_container_real_constructed;
	((RygelMediaContainerClass *) klass)->find_object = (void (*) (RygelMediaContainer*, const gchar*, GCancellable*, GAsyncReadyCallback, gpointer)) rygel_media_export_dvd_container_real_find_object;
	((RygelMediaContainerClass *) klass)->find_object_finish = (RygelMediaObject* (*) (RygelMediaContainer*, GAsyncResult*, GError**)) rygel_media_export_dvd_container_find_object_finish;
	G_OBJECT_CLASS (klass)->get_property = _vala_rygel_media_export_dvd_container_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_rygel_media_export_dvd_container_set_property;
	G_OBJECT_CLASS (klass)->finalize = rygel_media_export_dvd_container_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), RYGEL_MEDIA_EXPORT_DVD_CONTAINER_PATH_PROPERTY, rygel_media_export_dvd_container_properties[RYGEL_MEDIA_EXPORT_DVD_CONTAINER_PATH_PROPERTY] = g_param_spec_string ("path", "path", "path", NULL, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT));
}

static void
rygel_media_export_dvd_container_rygel_media_export_updatable_object_interface_init (RygelMediaExportUpdatableObjectIface * iface,
                                                                                     gpointer iface_data)
{
	rygel_media_export_dvd_container_rygel_media_export_updatable_object_parent_iface = g_type_interface_peek_parent (iface);
	iface->commit_custom = (void (*) (RygelMediaExportUpdatableObject*, gboolean, GAsyncReadyCallback, gpointer)) rygel_media_export_dvd_container_real_commit_custom;
	iface->commit_custom_finish = (void (*) (RygelMediaExportUpdatableObject*, GAsyncResult*, GError**)) rygel_media_export_dvd_container_commit_custom_finish;
}

static void
rygel_media_export_dvd_container_instance_init (RygelMediaExportDVDContainer * self,
                                                gpointer klass)
{
	self->priv = rygel_media_export_dvd_container_get_instance_private (self);
}

static void
rygel_media_export_dvd_container_finalize (GObject * obj)
{
	RygelMediaExportDVDContainer * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, RYGEL_MEDIA_EXPORT_TYPE_DVD_CONTAINER, RygelMediaExportDVDContainer);
	_g_free0 (self->priv->_path);
	_g_object_unref0 (self->priv->doc);
	G_OBJECT_CLASS (rygel_media_export_dvd_container_parent_class)->finalize (obj);
}

 G_GNUC_NO_INLINE static GType
rygel_media_export_dvd_container_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (RygelMediaExportDVDContainerClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) rygel_media_export_dvd_container_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (RygelMediaExportDVDContainer), 0, (GInstanceInitFunc) rygel_media_export_dvd_container_instance_init, NULL };
	static const GInterfaceInfo rygel_media_export_updatable_object_info = { (GInterfaceInitFunc) rygel_media_export_dvd_container_rygel_media_export_updatable_object_interface_init, (GInterfaceFinalizeFunc) NULL, NULL};
	GType rygel_media_export_dvd_container_type_id;
	rygel_media_export_dvd_container_type_id = g_type_register_static (RYGEL_TYPE_SIMPLE_CONTAINER, "RygelMediaExportDVDContainer", &g_define_type_info, 0);
	g_type_add_interface_static (rygel_media_export_dvd_container_type_id, RYGEL_MEDIA_EXPORT_TYPE_UPDATABLE_OBJECT, &rygel_media_export_updatable_object_info);
	RygelMediaExportDVDContainer_private_offset = g_type_add_instance_private (rygel_media_export_dvd_container_type_id, sizeof (RygelMediaExportDVDContainerPrivate));
	return rygel_media_export_dvd_container_type_id;
}

GType
rygel_media_export_dvd_container_get_type (void)
{
	static volatile gsize rygel_media_export_dvd_container_type_id__once = 0;
	if (g_once_init_enter (&rygel_media_export_dvd_container_type_id__once)) {
		GType rygel_media_export_dvd_container_type_id;
		rygel_media_export_dvd_container_type_id = rygel_media_export_dvd_container_get_type_once ();
		g_once_init_leave (&rygel_media_export_dvd_container_type_id__once, rygel_media_export_dvd_container_type_id);
	}
	return rygel_media_export_dvd_container_type_id__once;
}

static void
_vala_rygel_media_export_dvd_container_get_property (GObject * object,
                                                     guint property_id,
                                                     GValue * value,
                                                     GParamSpec * pspec)
{
	RygelMediaExportDVDContainer * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, RYGEL_MEDIA_EXPORT_TYPE_DVD_CONTAINER, RygelMediaExportDVDContainer);
	switch (property_id) {
		case RYGEL_MEDIA_EXPORT_DVD_CONTAINER_PATH_PROPERTY:
		g_value_set_string (value, rygel_media_export_dvd_container_get_path (self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static void
_vala_rygel_media_export_dvd_container_set_property (GObject * object,
                                                     guint property_id,
                                                     const GValue * value,
                                                     GParamSpec * pspec)
{
	RygelMediaExportDVDContainer * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, RYGEL_MEDIA_EXPORT_TYPE_DVD_CONTAINER, RygelMediaExportDVDContainer);
	switch (property_id) {
		case RYGEL_MEDIA_EXPORT_DVD_CONTAINER_PATH_PROPERTY:
		rygel_media_export_dvd_container_set_path (self, g_value_get_string (value));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

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

