/* rygel-gst-launch-root-container.c generated by valac 0.16.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 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 <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_;
	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;
		RygelMetaConfig* _tmp2_;
		GeeArrayList* _tmp3_ = NULL;
		GeeArrayList* item_names;
		_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 (_inner_error_ != NULL) {
			goto __catch0_g_error;
		}
		{
			GeeArrayList* _tmp4_;
			GeeArrayList* _tmp5_;
			GeeArrayList* _name_list;
			GeeArrayList* _tmp6_;
			gint _tmp7_;
			gint _tmp8_;
			gint _name_size;
			gint _name_index;
			_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_;
				gint _tmp10_;
				gint _tmp11_;
				GeeArrayList* _tmp12_;
				gint _tmp13_;
				gpointer _tmp14_ = NULL;
				gchar* name;
				const gchar* _tmp15_;
				_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_;
		const gchar* _tmp17_;
		err = _inner_error_;
		_inner_error_ = NULL;
		_tmp16_ = err;
		_tmp17_ = _tmp16_->message;
		g_debug ("rygel-gst-launch-root-container.vala:48: GstLaunch init failed: %s", _tmp17_);
		_g_error_free0 (err);
	}
	__finally0:
	if (_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);
	{
		RygelMetaConfig* _tmp0_;
		const gchar* _tmp1_;
		gchar* _tmp2_ = NULL;
		gchar* _tmp3_;
		gchar* _tmp4_ = NULL;
		gchar* _tmp5_;
		gchar* title;
		RygelMetaConfig* _tmp6_;
		const gchar* _tmp7_;
		gchar* _tmp8_ = NULL;
		gchar* _tmp9_;
		gchar* _tmp10_ = NULL;
		gchar* _tmp11_;
		gchar* mime_type;
		RygelMetaConfig* _tmp12_;
		const gchar* _tmp13_;
		gchar* _tmp14_ = NULL;
		gchar* _tmp15_;
		gchar* _tmp16_ = NULL;
		gchar* _tmp17_;
		gchar* launch_line;
		gchar* dlna_profile;
		RygelMediaItem* item = NULL;
		const gchar* _tmp25_;
		gboolean _tmp26_ = FALSE;
		RygelMediaItem* _tmp37_;
		_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 (_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 (_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 (_inner_error_ != NULL) {
			_g_free0 (mime_type);
			_g_free0 (title);
			goto __catch1_g_error;
		}
		dlna_profile = NULL;
		{
			RygelMetaConfig* _tmp18_;
			const gchar* _tmp19_;
			gchar* _tmp20_ = NULL;
			gchar* _tmp21_;
			gchar* _tmp22_ = NULL;
			gchar* _tmp23_;
			gchar* _tmp24_;
			_tmp18_ = self->priv->config;
			_tmp19_ = name;
			_tmp20_ = g_strdup_printf ("%s-dlnaprofile", _tmp19_);
			_tmp21_ = _tmp20_;
			_tmp22_ = rygel_configuration_get_string ((RygelConfiguration*) _tmp18_, RYGEL_GST_LAUNCH_ROOT_CONTAINER_CONFIG_GROUP, _tmp21_, &_inner_error_);
			_tmp23_ = _tmp22_;
			_g_free0 (_tmp21_);
			_tmp24_ = _tmp23_;
			if (_inner_error_ != NULL) {
				goto __catch2_g_error;
			}
			_g_free0 (dlna_profile);
			dlna_profile = _tmp24_;
		}
		goto __finally2;
		__catch2_g_error:
		{
			GError* _error_ = NULL;
			_error_ = _inner_error_;
			_inner_error_ = NULL;
			_g_error_free0 (_error_);
		}
		__finally2:
		if (_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;
		}
		_tmp25_ = mime_type;
		_tmp26_ = g_str_has_prefix (_tmp25_, "audio");
		if (_tmp26_) {
			const gchar* _tmp27_;
			const gchar* _tmp28_;
			const gchar* _tmp29_;
			const gchar* _tmp30_;
			RygelGstLaunchAudioItem* _tmp31_;
			_tmp27_ = name;
			_tmp28_ = title;
			_tmp29_ = mime_type;
			_tmp30_ = launch_line;
			_tmp31_ = rygel_gst_launch_audio_item_new (_tmp27_, (RygelMediaContainer*) self, _tmp28_, _tmp29_, _tmp30_);
			_g_object_unref0 (item);
			item = (RygelMediaItem*) _tmp31_;
		} else {
			const gchar* _tmp32_;
			const gchar* _tmp33_;
			const gchar* _tmp34_;
			const gchar* _tmp35_;
			RygelGstLaunchVideoItem* _tmp36_;
			_tmp32_ = name;
			_tmp33_ = title;
			_tmp34_ = mime_type;
			_tmp35_ = launch_line;
			_tmp36_ = rygel_gst_launch_video_item_new (_tmp32_, (RygelMediaContainer*) self, _tmp33_, _tmp34_, _tmp35_);
			_g_object_unref0 (item);
			item = (RygelMediaItem*) _tmp36_;
		}
		_tmp37_ = item;
		if (_tmp37_ != NULL) {
			const gchar* _tmp38_;
			RygelMediaItem* _tmp42_;
			_tmp38_ = dlna_profile;
			if (_tmp38_ != NULL) {
				RygelMediaItem* _tmp39_;
				const gchar* _tmp40_;
				gchar* _tmp41_;
				_tmp39_ = item;
				_tmp40_ = dlna_profile;
				_tmp41_ = g_strdup (_tmp40_);
				_g_free0 (_tmp39_->dlna_profile);
				_tmp39_->dlna_profile = _tmp41_;
			}
			_tmp42_ = item;
			rygel_simple_container_add_child_item ((RygelSimpleContainer*) self, _tmp42_);
		}
		_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* _tmp43_;
		GError* _tmp44_;
		const gchar* _tmp45_;
		err = _inner_error_;
		_inner_error_ = NULL;
		_tmp43_ = name;
		_tmp44_ = err;
		_tmp45_ = _tmp44_->message;
		g_debug ("rygel-gst-launch-root-container.vala:89: GstLaunch failed item '%s': %" \
"s", _tmp43_, _tmp45_);
		_g_error_free0 (err);
	}
	__finally1:
	if (_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 = RYGEL_GST_LAUNCH_ROOT_CONTAINER (obj);
	_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;
}



