/* rygel-media-export-playlist-extractor.c generated by valac 0.56.1, the Vala compiler
 * generated from rygel-media-export-playlist-extractor.vala, do not modify */

#include <glib-object.h>
#include <gio/gio.h>
#include <glib.h>
#include <libgupnp-av/gupnp-av.h>
#include "mx-constants.h"

#define UPNP_CLASS_PLAYLIST "object.item.playlistItem"
#if !defined(VALA_EXTERN)
#if defined(_MSC_VER)
#define VALA_EXTERN __declspec(dllexport) extern
#elif __GNUC__ >= 4
#define VALA_EXTERN __attribute__((visibility("default"))) extern
#else
#define VALA_EXTERN extern
#endif
#endif

#define RYGEL_MEDIA_EXPORT_TYPE_EXTRACTOR (rygel_media_export_extractor_get_type ())
#define RYGEL_MEDIA_EXPORT_EXTRACTOR(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), RYGEL_MEDIA_EXPORT_TYPE_EXTRACTOR, RygelMediaExportExtractor))
#define RYGEL_MEDIA_EXPORT_EXTRACTOR_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), RYGEL_MEDIA_EXPORT_TYPE_EXTRACTOR, RygelMediaExportExtractorClass))
#define RYGEL_MEDIA_EXPORT_IS_EXTRACTOR(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), RYGEL_MEDIA_EXPORT_TYPE_EXTRACTOR))
#define RYGEL_MEDIA_EXPORT_IS_EXTRACTOR_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), RYGEL_MEDIA_EXPORT_TYPE_EXTRACTOR))
#define RYGEL_MEDIA_EXPORT_EXTRACTOR_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), RYGEL_MEDIA_EXPORT_TYPE_EXTRACTOR, RygelMediaExportExtractorClass))

typedef struct _RygelMediaExportExtractor RygelMediaExportExtractor;
typedef struct _RygelMediaExportExtractorClass RygelMediaExportExtractorClass;
typedef struct _RygelMediaExportExtractorPrivate RygelMediaExportExtractorPrivate;

#define RYGEL_MEDIA_EXPORT_TYPE_PLAYLIST_EXTRACTOR (rygel_media_export_playlist_extractor_get_type ())
#define RYGEL_MEDIA_EXPORT_PLAYLIST_EXTRACTOR(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), RYGEL_MEDIA_EXPORT_TYPE_PLAYLIST_EXTRACTOR, RygelMediaExportPlaylistExtractor))
#define RYGEL_MEDIA_EXPORT_PLAYLIST_EXTRACTOR_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), RYGEL_MEDIA_EXPORT_TYPE_PLAYLIST_EXTRACTOR, RygelMediaExportPlaylistExtractorClass))
#define RYGEL_MEDIA_EXPORT_IS_PLAYLIST_EXTRACTOR(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), RYGEL_MEDIA_EXPORT_TYPE_PLAYLIST_EXTRACTOR))
#define RYGEL_MEDIA_EXPORT_IS_PLAYLIST_EXTRACTOR_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), RYGEL_MEDIA_EXPORT_TYPE_PLAYLIST_EXTRACTOR))
#define RYGEL_MEDIA_EXPORT_PLAYLIST_EXTRACTOR_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), RYGEL_MEDIA_EXPORT_TYPE_PLAYLIST_EXTRACTOR, RygelMediaExportPlaylistExtractorClass))

typedef struct _RygelMediaExportPlaylistExtractor RygelMediaExportPlaylistExtractor;
typedef struct _RygelMediaExportPlaylistExtractorClass RygelMediaExportPlaylistExtractorClass;
typedef struct _RygelMediaExportPlaylistExtractorPrivate RygelMediaExportPlaylistExtractorPrivate;
enum  {
	RYGEL_MEDIA_EXPORT_PLAYLIST_EXTRACTOR_0_PROPERTY,
	RYGEL_MEDIA_EXPORT_PLAYLIST_EXTRACTOR_NUM_PROPERTIES
};
static GParamSpec* rygel_media_export_playlist_extractor_properties[RYGEL_MEDIA_EXPORT_PLAYLIST_EXTRACTOR_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))

#define TYPE_EXTRACTOR_ERROR (extractor_error_get_type ())
#define _g_free0(var) (var = (g_free (var), NULL))
typedef struct _RygelMediaExportPlaylistExtractorRunData RygelMediaExportPlaylistExtractorRunData;

struct _RygelMediaExportExtractor {
	GObject parent_instance;
	RygelMediaExportExtractorPrivate * priv;
	GVariantDict* serialized_info;
};

struct _RygelMediaExportExtractorClass {
	GObjectClass parent_class;
	void (*run) (RygelMediaExportExtractor* self, GAsyncReadyCallback _callback_, gpointer _user_data_);
	void (*run_finish) (RygelMediaExportExtractor* self, GAsyncResult* _res_, GError** error);
};

struct _RygelMediaExportPlaylistExtractor {
	RygelMediaExportExtractor parent_instance;
	RygelMediaExportPlaylistExtractorPrivate * priv;
};

struct _RygelMediaExportPlaylistExtractorClass {
	RygelMediaExportExtractorClass parent_class;
};

typedef enum  {
	EXTRACTOR_ERROR_GENERAL,
	EXTRACTOR_ERROR_INVALID
} ExtractorError;
#define EXTRACTOR_ERROR extractor_error_quark ()

struct _RygelMediaExportPlaylistExtractorRunData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	RygelMediaExportPlaylistExtractor* self;
	guint8* contents;
	gint contents_length1;
	gint _contents_size_;
	gboolean _tmp0_;
	GFile* _tmp1_;
	GFile* _tmp2_;
	guint8* _tmp3_;
	gsize _tmp4_;
	gboolean _tmp5_;
	GError* _tmp6_;
	gint i;
	gboolean _tmp7_;
	guint8* _tmp8_;
	gint _tmp8__length1;
	guint8 _tmp9_;
	guint8* _tmp10_;
	gint _tmp10__length1;
	gint _tmp11_;
	guint8* _tmp12_;
	gint _tmp12__length1;
	guint8 _tmp13_;
	GError* _tmp14_;
	GUPnPMediaCollection* didl_s;
	guint8* _tmp15_;
	gint _tmp15__length1;
	GUPnPMediaCollection* _tmp16_;
	gchar* author;
	GUPnPMediaCollection* _tmp17_;
	const gchar* _tmp18_;
	const gchar* _tmp19_;
	gchar* _tmp20_;
	gchar* title;
	GUPnPMediaCollection* _tmp21_;
	const gchar* _tmp22_;
	const gchar* _tmp23_;
	gchar* _tmp24_;
	gboolean _tmp25_;
	gboolean _tmp26_;
	const gchar* _tmp27_;
	const gchar* _tmp28_;
	GUPnPMediaCollection* _tmp29_;
	GList* _tmp30_;
	GList* _tmp31_;
	GError* _tmp32_;
	const gchar* _tmp33_;
	GVariantDict* _tmp34_;
	const gchar* _tmp35_;
	const gchar* _tmp36_;
	GVariantDict* _tmp37_;
	const gchar* _tmp38_;
	GVariantDict* _tmp39_;
	GVariantDict* _tmp40_;
	GError* _inner_error0_;
};

static gpointer rygel_media_export_playlist_extractor_parent_class = NULL;

VALA_EXTERN GType rygel_media_export_extractor_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (RygelMediaExportExtractor, g_object_unref)
VALA_EXTERN GType rygel_media_export_playlist_extractor_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (RygelMediaExportPlaylistExtractor, g_object_unref)
VALA_EXTERN void rygel_media_export_extractor_run (RygelMediaExportExtractor* self,
                                       GAsyncReadyCallback _callback_,
                                       gpointer _user_data_);
VALA_EXTERN void rygel_media_export_extractor_run_finish (RygelMediaExportExtractor* self,
                                              GAsyncResult* _res_,
                                              GError** error);
VALA_EXTERN RygelMediaExportPlaylistExtractor* rygel_media_export_playlist_extractor_new (GFile* file);
VALA_EXTERN RygelMediaExportPlaylistExtractor* rygel_media_export_playlist_extractor_construct (GType object_type,
                                                                                    GFile* file);
static void rygel_media_export_playlist_extractor_real_run_data_free (gpointer _data);
static void rygel_media_export_playlist_extractor_real_run (RygelMediaExportExtractor* base,
                                                     GAsyncReadyCallback _callback_,
                                                     gpointer _user_data_);
static gboolean rygel_media_export_playlist_extractor_real_run_co (RygelMediaExportPlaylistExtractorRunData* _data_);
static void rygel_media_export_playlist_extractor_run_ready (GObject* source_object,
                                                      GAsyncResult* _res_,
                                                      gpointer _user_data_);
VALA_EXTERN GFile* rygel_media_export_extractor_get_file (RygelMediaExportExtractor* self);
VALA_EXTERN GQuark extractor_error_quark (void);
GType extractor_error_get_type (void) G_GNUC_CONST ;
static void _g_object_unref0_ (gpointer var);
static inline void _g_list_free__g_object_unref0_ (GList* self);
static GType rygel_media_export_playlist_extractor_get_type_once (void);

RygelMediaExportPlaylistExtractor*
rygel_media_export_playlist_extractor_construct (GType object_type,
                                                 GFile* file)
{
	RygelMediaExportPlaylistExtractor * self = NULL;
	g_return_val_if_fail (file != NULL, NULL);
	self = (RygelMediaExportPlaylistExtractor*) g_object_new (object_type, "file", file, NULL);
	return self;
}

RygelMediaExportPlaylistExtractor*
rygel_media_export_playlist_extractor_new (GFile* file)
{
	return rygel_media_export_playlist_extractor_construct (RYGEL_MEDIA_EXPORT_TYPE_PLAYLIST_EXTRACTOR, file);
}

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

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

static void
rygel_media_export_playlist_extractor_real_run (RygelMediaExportExtractor* base,
                                                GAsyncReadyCallback _callback_,
                                                gpointer _user_data_)
{
	RygelMediaExportPlaylistExtractor * self;
	RygelMediaExportPlaylistExtractorRunData* _data_;
	RygelMediaExportPlaylistExtractor* _tmp0_;
	self = (RygelMediaExportPlaylistExtractor*) base;
	_data_ = g_slice_new0 (RygelMediaExportPlaylistExtractorRunData);
	_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_playlist_extractor_real_run_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	rygel_media_export_playlist_extractor_real_run_co (_data_);
}

static void
rygel_media_export_playlist_extractor_run_finish (RygelMediaExportExtractor* base,
                                                  GAsyncResult* _res_,
                                                  GError** error)
{
	RygelMediaExportPlaylistExtractorRunData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), error);
	if (NULL == _data_) {
		return;
	}
}

static void
rygel_media_export_playlist_extractor_run_ready (GObject* source_object,
                                                 GAsyncResult* _res_,
                                                 gpointer _user_data_)
{
	RygelMediaExportPlaylistExtractorRunData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	rygel_media_export_playlist_extractor_real_run_co (_data_);
}

static void
_g_object_unref0_ (gpointer var)
{
	(var == NULL) ? NULL : (var = (g_object_unref (var), NULL));
}

static inline void
_g_list_free__g_object_unref0_ (GList* self)
{
	g_list_free_full (self, (GDestroyNotify) _g_object_unref0_);
}

static gboolean
rygel_media_export_playlist_extractor_real_run_co (RygelMediaExportPlaylistExtractorRunData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		case 2:
		goto _state_2;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_state_ = 1;
	RYGEL_MEDIA_EXPORT_EXTRACTOR_CLASS (rygel_media_export_playlist_extractor_parent_class)->run (G_TYPE_CHECK_INSTANCE_CAST (_data_->self, RYGEL_MEDIA_EXPORT_TYPE_EXTRACTOR, RygelMediaExportExtractor), rygel_media_export_playlist_extractor_run_ready, _data_);
	return FALSE;
	_state_1:
	RYGEL_MEDIA_EXPORT_EXTRACTOR_CLASS (rygel_media_export_playlist_extractor_parent_class)->run_finish (G_TYPE_CHECK_INSTANCE_CAST (_data_->self, RYGEL_MEDIA_EXPORT_TYPE_EXTRACTOR, RygelMediaExportExtractor), _data_->_res_, &_data_->_inner_error0_);
	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;
	}
	_data_->contents_length1 = 0;
	_data_->_contents_size_ = 0;
	_data_->_tmp1_ = rygel_media_export_extractor_get_file ((RygelMediaExportExtractor*) _data_->self);
	_data_->_tmp2_ = _data_->_tmp1_;
	_data_->_tmp3_ = NULL;
	_data_->_tmp4_ = 0;
	_data_->_state_ = 2;
	g_file_load_contents_async (_data_->_tmp2_, NULL, rygel_media_export_playlist_extractor_run_ready, _data_);
	return FALSE;
	_state_2:
	_data_->_tmp5_ = g_file_load_contents_finish (_data_->_tmp2_, _data_->_res_, &_data_->_tmp3_, &_data_->_tmp4_, NULL, &_data_->_inner_error0_);
	_data_->contents = (g_free (_data_->contents), NULL);
	_data_->contents = _data_->_tmp3_;
	_data_->contents_length1 = _data_->_tmp4_;
	_data_->_contents_size_ = _data_->contents_length1;
	_data_->_tmp0_ = _data_->_tmp5_;
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
		_data_->contents = (g_free (_data_->contents), NULL);
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	if (!_data_->_tmp0_) {
		_data_->_tmp6_ = g_error_new_literal (EXTRACTOR_ERROR, EXTRACTOR_ERROR_INVALID, "Failed to read file");
		_data_->_inner_error0_ = _data_->_tmp6_;
		g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
		_data_->contents = (g_free (_data_->contents), NULL);
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->i = 0;
	while (TRUE) {
		_data_->_tmp8_ = _data_->contents;
		_data_->_tmp8__length1 = _data_->contents_length1;
		_data_->_tmp9_ = _data_->_tmp8_[_data_->i];
		if (g_ascii_isspace ((gchar) _data_->_tmp9_)) {
			_data_->_tmp10_ = _data_->contents;
			_data_->_tmp10__length1 = _data_->contents_length1;
			_data_->_tmp7_ = _data_->i < _data_->_tmp10__length1;
		} else {
			_data_->_tmp7_ = FALSE;
		}
		if (!_data_->_tmp7_) {
			break;
		}
		_data_->_tmp11_ = _data_->i;
		_data_->i = _data_->_tmp11_ + 1;
	}
	_data_->_tmp12_ = _data_->contents;
	_data_->_tmp12__length1 = _data_->contents_length1;
	_data_->_tmp13_ = _data_->_tmp12_[_data_->i];
	if (_data_->_tmp13_ != ((guint8) '<')) {
		_data_->_tmp14_ = g_error_new_literal (EXTRACTOR_ERROR, EXTRACTOR_ERROR_INVALID, "Not an XML file");
		_data_->_inner_error0_ = _data_->_tmp14_;
		g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
		_data_->contents = (g_free (_data_->contents), NULL);
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_tmp15_ = _data_->contents;
	_data_->_tmp15__length1 = _data_->contents_length1;
	_data_->_tmp16_ = gupnp_media_collection_new_from_string ((const gchar*) _data_->_tmp15_);
	_data_->didl_s = _data_->_tmp16_;
	_data_->_tmp17_ = _data_->didl_s;
	_data_->_tmp18_ = gupnp_media_collection_get_author (_data_->_tmp17_);
	_data_->_tmp19_ = _data_->_tmp18_;
	_data_->_tmp20_ = g_strdup (_data_->_tmp19_);
	_data_->author = _data_->_tmp20_;
	_data_->_tmp21_ = _data_->didl_s;
	_data_->_tmp22_ = gupnp_media_collection_get_title (_data_->_tmp21_);
	_data_->_tmp23_ = _data_->_tmp22_;
	_data_->_tmp24_ = g_strdup (_data_->_tmp23_);
	_data_->title = _data_->_tmp24_;
	_data_->_tmp27_ = _data_->author;
	if (_data_->_tmp27_ == NULL) {
		_data_->_tmp28_ = _data_->title;
		_data_->_tmp26_ = _data_->_tmp28_ == NULL;
	} else {
		_data_->_tmp26_ = FALSE;
	}
	if (_data_->_tmp26_) {
		_data_->_tmp29_ = _data_->didl_s;
		_data_->_tmp30_ = gupnp_media_collection_get_items (_data_->_tmp29_);
		_data_->_tmp31_ = _data_->_tmp30_;
		_data_->_tmp25_ = _data_->_tmp31_ == NULL;
		(_data_->_tmp31_ == NULL) ? NULL : (_data_->_tmp31_ = (_g_list_free__g_object_unref0_ (_data_->_tmp31_), NULL));
	} else {
		_data_->_tmp25_ = FALSE;
	}
	if (_data_->_tmp25_) {
		_data_->_tmp32_ = g_error_new_literal (EXTRACTOR_ERROR, EXTRACTOR_ERROR_INVALID, "Not a DIDL-Lite playlist");
		_data_->_inner_error0_ = _data_->_tmp32_;
		g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
		_g_free0 (_data_->title);
		_g_free0 (_data_->author);
		_g_object_unref0 (_data_->didl_s);
		_data_->contents = (g_free (_data_->contents), NULL);
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_tmp33_ = _data_->title;
	if (_data_->_tmp33_ != NULL) {
		_data_->_tmp34_ = ((RygelMediaExportExtractor*) _data_->self)->serialized_info;
		_data_->_tmp35_ = _data_->title;
		g_variant_dict_insert (_data_->_tmp34_, RYGEL_MEDIA_EXPORT_SERIALIZER_TITLE, "s", _data_->_tmp35_, NULL);
	}
	_data_->_tmp36_ = _data_->author;
	if (_data_->_tmp36_ != NULL) {
		_data_->_tmp37_ = ((RygelMediaExportExtractor*) _data_->self)->serialized_info;
		_data_->_tmp38_ = _data_->author;
		g_variant_dict_insert (_data_->_tmp37_, RYGEL_MEDIA_EXPORT_SERIALIZER_ARTIST, "s", _data_->_tmp38_, NULL);
	}
	_data_->_tmp39_ = ((RygelMediaExportExtractor*) _data_->self)->serialized_info;
	g_variant_dict_insert (_data_->_tmp39_, RYGEL_MEDIA_EXPORT_SERIALIZER_DLNA_PROFILE, "s", "DIDL_S", NULL);
	_data_->_tmp40_ = ((RygelMediaExportExtractor*) _data_->self)->serialized_info;
	g_variant_dict_insert (_data_->_tmp40_, RYGEL_MEDIA_EXPORT_SERIALIZER_UPNP_CLASS, "s", UPNP_CLASS_PLAYLIST, NULL);
	_g_free0 (_data_->title);
	_g_free0 (_data_->author);
	_g_object_unref0 (_data_->didl_s);
	_data_->contents = (g_free (_data_->contents), 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 void
rygel_media_export_playlist_extractor_class_init (RygelMediaExportPlaylistExtractorClass * klass,
                                                  gpointer klass_data)
{
	rygel_media_export_playlist_extractor_parent_class = g_type_class_peek_parent (klass);
	((RygelMediaExportExtractorClass *) klass)->run = (void (*) (RygelMediaExportExtractor*, GAsyncReadyCallback, gpointer)) rygel_media_export_playlist_extractor_real_run;
	((RygelMediaExportExtractorClass *) klass)->run_finish = (void (*) (RygelMediaExportExtractor*, GAsyncResult*, GError**)) rygel_media_export_playlist_extractor_run_finish;
}

static void
rygel_media_export_playlist_extractor_instance_init (RygelMediaExportPlaylistExtractor * self,
                                                     gpointer klass)
{
}

static GType
rygel_media_export_playlist_extractor_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (RygelMediaExportPlaylistExtractorClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) rygel_media_export_playlist_extractor_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (RygelMediaExportPlaylistExtractor), 0, (GInstanceInitFunc) rygel_media_export_playlist_extractor_instance_init, NULL };
	GType rygel_media_export_playlist_extractor_type_id;
	rygel_media_export_playlist_extractor_type_id = g_type_register_static (RYGEL_MEDIA_EXPORT_TYPE_EXTRACTOR, "RygelMediaExportPlaylistExtractor", &g_define_type_info, 0);
	return rygel_media_export_playlist_extractor_type_id;
}

GType
rygel_media_export_playlist_extractor_get_type (void)
{
	static volatile gsize rygel_media_export_playlist_extractor_type_id__once = 0;
	if (g_once_init_enter (&rygel_media_export_playlist_extractor_type_id__once)) {
		GType rygel_media_export_playlist_extractor_type_id;
		rygel_media_export_playlist_extractor_type_id = rygel_media_export_playlist_extractor_get_type_once ();
		g_once_init_leave (&rygel_media_export_playlist_extractor_type_id__once, rygel_media_export_playlist_extractor_type_id);
	}
	return rygel_media_export_playlist_extractor_type_id__once;
}

