/* plugin-register.c generated by valac 0.35.5, the Vala compiler
 * generated from plugin-register.vala, do not modify */

/* This file is part of GNOME Games. License: GPLv3*/

#include <glib.h>
#include <glib-object.h>
#include <stdlib.h>
#include <string.h>
#include <gio/gio.h>


#define GAMES_TYPE_PLUGIN_REGISTER (games_plugin_register_get_type ())
#define GAMES_PLUGIN_REGISTER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GAMES_TYPE_PLUGIN_REGISTER, GamesPluginRegister))
#define GAMES_PLUGIN_REGISTER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GAMES_TYPE_PLUGIN_REGISTER, GamesPluginRegisterClass))
#define GAMES_IS_PLUGIN_REGISTER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GAMES_TYPE_PLUGIN_REGISTER))
#define GAMES_IS_PLUGIN_REGISTER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GAMES_TYPE_PLUGIN_REGISTER))
#define GAMES_PLUGIN_REGISTER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GAMES_TYPE_PLUGIN_REGISTER, GamesPluginRegisterClass))

typedef struct _GamesPluginRegister GamesPluginRegister;
typedef struct _GamesPluginRegisterClass GamesPluginRegisterClass;
typedef struct _GamesPluginRegisterPrivate GamesPluginRegisterPrivate;

#define GAMES_TYPE_PLUGIN_REGISTRAR (games_plugin_registrar_get_type ())
#define GAMES_PLUGIN_REGISTRAR(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GAMES_TYPE_PLUGIN_REGISTRAR, GamesPluginRegistrar))
#define GAMES_PLUGIN_REGISTRAR_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GAMES_TYPE_PLUGIN_REGISTRAR, GamesPluginRegistrarClass))
#define GAMES_IS_PLUGIN_REGISTRAR(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GAMES_TYPE_PLUGIN_REGISTRAR))
#define GAMES_IS_PLUGIN_REGISTRAR_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GAMES_TYPE_PLUGIN_REGISTRAR))
#define GAMES_PLUGIN_REGISTRAR_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GAMES_TYPE_PLUGIN_REGISTRAR, GamesPluginRegistrarClass))

typedef struct _GamesPluginRegistrar GamesPluginRegistrar;
typedef struct _GamesPluginRegistrarClass GamesPluginRegistrarClass;
#define _g_hash_table_unref0(var) ((var == NULL) ? NULL : (var = (g_hash_table_unref (var), NULL)))
#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)))

struct _GamesPluginRegister {
	GObject parent_instance;
	GamesPluginRegisterPrivate * priv;
};

struct _GamesPluginRegisterClass {
	GObjectClass parent_class;
};

struct _GamesPluginRegisterPrivate {
	GHashTable* plugin_registrars;
};

typedef void (*GamesPluginRegisterPluginRegistrarFunc) (GamesPluginRegistrar* plugin_registrar, void* user_data);
typedef enum  {
	GAMES_PLUGIN_ERROR_INVALID_PLUGIN_DESCRIPTOR,
	GAMES_PLUGIN_ERROR_NOT_A_PLUGIN
} GamesPluginError;
#define GAMES_PLUGIN_ERROR games_plugin_error_quark ()

static gpointer games_plugin_register_parent_class = NULL;
static GamesPluginRegister* games_plugin_register_instance;
static GamesPluginRegister* games_plugin_register_instance = NULL;

GType games_plugin_register_get_type (void) G_GNUC_CONST;
GType games_plugin_registrar_get_type (void) G_GNUC_CONST;
#define GAMES_PLUGIN_REGISTER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GAMES_TYPE_PLUGIN_REGISTER, GamesPluginRegisterPrivate))
enum  {
	GAMES_PLUGIN_REGISTER_DUMMY_PROPERTY
};
static GamesPluginRegister* games_plugin_register_new (void);
static GamesPluginRegister* games_plugin_register_construct (GType object_type);
static void _g_free0_ (gpointer var);
static void _g_object_unref0_ (gpointer var);
GamesPluginRegister* games_plugin_register_get_register (void);
void games_plugin_register_foreach_plugin_registrar (GamesPluginRegister* self, GamesPluginRegisterPluginRegistrarFunc func, void* func_target);
GamesPluginRegistrar* games_plugin_register_get_plugin_registrar (GamesPluginRegister* self, const gchar* descriptor_filename, GError** error);
GQuark games_plugin_error_quark (void);
GamesPluginRegistrar* games_plugin_registrar_new (const gchar* plugin_filename, GError** error);
GamesPluginRegistrar* games_plugin_registrar_construct (GType object_type, const gchar* plugin_filename, GError** error);
static void games_plugin_register_finalize (GObject * obj);


static void _g_free0_ (gpointer var) {
	var = (g_free (var), NULL);
}


static void _g_object_unref0_ (gpointer var) {
	(var == NULL) ? NULL : (var = (g_object_unref (var), NULL));
}


static GamesPluginRegister* games_plugin_register_construct (GType object_type) {
	GamesPluginRegister * self = NULL;
	GHashFunc _tmp0_;
	GEqualFunc _tmp1_;
	GHashTable* _tmp2_;
	self = (GamesPluginRegister*) g_object_new (object_type, NULL);
	_tmp0_ = g_str_hash;
	_tmp1_ = g_str_equal;
	_tmp2_ = g_hash_table_new_full (_tmp0_, _tmp1_, _g_free0_, _g_object_unref0_);
	_g_hash_table_unref0 (self->priv->plugin_registrars);
	self->priv->plugin_registrars = _tmp2_;
	return self;
}


static GamesPluginRegister* games_plugin_register_new (void) {
	return games_plugin_register_construct (GAMES_TYPE_PLUGIN_REGISTER);
}


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


GamesPluginRegister* games_plugin_register_get_register (void) {
	GamesPluginRegister* result = NULL;
	GamesPluginRegister* _tmp0_;
	GamesPluginRegister* _tmp2_;
	GamesPluginRegister* _tmp3_;
	_tmp0_ = games_plugin_register_instance;
	if (_tmp0_ == NULL) {
		GamesPluginRegister* _tmp1_;
		_tmp1_ = games_plugin_register_new ();
		_g_object_unref0 (games_plugin_register_instance);
		games_plugin_register_instance = _tmp1_;
	}
	_tmp2_ = games_plugin_register_instance;
	_tmp3_ = _g_object_ref0 (_tmp2_);
	result = _tmp3_;
	return result;
}


void games_plugin_register_foreach_plugin_registrar (GamesPluginRegister* self, GamesPluginRegisterPluginRegistrarFunc func, void* func_target) {
	GFile* directory;
	GFile* _tmp0_;
	GError * _inner_error_ = NULL;
	g_return_if_fail (self != NULL);
	_tmp0_ = g_file_new_for_path (GAMES_PLUGINS_DIR);
	directory = _tmp0_;
	{
		GFileEnumerator* enumerator;
		GFile* _tmp1_;
		GFileEnumerator* _tmp2_;
		GFileInfo* info = NULL;
		_tmp1_ = directory;
		_tmp2_ = g_file_enumerate_children (_tmp1_, G_FILE_ATTRIBUTE_STANDARD_NAME, 0, NULL, &_inner_error_);
		enumerator = _tmp2_;
		if (G_UNLIKELY (_inner_error_ != NULL)) {
			goto __catch1_g_error;
		}
		while (TRUE) {
			GFileInfo* _tmp3_;
			GFileEnumerator* _tmp4_;
			GFileInfo* _tmp5_;
			GFileInfo* _tmp6_;
			GFileInfo* _tmp7_;
			gchar* name;
			GFileInfo* _tmp8_;
			const gchar* _tmp9_;
			gchar* _tmp10_;
			const gchar* _tmp11_;
			gboolean _tmp12_;
			_tmp4_ = enumerator;
			_tmp5_ = g_file_enumerator_next_file (_tmp4_, NULL, &_inner_error_);
			_tmp3_ = _tmp5_;
			if (G_UNLIKELY (_inner_error_ != NULL)) {
				_g_object_unref0 (info);
				_g_object_unref0 (enumerator);
				goto __catch1_g_error;
			}
			_tmp6_ = _tmp3_;
			_tmp3_ = NULL;
			_g_object_unref0 (info);
			info = _tmp6_;
			_tmp7_ = info;
			if (!(_tmp7_ != NULL)) {
				_g_object_unref0 (_tmp3_);
				break;
			}
			_tmp8_ = info;
			_tmp9_ = g_file_info_get_name (_tmp8_);
			_tmp10_ = g_strdup (_tmp9_);
			name = _tmp10_;
			_tmp11_ = name;
			_tmp12_ = g_str_has_suffix (_tmp11_, ".plugin");
			if (_tmp12_) {
				GFile* descriptor;
				GFile* _tmp13_;
				const gchar* _tmp14_;
				GFile* _tmp15_;
				gchar* descriptor_path;
				GFile* _tmp16_;
				gchar* _tmp17_;
				GamesPluginRegistrar* registrar;
				const gchar* _tmp18_;
				GamesPluginRegistrar* _tmp19_;
				GamesPluginRegisterPluginRegistrarFunc _tmp20_;
				void* _tmp20__target;
				GamesPluginRegistrar* _tmp21_;
				_tmp13_ = directory;
				_tmp14_ = name;
				_tmp15_ = g_file_get_child (_tmp13_, _tmp14_);
				descriptor = _tmp15_;
				_tmp16_ = descriptor;
				_tmp17_ = g_file_get_path (_tmp16_);
				descriptor_path = _tmp17_;
				_tmp18_ = descriptor_path;
				_tmp19_ = games_plugin_register_get_plugin_registrar (self, _tmp18_, &_inner_error_);
				registrar = _tmp19_;
				if (G_UNLIKELY (_inner_error_ != NULL)) {
					_g_free0 (descriptor_path);
					_g_object_unref0 (descriptor);
					_g_free0 (name);
					_g_object_unref0 (_tmp3_);
					_g_object_unref0 (info);
					_g_object_unref0 (enumerator);
					goto __catch1_g_error;
				}
				_tmp20_ = func;
				_tmp20__target = func_target;
				_tmp21_ = registrar;
				_tmp20_ (_tmp21_, _tmp20__target);
				_g_object_unref0 (registrar);
				_g_free0 (descriptor_path);
				_g_object_unref0 (descriptor);
			}
			_g_free0 (name);
			_g_object_unref0 (_tmp3_);
		}
		_g_object_unref0 (info);
		_g_object_unref0 (enumerator);
	}
	goto __finally1;
	__catch1_g_error:
	{
		GError* e = NULL;
		GError* _tmp22_;
		const gchar* _tmp23_;
		e = _inner_error_;
		_inner_error_ = NULL;
		_tmp22_ = e;
		_tmp23_ = _tmp22_->message;
		g_debug ("plugin-register.vala:39: Error: %s", _tmp23_);
		_g_error_free0 (e);
	}
	__finally1:
	if (G_UNLIKELY (_inner_error_ != NULL)) {
		_g_object_unref0 (directory);
		g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
		g_clear_error (&_inner_error_);
		return;
	}
	_g_object_unref0 (directory);
}


GamesPluginRegistrar* games_plugin_register_get_plugin_registrar (GamesPluginRegister* self, const gchar* descriptor_filename, GError** error) {
	GamesPluginRegistrar* result = NULL;
	GHashTable* _tmp0_;
	const gchar* _tmp1_;
	gboolean _tmp2_;
	GamesPluginRegistrar* registrar;
	const gchar* _tmp7_;
	GamesPluginRegistrar* _tmp8_;
	GHashTable* _tmp9_;
	const gchar* _tmp10_;
	gchar* _tmp11_;
	GamesPluginRegistrar* _tmp12_;
	GamesPluginRegistrar* _tmp13_;
	GError * _inner_error_ = NULL;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (descriptor_filename != NULL, NULL);
	_tmp0_ = self->priv->plugin_registrars;
	_tmp1_ = descriptor_filename;
	_tmp2_ = g_hash_table_contains (_tmp0_, _tmp1_);
	if (_tmp2_) {
		GHashTable* _tmp3_;
		const gchar* _tmp4_;
		gconstpointer _tmp5_;
		GamesPluginRegistrar* _tmp6_;
		_tmp3_ = self->priv->plugin_registrars;
		_tmp4_ = descriptor_filename;
		_tmp5_ = g_hash_table_lookup (_tmp3_, _tmp4_);
		_tmp6_ = _g_object_ref0 ((GamesPluginRegistrar*) _tmp5_);
		result = _tmp6_;
		return result;
	}
	_tmp7_ = descriptor_filename;
	_tmp8_ = games_plugin_registrar_new (_tmp7_, &_inner_error_);
	registrar = _tmp8_;
	if (G_UNLIKELY (_inner_error_ != NULL)) {
		g_propagate_error (error, _inner_error_);
		return NULL;
	}
	_tmp9_ = self->priv->plugin_registrars;
	_tmp10_ = descriptor_filename;
	_tmp11_ = g_strdup (_tmp10_);
	_tmp12_ = registrar;
	_tmp13_ = _g_object_ref0 (_tmp12_);
	g_hash_table_insert (_tmp9_, _tmp11_, _tmp13_);
	result = registrar;
	return result;
}


static void games_plugin_register_class_init (GamesPluginRegisterClass * klass) {
	games_plugin_register_parent_class = g_type_class_peek_parent (klass);
	g_type_class_add_private (klass, sizeof (GamesPluginRegisterPrivate));
	G_OBJECT_CLASS (klass)->finalize = games_plugin_register_finalize;
}


static void games_plugin_register_instance_init (GamesPluginRegister * self) {
	self->priv = GAMES_PLUGIN_REGISTER_GET_PRIVATE (self);
}


static void games_plugin_register_finalize (GObject * obj) {
	GamesPluginRegister * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, GAMES_TYPE_PLUGIN_REGISTER, GamesPluginRegister);
	_g_hash_table_unref0 (self->priv->plugin_registrars);
	G_OBJECT_CLASS (games_plugin_register_parent_class)->finalize (obj);
}


GType games_plugin_register_get_type (void) {
	static volatile gsize games_plugin_register_type_id__volatile = 0;
	if (g_once_init_enter (&games_plugin_register_type_id__volatile)) {
		static const GTypeInfo g_define_type_info = { sizeof (GamesPluginRegisterClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) games_plugin_register_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (GamesPluginRegister), 0, (GInstanceInitFunc) games_plugin_register_instance_init, NULL };
		GType games_plugin_register_type_id;
		games_plugin_register_type_id = g_type_register_static (G_TYPE_OBJECT, "GamesPluginRegister", &g_define_type_info, 0);
		g_once_init_leave (&games_plugin_register_type_id__volatile, games_plugin_register_type_id);
	}
	return games_plugin_register_type_id__volatile;
}



