/* rygel-gst-launch-root-container.c generated by valac 0.42.2, 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;
enum  {
	RYGEL_GST_LAUNCH_ROOT_CONTAINER_0_PROPERTY,
	RYGEL_GST_LAUNCH_ROOT_CONTAINER_NUM_PROPERTIES
};
static GParamSpec* rygel_gst_launch_root_container_properties[RYGEL_GST_LAUNCH_ROOT_CONTAINER_NUM_PROPERTIES];
#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 gint RygelGstLaunchRootContainer_private_offset;
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_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 inline gpointer
rygel_gst_launch_root_container_get_instance_private (RygelGstLaunchRootContainer* self)
{
	return G_STRUCT_MEMBER_P (self, RygelGstLaunchRootContainer_private_offset);
}


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;
	GError * _inner_error_ = NULL;
	g_return_val_if_fail (title != NULL, NULL);
	self = (RygelGstLaunchRootContainer*) rygel_simple_container_construct_root (object_type, title);
	{
		RygelMetaConfig* _tmp0_;
		GeeArrayList* item_names = NULL;
		RygelMetaConfig* _tmp1_;
		GeeArrayList* _tmp2_;
		_tmp0_ = rygel_meta_config_get_default ();
		_g_object_unref0 (self->priv->config);
		self->priv->config = _tmp0_;
		_tmp1_ = self->priv->config;
		_tmp2_ = rygel_configuration_get_string_list ((RygelConfiguration*) _tmp1_, RYGEL_GST_LAUNCH_ROOT_CONTAINER_CONFIG_GROUP, RYGEL_GST_LAUNCH_ROOT_CONTAINER_ITEM_NAMES, &_inner_error_);
		item_names = _tmp2_;
		if (G_UNLIKELY (_inner_error_ != NULL)) {
			goto __catch0_g_error;
		}
		{
			GeeArrayList* _name_list = NULL;
			GeeArrayList* _tmp3_;
			GeeArrayList* _tmp4_;
			gint _name_size = 0;
			GeeArrayList* _tmp5_;
			gint _tmp6_;
			gint _tmp7_;
			gint _name_index = 0;
			_tmp3_ = item_names;
			_tmp4_ = _g_object_ref0 (_tmp3_);
			_name_list = _tmp4_;
			_tmp5_ = _name_list;
			_tmp6_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp5_);
			_tmp7_ = _tmp6_;
			_name_size = _tmp7_;
			_name_index = -1;
			while (TRUE) {
				gint _tmp8_;
				gint _tmp9_;
				gint _tmp10_;
				gchar* name = NULL;
				GeeArrayList* _tmp11_;
				gint _tmp12_;
				gpointer _tmp13_;
				const gchar* _tmp14_;
				_tmp8_ = _name_index;
				_name_index = _tmp8_ + 1;
				_tmp9_ = _name_index;
				_tmp10_ = _name_size;
				if (!(_tmp9_ < _tmp10_)) {
					break;
				}
				_tmp11_ = _name_list;
				_tmp12_ = _name_index;
				_tmp13_ = gee_abstract_list_get ((GeeAbstractList*) _tmp11_, _tmp12_);
				name = (gchar*) _tmp13_;
				_tmp14_ = name;
				rygel_gst_launch_root_container_add_launch_item (self, _tmp14_);
				_g_free0 (name);
			}
			_g_object_unref0 (_name_list);
		}
		_g_object_unref0 (item_names);
	}
	goto __finally0;
	__catch0_g_error:
	{
		GError* err = NULL;
		GError* _tmp15_;
		const gchar* _tmp16_;
		err = _inner_error_;
		_inner_error_ = NULL;
		_tmp15_ = err;
		_tmp16_ = _tmp15_->message;
		g_debug ("rygel-gst-launch-root-container.vala:43: GstLaunch init failed: %s", _tmp16_);
		_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_;
		gchar* _tmp1_;
		gchar* _tmp2_;
		gchar* _tmp3_;
		gchar* _tmp4_;
		gchar* mime_type = NULL;
		RygelMetaConfig* _tmp5_;
		gchar* _tmp6_;
		gchar* _tmp7_;
		gchar* _tmp8_;
		gchar* _tmp9_;
		gchar* launch_line = NULL;
		RygelMetaConfig* _tmp10_;
		gchar* _tmp11_;
		gchar* _tmp12_;
		gchar* _tmp13_;
		gchar* _tmp14_;
		gchar* dlna_profile = NULL;
		RygelMediaFileItem* item = NULL;
		const gchar* _tmp22_;
		RygelMediaFileItem* _tmp31_;
		_tmp0_ = self->priv->config;
		_tmp1_ = g_strdup_printf ("%s-title", name);
		_tmp2_ = _tmp1_;
		_tmp3_ = rygel_configuration_get_string ((RygelConfiguration*) _tmp0_, RYGEL_GST_LAUNCH_ROOT_CONTAINER_CONFIG_GROUP, _tmp2_, &_inner_error_);
		_tmp4_ = _tmp3_;
		_g_free0 (_tmp2_);
		title = _tmp4_;
		if (G_UNLIKELY (_inner_error_ != NULL)) {
			goto __catch1_g_error;
		}
		_tmp5_ = self->priv->config;
		_tmp6_ = g_strdup_printf ("%s-mime", name);
		_tmp7_ = _tmp6_;
		_tmp8_ = rygel_configuration_get_string ((RygelConfiguration*) _tmp5_, RYGEL_GST_LAUNCH_ROOT_CONTAINER_CONFIG_GROUP, _tmp7_, &_inner_error_);
		_tmp9_ = _tmp8_;
		_g_free0 (_tmp7_);
		mime_type = _tmp9_;
		if (G_UNLIKELY (_inner_error_ != NULL)) {
			_g_free0 (title);
			goto __catch1_g_error;
		}
		_tmp10_ = self->priv->config;
		_tmp11_ = g_strdup_printf ("%s-launch", name);
		_tmp12_ = _tmp11_;
		_tmp13_ = rygel_configuration_get_string ((RygelConfiguration*) _tmp10_, RYGEL_GST_LAUNCH_ROOT_CONTAINER_CONFIG_GROUP, _tmp12_, &_inner_error_);
		_tmp14_ = _tmp13_;
		_g_free0 (_tmp12_);
		launch_line = _tmp14_;
		if (G_UNLIKELY (_inner_error_ != NULL)) {
			_g_free0 (mime_type);
			_g_free0 (title);
			goto __catch1_g_error;
		}
		dlna_profile = NULL;
		{
			gchar* _tmp15_ = NULL;
			RygelMetaConfig* _tmp16_;
			gchar* _tmp17_;
			gchar* _tmp18_;
			gchar* _tmp19_;
			gchar* _tmp20_;
			gchar* _tmp21_;
			_tmp16_ = self->priv->config;
			_tmp17_ = g_strdup_printf ("%s-dlnaprofile", name);
			_tmp18_ = _tmp17_;
			_tmp19_ = rygel_configuration_get_string ((RygelConfiguration*) _tmp16_, RYGEL_GST_LAUNCH_ROOT_CONTAINER_CONFIG_GROUP, _tmp18_, &_inner_error_);
			_tmp20_ = _tmp19_;
			_g_free0 (_tmp18_);
			_tmp15_ = _tmp20_;
			if (G_UNLIKELY (_inner_error_ != NULL)) {
				goto __catch2_g_error;
			}
			_tmp21_ = _tmp15_;
			_tmp15_ = NULL;
			_g_free0 (dlna_profile);
			dlna_profile = _tmp21_;
			_g_free0 (_tmp15_);
		}
		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;
		}
		_tmp22_ = mime_type;
		if (g_str_has_prefix (_tmp22_, "audio")) {
			const gchar* _tmp23_;
			const gchar* _tmp24_;
			const gchar* _tmp25_;
			RygelGstLaunchAudioItem* _tmp26_;
			_tmp23_ = title;
			_tmp24_ = mime_type;
			_tmp25_ = launch_line;
			_tmp26_ = rygel_gst_launch_audio_item_new (name, (RygelMediaContainer*) self, _tmp23_, _tmp24_, _tmp25_);
			_g_object_unref0 (item);
			item = (RygelMediaFileItem*) _tmp26_;
		} else {
			const gchar* _tmp27_;
			const gchar* _tmp28_;
			const gchar* _tmp29_;
			RygelGstLaunchVideoItem* _tmp30_;
			_tmp27_ = title;
			_tmp28_ = mime_type;
			_tmp29_ = launch_line;
			_tmp30_ = rygel_gst_launch_video_item_new (name, (RygelMediaContainer*) self, _tmp27_, _tmp28_, _tmp29_);
			_g_object_unref0 (item);
			item = (RygelMediaFileItem*) _tmp30_;
		}
		_tmp31_ = item;
		if (_tmp31_ != NULL) {
			const gchar* _tmp32_;
			RygelMediaFileItem* _tmp35_;
			RygelMediaFileItem* _tmp36_;
			_tmp32_ = dlna_profile;
			if (_tmp32_ != NULL) {
				RygelMediaFileItem* _tmp33_;
				const gchar* _tmp34_;
				_tmp33_ = item;
				_tmp34_ = dlna_profile;
				rygel_media_file_item_set_dlna_profile (_tmp33_, _tmp34_);
			}
			_tmp35_ = item;
			rygel_media_file_item_add_engine_resources (_tmp35_, NULL, NULL);
			_tmp36_ = item;
			rygel_simple_container_add_child_item ((RygelSimpleContainer*) self, (RygelMediaItem*) _tmp36_);
		}
		_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;
		GError* _tmp37_;
		const gchar* _tmp38_;
		err = _inner_error_;
		_inner_error_ = NULL;
		_tmp37_ = err;
		_tmp38_ = _tmp37_->message;
		g_debug ("rygel-gst-launch-root-container.vala:86: GstLaunch failed item '%s': %" \
"s", name, _tmp38_);
		_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_adjust_private_offset (klass, &RygelGstLaunchRootContainer_private_offset);
	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_instance_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);
		RygelGstLaunchRootContainer_private_offset = g_type_add_instance_private (rygel_gst_launch_root_container_type_id, sizeof (RygelGstLaunchRootContainerPrivate));
		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;
}



