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

/*
 * Copyright (C) 2008 Nokia Corporation.
 * Copyright (C) 2008 Zeeshan Ali (Khattak) <zeeshanak@gnome.org>.
 * Copyright (C) 2012 Intel Corporation.
 *
 * 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 "rygel-core.h"
#include <gee.h>
#include <glib-object.h>
#include <stdlib.h>
#include <string.h>
#include <glib.h>
#include <gio/gio.h>
#include <glib/gi18n-lib.h>
#include <gmodule.h>
#include "config.h"

enum  {
	RYGEL_PLUGIN_LOADER_0_PROPERTY,
	RYGEL_PLUGIN_LOADER_NUM_PROPERTIES
};
static GParamSpec* rygel_plugin_loader_properties[RYGEL_PLUGIN_LOADER_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_free0(var) (var = (g_free (var), NULL))
#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))
#define _g_module_close0(var) ((var == NULL) ? NULL : (var = (g_module_close (var), NULL)))
typedef void (*RygelPluginLoaderModuleInitFunc) (RygelPluginLoader* loader, gpointer user_data);
enum  {
	RYGEL_PLUGIN_LOADER_PLUGIN_AVAILABLE_SIGNAL,
	RYGEL_PLUGIN_LOADER_NUM_SIGNALS
};
static guint rygel_plugin_loader_signals[RYGEL_PLUGIN_LOADER_NUM_SIGNALS] = {0};
#define _vala_assert(expr, msg) if G_LIKELY (expr) ; else g_assertion_message_expr (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, msg);
#define _vala_return_if_fail(expr, msg) if G_LIKELY (expr) ; else { g_return_if_fail_warning (G_LOG_DOMAIN, G_STRFUNC, msg); return; }
#define _vala_return_val_if_fail(expr, msg, val) if G_LIKELY (expr) ; else { g_return_if_fail_warning (G_LOG_DOMAIN, G_STRFUNC, msg); return val; }
#define _vala_warn_if_fail(expr, msg) if G_LIKELY (expr) ; else g_warn_message (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, msg);

struct _RygelPluginLoaderPrivate {
	GeeHashMap* plugin_hash;
	GeeHashMap* available_plugins;
	GeeHashSet* loaded_modules;
	RygelConfiguration* config;
};

static gint RygelPluginLoader_private_offset;
static gpointer rygel_plugin_loader_parent_class = NULL;

static gchar* rygel_plugin_loader_get_config_path (void);
static void rygel_plugin_loader_real_constructed (GObject* base);
static void rygel_plugin_loader_on_section_changed (RygelPluginLoader* self,
                                             const gchar* section,
                                             RygelSectionEntry entry);
static void _rygel_plugin_loader_on_section_changed_rygel_configuration_section_changed (RygelConfiguration* _sender,
                                                                                  const gchar* section,
                                                                                  RygelSectionEntry entry,
                                                                                  gpointer self);
static gboolean rygel_plugin_loader_real_load_module_from_file (RygelRecursiveModuleLoader* base,
                                                         GFile* module_file);
static gboolean rygel_plugin_loader_real_load_module_from_info (RygelRecursiveModuleLoader* base,
                                                         RygelPluginInformation* info);
static void rygel_plugin_loader_finalize (GObject * obj);
static GType rygel_plugin_loader_get_type_once (void);

static inline gpointer
rygel_plugin_loader_get_instance_private (RygelPluginLoader* self)
{
	return G_STRUCT_MEMBER_P (self, RygelPluginLoader_private_offset);
}

RygelPluginLoader*
rygel_plugin_loader_construct (GType object_type)
{
	RygelPluginLoader * self = NULL;
	gchar* _tmp0_;
	gchar* _tmp1_;
	_tmp0_ = rygel_plugin_loader_get_config_path ();
	_tmp1_ = _tmp0_;
	self = (RygelPluginLoader*) g_object_new (object_type, "base-path", _tmp1_, NULL);
	_g_free0 (_tmp1_);
	return self;
}

RygelPluginLoader*
rygel_plugin_loader_new (void)
{
	return rygel_plugin_loader_construct (RYGEL_TYPE_PLUGIN_LOADER);
}

static void
_rygel_plugin_loader_on_section_changed_rygel_configuration_section_changed (RygelConfiguration* _sender,
                                                                             const gchar* section,
                                                                             RygelSectionEntry entry,
                                                                             gpointer self)
{
	rygel_plugin_loader_on_section_changed ((RygelPluginLoader*) self, section, entry);
}

static void
rygel_plugin_loader_real_constructed (GObject* base)
{
	RygelPluginLoader * self;
	const gchar* _tmp0_;
	const gchar* _tmp1_;
	GeeHashMap* _tmp4_;
	GeeHashSet* _tmp5_;
	RygelMetaConfig* _tmp6_;
	RygelConfiguration* _tmp7_;
	GeeHashMap* _tmp8_;
	self = (RygelPluginLoader*) base;
	G_OBJECT_CLASS (rygel_plugin_loader_parent_class)->constructed ((GObject*) G_TYPE_CHECK_INSTANCE_CAST (self, RYGEL_TYPE_RECURSIVE_MODULE_LOADER, RygelRecursiveModuleLoader));
	_tmp0_ = rygel_recursive_module_loader_get_base_path ((RygelRecursiveModuleLoader*) self);
	_tmp1_ = _tmp0_;
	if (_tmp1_ == NULL) {
		gchar* _tmp2_;
		gchar* _tmp3_;
		_tmp2_ = rygel_plugin_loader_get_config_path ();
		_tmp3_ = _tmp2_;
		rygel_recursive_module_loader_set_base_path ((RygelRecursiveModuleLoader*) self, _tmp3_);
		_g_free0 (_tmp3_);
	}
	_tmp4_ = gee_hash_map_new (G_TYPE_STRING, (GBoxedCopyFunc) g_strdup, (GDestroyNotify) g_free, RYGEL_TYPE_PLUGIN, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
	_g_object_unref0 (self->priv->plugin_hash);
	self->priv->plugin_hash = _tmp4_;
	_tmp5_ = gee_hash_set_new (G_TYPE_STRING, (GBoxedCopyFunc) g_strdup, (GDestroyNotify) g_free, NULL, NULL, NULL, NULL, NULL, NULL);
	_g_object_unref0 (self->priv->loaded_modules);
	self->priv->loaded_modules = _tmp5_;
	_tmp6_ = rygel_meta_config_get_default ();
	_g_object_unref0 (self->priv->config);
	self->priv->config = (RygelConfiguration*) _tmp6_;
	_tmp7_ = self->priv->config;
	g_signal_connect_object (_tmp7_, "section-changed", (GCallback) _rygel_plugin_loader_on_section_changed_rygel_configuration_section_changed, self, 0);
	_tmp8_ = gee_hash_map_new (G_TYPE_STRING, (GBoxedCopyFunc) g_strdup, (GDestroyNotify) g_free, RYGEL_TYPE_PLUGIN_INFORMATION, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
	_g_object_unref0 (self->priv->available_plugins);
	self->priv->available_plugins = _tmp8_;
}

/**
     * Checks if a plugin is disabled by the user
     *
     * @param name the name of plugin to check for.
     *
     * @return true if plugin is disabled, false if not.
     */
gboolean
rygel_plugin_loader_plugin_disabled (RygelPluginLoader* self,
                                     const gchar* name)
{
	gboolean enabled = FALSE;
	GError* _inner_error0_ = NULL;
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	g_return_val_if_fail (name != NULL, FALSE);
	enabled = TRUE;
	{
		gboolean _tmp0_ = FALSE;
		RygelConfiguration* _tmp1_;
		_tmp1_ = self->priv->config;
		_tmp0_ = rygel_configuration_get_enabled (_tmp1_, name, &_inner_error0_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			goto __catch0_g_error;
		}
		enabled = _tmp0_;
	}
	goto __finally0;
	__catch0_g_error:
	{
		GError* err = NULL;
		GError* _tmp2_;
		const gchar* _tmp3_;
		err = _inner_error0_;
		_inner_error0_ = NULL;
		_tmp2_ = err;
		_tmp3_ = _tmp2_->message;
		g_debug ("rygel-plugin-loader.vala:80: Could not find plugin '%s' in configurati" \
"on: %s", name, _tmp3_);
		_g_error_free0 (err);
	}
	__finally0:
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		gboolean _tmp4_ = FALSE;
		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 _tmp4_;
	}
	result = !enabled;
	return result;
}

void
rygel_plugin_loader_add_plugin (RygelPluginLoader* self,
                                RygelPlugin* plugin)
{
	const gchar* _tmp0_;
	const gchar* _tmp1_;
	GeeHashMap* _tmp2_;
	const gchar* _tmp3_;
	const gchar* _tmp4_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (plugin != NULL);
	_tmp0_ = rygel_plugin_get_name (plugin);
	_tmp1_ = _tmp0_;
	g_message (_ ("New plugin “%s” available"), _tmp1_);
	_tmp2_ = self->priv->plugin_hash;
	_tmp3_ = rygel_plugin_get_name (plugin);
	_tmp4_ = _tmp3_;
	gee_abstract_map_set ((GeeAbstractMap*) _tmp2_, _tmp4_, plugin);
	g_signal_emit (self, rygel_plugin_loader_signals[RYGEL_PLUGIN_LOADER_PLUGIN_AVAILABLE_SIGNAL], 0, plugin);
}

RygelPlugin*
rygel_plugin_loader_get_plugin_by_name (RygelPluginLoader* self,
                                        const gchar* name)
{
	GeeHashMap* _tmp0_;
	gpointer _tmp1_;
	RygelPlugin* result;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (name != NULL, NULL);
	_tmp0_ = self->priv->plugin_hash;
	_tmp1_ = gee_abstract_map_get ((GeeAbstractMap*) _tmp0_, name);
	result = (RygelPlugin*) _tmp1_;
	return result;
}

GeeCollection*
rygel_plugin_loader_list_plugins (RygelPluginLoader* self)
{
	GeeHashMap* _tmp0_;
	GeeCollection* _tmp1_;
	GeeCollection* _tmp2_;
	GeeCollection* result;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->plugin_hash;
	_tmp1_ = gee_abstract_map_get_values ((GeeAbstractMap*) _tmp0_);
	_tmp2_ = _tmp1_;
	result = _tmp2_;
	return result;
}

static gboolean
rygel_plugin_loader_real_load_module_from_file (RygelRecursiveModuleLoader* base,
                                                GFile* module_file)
{
	RygelPluginLoader * self;
	GeeHashSet* _tmp0_;
	gchar* _tmp1_;
	gchar* _tmp2_;
	gboolean _tmp3_;
	GModule* module = NULL;
	gchar* _tmp6_;
	gchar* _tmp7_;
	GModule* _tmp8_;
	GModule* _tmp9_;
	GModule* _tmp10_;
	void* function = NULL;
	GModule* _tmp14_;
	void* _tmp15_ = NULL;
	gboolean _tmp16_;
	RygelPluginLoaderModuleInitFunc module_init = NULL;
	void* _tmp20_;
	gpointer module_init_target;
	RygelPluginLoaderModuleInitFunc _tmp21_;
	gpointer _tmp21__target;
	GeeHashSet* _tmp22_;
	gchar* _tmp23_;
	gchar* _tmp24_;
	GModule* _tmp25_;
	RygelPluginLoaderModuleInitFunc _tmp26_;
	gpointer _tmp26__target;
	GModule* _tmp27_;
	const gchar* _tmp28_;
	gboolean result;
	self = (RygelPluginLoader*) base;
	g_return_val_if_fail (module_file != NULL, FALSE);
	_tmp0_ = self->priv->loaded_modules;
	_tmp1_ = g_file_get_basename (module_file);
	_tmp2_ = _tmp1_;
	_tmp3_ = gee_abstract_collection_contains ((GeeAbstractCollection*) _tmp0_, _tmp2_);
	_g_free0 (_tmp2_);
	if (_tmp3_) {
		gchar* _tmp4_;
		gchar* _tmp5_;
		_tmp4_ = g_file_get_basename (module_file);
		_tmp5_ = _tmp4_;
		g_warning (_ ("A module named %s is already loaded"), _tmp5_);
		_g_free0 (_tmp5_);
		result = TRUE;
		return result;
	}
	_tmp6_ = g_file_get_path (module_file);
	_tmp7_ = _tmp6_;
	_tmp8_ = g_module_open (_tmp7_, G_MODULE_BIND_LOCAL);
	_tmp9_ = _tmp8_;
	_g_free0 (_tmp7_);
	module = _tmp9_;
	_tmp10_ = module;
	if (_tmp10_ == NULL) {
		gchar* _tmp11_;
		gchar* _tmp12_;
		const gchar* _tmp13_;
		_tmp11_ = g_file_get_path (module_file);
		_tmp12_ = _tmp11_;
		_tmp13_ = g_module_error ();
		g_warning (_ ("Failed to load module from path “%s”: %s"), _tmp12_, _tmp13_);
		_g_free0 (_tmp12_);
		result = TRUE;
		_g_module_close0 (module);
		return result;
	}
	_tmp14_ = module;
	_tmp16_ = g_module_symbol (_tmp14_, "module_init", &_tmp15_);
	function = _tmp15_;
	if (!_tmp16_) {
		gchar* _tmp17_;
		gchar* _tmp18_;
		const gchar* _tmp19_;
		_tmp17_ = g_file_get_path (module_file);
		_tmp18_ = _tmp17_;
		_tmp19_ = g_module_error ();
		g_warning (_ ("Failed to find entry point function “%s” in “%s”: %s"), "module_init", _tmp18_, _tmp19_);
		_g_free0 (_tmp18_);
		result = TRUE;
		_g_module_close0 (module);
		return result;
	}
	_tmp20_ = function;
	module_init = (RygelPluginLoaderModuleInitFunc) _tmp20_;
	module_init_target = NULL;
	_tmp21_ = module_init;
	_tmp21__target = module_init_target;
	_vala_assert (_tmp21_ != NULL, "module_init != null");
	_tmp22_ = self->priv->loaded_modules;
	_tmp23_ = g_file_get_basename (module_file);
	_tmp24_ = _tmp23_;
	gee_abstract_collection_add ((GeeAbstractCollection*) _tmp22_, _tmp24_);
	_g_free0 (_tmp24_);
	_tmp25_ = module;
	g_module_make_resident (_tmp25_);
	_tmp26_ = module_init;
	_tmp26__target = module_init_target;
	_tmp26_ (self, _tmp26__target);
	_tmp27_ = module;
	_tmp28_ = g_module_name (_tmp27_);
	g_debug ("rygel-plugin-loader.vala:145: Loaded module source: '%s'", _tmp28_);
	result = TRUE;
	_g_module_close0 (module);
	return result;
}

static gboolean
rygel_plugin_loader_real_load_module_from_info (RygelRecursiveModuleLoader* base,
                                                RygelPluginInformation* info)
{
	RygelPluginLoader * self;
	const gchar* _tmp0_;
	const gchar* _tmp1_;
	GHashTable* _tmp2_;
	GHashTable* _tmp3_;
	GList* _tmp4_;
	GeeHashMap* _tmp17_;
	const gchar* _tmp18_;
	const gchar* _tmp19_;
	const gchar* _tmp20_;
	const gchar* _tmp21_;
	GFile* module_file = NULL;
	const gchar* _tmp24_;
	const gchar* _tmp25_;
	GFile* _tmp26_;
	gboolean loaded = FALSE;
	GFile* _tmp27_;
	gboolean result;
	self = (RygelPluginLoader*) base;
	g_return_val_if_fail (info != NULL, FALSE);
	_tmp0_ = rygel_plugin_information_get_name (info);
	_tmp1_ = _tmp0_;
	g_debug ("rygel-plugin-loader.vala:151: Trying to load plugin '%s'", _tmp1_);
	_tmp2_ = rygel_plugin_information_get_conflicts (info);
	_tmp3_ = _tmp2_;
	_tmp4_ = g_hash_table_get_values (_tmp3_);
	{
		GList* conflicting_collection = NULL;
		GList* conflicting_it = NULL;
		conflicting_collection = _tmp4_;
		for (conflicting_it = conflicting_collection; conflicting_it != NULL; conflicting_it = conflicting_it->next) {
			const gchar* conflicting = NULL;
			conflicting = (const gchar*) conflicting_it->data;
			{
				gboolean _tmp5_ = FALSE;
				GeeHashMap* _tmp6_;
				const gchar* _tmp7_;
				_tmp6_ = self->priv->available_plugins;
				_tmp7_ = conflicting;
				if (gee_abstract_map_has_key ((GeeAbstractMap*) _tmp6_, _tmp7_)) {
					GeeHashMap* _tmp8_;
					const gchar* _tmp9_;
					gpointer _tmp10_;
					RygelPluginInformation* _tmp11_;
					gboolean _tmp12_;
					gboolean _tmp13_;
					_tmp8_ = self->priv->available_plugins;
					_tmp9_ = conflicting;
					_tmp10_ = gee_abstract_map_get ((GeeAbstractMap*) _tmp8_, _tmp9_);
					_tmp11_ = (RygelPluginInformation*) _tmp10_;
					_tmp12_ = rygel_plugin_information_get_module_loaded (_tmp11_);
					_tmp13_ = _tmp12_;
					_tmp5_ = _tmp13_;
					_g_object_unref0 (_tmp11_);
				} else {
					_tmp5_ = FALSE;
				}
				if (_tmp5_) {
					const gchar* _tmp14_;
					const gchar* _tmp15_;
					const gchar* _tmp16_;
					_tmp14_ = rygel_plugin_information_get_name (info);
					_tmp15_ = _tmp14_;
					_tmp16_ = conflicting;
					g_message (_ ("Module '%s' conflicts with already loaded module '%s'. Skipping"), _tmp15_, _tmp16_);
					result = FALSE;
					(conflicting_collection == NULL) ? NULL : (conflicting_collection = (g_list_free (conflicting_collection), NULL));
					return result;
				}
			}
		}
		(conflicting_collection == NULL) ? NULL : (conflicting_collection = (g_list_free (conflicting_collection), NULL));
	}
	_tmp17_ = self->priv->available_plugins;
	_tmp18_ = rygel_plugin_information_get_name (info);
	_tmp19_ = _tmp18_;
	gee_abstract_map_set ((GeeAbstractMap*) _tmp17_, _tmp19_, info);
	_tmp20_ = rygel_plugin_information_get_name (info);
	_tmp21_ = _tmp20_;
	if (rygel_plugin_loader_plugin_disabled (self, _tmp21_)) {
		const gchar* _tmp22_;
		const gchar* _tmp23_;
		_tmp22_ = rygel_plugin_information_get_name (info);
		_tmp23_ = _tmp22_;
		g_debug ("rygel-plugin-loader.vala:166: Module '%s' disabled by user. Ignoring…", _tmp23_);
		result = TRUE;
		return result;
	}
	_tmp24_ = rygel_plugin_information_get_module_path (info);
	_tmp25_ = _tmp24_;
	_tmp26_ = g_file_new_for_path (_tmp25_);
	module_file = _tmp26_;
	_tmp27_ = module_file;
	loaded = rygel_recursive_module_loader_load_module_from_file ((RygelRecursiveModuleLoader*) self, _tmp27_);
	rygel_plugin_information_set_module_loaded (info, loaded);
	result = loaded;
	_g_object_unref0 (module_file);
	return result;
}

static void
rygel_plugin_loader_on_section_changed (RygelPluginLoader* self,
                                        const gchar* section,
                                        RygelSectionEntry entry)
{
	GError* _inner_error0_ = NULL;
	g_return_if_fail (self != NULL);
	g_return_if_fail (section != NULL);
	if (entry == RYGEL_SECTION_ENTRY_ENABLED) {
		{
			gboolean enabled = FALSE;
			RygelConfiguration* _tmp0_;
			_tmp0_ = self->priv->config;
			enabled = rygel_configuration_get_enabled (_tmp0_, section, &_inner_error0_);
			if (G_UNLIKELY (_inner_error0_ != NULL)) {
				goto __catch0_g_error;
			}
			if (!enabled) {
				GeeHashMap* _tmp1_;
				_tmp1_ = self->priv->plugin_hash;
				if (gee_abstract_map_has_key ((GeeAbstractMap*) _tmp1_, section)) {
					GeeHashMap* _tmp2_;
					gpointer _tmp3_;
					RygelPlugin* _tmp4_;
					_tmp2_ = self->priv->plugin_hash;
					_tmp3_ = gee_abstract_map_get ((GeeAbstractMap*) _tmp2_, section);
					_tmp4_ = (RygelPlugin*) _tmp3_;
					rygel_plugin_set_active (_tmp4_, enabled);
					_g_object_unref0 (_tmp4_);
				}
			} else {
				GeeHashMap* _tmp5_;
				_tmp5_ = self->priv->plugin_hash;
				if (gee_abstract_map_has_key ((GeeAbstractMap*) _tmp5_, section)) {
					GeeHashMap* _tmp6_;
					gpointer _tmp7_;
					RygelPlugin* _tmp8_;
					_tmp6_ = self->priv->plugin_hash;
					_tmp7_ = gee_abstract_map_get ((GeeAbstractMap*) _tmp6_, section);
					_tmp8_ = (RygelPlugin*) _tmp7_;
					rygel_plugin_set_active (_tmp8_, enabled);
					_g_object_unref0 (_tmp8_);
				} else {
					GeeHashMap* _tmp9_;
					_tmp9_ = self->priv->available_plugins;
					if (gee_abstract_map_has_key ((GeeAbstractMap*) _tmp9_, section)) {
						GeeHashMap* _tmp10_;
						gpointer _tmp11_;
						RygelPluginInformation* _tmp12_;
						_tmp10_ = self->priv->available_plugins;
						_tmp11_ = gee_abstract_map_get ((GeeAbstractMap*) _tmp10_, section);
						_tmp12_ = (RygelPluginInformation*) _tmp11_;
						rygel_recursive_module_loader_load_module_from_info ((RygelRecursiveModuleLoader*) self, _tmp12_);
						_g_object_unref0 (_tmp12_);
					}
				}
			}
		}
		goto __finally0;
		__catch0_g_error:
		{
			GError* _error_ = NULL;
			GError* _tmp13_;
			const gchar* _tmp14_;
			_error_ = _inner_error0_;
			_inner_error0_ = NULL;
			_tmp13_ = _error_;
			_tmp14_ = _tmp13_->message;
			g_debug ("rygel-plugin-loader.vala:199: Failed to get enabled state for %s: %s", section, _tmp14_);
			_g_error_free0 (_error_);
		}
		__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 gchar*
rygel_plugin_loader_get_config_path (void)
{
	gchar* path = NULL;
	gchar* _tmp0_;
	GError* _inner_error0_ = NULL;
	gchar* result;
	_tmp0_ = g_strdup (PLUGIN_DIR);
	path = _tmp0_;
	{
		gchar* _tmp1_ = NULL;
		RygelMetaConfig* _tmp2_;
		RygelMetaConfig* _tmp3_;
		gchar* _tmp4_;
		gchar* _tmp5_;
		gchar* _tmp6_;
		_tmp2_ = rygel_meta_config_get_default ();
		_tmp3_ = _tmp2_;
		_tmp4_ = rygel_configuration_get_plugin_path ((RygelConfiguration*) _tmp3_, &_inner_error0_);
		_tmp5_ = _tmp4_;
		_g_object_unref0 (_tmp3_);
		_tmp1_ = _tmp5_;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			goto __catch0_g_error;
		}
		_tmp6_ = _tmp1_;
		_tmp1_ = NULL;
		_g_free0 (path);
		path = _tmp6_;
		_g_free0 (_tmp1_);
	}
	goto __finally0;
	__catch0_g_error:
	{
		GError* _error_ = NULL;
		GError* _tmp7_;
		const gchar* _tmp8_;
		const gchar* _tmp9_;
		_error_ = _inner_error0_;
		_inner_error0_ = NULL;
		_tmp7_ = _error_;
		_tmp8_ = _tmp7_->message;
		_tmp9_ = path;
		g_debug ("rygel-plugin-loader.vala:211: Could not get plugin path from config: %" \
"s, using %s", _tmp8_, _tmp9_);
		_g_error_free0 (_error_);
	}
	__finally0:
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		_g_free0 (path);
		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 NULL;
	}
	result = path;
	return result;
}

static void
rygel_plugin_loader_class_init (RygelPluginLoaderClass * klass,
                                gpointer klass_data)
{
	rygel_plugin_loader_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &RygelPluginLoader_private_offset);
	((GObjectClass *) klass)->constructed = (void (*) (GObject*)) rygel_plugin_loader_real_constructed;
	((RygelRecursiveModuleLoaderClass *) klass)->load_module_from_file = (gboolean (*) (RygelRecursiveModuleLoader*, GFile*)) rygel_plugin_loader_real_load_module_from_file;
	((RygelRecursiveModuleLoaderClass *) klass)->load_module_from_info = (gboolean (*) (RygelRecursiveModuleLoader*, RygelPluginInformation*)) rygel_plugin_loader_real_load_module_from_info;
	G_OBJECT_CLASS (klass)->finalize = rygel_plugin_loader_finalize;
	rygel_plugin_loader_signals[RYGEL_PLUGIN_LOADER_PLUGIN_AVAILABLE_SIGNAL] = g_signal_new ("plugin-available", RYGEL_TYPE_PLUGIN_LOADER, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__OBJECT, G_TYPE_NONE, 1, RYGEL_TYPE_PLUGIN);
}

static void
rygel_plugin_loader_instance_init (RygelPluginLoader * self,
                                   gpointer klass)
{
	self->priv = rygel_plugin_loader_get_instance_private (self);
}

static void
rygel_plugin_loader_finalize (GObject * obj)
{
	RygelPluginLoader * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, RYGEL_TYPE_PLUGIN_LOADER, RygelPluginLoader);
	_g_object_unref0 (self->priv->plugin_hash);
	_g_object_unref0 (self->priv->available_plugins);
	_g_object_unref0 (self->priv->loaded_modules);
	_g_object_unref0 (self->priv->config);
	G_OBJECT_CLASS (rygel_plugin_loader_parent_class)->finalize (obj);
}

/**
 * This class is responsible for plugin loading.
 *
 * It probes for shared library files in a specific directory, tries to
 * find a module_init() function with this signature:
 * ``void module_init (RygelPluginLoader* loader);``
 *
 * It then calls that function, passing a pointer to itself. The loaded
 * module can then add plugins to Rygel by calling the
 * rygel_plugin_loader_add_plugin() function.
 */
static GType
rygel_plugin_loader_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (RygelPluginLoaderClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) rygel_plugin_loader_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (RygelPluginLoader), 0, (GInstanceInitFunc) rygel_plugin_loader_instance_init, NULL };
	GType rygel_plugin_loader_type_id;
	rygel_plugin_loader_type_id = g_type_register_static (RYGEL_TYPE_RECURSIVE_MODULE_LOADER, "RygelPluginLoader", &g_define_type_info, 0);
	RygelPluginLoader_private_offset = g_type_add_instance_private (rygel_plugin_loader_type_id, sizeof (RygelPluginLoaderPrivate));
	return rygel_plugin_loader_type_id;
}

GType
rygel_plugin_loader_get_type (void)
{
	static volatile gsize rygel_plugin_loader_type_id__once = 0;
	if (g_once_init_enter (&rygel_plugin_loader_type_id__once)) {
		GType rygel_plugin_loader_type_id;
		rygel_plugin_loader_type_id = rygel_plugin_loader_get_type_once ();
		g_once_init_leave (&rygel_plugin_loader_type_id__once, rygel_plugin_loader_type_id);
	}
	return rygel_plugin_loader_type_id__once;
}

