/* localsearch-plugin-factory.c generated by valac 0.56.19, the Vala compiler
 * generated from localsearch-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-localsearch.h"
#include "rygel-core.h"
#include <glib.h>
#include <glib/gi18n-lib.h>
#include <stdlib.h>
#include <string.h>
#include <glib-object.h>
#include <gobject/gvaluecollector.h>

#if !defined(VALA_STRICT_C)
#if !defined(__clang__) && defined(__GNUC__) && (__GNUC__ >= 14)
#pragma GCC diagnostic warning "-Wincompatible-pointer-types"
#elif defined(__clang__) && (__clang_major__ >= 16)
#pragma clang diagnostic ignored "-Wincompatible-function-pointer-types"
#pragma clang diagnostic ignored "-Wincompatible-pointer-types"
#endif
#endif

#define _rygel_local_search_plugin_factory_unref0(var) ((var == NULL) ? NULL : (var = (rygel_local_search_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 _RygelLocalSearchParamSpecPluginFactory RygelLocalSearchParamSpecPluginFactory;

struct _RygelLocalSearchPluginFactoryPrivate {
	RygelPluginLoader* loader;
};

struct _RygelLocalSearchParamSpecPluginFactory {
	GParamSpec parent_instance;
};

VALA_EXTERN RygelLocalSearchPluginFactory* plugin_factory;
RygelLocalSearchPluginFactory* plugin_factory = NULL;
static gint RygelLocalSearchPluginFactory_private_offset;
static gpointer rygel_local_search_plugin_factory_parent_class = NULL;

static void rygel_local_search_plugin_factory_finalize (RygelLocalSearchPluginFactory * obj);
static GType rygel_local_search_plugin_factory_get_type_once (void);

void
module_init (RygelPluginLoader* loader)
{
	GError* _inner_error0_ = NULL;
	g_return_if_fail (loader != NULL);
	{
		RygelLocalSearchPluginFactory* _tmp0_ = NULL;
		RygelLocalSearchPluginFactory* _tmp1_;
		RygelLocalSearchPluginFactory* _tmp2_;
		_tmp1_ = rygel_local_search_plugin_factory_new (loader, &_inner_error0_);
		_tmp0_ = _tmp1_;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			goto __catch0_g_error;
		}
		_tmp2_ = _tmp0_;
		_tmp0_ = NULL;
		_rygel_local_search_plugin_factory_unref0 (plugin_factory);
		plugin_factory = _tmp2_;
		_rygel_local_search_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 LocalSearch 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_local_search_plugin_factory_get_instance_private (RygelLocalSearchPluginFactory* self)
{
	return G_STRUCT_MEMBER_P (self, RygelLocalSearchPluginFactory_private_offset);
}

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

RygelLocalSearchPluginFactory*
rygel_local_search_plugin_factory_construct (GType object_type,
                                             RygelPluginLoader* loader,
                                             GError** error)
{
	RygelLocalSearchPluginFactory* self = NULL;
	RygelPluginLoader* _tmp0_;
	RygelLocalSearchPlugin* _tmp1_ = NULL;
	RygelLocalSearchPlugin* _tmp2_;
	RygelPluginLoader* _tmp3_;
	GError* _inner_error0_ = NULL;
	g_return_val_if_fail (loader != NULL, NULL);
	self = (RygelLocalSearchPluginFactory*) g_type_create_instance (object_type);
	_tmp0_ = _g_object_ref0 (loader);
	_g_object_unref0 (self->priv->loader);
	self->priv->loader = _tmp0_;
	_tmp2_ = rygel_local_search_plugin_new (&_inner_error0_);
	_tmp1_ = _tmp2_;
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_rygel_local_search_plugin_factory_unref0 (self);
		return NULL;
	}
	_tmp3_ = self->priv->loader;
	rygel_plugin_loader_add_plugin (_tmp3_, (RygelPlugin*) _tmp1_);
	_g_object_unref0 (_tmp1_);
	return self;
}

RygelLocalSearchPluginFactory*
rygel_local_search_plugin_factory_new (RygelPluginLoader* loader,
                                       GError** error)
{
	return rygel_local_search_plugin_factory_construct (RYGEL_LOCAL_SEARCH_TYPE_PLUGIN_FACTORY, loader, error);
}

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

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

static void
rygel_local_search_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_local_search_plugin_factory_ref (src_value->data[0].v_pointer);
	} else {
		dest_value->data[0].v_pointer = NULL;
	}
}

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

static gchar*
rygel_local_search_value_plugin_factory_collect_value (GValue* value,
                                                       guint n_collect_values,
                                                       GTypeCValue* collect_values,
                                                       guint collect_flags)
{
	if (collect_values[0].v_pointer) {
		RygelLocalSearchPluginFactory * 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_local_search_plugin_factory_ref (object);
	} else {
		value->data[0].v_pointer = NULL;
	}
	return NULL;
}

static gchar*
rygel_local_search_value_plugin_factory_lcopy_value (const GValue* value,
                                                     guint n_collect_values,
                                                     GTypeCValue* collect_values,
                                                     guint collect_flags)
{
	RygelLocalSearchPluginFactory ** 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_local_search_plugin_factory_ref (value->data[0].v_pointer);
	}
	return NULL;
}

GParamSpec*
rygel_local_search_param_spec_plugin_factory (const gchar* name,
                                              const gchar* nick,
                                              const gchar* blurb,
                                              GType object_type,
                                              GParamFlags flags)
{
	RygelLocalSearchParamSpecPluginFactory* spec;
	g_return_val_if_fail (g_type_is_a (object_type, RYGEL_LOCAL_SEARCH_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_local_search_value_get_plugin_factory (const GValue* value)
{
	g_return_val_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, RYGEL_LOCAL_SEARCH_TYPE_PLUGIN_FACTORY), NULL);
	return value->data[0].v_pointer;
}

void
rygel_local_search_value_set_plugin_factory (GValue* value,
                                             gpointer v_object)
{
	RygelLocalSearchPluginFactory * old;
	g_return_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, RYGEL_LOCAL_SEARCH_TYPE_PLUGIN_FACTORY));
	old = value->data[0].v_pointer;
	if (v_object) {
		g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (v_object, RYGEL_LOCAL_SEARCH_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_local_search_plugin_factory_ref (value->data[0].v_pointer);
	} else {
		value->data[0].v_pointer = NULL;
	}
	if (old) {
		rygel_local_search_plugin_factory_unref (old);
	}
}

void
rygel_local_search_value_take_plugin_factory (GValue* value,
                                              gpointer v_object)
{
	RygelLocalSearchPluginFactory * old;
	g_return_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, RYGEL_LOCAL_SEARCH_TYPE_PLUGIN_FACTORY));
	old = value->data[0].v_pointer;
	if (v_object) {
		g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (v_object, RYGEL_LOCAL_SEARCH_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_local_search_plugin_factory_unref (old);
	}
}

static void
rygel_local_search_plugin_factory_class_init (RygelLocalSearchPluginFactoryClass * klass,
                                              gpointer klass_data)
{
	rygel_local_search_plugin_factory_parent_class = g_type_class_peek_parent (klass);
	((RygelLocalSearchPluginFactoryClass *) klass)->finalize = rygel_local_search_plugin_factory_finalize;
	g_type_class_adjust_private_offset (klass, &RygelLocalSearchPluginFactory_private_offset);
}

static void
rygel_local_search_plugin_factory_instance_init (RygelLocalSearchPluginFactory * self,
                                                 gpointer klass)
{
	self->priv = rygel_local_search_plugin_factory_get_instance_private (self);
	self->ref_count = 1;
}

static void
rygel_local_search_plugin_factory_finalize (RygelLocalSearchPluginFactory * obj)
{
	RygelLocalSearchPluginFactory * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, RYGEL_LOCAL_SEARCH_TYPE_PLUGIN_FACTORY, RygelLocalSearchPluginFactory);
	g_signal_handlers_destroy (self);
	_g_object_unref0 (self->priv->loader);
}

 G_GNUC_NO_INLINE static GType
rygel_local_search_plugin_factory_get_type_once (void)
{
	static const GTypeValueTable g_define_type_value_table = { rygel_local_search_value_plugin_factory_init, rygel_local_search_value_plugin_factory_free_value, rygel_local_search_value_plugin_factory_copy_value, rygel_local_search_value_plugin_factory_peek_pointer, "p", rygel_local_search_value_plugin_factory_collect_value, "p", rygel_local_search_value_plugin_factory_lcopy_value };
	static const GTypeInfo g_define_type_info = { sizeof (RygelLocalSearchPluginFactoryClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) rygel_local_search_plugin_factory_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (RygelLocalSearchPluginFactory), 0, (GInstanceInitFunc) rygel_local_search_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_local_search_plugin_factory_type_id;
	rygel_local_search_plugin_factory_type_id = g_type_register_fundamental (g_type_fundamental_next (), "RygelLocalSearchPluginFactory", &g_define_type_info, &g_define_type_fundamental_info, 0);
	RygelLocalSearchPluginFactory_private_offset = g_type_add_instance_private (rygel_local_search_plugin_factory_type_id, sizeof (RygelLocalSearchPluginFactoryPrivate));
	return rygel_local_search_plugin_factory_type_id;
}

GType
rygel_local_search_plugin_factory_get_type (void)
{
	static volatile gsize rygel_local_search_plugin_factory_type_id__once = 0;
	if (g_once_init_enter (&rygel_local_search_plugin_factory_type_id__once)) {
		GType rygel_local_search_plugin_factory_type_id;
		rygel_local_search_plugin_factory_type_id = rygel_local_search_plugin_factory_get_type_once ();
		g_once_init_leave (&rygel_local_search_plugin_factory_type_id__once, rygel_local_search_plugin_factory_type_id);
	}
	return rygel_local_search_plugin_factory_type_id__once;
}

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

void
rygel_local_search_plugin_factory_unref (gpointer instance)
{
	RygelLocalSearchPluginFactory * self;
	self = instance;
	if (g_atomic_int_dec_and_test (&self->ref_count)) {
		RYGEL_LOCAL_SEARCH_PLUGIN_FACTORY_GET_CLASS (self)->finalize (self);
		g_type_free_instance ((GTypeInstance *) self);
	}
}

