/* rygel-gst-launch-root-container.c generated by valac 0.32.1, the Vala compiler
 * generated from rygel-gst-launch-root-container.vala, do not modify */

/*
 * Copyright (C) 2009 Thijs Vermeir <thijsvermeir@gmail.com>
 *
 * Author: Thijs Vermeir <thijsvermeir@gmail.com>
 *
 * 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 <rygel-core.h>
#include <stdlib.h>
#include <string.h>
#include <gee.h>


#define RYGEL_GST_LAUNCH_TYPE_ROOT_CONTAINER (rygel_gst_launch_root_container_get_type ())
#define RYGEL_GST_LAUNCH_ROOT_CONTAINER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), RYGEL_GST_LAUNCH_TYPE_ROOT_CONTAINER, RygelGstLaunchRootContainer))
#define RYGEL_GST_LAUNCH_ROOT_CONTAINER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), RYGEL_GST_LAUNCH_TYPE_ROOT_CONTAINER, RygelGstLaunchRootContainerClass))
#define RYGEL_GST_LAUNCH_IS_ROOT_CONTAINER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), RYGEL_GST_LAUNCH_TYPE_ROOT_CONTAINER))
#define RYGEL_GST_LAUNCH_IS_ROOT_CONTAINER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), RYGEL_GST_LAUNCH_TYPE_ROOT_CONTAINER))
#define RYGEL_GST_LAUNCH_ROOT_CONTAINER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), RYGEL_GST_LAUNCH_TYPE_ROOT_CONTAINER, RygelGstLaunchRootContainerClass))

typedef struct _RygelGstLaunchRootContainer RygelGstLaunchRootContainer;
typedef struct _RygelGstLaunchRootContainerClass RygelGstLaunchRootContainerClass;
typedef struct _RygelGstLaunchRootContainerPrivate RygelGstLaunchRootContainerPrivate;
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_free0(var) (var = (g_free (var), NULL))
#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))

#define RYGEL_GST_LAUNCH_TYPE_AUDIO_ITEM (rygel_gst_launch_audio_item_get_type ())
#define RYGEL_GST_LAUNCH_AUDIO_ITEM(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), RYGEL_GST_LAUNCH_TYPE_AUDIO_ITEM, RygelGstLaunchAudioItem))
#define RYGEL_GST_LAUNCH_AUDIO_ITEM_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), RYGEL_GST_LAUNCH_TYPE_AUDIO_ITEM, RygelGstLaunchAudioItemClass))
#define RYGEL_GST_LAUNCH_IS_AUDIO_ITEM(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), RYGEL_GST_LAUNCH_TYPE_AUDIO_ITEM))
#define RYGEL_GST_LAUNCH_IS_AUDIO_ITEM_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), RYGEL_GST_LAUNCH_TYPE_AUDIO_ITEM))
#define RYGEL_GST_LAUNCH_AUDIO_ITEM_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), RYGEL_GST_LAUNCH_TYPE_AUDIO_ITEM, RygelGstLaunchAudioItemClass))

typedef struct _RygelGstLaunchAudioItem RygelGstLaunchAudioItem;
typedef struct _RygelGstLaunchAudioItemClass RygelGstLaunchAudioItemClass;

#define RYGEL_GST_LAUNCH_TYPE_VIDEO_ITEM (rygel_gst_launch_video_item_get_type ())
#define RYGEL_GST_LAUNCH_VIDEO_ITEM(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), RYGEL_GST_LAUNCH_TYPE_VIDEO_ITEM, RygelGstLaunchVideoItem))
#define RYGEL_GST_LAUNCH_VIDEO_ITEM_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), RYGEL_GST_LAUNCH_TYPE_VIDEO_ITEM, RygelGstLaunchVideoItemClass))
#define RYGEL_GST_LAUNCH_IS_VIDEO_ITEM(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), RYGEL_GST_LAUNCH_TYPE_VIDEO_ITEM))
#define RYGEL_GST_LAUNCH_IS_VIDEO_ITEM_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), RYGEL_GST_LAUNCH_TYPE_VIDEO_ITEM))
#define RYGEL_GST_LAUNCH_VIDEO_ITEM_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), RYGEL_GST_LAUNCH_TYPE_VIDEO_ITEM, RygelGstLaunchVideoItemClass))

typedef struct _RygelGstLaunchVideoItem RygelGstLaunchVideoItem;
typedef struct _RygelGstLaunchVideoItemClass RygelGstLaunchVideoItemClass;

struct _RygelGstLaunchRootContainer {
	RygelSimpleContainer parent_instance;
	RygelGstLaunchRootContainerPrivate * priv;
};

struct _RygelGstLaunchRootContainerClass {
	RygelSimpleContainerClass parent_class;
};

struct _RygelGstLaunchRootContainerPrivate {
	RygelMetaConfig* config;
};


static gpointer rygel_gst_launch_root_container_parent_class = NULL;

GType rygel_gst_launch_root_container_get_type (void) G_GNUC_CONST;
#define RYGEL_GST_LAUNCH_ROOT_CONTAINER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), RYGEL_GST_LAUNCH_TYPE_ROOT_CONTAINER, RygelGstLaunchRootContainerPrivate))
enum  {
	RYGEL_GST_LAUNCH_ROOT_CONTAINER_DUMMY_PROPERTY
};
#define RYGEL_GST_LAUNCH_ROOT_CONTAINER_CONFIG_GROUP "GstLaunch"
#define RYGEL_GST_LAUNCH_ROOT_CONTAINER_ITEM_NAMES "launch-items"
RygelGstLaunchRootContainer* rygel_gst_launch_root_container_new (const gchar* title);
RygelGstLaunchRootContainer* rygel_gst_launch_root_container_construct (GType object_type, const gchar* title);
static void rygel_gst_launch_root_container_add_launch_item (RygelGstLaunchRootContainer* self, const gchar* name);
RygelGstLaunchAudioItem* rygel_gst_launch_audio_item_new (const gchar* id, RygelMediaContainer* parent, const gchar* title, const gchar* mime_type, const gchar* launch_line);
RygelGstLaunchAudioItem* rygel_gst_launch_audio_item_construct (GType object_type, const gchar* id, RygelMediaContainer* parent, const gchar* title, const gchar* mime_type, const gchar* launch_line);
GType rygel_gst_launch_audio_item_get_type (void) G_GNUC_CONST;
RygelGstLaunchVideoItem* rygel_gst_launch_video_item_new (const gchar* id, RygelMediaContainer* parent, const gchar* title, const gchar* mime_type, const gchar* launch_line);
RygelGstLaunchVideoItem* rygel_gst_launch_video_item_construct (GType object_type, const gchar* id, RygelMediaContainer* parent, const gchar* title, const gchar* mime_type, const gchar* launch_line);
GType rygel_gst_launch_video_item_get_type (void) G_GNUC_CONST;
static void rygel_gst_launch_root_container_finalize (GObject* obj);


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


RygelGstLaunchRootContainer* rygel_gst_launch_root_container_construct (GType object_type, const gchar* title) {
	RygelGstLaunchRootContainer * self = NULL;
	const gchar* _tmp0_ = NULL;
	GError * _inner_error_ = NULL;
	g_return_val_if_fail (title != NULL, NULL);
	_tmp0_ = title;
	self = (RygelGstLaunchRootContainer*) rygel_simple_container_construct_root (object_type, _tmp0_);
	{
		RygelMetaConfig* _tmp1_ = NULL;
		GeeArrayList* item_names = NULL;
		RygelMetaConfig* _tmp2_ = NULL;
		GeeArrayList* _tmp3_ = NULL;
		_tmp1_ = rygel_meta_config_get_default ();
		_g_object_unref0 (self->priv->config);
		self->priv->config = _tmp1_;
		_tmp2_ = self->priv->config;
		_tmp3_ = rygel_configuration_get_string_list ((RygelConfiguration*) _tmp2_, RYGEL_GST_LAUNCH_ROOT_CONTAINER_CONFIG_GROUP, RYGEL_GST_LAUNCH_ROOT_CONTAINER_ITEM_NAMES, &_inner_error_);
		item_names = _tmp3_;
		if (G_UNLIKELY (_inner_error_ != NULL)) {
			goto __catch0_g_error;
		}
		{
			GeeArrayList* _name_list = NULL;
			GeeArrayList* _tmp4_ = NULL;
			GeeArrayList* _tmp5_ = NULL;
			gint _name_size = 0;
			GeeArrayList* _tmp6_ = NULL;
			gint _tmp7_ = 0;
			gint _tmp8_ = 0;
			gint _name_index = 0;
			_tmp4_ = item_names;
			_tmp5_ = _g_object_ref0 (_tmp4_);
			_name_list = _tmp5_;
			_tmp6_ = _name_list;
			_tmp7_ = gee_abstract_collection_get_size ((GeeCollection*) _tmp6_);
			_tmp8_ = _tmp7_;
			_name_size = _tmp8_;
			_name_index = -1;
			while (TRUE) {
				gint _tmp9_ = 0;
				gint _tmp10_ = 0;
				gint _tmp11_ = 0;
				gchar* name = NULL;
				GeeArrayList* _tmp12_ = NULL;
				gint _tmp13_ = 0;
				gpointer _tmp14_ = NULL;
				const gchar* _tmp15_ = NULL;
				_tmp9_ = _name_index;
				_name_index = _tmp9_ + 1;
				_tmp10_ = _name_index;
				_tmp11_ = _name_size;
				if (!(_tmp10_ < _tmp11_)) {
					break;
				}
				_tmp12_ = _name_list;
				_tmp13_ = _name_index;
				_tmp14_ = gee_abstract_list_get ((GeeAbstractList*) _tmp12_, _tmp13_);
				name = (gchar*) _tmp14_;
				_tmp15_ = name;
				rygel_gst_launch_root_container_add_launch_item (self, _tmp15_);
				_g_free0 (name);
			}
			_g_object_unref0 (_name_list);
		}
		_g_object_unref0 (item_names);
	}
	goto __finally0;
	__catch0_g_error:
	{
		GError* err = NULL;
		GError* _tmp16_ = NULL;
		const gchar* _tmp17_ = NULL;
		err = _inner_error_;
		_inner_error_ = NULL;
		_tmp16_ = err;
		_tmp17_ = _tmp16_->message;
		g_debug ("rygel-gst-launch-root-container.vala:43: GstLaunch init failed: %s", _tmp17_);
		_g_error_free0 (err);
	}
	__finally0:
	if (G_UNLIKELY (_inner_error_ != NULL)) {
		g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
		g_clear_error (&_inner_error_);
		return NULL;
	}
	return self;
}


RygelGstLaunchRootContainer* rygel_gst_launch_root_container_new (const gchar* title) {
	return rygel_gst_launch_root_container_construct (RYGEL_GST_LAUNCH_TYPE_ROOT_CONTAINER, title);
}


static void rygel_gst_launch_root_container_add_launch_item (RygelGstLaunchRootContainer* self, const gchar* name) {
	GError * _inner_error_ = NULL;
	g_return_if_fail (self != NULL);
	g_return_if_fail (name != NULL);
	{
		gchar* title = NULL;
		RygelMetaConfig* _tmp0_ = NULL;
		const gchar* _tmp1_ = NULL;
		gchar* _tmp2_ = NULL;
		gchar* _tmp3_ = NULL;
		gchar* _tmp4_ = NULL;
		gchar* _tmp5_ = NULL;
		gchar* mime_type = NULL;
		RygelMetaConfig* _tmp6_ = NULL;
		const gchar* _tmp7_ = NULL;
		gchar* _tmp8_ = NULL;
		gchar* _tmp9_ = NULL;
		gchar* _tmp10_ = NULL;
		gchar* _tmp11_ = NULL;
		gchar* launch_line = NULL;
		RygelMetaConfig* _tmp12_ = NULL;
		const gchar* _tmp13_ = NULL;
		gchar* _tmp14_ = NULL;
		gchar* _tmp15_ = NULL;
		gchar* _tmp16_ = NULL;
		gchar* _tmp17_ = NULL;
		gchar* dlna_profile = NULL;
		RygelMediaFileItem* item = NULL;
		const gchar* _tmp26_ = NULL;
		gboolean _tmp27_ = FALSE;
		RygelMediaFileItem* _tmp38_ = NULL;
		_tmp0_ = self->priv->config;
		_tmp1_ = name;
		_tmp2_ = g_strdup_printf ("%s-title", _tmp1_);
		_tmp3_ = _tmp2_;
		_tmp4_ = rygel_configuration_get_string ((RygelConfiguration*) _tmp0_, RYGEL_GST_LAUNCH_ROOT_CONTAINER_CONFIG_GROUP, _tmp3_, &_inner_error_);
		_tmp5_ = _tmp4_;
		_g_free0 (_tmp3_);
		title = _tmp5_;
		if (G_UNLIKELY (_inner_error_ != NULL)) {
			goto __catch1_g_error;
		}
		_tmp6_ = self->priv->config;
		_tmp7_ = name;
		_tmp8_ = g_strdup_printf ("%s-mime", _tmp7_);
		_tmp9_ = _tmp8_;
		_tmp10_ = rygel_configuration_get_string ((RygelConfiguration*) _tmp6_, RYGEL_GST_LAUNCH_ROOT_CONTAINER_CONFIG_GROUP, _tmp9_, &_inner_error_);
		_tmp11_ = _tmp10_;
		_g_free0 (_tmp9_);
		mime_type = _tmp11_;
		if (G_UNLIKELY (_inner_error_ != NULL)) {
			_g_free0 (title);
			goto __catch1_g_error;
		}
		_tmp12_ = self->priv->config;
		_tmp13_ = name;
		_tmp14_ = g_strdup_printf ("%s-launch", _tmp13_);
		_tmp15_ = _tmp14_;
		_tmp16_ = rygel_configuration_get_string ((RygelConfiguration*) _tmp12_, RYGEL_GST_LAUNCH_ROOT_CONTAINER_CONFIG_GROUP, _tmp15_, &_inner_error_);
		_tmp17_ = _tmp16_;
		_g_free0 (_tmp15_);
		launch_line = _tmp17_;
		if (G_UNLIKELY (_inner_error_ != NULL)) {
			_g_free0 (mime_type);
			_g_free0 (title);
			goto __catch1_g_error;
		}
		dlna_profile = NULL;
		{
			gchar* _tmp18_ = NULL;
			RygelMetaConfig* _tmp19_ = NULL;
			const gchar* _tmp20_ = NULL;
			gchar* _tmp21_ = NULL;
			gchar* _tmp22_ = NULL;
			gchar* _tmp23_ = NULL;
			gchar* _tmp24_ = NULL;
			gchar* _tmp25_ = NULL;
			_tmp19_ = self->priv->config;
			_tmp20_ = name;
			_tmp21_ = g_strdup_printf ("%s-dlnaprofile", _tmp20_);
			_tmp22_ = _tmp21_;
			_tmp23_ = rygel_configuration_get_string ((RygelConfiguration*) _tmp19_, RYGEL_GST_LAUNCH_ROOT_CONTAINER_CONFIG_GROUP, _tmp22_, &_inner_error_);
			_tmp24_ = _tmp23_;
			_g_free0 (_tmp22_);
			_tmp18_ = _tmp24_;
			if (G_UNLIKELY (_inner_error_ != NULL)) {
				goto __catch2_g_error;
			}
			_tmp25_ = _tmp18_;
			_tmp18_ = NULL;
			_g_free0 (dlna_profile);
			dlna_profile = _tmp25_;
			_g_free0 (_tmp18_);
		}
		goto __finally2;
		__catch2_g_error:
		{
			GError* _error_ = NULL;
			_error_ = _inner_error_;
			_inner_error_ = NULL;
			_g_error_free0 (_error_);
		}
		__finally2:
		if (G_UNLIKELY (_inner_error_ != NULL)) {
			_g_object_unref0 (item);
			_g_free0 (dlna_profile);
			_g_free0 (launch_line);
			_g_free0 (mime_type);
			_g_free0 (title);
			goto __catch1_g_error;
		}
		_tmp26_ = mime_type;
		_tmp27_ = g_str_has_prefix (_tmp26_, "audio");
		if (_tmp27_) {
			const gchar* _tmp28_ = NULL;
			const gchar* _tmp29_ = NULL;
			const gchar* _tmp30_ = NULL;
			const gchar* _tmp31_ = NULL;
			RygelGstLaunchAudioItem* _tmp32_ = NULL;
			_tmp28_ = name;
			_tmp29_ = title;
			_tmp30_ = mime_type;
			_tmp31_ = launch_line;
			_tmp32_ = rygel_gst_launch_audio_item_new (_tmp28_, (RygelMediaContainer*) self, _tmp29_, _tmp30_, _tmp31_);
			_g_object_unref0 (item);
			item = (RygelMediaFileItem*) _tmp32_;
		} else {
			const gchar* _tmp33_ = NULL;
			const gchar* _tmp34_ = NULL;
			const gchar* _tmp35_ = NULL;
			const gchar* _tmp36_ = NULL;
			RygelGstLaunchVideoItem* _tmp37_ = NULL;
			_tmp33_ = name;
			_tmp34_ = title;
			_tmp35_ = mime_type;
			_tmp36_ = launch_line;
			_tmp37_ = rygel_gst_launch_video_item_new (_tmp33_, (RygelMediaContainer*) self, _tmp34_, _tmp35_, _tmp36_);
			_g_object_unref0 (item);
			item = (RygelMediaFileItem*) _tmp37_;
		}
		_tmp38_ = item;
		if (_tmp38_ != NULL) {
			const gchar* _tmp39_ = NULL;
			RygelMediaFileItem* _tmp42_ = NULL;
			RygelMediaFileItem* _tmp43_ = NULL;
			_tmp39_ = dlna_profile;
			if (_tmp39_ != NULL) {
				RygelMediaFileItem* _tmp40_ = NULL;
				const gchar* _tmp41_ = NULL;
				_tmp40_ = item;
				_tmp41_ = dlna_profile;
				rygel_media_file_item_set_dlna_profile (_tmp40_, _tmp41_);
			}
			_tmp42_ = item;
			rygel_media_file_item_add_engine_resources (_tmp42_, NULL, NULL);
			_tmp43_ = item;
			rygel_simple_container_add_child_item ((RygelSimpleContainer*) self, (RygelMediaItem*) _tmp43_);
		}
		_g_object_unref0 (item);
		_g_free0 (dlna_profile);
		_g_free0 (launch_line);
		_g_free0 (mime_type);
		_g_free0 (title);
	}
	goto __finally1;
	__catch1_g_error:
	{
		GError* err = NULL;
		const gchar* _tmp44_ = NULL;
		GError* _tmp45_ = NULL;
		const gchar* _tmp46_ = NULL;
		err = _inner_error_;
		_inner_error_ = NULL;
		_tmp44_ = name;
		_tmp45_ = err;
		_tmp46_ = _tmp45_->message;
		g_debug ("rygel-gst-launch-root-container.vala:86: GstLaunch failed item '%s': %" \
"s", _tmp44_, _tmp46_);
		_g_error_free0 (err);
	}
	__finally1:
	if (G_UNLIKELY (_inner_error_ != NULL)) {
		g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
		g_clear_error (&_inner_error_);
		return;
	}
}


static void rygel_gst_launch_root_container_class_init (RygelGstLaunchRootContainerClass * klass) {
	rygel_gst_launch_root_container_parent_class = g_type_class_peek_parent (klass);
	g_type_class_add_private (klass, sizeof (RygelGstLaunchRootContainerPrivate));
	G_OBJECT_CLASS (klass)->finalize = rygel_gst_launch_root_container_finalize;
}


static void rygel_gst_launch_root_container_instance_init (RygelGstLaunchRootContainer * self) {
	self->priv = RYGEL_GST_LAUNCH_ROOT_CONTAINER_GET_PRIVATE (self);
}


static void rygel_gst_launch_root_container_finalize (GObject* obj) {
	RygelGstLaunchRootContainer * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, RYGEL_GST_LAUNCH_TYPE_ROOT_CONTAINER, RygelGstLaunchRootContainer);
	_g_object_unref0 (self->priv->config);
	G_OBJECT_CLASS (rygel_gst_launch_root_container_parent_class)->finalize (obj);
}


/**
 * Represents the root container for GstLaunch content hierarchy.
 */
GType rygel_gst_launch_root_container_get_type (void) {
	static volatile gsize rygel_gst_launch_root_container_type_id__volatile = 0;
	if (g_once_init_enter (&rygel_gst_launch_root_container_type_id__volatile)) {
		static const GTypeInfo g_define_type_info = { sizeof (RygelGstLaunchRootContainerClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) rygel_gst_launch_root_container_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (RygelGstLaunchRootContainer), 0, (GInstanceInitFunc) rygel_gst_launch_root_container_instance_init, NULL };
		GType rygel_gst_launch_root_container_type_id;
		rygel_gst_launch_root_container_type_id = g_type_register_static (RYGEL_TYPE_SIMPLE_CONTAINER, "RygelGstLaunchRootContainer", &g_define_type_info, 0);
		g_once_init_leave (&rygel_gst_launch_root_container_type_id__volatile, rygel_gst_launch_root_container_type_id);
	}
	return rygel_gst_launch_root_container_type_id__volatile;
}



