/* rygel-sink-connection-manager.c generated by valac 0.17.4.16-52707, the Vala compiler
 * generated from rygel-sink-connection-manager.vala, do not modify */

/*
 * Copyright (C) 2008 OpenedHand Ltd.
 * Copyright (C) 2009 Nokia Corporation.
 *
 * Author: Jorn Baayen <jorn@openedhand.com>
 *         Zeeshan Ali (Khattak) <zeeshanak@gnome.org>
 *                               <zeeshan.ali@nokia.com>
 *
 * 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-core.h>
#include <gst/gst.h>
#include <stdlib.h>
#include <string.h>
#include <float.h>
#include <math.h>
#include <libgupnp/gupnp.h>


#define RYGEL_TYPE_SINK_CONNECTION_MANAGER (rygel_sink_connection_manager_get_type ())
#define RYGEL_SINK_CONNECTION_MANAGER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), RYGEL_TYPE_SINK_CONNECTION_MANAGER, RygelSinkConnectionManager))
#define RYGEL_SINK_CONNECTION_MANAGER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), RYGEL_TYPE_SINK_CONNECTION_MANAGER, RygelSinkConnectionManagerClass))
#define RYGEL_IS_SINK_CONNECTION_MANAGER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), RYGEL_TYPE_SINK_CONNECTION_MANAGER))
#define RYGEL_IS_SINK_CONNECTION_MANAGER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), RYGEL_TYPE_SINK_CONNECTION_MANAGER))
#define RYGEL_SINK_CONNECTION_MANAGER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), RYGEL_TYPE_SINK_CONNECTION_MANAGER, RygelSinkConnectionManagerClass))

typedef struct _RygelSinkConnectionManager RygelSinkConnectionManager;
typedef struct _RygelSinkConnectionManagerClass RygelSinkConnectionManagerClass;
typedef struct _RygelSinkConnectionManagerPrivate RygelSinkConnectionManagerPrivate;

#define RYGEL_TYPE_MEDIA_PLAYER (rygel_media_player_get_type ())
#define RYGEL_MEDIA_PLAYER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), RYGEL_TYPE_MEDIA_PLAYER, RygelMediaPlayer))
#define RYGEL_IS_MEDIA_PLAYER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), RYGEL_TYPE_MEDIA_PLAYER))
#define RYGEL_MEDIA_PLAYER_GET_INTERFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), RYGEL_TYPE_MEDIA_PLAYER, RygelMediaPlayerIface))

typedef struct _RygelMediaPlayer RygelMediaPlayer;
typedef struct _RygelMediaPlayerIface RygelMediaPlayerIface;
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_free0(var) (var = (g_free (var), NULL))

#define RYGEL_TYPE_MEDIA_RENDERER_PLUGIN (rygel_media_renderer_plugin_get_type ())
#define RYGEL_MEDIA_RENDERER_PLUGIN(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), RYGEL_TYPE_MEDIA_RENDERER_PLUGIN, RygelMediaRendererPlugin))
#define RYGEL_MEDIA_RENDERER_PLUGIN_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), RYGEL_TYPE_MEDIA_RENDERER_PLUGIN, RygelMediaRendererPluginClass))
#define RYGEL_IS_MEDIA_RENDERER_PLUGIN(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), RYGEL_TYPE_MEDIA_RENDERER_PLUGIN))
#define RYGEL_IS_MEDIA_RENDERER_PLUGIN_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), RYGEL_TYPE_MEDIA_RENDERER_PLUGIN))
#define RYGEL_MEDIA_RENDERER_PLUGIN_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), RYGEL_TYPE_MEDIA_RENDERER_PLUGIN, RygelMediaRendererPluginClass))

typedef struct _RygelMediaRendererPlugin RygelMediaRendererPlugin;
typedef struct _RygelMediaRendererPluginClass RygelMediaRendererPluginClass;

struct _RygelSinkConnectionManager {
	RygelConnectionManager parent_instance;
	RygelSinkConnectionManagerPrivate * priv;
};

struct _RygelSinkConnectionManagerClass {
	RygelConnectionManagerClass parent_class;
};

struct _RygelMediaPlayerIface {
	GTypeInterface parent_iface;
	gboolean (*seek) (RygelMediaPlayer* self, GstClockTime time);
	gchar** (*get_protocols) (RygelMediaPlayer* self, int* result_length1);
	gchar** (*get_mime_types) (RygelMediaPlayer* self, int* result_length1);
	gchar* (*get_playback_state) (RygelMediaPlayer* self);
	void (*set_playback_state) (RygelMediaPlayer* self, const gchar* value);
	gchar* (*get_uri) (RygelMediaPlayer* self);
	void (*set_uri) (RygelMediaPlayer* self, const gchar* value);
	gdouble (*get_volume) (RygelMediaPlayer* self);
	void (*set_volume) (RygelMediaPlayer* self, gdouble value);
	gint64 (*get_duration) (RygelMediaPlayer* self);
	gchar* (*get_metadata) (RygelMediaPlayer* self);
	void (*set_metadata) (RygelMediaPlayer* self, const gchar* value);
	gchar* (*get_mime_type) (RygelMediaPlayer* self);
	void (*set_mime_type) (RygelMediaPlayer* self, const gchar* value);
	gchar* (*get_content_features) (RygelMediaPlayer* self);
	void (*set_content_features) (RygelMediaPlayer* self, const gchar* value);
	gint64 (*get_position) (RygelMediaPlayer* self);
};

struct _RygelSinkConnectionManagerPrivate {
	RygelMediaPlayer* player;
};


static gpointer rygel_sink_connection_manager_parent_class = NULL;

GType rygel_sink_connection_manager_get_type (void) G_GNUC_CONST;
GType rygel_media_player_get_type (void) G_GNUC_CONST;
#define RYGEL_SINK_CONNECTION_MANAGER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), RYGEL_TYPE_SINK_CONNECTION_MANAGER, RygelSinkConnectionManagerPrivate))
enum  {
	RYGEL_SINK_CONNECTION_MANAGER_DUMMY_PROPERTY
};
static void rygel_sink_connection_manager_real_constructed (GObject* base);
GType rygel_media_renderer_plugin_get_type (void) G_GNUC_CONST;
RygelMediaPlayer* rygel_media_renderer_plugin_get_player (RygelMediaRendererPlugin* self);
gchar** rygel_media_player_get_protocols (RygelMediaPlayer* self, int* result_length1);
gchar** rygel_media_player_get_mime_types (RygelMediaPlayer* self, int* result_length1);
RygelSinkConnectionManager* rygel_sink_connection_manager_new (void);
RygelSinkConnectionManager* rygel_sink_connection_manager_construct (GType object_type);
static void rygel_sink_connection_manager_finalize (GObject* obj);
static void _vala_array_destroy (gpointer array, gint array_length, GDestroyNotify destroy_func);
static void _vala_array_free (gpointer array, gint array_length, GDestroyNotify destroy_func);


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


static void rygel_sink_connection_manager_real_constructed (GObject* base) {
	RygelSinkConnectionManager * self;
	gchar* _tmp0_;
	GUPnPRootDevice* _tmp1_ = NULL;
	GUPnPRootDevice* _tmp2_;
	GUPnPRootDevice* _tmp3_;
	GUPnPResourceFactory* _tmp4_;
	GUPnPResourceFactory* _tmp5_;
	RygelMediaRendererPlugin* _tmp6_;
	RygelMediaRendererPlugin* _tmp7_;
	RygelMediaRendererPlugin* plugin;
	RygelMediaRendererPlugin* _tmp8_;
	RygelMediaPlayer* _tmp9_ = NULL;
	RygelMediaPlayer* _tmp10_;
	gint _tmp11_ = 0;
	gchar** _tmp12_ = NULL;
	gchar** protocols;
	gint protocols_length1;
	gint _protocols_size_;
	gchar** _tmp13_;
	gint _tmp13__length1;
	self = (RygelSinkConnectionManager*) base;
	G_OBJECT_CLASS (rygel_sink_connection_manager_parent_class)->constructed ((GObject*) G_TYPE_CHECK_INSTANCE_CAST (self, RYGEL_TYPE_CONNECTION_MANAGER, RygelConnectionManager));
	((RygelConnectionManager*) self)->rcs_id = 0;
	((RygelConnectionManager*) self)->av_transport_id = 0;
	_tmp0_ = g_strdup ("Input");
	_g_free0 (((RygelConnectionManager*) self)->direction);
	((RygelConnectionManager*) self)->direction = _tmp0_;
	g_object_get ((GUPnPService*) self, "root-device", &_tmp1_, NULL);
	_tmp2_ = _tmp1_;
	_tmp3_ = _tmp2_;
	_tmp4_ = gupnp_device_info_get_resource_factory ((GUPnPDeviceInfo*) _tmp3_);
	_tmp5_ = _tmp4_;
	_tmp6_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_TYPE (_tmp5_, RYGEL_TYPE_MEDIA_RENDERER_PLUGIN) ? ((RygelMediaRendererPlugin*) _tmp5_) : NULL);
	_tmp7_ = _tmp6_;
	_g_object_unref0 (_tmp3_);
	plugin = _tmp7_;
	_tmp8_ = plugin;
	_tmp9_ = rygel_media_renderer_plugin_get_player (_tmp8_);
	_g_object_unref0 (self->priv->player);
	self->priv->player = _tmp9_;
	_tmp10_ = self->priv->player;
	_tmp12_ = rygel_media_player_get_protocols (_tmp10_, &_tmp11_);
	protocols = _tmp12_;
	protocols_length1 = _tmp11_;
	_protocols_size_ = protocols_length1;
	_tmp13_ = protocols;
	_tmp13__length1 = protocols_length1;
	{
		gchar** protocol_collection = NULL;
		gint protocol_collection_length1 = 0;
		gint _protocol_collection_size_ = 0;
		gint protocol_it = 0;
		protocol_collection = _tmp13_;
		protocol_collection_length1 = _tmp13__length1;
		for (protocol_it = 0; protocol_it < _tmp13__length1; protocol_it = protocol_it + 1) {
			gchar* _tmp14_;
			gchar* protocol = NULL;
			_tmp14_ = g_strdup (protocol_collection[protocol_it]);
			protocol = _tmp14_;
			{
				gchar** _tmp15_;
				gint _tmp15__length1;
				const gchar* _tmp16_;
				const gchar* _tmp17_;
				RygelMediaPlayer* _tmp20_;
				gint _tmp21_ = 0;
				gchar** _tmp22_ = NULL;
				gchar** mime_types;
				gint mime_types_length1;
				gint _mime_types_size_;
				gchar** _tmp23_;
				gint _tmp23__length1;
				_tmp15_ = protocols;
				_tmp15__length1 = protocols_length1;
				_tmp16_ = _tmp15_[0];
				_tmp17_ = protocol;
				if (g_strcmp0 (_tmp16_, _tmp17_) != 0) {
					const gchar* _tmp18_;
					gchar* _tmp19_;
					_tmp18_ = ((RygelConnectionManager*) self)->sink_protocol_info;
					_tmp19_ = g_strconcat (_tmp18_, ",", NULL);
					_g_free0 (((RygelConnectionManager*) self)->sink_protocol_info);
					((RygelConnectionManager*) self)->sink_protocol_info = _tmp19_;
				}
				_tmp20_ = self->priv->player;
				_tmp22_ = rygel_media_player_get_mime_types (_tmp20_, &_tmp21_);
				mime_types = _tmp22_;
				mime_types_length1 = _tmp21_;
				_mime_types_size_ = mime_types_length1;
				_tmp23_ = mime_types;
				_tmp23__length1 = mime_types_length1;
				{
					gchar** mime_type_collection = NULL;
					gint mime_type_collection_length1 = 0;
					gint _mime_type_collection_size_ = 0;
					gint mime_type_it = 0;
					mime_type_collection = _tmp23_;
					mime_type_collection_length1 = _tmp23__length1;
					for (mime_type_it = 0; mime_type_it < _tmp23__length1; mime_type_it = mime_type_it + 1) {
						gchar* _tmp24_;
						gchar* mime_type = NULL;
						_tmp24_ = g_strdup (mime_type_collection[mime_type_it]);
						mime_type = _tmp24_;
						{
							gchar** _tmp25_;
							gint _tmp25__length1;
							const gchar* _tmp26_;
							const gchar* _tmp27_;
							const gchar* _tmp30_;
							const gchar* _tmp31_;
							gchar* _tmp32_;
							gchar* _tmp33_;
							const gchar* _tmp34_;
							gchar* _tmp35_;
							gchar* _tmp36_;
							gchar* _tmp37_;
							gchar* _tmp38_;
							gchar* _tmp39_;
							_tmp25_ = mime_types;
							_tmp25__length1 = mime_types_length1;
							_tmp26_ = _tmp25_[0];
							_tmp27_ = mime_type;
							if (g_strcmp0 (_tmp26_, _tmp27_) != 0) {
								const gchar* _tmp28_;
								gchar* _tmp29_;
								_tmp28_ = ((RygelConnectionManager*) self)->sink_protocol_info;
								_tmp29_ = g_strconcat (_tmp28_, ",", NULL);
								_g_free0 (((RygelConnectionManager*) self)->sink_protocol_info);
								((RygelConnectionManager*) self)->sink_protocol_info = _tmp29_;
							}
							_tmp30_ = ((RygelConnectionManager*) self)->sink_protocol_info;
							_tmp31_ = protocol;
							_tmp32_ = g_strconcat (_tmp31_, ":*:", NULL);
							_tmp33_ = _tmp32_;
							_tmp34_ = mime_type;
							_tmp35_ = g_strconcat (_tmp33_, _tmp34_, NULL);
							_tmp36_ = _tmp35_;
							_tmp37_ = g_strconcat (_tmp36_, ":*", NULL);
							_tmp38_ = _tmp37_;
							_tmp39_ = g_strconcat (_tmp30_, _tmp38_, NULL);
							_g_free0 (((RygelConnectionManager*) self)->sink_protocol_info);
							((RygelConnectionManager*) self)->sink_protocol_info = _tmp39_;
							_g_free0 (_tmp38_);
							_g_free0 (_tmp36_);
							_g_free0 (_tmp33_);
							_g_free0 (mime_type);
						}
					}
				}
				mime_types = (_vala_array_free (mime_types, mime_types_length1, (GDestroyNotify) g_free), NULL);
				_g_free0 (protocol);
			}
		}
	}
	protocols = (_vala_array_free (protocols, protocols_length1, (GDestroyNotify) g_free), NULL);
	_g_object_unref0 (plugin);
}


RygelSinkConnectionManager* rygel_sink_connection_manager_construct (GType object_type) {
	RygelSinkConnectionManager * self = NULL;
	self = (RygelSinkConnectionManager*) rygel_connection_manager_construct (object_type);
	return self;
}


RygelSinkConnectionManager* rygel_sink_connection_manager_new (void) {
	return rygel_sink_connection_manager_construct (RYGEL_TYPE_SINK_CONNECTION_MANAGER);
}


static void rygel_sink_connection_manager_class_init (RygelSinkConnectionManagerClass * klass) {
	rygel_sink_connection_manager_parent_class = g_type_class_peek_parent (klass);
	g_type_class_add_private (klass, sizeof (RygelSinkConnectionManagerPrivate));
	G_OBJECT_CLASS (klass)->constructed = rygel_sink_connection_manager_real_constructed;
	G_OBJECT_CLASS (klass)->finalize = rygel_sink_connection_manager_finalize;
}


static void rygel_sink_connection_manager_instance_init (RygelSinkConnectionManager * self) {
	self->priv = RYGEL_SINK_CONNECTION_MANAGER_GET_PRIVATE (self);
}


static void rygel_sink_connection_manager_finalize (GObject* obj) {
	RygelSinkConnectionManager * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, RYGEL_TYPE_SINK_CONNECTION_MANAGER, RygelSinkConnectionManager);
	_g_object_unref0 (self->priv->player);
	G_OBJECT_CLASS (rygel_sink_connection_manager_parent_class)->finalize (obj);
}


GType rygel_sink_connection_manager_get_type (void) {
	static volatile gsize rygel_sink_connection_manager_type_id__volatile = 0;
	if (g_once_init_enter (&rygel_sink_connection_manager_type_id__volatile)) {
		static const GTypeInfo g_define_type_info = { sizeof (RygelSinkConnectionManagerClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) rygel_sink_connection_manager_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (RygelSinkConnectionManager), 0, (GInstanceInitFunc) rygel_sink_connection_manager_instance_init, NULL };
		GType rygel_sink_connection_manager_type_id;
		rygel_sink_connection_manager_type_id = g_type_register_static (RYGEL_TYPE_CONNECTION_MANAGER, "RygelSinkConnectionManager", &g_define_type_info, 0);
		g_once_init_leave (&rygel_sink_connection_manager_type_id__volatile, rygel_sink_connection_manager_type_id);
	}
	return rygel_sink_connection_manager_type_id__volatile;
}


static void _vala_array_destroy (gpointer array, gint array_length, GDestroyNotify destroy_func) {
	if ((array != NULL) && (destroy_func != NULL)) {
		int 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, gint array_length, GDestroyNotify destroy_func) {
	_vala_array_destroy (array, array_length, destroy_func);
	g_free (array);
}



