/* rygel-root-device.c generated by valac 0.40.8, 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.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 <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;
enum  {
	RYGEL_ROOT_DEVICE_0_PROPERTY,
	RYGEL_ROOT_DEVICE_SERVICES_PROPERTY,
	RYGEL_ROOT_DEVICE_NUM_PROPERTIES
};
static GParamSpec* rygel_root_device_properties[RYGEL_ROOT_DEVICE_NUM_PROPERTIES];
#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))
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);
static void rygel_root_device_real_constructed (GObject* base);
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);


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;
	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);
	self = (RygelRootDevice*) g_object_new (object_type, "context", context, "resource-factory", plugin, "description-doc", description_doc, "description-path", description_path, "description-dir", description_dir, NULL);
	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);
}


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


static void
rygel_root_device_real_constructed (GObject* base)
{
	RygelRootDevice * self;
	GeeArrayList* _tmp0_;
	GeeArrayList* _tmp1_;
	RygelPlugin* plugin = NULL;
	GUPnPResourceFactory* _tmp2_;
	GUPnPResourceFactory* _tmp3_;
	RygelPlugin* _tmp4_;
	self = (RygelRootDevice*) base;
	G_OBJECT_CLASS (rygel_root_device_parent_class)->constructed ((GObject*) G_TYPE_CHECK_INSTANCE_CAST (self, gupnp_root_device_get_type (), GUPnPRootDevice));
	_tmp0_ = gee_array_list_new (gupnp_service_info_get_type (), (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, NULL, NULL, NULL);
	_tmp1_ = _tmp0_;
	rygel_root_device_set_services (self, _tmp1_);
	_g_object_unref0 (_tmp1_);
	_tmp2_ = gupnp_device_info_get_resource_factory ((GUPnPDeviceInfo*) self);
	_tmp3_ = _tmp2_;
	_tmp4_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_TYPE (_tmp3_, RYGEL_TYPE_PLUGIN) ? ((RygelPlugin*) _tmp3_) : NULL);
	plugin = _tmp4_;
	{
		GeeArrayList* _info_list = NULL;
		RygelPlugin* _tmp5_;
		GeeArrayList* _tmp6_;
		GeeArrayList* _tmp7_;
		GeeArrayList* _tmp8_;
		gint _info_size = 0;
		GeeArrayList* _tmp9_;
		gint _tmp10_;
		gint _tmp11_;
		gint _info_index = 0;
		_tmp5_ = plugin;
		_tmp6_ = rygel_plugin_get_resource_infos (_tmp5_);
		_tmp7_ = _tmp6_;
		_tmp8_ = _g_object_ref0 (_tmp7_);
		_info_list = _tmp8_;
		_tmp9_ = _info_list;
		_tmp10_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp9_);
		_tmp11_ = _tmp10_;
		_info_size = _tmp11_;
		_info_index = -1;
		while (TRUE) {
			gint _tmp12_;
			gint _tmp13_;
			gint _tmp14_;
			RygelResourceInfo* info = NULL;
			GeeArrayList* _tmp15_;
			gint _tmp16_;
			gpointer _tmp17_;
			RygelResourceInfo* _tmp18_;
			GType _tmp19_;
			_tmp12_ = _info_index;
			_info_index = _tmp12_ + 1;
			_tmp13_ = _info_index;
			_tmp14_ = _info_size;
			if (!(_tmp13_ < _tmp14_)) {
				break;
			}
			_tmp15_ = _info_list;
			_tmp16_ = _info_index;
			_tmp17_ = gee_abstract_list_get ((GeeAbstractList*) _tmp15_, _tmp16_);
			info = (RygelResourceInfo*) _tmp17_;
			_tmp18_ = info;
			_tmp19_ = _tmp18_->type;
			if (g_type_is_a (_tmp19_, gupnp_service_get_type ())) {
				GUPnPServiceInfo* service = NULL;
				RygelResourceInfo* _tmp20_;
				const gchar* _tmp21_;
				GUPnPServiceInfo* _tmp22_;
				GeeArrayList* _tmp23_;
				GUPnPServiceInfo* _tmp24_;
				_tmp20_ = info;
				_tmp21_ = _tmp20_->upnp_type;
				_tmp22_ = gupnp_device_info_get_service ((GUPnPDeviceInfo*) self, _tmp21_);
				service = _tmp22_;
				_tmp23_ = self->priv->_services;
				_tmp24_ = service;
				gee_abstract_collection_add ((GeeAbstractCollection*) _tmp23_, _tmp24_);
				_g_object_unref0 (service);
			}
			_rygel_resource_info_unref0 (info);
		}
		_g_object_unref0 (_info_list);
	}
	_g_object_unref0 (plugin);
}


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)
{
	g_return_if_fail (self != NULL);
	if (rygel_root_device_get_services (self) != value) {
		GeeArrayList* _tmp0_;
		_tmp0_ = _g_object_ref0 (value);
		_g_object_unref0 (self->priv->_services);
		self->priv->_services = _tmp0_;
		g_object_notify_by_pspec ((GObject *) self, rygel_root_device_properties[RYGEL_ROOT_DEVICE_SERVICES_PROPERTY]);
	}
}


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));
	((GObjectClass *) klass)->constructed = (void (*) (GObject *)) rygel_root_device_real_constructed;
	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_PROPERTY, rygel_root_device_properties[RYGEL_ROOT_DEVICE_SERVICES_PROPERTY] = g_param_spec_object ("services", "services", "services", GEE_TYPE_ARRAY_LIST, G_PARAM_STATIC_STRINGS | 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_PROPERTY:
		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_PROPERTY:
		rygel_root_device_set_services (self, g_value_get_object (value));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}



