/* rygel-root-device.c generated by valac 0.18.1, the Vala compiler
 * generated from rygel-root-device.vala, do not modify */

/*
 * Copyright (C) 2008 Nokia Corporation.
 * Copyright (C) 2008 Zeeshan Ali (Khattak) <zeeshanak@gnome.org>.
 * Copyright (C) 2012 Openismus GmbH.
 *
 * Author: Zeeshan Ali (Khattak) <zeeshanak@gnome.org>
 *         Jens Georg <jensg@openismus.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 <libgupnp/gupnp.h>
#include <gee.h>
#include <stdlib.h>
#include <string.h>


#define RYGEL_TYPE_ROOT_DEVICE (rygel_root_device_get_type ())
#define RYGEL_ROOT_DEVICE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), RYGEL_TYPE_ROOT_DEVICE, RygelRootDevice))
#define RYGEL_ROOT_DEVICE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), RYGEL_TYPE_ROOT_DEVICE, RygelRootDeviceClass))
#define RYGEL_IS_ROOT_DEVICE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), RYGEL_TYPE_ROOT_DEVICE))
#define RYGEL_IS_ROOT_DEVICE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), RYGEL_TYPE_ROOT_DEVICE))
#define RYGEL_ROOT_DEVICE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), RYGEL_TYPE_ROOT_DEVICE, RygelRootDeviceClass))

typedef struct _RygelRootDevice RygelRootDevice;
typedef struct _RygelRootDeviceClass RygelRootDeviceClass;
typedef struct _RygelRootDevicePrivate RygelRootDevicePrivate;
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))

#define RYGEL_TYPE_PLUGIN (rygel_plugin_get_type ())
#define RYGEL_PLUGIN(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), RYGEL_TYPE_PLUGIN, RygelPlugin))
#define RYGEL_PLUGIN_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), RYGEL_TYPE_PLUGIN, RygelPluginClass))
#define RYGEL_IS_PLUGIN(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), RYGEL_TYPE_PLUGIN))
#define RYGEL_IS_PLUGIN_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), RYGEL_TYPE_PLUGIN))
#define RYGEL_PLUGIN_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), RYGEL_TYPE_PLUGIN, RygelPluginClass))

typedef struct _RygelPlugin RygelPlugin;
typedef struct _RygelPluginClass RygelPluginClass;

#define RYGEL_TYPE_RESOURCE_INFO (rygel_resource_info_get_type ())
#define RYGEL_RESOURCE_INFO(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), RYGEL_TYPE_RESOURCE_INFO, RygelResourceInfo))
#define RYGEL_RESOURCE_INFO_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), RYGEL_TYPE_RESOURCE_INFO, RygelResourceInfoClass))
#define RYGEL_IS_RESOURCE_INFO(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), RYGEL_TYPE_RESOURCE_INFO))
#define RYGEL_IS_RESOURCE_INFO_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), RYGEL_TYPE_RESOURCE_INFO))
#define RYGEL_RESOURCE_INFO_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), RYGEL_TYPE_RESOURCE_INFO, RygelResourceInfoClass))

typedef struct _RygelResourceInfo RygelResourceInfo;
typedef struct _RygelResourceInfoClass RygelResourceInfoClass;
typedef struct _RygelResourceInfoPrivate RygelResourceInfoPrivate;
#define _rygel_resource_info_unref0(var) ((var == NULL) ? NULL : (var = (rygel_resource_info_unref (var), NULL)))

struct _RygelRootDevice {
	GUPnPRootDevice parent_instance;
	RygelRootDevicePrivate * priv;
};

struct _RygelRootDeviceClass {
	GUPnPRootDeviceClass parent_class;
};

struct _RygelRootDevicePrivate {
	GeeArrayList* _services;
};

struct _RygelResourceInfo {
	GTypeInstance parent_instance;
	volatile int ref_count;
	RygelResourceInfoPrivate * priv;
	gchar* upnp_type;
	gchar* upnp_id;
	gchar* description_path;
	GType type;
};

struct _RygelResourceInfoClass {
	GTypeClass parent_class;
	void (*finalize) (RygelResourceInfo *self);
};


static gpointer rygel_root_device_parent_class = NULL;

GType rygel_root_device_get_type (void) G_GNUC_CONST;
#define RYGEL_ROOT_DEVICE_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), RYGEL_TYPE_ROOT_DEVICE, RygelRootDevicePrivate))
enum  {
	RYGEL_ROOT_DEVICE_DUMMY_PROPERTY,
	RYGEL_ROOT_DEVICE_SERVICES
};
GType rygel_plugin_get_type (void) G_GNUC_CONST;
RygelRootDevice* rygel_root_device_new (GUPnPContext* context, RygelPlugin* plugin, GUPnPXMLDoc* description_doc, const gchar* description_path, const gchar* description_dir);
RygelRootDevice* rygel_root_device_construct (GType object_type, GUPnPContext* context, RygelPlugin* plugin, GUPnPXMLDoc* description_doc, const gchar* description_path, const gchar* description_dir);
void rygel_root_device_set_services (RygelRootDevice* self, GeeArrayList* value);
gpointer rygel_resource_info_ref (gpointer instance);
void rygel_resource_info_unref (gpointer instance);
GParamSpec* rygel_param_spec_resource_info (const gchar* name, const gchar* nick, const gchar* blurb, GType object_type, GParamFlags flags);
void rygel_value_set_resource_info (GValue* value, gpointer v_object);
void rygel_value_take_resource_info (GValue* value, gpointer v_object);
gpointer rygel_value_get_resource_info (const GValue* value);
GType rygel_resource_info_get_type (void) G_GNUC_CONST;
GeeArrayList* rygel_plugin_get_resource_infos (RygelPlugin* self);
GeeArrayList* rygel_root_device_get_services (RygelRootDevice* self);
static void rygel_root_device_finalize (GObject* obj);
static void _vala_rygel_root_device_get_property (GObject * object, guint property_id, GValue * value, GParamSpec * pspec);
static void _vala_rygel_root_device_set_property (GObject * object, guint property_id, const GValue * value, GParamSpec * pspec);


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


RygelRootDevice* rygel_root_device_construct (GType object_type, GUPnPContext* context, RygelPlugin* plugin, GUPnPXMLDoc* description_doc, const gchar* description_path, const gchar* description_dir) {
	RygelRootDevice * self = NULL;
	GUPnPContext* _tmp0_;
	RygelPlugin* _tmp1_;
	GUPnPXMLDoc* _tmp2_;
	const gchar* _tmp3_;
	const gchar* _tmp4_;
	g_return_val_if_fail (context != NULL, NULL);
	g_return_val_if_fail (plugin != NULL, NULL);
	g_return_val_if_fail (description_doc != NULL, NULL);
	g_return_val_if_fail (description_path != NULL, NULL);
	g_return_val_if_fail (description_dir != NULL, NULL);
	_tmp0_ = context;
	_tmp1_ = plugin;
	_tmp2_ = description_doc;
	_tmp3_ = description_path;
	_tmp4_ = description_dir;
	self = (RygelRootDevice*) g_object_new (object_type, "context", _tmp0_, "resource-factory", _tmp1_, "description-doc", _tmp2_, "description-path", _tmp3_, "description-dir", _tmp4_, NULL);
	if (self != NULL) {
		GeeArrayList* _tmp5_;
		GeeArrayList* _tmp6_;
		_tmp5_ = gee_array_list_new (gupnp_service_info_get_type (), (GBoxedCopyFunc) g_object_ref, g_object_unref, NULL, NULL, NULL);
		_tmp6_ = _tmp5_;
		rygel_root_device_set_services (self, _tmp6_);
		_g_object_unref0 (_tmp6_);
		{
			RygelPlugin* _tmp7_;
			GeeArrayList* _tmp8_;
			GeeArrayList* _tmp9_;
			GeeArrayList* _tmp10_;
			GeeArrayList* _info_list;
			GeeArrayList* _tmp11_;
			gint _tmp12_;
			gint _tmp13_;
			gint _info_size;
			gint _info_index;
			_tmp7_ = plugin;
			_tmp8_ = rygel_plugin_get_resource_infos (_tmp7_);
			_tmp9_ = _tmp8_;
			_tmp10_ = _g_object_ref0 (_tmp9_);
			_info_list = _tmp10_;
			_tmp11_ = _info_list;
			_tmp12_ = gee_abstract_collection_get_size ((GeeCollection*) _tmp11_);
			_tmp13_ = _tmp12_;
			_info_size = _tmp13_;
			_info_index = -1;
			while (TRUE) {
				gint _tmp14_;
				gint _tmp15_;
				gint _tmp16_;
				GeeArrayList* _tmp17_;
				gint _tmp18_;
				gpointer _tmp19_ = NULL;
				RygelResourceInfo* info;
				RygelResourceInfo* _tmp20_;
				GType _tmp21_;
				gboolean _tmp22_ = FALSE;
				_tmp14_ = _info_index;
				_info_index = _tmp14_ + 1;
				_tmp15_ = _info_index;
				_tmp16_ = _info_size;
				if (!(_tmp15_ < _tmp16_)) {
					break;
				}
				_tmp17_ = _info_list;
				_tmp18_ = _info_index;
				_tmp19_ = gee_abstract_list_get ((GeeAbstractList*) _tmp17_, _tmp18_);
				info = (RygelResourceInfo*) _tmp19_;
				_tmp20_ = info;
				_tmp21_ = _tmp20_->type;
				_tmp22_ = g_type_is_a (_tmp21_, gupnp_service_get_type ());
				if (_tmp22_) {
					RygelResourceInfo* _tmp23_;
					const gchar* _tmp24_;
					GUPnPServiceInfo* _tmp25_ = NULL;
					GUPnPServiceInfo* service;
					GeeArrayList* _tmp26_;
					GUPnPServiceInfo* _tmp27_;
					_tmp23_ = info;
					_tmp24_ = _tmp23_->upnp_type;
					_tmp25_ = gupnp_device_info_get_service ((GUPnPDeviceInfo*) self, _tmp24_);
					service = _tmp25_;
					_tmp26_ = self->priv->_services;
					_tmp27_ = service;
					gee_abstract_collection_add ((GeeAbstractCollection*) _tmp26_, _tmp27_);
					_g_object_unref0 (service);
				}
				_rygel_resource_info_unref0 (info);
			}
			_g_object_unref0 (_info_list);
		}
	}
	return self;
}


RygelRootDevice* rygel_root_device_new (GUPnPContext* context, RygelPlugin* plugin, GUPnPXMLDoc* description_doc, const gchar* description_path, const gchar* description_dir) {
	return rygel_root_device_construct (RYGEL_TYPE_ROOT_DEVICE, context, plugin, description_doc, description_path, description_dir);
}


GeeArrayList* rygel_root_device_get_services (RygelRootDevice* self) {
	GeeArrayList* result;
	GeeArrayList* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_services;
	result = _tmp0_;
	return result;
}


void rygel_root_device_set_services (RygelRootDevice* self, GeeArrayList* value) {
	GeeArrayList* _tmp0_;
	GeeArrayList* _tmp1_;
	g_return_if_fail (self != NULL);
	_tmp0_ = value;
	_tmp1_ = _g_object_ref0 (_tmp0_);
	_g_object_unref0 (self->priv->_services);
	self->priv->_services = _tmp1_;
	g_object_notify ((GObject *) self, "services");
}


static void rygel_root_device_class_init (RygelRootDeviceClass * klass) {
	rygel_root_device_parent_class = g_type_class_peek_parent (klass);
	g_type_class_add_private (klass, sizeof (RygelRootDevicePrivate));
	G_OBJECT_CLASS (klass)->get_property = _vala_rygel_root_device_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_rygel_root_device_set_property;
	G_OBJECT_CLASS (klass)->finalize = rygel_root_device_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), RYGEL_ROOT_DEVICE_SERVICES, g_param_spec_object ("services", "services", "services", GEE_TYPE_ARRAY_LIST, G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_READABLE | G_PARAM_WRITABLE));
}


static void rygel_root_device_instance_init (RygelRootDevice * self) {
	self->priv = RYGEL_ROOT_DEVICE_GET_PRIVATE (self);
}


static void rygel_root_device_finalize (GObject* obj) {
	RygelRootDevice * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, RYGEL_TYPE_ROOT_DEVICE, RygelRootDevice);
	_g_object_unref0 (self->priv->_services);
	G_OBJECT_CLASS (rygel_root_device_parent_class)->finalize (obj);
}


/**
 * This represents a UPnP root device.
 *
 * Each Rygel plugin corresponds to one UPnP root device, so
 * each #RygelPlugin corresponds to one #RygelRootDevice.
 *
 * Rygel creates the #RygelRootDevice by calling
 * rygel_root_device_factory_create() with the plugin,
 * having first instantiated the #RygelRootDeviceFactory
 * for a #GUPnPContext.
 */
GType rygel_root_device_get_type (void) {
	static volatile gsize rygel_root_device_type_id__volatile = 0;
	if (g_once_init_enter (&rygel_root_device_type_id__volatile)) {
		static const GTypeInfo g_define_type_info = { sizeof (RygelRootDeviceClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) rygel_root_device_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (RygelRootDevice), 0, (GInstanceInitFunc) rygel_root_device_instance_init, NULL };
		GType rygel_root_device_type_id;
		rygel_root_device_type_id = g_type_register_static (gupnp_root_device_get_type (), "RygelRootDevice", &g_define_type_info, 0);
		g_once_init_leave (&rygel_root_device_type_id__volatile, rygel_root_device_type_id);
	}
	return rygel_root_device_type_id__volatile;
}


static void _vala_rygel_root_device_get_property (GObject * object, guint property_id, GValue * value, GParamSpec * pspec) {
	RygelRootDevice * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, RYGEL_TYPE_ROOT_DEVICE, RygelRootDevice);
	switch (property_id) {
		case RYGEL_ROOT_DEVICE_SERVICES:
		g_value_set_object (value, rygel_root_device_get_services (self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}


static void _vala_rygel_root_device_set_property (GObject * object, guint property_id, const GValue * value, GParamSpec * pspec) {
	RygelRootDevice * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, RYGEL_TYPE_ROOT_DEVICE, RygelRootDevice);
	switch (property_id) {
		case RYGEL_ROOT_DEVICE_SERVICES:
		rygel_root_device_set_services (self, g_value_get_object (value));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}



