/* rygel-tracker-plugin-factory.c generated by valac 0.56.1, the Vala compiler
 * generated from rygel-tracker-plugin-factory.vala, do not modify */

/*
 * Copyright (C) 2009 Zeeshan Ali (Khattak) <zeeshanak@gnome.org>.
 * Copyright (C) 2009-2012 Nokia Corporation.
 *
 * Author: Zeeshan Ali (Khattak) <zeeshanak@gnome.org>
 *                               <zeeshan.ali@nokia.com>
 *         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 "rygel-tracker3.h"
#include "rygel-core.h"
#include <glib.h>
#include <glib/gi18n-lib.h>
#include <stdlib.h>
#include <string.h>
#include <gobject/gvaluecollector.h>

#define _rygel_tracker_plugin_factory_unref0(var) ((var == NULL) ? NULL : (var = (rygel_tracker_plugin_factory_unref (var), NULL)))
#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
typedef struct _RygelTrackerParamSpecPluginFactory RygelTrackerParamSpecPluginFactory;

struct _RygelTrackerPluginFactoryPrivate {
	RygelPluginLoader* loader;
};

struct _RygelTrackerParamSpecPluginFactory {
	GParamSpec parent_instance;
};

VALA_EXTERN RygelTrackerPluginFactory* plugin_factory;
RygelTrackerPluginFactory* plugin_factory = NULL;
static gint RygelTrackerPluginFactory_private_offset;
static gpointer rygel_tracker_plugin_factory_parent_class = NULL;

static void rygel_tracker_plugin_factory_finalize (RygelTrackerPluginFactory * obj);
static GType rygel_tracker_plugin_factory_get_type_once (void);

void
module_init (RygelPluginLoader* loader)
{
	GError* _inner_error0_ = NULL;
	g_return_if_fail (loader != NULL);
	{
		RygelTrackerPluginFactory* _tmp0_ = NULL;
		RygelTrackerPluginFactory* _tmp1_;
		RygelTrackerPluginFactory* _tmp2_;
		_tmp1_ = rygel_tracker_plugin_factory_new (loader, &_inner_error0_);
		_tmp0_ = _tmp1_;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			goto __catch0_g_error;
		}
		_tmp2_ = _tmp0_;
		_tmp0_ = NULL;
		_rygel_tracker_plugin_factory_unref0 (plugin_factory);
		plugin_factory = _tmp2_;
		_rygel_tracker_plugin_factory_unref0 (_tmp0_);
	}
	goto __finally0;
	__catch0_g_error:
	{
		GError* err = NULL;
		GError* _tmp3_;
		const gchar* _tmp4_;
		err = _inner_error0_;
		_inner_error0_ = NULL;
		_tmp3_ = err;
		_tmp4_ = _tmp3_->message;
		g_warning (_ ("Failed to start Tracker service: %s. Plugin disabled."), _tmp4_);
		_g_error_free0 (err);
	}
	__finally0:
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
		g_clear_error (&_inner_error0_);
		return;
	}
}

static inline gpointer
rygel_tracker_plugin_factory_get_instance_private (RygelTrackerPluginFactory* self)
{
	return G_STRUCT_MEMBER_P (self, RygelTrackerPluginFactory_private_offset);
}

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

RygelTrackerPluginFactory*
rygel_tracker_plugin_factory_construct (GType object_type,
                                        RygelPluginLoader* loader,
                                        GError** error)
{
	RygelTrackerPluginFactory* self = NULL;
	RygelPluginLoader* _tmp0_;
	RygelTrackerPlugin* _tmp1_ = NULL;
	RygelTrackerPlugin* _tmp2_;
	RygelPluginLoader* _tmp3_;
	GError* _inner_error0_ = NULL;
	g_return_val_if_fail (loader != NULL, NULL);
	self = (RygelTrackerPluginFactory*) g_type_create_instance (object_type);
	_tmp0_ = _g_object_ref0 (loader);
	_g_object_unref0 (self->priv->loader);
	self->priv->loader = _tmp0_;
	_tmp2_ = rygel_tracker_plugin_new (&_inner_error0_);
	_tmp1_ = _tmp2_;
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_rygel_tracker_plugin_factory_unref0 (self);
		return NULL;
	}
	_tmp3_ = self->priv->loader;
	rygel_plugin_loader_add_plugin (_tmp3_, (RygelPlugin*) _tmp1_);
	_g_object_unref0 (_tmp1_);
	return self;
}

RygelTrackerPluginFactory*
rygel_tracker_plugin_factory_new (RygelPluginLoader* loader,
                                  GError** error)
{
	return rygel_tracker_plugin_factory_construct (RYGEL_TRACKER_TYPE_PLUGIN_FACTORY, loader, error);
}

static void
rygel_tracker_value_plugin_factory_init (GValue* value)
{
	value->data[0].v_pointer = NULL;
}

static void
rygel_tracker_value_plugin_factory_free_value (GValue* value)
{
	if (value->data[0].v_pointer) {
		rygel_tracker_plugin_factory_unref (value->data[0].v_pointer);
	}
}

static void
rygel_tracker_value_plugin_factory_copy_value (const GValue* src_value,
                                               GValue* dest_value)
{
	if (src_value->data[0].v_pointer) {
		dest_value->data[0].v_pointer = rygel_tracker_plugin_factory_ref (src_value->data[0].v_pointer);
	} else {
		dest_value->data[0].v_pointer = NULL;
	}
}

static gpointer
rygel_tracker_value_plugin_factory_peek_pointer (const GValue* value)
{
	return value->data[0].v_pointer;
}

static gchar*
rygel_tracker_value_plugin_factory_collect_value (GValue* value,
                                                  guint n_collect_values,
                                                  GTypeCValue* collect_values,
                                                  guint collect_flags)
{
	if (collect_values[0].v_pointer) {
		RygelTrackerPluginFactory * object;
		object = collect_values[0].v_pointer;
		if (object->parent_instance.g_class == NULL) {
			return g_strconcat ("invalid unclassed object pointer for value type `", G_VALUE_TYPE_NAME (value), "'", NULL);
		} else if (!g_value_type_compatible (G_TYPE_FROM_INSTANCE (object), G_VALUE_TYPE (value))) {
			return g_strconcat ("invalid object type `", g_type_name (G_TYPE_FROM_INSTANCE (object)), "' for value type `", G_VALUE_TYPE_NAME (value), "'", NULL);
		}
		value->data[0].v_pointer = rygel_tracker_plugin_factory_ref (object);
	} else {
		value->data[0].v_pointer = NULL;
	}
	return NULL;
}

static gchar*
rygel_tracker_value_plugin_factory_lcopy_value (const GValue* value,
                                                guint n_collect_values,
                                                GTypeCValue* collect_values,
                                                guint collect_flags)
{
	RygelTrackerPluginFactory ** object_p;
	object_p = collect_values[0].v_pointer;
	if (!object_p) {
		return g_strdup_printf ("value location for `%s' passed as NULL", G_VALUE_TYPE_NAME (value));
	}
	if (!value->data[0].v_pointer) {
		*object_p = NULL;
	} else if (collect_flags & G_VALUE_NOCOPY_CONTENTS) {
		*object_p = value->data[0].v_pointer;
	} else {
		*object_p = rygel_tracker_plugin_factory_ref (value->data[0].v_pointer);
	}
	return NULL;
}

GParamSpec*
rygel_tracker_param_spec_plugin_factory (const gchar* name,
                                         const gchar* nick,
                                         const gchar* blurb,
                                         GType object_type,
                                         GParamFlags flags)
{
	RygelTrackerParamSpecPluginFactory* spec;
	g_return_val_if_fail (g_type_is_a (object_type, RYGEL_TRACKER_TYPE_PLUGIN_FACTORY), NULL);
	spec = g_param_spec_internal (G_TYPE_PARAM_OBJECT, name, nick, blurb, flags);
	G_PARAM_SPEC (spec)->value_type = object_type;
	return G_PARAM_SPEC (spec);
}

gpointer
rygel_tracker_value_get_plugin_factory (const GValue* value)
{
	g_return_val_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, RYGEL_TRACKER_TYPE_PLUGIN_FACTORY), NULL);
	return value->data[0].v_pointer;
}

void
rygel_tracker_value_set_plugin_factory (GValue* value,
                                        gpointer v_object)
{
	RygelTrackerPluginFactory * old;
	g_return_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, RYGEL_TRACKER_TYPE_PLUGIN_FACTORY));
	old = value->data[0].v_pointer;
	if (v_object) {
		g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (v_object, RYGEL_TRACKER_TYPE_PLUGIN_FACTORY));
		g_return_if_fail (g_value_type_compatible (G_TYPE_FROM_INSTANCE (v_object), G_VALUE_TYPE (value)));
		value->data[0].v_pointer = v_object;
		rygel_tracker_plugin_factory_ref (value->data[0].v_pointer);
	} else {
		value->data[0].v_pointer = NULL;
	}
	if (old) {
		rygel_tracker_plugin_factory_unref (old);
	}
}

void
rygel_tracker_value_take_plugin_factory (GValue* value,
                                         gpointer v_object)
{
	RygelTrackerPluginFactory * old;
	g_return_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, RYGEL_TRACKER_TYPE_PLUGIN_FACTORY));
	old = value->data[0].v_pointer;
	if (v_object) {
		g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (v_object, RYGEL_TRACKER_TYPE_PLUGIN_FACTORY));
		g_return_if_fail (g_value_type_compatible (G_TYPE_FROM_INSTANCE (v_object), G_VALUE_TYPE (value)));
		value->data[0].v_pointer = v_object;
	} else {
		value->data[0].v_pointer = NULL;
	}
	if (old) {
		rygel_tracker_plugin_factory_unref (old);
	}
}

static void
rygel_tracker_plugin_factory_class_init (RygelTrackerPluginFactoryClass * klass,
                                         gpointer klass_data)
{
	rygel_tracker_plugin_factory_parent_class = g_type_class_peek_parent (klass);
	((RygelTrackerPluginFactoryClass *) klass)->finalize = rygel_tracker_plugin_factory_finalize;
	g_type_class_adjust_private_offset (klass, &RygelTrackerPluginFactory_private_offset);
}

static void
rygel_tracker_plugin_factory_instance_init (RygelTrackerPluginFactory * self,
                                            gpointer klass)
{
	self->priv = rygel_tracker_plugin_factory_get_instance_private (self);
	self->ref_count = 1;
}

static void
rygel_tracker_plugin_factory_finalize (RygelTrackerPluginFactory * obj)
{
	RygelTrackerPluginFactory * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, RYGEL_TRACKER_TYPE_PLUGIN_FACTORY, RygelTrackerPluginFactory);
	g_signal_handlers_destroy (self);
	_g_object_unref0 (self->priv->loader);
}

static GType
rygel_tracker_plugin_factory_get_type_once (void)
{
	static const GTypeValueTable g_define_type_value_table = { rygel_tracker_value_plugin_factory_init, rygel_tracker_value_plugin_factory_free_value, rygel_tracker_value_plugin_factory_copy_value, rygel_tracker_value_plugin_factory_peek_pointer, "p", rygel_tracker_value_plugin_factory_collect_value, "p", rygel_tracker_value_plugin_factory_lcopy_value };
	static const GTypeInfo g_define_type_info = { sizeof (RygelTrackerPluginFactoryClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) rygel_tracker_plugin_factory_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (RygelTrackerPluginFactory), 0, (GInstanceInitFunc) rygel_tracker_plugin_factory_instance_init, &g_define_type_value_table };
	static const GTypeFundamentalInfo g_define_type_fundamental_info = { (G_TYPE_FLAG_CLASSED | G_TYPE_FLAG_INSTANTIATABLE | G_TYPE_FLAG_DERIVABLE | G_TYPE_FLAG_DEEP_DERIVABLE) };
	GType rygel_tracker_plugin_factory_type_id;
	rygel_tracker_plugin_factory_type_id = g_type_register_fundamental (g_type_fundamental_next (), "RygelTrackerPluginFactory", &g_define_type_info, &g_define_type_fundamental_info, 0);
	RygelTrackerPluginFactory_private_offset = g_type_add_instance_private (rygel_tracker_plugin_factory_type_id, sizeof (RygelTrackerPluginFactoryPrivate));
	return rygel_tracker_plugin_factory_type_id;
}

GType
rygel_tracker_plugin_factory_get_type (void)
{
	static volatile gsize rygel_tracker_plugin_factory_type_id__once = 0;
	if (g_once_init_enter (&rygel_tracker_plugin_factory_type_id__once)) {
		GType rygel_tracker_plugin_factory_type_id;
		rygel_tracker_plugin_factory_type_id = rygel_tracker_plugin_factory_get_type_once ();
		g_once_init_leave (&rygel_tracker_plugin_factory_type_id__once, rygel_tracker_plugin_factory_type_id);
	}
	return rygel_tracker_plugin_factory_type_id__once;
}

gpointer
rygel_tracker_plugin_factory_ref (gpointer instance)
{
	RygelTrackerPluginFactory * self;
	self = instance;
	g_atomic_int_inc (&self->ref_count);
	return instance;
}

void
rygel_tracker_plugin_factory_unref (gpointer instance)
{
	RygelTrackerPluginFactory * self;
	self = instance;
	if (g_atomic_int_dec_and_test (&self->ref_count)) {
		RYGEL_TRACKER_PLUGIN_FACTORY_GET_CLASS (self)->finalize (self);
		g_type_free_instance ((GTypeInstance *) self);
	}
}

